From daf10b5a0b1de3f80989f3d9f0a0894ac4fbabec Mon Sep 17 00:00:00 2001
From: Qiao Nuohan <qiaonuohan@cn.fujitsu.com>
Date: Mon, 25 Aug 2014 10:21:15 +0800
Subject: [PATCH 21/23] x86_64: modify ps only to display online cpus' idle
 tasks

this patch fix get_idle_threads and get_active_set to ignore tasks on
offline cpus, then command ps will not display idle tasks on offline
cpus

Signed-off-by: Qiao Nuohan <qiaonuohan@cn.fujitsu.com>
---
 task.c | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git a/task.c b/task.c
index 75b1964..65d7ebb 100755
--- a/task.c
+++ b/task.c
@@ -1051,6 +1051,8 @@ retry_pidhash:
 	 */
 	cnt = 0;
 	for (i = 0; i < kt->cpus; i++) {
+		if (!tt->idle_threads[i])
+			continue;
 		if (hq_enter(tt->idle_threads[i]))
 			cnt++;
 		else
@@ -1268,6 +1270,8 @@ retry_pid_hash:
 	 */
 	cnt = 0;
 	for (i = 0; i < kt->cpus; i++) {
+		if (!tt->idle_threads[i])
+			continue;
 		if (hq_enter(tt->idle_threads[i]))
 			cnt++;
 		else
@@ -1516,6 +1520,8 @@ retry_pid_hash:
 	 */
 	cnt = 0;
 	for (i = 0; i < kt->cpus; i++) {
+		if (!tt->idle_threads[i])
+			continue;
 		if (hq_enter(tt->idle_threads[i]))
 			cnt++;
 		else
@@ -1745,6 +1751,8 @@ retry_pid_hash:
 	 */
 	cnt = 0;
 	for (i = 0; i < kt->cpus; i++) {
+		if (!tt->idle_threads[i])
+			continue;
 		if (hq_enter(tt->idle_threads[i]))
 			cnt++;
 		else
@@ -2199,6 +2207,8 @@ retry_active:
 	 */
 	cnt = 0;
 	for (i = 0; i < kt->cpus; i++) {
+		if (!tt->idle_threads[i])
+			continue;
 		if (hq_enter(tt->active_set[i]))
 			cnt++;
 		else
@@ -6958,6 +6968,9 @@ get_idle_threads(ulong *tasklist, int nr_cpus)
 	    VALID_MEMBER(runqueue_idle)) {
 		runqbuf = GETBUF(SIZE(runqueue));
 		for (i = 0; i < nr_cpus; i++) {
+			if (check_offline_cpu(i))
+				continue;
+
 			if ((kt->flags & SMP) && (kt->flags & PER_CPU_OFF))
 				runq = rq_sp->value + kt->__per_cpu_offset[i];
 			else
@@ -7147,6 +7160,9 @@ get_active_set(void)
 		FREEBUF(vcpu_struct_buf);
 	} else if (VALID_MEMBER(runqueue_curr) && rq_sp) {
                	for (i = 0; i < kt->cpus; i++) {
+			if (check_offline_cpu(i))
+				continue;
+
                         if ((kt->flags & SMP) && (kt->flags & PER_CPU_OFF))
                                 runq = rq_sp->value + kt->__per_cpu_offset[i];
                         else
-- 
1.8.5.3

