mirror of
https://github.com/anrieff/libcpuid
synced 2025-07-02 14:04:15 +00:00
cpuid_tool: Added --clock-os key to enable queries to cpu_clock_by_os()
rdtsc.c: Ported CPU clocking code to Win32, debugged Registry stuff git-svn-id: https://svn.code.sf.net/p/libcpuid/code/HEAD/libcpuid@30 3b4be424-7ac5-41d7-8526-f4ddcb85d872
This commit is contained in:
parent
9cf8005f3a
commit
2fb7b0522b
2 changed files with 16 additions and 14 deletions
|
@ -81,6 +81,7 @@ typedef enum {
|
||||||
NEED_CODENAME,
|
NEED_CODENAME,
|
||||||
NEED_FEATURES,
|
NEED_FEATURES,
|
||||||
NEED_CLOCK,
|
NEED_CLOCK,
|
||||||
|
NEED_CLOCK_OS,
|
||||||
NEED_CLOCK_RDTSC,
|
NEED_CLOCK_RDTSC,
|
||||||
} output_data_switch;
|
} output_data_switch;
|
||||||
|
|
||||||
|
@ -128,6 +129,7 @@ matchtable[] = {
|
||||||
{ NEED_CODENAME , "--codename" , 1},
|
{ NEED_CODENAME , "--codename" , 1},
|
||||||
{ NEED_FEATURES , "--flags" , 1},
|
{ NEED_FEATURES , "--flags" , 1},
|
||||||
{ NEED_CLOCK , "--clock" , 0},
|
{ NEED_CLOCK , "--clock" , 0},
|
||||||
|
{ NEED_CLOCK_OS , "--clock-os" , 0},
|
||||||
{ NEED_CLOCK_RDTSC , "--clock-rdtsc" , 1},
|
{ NEED_CLOCK_RDTSC , "--clock-rdtsc" , 1},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -378,6 +380,9 @@ static void print_info(output_data_switch query, struct cpu_raw_data_t* raw,
|
||||||
case NEED_CLOCK:
|
case NEED_CLOCK:
|
||||||
fprintf(fout, "%d\n", cpu_clock());
|
fprintf(fout, "%d\n", cpu_clock());
|
||||||
break;
|
break;
|
||||||
|
case NEED_CLOCK_OS:
|
||||||
|
fprintf(fout, "%d\n", cpu_clock_by_os());
|
||||||
|
break;
|
||||||
case NEED_CLOCK_RDTSC:
|
case NEED_CLOCK_RDTSC:
|
||||||
fprintf(fout, "%d\n", cpu_clock_measure(400, 1));
|
fprintf(fout, "%d\n", cpu_clock_measure(400, 1));
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -31,12 +31,13 @@
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
static void sys_precise_clock(uint64_t *result)
|
static void sys_precise_clock(uint64_t *result)
|
||||||
{
|
{
|
||||||
|
double c, f;
|
||||||
LARGE_INTEGER freq, counter;
|
LARGE_INTEGER freq, counter;
|
||||||
QueryPerformanceCounter(&counter);
|
QueryPerformanceCounter(&counter);
|
||||||
QueryPerformanceFrequency(&freq);
|
QueryPerformanceFrequency(&freq);
|
||||||
double c = counter.QuadPart;
|
c = (double) counter.QuadPart;
|
||||||
double f = freq.QuadPart;
|
f = (double) freq.QuadPart;
|
||||||
result = (uint64_t) ( c * 1000000.0 / f );
|
*result = (uint64_t) ( c * 1000000.0 / f );
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
/* assuming Linux, Mac OS or other POSIX */
|
/* assuming Linux, Mac OS or other POSIX */
|
||||||
|
@ -91,23 +92,19 @@ int cpu_clock_by_mark(struct cpu_mark_t* mark)
|
||||||
int cpu_clock_by_os(void)
|
int cpu_clock_by_os(void)
|
||||||
{
|
{
|
||||||
HKEY key;
|
HKEY key;
|
||||||
char buff[20];
|
DWORD result;
|
||||||
DWORD size = 20;
|
DWORD size = 4;
|
||||||
int result;
|
|
||||||
|
|
||||||
if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, "HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\0\\~MHz", 0, KEY_READ, &key) != ERROR_SUCCESS)
|
if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, TEXT("HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\0"), 0, KEY_READ, &key) != ERROR_SUCCESS)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
if (RegQueryValueEx(key, "~MHz", NULL, NULL, (LPBYTE) buff, (LPDWORD) &size) != ERROR_SUCCESS) {
|
if (RegQueryValueEx(key, TEXT("~MHz"), NULL, NULL, (LPBYTE) &result, (LPDWORD) &size) != ERROR_SUCCESS) {
|
||||||
RegCloseKey(key);
|
RegCloseKey(key);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
buff[size] = 0;
|
|
||||||
RegCloseKey(key);
|
RegCloseKey(key);
|
||||||
|
|
||||||
if (1 != sscanf(buff, "%d", &result))
|
return (int)result;
|
||||||
return -1;
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
/* Assuming Linux with /proc/cpuinfo */
|
/* Assuming Linux with /proc/cpuinfo */
|
||||||
|
@ -175,7 +172,7 @@ int cpu_clock_measure(int millis, int quad_check)
|
||||||
mark_t_subtract(&end[k], &begin[k], &temp);
|
mark_t_subtract(&end[k], &begin[k], &temp);
|
||||||
results[k] = cpu_clock_by_mark(&temp);
|
results[k] = cpu_clock_by_mark(&temp);
|
||||||
}
|
}
|
||||||
if (n == 1) return results[k];
|
if (n == 1) return results[0];
|
||||||
mdiff = 0x7fffffff;
|
mdiff = 0x7fffffff;
|
||||||
bi = bj = -1;
|
bi = bj = -1;
|
||||||
for (i = 0; i < 4; i++) {
|
for (i = 0; i < 4; i++) {
|
||||||
|
@ -198,6 +195,6 @@ int cpu_clock(void)
|
||||||
int result;
|
int result;
|
||||||
result = cpu_clock_by_os();
|
result = cpu_clock_by_os();
|
||||||
if (result <= 0)
|
if (result <= 0)
|
||||||
result = cpu_clock_measure(200, 1);
|
result = cpu_clock_measure(200, 0);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue