diff options
Diffstat (limited to 'modules/devices/cpu_util.c')
-rw-r--r-- | modules/devices/cpu_util.c | 38 |
1 files changed, 36 insertions, 2 deletions
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) |