From 05c4a4c9451b7b07577255f7927cec6d70f2cf8d Mon Sep 17 00:00:00 2001 From: Burt P Date: Thu, 10 Aug 2017 11:20:16 -0500 Subject: Separate processor name and description + count cores and threads * add cpu_procs_cores_threads() function to get counts from sysfs/topology * each platform must now provide processor_name() and processor_describe() * processor_name_default(): returns a list of unique processor->model_name * processor_describe_default(): returns "N physical; M cores; L threads" * processor_describe_by_counting_names(): returns a list of unique processor->model_name with Nx prefix (ex: "4x ARM Cortex A53 + 4x ARM Cortex A33") * x86: _name and _describe use defaults * arm: _name returns name of SOC, if available, _describe returns processor_describe_by_counting_names() * all other platforms: _name and _describe use defaults * Computer module summary now shows both name and description for CPU Signed-off-by: Burt P --- modules/devices/cpu_util.c | 38 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 36 insertions(+), 2 deletions(-) (limited to 'modules/devices/cpu_util.c') diff --git a/modules/devices/cpu_util.c b/modules/devices/cpu_util.c index 123b325f..6a689a4e 100644 --- a/modules/devices/cpu_util.c +++ b/modules/devices/cpu_util.c @@ -21,6 +21,10 @@ #include "hardinfo.h" #include "cpu_util.h" +#include "cpubits.c" + +#define CPU_TOPO_NULL -9877 + const gchar *byte_order_str() { #if G_BYTE_ORDER == G_LITTLE_ENDIAN return _("Little Endian"); @@ -61,6 +65,38 @@ gint get_cpu_int(const char* item, int cpuid, int null_val) { return ret; } +int cpu_procs_cores_threads(int *p, int *c, int *t) { + cpubits *threads, *cores, *packs; + char *tmp; + int i, m, pack_id, core_id; + g_file_get_contents("/sys/devices/system/cpu/present", &tmp, NULL, NULL); + if (tmp != NULL) { + threads = cpubits_from_str(tmp); + cores = cpubits_from_str(""); + packs = cpubits_from_str(""); + m = cpubits_max(threads); + for (i = 0; i <= m; i++) { + pack_id = get_cpu_int("topology/physical_package_id", i, CPU_TOPO_NULL); + core_id = get_cpu_int("topology/core_id", i, CPU_TOPO_NULL); + if (pack_id >= 0) { CPUBIT_SET(packs, pack_id); } + if (core_id >= 0) { CPUBIT_SET(cores, core_id); } + } + *t = cpubits_count(threads); + *c = cpubits_count(cores); + *p = cpubits_count(packs); + if (!*c) *c = 1; + if (!*p) *p = 1; + free(threads); + free(cores); + free(packs); + free(tmp); + return 1; + } else { + *p = *c = *t = -1; + return 0; + } +} + cpufreq_data *cpufreq_new(gint id) { cpufreq_data *cpufd; @@ -97,7 +133,6 @@ void cpufreq_free(cpufreq_data *cpufd) g_free(cpufd); } -#define CPU_TOPO_NULL -9877 cpu_topology_data *cputopo_new(gint id) { cpu_topology_data *cputd; @@ -119,7 +154,6 @@ void cputopo_free(cpu_topology_data *cputd) g_free(cputd); } - gchar *cpufreq_section_str(cpufreq_data *cpufd) { if (cpufd == NULL) -- cgit v1.2.3