diff options
author | Dave Jones <davej@redhat.com> | 2011-02-22 15:46:13 -0500 |
---|---|---|
committer | Dave Jones <davej@redhat.com> | 2011-02-22 15:46:13 -0500 |
commit | cebafcef0cfeb0506100b4c1532bf779571f72ce (patch) | |
tree | 06819571b3a8dc34bb4a4c0a20fa418484e8d54b | |
parent | d0911c3cb894e8e0ba3b68dc88fec48f47d408de (diff) |
split topology code out to separate file
-rw-r--r-- | Makefile | 1 | ||||
-rw-r--r-- | topology.c | 107 | ||||
-rw-r--r-- | x86info.c | 99 | ||||
-rw-r--r-- | x86info.h | 3 |
4 files changed, 111 insertions, 99 deletions
@@ -89,6 +89,7 @@ X86INFO_SRC =\ mtrr.c \ apic.c \ connector.c\ + topology.c\ \ bench/benchmarks.c\ bench/MHz.c diff --git a/topology.c b/topology.c new file mode 100644 index 0000000..86ad05d --- /dev/null +++ b/topology.c @@ -0,0 +1,107 @@ +/* + * (C) 2011 Dave Jones. + * + * Licensed under the terms of the GNU GPL License version 2. + */ + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include "x86info.h" + +static char * corenum(int num) +{ + switch (num) { + case 1: return ("single"); + case 2: return ("dual"); + case 3: return ("tri"); + case 4: return ("quad"); + case 6: return ("six"); + case 8: return ("eight"); + default: + return ("?"); + } +} + +void display_topology(struct cpudata *head) +{ + struct cpudata *cpu; + unsigned int threads_per_socket; + unsigned int i; + char *sockets; + + int num_sockets = 0; + + if (debug == 1) { + cpu = head; + printf("cpu->phys_proc_id: "); + for (i = 0; i < nrCPUs; i++) { + printf("%d, ", cpu->phys_proc_id); + cpu = cpu->next; + } + printf("\n"); + + cpu = head; + printf("cpu->x86_max_cores: "); + for (i = 0; i < nrCPUs; i++) { + printf("%d, ", cpu->x86_max_cores); + cpu = cpu->next; + } + printf("\n"); + + cpu = head; + printf("cpu->cpu_core_id: "); + for (i = 0; i < nrCPUs; i++) { + printf("%d, ", cpu->cpu_core_id); + cpu = cpu->next; + } + printf("\n"); + } + + sockets = malloc(nrCPUs); + if (sockets == NULL) + return; + + for (i = 0; i < nrCPUs; i++) + sockets[i]=0; + + cpu = head; + for (i = 0; i < nrCPUs; i++) { + sockets[cpu->phys_proc_id]++; + cpu = cpu->next; + } + + for (i = 0; i < nrCPUs; i++) { + if (debug == 1) + printf("Socket %d: %d threads\n", i, sockets[i]); + if (sockets[i] != 0) /* only count populated sockets */ + num_sockets++; + } + + /* Print a topology summary */ + cpu = head; + printf("Total processor threads: %d\n", sockets[0] * num_sockets); + printf("This system has %d ", num_sockets); + threads_per_socket = sockets[0]; + if (cpu->flags_edx & X86_FEATURE_HT) + if (cpu->num_siblings > 1) + threads_per_socket = sockets[0]/2; + + if (nrCPUs == 1) { + /* Handle the single CPU case */ + printf("processor"); + } else { + char *p; + p = corenum(threads_per_socket); + + if (strncmp("?", p, 1)) + printf("%s-core processor", corenum(threads_per_socket)); + else + printf("%d-core processor", threads_per_socket); + if (num_sockets > 1) + printf("s"); + } + + if (cpu->flags_edx & X86_FEATURE_HT && cpu->num_siblings > 1) + printf(" with hyper-threading (%d threads per core)", cpu->num_siblings); +} @@ -36,8 +36,6 @@ static int show_addr_sizes=0; unsigned int all_cpus = 0; -static int num_sockets = 0; - int debug = 0; int verbose = 0; int used_UP = 0; @@ -220,103 +218,6 @@ static void display_address_sizes(struct cpudata *cpu) } -static char * corenum(int num) -{ - switch (num) { - case 1: return ("single"); - case 2: return ("dual"); - case 3: return ("tri"); - case 4: return ("quad"); - case 6: return ("six"); - case 8: return ("eight"); - default: - return ("?"); - } -} - -static void display_topology(struct cpudata *head) -{ - struct cpudata *cpu; - unsigned int threads_per_socket; - unsigned int i; - char *sockets; - - if (debug == 1) { - cpu = head; - printf("cpu->phys_proc_id: "); - for (i = 0; i < nrCPUs; i++) { - printf("%d, ", cpu->phys_proc_id); - cpu = cpu->next; - } - printf("\n"); - - cpu = head; - printf("cpu->x86_max_cores: "); - for (i = 0; i < nrCPUs; i++) { - printf("%d, ", cpu->x86_max_cores); - cpu = cpu->next; - } - printf("\n"); - - cpu = head; - printf("cpu->cpu_core_id: "); - for (i = 0; i < nrCPUs; i++) { - printf("%d, ", cpu->cpu_core_id); - cpu = cpu->next; - } - printf("\n"); - } - - sockets = malloc(nrCPUs); - if (sockets == NULL) - return; - - for (i = 0; i < nrCPUs; i++) - sockets[i]=0; - - cpu = head; - for (i = 0; i < nrCPUs; i++) { - sockets[cpu->phys_proc_id]++; - cpu = cpu->next; - } - - for (i = 0; i < nrCPUs; i++) { - if (debug == 1) - printf("Socket %d: %d threads\n", i, sockets[i]); - if (sockets[i] != 0) /* only count populated sockets */ - num_sockets++; - } - - /* Print a summary */ - printf("Summary:\n"); - cpu = head; - printf("Total processor threads: %d\n", sockets[0] * num_sockets); - printf("This system has %d ", num_sockets); - threads_per_socket = sockets[0]; - if (cpu->flags_edx & X86_FEATURE_HT) - if (cpu->num_siblings > 1) - threads_per_socket = sockets[0]/2; - - if (nrCPUs == 1) { - /* Handle the single CPU case */ - printf("processor"); - } else { - char *p; - p = corenum(threads_per_socket); - - if (strncmp("?", p, 1)) - printf("%s-core processor", corenum(threads_per_socket)); - else - printf("%d-core processor", threads_per_socket); - if (num_sockets > 1) - printf("s"); - } - - if (cpu->flags_edx & X86_FEATURE_HT && cpu->num_siblings > 1) - printf(" with hyper-threading (%d threads per core)", cpu->num_siblings); -} - - static void display_detailed_info(struct cpudata *cpu) { bind_cpu(cpu); /* FIXME: Eventually remove once 'gather' has all the per-cpu stuff */ @@ -169,6 +169,7 @@ extern void decode_connector(enum connector type); extern void show_benchmarks(struct cpudata *cpu); extern void decode_serial_number(struct cpudata *cpu); +extern void display_topology(struct cpudata *head); extern void show_intel_topology(struct cpudata *cpu); void decode_AMD_cacheinfo(struct cpudata *cpu); @@ -197,6 +198,8 @@ extern struct cpudata *firstcpu; extern int used_UP; extern int user_is_root; +extern int debug; + #define X86_FEATURE_MTRR 1<<12 #define X86_FEATURE_APIC 1<<9 |