mirror of
https://github.com/Dr-Noob/cpufetch.git
synced 2026-03-25 07:50:40 +01:00
[v0.98][PPC] Add cache detection using udev and use it for ppc
This commit is contained in:
@@ -578,11 +578,10 @@ bool print_cpufetch_ppc(struct cpuInfo* cpu, STYLE s, struct colors* cs) {
|
|||||||
char* cpu_name = get_str_cpu_name(cpu);
|
char* cpu_name = get_str_cpu_name(cpu);
|
||||||
char* altivec = get_str_altivec(cpu);
|
char* altivec = get_str_altivec(cpu);
|
||||||
|
|
||||||
/*
|
|
||||||
char* l1i = get_str_l1i(cpu->cach);
|
char* l1i = get_str_l1i(cpu->cach);
|
||||||
char* l1d = get_str_l1d(cpu->cach);
|
char* l1d = get_str_l1d(cpu->cach);
|
||||||
char* l2 = get_str_l2(cpu->cach);
|
char* l2 = get_str_l2(cpu->cach);
|
||||||
char* l3 = get_str_l3(cpu->cach);*/
|
char* l3 = get_str_l3(cpu->cach);
|
||||||
char* pp = get_str_peak_performance(cpu,cpu->topo,get_freq(cpu->freq));
|
char* pp = get_str_peak_performance(cpu,cpu->topo,get_freq(cpu->freq));
|
||||||
|
|
||||||
setAttribute(art,ATTRIBUTE_NAME,cpu_name);
|
setAttribute(art,ATTRIBUTE_NAME,cpu_name);
|
||||||
@@ -603,13 +602,12 @@ bool print_cpufetch_ppc(struct cpuInfo* cpu, STYLE s, struct colors* cs) {
|
|||||||
setAttribute(art,ATTRIBUTE_NCORES, n_cores);
|
setAttribute(art,ATTRIBUTE_NCORES, n_cores);
|
||||||
}
|
}
|
||||||
setAttribute(art,ATTRIBUTE_ALTIVEC, altivec);
|
setAttribute(art,ATTRIBUTE_ALTIVEC, altivec);
|
||||||
/*
|
|
||||||
setAttribute(art,ATTRIBUTE_L1i,l1i);
|
setAttribute(art,ATTRIBUTE_L1i,l1i);
|
||||||
setAttribute(art,ATTRIBUTE_L1d,l1d);
|
setAttribute(art,ATTRIBUTE_L1d,l1d);
|
||||||
setAttribute(art,ATTRIBUTE_L2,l2);
|
setAttribute(art,ATTRIBUTE_L2,l2);
|
||||||
if(l3 != NULL) {
|
if(l3 != NULL) {
|
||||||
setAttribute(art,ATTRIBUTE_L3,l3);
|
setAttribute(art,ATTRIBUTE_L3,l3);
|
||||||
}*/
|
}
|
||||||
setAttribute(art,ATTRIBUTE_PEAK,pp);
|
setAttribute(art,ATTRIBUTE_PEAK,pp);
|
||||||
|
|
||||||
if(art->n_attributes_set > NUMBER_OF_LINES) {
|
if(art->n_attributes_set > NUMBER_OF_LINES) {
|
||||||
|
|||||||
@@ -63,6 +63,31 @@ long get_freq_from_file(char* path, bool hv_present) {
|
|||||||
return ret/1000;
|
return ret/1000;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
long get_cache_size_from_file(char* path) {
|
||||||
|
int filelen;
|
||||||
|
char* buf;
|
||||||
|
if((buf = read_file(path, &filelen)) == NULL) {
|
||||||
|
printWarn("Could not open '%s'", path);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
buf[filelen] = '\0'; // remove the K at the end
|
||||||
|
|
||||||
|
char* end;
|
||||||
|
errno = 0;
|
||||||
|
long ret = strtol(buf, &end, 10);
|
||||||
|
if(errno != 0) {
|
||||||
|
perror("strtol");
|
||||||
|
printBug("Failed parsing '%s' file. Read data was: '%s'", path, buf);
|
||||||
|
free(buf);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
free(buf);
|
||||||
|
|
||||||
|
return ret * 1024;
|
||||||
|
}
|
||||||
|
|
||||||
long get_max_freq_from_file(uint32_t core, bool hv_present) {
|
long get_max_freq_from_file(uint32_t core, bool hv_present) {
|
||||||
char path[_PATH_FREQUENCY_MAX_LEN];
|
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);
|
sprintf(path, "%s%s/cpu%d%s%s", _PATH_SYS_SYSTEM, _PATH_SYS_CPU, core, _PATH_FREQUENCY, _PATH_FREQUENCY_MAX);
|
||||||
@@ -74,3 +99,27 @@ long get_min_freq_from_file(uint32_t core, bool hv_present) {
|
|||||||
sprintf(path, "%s%s/cpu%d%s%s", _PATH_SYS_SYSTEM, _PATH_SYS_CPU, core, _PATH_FREQUENCY, _PATH_FREQUENCY_MIN);
|
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, hv_present);
|
return get_freq_from_file(path, hv_present);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
long get_l1i_cache_size(uint32_t core) {
|
||||||
|
char path[_PATH_CACHE_MAX_LEN];
|
||||||
|
sprintf(path, "%s%s/cpu%d%s", _PATH_SYS_SYSTEM, _PATH_SYS_CPU, core, _PATH_CACHE_L1I);
|
||||||
|
return get_cache_size_from_file(path);
|
||||||
|
}
|
||||||
|
|
||||||
|
long get_l1d_cache_size(uint32_t core) {
|
||||||
|
char path[_PATH_CACHE_MAX_LEN];
|
||||||
|
sprintf(path, "%s%s/cpu%d%s", _PATH_SYS_SYSTEM, _PATH_SYS_CPU, core, _PATH_CACHE_L1D);
|
||||||
|
return get_cache_size_from_file(path);
|
||||||
|
}
|
||||||
|
|
||||||
|
long get_l2_cache_size(uint32_t core) {
|
||||||
|
char path[_PATH_CACHE_MAX_LEN];
|
||||||
|
sprintf(path, "%s%s/cpu%d%s", _PATH_SYS_SYSTEM, _PATH_SYS_CPU, core, _PATH_CACHE_L2);
|
||||||
|
return get_cache_size_from_file(path);
|
||||||
|
}
|
||||||
|
|
||||||
|
long get_l3_cache_size(uint32_t core) {
|
||||||
|
char path[_PATH_CACHE_MAX_LEN];
|
||||||
|
sprintf(path, "%s%s/cpu%d%s", _PATH_SYS_SYSTEM, _PATH_SYS_CPU, core, _PATH_CACHE_L3);
|
||||||
|
return get_cache_size_from_file(path);
|
||||||
|
}
|
||||||
|
|||||||
@@ -17,12 +17,21 @@
|
|||||||
#define _PATH_FREQUENCY "/cpufreq"
|
#define _PATH_FREQUENCY "/cpufreq"
|
||||||
#define _PATH_FREQUENCY_MAX "/cpuinfo_max_freq"
|
#define _PATH_FREQUENCY_MAX "/cpuinfo_max_freq"
|
||||||
#define _PATH_FREQUENCY_MIN "/cpuinfo_min_freq"
|
#define _PATH_FREQUENCY_MIN "/cpuinfo_min_freq"
|
||||||
|
#define _PATH_CACHE_L1D "/cache/index0/size"
|
||||||
|
#define _PATH_CACHE_L1I "/cache/index1/size"
|
||||||
|
#define _PATH_CACHE_L2 "/cache/index2/size"
|
||||||
|
#define _PATH_CACHE_L3 "/cache/index3/size"
|
||||||
|
|
||||||
#define _PATH_FREQUENCY_MAX_LEN 100
|
#define _PATH_FREQUENCY_MAX_LEN 100
|
||||||
|
#define _PATH_CACHE_MAX_LEN 200
|
||||||
#define DEFAULT_FILE_SIZE 4096
|
#define DEFAULT_FILE_SIZE 4096
|
||||||
|
|
||||||
char* read_file(char* path, int* len);
|
char* read_file(char* path, int* len);
|
||||||
long get_max_freq_from_file(uint32_t core, bool hv_present);
|
long get_max_freq_from_file(uint32_t core, bool hv_present);
|
||||||
long get_min_freq_from_file(uint32_t core, bool hv_present);
|
long get_min_freq_from_file(uint32_t core, bool hv_present);
|
||||||
|
long get_l1i_cache_size(uint32_t core);
|
||||||
|
long get_l1d_cache_size(uint32_t core);
|
||||||
|
long get_l2_cache_size(uint32_t core);
|
||||||
|
long get_l3_cache_size(uint32_t core);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -44,6 +44,32 @@ struct cache* get_cache_info(struct cpuInfo* cpu) {
|
|||||||
struct cache* cach = malloc(sizeof(struct cache));
|
struct cache* cach = malloc(sizeof(struct cache));
|
||||||
init_cache_struct(cach);
|
init_cache_struct(cach);
|
||||||
|
|
||||||
|
cach->L1i->size = get_l1i_cache_size(0);
|
||||||
|
cach->L1d->size = get_l1d_cache_size(0);
|
||||||
|
cach->L2->size = get_l2_cache_size(0);
|
||||||
|
cach->L3->size = get_l3_cache_size(0);
|
||||||
|
|
||||||
|
if(cach->L1i->size > 0) {
|
||||||
|
cach->L1i->exists = true;
|
||||||
|
cach->L1i->num_caches = cpu->topo->physical_cores * cpu->topo->sockets;
|
||||||
|
cach->max_cache_level++;
|
||||||
|
}
|
||||||
|
if(cach->L1d->size > 0) {
|
||||||
|
cach->L1d->exists = true;
|
||||||
|
cach->L1d->num_caches = cpu->topo->physical_cores * cpu->topo->sockets;
|
||||||
|
cach->max_cache_level++;
|
||||||
|
}
|
||||||
|
if(cach->L2->size > 0) {
|
||||||
|
cach->L2->exists = true;
|
||||||
|
cach->L2->num_caches = cpu->topo->physical_cores * cpu->topo->sockets;
|
||||||
|
cach->max_cache_level++;
|
||||||
|
}
|
||||||
|
if(cach->L3->size > 0) {
|
||||||
|
cach->L3->exists = true;
|
||||||
|
cach->L3->num_caches = cpu->topo->physical_cores * cpu->topo->sockets; // does not have to be true!
|
||||||
|
cach->max_cache_level++;
|
||||||
|
}
|
||||||
|
|
||||||
return cach;
|
return cach;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -145,8 +171,8 @@ struct cpuInfo* get_cpu_info() {
|
|||||||
|
|
||||||
cpu->arch = get_cpu_uarch();
|
cpu->arch = get_cpu_uarch();
|
||||||
cpu->freq = get_frequency_info();
|
cpu->freq = get_frequency_info();
|
||||||
cpu->cach = get_cache_info(cpu);
|
|
||||||
cpu->topo = get_topology_info(cpu, cpu->cach);
|
cpu->topo = get_topology_info(cpu, cpu->cach);
|
||||||
|
cpu->cach = get_cache_info(cpu);
|
||||||
|
|
||||||
feat->altivec = has_altivec(cpu->arch);
|
feat->altivec = has_altivec(cpu->arch);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user