mirror of
https://github.com/Dr-Noob/cpufetch.git
synced 2026-03-25 16:00:39 +01:00
[v0.98][PPC] Add cache detection using udev and use it for ppc
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user