lkml.org 
[lkml]   [2005]   [May]   [19]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
    /
    Date
    From
    SubjectRe: Illegal use of reserved word in system.h

    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))


    -
    To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
    the body of a message to majordomo@vger.kernel.org
    More majordomo info at http://vger.kernel.org/majordomo-info.html
    Please read the FAQ at http://www.tux.org/lkml/

    \
     
     \ /
      Last update: 2005-05-20 00:34    [W:0.033 / U:89.328 seconds]
    ©2003-2016 Jasper Spaans. hosted at Digital OceanAdvertise on this site