diff --git a/src/common/printer.c b/src/common/printer.c index e6e5eec..2f1dc0b 100644 --- a/src/common/printer.c +++ b/src/common/printer.c @@ -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* altivec = get_str_altivec(cpu); - /* char* l1i = get_str_l1i(cpu->cach); char* l1d = get_str_l1d(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)); 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_ALTIVEC, altivec); - /* setAttribute(art,ATTRIBUTE_L1i,l1i); setAttribute(art,ATTRIBUTE_L1d,l1d); setAttribute(art,ATTRIBUTE_L2,l2); if(l3 != NULL) { setAttribute(art,ATTRIBUTE_L3,l3); - }*/ + } setAttribute(art,ATTRIBUTE_PEAK,pp); if(art->n_attributes_set > NUMBER_OF_LINES) { diff --git a/src/common/udev.c b/src/common/udev.c index 1e875a2..596b7da 100644 --- a/src/common/udev.c +++ b/src/common/udev.c @@ -63,6 +63,31 @@ long get_freq_from_file(char* path, bool hv_present) { 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) { 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); @@ -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); 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); +} diff --git a/src/common/udev.h b/src/common/udev.h index 863fc2d..5d35e5f 100644 --- a/src/common/udev.h +++ b/src/common/udev.h @@ -17,12 +17,21 @@ #define _PATH_FREQUENCY "/cpufreq" #define _PATH_FREQUENCY_MAX "/cpuinfo_max_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_CACHE_MAX_LEN 200 #define DEFAULT_FILE_SIZE 4096 char* read_file(char* path, int* len); 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_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 diff --git a/src/ppc/ppc.c b/src/ppc/ppc.c index fcb443e..b7eaf9f 100644 --- a/src/ppc/ppc.c +++ b/src/ppc/ppc.c @@ -44,6 +44,32 @@ struct cache* get_cache_info(struct cpuInfo* cpu) { struct cache* cach = malloc(sizeof(struct cache)); 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; } @@ -145,8 +171,8 @@ struct cpuInfo* get_cpu_info() { cpu->arch = get_cpu_uarch(); cpu->freq = get_frequency_info(); - cpu->cach = get_cache_info(cpu); cpu->topo = get_topology_info(cpu, cpu->cach); + cpu->cach = get_cache_info(cpu); feat->altivec = has_altivec(cpu->arch);