Changed sysfs CPU cores detection based on thread_siblings_list
This commit is contained in:
parent
696e5bbe87
commit
86d6046bbd
|
@ -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;
|
||||
|
|
42
src/sysfs.c
42
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);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue