[v0.98][Refactoring] Use int for peak performance, which makes code cleaner

This commit is contained in:
Dr-Noob
2021-08-06 11:04:29 +02:00
parent 6953d8dda5
commit c24dd7cbb6
9 changed files with 106 additions and 115 deletions

View File

@@ -151,24 +151,25 @@ char* get_str_freq(struct frequency* freq) {
return string;
}
char* get_str_peak_performance(double flops, bool valid_flops) {
char* get_str_peak_performance(int64_t flops) {
char* str;
if(!valid_flops) {
if(flops == -1) {
str = emalloc(sizeof(char) * (strlen(STRING_UNKNOWN) + 1));
strncpy(str, STRING_UNKNOWN, strlen(STRING_UNKNOWN) + 1);
}
// 7 for digits (e.g, XXXX.XX), 7 for XFLOP/s
double flopsd = (double) flops;
uint32_t max_size = 7+1+7+1;
str = ecalloc(max_size, sizeof(char));
if(flops >= (double)1000000000000.0)
snprintf(str, max_size, "%.2f TFLOP/s", flops/1000000000000);
else if(flops >= 1000000000.0)
snprintf(str, max_size, "%.2f GFLOP/s", flops/1000000000);
if(flopsd >= (double)1000000000000.0)
snprintf(str, max_size, "%.2f TFLOP/s", flopsd/1000000000000);
else if(flopsd >= 1000000000.0)
snprintf(str, max_size, "%.2f GFLOP/s", flopsd/1000000000);
else
snprintf(str, max_size, "%.2f MFLOP/s", flops/1000000);
snprintf(str, max_size, "%.2f MFLOP/s", flopsd/1000000);
return str;
}

View File

@@ -115,6 +115,7 @@ struct cpuInfo {
struct cache* cach;
struct topology* topo;
struct features* feat;
int64_t peak_performance;
#if defined(ARCH_X86) || defined(ARCH_PPC)
// CPU name from model
@@ -161,7 +162,7 @@ char* get_str_l1d(struct cache* cach);
char* get_str_l2(struct cache* cach);
char* get_str_l3(struct cache* cach);
char* get_str_freq(struct frequency* freq);
char* get_str_peak_performance(double flops, bool valid_pp);
char* get_str_peak_performance(int64_t flops);
void init_topology_struct(struct topology* topo, struct cache* cach);
void init_cache_struct(struct cache* cach);

View File

@@ -446,9 +446,6 @@ bool print_cpufetch_x86(struct cpuInfo* cpu, STYLE s, struct colors* cs) {
if(art == NULL)
return false;
double flops;
bool valid_pp = get_peak_performance(cpu, cpu->topo, get_freq(cpu->freq), &flops);
char* uarch = get_str_uarch(cpu);
char* manufacturing_process = get_str_process(cpu);
char* sockets = get_str_sockets(cpu->topo);
@@ -463,7 +460,7 @@ bool print_cpufetch_x86(struct cpuInfo* cpu, STYLE s, struct colors* cs) {
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(flops, valid_pp);
char* pp = get_str_peak_performance(cpu->peak_performance);
setAttribute(art,ATTRIBUTE_NAME,cpu_name);
if(cpu->hv->present) {
@@ -570,9 +567,6 @@ bool print_cpufetch_ppc(struct cpuInfo* cpu, STYLE s, struct colors* cs) {
if(art == NULL)
return false;
double flops;
bool valid_pp = get_peak_performance(cpu, cpu->topo, get_freq(cpu->freq), &flops);
char* uarch = get_str_uarch(cpu);
char* manufacturing_process = get_str_process(cpu);
char* sockets = get_str_sockets(cpu->topo);
@@ -586,7 +580,7 @@ bool print_cpufetch_ppc(struct cpuInfo* cpu, STYLE s, struct colors* cs) {
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(flops, valid_pp);
char* pp = get_str_peak_performance(cpu->peak_performance);
if(cpu_name != NULL) {
setAttribute(art,ATTRIBUTE_NAME,cpu_name);
@@ -792,9 +786,7 @@ bool print_cpufetch_arm(struct cpuInfo* cpu, STYLE s, struct colors* cs) {
}
}
}
double flops;
bool valid_pp = get_peak_performance(cpu, &flops);
char* pp = get_str_peak_performance(flops, valid_pp);
char* pp = get_str_peak_performance(cpu->peak_performance);
setAttribute(art,ATTRIBUTE_PEAK,pp);
if(art->n_attributes_set > NUMBER_OF_LINES) {