diff --git a/src/common/printer.c b/src/common/printer.c index 4a3aa1d..18a3079 100644 --- a/src/common/printer.c +++ b/src/common/printer.c @@ -498,22 +498,37 @@ bool print_cpufetch_x86(struct cpuInfo* cpu, STYLE s, struct color** cs, struct return false; art->new_intel_logo = choose_new_intel_logo(cpu); + + uint32_t socket_num = 1; + char* l1i = NULL; + char *l1d = NULL; + char *l2 = NULL; + char *l3 = NULL; + char* n_cores = NULL; + char* n_cores_dual = NULL; + char* sockets = NULL; + char* uarch = get_str_uarch(cpu); char* manufacturing_process = get_str_process(cpu); - char* sockets = get_str_sockets(cpu->topo); char* max_frequency = get_str_freq(cpu->freq); - char* n_cores = get_str_topology(cpu, cpu->topo, false); - char* n_cores_dual = get_str_topology(cpu, cpu->topo, true); char* cpu_name = get_str_cpu_name(cpu, fcpuname); char* avx = get_str_avx(cpu); char* fma = get_str_fma(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* pp = get_str_peak_performance(cpu->peak_performance); + if(cpu->topo != NULL) { + sockets = get_str_sockets(cpu->topo); + n_cores = get_str_topology(cpu, cpu->topo, false); + n_cores_dual = get_str_topology(cpu, cpu->topo, true); + } + + if(cpu->cach != NULL) { + l1i = get_str_l1i(cpu->cach); + l1d = get_str_l1d(cpu->cach); + l2 = get_str_l2(cpu->cach); + l3 = get_str_l3(cpu->cach); + } + setAttribute(art,ATTRIBUTE_NAME,cpu_name); if(cpu->hv->present) { setAttribute(art, ATTRIBUTE_HYPERVISOR, cpu->hv->hv_name); @@ -521,23 +536,23 @@ bool print_cpufetch_x86(struct cpuInfo* cpu, STYLE s, struct color** cs, struct setAttribute(art,ATTRIBUTE_UARCH,uarch); setAttribute(art,ATTRIBUTE_TECHNOLOGY,manufacturing_process); setAttribute(art,ATTRIBUTE_FREQUENCY,max_frequency); - uint32_t socket_num = get_nsockets(cpu->topo); - if (socket_num > 1) { - setAttribute(art, ATTRIBUTE_SOCKETS, sockets); - setAttribute(art, ATTRIBUTE_NCORES,n_cores); - setAttribute(art, ATTRIBUTE_NCORES_DUAL, n_cores_dual); - } - else { - setAttribute(art,ATTRIBUTE_NCORES,n_cores); + if(cpu->topo != NULL) { + socket_num = get_nsockets(cpu->topo); + if (socket_num > 1) { + setAttribute(art, ATTRIBUTE_SOCKETS, sockets); + setAttribute(art, ATTRIBUTE_NCORES, n_cores); + setAttribute(art, ATTRIBUTE_NCORES_DUAL, n_cores_dual); + } + else { + setAttribute(art,ATTRIBUTE_NCORES,n_cores); + } } setAttribute(art,ATTRIBUTE_AVX,avx); setAttribute(art,ATTRIBUTE_FMA,fma); - setAttribute(art,ATTRIBUTE_L1i,l1i); - setAttribute(art,ATTRIBUTE_L1d,l1d); - setAttribute(art,ATTRIBUTE_L2,l2); - if(l3 != NULL) { - setAttribute(art,ATTRIBUTE_L3,l3); - } + if(l1i != NULL) setAttribute(art,ATTRIBUTE_L1i,l1i); + if(l1d != NULL) setAttribute(art,ATTRIBUTE_L1d,l1d); + if(l2 != NULL) setAttribute(art,ATTRIBUTE_L2,l2); + if(l3 != NULL) setAttribute(art,ATTRIBUTE_L3,l3); setAttribute(art,ATTRIBUTE_PEAK,pp); const char** attribute_fields = ATTRIBUTE_FIELDS; @@ -571,8 +586,8 @@ bool print_cpufetch_x86(struct cpuInfo* cpu, STYLE s, struct color** cs, struct free(art); if(cs != NULL) free_colors_struct(cs); - free_cache_struct(cpu->cach); - free_topo_struct(cpu->topo); + if(cpu->cach != NULL) free_cache_struct(cpu->cach); + if(cpu->topo != NULL) free_topo_struct(cpu->topo); free_freq_struct(cpu->freq); free_cpuinfo_struct(cpu); diff --git a/src/x86/cpuid.c b/src/x86/cpuid.c index 17c391d..d0b7eb1 100644 --- a/src/x86/cpuid.c +++ b/src/x86/cpuid.c @@ -278,6 +278,9 @@ struct cpuInfo* get_cpu_info() { struct cpuInfo* cpu = emalloc(sizeof(struct cpuInfo)); struct features* feat = emalloc(sizeof(struct features)); cpu->feat = feat; + cpu->peak_performance = -1; + cpu->topo = NULL; + cpu->cach = NULL; bool *ptr = &(feat->AES); for(uint32_t i = 0; i < sizeof(struct features)/sizeof(bool); i++, ptr++) { @@ -386,15 +389,20 @@ struct cpuInfo* get_cpu_info() { cpu->topology_extensions = (ecx >> 22) & 1; } + // If any field of the struct is NULL, + // return inmideately, as further functions + // require valid fields (cach, topo, etc) cpu->arch = get_cpu_uarch(cpu); cpu->freq = get_frequency_info(cpu); + cpu->cach = get_cache_info(cpu); + if(cpu->cach == NULL) return cpu; + cpu->topo = get_topology_info(cpu, cpu->cach); + if(cpu->topo == NULL) return cpu; + cpu->peak_performance = get_peak_performance(cpu, cpu->topo, get_freq(cpu->freq), accurate_pp()); - if(cpu->cach == NULL || cpu->topo == NULL) { - return NULL; - } return cpu; }