[v0.87][FREQ] Frequency in udev is now fetched as a per core basis. Before this commit, freq was always fetched from core 0. This allows ARM do detect the max frequency of each of the cores (which may or may not be the same in all of them)

This commit is contained in:
Dr-Noob
2020-11-22 10:23:02 +01:00
parent 0875c4d425
commit fcb2c716db
5 changed files with 24 additions and 22 deletions

View File

@@ -52,11 +52,11 @@ struct cache* get_cache_info(struct cpuInfo* cpu) {
return cach; return cach;
} }
struct frequency* get_frequency_info(struct cpuInfo* cpu) { struct frequency* get_frequency_info(uint32_t core) {
struct frequency* freq = malloc(sizeof(struct frequency)); struct frequency* freq = malloc(sizeof(struct frequency));
freq->base = UNKNOWN_FREQ; freq->base = UNKNOWN_FREQ;
freq->max = get_max_freq_from_file(); freq->max = get_max_freq_from_file(core);
return freq; return freq;
} }
@@ -151,7 +151,7 @@ struct cpuInfo* get_cpu_info() {
ptr->midr = midr_array[midr_idx]; ptr->midr = midr_array[midr_idx];
ptr->arch = get_uarch_from_midr(ptr->midr, ptr); ptr->arch = get_uarch_from_midr(ptr->midr, ptr);
ptr->freq = get_frequency_info(ptr); ptr->freq = get_frequency_info(i); // TODO: wrong!
ptr->cach = get_cache_info(ptr); ptr->cach = get_cache_info(ptr);
ptr->topo = get_topology_info(ptr, ptr->cach); ptr->topo = get_topology_info(ptr, ptr->cach);
} }
@@ -210,18 +210,17 @@ char* get_soc_name(struct cpuInfo* cpu) {
return cpu->soc_name; return cpu->soc_name;
} }
//TODO: Fix wrong implementation
void print_debug(struct cpuInfo* cpu) { void print_debug(struct cpuInfo* cpu) {
int ncores = get_ncores_from_cpuinfo(); int ncores = get_ncores_from_cpuinfo();
if(ncores >= 10) { if(ncores >= 10) {
for(int i=0; i < ncores; i++) { for(int i=0; i < ncores; i++) {
printf("[Core %02d] 0x%.8X\n", i, cpu->midr); printf("[Core %02d] 0x%.8X %ld MHz\n", i, get_midr_from_cpuinfo(i), get_max_freq_from_file(i));
} }
} }
else { else {
for(int i=0; i < ncores; i++) { for(int i=0; i < ncores; i++) {
printf("[Core %d] 0x%.8X\n", i, cpu->midr); printf("[Core %d] 0x%.8X %ld MHz\n", i, get_midr_from_cpuinfo(i), get_max_freq_from_file(i));
} }
} }
} }

View File

@@ -5,7 +5,7 @@
struct cpuInfo* get_cpu_info(); struct cpuInfo* get_cpu_info();
struct cache* get_cache_info(struct cpuInfo* cpu); struct cache* get_cache_info(struct cpuInfo* cpu);
struct frequency* get_frequency_info(struct cpuInfo* cpu); struct frequency* get_frequency_info(uint32_t core);
struct topology* get_topology_info(struct cpuInfo* cpu, struct cache* cach); struct topology* get_topology_info(struct cpuInfo* cpu, struct cache* cach);
uint32_t get_nsockets(struct topology* topo); uint32_t get_nsockets(struct topology* topo);

View File

@@ -13,15 +13,14 @@
#include "../arm/midr.h" #include "../arm/midr.h"
#endif #endif
#define _PATH_SYS_SYSTEM "/sys/devices/system" #define _PATH_SYS_SYSTEM "/sys/devices/system"
#define _PATH_SYS_CPU _PATH_SYS_SYSTEM"/cpu" #define _PATH_SYS_CPU "/cpu"
#define _PATH_ONE_CPU _PATH_SYS_CPU"/cpu0" #define _PATH_FREQUENCY "/cpufreq"
#define _PATH_FREQUENCY_MAX "/cpuinfo_max_freq"
#define _PATH_FREQUENCY_MIN "/cpuinfo_min_freq"
#define _PATH_FREQUENCY _PATH_ONE_CPU"/cpufreq" #define _PATH_FREQUENCY_MAX_LEN 100
#define _PATH_FREQUENCY_MAX _PATH_FREQUENCY"/cpuinfo_max_freq" #define DEFAULT_FILE_SIZE 4096
#define _PATH_FREQUENCY_MIN _PATH_FREQUENCY"/cpuinfo_min_freq"
#define DEFAULT_FILE_SIZE 4096
long get_freq_from_file(char* path) { long get_freq_from_file(char* path) {
int fd = open(path, O_RDONLY); int fd = open(path, O_RDONLY);
@@ -70,12 +69,16 @@ long get_freq_from_file(char* path) {
return ret/1000; return ret/1000;
} }
long get_max_freq_from_file() { long get_max_freq_from_file(uint32_t core) {
return get_freq_from_file(_PATH_FREQUENCY_MAX); char path[_PATH_FREQUENCY_MAX_LEN];
sprintf(path, "%s%s/cpu%d%s%s", _PATH_SYS_SYSTEM, _PATH_SYS_CPU, core, _PATH_FREQUENCY, _PATH_FREQUENCY_MAX);
return get_freq_from_file(path);
} }
long get_min_freq_from_file() { long get_min_freq_from_file(uint32_t core) {
return get_freq_from_file(_PATH_FREQUENCY_MIN); char path[_PATH_FREQUENCY_MAX_LEN];
sprintf(path, "%s%s/cpu%d%s%s", _PATH_SYS_SYSTEM, _PATH_SYS_CPU, core, _PATH_FREQUENCY, _PATH_FREQUENCY_MIN);
return get_freq_from_file(path);
} }
#ifdef ARCH_ARM #ifdef ARCH_ARM

View File

@@ -3,8 +3,8 @@
#include <stdint.h> #include <stdint.h>
long get_max_freq_from_file(); long get_max_freq_from_file(uint32_t core);
long get_min_freq_from_file(); long get_min_freq_from_file(uint32_t core);
#ifdef ARCH_ARM #ifdef ARCH_ARM
int get_ncores_from_cpuinfo(); int get_ncores_from_cpuinfo();

View File

@@ -678,7 +678,7 @@ struct frequency* get_frequency_info(struct cpuInfo* cpu) {
#else #else
printWarn("Can't read frequency information from cpuid (needed level is 0x%.8X, max is 0x%.8X). Using udev", 0x00000016, cpu->maxLevels); printWarn("Can't read frequency information from cpuid (needed level is 0x%.8X, max is 0x%.8X). Using udev", 0x00000016, cpu->maxLevels);
freq->base = UNKNOWN_FREQ; freq->base = UNKNOWN_FREQ;
freq->max = get_max_freq_from_file(); freq->max = get_max_freq_from_file(0);
#endif #endif
} }
else { else {