[v1.02][x86] Adding support printing Intel hybrid CPUs

This commit is contained in:
Dr-Noob
2022-11-05 17:49:43 +00:00
parent ff5166ea2e
commit cec91a1e4d

View File

@@ -44,6 +44,8 @@ enum {
ATTRIBUTE_NAME, ATTRIBUTE_NAME,
#elif ARCH_ARM #elif ARCH_ARM
ATTRIBUTE_SOC, ATTRIBUTE_SOC,
#endif
#if defined(ARCH_X86) || defined(ARCH_ARM)
ATTRIBUTE_CPU_NUM, ATTRIBUTE_CPU_NUM,
#endif #endif
ATTRIBUTE_HYPERVISOR, ATTRIBUTE_HYPERVISOR,
@@ -75,6 +77,8 @@ static const char* ATTRIBUTE_FIELDS [] = {
"Part Number:", "Part Number:",
#elif ARCH_ARM #elif ARCH_ARM
"SoC:", "SoC:",
#endif
#if defined(ARCH_X86) || defined(ARCH_ARM)
"", "",
#endif #endif
"Hypervisor:", "Hypervisor:",
@@ -106,6 +110,8 @@ static const char* ATTRIBUTE_FIELDS_SHORT [] = {
"P/N:", "P/N:",
#elif ARCH_ARM #elif ARCH_ARM
"SoC:", "SoC:",
#endif
#if defined(ARCH_X86) || defined(ARCH_ARM)
"", "",
#endif #endif
"Hypervisor:", "Hypervisor:",
@@ -429,6 +435,7 @@ void print_ascii_generic(struct ascii* art, uint32_t la, int32_t termw, const ch
int attr_to_print = 0; int attr_to_print = 0;
int attr_type; int attr_type;
char* attr_value; char* attr_value;
int32_t beg_space;
int32_t space_right; int32_t space_right;
int32_t space_up = ((int)logo->height - (int)art->n_attributes_set)/2; int32_t space_up = ((int)logo->height - (int)art->n_attributes_set)/2;
int32_t space_down = (int)logo->height - (int)art->n_attributes_set - (int)space_up; int32_t space_down = (int)logo->height - (int)art->n_attributes_set - (int)space_up;
@@ -439,6 +446,7 @@ void print_ascii_generic(struct ascii* art, uint32_t la, int32_t termw, const ch
lbuf->buf = emalloc(sizeof(char) * LINE_BUFFER_SIZE); lbuf->buf = emalloc(sizeof(char) * LINE_BUFFER_SIZE);
lbuf->pos = 0; lbuf->pos = 0;
lbuf->chars = 0; lbuf->chars = 0;
bool add_space = false;
printf("\n"); printf("\n");
for(int32_t n=0; n < iters; n++) { for(int32_t n=0; n < iters; n++) {
@@ -473,9 +481,24 @@ void print_ascii_generic(struct ascii* art, uint32_t la, int32_t termw, const ch
attr_value = art->attributes[attr_to_print]->value; attr_value = art->attributes[attr_to_print]->value;
attr_to_print++; attr_to_print++;
space_right = 1 + (la - strlen(attribute_fields[attr_type])); if(attr_type == ATTRIBUTE_PEAK) {
printOut(lbuf, strlen(attribute_fields[attr_type]) + space_right + strlen(attr_value), add_space = false;
"%s%s%s%*s%s%s%s", logo->color_text[0], attribute_fields[attr_type], art->reset, space_right, "", logo->color_text[1], attr_value, art->reset); }
if(attr_type == ATTRIBUTE_CPU_NUM) {
printOut(lbuf, strlen(attr_value), "%s%s%s", logo->color_text[0], attr_value, art->reset);
add_space = true;
}
else {
beg_space = 0;
space_right = 2 + 1 + (la - strlen(attribute_fields[attr_type]));
if(add_space) {
beg_space = 2;
space_right -= 2;
}
printOut(lbuf, beg_space + strlen(attribute_fields[attr_type]) + space_right + strlen(attr_value),
"%*s%s%s%s%*s%s%s%s", beg_space, "", logo->color_text[0], attribute_fields[attr_type], art->reset, space_right, "", logo->color_text[1], attr_value, art->reset);
}
} }
printOutLine(lbuf, art, termw); printOutLine(lbuf, art, termw);
printf("\n"); printf("\n");
@@ -501,43 +524,47 @@ bool print_cpufetch_x86(struct cpuInfo* cpu, STYLE s, struct color** cs, struct
art->new_intel_logo = choose_new_intel_logo(cpu); art->new_intel_logo = choose_new_intel_logo(cpu);
// Step 1. Retrieve attributes (if some structures are NULL, like topo
// or cache, do not try to retrieve them)
uint32_t socket_num = 1; uint32_t socket_num = 1;
char* l1i, *l1d, *l2, *l3, *n_cores, *n_cores_dual, *sockets; char* l1i, *l1d, *l2, *l3, *n_cores, *n_cores_dual, *sockets;
l1i = l1d = l2 = l3 = n_cores = n_cores_dual = sockets = NULL; l1i = l1d = l2 = l3 = n_cores = n_cores_dual = sockets = NULL;
char* uarch = get_str_uarch(cpu);
char* manufacturing_process = get_str_process(cpu);
char* max_frequency = get_str_freq(cpu->freq);
char* cpu_name = get_str_cpu_name(cpu, fcpuname); char* cpu_name = get_str_cpu_name(cpu, fcpuname);
char* avx = get_str_avx(cpu); char* uarch = get_str_uarch(cpu);
char* fma = get_str_fma(cpu);
char* pp = get_str_peak_performance(cpu->peak_performance); char* pp = get_str_peak_performance(cpu->peak_performance);
char* manufacturing_process = get_str_process(cpu);
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);
}
// Step 2. Set attributes
setAttribute(art, ATTRIBUTE_NAME, cpu_name); setAttribute(art, ATTRIBUTE_NAME, cpu_name);
if(cpu->hv->present) { if(cpu->hv->present) {
setAttribute(art, ATTRIBUTE_HYPERVISOR, cpu->hv->hv_name); setAttribute(art, ATTRIBUTE_HYPERVISOR, cpu->hv->hv_name);
} }
setAttribute(art, ATTRIBUTE_UARCH, uarch); setAttribute(art, ATTRIBUTE_UARCH, uarch);
setAttribute(art, ATTRIBUTE_TECHNOLOGY, manufacturing_process); setAttribute(art, ATTRIBUTE_TECHNOLOGY, manufacturing_process);
struct cpuInfo* ptr = cpu;
for(int i = 0; i < cpu->num_cpus; ptr = ptr->next_cpu, i++) {
char* max_frequency = get_str_freq(ptr->freq);
char* avx = get_str_avx(ptr);
char* fma = get_str_fma(ptr);
char* cpu_num = emalloc(sizeof(char) * 9);
if(ptr->topo != NULL) {
sockets = get_str_sockets(ptr->topo);
n_cores = get_str_topology(ptr, ptr->topo, false);
n_cores_dual = get_str_topology(ptr, ptr->topo, true);
}
if(ptr->cach != NULL) {
l1i = get_str_l1i(ptr->cach);
l1d = get_str_l1d(ptr->cach);
l2 = get_str_l2(ptr->cach);
l3 = get_str_l3(ptr->cach);
}
sprintf(cpu_num, "CPU %d:", i+1);
setAttribute(art, ATTRIBUTE_CPU_NUM, cpu_num);
setAttribute(art, ATTRIBUTE_FREQUENCY, max_frequency); setAttribute(art, ATTRIBUTE_FREQUENCY, max_frequency);
if(cpu->topo != NULL) { if(ptr->topo != NULL) {
socket_num = get_nsockets(cpu->topo); socket_num = get_nsockets(ptr->topo);
if (socket_num > 1) { if (socket_num > 1) {
setAttribute(art, ATTRIBUTE_SOCKETS, sockets); setAttribute(art, ATTRIBUTE_SOCKETS, sockets);
setAttribute(art, ATTRIBUTE_NCORES, n_cores); setAttribute(art, ATTRIBUTE_NCORES, n_cores);
@@ -553,6 +580,7 @@ bool print_cpufetch_x86(struct cpuInfo* cpu, STYLE s, struct color** cs, struct
if(l1d != NULL) setAttribute(art, ATTRIBUTE_L1d, l1d); if(l1d != NULL) setAttribute(art, ATTRIBUTE_L1d, l1d);
if(l2 != NULL) setAttribute(art, ATTRIBUTE_L2, l2); if(l2 != NULL) setAttribute(art, ATTRIBUTE_L2, l2);
if(l3 != NULL) setAttribute(art, ATTRIBUTE_L3, l3); if(l3 != NULL) setAttribute(art, ATTRIBUTE_L3, l3);
}
setAttribute(art, ATTRIBUTE_PEAK, pp); setAttribute(art, ATTRIBUTE_PEAK, pp);
// Step 3. Print output // Step 3. Print output
@@ -571,12 +599,9 @@ bool print_cpufetch_x86(struct cpuInfo* cpu, STYLE s, struct color** cs, struct
print_ascii_generic(art, longest_attribute, term->w, attribute_fields); print_ascii_generic(art, longest_attribute, term->w, attribute_fields);
free(manufacturing_process); free(manufacturing_process);
free(max_frequency);
free(sockets); free(sockets);
free(n_cores); free(n_cores);
free(n_cores_dual); free(n_cores_dual);
free(avx);
free(fma);
free(l1i); free(l1i);
free(l1d); free(l1d);
free(l2); free(l2);