1
0
Fork 0
mirror of https://github.com/anrieff/libcpuid synced 2024-12-16 16:35:45 +00:00

Use cpu_id_t in cpu_msrinfo()

It can be useful to have more informations on CPU
This commit is contained in:
Xorg 2016-06-04 13:16:41 +02:00
parent 5467504680
commit 1ef4615d8f

View file

@ -486,7 +486,8 @@ static int perfmsr_measure(struct msr_driver_t* handle, int msr)
return (int) ((y - x) / (b - a)); return (int) ((y - x) / (b - a));
} }
static double get_info_cur_multiplier(struct msr_driver_t* handle, struct internal_id_info_t *internal) static double get_info_cur_multiplier(struct msr_driver_t* handle, struct cpu_id_t *id,
struct internal_id_info_t *internal)
{ {
int err, cur_clock; int err, cur_clock;
uint64_t r; uint64_t r;
@ -507,7 +508,8 @@ static double get_info_cur_multiplier(struct msr_driver_t* handle, struct intern
return (r>>22) & 0x1f; return (r>>22) & 0x1f;
} }
static double get_info_max_multiplier(struct msr_driver_t* handle, struct internal_id_info_t *internal) static double get_info_max_multiplier(struct msr_driver_t* handle, struct cpu_id_t *id,
struct internal_id_info_t *internal)
{ {
#define PLATFORM_INFO_MSR 206 #define PLATFORM_INFO_MSR 206
#define PLATFORM_INFO_MSR_low 8 #define PLATFORM_INFO_MSR_low 8
@ -530,7 +532,8 @@ static double get_info_max_multiplier(struct msr_driver_t* handle, struct intern
return (r >> 40) & 0x1f; return (r >> 40) & 0x1f;
} }
static int get_info_temperature(struct msr_driver_t* handle, struct internal_id_info_t *internal) static int get_info_temperature(struct msr_driver_t* handle, struct cpu_id_t *id,
struct internal_id_info_t *internal)
{ {
#define IA32_THERM_STATUS 0x19C #define IA32_THERM_STATUS 0x19C
#define IA32_TEMPERATURE_TARGET 0x1a2 #define IA32_TEMPERATURE_TARGET 0x1a2
@ -550,7 +553,8 @@ static int get_info_temperature(struct msr_driver_t* handle, struct internal_id_
return CPU_INVALID_VALUE; return CPU_INVALID_VALUE;
} }
static double get_info_voltage(struct msr_driver_t* handle, struct internal_id_info_t *internal) static double get_info_voltage(struct msr_driver_t* handle, struct cpu_id_t *id,
struct internal_id_info_t *internal)
{ {
#define MSR_PERF_STATUS 0x198 #define MSR_PERF_STATUS 0x198
#define MSR_PSTATE_S 0xC0010063 #define MSR_PSTATE_S 0xC0010063
@ -577,7 +581,8 @@ static double get_info_voltage(struct msr_driver_t* handle, struct internal_id_i
return CPU_INVALID_VALUE; return CPU_INVALID_VALUE;
} }
static double get_info_bclk(struct msr_driver_t* handle, struct internal_id_info_t *internal) static double get_info_bclk(struct msr_driver_t* handle, struct cpu_id_t *id,
struct internal_id_info_t *internal)
{ {
static int max_clock = 0, multiplier = 0; static int max_clock = 0, multiplier = 0;
@ -619,33 +624,34 @@ int cpu_rdmsr_range(struct msr_driver_t* handle, uint32_t msr_index, uint8_t hig
int cpu_msrinfo(struct msr_driver_t* handle, cpu_msrinfo_request_t which) int cpu_msrinfo(struct msr_driver_t* handle, cpu_msrinfo_request_t which)
{ {
struct cpu_raw_data_t raw; struct cpu_raw_data_t raw;
struct cpu_id_t id; static struct cpu_id_t id;
static struct internal_id_info_t internal = { .score = -1 }; static struct internal_id_info_t internal = { .score = -1 };
if(internal.score == -1) { if (handle == NULL)
return set_error(ERR_HANDLE);
if (internal.score == -1) {
cpuid_get_raw_data(&raw); cpuid_get_raw_data(&raw);
cpu_ident_internal(&raw, &id, &internal); cpu_ident_internal(&raw, &id, &internal);
} }
if (handle == NULL)
return set_error(ERR_HANDLE);
switch (which) { switch (which) {
case INFO_MPERF: case INFO_MPERF:
return perfmsr_measure(handle, 0xe7); return perfmsr_measure(handle, 0xe7);
case INFO_APERF: case INFO_APERF:
return perfmsr_measure(handle, 0xe8); return perfmsr_measure(handle, 0xe8);
case INFO_CUR_MULTIPLIER: case INFO_CUR_MULTIPLIER:
return (int) get_info_cur_multiplier(handle, &internal) * 100; return (int) get_info_cur_multiplier(handle, &id, &internal) * 100;
case INFO_MAX_MULTIPLIER: case INFO_MAX_MULTIPLIER:
return (int) get_info_max_multiplier(handle, &internal) * 100; return (int) get_info_max_multiplier(handle, &id, &internal) * 100;
case INFO_TEMPERATURE: case INFO_TEMPERATURE:
return get_info_temperature(handle, &internal); return get_info_temperature(handle, &id, &internal);
case INFO_THROTTLING: case INFO_THROTTLING:
return CPU_INVALID_VALUE; return CPU_INVALID_VALUE;
case INFO_VOLTAGE: case INFO_VOLTAGE:
return (int) get_info_voltage(handle, &internal) * 100; return (int) get_info_voltage(handle, &id, &internal) * 100;
case INFO_BCLK: case INFO_BCLK:
return (int) get_info_bclk(handle, &internal) * 100; return (int) get_info_bclk(handle, &id, &internal) * 100;
default: default:
return CPU_INVALID_VALUE; return CPU_INVALID_VALUE;
} }