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

Use cpu_ident_internal() in cpu_msrinfo()

This commit is contained in:
Xorg 2016-06-03 15:58:45 +02:00
parent 93cdd0de75
commit 5467504680

View file

@ -29,6 +29,7 @@
#include "libcpuid.h"
#include "asm-bits.h"
#include "libcpuid_util.h"
#include "libcpuid_internal.h"
#include "rdtsc.h"
#if defined (__linux__) || defined (__gnu_linux__)
@ -485,7 +486,7 @@ static int perfmsr_measure(struct msr_driver_t* handle, int msr)
return (int) ((y - x) / (b - a));
}
static double get_info_cur_multiplier(struct msr_driver_t* handle)
static double get_info_cur_multiplier(struct msr_driver_t* handle, struct internal_id_info_t *internal)
{
int err, cur_clock;
uint64_t r;
@ -506,7 +507,7 @@ static double get_info_cur_multiplier(struct msr_driver_t* handle)
return (r>>22) & 0x1f;
}
static double get_info_max_multiplier(struct msr_driver_t* handle)
static double get_info_max_multiplier(struct msr_driver_t* handle, struct internal_id_info_t *internal)
{
#define PLATFORM_INFO_MSR 206
#define PLATFORM_INFO_MSR_low 8
@ -529,7 +530,7 @@ static double get_info_max_multiplier(struct msr_driver_t* handle)
return (r >> 40) & 0x1f;
}
static int get_info_temperature(struct msr_driver_t* handle)
static int get_info_temperature(struct msr_driver_t* handle, struct internal_id_info_t *internal)
{
#define IA32_THERM_STATUS 0x19C
#define IA32_TEMPERATURE_TARGET 0x1a2
@ -549,7 +550,7 @@ static int get_info_temperature(struct msr_driver_t* handle)
return CPU_INVALID_VALUE;
}
static double get_info_voltage(struct msr_driver_t* handle)
static double get_info_voltage(struct msr_driver_t* handle, struct internal_id_info_t *internal)
{
#define MSR_PERF_STATUS 0x198
#define MSR_PSTATE_S 0xC0010063
@ -576,7 +577,7 @@ static double get_info_voltage(struct msr_driver_t* handle)
return CPU_INVALID_VALUE;
}
static double get_info_bclk(struct msr_driver_t* handle)
static double get_info_bclk(struct msr_driver_t* handle, struct internal_id_info_t *internal)
{
static int max_clock = 0, multiplier = 0;
@ -617,6 +618,15 @@ 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)
{
struct cpu_raw_data_t raw;
struct cpu_id_t id;
static struct internal_id_info_t internal = { .score = -1 };
if(internal.score == -1) {
cpuid_get_raw_data(&raw);
cpu_ident_internal(&raw, &id, &internal);
}
if (handle == NULL)
return set_error(ERR_HANDLE);
switch (which) {
@ -625,17 +635,17 @@ int cpu_msrinfo(struct msr_driver_t* handle, cpu_msrinfo_request_t which)
case INFO_APERF:
return perfmsr_measure(handle, 0xe8);
case INFO_CUR_MULTIPLIER:
return (int) get_info_cur_multiplier(handle) * 100;
return (int) get_info_cur_multiplier(handle, &internal) * 100;
case INFO_MAX_MULTIPLIER:
return (int) get_info_max_multiplier(handle) * 100;
return (int) get_info_max_multiplier(handle, &internal) * 100;
case INFO_TEMPERATURE:
return get_info_temperature(handle);
return get_info_temperature(handle, &internal);
case INFO_THROTTLING:
return CPU_INVALID_VALUE;
case INFO_VOLTAGE:
return (int) get_info_voltage(handle) * 100;
return (int) get_info_voltage(handle, &internal) * 100;
case INFO_BCLK:
return (int) get_info_bclk(handle) * 100;
return (int) get_info_bclk(handle, &internal) * 100;
default:
return CPU_INVALID_VALUE;
}