mirror of
https://github.com/anrieff/libcpuid
synced 2025-01-23 20:06:41 +00:00
Improve msr_serialize_raw_data function
- Use cached CPUID - Cache CPU clock - Make all output fields parsable
This commit is contained in:
parent
967f3ab80d
commit
951c42be82
1 changed files with 22 additions and 14 deletions
|
@ -1026,30 +1026,37 @@ int msr_serialize_raw_data(struct msr_driver_t* handle, const char* filename)
|
||||||
FILE *f;
|
FILE *f;
|
||||||
uint64_t reg;
|
uint64_t reg;
|
||||||
const uint32_t *msr;
|
const uint32_t *msr;
|
||||||
struct cpu_raw_data_t raw;
|
struct cpu_id_t* id;
|
||||||
struct cpu_id_t id;
|
static int cpu_clock = 0;
|
||||||
struct internal_id_info_t internal;
|
|
||||||
|
|
||||||
|
/* Check if MSR driver is initialized */
|
||||||
if (handle == NULL)
|
if (handle == NULL)
|
||||||
return set_error(ERR_HANDLE);
|
return set_error(ERR_HANDLE);
|
||||||
|
|
||||||
if ((filename == NULL) || !strcmp(filename, ""))
|
/* Open file descriptor */
|
||||||
f = stdout;
|
f = ((filename == NULL) || !strcmp(filename, "")) ? stdout : fopen(filename, "wt");
|
||||||
else
|
if (!f)
|
||||||
f = fopen(filename, "wt");
|
return set_error(ERR_OPEN);
|
||||||
if (!f) return set_error(ERR_OPEN);
|
|
||||||
|
/* Get cached decoded CPUID information */
|
||||||
|
id = get_cached_cpuid();
|
||||||
|
if (id->vendor == VENDOR_UNKNOWN)
|
||||||
|
return get_error();
|
||||||
|
|
||||||
if (cpuid_get_raw_data(&raw) || cpu_ident_internal(&raw, &id, &internal))
|
/* Get CPU stock speed */
|
||||||
return -1;
|
if (cpu_clock == 0)
|
||||||
|
cpu_clock = cpu_clock_measure(250, 1);
|
||||||
|
|
||||||
fprintf(f, "CPU is %s %s, stock clock is %dMHz.\n", id.vendor_str, id.brand_str, cpu_clock_measure(250, 1));
|
/* Check if CPU vendor is supported */
|
||||||
switch (id.vendor) {
|
fprintf(f, "vendor_str=%s\nbrand_str=%s\ncpu_clock_measure=%dMHz\n", id->vendor_str, id->brand_str, cpu_clock);
|
||||||
|
switch (id->vendor) {
|
||||||
case VENDOR_HYGON:
|
case VENDOR_HYGON:
|
||||||
case VENDOR_AMD: msr = amd_msr; break;
|
case VENDOR_AMD: msr = amd_msr; break;
|
||||||
case VENDOR_INTEL: msr = intel_msr; break;
|
case VENDOR_INTEL: msr = intel_msr; break;
|
||||||
default: return set_error(ERR_CPU_UNKN);
|
default: return set_error(ERR_CPU_UNKN);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Print raw MSR values */
|
||||||
for (i = 0; msr[i] != CPU_INVALID_VALUE; i++) {
|
for (i = 0; msr[i] != CPU_INVALID_VALUE; i++) {
|
||||||
cpu_rdmsr(handle, msr[i], ®);
|
cpu_rdmsr(handle, msr[i], ®);
|
||||||
fprintf(f, "msr[%#08x]=", msr[i]);
|
fprintf(f, "msr[%#08x]=", msr[i]);
|
||||||
|
@ -1058,7 +1065,8 @@ int msr_serialize_raw_data(struct msr_driver_t* handle, const char* filename)
|
||||||
fprintf(f, "\n");
|
fprintf(f, "\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((filename != NULL) && strcmp(filename, ""))
|
/* Close file descriptor */
|
||||||
|
if (f != stdout)
|
||||||
fclose(f);
|
fclose(f);
|
||||||
return set_error(ERR_OK);
|
return set_error(ERR_OK);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue