mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "J.A. Magallon" <jamagallon@able.es>
To: linux-kernel@vger.kernel.org
Subject: Re: Illegal use of reserved word in system.h
Date: Thu, 19 May 2005 22:30:32 +0000	[thread overview]
Message-ID: <1116541832l.2940l.1l@werewolf.able.es> (raw)
In-Reply-To: <jeacmqg8ww.fsf@sykes.suse.de> (from schwab@suse.de on Fri May 20 00:14:55 2005)


On 05.20, Andreas Schwab wrote:
> Ben Greear <greearb@candelatech.com> writes:
> 
> > Chris Friesen wrote:
> >> Ben Greear wrote:
> >> 
> >>> It can be helpful to know what HZ you are running at, for instance if
> >>> you care
> >>> very much about the (average) precision of a select/poll timeout.
> >> If you move the binary to a different system (or upgrade the kernel, for
> >> that matter) the assumptions can be totally wrong.
> >> This should be checked at runtime, not compile time.
> >
> > If course...that is why I like the idea of some system call or standard API
> > to get the information.
> 
> sysconf(3)
> 

Yup, I do it to start a thread per core.
Stupid and portable C++ code follows:

//! Node Information
__class Node {
private:
    static void init();
public:
    //! Node name
    static char name[MAXNAMLEN];
    //! Node model name
    static char model[MAXNAMLEN];
    //! Node hardware architecture
    static char arch[MAXNAMLEN];
    //! Node Operating Node name
    static char osname[MAXNAMLEN];
    //! Node Operating Node release
    static char osrel[MAXNAMLEN];
    //! Node memory
    static int  ram;
    //! Node number of available processors
    static int  nproc;
};

#ifdef __UNX__

# include <unistd.h>

# ifdef sgi
#  include <sys/systeminfo.h>
#  include <invent.h>
# endif

# ifdef __linux__
#  include <sys/sysinfo.h>                                   
# endif

# ifdef sun
#  include <sys/systeminfo.h>
# endif

# ifdef __hpux
extern "C" {
#  include <sys/mpctl.h>
}
# endif

#endif

int  Node::inited = 0;
char Node::name[MAXNAMLEN];
char Node::model[MAXNAMLEN];
char Node::arch[MAXNAMLEN];
char Node::osname[MAXNAMLEN];
char Node::osrel[MAXNAMLEN];
int	 Node::ram;
int	 Node::nproc;

void Node::init()
{
	if (inited) return;

	nproc = 1;
	ram = 0;

#if defined(__UNX__)
	struct utsname sys;
	uname(&sys);
	strcpy(name,sys.nodename);
	strcpy(model,sys.machine);
	strcpy(osname,sys.sysname);
	strcpy(osrel,sys.release);
# ifdef sgi
	sysinfo(SI_ARCHITECTURE,arch,MAXNAMLEN);
	nproc = sysconf(_SC_NPROC_ONLN);
	inventory_t* ip;
	while (ip=getinvent())
	{
		if ((ip->inv_class==INV_MEMORY) && (ip->inv_type==INV_MAIN))
			ram = ip->inv_state;
	}
	endinvent();
# endif
# ifdef sun
	sysinfo(SI_ARCHITECTURE,arch,MAXNAMLEN);
	nproc = sysconf(_SC_NPROCESSORS_ONLN);
	ram = sysconf(_SC_PAGESIZE)*sysconf(_SC_PHYS_PAGES);
# endif
# ifdef __linux__
	strcpy(arch,"x86");
	nproc = sysconf(_SC_NPROCESSORS_ONLN);
	if (!nproc) nproc = 1;
	ram = sysconf(_SC_PAGESIZE)*sysconf(_SC_PHYS_PAGES);
# endif
# ifdef __hpux
	strcpy(arch,"PA-RISC");
	nproc = mpctl(MPC_GETNUMSPUS,0,0);
	ram = 0; // TODO...
# endif

#elif defined(__WIN__)
	DWORD	len=MAXNAMLEN;
	GetComputerNameA(name,&len);
	strcpy(model,"Intel");
	SYSTEM_INFO	sys;
	GetSystemInfo(&sys);
	nproc = sys.dwNumberOfProcessors;
	sprintf(arch,"i%d86",sys.wProcessorLevel);
	MEMORYSTATUS minfo;
	GlobalMemoryStatus(&minfo);
	ram = minfo.dwTotalPhys;
	OSVERSIONINFO	osver;
	osver.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
	GetVersionEx(&osver);
	int relmaj = osver.dwMajorVersion;
	int relmin = osver.dwMinorVersion;
	switch(osver.dwPlatformId)
	{
		case VER_PLATFORM_WIN32s:
			strcpy(osname,"Win3.1");
			break;
		case VER_PLATFORM_WIN32_WINDOWS:
			sprintf(osname,"Win9%c",(relmin>0 ? '8' : '5'));
			break;
		case VER_PLATFORM_WIN32_NT:
			strcpy(osname,"WinNT");
			break;
		default:
			strcpy(osname,"Win??");
	}

	sprintf(osrel,"%d.%d (build %d) %s",
		relmaj,relmin,osver.dwBuildNumber,osver.szCSDVersion);

#else

	strcpy(name,"Unknown");
	strcpy(model,"Unknown");
	strcpy(arch,"Unknown");
	strcpy(osname,"Unknown");
	strcpy(osrel,"?.?");

#endif

	inited = 1;

	info();
}

--
J.A. Magallon <jamagallon()able!es>     \               Software is like sex:
werewolf!able!es                         \         It's better when it's free
Mandriva Linux release 2006.0 (Cooker) for i586
Linux 2.6.11-jam19 (gcc 4.0.0 (4.0.0-3mdk for Mandriva Linux release 2006.0))



  reply	other threads:[~2005-05-19 22:31 UTC|newest]

Thread overview: 60+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-05-18 19:07 Gilbert, John
2005-05-18 19:53 ` Adrian Bunk
2005-05-19  2:22   ` Kyle Moffett
2005-05-19 11:28     ` Adrian Bunk
2005-05-19 12:19       ` Richard B. Johnson
2005-05-19 12:27         ` Arjan van de Ven
2005-05-19 12:47           ` Maciej W. Rozycki
2005-05-19 13:01             ` Richard B. Johnson
2005-05-19 13:47               ` Steven Rostedt
2005-05-19 14:06               ` Andreas Schwab
2005-05-19 14:15                 ` Steven Rostedt
2005-05-19 14:36                   ` Richard B. Johnson
2005-05-19 15:19                     ` Andreas Schwab
2005-05-19 15:56                       ` Steven Rostedt
2005-05-19 16:03                         ` Richard B. Johnson
2005-05-19 15:58                       ` Richard B. Johnson
2005-05-19 16:22                         ` Steven Rostedt
2005-05-19 17:06                           ` Richard B. Johnson
2005-05-19 17:36                             ` Steven Rostedt
2005-05-19 14:43                   ` Maciej W. Rozycki
2005-05-19 14:59                     ` Steven Rostedt
2005-05-20 12:23                       ` Maciej W. Rozycki
2005-05-19 14:53                   ` Arjan van de Ven
2005-05-19 14:58                     ` Maciej W. Rozycki
2005-05-19 15:06                       ` Arjan van de Ven
2005-05-19 13:56           ` Steven Rostedt
2005-05-19 17:30           ` Ben Greear
2005-05-19 17:36             ` Chris Friesen
2005-05-19 17:40               ` Ben Greear
2005-05-19 22:14                 ` Andreas Schwab
2005-05-19 22:30                   ` J.A. Magallon [this message]
2005-05-19 22:41                     ` Russell King
2005-05-19 23:10                       ` J.A. Magallon
2005-05-20  0:01                         ` Jeff Woods
2005-05-20  9:27             ` Helge Hafting
2005-05-20 16:47               ` Lee Revell
2005-05-20 16:56                 ` Ben Greear
2005-05-18 23:42 ` Andi Kleen
2005-05-18 23:59   ` Adrian Bunk
  -- strict thread matches above, loose matches on Subject: below --
2005-05-20 17:30 Gilbert, John
2005-05-19 20:18 Gilbert, John
2005-05-19  1:51 Gilbert, John
2005-05-18 21:31 Gilbert, John
2005-05-19 17:37 ` Alan Cox
2005-05-20 11:49   ` Dave Airlie
2005-05-20 16:42     ` Alan Cox
2005-05-18 18:23 Gilbert, John
2005-05-18 19:02 ` Adrian Bunk
2005-05-18 19:32 ` Richard B. Johnson
2005-05-19  1:06 ` rdunlap
2005-05-18  0:51 Gilbert, John
2005-05-18  0:57 ` Lee Revell
2005-05-18  1:19 ` Chris Wedgwood
2005-05-18  2:51 ` Steven Rostedt
2005-05-18  4:12   ` Willy Tarreau
2005-05-18 10:06   ` Patrick McFarland
2005-05-18 10:49     ` Coywolf Qi Hunt
2005-05-18 11:12     ` Richard B. Johnson
2005-05-18 21:52       ` Matan Peled
2005-05-19 11:03         ` Richard B. Johnson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1116541832l.2940l.1l@werewolf.able.es \
    --to=jamagallon@able.es \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®