From: Waiman Long <longman@redhat.com>
To: Ingo Molnar <mingo@redhat.com>,
Peter Zijlstra <peterz@infradead.org>,
Juri Lelli <juri.lelli@redhat.com>,
Vincent Guittot <vincent.guittot@linaro.org>,
Dietmar Eggemann <dietmar.eggemann@arm.com>,
Steven Rostedt <rostedt@goodmis.org>,
Ben Segall <bsegall@google.com>, Mel Gorman <mgorman@suse.de>,
Valentin Schneider <vschneid@redhat.com>,
Jonathan Corbet <corbet@lwn.net>
Cc: linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org,
linux-doc@vger.kernel.org,
Andrew Morton <akpm@linux-foundation.org>,
David Hildenbrand <david@redhat.com>,
Catalin Marinas <catalin.marinas@arm.com>,
Nico Pache <npache@redhat.com>, Phil Auld <pauld@redhat.com>,
John Coleman <jocolema@redhat.com>,
Waiman Long <longman@redhat.com>
Subject: [PATCH v2 2/2] fs/proc: Show the content of task->user_cpus_ptr in /proc/<pid>/status
Date: Wed, 29 Oct 2025 17:55:55 -0400 [thread overview]
Message-ID: <20251029215555.1006595-3-longman@redhat.com> (raw)
In-Reply-To: <20251029215555.1006595-1-longman@redhat.com>
The task->user_cpus_ptr was introduced by commit b90ca8badbd1 ("sched:
Introduce task_struct::user_cpus_ptr to track requested affinity") to
keep track of user-requested CPU affinity. With commit da019032819a
("sched: Enforce user requested affinity"), user_cpus_ptr will
persistently affect how cpus_allowed will be set.
As child processes inherit the user_cpus_ptr setting from its parent,
they may not know that their user_cpus_ptr may be set changing their
CPU affinity in an unexpected way. Currently there is not an easy way
to figure out if their user_cpus_ptr is set even if they have never
called sched_setaffinity(2) themselves. So it makes sense to enable
users to see the presence of a previously set user_cpus_ptr so they
can do something about it without getting a surprise.
Add new "Cpus_user" and "Cpus_user_list" fields to /proc/<pid>/status
output via task_cpus_allowed() as the presence of user_cpus_ptr will
affect their cpus_allowed cpumask. The new fields will be empty if
user_cpus_ptr isn't set.
Signed-off-by: Waiman Long <longman@redhat.com>
---
Documentation/filesystems/proc.rst | 3 +++
fs/proc/array.c | 9 +++++++++
2 files changed, 12 insertions(+)
diff --git a/Documentation/filesystems/proc.rst b/Documentation/filesystems/proc.rst
index 0b86a8022fa1..4317c79a530f 100644
--- a/Documentation/filesystems/proc.rst
+++ b/Documentation/filesystems/proc.rst
@@ -291,6 +291,9 @@ It's slow but very precise.
SpeculationIndirectBranch indirect branch speculation mode
Cpus_allowed mask of CPUs on which this process may run
Cpus_allowed_list Same as previous, but in "list format"
+ Cpus_user mask of user requested CPUs from
+ sched_setaffinity(2), empty if not defined
+ Cpus_user_list Same as previous, but in "list format"
Mems_allowed mask of memory nodes allowed to this process
Mems_allowed_list Same as previous, but in "list format"
voluntary_ctxt_switches number of voluntary context switches
diff --git a/fs/proc/array.c b/fs/proc/array.c
index 2ae63189091e..17e700556daa 100644
--- a/fs/proc/array.c
+++ b/fs/proc/array.c
@@ -403,10 +403,19 @@ static inline void task_context_switch_counts(struct seq_file *m,
static void task_cpus_allowed(struct seq_file *m, struct task_struct *task)
{
+ cpumask_t *user_cpus = task->user_cpus_ptr;
+
seq_printf(m, "Cpus_allowed:\t%*pb\n",
cpumask_pr_args(&task->cpus_mask));
seq_printf(m, "Cpus_allowed_list:\t%*pbl\n",
cpumask_pr_args(&task->cpus_mask));
+
+ if (user_cpus) {
+ seq_printf(m, "Cpus_user:\t%*pb\n", cpumask_pr_args(user_cpus));
+ seq_printf(m, "Cpus_user_list:\t%*pbl\n", cpumask_pr_args(user_cpus));
+ } else {
+ seq_puts(m, "Cpus_user:\nCpus_user_list:\n");
+ }
}
static inline void task_core_dumping(struct seq_file *m, struct task_struct *task)
--
2.51.0
prev parent reply other threads:[~2025-10-29 21:56 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-10-29 21:55 [PATCH v2 0/2] sched/core: Show user_cpus_ptr & allow its reset Waiman Long
2025-10-29 21:55 ` [PATCH v2 1/2] sched/core: Enable full cpumask to clear user cpumask in sched_setaffinity() Waiman Long
2025-10-29 21:55 ` Waiman Long [this message]
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=20251029215555.1006595-3-longman@redhat.com \
--to=longman@redhat.com \
--cc=akpm@linux-foundation.org \
--cc=bsegall@google.com \
--cc=catalin.marinas@arm.com \
--cc=corbet@lwn.net \
--cc=david@redhat.com \
--cc=dietmar.eggemann@arm.com \
--cc=jocolema@redhat.com \
--cc=juri.lelli@redhat.com \
--cc=linux-doc@vger.kernel.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mgorman@suse.de \
--cc=mingo@redhat.com \
--cc=npache@redhat.com \
--cc=pauld@redhat.com \
--cc=peterz@infradead.org \
--cc=rostedt@goodmis.org \
--cc=vincent.guittot@linaro.org \
--cc=vschneid@redhat.com \
/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;
as well as URLs for NNTP newsgroup(s).