From: Patrick Bellasi <patrick.bell...@arm.com>

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 <patrick.bell...@arm.com>
Signed-off-by: Daniel Lezcano <daniel.lezc...@linaro.org>
---
 idlestat.c |   11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/idlestat.c b/idlestat.c
index 0e0e1df..2a0c549 100644
--- a/idlestat.c
+++ b/idlestat.c
@@ -1210,6 +1210,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)
@@ -1219,18 +1220,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


_______________________________________________
linaro-dev mailing list
linaro-dev@lists.linaro.org
http://lists.linaro.org/mailman/listinfo/linaro-dev

Reply via email to