#include <stdio.h>
#include <libcpuid.h>
int main(void)
{
if (!cpuid_present()) { // check for CPUID presence
printf("Sorry, your CPU doesn't support CPUID!\n");
return -1;
}
struct cpu_raw_data_t raw;
struct cpu_id_t data; // contains recognized CPU features data
if (cpuid_get_raw_data(&raw) < 0) { // obtain the raw CPUID data
printf("Sorry, cannot get the CPUID raw data.\n");
printf("Error: %s\n", cpuid_error()); // cpuid_error() gives the last error description
return -2;
}
if (cpu_identify(&raw, &data) < 0) { // identify the CPU, using the given raw data.
printf("Sorrry, CPU identification failed.\n");
printf("Error: %s\n", cpuid_error());
return -3;
}
struct cpu_mark_t mark;
cpu_tsc_mark(&mark);
cpu_tsc_unmark(&mark);
printf("{\n");
printf(" \"VENDOR_STR\": \"%s\",\n", data.vendor_str); //
printf(" \"CPU_CODENAME\": \"%s\",\n", data.cpu_codename); //
printf(" \"BRAND_STR\": \"%s\",\n", data.brand_str); //
printf(" \"NUM_CORES\": \"%d\",\n", data.num_cores); //
printf(" \"NUM_LOGICAL_CPUS\": \"%d\",\n", data.num_logical_cpus); //
printf(" \"TOTAL_LOGICAL_CPUS\": \"%d\",\n", data.total_logical_cpus); //
printf(" \"FAMILY\": \"%d\",\n", data.family); //
printf(" \"MODEL\": \"%d\",\n", data.model); //
printf(" \"STEPPING\": \"%d\",\n", data.stepping); //
printf(" \"EXT_FAMILY\": \"%d\",\n", data.ext_family); //
printf(" \"EXT_MODEL\": \"%d\",\n", data.ext_model); //
printf(" \"CPU_CLOCK\": \"%d MHz\",\n", cpu_clock()); //
printf(" \"CPU_CLOCK_BY_OS\": \"%d MHz\",\n", cpu_clock_by_os()); //
printf(" \"CPU_CLOCK_BY_IC\": \"%d MHz\",\n", cpu_clock_by_ic(25, 16)); //
printf(" \"CPU_CLOCK_MEASURE\": \"%d MHz\",\n", cpu_clock_measure(400, 1));//
printf(" \"MARK_TSC\": \"%llu\",\n", mark.tsc); //
printf(" \"MARK_SYS_CLOCK\": \"%llu\",\n", mark.sys_clock); //
It seems that in order to initiate the data is sufficient to initiate: cpu_identify() and cpuid_get_raw_data()