From: Tim Chen <tim.c.chen@linux.intel.com>
To: Peter Zijlstra <peterz@infradead.org>, Ingo Molnar <mingo@redhat.com>
Cc: Tim Chen <tim.c.chen@linux.intel.com>,
Vincent Guittot <vincent.guittot@linaro.org>,
Qais Yousef <qyousef@layalina.io>,
K Prateek Nayak <kprateek.nayak@amd.com>,
Juri Lelli <juri.lelli@redhat.com>,
Dietmar Eggemann <dietmar.eggemann@arm.com>,
Valentin Schneider <vschneid@redhat.com>,
Madadi Vineeth Reddy <vineethr@linux.ibm.com>,
Shrikanth Hegde <sshegde@linux.ibm.com>,
Jianyong Wu <jianyong.wu@outlook.com>,
Yangyu Chen <cyy@cyyself.name>,
Tingyin Duan <tingyin.duan@gmail.com>,
Vern Hao <vernhao@tencent.com>, Vern Hao <haoxing990@gmail.com>,
Len Brown <len.brown@intel.com>, Aubrey Li <aubrey.li@intel.com>,
Zhao Liu <zhao1.liu@intel.com>, Chen Yu <yu.chen.surf@gmail.com>,
Chen Yu <yu.c.chen@intel.com>,
Adam Li <adamli@os.amperecomputing.com>,
Aaron Lu <ziqianlu@bytedance.com>,
Tim Chen <tim.c.chen@intel.com>, Josh Don <joshdon@google.com>,
Luo Gengkun <luogengkun2@huawei.com>,
Gavin Guo <gavinguo@igalia.com>, Yi Lai <yi1.lai@intel.com>,
Ricardo Neri <ricardo.neri@intel.com>,
linux-kernel@vger.kernel.org, linux-api@vger.kernel.org
Subject: [RFC PATCH 5/7] sched/cache: Allow a process to enable cache aware scheduling via prctl
Date: Fri, 28 Aug 2026 15:29:12 -0700 [thread overview]
Message-ID: <14772dcf31c7eae3cec060fd6884579ed1c0f03b.1787955777.git.tim.c.chen@linux.intel.com> (raw)
In-Reply-To: <cover.1787955777.git.tim.c.chen@linux.intel.com>
Add the PR_SCHED_CACHE_ENABLE and PR_SCHED_CACHE_DISABLE subops to the
PR_SCHED_CACHE prctl interface, allowing a process to turn cache aware
scheduling on or off.
int prctl(PR_SCHED_CACHE, unsigned long subop, pid_t pid,
unsigned long cookie, unsigned long type);
/* disable cache aware scheduling for this task */
prctl(PR_SCHED_CACHE, PR_SCHED_CACHE_DISABLE, 0, 0, PIDTYPE_PID);
/* enable cache aware scheduling for this task */
prctl(PR_SCHED_CACHE, PR_SCHED_CACHE_ENABLE, 0, 0, PIDTYPE_PID);
pid 0 targets the calling task; otherwise the group of the given pid is
used. Both return -ENOENT when the task has no cache scheduling group.
Co-developed-by: Chen Yu <yu.c.chen@intel.com>
Signed-off-by: Chen Yu <yu.c.chen@intel.com>
Signed-off-by: Tim Chen <tim.c.chen@linux.intel.com>
---
include/linux/sched.h | 1 +
include/uapi/linux/prctl.h | 4 +++-
kernel/sched/cache_sched.c | 15 +++++++++++++++
kernel/sched/fair.c | 6 ++++++
4 files changed, 25 insertions(+), 1 deletion(-)
diff --git a/include/linux/sched.h b/include/linux/sched.h
index 79f0079c3aa1..1529730c91a5 100644
--- a/include/linux/sched.h
+++ b/include/linux/sched.h
@@ -2399,6 +2399,7 @@ struct sched_cache_group {
unsigned long next_scan;
unsigned long footprint;
int cpu;
+ int enabled;
refcount_t refcnt;
struct rcu_head rcu;
} ____cacheline_aligned_in_smp;
diff --git a/include/uapi/linux/prctl.h b/include/uapi/linux/prctl.h
index fed7bb028f9a..3fb31c4ab7b5 100644
--- a/include/uapi/linux/prctl.h
+++ b/include/uapi/linux/prctl.h
@@ -421,6 +421,8 @@ struct prctl_mm_map {
# define PR_SCHED_CACHE_GET 0
# define PR_SCHED_CACHE_CREATE 1
# define PR_SCHED_CACHE_SHARE_FROM 2
-# define PR_SCHED_CACHE_MAX 3
+# define PR_SCHED_CACHE_DISABLE 3
+# define PR_SCHED_CACHE_ENABLE 4
+# define PR_SCHED_CACHE_MAX 5
#endif /* _LINUX_PRCTL_H */
diff --git a/kernel/sched/cache_sched.c b/kernel/sched/cache_sched.c
index d1932f0c5ee8..c4ec6c553cca 100644
--- a/kernel/sched/cache_sched.c
+++ b/kernel/sched/cache_sched.c
@@ -60,6 +60,7 @@ static void sched_cache_group_init(struct sched_cache_group *grp,
grp->next_scan = jiffies;
grp->nr_running_avg = 0;
grp->footprint = 0;
+ grp->enabled = 1;
refcount_set(&grp->refcnt, 1);
/*
* The update to grp->pcpu_sched should not be reordered
@@ -261,6 +262,20 @@ int sched_cache_prctl(int option, unsigned long arg2, unsigned long arg3,
}
switch (arg2) {
+ case PR_SCHED_CACHE_DISABLE:
+ case PR_SCHED_CACHE_ENABLE:
+ /*
+ * Setting a single task is OK, because the sched_cache_group is
+ * shared by multiple tasks, setting one equals to setting all.
+ */
+ grp = task_cache_group_get(dst);
+ if (!grp) {
+ err = -ENOENT;
+ goto out_task;
+ }
+ WRITE_ONCE(grp->enabled, arg2 == PR_SCHED_CACHE_ENABLE);
+
+ goto out_group;
case PR_SCHED_CACHE_GET: {
unsigned long id = 0;
diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
index d422b62ba987..e7c8b031946c 100644
--- a/kernel/sched/fair.c
+++ b/kernel/sched/fair.c
@@ -1652,6 +1652,9 @@ static int get_pref_llc(struct task_struct *p, struct sched_cache_group *grp)
if (!grp)
return -1;
+ if (!READ_ONCE(grp->enabled))
+ return -1;
+
mm_sched_cpu = READ_ONCE(grp->cpu);
if (mm_sched_cpu != -1) {
mm_sched_llc = llc_id(mm_sched_cpu);
@@ -1743,6 +1746,9 @@ static void task_tick_cache(struct rq *rq, struct task_struct *p)
!grp->pcpu_sched)
return;
+ if (!READ_ONCE(grp->enabled))
+ return;
+
epoch = rq->cpu_epoch;
/* avoid moving backwards */
if (time_after_eq(grp->epoch, epoch))
--
2.32.0
next prev parent reply other threads:[~2026-08-28 22:23 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-28 22:29 [RFC PATCH 0/7] sched/cache: Per-task control of " Tim Chen
2026-08-28 22:29 ` [RFC PATCH 1/7] sched/cache: Decouple sched_cache_group from mm Tim Chen
2026-08-28 22:29 ` [RFC PATCH 2/7] sched/cache: Introduce task_struct->sched_cache_grp Tim Chen
2026-08-28 22:29 ` [RFC PATCH 3/7] sched/cache: Extract sched_cache_alloc_group() helper Tim Chen
2026-08-28 22:29 ` [RFC PATCH 4/7] sched/cache: Add prctl to manage per process cache scheduling groups Tim Chen
2026-08-28 22:29 ` Tim Chen [this message]
2026-08-28 22:29 ` [RFC PATCH 6/7] sched/cache: Extend the enabled debugfs to more modes Tim Chen
2026-08-28 22:29 ` [RFC PATCH 7/7] sched/cache: Documentation: document the PR_SCHED_CACHE prctl Tim Chen
2026-08-29 9:27 ` [RFC PATCH 0/7] sched/cache: Per-task control of cache aware scheduling via prctl Peter Zijlstra
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=14772dcf31c7eae3cec060fd6884579ed1c0f03b.1787955777.git.tim.c.chen@linux.intel.com \
--to=tim.c.chen@linux.intel.com \
--cc=adamli@os.amperecomputing.com \
--cc=aubrey.li@intel.com \
--cc=cyy@cyyself.name \
--cc=dietmar.eggemann@arm.com \
--cc=gavinguo@igalia.com \
--cc=haoxing990@gmail.com \
--cc=jianyong.wu@outlook.com \
--cc=joshdon@google.com \
--cc=juri.lelli@redhat.com \
--cc=kprateek.nayak@amd.com \
--cc=len.brown@intel.com \
--cc=linux-api@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=luogengkun2@huawei.com \
--cc=mingo@redhat.com \
--cc=peterz@infradead.org \
--cc=qyousef@layalina.io \
--cc=ricardo.neri@intel.com \
--cc=sshegde@linux.ibm.com \
--cc=tim.c.chen@intel.com \
--cc=tingyin.duan@gmail.com \
--cc=vernhao@tencent.com \
--cc=vincent.guittot@linaro.org \
--cc=vineethr@linux.ibm.com \
--cc=vschneid@redhat.com \
--cc=yi1.lai@intel.com \
--cc=yu.c.chen@intel.com \
--cc=yu.chen.surf@gmail.com \
--cc=zhao1.liu@intel.com \
--cc=ziqianlu@bytedance.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
all inboxes | Powered by JetHome®