diff options
author | Ondrej Čerman | 2020-06-06 20:11:47 +0200 |
---|---|---|
committer | Ondrej Čerman | 2020-06-07 12:21:21 +0200 |
commit | 86d6046bbd3ebb110465bb0ccd009dbc86e71d69 (patch) | |
tree | a00a6693e39861d9106f5fa189e9b9c7fb210af4 | |
parent | 696e5bbe87f94e64afc307b436172cd852e17b35 (diff) |
Changed sysfs CPU cores detection based on thread_siblings_listsysdet2
-rw-r--r-- | src/ss/os.c | 4 | ||||
-rw-r--r-- | src/sysfs.c | 42 |
2 files changed, 37 insertions, 9 deletions
diff --git a/src/ss/os.c b/src/ss/os.c index a3ee7a6..8543c5f 100644 --- a/src/ss/os.c +++ b/src/ss/os.c @@ -15,11 +15,11 @@ gfloat *core_freq; gfloat *core_freq_min; gfloat *core_freq_max; -static gdouble get_frequency(guint coreid) { +static gdouble get_frequency(guint corei) { gchar *data; gdouble freq; - if (!g_file_get_contents(frq_files[coreid], &data, NULL, NULL)) + if (!g_file_get_contents(frq_files[corei], &data, NULL, NULL)) return 0.0; freq = atoi(data) / 1000000.0; diff --git a/src/sysfs.c b/src/sysfs.c index c7c4803..a6cc675 100644 --- a/src/sysfs.c +++ b/src/sysfs.c @@ -5,13 +5,13 @@ #include "sysfs.h" #include "zenmonitor.h" -#define CORES_MAX 256 +#define CPUD_MAX 512 struct bitset { - guint bits[CORES_MAX/32]; + guint bits[CPUD_MAX/32]; }; static int bitset_set(struct bitset *set, int id) { - if (id < CORES_MAX) { + if (id < CPUD_MAX) { int v = (set->bits[id/32] >> (id & 31)) & 1; set->bits[id/32] |= 1 << (id & 31); @@ -21,16 +21,19 @@ static int bitset_set(struct bitset *set, int id) { } static int cmp_cpudev(const void *ap, const void *bp) { - return ((struct cpudev *)ap)->coreid - ((struct cpudev *)bp)->coreid; + return ((struct cpudev *)ap)->cpuid - ((struct cpudev *)bp)->cpuid; } struct cpudev* get_cpu_dev_ids(void) { struct cpudev *cpu_dev_ids; - gshort coreid, cpuid; + gshort coreid, cpuid, siblingid; GDir *dir; const gchar *entry; gchar *filename, *buffer; + gchar **cpusiblings; + gchar **ptr; guint cores; + gboolean found; struct bitset seen = { 0 }; int i; @@ -48,15 +51,40 @@ struct cpudev* get_cpu_dev_ids(void) { continue; } + found = FALSE; + filename = g_build_filename(SYSFS_DIR_CPUS, entry, "topology", "core_id", NULL); if (g_file_get_contents(filename, &buffer, NULL, NULL)) { coreid = (gshort) atoi(buffer); - if (i < cores && !bitset_set(&seen, coreid)) { - cpu_dev_ids[i++] = (struct cpudev) { coreid, cpuid }; + g_free(filename); + g_free(buffer); + + filename = g_build_filename(SYSFS_DIR_CPUS, entry, "topology", "thread_siblings_list", NULL); + if (g_file_get_contents(filename, &buffer, NULL, NULL)) { + cpusiblings = g_strsplit(buffer, ",", -1); + found = TRUE; + + // check whether cpu device is not for SMT thread sibling + for (ptr = cpusiblings; *ptr; ptr++) { + siblingid = (gshort) atoi(*ptr); + + // let's save the cpu device with lower number + if (siblingid < cpuid) + cpuid = siblingid; + + if (bitset_set(&seen, siblingid)) { + found = FALSE; + } + } + g_strfreev(cpusiblings); } } + if (found && i < cores) { + cpu_dev_ids[i++] = (struct cpudev) { coreid, cpuid }; + } + g_free(filename); g_free(buffer); } |