From 79ce7c4553f752269a038fd53fec871cef3bcb02 Mon Sep 17 00:00:00 2001 From: Patrick Bellasi Date: Thu, 24 Jul 2014 17:28:54 +0100 Subject: [PATCH] Fix CPU affinity mask To properly identify the initial PState of each CPU, the idlestat_wake_all function is used to force an idle state exit on all CPUs by pinning idlestat on each CPUs. However, this routine forgets to recover the original mask at the end of the pinning process. This patch solve this issue, by properly recovering the original CPU affinity mask. Moreover, it avoids to wake up CPUs that will not be used to run the workload. Signed-off-by: Patrick Bellasi --- idlestat.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/idlestat.c b/idlestat.c index 98c1c87..8c5d1f4 100644 --- a/idlestat.c +++ b/idlestat.c @@ -1150,6 +1150,7 @@ static int idlestat_wake_all(void) { int rcpu, i, ret; cpu_set_t cpumask; + cpu_set_t original_cpumask; ret = sysconf(_SC_NPROCESSORS_CONF); if (ret < 0) @@ -1159,18 +1160,28 @@ static int idlestat_wake_all(void) if (rcpu < 0) return -1; + /* Keep track of the CPUs we will run on */ + sched_getaffinity(0, sizeof(original_cpumask), &original_cpumask); + for (i = 0; i < ret; i++) { /* Pointless to wake up ourself */ if (i == rcpu) continue; + /* Pointless to wake CPUs we will not run on */ + if (!CPU_ISSET(i, &original_cpumask)) + continue; + CPU_ZERO(&cpumask); CPU_SET(i, &cpumask); sched_setaffinity(0, sizeof(cpumask), &cpumask); } + /* Enable all the CPUs of the original mask */ + sched_setaffinity(0, sizeof(original_cpumask), &original_cpumask); + return 0; } -- 1.7.9.5