mirror of
https://github.com/Dr-Noob/cpufetch.git
synced 2026-03-25 16:00:39 +01:00
[v0.98][Refactoring] Unify the use of init_topology_struct and init_cache_struct
This commit is contained in:
@@ -13,25 +13,6 @@
|
|||||||
#include "uarch.h"
|
#include "uarch.h"
|
||||||
#include "soc.h"
|
#include "soc.h"
|
||||||
|
|
||||||
void init_cache_struct(struct cache* cach) {
|
|
||||||
cach->L1i = emalloc(sizeof(struct cach));
|
|
||||||
cach->L1d = emalloc(sizeof(struct cach));
|
|
||||||
cach->L2 = emalloc(sizeof(struct cach));
|
|
||||||
cach->L3 = emalloc(sizeof(struct cach));
|
|
||||||
|
|
||||||
cach->cach_arr = emalloc(sizeof(struct cach*) * 4);
|
|
||||||
cach->cach_arr[0] = cach->L1i;
|
|
||||||
cach->cach_arr[1] = cach->L1d;
|
|
||||||
cach->cach_arr[2] = cach->L2;
|
|
||||||
cach->cach_arr[3] = cach->L3;
|
|
||||||
|
|
||||||
cach->max_cache_level = 0;
|
|
||||||
cach->L1i->exists = false;
|
|
||||||
cach->L1d->exists = false;
|
|
||||||
cach->L2->exists = false;
|
|
||||||
cach->L3->exists = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
struct cache* get_cache_info(struct cpuInfo* cpu) {
|
struct cache* get_cache_info(struct cpuInfo* cpu) {
|
||||||
struct cache* cach = emalloc(sizeof(struct cache));
|
struct cache* cach = emalloc(sizeof(struct cache));
|
||||||
init_cache_struct(cach);
|
init_cache_struct(cach);
|
||||||
@@ -57,9 +38,7 @@ struct frequency* get_frequency_info(uint32_t core) {
|
|||||||
|
|
||||||
struct topology* get_topology_info(struct cpuInfo* cpu, struct cache* cach, uint32_t* midr_array, int socket_idx, int ncores) {
|
struct topology* get_topology_info(struct cpuInfo* cpu, struct cache* cach, uint32_t* midr_array, int socket_idx, int ncores) {
|
||||||
struct topology* topo = emalloc(sizeof(struct topology));
|
struct topology* topo = emalloc(sizeof(struct topology));
|
||||||
|
init_topology_struct(topo, cach);
|
||||||
topo->cach = cach;
|
|
||||||
topo->total_cores = 0;
|
|
||||||
|
|
||||||
int sockets_seen = 0;
|
int sockets_seen = 0;
|
||||||
int first_core_idx = 0;
|
int first_core_idx = 0;
|
||||||
|
|||||||
@@ -9,6 +9,7 @@
|
|||||||
|
|
||||||
#ifdef ARCH_X86
|
#ifdef ARCH_X86
|
||||||
#include "../x86/uarch.h"
|
#include "../x86/uarch.h"
|
||||||
|
#include "../x86/apic.h"
|
||||||
#elif ARCH_PPC
|
#elif ARCH_PPC
|
||||||
#include "../ppc/uarch.h"
|
#include "../ppc/uarch.h"
|
||||||
#elif ARCH_ARM
|
#elif ARCH_ARM
|
||||||
@@ -150,6 +151,40 @@ char* get_str_freq(struct frequency* freq) {
|
|||||||
return string;
|
return string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void init_topology_struct(struct topology* topo, struct cache* cach) {
|
||||||
|
topo->total_cores = 0;
|
||||||
|
topo->cach = cach;
|
||||||
|
#if defined(ARCH_X86) || defined(ARCH_PPC)
|
||||||
|
topo->physical_cores = 0;
|
||||||
|
topo->logical_cores = 0;
|
||||||
|
topo->smt_supported = 0;
|
||||||
|
topo->sockets = 0;
|
||||||
|
#ifdef ARCH_X86
|
||||||
|
topo->smt_available = 0;
|
||||||
|
topo->apic = emalloc(sizeof(struct apic));
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
void init_cache_struct(struct cache* cach) {
|
||||||
|
cach->L1i = emalloc(sizeof(struct cach));
|
||||||
|
cach->L1d = emalloc(sizeof(struct cach));
|
||||||
|
cach->L2 = emalloc(sizeof(struct cach));
|
||||||
|
cach->L3 = emalloc(sizeof(struct cach));
|
||||||
|
|
||||||
|
cach->cach_arr = emalloc(sizeof(struct cach*) * 4);
|
||||||
|
cach->cach_arr[0] = cach->L1i;
|
||||||
|
cach->cach_arr[1] = cach->L1d;
|
||||||
|
cach->cach_arr[2] = cach->L2;
|
||||||
|
cach->cach_arr[3] = cach->L3;
|
||||||
|
|
||||||
|
cach->max_cache_level = 0;
|
||||||
|
cach->L1i->exists = false;
|
||||||
|
cach->L1d->exists = false;
|
||||||
|
cach->L2->exists = false;
|
||||||
|
cach->L3->exists = false;
|
||||||
|
}
|
||||||
|
|
||||||
void free_cache_struct(struct cache* cach) {
|
void free_cache_struct(struct cache* cach) {
|
||||||
for(int i=0; i < 4; i++) free(cach->cach_arr[i]);
|
for(int i=0; i < 4; i++) free(cach->cach_arr[i]);
|
||||||
free(cach->cach_arr);
|
free(cach->cach_arr);
|
||||||
|
|||||||
@@ -162,6 +162,9 @@ char* get_str_l2(struct cache* cach);
|
|||||||
char* get_str_l3(struct cache* cach);
|
char* get_str_l3(struct cache* cach);
|
||||||
char* get_str_freq(struct frequency* freq);
|
char* get_str_freq(struct frequency* freq);
|
||||||
|
|
||||||
|
void init_topology_struct(struct topology* topo, struct cache* cach);
|
||||||
|
void init_cache_struct(struct cache* cach);
|
||||||
|
|
||||||
void free_cache_struct(struct cache* cach);
|
void free_cache_struct(struct cache* cach);
|
||||||
void free_freq_struct(struct frequency* freq);
|
void free_freq_struct(struct frequency* freq);
|
||||||
void free_cpuinfo_struct(struct cpuInfo* cpu);
|
void free_cpuinfo_struct(struct cpuInfo* cpu);
|
||||||
|
|||||||
@@ -11,34 +11,6 @@
|
|||||||
#include "../common/udev.h"
|
#include "../common/udev.h"
|
||||||
#include "../common/global.h"
|
#include "../common/global.h"
|
||||||
|
|
||||||
void init_topology_struct(struct topology* topo, struct cache* cach) {
|
|
||||||
topo->total_cores = 0;
|
|
||||||
topo->physical_cores = 0;
|
|
||||||
topo->logical_cores = 0;
|
|
||||||
topo->smt_supported = 0;
|
|
||||||
topo->sockets = 0;
|
|
||||||
topo->cach = cach;
|
|
||||||
}
|
|
||||||
|
|
||||||
void init_cache_struct(struct cache* cach) {
|
|
||||||
cach->L1i = emalloc(sizeof(struct cach));
|
|
||||||
cach->L1d = emalloc(sizeof(struct cach));
|
|
||||||
cach->L2 = emalloc(sizeof(struct cach));
|
|
||||||
cach->L3 = emalloc(sizeof(struct cach));
|
|
||||||
|
|
||||||
cach->cach_arr = emalloc(sizeof(struct cach*) * 4);
|
|
||||||
cach->cach_arr[0] = cach->L1i;
|
|
||||||
cach->cach_arr[1] = cach->L1d;
|
|
||||||
cach->cach_arr[2] = cach->L2;
|
|
||||||
cach->cach_arr[3] = cach->L3;
|
|
||||||
|
|
||||||
cach->max_cache_level = 0;
|
|
||||||
cach->L1i->exists = false;
|
|
||||||
cach->L1d->exists = false;
|
|
||||||
cach->L2->exists = false;
|
|
||||||
cach->L3->exists = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
struct cache* get_cache_info(struct cpuInfo* cpu) {
|
struct cache* get_cache_info(struct cpuInfo* cpu) {
|
||||||
struct cache* cach = emalloc(sizeof(struct cache));
|
struct cache* cach = emalloc(sizeof(struct cache));
|
||||||
init_cache_struct(cach);
|
init_cache_struct(cach);
|
||||||
|
|||||||
@@ -49,36 +49,6 @@ static char *hv_vendors_name[] = {
|
|||||||
* cpuid amd: https://www.amd.com/system/files/TechDocs/25481.pdf
|
* cpuid amd: https://www.amd.com/system/files/TechDocs/25481.pdf
|
||||||
*/
|
*/
|
||||||
|
|
||||||
void init_topology_struct(struct topology* topo, struct cache* cach) {
|
|
||||||
topo->total_cores = 0;
|
|
||||||
topo->physical_cores = 0;
|
|
||||||
topo->logical_cores = 0;
|
|
||||||
topo->smt_available = 0;
|
|
||||||
topo->smt_supported = 0;
|
|
||||||
topo->sockets = 0;
|
|
||||||
topo->apic = emalloc(sizeof(struct apic));
|
|
||||||
topo->cach = cach;
|
|
||||||
}
|
|
||||||
|
|
||||||
void init_cache_struct(struct cache* cach) {
|
|
||||||
cach->L1i = emalloc(sizeof(struct cach));
|
|
||||||
cach->L1d = emalloc(sizeof(struct cach));
|
|
||||||
cach->L2 = emalloc(sizeof(struct cach));
|
|
||||||
cach->L3 = emalloc(sizeof(struct cach));
|
|
||||||
|
|
||||||
cach->cach_arr = emalloc(sizeof(struct cach*) * 4);
|
|
||||||
cach->cach_arr[0] = cach->L1i;
|
|
||||||
cach->cach_arr[1] = cach->L1d;
|
|
||||||
cach->cach_arr[2] = cach->L2;
|
|
||||||
cach->cach_arr[3] = cach->L3;
|
|
||||||
|
|
||||||
cach->max_cache_level = 0;
|
|
||||||
cach->L1i->exists = false;
|
|
||||||
cach->L1d->exists = false;
|
|
||||||
cach->L2->exists = false;
|
|
||||||
cach->L3->exists = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
void get_name_cpuid(char* name, uint32_t reg1, uint32_t reg2, uint32_t reg3) {
|
void get_name_cpuid(char* name, uint32_t reg1, uint32_t reg2, uint32_t reg3) {
|
||||||
uint32_t c = 0;
|
uint32_t c = 0;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user