* fhandler_proc.cc (read_value): Remove definition.

(print): Simplify.
	(format_proc_cpuinfo): Drop useless call to GetSystemInfo.  Rearrange
	to use Rtl registry functions.  Rename dwOldThreadAffinityMask to
	orig_affinity_mask.
This commit is contained in:
Corinna Vinschen 2011-04-19 08:39:38 +00:00
parent 060e5c9785
commit f5ab5b84de
2 changed files with 57 additions and 58 deletions

View File

@ -1,3 +1,11 @@
2011-04-19 Corinna Vinschen <corinna@vinschen.de>
* fhandler_proc.cc (read_value): Remove definition.
(print): Simplify.
(format_proc_cpuinfo): Drop useless call to GetSystemInfo. Rearrange
to use Rtl registry functions. Rename dwOldThreadAffinityMask to
orig_affinity_mask.
2011-04-18 Corinna Vinschen <corinna@vinschen.de> 2011-04-18 Corinna Vinschen <corinna@vinschen.de>
* localtime.cc (tzload): Don't change global timezone information * localtime.cc (tzload): Don't change global timezone information

View File

@ -605,41 +605,19 @@ format_proc_stat (void *, char *&destbuf)
return eobuf - buf; return eobuf - buf;
} }
#define read_value(x,y) \ #define print(x) { bufptr = stpcpy (bufptr, (x)); }
do {\
dwCount = BUFSIZE; \
if ((dwError = RegQueryValueEx (hKey, x, NULL, &dwType, in_buf.b, &dwCount)), \
(dwError != ERROR_SUCCESS && dwError != ERROR_MORE_DATA)) \
{ \
debug_printf ("RegQueryValueEx failed retcode %d", dwError); \
return 0; \
} \
if (dwType != y) \
{ \
debug_printf ("Value %s had an unexpected type (expected %d, found %d)", y, dwType); \
return 0; \
}\
} while (0)
#define print(x) \
do { \
strcpy (bufptr, x), \
bufptr += sizeof (x) - 1; \
} while (0)
static _off64_t static _off64_t
format_proc_cpuinfo (void *, char *&destbuf) format_proc_cpuinfo (void *, char *&destbuf)
{ {
SYSTEM_INFO siSystemInfo; DWORD orig_affinity_mask;
HKEY hKey;
DWORD dwError, dwCount, dwType;
DWORD dwOldThreadAffinityMask;
int cpu_number; int cpu_number;
const int BUFSIZE = 256; const int BUFSIZE = 256;
union union
{ {
BYTE b[BUFSIZE]; BYTE b[BUFSIZE];
char s[BUFSIZE]; char s[BUFSIZE];
WCHAR w[BUFSIZE / sizeof (WCHAR)];
DWORD d; DWORD d;
unsigned m[13]; unsigned m[13];
} in_buf; } in_buf;
@ -648,27 +626,23 @@ format_proc_cpuinfo (void *, char *&destbuf)
char *buf = tp.c_get (); char *buf = tp.c_get ();
char *bufptr = buf; char *bufptr = buf;
GetSystemInfo (&siSystemInfo);
for (cpu_number = 0; ; cpu_number++) for (cpu_number = 0; ; cpu_number++)
{ {
WCHAR cpu_key[128];
__small_swprintf (cpu_key, L"\\Registry\\Machine\\HARDWARE\\DESCRIPTION"
"\\System\\CentralProcessor\\%d", cpu_number);
if (!NT_SUCCESS (RtlCheckRegistryKey (RTL_REGISTRY_ABSOLUTE, cpu_key)))
break;
if (cpu_number) if (cpu_number)
print ("\n"); print ("\n");
__small_sprintf (in_buf.s, "HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\%d", cpu_number); orig_affinity_mask = SetThreadAffinityMask (GetCurrentThread (),
1 << cpu_number);
if ((dwError = RegOpenKeyEx (HKEY_LOCAL_MACHINE, in_buf.s, 0, KEY_QUERY_VALUE, &hKey)) != ERROR_SUCCESS) if (orig_affinity_mask == 0)
{
if (dwError == ERROR_FILE_NOT_FOUND)
break;
debug_printf ("RegOpenKeyEx failed retcode %d", dwError);
return 0;
}
dwOldThreadAffinityMask = SetThreadAffinityMask (GetCurrentThread (), 1 << cpu_number);
if (dwOldThreadAffinityMask == 0)
debug_printf ("SetThreadAffinityMask failed %E"); debug_printf ("SetThreadAffinityMask failed %E");
// I'm not sure whether the thread changes processor immediately /* I'm not sure whether the thread changes processor immediately
// and I'm not sure whether this function will cause the thread to be rescheduled and I'm not sure whether this function will cause the thread
to be rescheduled */
yield (); yield ();
bool has_cpuid = false; bool has_cpuid = false;
@ -687,17 +661,31 @@ format_proc_cpuinfo (void *, char *&destbuf)
debug_printf ("processor does not support CPUID instruction"); debug_printf ("processor does not support CPUID instruction");
} }
if (!has_cpuid) if (!has_cpuid)
{ {
bufptr += __small_sprintf (bufptr, "processor : %d\n", cpu_number); WCHAR vendor[64], id[64];
read_value ("VendorIdentifier", REG_SZ); UNICODE_STRING uvendor, uid;
bufptr += __small_sprintf (bufptr, "vendor_id : %s\n", in_buf.s); RtlInitEmptyUnicodeString (&uvendor, vendor, sizeof (vendor));
read_value ("Identifier", REG_SZ); RtlInitEmptyUnicodeString (&uid, id, sizeof (id));
bufptr += __small_sprintf (bufptr, "identifier : %s\n", in_buf.s); DWORD cpu_mhz = 0;
read_value ("~Mhz", REG_DWORD); RTL_QUERY_REGISTRY_TABLE tab[4] = {
bufptr += __small_sprintf (bufptr, "cpu MHz : %u\n", in_buf.d); { NULL, RTL_QUERY_REGISTRY_NOEXPAND | RTL_QUERY_REGISTRY_DIRECT,
L"VendorIdentifier", &uvendor, REG_NONE, NULL, 0 },
{ NULL, RTL_QUERY_REGISTRY_NOEXPAND | RTL_QUERY_REGISTRY_DIRECT,
L"Identifier", &uid, REG_NONE, NULL, 0 },
{ NULL, RTL_QUERY_REGISTRY_DIRECT | RTL_QUERY_REGISTRY_NOSTRING,
L"~Mhz", &cpu_mhz, REG_NONE, NULL, 0 },
{ NULL, 0, NULL, NULL, 0, NULL, 0 }
};
RtlQueryRegistryValues (RTL_REGISTRY_ABSOLUTE, cpu_key, tab,
NULL, NULL);
bufptr += __small_sprintf (bufptr,
"processor : %d\n"
"vendor_id : %S\n"
"identifier : %S\n"
"cpu MHz : %u\n",
cpu_number, &uvendor, &uid, cpu_mhz);
print ("flags :"); print ("flags :");
if (IsProcessorFeaturePresent (PF_3DNOW_INSTRUCTIONS_AVAILABLE)) if (IsProcessorFeaturePresent (PF_3DNOW_INSTRUCTIONS_AVAILABLE))
print (" 3dnow"); print (" 3dnow");
@ -718,6 +706,15 @@ format_proc_cpuinfo (void *, char *&destbuf)
} }
else else
{ {
DWORD cpu_mhz = 0;
RTL_QUERY_REGISTRY_TABLE tab[2] = {
{ NULL, RTL_QUERY_REGISTRY_DIRECT | RTL_QUERY_REGISTRY_NOSTRING,
L"~Mhz", &cpu_mhz, REG_NONE, NULL, 0 },
{ NULL, 0, NULL, NULL, 0, NULL, 0 }
};
RtlQueryRegistryValues (RTL_REGISTRY_ABSOLUTE, cpu_key, tab,
NULL, NULL);
bufptr += __small_sprintf (bufptr, "processor\t: %d\n", cpu_number); bufptr += __small_sprintf (bufptr, "processor\t: %d\n", cpu_number);
unsigned maxf, vendor_id[4], unused; unsigned maxf, vendor_id[4], unused;
cpuid (&maxf, &vendor_id[0], &vendor_id[2], &vendor_id[1], 0); cpuid (&maxf, &vendor_id[0], &vendor_id[2], &vendor_id[1], 0);
@ -733,8 +730,6 @@ format_proc_cpuinfo (void *, char *&destbuf)
bufptr += __small_sprintf (bufptr, "vendor_id\t: %s\n", bufptr += __small_sprintf (bufptr, "vendor_id\t: %s\n",
(char *)vendor_id); (char *)vendor_id);
read_value ("~Mhz", REG_DWORD);
unsigned cpu_mhz = in_buf.d;
if (maxf >= 1) if (maxf >= 1)
{ {
unsigned features2, features1, extra_info, cpuid_sig; unsigned features2, features1, extra_info, cpuid_sig;
@ -1092,20 +1087,16 @@ format_proc_cpuinfo (void *, char *&destbuf)
IsProcessorFeaturePresent (PF_FLOATING_POINT_EMULATED) ? "no" : "yes"); IsProcessorFeaturePresent (PF_FLOATING_POINT_EMULATED) ? "no" : "yes");
} }
} }
if (dwOldThreadAffinityMask != 0) if (orig_affinity_mask != 0)
SetThreadAffinityMask (GetCurrentThread (), dwOldThreadAffinityMask); SetThreadAffinityMask (GetCurrentThread (), orig_affinity_mask);
print ("\n");
RegCloseKey (hKey); }
bufptr += __small_sprintf (bufptr, "\n");
}
destbuf = (char *) crealloc_abort (destbuf, bufptr - buf); destbuf = (char *) crealloc_abort (destbuf, bufptr - buf);
memcpy (destbuf, buf, bufptr - buf); memcpy (destbuf, buf, bufptr - buf);
return bufptr - buf; return bufptr - buf;
} }
#undef read_value
static _off64_t static _off64_t
format_proc_partitions (void *, char *&destbuf) format_proc_partitions (void *, char *&destbuf)
{ {