aboutsummaryrefslogtreecommitdiff
path: root/src/sysfs.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/sysfs.c')
-rw-r--r--src/sysfs.c42
1 files changed, 35 insertions, 7 deletions
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);
}