mirror of
https://github.com/anrieff/libcpuid
synced 2024-12-16 16:35:45 +00:00
Rename set_error -> cpuid_set_error and get_error -> cpuid_get_error (#188)
This commit is contained in:
parent
10bebe5d44
commit
e3e1c16190
4 changed files with 71 additions and 71 deletions
|
@ -49,13 +49,13 @@
|
||||||
|
|
||||||
INTERNAL_SCOPE int _libcpuid_errno = ERR_OK;
|
INTERNAL_SCOPE int _libcpuid_errno = ERR_OK;
|
||||||
|
|
||||||
int set_error(cpu_error_t err)
|
int cpuid_set_error(cpu_error_t err)
|
||||||
{
|
{
|
||||||
_libcpuid_errno = (int) err;
|
_libcpuid_errno = (int) err;
|
||||||
return (int) err;
|
return (int) err;
|
||||||
}
|
}
|
||||||
|
|
||||||
int get_error()
|
int cpuid_get_error()
|
||||||
{
|
{
|
||||||
return _libcpuid_errno;
|
return _libcpuid_errno;
|
||||||
}
|
}
|
||||||
|
@ -126,7 +126,7 @@ static void cpuid_grow_raw_data_array(struct cpu_raw_data_array_t* raw_array, lo
|
||||||
debugf(3, "Growing cpu_raw_data_array_t from %u to %u items\n", raw_array->num_raw, n);
|
debugf(3, "Growing cpu_raw_data_array_t from %u to %u items\n", raw_array->num_raw, n);
|
||||||
tmp = realloc(raw_array->raw, sizeof(struct cpu_raw_data_t) * n);
|
tmp = realloc(raw_array->raw, sizeof(struct cpu_raw_data_t) * n);
|
||||||
if (tmp == NULL) { /* Memory allocation failure */
|
if (tmp == NULL) { /* Memory allocation failure */
|
||||||
set_error(ERR_NO_MEM);
|
cpuid_set_error(ERR_NO_MEM);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -145,7 +145,7 @@ static void cpuid_grow_system_id(struct system_id_t* system, uint8_t n)
|
||||||
debugf(3, "Growing system_id_t from %u to %u items\n", system->num_cpu_types, n);
|
debugf(3, "Growing system_id_t from %u to %u items\n", system->num_cpu_types, n);
|
||||||
tmp = realloc(system->cpu_types, sizeof(struct cpu_id_t) * n);
|
tmp = realloc(system->cpu_types, sizeof(struct cpu_id_t) * n);
|
||||||
if (tmp == NULL) { /* Memory allocation failure */
|
if (tmp == NULL) { /* Memory allocation failure */
|
||||||
set_error(ERR_NO_MEM);
|
cpuid_set_error(ERR_NO_MEM);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -534,7 +534,7 @@ static int cpuid_serialize_raw_data_internal(struct cpu_raw_data_t* single_raw,
|
||||||
/* Open file descriptor */
|
/* Open file descriptor */
|
||||||
f = !strcmp(filename, "") ? stdout : fopen(filename, "wt");
|
f = !strcmp(filename, "") ? stdout : fopen(filename, "wt");
|
||||||
if (!f)
|
if (!f)
|
||||||
return set_error(ERR_OPEN);
|
return cpuid_set_error(ERR_OPEN);
|
||||||
debugf(1, "Writing raw CPUID dump to '%s'\n", f == stdout ? "stdout" : filename);
|
debugf(1, "Writing raw CPUID dump to '%s'\n", f == stdout ? "stdout" : filename);
|
||||||
|
|
||||||
/* Write raw data to output file */
|
/* Write raw data to output file */
|
||||||
|
@ -580,7 +580,7 @@ static int cpuid_serialize_raw_data_internal(struct cpu_raw_data_t* single_raw,
|
||||||
/* Close file descriptor */
|
/* Close file descriptor */
|
||||||
if (strcmp(filename, ""))
|
if (strcmp(filename, ""))
|
||||||
fclose(f);
|
fclose(f);
|
||||||
return set_error(ERR_OK);
|
return cpuid_set_error(ERR_OK);
|
||||||
}
|
}
|
||||||
|
|
||||||
#define RAW_ASSIGN_LINE(__line) __line[EAX] = eax ; __line[EBX] = ebx ; __line[ECX] = ecx ; __line[EDX] = edx
|
#define RAW_ASSIGN_LINE(__line) __line[EAX] = eax ; __line[EBX] = ebx ; __line[ECX] = ecx ; __line[EDX] = edx
|
||||||
|
@ -604,7 +604,7 @@ static int cpuid_deserialize_raw_data_internal(struct cpu_raw_data_t* single_raw
|
||||||
/* Open file descriptor */
|
/* Open file descriptor */
|
||||||
f = !strcmp(filename, "") ? stdin : fopen(filename, "rt");
|
f = !strcmp(filename, "") ? stdin : fopen(filename, "rt");
|
||||||
if (!f)
|
if (!f)
|
||||||
return set_error(ERR_OPEN);
|
return cpuid_set_error(ERR_OPEN);
|
||||||
debugf(1, "Opening raw dump from '%s'\n", f == stdin ? "stdin" : filename);
|
debugf(1, "Opening raw dump from '%s'\n", f == stdin ? "stdin" : filename);
|
||||||
|
|
||||||
if (use_raw_array)
|
if (use_raw_array)
|
||||||
|
@ -717,7 +717,7 @@ static int cpuid_deserialize_raw_data_internal(struct cpu_raw_data_t* single_raw
|
||||||
/* Close file descriptor */
|
/* Close file descriptor */
|
||||||
if (strcmp(filename, ""))
|
if (strcmp(filename, ""))
|
||||||
fclose(f);
|
fclose(f);
|
||||||
return set_error(ERR_OK);
|
return cpuid_set_error(ERR_OK);
|
||||||
}
|
}
|
||||||
#undef RAW_ASSIGN_LINE
|
#undef RAW_ASSIGN_LINE
|
||||||
|
|
||||||
|
@ -859,7 +859,7 @@ static int cpuid_basic_identify(struct cpu_raw_data_t* raw, struct cpu_id_t* dat
|
||||||
data->vendor = cpuid_vendor_identify(raw->basic_cpuid[0], data->vendor_str);
|
data->vendor = cpuid_vendor_identify(raw->basic_cpuid[0], data->vendor_str);
|
||||||
|
|
||||||
if (data->vendor == VENDOR_UNKNOWN)
|
if (data->vendor == VENDOR_UNKNOWN)
|
||||||
return set_error(ERR_CPU_UNKN);
|
return cpuid_set_error(ERR_CPU_UNKN);
|
||||||
data->architecture = ARCHITECTURE_X86;
|
data->architecture = ARCHITECTURE_X86;
|
||||||
basic = raw->basic_cpuid[0][EAX];
|
basic = raw->basic_cpuid[0][EAX];
|
||||||
if (basic >= 1) {
|
if (basic >= 1) {
|
||||||
|
@ -890,7 +890,7 @@ static int cpuid_basic_identify(struct cpu_raw_data_t* raw, struct cpu_id_t* dat
|
||||||
}
|
}
|
||||||
load_features_common(raw, data);
|
load_features_common(raw, data);
|
||||||
data->total_logical_cpus = get_total_cpus();
|
data->total_logical_cpus = get_total_cpus();
|
||||||
return set_error(ERR_OK);
|
return cpuid_set_error(ERR_OK);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void make_list_from_string(const char* csv, struct cpu_list_t* list)
|
static void make_list_from_string(const char* csv, struct cpu_list_t* list)
|
||||||
|
@ -903,7 +903,7 @@ static void make_list_from_string(const char* csv, struct cpu_list_t* list)
|
||||||
list->names = (char**) malloc(sizeof(char*) * n);
|
list->names = (char**) malloc(sizeof(char*) * n);
|
||||||
if (!list->names) { /* Memory allocation failed */
|
if (!list->names) { /* Memory allocation failed */
|
||||||
list->num_entries = 0;
|
list->num_entries = 0;
|
||||||
set_error(ERR_NO_MEM);
|
cpuid_set_error(ERR_NO_MEM);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
list->num_entries = n;
|
list->num_entries = n;
|
||||||
|
@ -912,7 +912,7 @@ static void make_list_from_string(const char* csv, struct cpu_list_t* list)
|
||||||
for (i = 0; i <= l; i++) if (i == l || csv[i] == ',') {
|
for (i = 0; i <= l; i++) if (i == l || csv[i] == ',') {
|
||||||
list->names[n] = (char*) malloc(i - last);
|
list->names[n] = (char*) malloc(i - last);
|
||||||
if (!list->names[n]) { /* Memory allocation failed */
|
if (!list->names[n]) { /* Memory allocation failed */
|
||||||
set_error(ERR_NO_MEM);
|
cpuid_set_error(ERR_NO_MEM);
|
||||||
for (j = 0; j < n; j++) free(list->names[j]);
|
for (j = 0; j < n; j++) free(list->names[j]);
|
||||||
free(list->names);
|
free(list->names);
|
||||||
list->num_entries = 0;
|
list->num_entries = 0;
|
||||||
|
@ -946,7 +946,7 @@ static bool cpu_ident_apic_id(logical_cpu_t logical_cpu, struct cpu_raw_data_t*
|
||||||
is_apic_id_supported = true;
|
is_apic_id_supported = true;
|
||||||
break;
|
break;
|
||||||
case VENDOR_UNKNOWN:
|
case VENDOR_UNKNOWN:
|
||||||
set_error(ERR_CPU_UNKN);
|
cpuid_set_error(ERR_CPU_UNKN);
|
||||||
/* Fall through */
|
/* Fall through */
|
||||||
default:
|
default:
|
||||||
is_apic_id_supported = false;
|
is_apic_id_supported = false;
|
||||||
|
@ -1025,7 +1025,7 @@ int cpuid_get_raw_data(struct cpu_raw_data_t* data)
|
||||||
{
|
{
|
||||||
unsigned i;
|
unsigned i;
|
||||||
if (!cpuid_present())
|
if (!cpuid_present())
|
||||||
return set_error(ERR_NO_CPUID);
|
return cpuid_set_error(ERR_NO_CPUID);
|
||||||
for (i = 0; i < 32; i++)
|
for (i = 0; i < 32; i++)
|
||||||
cpu_exec_cpuid(i, data->basic_cpuid[i]);
|
cpu_exec_cpuid(i, data->basic_cpuid[i]);
|
||||||
for (i = 0; i < 32; i++)
|
for (i = 0; i < 32; i++)
|
||||||
|
@ -1060,18 +1060,18 @@ int cpuid_get_raw_data(struct cpu_raw_data_t* data)
|
||||||
data->amd_fn8000001dh[i][ECX] = i;
|
data->amd_fn8000001dh[i][ECX] = i;
|
||||||
cpu_exec_cpuid_ext(data->amd_fn8000001dh[i]);
|
cpu_exec_cpuid_ext(data->amd_fn8000001dh[i]);
|
||||||
}
|
}
|
||||||
return set_error(ERR_OK);
|
return cpuid_set_error(ERR_OK);
|
||||||
}
|
}
|
||||||
|
|
||||||
int cpuid_get_all_raw_data(struct cpu_raw_data_array_t* data)
|
int cpuid_get_all_raw_data(struct cpu_raw_data_array_t* data)
|
||||||
{
|
{
|
||||||
int cur_error = set_error(ERR_OK);
|
int cur_error = cpuid_set_error(ERR_OK);
|
||||||
int ret_error = set_error(ERR_OK);
|
int ret_error = cpuid_set_error(ERR_OK);
|
||||||
logical_cpu_t logical_cpu = 0;
|
logical_cpu_t logical_cpu = 0;
|
||||||
struct cpu_raw_data_t* raw_ptr = NULL;
|
struct cpu_raw_data_t* raw_ptr = NULL;
|
||||||
|
|
||||||
if (data == NULL)
|
if (data == NULL)
|
||||||
return set_error(ERR_HANDLE);
|
return cpuid_set_error(ERR_HANDLE);
|
||||||
|
|
||||||
bool affinity_saved = save_cpu_affinity();
|
bool affinity_saved = save_cpu_affinity();
|
||||||
|
|
||||||
|
@ -1119,13 +1119,13 @@ int cpu_ident_internal(struct cpu_raw_data_t* raw, struct cpu_id_t* data, struct
|
||||||
struct cpu_raw_data_t myraw;
|
struct cpu_raw_data_t myraw;
|
||||||
if (!raw) {
|
if (!raw) {
|
||||||
if ((r = cpuid_get_raw_data(&myraw)) < 0)
|
if ((r = cpuid_get_raw_data(&myraw)) < 0)
|
||||||
return set_error(r);
|
return cpuid_set_error(r);
|
||||||
raw = &myraw;
|
raw = &myraw;
|
||||||
}
|
}
|
||||||
cpu_id_t_constructor(data);
|
cpu_id_t_constructor(data);
|
||||||
memset(internal->cache_mask, 0, sizeof(internal->cache_mask));
|
memset(internal->cache_mask, 0, sizeof(internal->cache_mask));
|
||||||
if ((r = cpuid_basic_identify(raw, data)) < 0)
|
if ((r = cpuid_basic_identify(raw, data)) < 0)
|
||||||
return set_error(r);
|
return cpuid_set_error(r);
|
||||||
switch (data->vendor) {
|
switch (data->vendor) {
|
||||||
case VENDOR_INTEL:
|
case VENDOR_INTEL:
|
||||||
r = cpuid_identify_intel(raw, data, internal);
|
r = cpuid_identify_intel(raw, data, internal);
|
||||||
|
@ -1141,7 +1141,7 @@ int cpu_ident_internal(struct cpu_raw_data_t* raw, struct cpu_id_t* data, struct
|
||||||
/* - Deprecated since v0.5.0 */
|
/* - Deprecated since v0.5.0 */
|
||||||
data->l1_assoc = data->l1_data_assoc;
|
data->l1_assoc = data->l1_data_assoc;
|
||||||
data->l1_cacheline = data->l1_data_cacheline;
|
data->l1_cacheline = data->l1_data_cacheline;
|
||||||
return set_error(r);
|
return cpuid_set_error(r);
|
||||||
}
|
}
|
||||||
|
|
||||||
static cpu_purpose_t cpu_ident_purpose(struct cpu_raw_data_t* raw)
|
static cpu_purpose_t cpu_ident_purpose(struct cpu_raw_data_t* raw)
|
||||||
|
@ -1152,7 +1152,7 @@ static cpu_purpose_t cpu_ident_purpose(struct cpu_raw_data_t* raw)
|
||||||
|
|
||||||
vendor = cpuid_vendor_identify(raw->basic_cpuid[0], vendor_str);
|
vendor = cpuid_vendor_identify(raw->basic_cpuid[0], vendor_str);
|
||||||
if (vendor == VENDOR_UNKNOWN) {
|
if (vendor == VENDOR_UNKNOWN) {
|
||||||
set_error(ERR_CPU_UNKN);
|
cpuid_set_error(ERR_CPU_UNKN);
|
||||||
return purpose;
|
return purpose;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1233,8 +1233,8 @@ static void update_cache_instances(struct internal_cache_instances_t* caches,
|
||||||
|
|
||||||
int cpu_identify_all(struct cpu_raw_data_array_t* raw_array, struct system_id_t* system)
|
int cpu_identify_all(struct cpu_raw_data_array_t* raw_array, struct system_id_t* system)
|
||||||
{
|
{
|
||||||
int cur_error = set_error(ERR_OK);
|
int cur_error = cpuid_set_error(ERR_OK);
|
||||||
int ret_error = set_error(ERR_OK);
|
int ret_error = cpuid_set_error(ERR_OK);
|
||||||
double smt_divisor;
|
double smt_divisor;
|
||||||
bool is_new_cpu_type;
|
bool is_new_cpu_type;
|
||||||
bool is_last_item;
|
bool is_last_item;
|
||||||
|
@ -1254,10 +1254,10 @@ int cpu_identify_all(struct cpu_raw_data_array_t* raw_array, struct system_id_t*
|
||||||
struct internal_cache_instances_t caches_type, caches_all;
|
struct internal_cache_instances_t caches_type, caches_all;
|
||||||
|
|
||||||
if (system == NULL)
|
if (system == NULL)
|
||||||
return set_error(ERR_HANDLE);
|
return cpuid_set_error(ERR_HANDLE);
|
||||||
if (!raw_array) {
|
if (!raw_array) {
|
||||||
if ((ret_error = cpuid_get_all_raw_data(&my_raw_array)) < 0)
|
if ((ret_error = cpuid_get_all_raw_data(&my_raw_array)) < 0)
|
||||||
return set_error(ret_error);
|
return cpuid_set_error(ret_error);
|
||||||
raw_array = &my_raw_array;
|
raw_array = &my_raw_array;
|
||||||
}
|
}
|
||||||
system_id_t_constructor(system);
|
system_id_t_constructor(system);
|
||||||
|
@ -1324,7 +1324,7 @@ int cpu_identify_all(struct cpu_raw_data_array_t* raw_array, struct system_id_t*
|
||||||
switch (event) {
|
switch (event) {
|
||||||
case EVENT_NEW_CPU_TYPE: cpu_type_index = system->num_cpu_types - 2; break;
|
case EVENT_NEW_CPU_TYPE: cpu_type_index = system->num_cpu_types - 2; break;
|
||||||
case EVENT_LAST_ITEM: cpu_type_index = system->num_cpu_types - 1; break;
|
case EVENT_LAST_ITEM: cpu_type_index = system->num_cpu_types - 1; break;
|
||||||
default: warnf("Warning: event %i in cpu_identify_all() not handled.\n", event); return set_error(ERR_NOT_IMP);
|
default: warnf("Warning: event %i in cpu_identify_all() not handled.\n", event); return cpuid_set_error(ERR_NOT_IMP);
|
||||||
}
|
}
|
||||||
copy_affinity_mask(&system->cpu_types[cpu_type_index].affinity_mask, &affinity_mask);
|
copy_affinity_mask(&system->cpu_types[cpu_type_index].affinity_mask, &affinity_mask);
|
||||||
if (event != EVENT_LAST_ITEM) {
|
if (event != EVENT_LAST_ITEM) {
|
||||||
|
@ -1385,18 +1385,18 @@ int cpu_request_core_type(cpu_purpose_t purpose, struct cpu_raw_data_array_t* ra
|
||||||
|
|
||||||
if (!raw_array) {
|
if (!raw_array) {
|
||||||
if ((error = cpuid_get_all_raw_data(&my_raw_array)) < 0)
|
if ((error = cpuid_get_all_raw_data(&my_raw_array)) < 0)
|
||||||
return set_error(error);
|
return cpuid_set_error(error);
|
||||||
raw_array = &my_raw_array;
|
raw_array = &my_raw_array;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (logical_cpu = 0; logical_cpu < raw_array->num_raw; logical_cpu++) {
|
for (logical_cpu = 0; logical_cpu < raw_array->num_raw; logical_cpu++) {
|
||||||
if (cpu_ident_purpose(&raw_array->raw[logical_cpu]) == purpose) {
|
if (cpu_ident_purpose(&raw_array->raw[logical_cpu]) == purpose) {
|
||||||
cpu_ident_internal(&raw_array->raw[logical_cpu], data, &throwaway);
|
cpu_ident_internal(&raw_array->raw[logical_cpu], data, &throwaway);
|
||||||
return set_error(ERR_OK);
|
return cpuid_set_error(ERR_OK);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return set_error(ERR_NOT_FOUND);
|
return cpuid_set_error(ERR_NOT_FOUND);
|
||||||
}
|
}
|
||||||
|
|
||||||
const char* cpu_architecture_str(cpu_architecture_t architecture)
|
const char* cpu_architecture_str(cpu_architecture_t architecture)
|
||||||
|
@ -1648,7 +1648,7 @@ cpu_vendor_t cpuid_get_vendor(void)
|
||||||
|
|
||||||
if(vendor == VENDOR_UNKNOWN) {
|
if(vendor == VENDOR_UNKNOWN) {
|
||||||
if (!cpuid_present())
|
if (!cpuid_present())
|
||||||
set_error(ERR_NO_CPUID);
|
cpuid_set_error(ERR_NO_CPUID);
|
||||||
else {
|
else {
|
||||||
cpu_exec_cpuid(0, raw_vendor);
|
cpu_exec_cpuid(0, raw_vendor);
|
||||||
vendor = cpuid_vendor_identify(raw_vendor, vendor_str);
|
vendor = cpuid_vendor_identify(raw_vendor, vendor_str);
|
||||||
|
@ -1693,7 +1693,7 @@ void cpuid_get_cpu_list(cpu_vendor_t vendor, struct cpu_list_t* list)
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
warnf("Unknown vendor passed to cpuid_get_cpu_list()\n");
|
warnf("Unknown vendor passed to cpuid_get_cpu_list()\n");
|
||||||
set_error(ERR_INVRANGE);
|
cpuid_set_error(ERR_INVRANGE);
|
||||||
list->num_entries = 0;
|
list->num_entries = 0;
|
||||||
list->names = NULL;
|
list->names = NULL;
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -153,7 +153,7 @@ void generic_get_cpu_list(const struct match_entry_t* matchtable, int count,
|
||||||
n = 0;
|
n = 0;
|
||||||
list->names = (char**) malloc(sizeof(char*) * count);
|
list->names = (char**) malloc(sizeof(char*) * count);
|
||||||
if (!list->names) { /* Memory allocation failure */
|
if (!list->names) { /* Memory allocation failure */
|
||||||
set_error(ERR_NO_MEM);
|
cpuid_set_error(ERR_NO_MEM);
|
||||||
list->num_entries = 0;
|
list->num_entries = 0;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -172,7 +172,7 @@ void generic_get_cpu_list(const struct match_entry_t* matchtable, int count,
|
||||||
list->names[n] = strdup(matchtable[i].name);
|
list->names[n] = strdup(matchtable[i].name);
|
||||||
#endif
|
#endif
|
||||||
if (!list->names[n]) { /* Memory allocation failure */
|
if (!list->names[n]) { /* Memory allocation failure */
|
||||||
set_error(ERR_NO_MEM);
|
cpuid_set_error(ERR_NO_MEM);
|
||||||
list->num_entries = 0;
|
list->num_entries = 0;
|
||||||
for (j = 0; j < n; j++) {
|
for (j = 0; j < n; j++) {
|
||||||
free(list->names[j]);
|
free(list->names[j]);
|
||||||
|
|
|
@ -92,12 +92,12 @@ void debug_print_lbits(int debuglevel, uint64_t mask);
|
||||||
/*
|
/*
|
||||||
* Sets the current errno
|
* Sets the current errno
|
||||||
*/
|
*/
|
||||||
int set_error(cpu_error_t err);
|
int cpuid_set_error(cpu_error_t err);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Gets the current errno
|
* Gets the current errno
|
||||||
*/
|
*/
|
||||||
int get_error(void);
|
int cpuid_get_error(void);
|
||||||
|
|
||||||
extern libcpuid_warn_fn_t _warn_fun;
|
extern libcpuid_warn_fn_t _warn_fun;
|
||||||
extern int _current_verboselevel;
|
extern int _current_verboselevel;
|
||||||
|
|
|
@ -72,30 +72,30 @@ struct msr_driver_t* cpu_msr_driver_open_core(unsigned core_num)
|
||||||
char msr[MSR_PATH_LEN];
|
char msr[MSR_PATH_LEN];
|
||||||
struct msr_driver_t* handle;
|
struct msr_driver_t* handle;
|
||||||
if (core_num >= cpuid_get_total_cpus()) {
|
if (core_num >= cpuid_get_total_cpus()) {
|
||||||
set_error(ERR_INVCNB);
|
cpuid_set_error(ERR_INVCNB);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
if (!rdmsr_supported()) {
|
if (!rdmsr_supported()) {
|
||||||
set_error(ERR_NO_RDMSR);
|
cpuid_set_error(ERR_NO_RDMSR);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
snprintf(msr, MSR_PATH_LEN, "/dev/cpu/%u/msr", core_num);
|
snprintf(msr, MSR_PATH_LEN, "/dev/cpu/%u/msr", core_num);
|
||||||
if(!load_driver(msr)) {
|
if(!load_driver(msr)) {
|
||||||
set_error(ERR_NO_DRIVER);
|
cpuid_set_error(ERR_NO_DRIVER);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
int fd = open(msr, O_RDONLY);
|
int fd = open(msr, O_RDONLY);
|
||||||
if (fd < 0) {
|
if (fd < 0) {
|
||||||
if (errno == EIO) {
|
if (errno == EIO) {
|
||||||
set_error(ERR_NO_RDMSR);
|
cpuid_set_error(ERR_NO_RDMSR);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
set_error(ERR_NO_DRIVER);
|
cpuid_set_error(ERR_NO_DRIVER);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
handle = (struct msr_driver_t*) malloc(sizeof(struct msr_driver_t));
|
handle = (struct msr_driver_t*) malloc(sizeof(struct msr_driver_t));
|
||||||
if (!handle) {
|
if (!handle) {
|
||||||
set_error(ERR_NO_MEM);
|
cpuid_set_error(ERR_NO_MEM);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
handle->fd = fd;
|
handle->fd = fd;
|
||||||
|
@ -107,10 +107,10 @@ int cpu_rdmsr(struct msr_driver_t* driver, uint32_t msr_index, uint64_t* result)
|
||||||
ssize_t ret;
|
ssize_t ret;
|
||||||
|
|
||||||
if (!driver || driver->fd < 0)
|
if (!driver || driver->fd < 0)
|
||||||
return set_error(ERR_HANDLE);
|
return cpuid_set_error(ERR_HANDLE);
|
||||||
ret = pread(driver->fd, result, 8, msr_index);
|
ret = pread(driver->fd, result, 8, msr_index);
|
||||||
if (ret != 8)
|
if (ret != 8)
|
||||||
return set_error(ERR_INVMSR);
|
return cpuid_set_error(ERR_INVMSR);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -160,30 +160,30 @@ struct msr_driver_t* cpu_msr_driver_open_core(unsigned core_num)
|
||||||
char msr[MSR_PATH_LEN];
|
char msr[MSR_PATH_LEN];
|
||||||
struct msr_driver_t* handle;
|
struct msr_driver_t* handle;
|
||||||
if (core_num >= cpuid_get_total_cpus()) {
|
if (core_num >= cpuid_get_total_cpus()) {
|
||||||
set_error(ERR_INVCNB);
|
cpuid_set_error(ERR_INVCNB);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
if (!rdmsr_supported()) {
|
if (!rdmsr_supported()) {
|
||||||
set_error(ERR_NO_RDMSR);
|
cpuid_set_error(ERR_NO_RDMSR);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
snprintf(msr, MSR_PATH_LEN, "/dev/cpuctl%u", core_num);
|
snprintf(msr, MSR_PATH_LEN, "/dev/cpuctl%u", core_num);
|
||||||
if(!load_driver(msr)) {
|
if(!load_driver(msr)) {
|
||||||
set_error(ERR_NO_DRIVER);
|
cpuid_set_error(ERR_NO_DRIVER);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
int fd = open(msr, O_RDONLY);
|
int fd = open(msr, O_RDONLY);
|
||||||
if (fd < 0) {
|
if (fd < 0) {
|
||||||
if (errno == EIO) {
|
if (errno == EIO) {
|
||||||
set_error(ERR_NO_RDMSR);
|
cpuid_set_error(ERR_NO_RDMSR);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
set_error(ERR_NO_DRIVER);
|
cpuid_set_error(ERR_NO_DRIVER);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
handle = (struct msr_driver_t*) malloc(sizeof(struct msr_driver_t));
|
handle = (struct msr_driver_t*) malloc(sizeof(struct msr_driver_t));
|
||||||
if (!handle) {
|
if (!handle) {
|
||||||
set_error(ERR_NO_MEM);
|
cpuid_set_error(ERR_NO_MEM);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
handle->fd = fd;
|
handle->fd = fd;
|
||||||
|
@ -196,10 +196,10 @@ int cpu_rdmsr(struct msr_driver_t* driver, uint32_t msr_index, uint64_t* result)
|
||||||
args.msr = msr_index;
|
args.msr = msr_index;
|
||||||
|
|
||||||
if (!driver || driver->fd < 0)
|
if (!driver || driver->fd < 0)
|
||||||
return set_error(ERR_HANDLE);
|
return cpuid_set_error(ERR_HANDLE);
|
||||||
|
|
||||||
if(ioctl(driver->fd, CPUCTL_RDMSR, &args))
|
if(ioctl(driver->fd, CPUCTL_RDMSR, &args))
|
||||||
return set_error(ERR_INVMSR);
|
return cpuid_set_error(ERR_INVMSR);
|
||||||
|
|
||||||
*result = args.data;
|
*result = args.data;
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -244,20 +244,20 @@ struct msr_driver_t* cpu_msr_driver_open(void)
|
||||||
struct msr_driver_t* drv;
|
struct msr_driver_t* drv;
|
||||||
int status;
|
int status;
|
||||||
if (!rdmsr_supported()) {
|
if (!rdmsr_supported()) {
|
||||||
set_error(ERR_NO_RDMSR);
|
cpuid_set_error(ERR_NO_RDMSR);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
drv = (struct msr_driver_t*) malloc(sizeof(struct msr_driver_t));
|
drv = (struct msr_driver_t*) malloc(sizeof(struct msr_driver_t));
|
||||||
if (!drv) {
|
if (!drv) {
|
||||||
set_error(ERR_NO_MEM);
|
cpuid_set_error(ERR_NO_MEM);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
memset(drv, 0, sizeof(struct msr_driver_t));
|
memset(drv, 0, sizeof(struct msr_driver_t));
|
||||||
|
|
||||||
if (!extract_driver(drv)) {
|
if (!extract_driver(drv)) {
|
||||||
free(drv);
|
free(drv);
|
||||||
set_error(ERR_EXTRACT);
|
cpuid_set_error(ERR_EXTRACT);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -265,7 +265,7 @@ struct msr_driver_t* cpu_msr_driver_open(void)
|
||||||
if (!DeleteFile(drv->driver_path))
|
if (!DeleteFile(drv->driver_path))
|
||||||
debugf(1, "Deleting temporary driver file failed.\n");
|
debugf(1, "Deleting temporary driver file failed.\n");
|
||||||
if (!status) {
|
if (!status) {
|
||||||
set_error(drv->errorcode ? drv->errorcode : ERR_NO_DRIVER);
|
cpuid_set_error(drv->errorcode ? drv->errorcode : ERR_NO_DRIVER);
|
||||||
free(drv);
|
free(drv);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -446,7 +446,7 @@ int cpu_rdmsr(struct msr_driver_t* driver, uint32_t msr_index, uint64_t* result)
|
||||||
SERVICE_STATUS srvStatus = {0};
|
SERVICE_STATUS srvStatus = {0};
|
||||||
|
|
||||||
if (!driver)
|
if (!driver)
|
||||||
return set_error(ERR_HANDLE);
|
return cpuid_set_error(ERR_HANDLE);
|
||||||
DeviceIoControl(driver->hhDriver, IOCTL_PROCVIEW_RDMSR, &msr_index, sizeof(int), &msrdata, sizeof(__int64), &dwBytesReturned, &driver->ovl);
|
DeviceIoControl(driver->hhDriver, IOCTL_PROCVIEW_RDMSR, &msr_index, sizeof(int), &msrdata, sizeof(__int64), &dwBytesReturned, &driver->ovl);
|
||||||
GetOverlappedResult(driver->hhDriver, &driver->ovl, &dwBytesReturned, TRUE);
|
GetOverlappedResult(driver->hhDriver, &driver->ovl, &dwBytesReturned, TRUE);
|
||||||
*result = msrdata;
|
*result = msrdata;
|
||||||
|
@ -484,40 +484,40 @@ int cpu_msr_driver_close(struct msr_driver_t* drv)
|
||||||
struct msr_driver_t { int dummy; };
|
struct msr_driver_t { int dummy; };
|
||||||
struct msr_driver_t* cpu_msr_driver_open(void)
|
struct msr_driver_t* cpu_msr_driver_open(void)
|
||||||
{
|
{
|
||||||
set_error(ERR_NOT_IMP);
|
cpuid_set_error(ERR_NOT_IMP);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct msr_driver_t* cpu_msr_driver_open_core(unsigned core_num)
|
struct msr_driver_t* cpu_msr_driver_open_core(unsigned core_num)
|
||||||
{
|
{
|
||||||
set_error(ERR_NOT_IMP);
|
cpuid_set_error(ERR_NOT_IMP);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
int cpu_rdmsr(struct msr_driver_t* driver, uint32_t msr_index, uint64_t* result)
|
int cpu_rdmsr(struct msr_driver_t* driver, uint32_t msr_index, uint64_t* result)
|
||||||
{
|
{
|
||||||
return set_error(ERR_NOT_IMP);
|
return cpuid_set_error(ERR_NOT_IMP);
|
||||||
}
|
}
|
||||||
|
|
||||||
int cpu_msr_driver_close(struct msr_driver_t* driver)
|
int cpu_msr_driver_close(struct msr_driver_t* driver)
|
||||||
{
|
{
|
||||||
return set_error(ERR_NOT_IMP);
|
return cpuid_set_error(ERR_NOT_IMP);
|
||||||
}
|
}
|
||||||
|
|
||||||
int cpu_rdmsr_range(struct msr_driver_t* handle, uint32_t msr_index, uint8_t highbit,
|
int cpu_rdmsr_range(struct msr_driver_t* handle, uint32_t msr_index, uint8_t highbit,
|
||||||
uint8_t lowbit, uint64_t* result)
|
uint8_t lowbit, uint64_t* result)
|
||||||
{
|
{
|
||||||
return set_error(ERR_NOT_IMP);
|
return cpuid_set_error(ERR_NOT_IMP);
|
||||||
}
|
}
|
||||||
|
|
||||||
int cpu_msrinfo(struct msr_driver_t* driver, cpu_msrinfo_request_t which)
|
int cpu_msrinfo(struct msr_driver_t* driver, cpu_msrinfo_request_t which)
|
||||||
{
|
{
|
||||||
return set_error(ERR_NOT_IMP);
|
return cpuid_set_error(ERR_NOT_IMP);
|
||||||
}
|
}
|
||||||
|
|
||||||
int msr_serialize_raw_data(struct msr_driver_t* handle, const char* filename)
|
int msr_serialize_raw_data(struct msr_driver_t* handle, const char* filename)
|
||||||
{
|
{
|
||||||
return set_error(ERR_NOT_IMP);
|
return cpuid_set_error(ERR_NOT_IMP);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif /* Unsupported OS */
|
#endif /* Unsupported OS */
|
||||||
|
@ -985,7 +985,7 @@ int cpu_rdmsr_range(struct msr_driver_t* handle, uint32_t msr_index, uint8_t hig
|
||||||
const uint8_t bits = highbit - lowbit + 1;
|
const uint8_t bits = highbit - lowbit + 1;
|
||||||
|
|
||||||
if(highbit > 63 || lowbit > highbit)
|
if(highbit > 63 || lowbit > highbit)
|
||||||
return set_error(ERR_INVRANGE);
|
return cpuid_set_error(ERR_INVRANGE);
|
||||||
|
|
||||||
err = cpu_rdmsr(handle, msr_index, result);
|
err = cpu_rdmsr(handle, msr_index, result);
|
||||||
|
|
||||||
|
@ -1007,7 +1007,7 @@ int cpu_msrinfo(struct msr_driver_t* handle, cpu_msrinfo_request_t which)
|
||||||
static struct msr_info_t info;
|
static struct msr_info_t info;
|
||||||
|
|
||||||
if (handle == NULL) {
|
if (handle == NULL) {
|
||||||
set_error(ERR_HANDLE);
|
cpuid_set_error(ERR_HANDLE);
|
||||||
return CPU_INVALID_VALUE;
|
return CPU_INVALID_VALUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1060,17 +1060,17 @@ int msr_serialize_raw_data(struct msr_driver_t* handle, const char* filename)
|
||||||
|
|
||||||
/* Check if MSR driver is initialized */
|
/* Check if MSR driver is initialized */
|
||||||
if (handle == NULL)
|
if (handle == NULL)
|
||||||
return set_error(ERR_HANDLE);
|
return cpuid_set_error(ERR_HANDLE);
|
||||||
|
|
||||||
/* Open file descriptor */
|
/* Open file descriptor */
|
||||||
f = ((filename == NULL) || !strcmp(filename, "")) ? stdout : fopen(filename, "wt");
|
f = ((filename == NULL) || !strcmp(filename, "")) ? stdout : fopen(filename, "wt");
|
||||||
if (!f)
|
if (!f)
|
||||||
return set_error(ERR_OPEN);
|
return cpuid_set_error(ERR_OPEN);
|
||||||
|
|
||||||
/* Get cached decoded CPUID information */
|
/* Get cached decoded CPUID information */
|
||||||
id = get_cached_cpuid();
|
id = get_cached_cpuid();
|
||||||
if (id->vendor == VENDOR_UNKNOWN)
|
if (id->vendor == VENDOR_UNKNOWN)
|
||||||
return get_error();
|
return cpuid_get_error();
|
||||||
|
|
||||||
/* Get CPU stock speed */
|
/* Get CPU stock speed */
|
||||||
if (cpu_clock == 0)
|
if (cpu_clock == 0)
|
||||||
|
@ -1082,7 +1082,7 @@ int msr_serialize_raw_data(struct msr_driver_t* handle, const char* filename)
|
||||||
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 cpuid_set_error(ERR_CPU_UNKN);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Print raw MSR values */
|
/* Print raw MSR values */
|
||||||
|
@ -1097,7 +1097,7 @@ int msr_serialize_raw_data(struct msr_driver_t* handle, const char* filename)
|
||||||
/* Close file descriptor */
|
/* Close file descriptor */
|
||||||
if (f != stdout)
|
if (f != stdout)
|
||||||
fclose(f);
|
fclose(f);
|
||||||
return set_error(ERR_OK);
|
return cpuid_set_error(ERR_OK);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // RDMSR_UNSUPPORTED_OS
|
#endif // RDMSR_UNSUPPORTED_OS
|
||||||
|
|
Loading…
Reference in a new issue