[PATCH 6/8] ntdll: Standardize on sysconf to detect the number of processors for all platforms.
James Eder
jimportal at gmail.com
Sat Oct 20 19:40:48 CDT 2012
---
dlls/ntdll/nt.c | 58 ++++++++++-----------------------------------------------
1 file changed, 10 insertions(+), 48 deletions(-)
diff --git a/dlls/ntdll/nt.c b/dlls/ntdll/nt.c
index 68c451f..fe450c1 100644
--- a/dlls/ntdll/nt.c
+++ b/dlls/ntdll/nt.c
@@ -1010,6 +1010,16 @@ static inline void get_cpuinfo(SYSTEM_CPU_INFORMATION* info)
*/
void fill_cpu_info(void)
{
+ long num;
+
+ num = sysconf(_SC_NPROCESSORS_ONLN);
+ if (num < 1)
+ {
+ num = 1;
+ WARN("Failed to detect the number of processors.\n");
+ }
+ NtCurrentTeb()->Peb->NumberOfProcessors = num;
+
memset(&cached_sci, 0, sizeof(cached_sci));
/* choose sensible defaults ...
* FIXME: perhaps overridable with precompiler flags?
@@ -1032,8 +1042,6 @@ void fill_cpu_info(void)
cached_sci.Reserved = 0;
cached_sci.FeatureSet = 0x1fff;
- NtCurrentTeb()->Peb->NumberOfProcessors = 1;
-
/* Hmm, reasonable processor feature defaults? */
#ifdef linux
@@ -1062,17 +1070,6 @@ void fill_cpu_info(void)
if ((s = strchr(value,'\n')))
*s='\0';
- if (!strcasecmp(line, "processor"))
- {
- /* processor number counts up... */
- unsigned int x;
-
- if (sscanf(value, "%d",&x))
- if (x + 1 > NtCurrentTeb()->Peb->NumberOfProcessors)
- NtCurrentTeb()->Peb->NumberOfProcessors = x + 1;
-
- continue;
- }
if (!strcasecmp(line, "model"))
{
/* First part of Revision */
@@ -1204,11 +1201,6 @@ void fill_cpu_info(void)
if (value) user_shared_data->ProcessorFeatures[PF_MMX_INSTRUCTIONS_AVAILABLE] = TRUE;
#endif
mib[0] = CTL_HW;
- mib[1] = HW_NCPU;
- val_len = sizeof(value);
- if (sysctl(mib, 2, &value, &val_len, NULL, 0) >= 0)
- if (value > NtCurrentTeb()->Peb->NumberOfProcessors)
- NtCurrentTeb()->Peb->NumberOfProcessors = value;
mib[1] = HW_MODEL;
val_len = sizeof(model)-1;
if (sysctl(mib, 2, model, &val_len, NULL, 0) >= 0)
@@ -1268,9 +1260,6 @@ void fill_cpu_info(void)
}
#elif defined(__FreeBSD__) || defined (__FreeBSD_kernel__) || defined(__DragonFly__)
{
- int ret, num;
- size_t len;
-
get_cpuinfo( &cached_sci );
/* Check for OS support of SSE -- Is this used, and should it be sse1 or sse2? */
@@ -1278,32 +1267,10 @@ void fill_cpu_info(void)
ret = sysctlbyname("hw.instruction_sse", &num, &len, NULL, 0);
if (!ret)
user_shared_data->ProcessorFeatures[PF_XMMI_INSTRUCTIONS_AVAILABLE] = num;*/
-
- len = sizeof(num);
- ret = sysctlbyname("hw.ncpu", &num, &len, NULL, 0);
- if (!ret)
- NtCurrentTeb()->Peb->NumberOfProcessors = num;
}
#elif defined(__sun)
{
- int num = sysconf( _SC_NPROCESSORS_ONLN );
-
- if (num == -1) num = 1;
get_cpuinfo( &cached_sci );
- NtCurrentTeb()->Peb->NumberOfProcessors = num;
- }
-#elif defined (__OpenBSD__)
- {
- int mib[2], num, ret;
- size_t len;
-
- mib[0] = CTL_HW;
- mib[1] = HW_NCPU;
- len = sizeof(num);
-
- ret = sysctl(mib, 2, &num, &len, NULL, 0);
- if (!ret)
- NtCurrentTeb()->Peb->NumberOfProcessors = num;
}
#elif defined (__APPLE__)
{
@@ -1320,11 +1287,6 @@ void fill_cpu_info(void)
else
user_shared_data->ProcessorFeatures[PF_FLOATING_POINT_EMULATED] = TRUE;
}
- valSize = sizeof(int);
- if (sysctlbyname ("hw.ncpu", &value, &valSize, NULL, 0) == 0)
- NtCurrentTeb()->Peb->NumberOfProcessors = value;
-
- /* FIXME: we don't use the "hw.activecpu" value... but the cached one */
valSize = sizeof(int);
if (sysctlbyname ("hw.cputype", &cputype, &valSize, NULL, 0) == 0)
--
1.7.12.4
More information about the wine-patches
mailing list