Author: weiden Date: Thu Jan 10 08:18:53 2008 New Revision: 31693
URL: http://svn.reactos.org/svn/reactos?rev=31693&view=rev Log: Add the ability to determine the cpu count based on the inherited process affinity mask (only for win32 hosts)
Modified: trunk/tools/RosBE/Tools/cpucount.c
Modified: trunk/tools/RosBE/Tools/cpucount.c URL: http://svn.reactos.org/svn/reactos/trunk/tools/RosBE/Tools/cpucount.c?rev=31... ============================================================================== --- trunk/tools/RosBE/Tools/cpucount.c (original) +++ trunk/tools/RosBE/Tools/cpucount.c Thu Jan 10 08:18:53 2008 @@ -24,17 +24,41 @@ { int cpuCount = 0;
+#if defined(WIN32) + if(argc > 3) +#else if(argc > 2) +#endif { fprintf(stderr, "%s: Error too many parameters specified.\n", argv[0]); return -1; }
#if defined(WIN32) - SYSTEM_INFO SystemInformation; + if (argc != 1 && !strncmp(argv[argc - 1], "-a", 2)) + { + DWORD_PTR ProcessAffinityMask, SystemAffinityMask;
- GetSystemInfo(&SystemInformation); - cpuCount = SystemInformation.dwNumberOfProcessors; + if (GetProcessAffinityMask(GetCurrentProcess(), &ProcessAffinityMask, &SystemAffinityMask)) + { + while (ProcessAffinityMask != 0) + { + if (ProcessAffinityMask & 0x1) + cpuCount++; + + ProcessAffinityMask >>= 1; + } + } + + argc--; /* don't look at this argument again */ + } + else + { + SYSTEM_INFO SystemInformation; + + GetSystemInfo(&SystemInformation); + cpuCount = SystemInformation.dwNumberOfProcessors; + } #elif defined(__APPLE__) size_t countSize = sizeof(cpuCount);
@@ -43,7 +67,7 @@ cpuCount = sysconf(_SC_NPROCESSORS_ONLN); #endif
- if(argc != 1) + if (argc != 1) { if(!strncmp(argv[1], "-x1", 3)) { @@ -55,11 +79,18 @@ } else { - printf("Usage: %s [OPTIONS]\n", argv[0]); +#if defined(WIN32) + printf("Usage: %s [-x1|-x2] [-a]\n", argv[0]); +#else + printf("Usage: %s [-x1|-x2]\n", argv[0]); +#endif printf("Running cpucount without options returns the number of\n"); printf("processors in the system.\n"); printf("-x1 - Number of processors in the system, plus 1.\n"); printf("-x2 - Number of processors in the system, doubled.\n"); +#if defined(WIN32) + printf("-a - Use the affinity mask to determine number of processors\n"); +#endif return 0; } }