mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Paul Jackson <pj@sgi.com>
To: Andrew Morton <akpm@osdl.org>
Cc: Paul Jackson <pj@sgi.com>, Simon Derr <Simon.Derr@bull.net>,
	linux-kernel@vger.kernel.org
Subject: [Patch 1/4] cpusets display allowed masks in proc status
Date: Sat, 11 Sep 2004 01:28:14 -0700 (PDT)	[thread overview]
Message-ID: <20040911082816.10372.16867.91982@sam.engr.sgi.com> (raw)
In-Reply-To: <20040911082810.10372.86008.84920@sam.engr.sgi.com>

Should have done this earlier - the cpus_allowed and mems_allowed
values for each task are not always obvious from the tasks cpuset
settings, for various reasons, including:

  1) a task might use sched_setaffinity, mbind or set_mempolicy
     to restrain its placement to less than its cpuset, or
  2) various temporary changes to cpus_allowed are done by
     kernel internal code, or
  3) attaching a task to a cpuset doesn't change its mems_allowed
     until the next time that task needs kernel memory, or
  4) changing a cpusets 'cpus' doesn't change the cpus_allowed of
     the tasks attached to it until those tasks are reattached
     to that cpuset (to avoid a hook in the hotpath scheduler
     code in the kernel).

So it is useful, when learning and making new uses of cpusets and
placement to be able to see what are the current value of a tasks
cpus_allowed and mems_allowed, which are the actual placement used
by the kernel scheduler and memory allocator.

The cpus_allowed and mems_allowed values are needed by user space
apps that are micromanaging placement, such as when moving an app to a
different cpuset, and trying to recreate the cpuset-relative placement
obtained by that app within its cpuset using sched_setaffinity,
mbind and set_mempolicy.

The cpus_allowed value is also available via the sched_getaffinity
system call.  But since the entire rest of the cpuset API, including
the display of mems_allowed added here, is via an ascii style
presentation in /proc and /dev/cpuset, it is worth the extra couple
lines of code to display cpus_allowed in the same way.

This patch adds the display of these two fields to the 'status'
file in the /proc/<pid> directory of each task.  The fields are only
added if CONFIG_CPUSETS is enabled (which is also needed to define
the mems_allowed field of each task).  The new output lines look like:

  $ tail -2 /proc/1/status
  Cpus_allowed:   ffffffff,ffffffff,ffffffff,ffffffff
  Mems_allowed:   ffffffff,ffffffff

Signed-off-by: Paul Jackson <pj@sgi.com>

Index: 2.6.9-rc1-mm4/fs/proc/array.c
===================================================================
--- 2.6.9-rc1-mm4.orig/fs/proc/array.c	2004-09-10 09:11:33.000000000 -0700
+++ 2.6.9-rc1-mm4/fs/proc/array.c	2004-09-10 15:27:23.000000000 -0700
@@ -73,6 +73,7 @@
 #include <linux/highmem.h>
 #include <linux/file.h>
 #include <linux/times.h>
+#include <linux/cpuset.h>
 
 #include <asm/uaccess.h>
 #include <asm/pgtable.h>
@@ -295,6 +296,7 @@ int proc_pid_status(struct task_struct *
 	}
 	buffer = task_sig(task, buffer);
 	buffer = task_cap(task, buffer);
+	buffer = cpuset_task_status_allowed(task, buffer);
 #if defined(CONFIG_ARCH_S390)
 	buffer = task_show_regs(task, buffer);
 #endif
Index: 2.6.9-rc1-mm4/include/linux/cpuset.h
===================================================================
--- 2.6.9-rc1-mm4.orig/include/linux/cpuset.h	2004-09-10 09:11:33.000000000 -0700
+++ 2.6.9-rc1-mm4/include/linux/cpuset.h	2004-09-10 15:27:23.000000000 -0700
@@ -25,6 +25,7 @@ void cpuset_restrict_to_mems_allowed(uns
 int cpuset_zonelist_valid_mems_allowed(struct zonelist *zl);
 int cpuset_zone_allowed(struct zone *z);
 extern struct file_operations proc_cpuset_operations;
+extern char *cpuset_task_status_allowed(struct task_struct *task, char *buffer);
 
 #else /* !CONFIG_CPUSETS */
 
@@ -52,6 +53,12 @@ static inline int cpuset_zone_allowed(st
 	return 1;
 }
 
+static inline char *cpuset_task_status_allowed(struct task_struct *task,
+							char *buffer)
+{
+	return buffer;
+}
+
 #endif /* !CONFIG_CPUSETS */
 
 #endif /* _LINUX_CPUSET_H */
Index: 2.6.9-rc1-mm4/kernel/cpuset.c
===================================================================
--- 2.6.9-rc1-mm4.orig/kernel/cpuset.c	2004-09-10 15:27:03.000000000 -0700
+++ 2.6.9-rc1-mm4/kernel/cpuset.c	2004-09-10 15:27:23.000000000 -0700
@@ -1495,3 +1495,15 @@ struct file_operations proc_cpuset_opera
 	.llseek		= seq_lseek,
 	.release	= single_release,
 };
+
+/* Display task cpus_allowed, mems_allowed in /proc/<pid>/status file. */
+char *cpuset_task_status_allowed(struct task_struct *task, char *buffer)
+{
+	buffer += sprintf(buffer, "Cpus_allowed:\t");
+	buffer += cpumask_scnprintf(buffer, PAGE_SIZE, task->cpus_allowed);
+	buffer += sprintf(buffer, "\n");
+	buffer += sprintf(buffer, "Mems_allowed:\t");
+	buffer += nodemask_scnprintf(buffer, PAGE_SIZE, task->mems_allowed);
+	buffer += sprintf(buffer, "\n");
+	return buffer;
+}

-- 
                          I won't rest till it's the best ...
                          Programmer, Linux Scalability
                          Paul Jackson <pj@sgi.com> 1.650.933.1373

  reply	other threads:[~2004-09-11  8:29 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-09-11  8:28 [Patch 0/4] four small cpuset patches Paul Jackson
2004-09-11  8:28 ` Paul Jackson [this message]
2004-09-11  8:28 ` [Patch 2/4] cpusets simplify cpus_allowed setting in attach Paul Jackson
2004-09-11  8:28 ` [Patch 3/4] cpusets remove useless validation check Paul Jackson
2004-09-11  8:28 ` [Patch 4/4] cpusets top mask just online, not all possible Paul Jackson
2004-09-11 14:10   ` Anton Blanchard
2004-09-11 17:07     ` Paul Jackson
2004-09-11 17:28       ` Dave Hansen
2004-09-12  2:21         ` Paul Jackson
2004-09-12  4:43           ` Dave Hansen
2004-09-12  5:35             ` Paul Jackson
2004-09-12  5:42             ` Paul Jackson
2004-09-11 17:39       ` Dave Hansen
2004-09-11 18:55       ` Andi Kleen
2004-09-12  2:29         ` Paul Jackson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20040911082816.10372.16867.91982@sam.engr.sgi.com \
    --to=pj@sgi.com \
    --cc=Simon.Derr@bull.net \
    --cc=akpm@osdl.org \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®