From: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
To: linux-kernel@vger.kernel.org, cgroups@vger.kernel.org,
rcu@vger.kernel.org, linux-doc@vger.kernel.org
Cc: "Sebastian Andrzej Siewior" <bigeasy@linutronix.de>,
"Jonathan Corbet" <corbet@lwn.net>,
"Shuah Khan" <skhan@linuxfoundation.org>,
"Randy Dunlap" <rdunlap@infradead.org>,
"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>,
"K Prateek Nayak" <kprateek.nayak@amd.com>,
"luca abeni" <luca.abeni@santannapisa.it>,
"Yuri Andriaccio" <yurand2000@gmail.com>,
"Yuri Andriaccio" <yuri.andriaccio@santannapisa.it>,
"Paul E. McKenney" <paulmck@kernel.org>,
"Frederic Weisbecker" <frederic@kernel.org>,
"Neeraj Upadhyay" <neeraj.upadhyay@kernel.org>,
"Joel Fernandes" <joelagnelf@nvidia.com>,
"Josh Triplett" <josh@joshtriplett.org>,
"Boqun Feng" <boqun@kernel.org>,
"Uladzislau Rezki" <urezki@gmail.com>,
"Mathieu Desnoyers" <mathieu.desnoyers@efficios.com>,
"Lai Jiangshan" <jiangshanlai@gmail.com>,
Zqiang <qiang.zhang@linux.dev>,
"Davidlohr Bueso" <dave@stgolabs.net>,
"Tejun Heo" <tj@kernel.org>,
"Johannes Weiner" <hannes@cmpxchg.org>,
"Michal Koutný" <mkoutny@suse.com>,
"Qais Yousef" <qyousef@layalina.io>,
"John Ogness" <john.ogness@linutronix.de>
Subject: [PATCH v3 7/8] sched: Add sysfs files for the per-CPU fair_server knobs
Date: Fri, 13 Nov 2026 11:50:28 +0100 [thread overview]
Message-ID: <20261113-sched_dl-v3-7-a76ffa1cdeee@linutronix.de> (raw)
In-Reply-To: <20261113-sched_dl-v3-0-a76ffa1cdeee@linutronix.de>
The fair_server exposes the runtime and period knobs per-CPU in the
debugfs folder. The debugfs interface is not a stable ABI.
Make the /sys/kernel/debug/sched/fair_server/cpu*/{period|runtime} knobs
available as /sys/kernel/sched/cpuX/{fair_server_period|fair_server_runtime}.
It adds a struct kobject to the rq and exposes only those two. The
per-runqueue folder is named `cpu' rather than `rq' since it might be
more intuitive to the user than `rq' or `runqueue'.
The set logic is pulled from the debugfs folder but it is still shared.
That debugfs logic could be removed (after providing the same for
ext-server) or symlinked for a while.
Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
---
kernel/sched/deadline.c | 152 +++++++++++++++++++++++++++++++++++++++++++++++-
kernel/sched/debug.c | 56 ++----------------
kernel/sched/sched.h | 8 +++
3 files changed, 163 insertions(+), 53 deletions(-)
diff --git a/kernel/sched/deadline.c b/kernel/sched/deadline.c
index 839ae9a6acf63..6cc1a5f53735f 100644
--- a/kernel/sched/deadline.c
+++ b/kernel/sched/deadline.c
@@ -4137,6 +4137,59 @@ void print_dl_stats(struct seq_file *m, int cpu)
print_dl_rq(m, cpu, &cpu_rq(cpu)->dl);
}
+static unsigned long dl_server_period_max = (1UL << 22) * NSEC_PER_USEC; /* ~4 seconds */
+static unsigned long dl_server_period_min = (100) * NSEC_PER_USEC; /* 100 us */
+
+int __sched_server_write_common(enum dl_param param, u64 value, struct rq *rq,
+ struct sched_dl_entity *dl_se, const char *sname)
+{
+ u64 old_runtime, runtime, period;
+ int retval = 0;
+
+ scoped_guard (rq_lock_irqsave, rq) {
+ old_runtime = runtime = dl_se->dl_runtime;
+ period = dl_se->dl_period;
+
+ switch (param) {
+ case DL_RUNTIME:
+ if (runtime == value)
+ break;
+ runtime = value;
+ break;
+ case DL_PERIOD:
+ if (value == period)
+ break;
+ period = value;
+ break;
+ }
+
+ if (runtime > period ||
+ period > dl_server_period_max ||
+ period < dl_server_period_min) {
+ return -EINVAL;
+ }
+
+ if (!cpu_online(cpu_of(rq)))
+ return -EBUSY;
+
+ update_rq_clock(rq);
+ dl_server_stop(dl_se);
+ retval = dl_server_apply_params(dl_se, runtime, period, 0);
+ dl_server_start(dl_se);
+
+ if (retval < 0)
+ return retval;
+ }
+ if (!!old_runtime ^ !!runtime) {
+ pr_info("%s server %sabled on CPU %d%s.\n",
+ sname,
+ runtime ? "en" : "dis",
+ cpu_of(rq),
+ runtime ? "" : ", system may malfunction due to starvation");
+ }
+ return 0;
+}
+
#define SCHED_ATTR(_name) \
static struct kobj_attribute sched_attr_## _name = \
__ATTR(_name, 0644, sched_attr_##_name##_show, sched_attr_##_name##_store)
@@ -4261,13 +4314,110 @@ static const struct attribute_group sched_global_attrs_group = {
.attrs = sched_global_attrs,
};
+/* RQ */
+#define RQ_ATTR(_name) \
+ static struct kobj_attribute rq_## _name = \
+ __ATTR(_name, 0644, rq_##_name##_show, rq_##_name##_store)
+
+#define kobj_to_rq(__kobj) container_of(__kobj, struct rq, rq_kobj)
+
+static ssize_t rq_fair_server_runtime_show(struct kobject *kobj, struct kobj_attribute *attr,
+ char *buf)
+{
+ struct rq *rq = kobj_to_rq(kobj);
+ struct sched_dl_entity *dl_se;
+
+ dl_se = &rq->fair_server;
+
+ return sysfs_emit(buf, "%llu\n", dl_se->dl_runtime);
+}
+
+static ssize_t rq_fair_server_runtime_store(struct kobject *kobj, struct kobj_attribute *attr,
+ const char *buf, size_t count)
+{
+ struct rq *rq = kobj_to_rq(kobj);
+ u64 val;
+ int ret;
+
+ ret = kstrtoull(buf, 10, &val);
+ if (ret)
+ return ret;
+
+ ret = __sched_server_write_common(DL_RUNTIME, val, rq, &rq->fair_server, "Fair");
+ if (ret)
+ return ret;
+ return count;
+}
+RQ_ATTR(fair_server_runtime);
+
+static ssize_t rq_fair_server_period_show(struct kobject *kobj, struct kobj_attribute *attr,
+ char *buf)
+{
+ struct rq *rq = kobj_to_rq(kobj);
+ struct sched_dl_entity *dl_se;
+
+ dl_se = &rq->fair_server;
+
+ return sysfs_emit(buf, "%llu\n", dl_se->dl_period);
+}
+
+static ssize_t rq_fair_server_period_store(struct kobject *kobj, struct kobj_attribute *attr,
+ const char *buf, size_t count)
+{
+ struct rq *rq = kobj_to_rq(kobj);
+ u64 val;
+ int ret;
+
+ ret = kstrtoull(buf, 10, &val);
+ if (ret)
+ return ret;
+
+ ret = __sched_server_write_common(DL_PERIOD, val, rq, &rq->fair_server, "Fair");
+ if (ret)
+ return ret;
+ return count;
+}
+RQ_ATTR(fair_server_period);
+
+static struct attribute *rq_attrs[] = {
+ &rq_fair_server_runtime.attr,
+ &rq_fair_server_period.attr,
+ NULL
+};
+ATTRIBUTE_GROUPS(rq);
+
+static const struct kobj_type rq_ktype = {
+ .sysfs_ops = &kobj_sysfs_ops,
+ .default_groups = rq_groups,
+};
+
+static int sched_create_rq_sysfs(struct kobject *sched_kobj)
+{
+ unsigned int cpu;
+ int ret;
+
+ for_each_possible_cpu(cpu) {
+ struct rq *rq = cpu_rq(cpu);
+
+ ret = kobject_init_and_add(&rq->rq_kobj, &rq_ktype, sched_kobj,
+ "cpu%d", cpu);
+ if (ret)
+ return ret;
+ }
+ return 0;
+}
+
static int __init sched_dl_init(void)
{
struct kobject *sched_kobj;
+ int ret;
sched_kobj = kobject_create_and_add("sched", kernel_kobj);
if (!sched_kobj)
return -ENOMEM;
- return sysfs_create_group(sched_kobj, &sched_global_attrs_group);
+ ret = sysfs_create_group(sched_kobj, &sched_global_attrs_group);
+ if (ret)
+ return ret;
+ return sched_create_rq_sysfs(sched_kobj);
}
late_initcall(sched_dl_init);
diff --git a/kernel/sched/debug.c b/kernel/sched/debug.c
index 1545139e52443..0e0782603a99a 100644
--- a/kernel/sched/debug.c
+++ b/kernel/sched/debug.c
@@ -363,23 +363,13 @@ static const struct file_operations sched_debug_fops = {
.release = seq_release,
};
-enum dl_param {
- DL_RUNTIME = 0,
- DL_PERIOD,
-};
-
-static unsigned long dl_server_period_max = (1UL << 22) * NSEC_PER_USEC; /* ~4 seconds */
-static unsigned long dl_server_period_min = (100) * NSEC_PER_USEC; /* 100 us */
-
static ssize_t sched_server_write_common(struct file *filp, const char __user *ubuf,
size_t cnt, loff_t *ppos, enum dl_param param,
void *server)
{
long cpu = (long) ((struct seq_file *) filp->private_data)->private;
struct sched_dl_entity *dl_se = (struct sched_dl_entity *)server;
- u64 old_runtime, runtime, period;
struct rq *rq = cpu_rq(cpu);
- int retval = 0;
size_t err;
u64 value;
@@ -387,48 +377,10 @@ static ssize_t sched_server_write_common(struct file *filp, const char __user *u
if (err)
return err;
- scoped_guard (rq_lock_irqsave, rq) {
- old_runtime = runtime = dl_se->dl_runtime;
- period = dl_se->dl_period;
-
- switch (param) {
- case DL_RUNTIME:
- if (runtime == value)
- break;
- runtime = value;
- break;
- case DL_PERIOD:
- if (value == period)
- break;
- period = value;
- break;
- }
-
- if (runtime > period ||
- period > dl_server_period_max ||
- period < dl_server_period_min) {
- return -EINVAL;
- }
-
- if (!cpu_active(cpu_of(rq)))
- return -EBUSY;
-
- update_rq_clock(rq);
- dl_server_stop(dl_se);
- retval = dl_server_apply_params(dl_se, runtime, period, 0);
- dl_server_start(dl_se);
-
- if (retval < 0)
- return retval;
- }
-
- if (!!old_runtime ^ !!runtime) {
- pr_info("%s server %sabled on CPU %d%s.\n",
- server == &rq->fair_server ? "Fair" : "Ext",
- runtime ? "en" : "dis",
- cpu_of(rq),
- runtime ? "" : ", system may malfunction due to starvation");
- }
+ err = __sched_server_write_common(param, value, rq, dl_se,
+ server == &rq->fair_server ? "Fair" : "Ext");
+ if (err)
+ return err;
*ppos += cnt;
return cnt;
diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h
index 966fe46fb38e7..661927a464c95 100644
--- a/kernel/sched/sched.h
+++ b/kernel/sched/sched.h
@@ -1434,6 +1434,7 @@ struct rq {
#endif
atomic_t nr_iowait;
+ struct kobject rq_kobj;
} __no_randomize_layout;
#ifdef CONFIG_FAIR_GROUP_SCHED
@@ -3509,6 +3510,13 @@ extern void print_cfs_rq(struct seq_file *m, int cpu, struct cfs_rq *cfs_rq);
extern void print_rt_rq(struct seq_file *m, int cpu, struct rt_rq *rt_rq);
extern void print_dl_rq(struct seq_file *m, int cpu, struct dl_rq *dl_rq);
+enum dl_param {
+ DL_RUNTIME = 0,
+ DL_PERIOD,
+};
+extern int __sched_server_write_common(enum dl_param param, u64 value, struct rq *rq,
+ struct sched_dl_entity *dl_se, const char *sname);
+
extern void resched_latency_warn(int cpu, u64 latency);
#ifdef CONFIG_NUMA_BALANCING
--
2.55.0
next prev parent reply other threads:[~2026-11-13 10:50 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-13 10:50 [PATCH v3 0/8] sched: RT throttling cleanup and a bit of documentation Sebastian Andrzej Siewior
2026-11-13 10:50 ` [PATCH v3 1/8] sched/deadline: Reject debugfs dl_server writes for not-active CPUs Sebastian Andrzej Siewior
2026-11-13 10:50 ` [PATCH v3 2/8] sched: Mark RT_GROUP_SCHED broken Sebastian Andrzej Siewior
2026-11-13 10:50 ` [PATCH v3 3/8] rcutorture: Don't try to disable to RT throttling Sebastian Andrzej Siewior
2026-11-13 10:50 ` [PATCH v3 4/8] sched: rcutorture: Allow to disable DL fair_server Sebastian Andrzej Siewior
2026-11-13 10:50 ` [PATCH v3 5/8] sched: Move DL's admission control to sysfs Sebastian Andrzej Siewior
2026-11-13 10:50 ` [PATCH v3 6/8] sched: Limit sysctl sched_rt_{period|runtime}_us to RT_GROUP_SCHED Sebastian Andrzej Siewior
2026-11-13 10:50 ` Sebastian Andrzej Siewior [this message]
2026-11-13 10:50 ` [PATCH v3 8/8] Documentation/sched: Add fairserver to sched-deadline Sebastian Andrzej Siewior
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=20261113-sched_dl-v3-7-a76ffa1cdeee@linutronix.de \
--to=bigeasy@linutronix.de \
--cc=boqun@kernel.org \
--cc=bsegall@google.com \
--cc=cgroups@vger.kernel.org \
--cc=corbet@lwn.net \
--cc=dave@stgolabs.net \
--cc=dietmar.eggemann@arm.com \
--cc=frederic@kernel.org \
--cc=hannes@cmpxchg.org \
--cc=jiangshanlai@gmail.com \
--cc=joelagnelf@nvidia.com \
--cc=john.ogness@linutronix.de \
--cc=josh@joshtriplett.org \
--cc=juri.lelli@redhat.com \
--cc=kprateek.nayak@amd.com \
--cc=linux-doc@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=luca.abeni@santannapisa.it \
--cc=mathieu.desnoyers@efficios.com \
--cc=mgorman@suse.de \
--cc=mingo@redhat.com \
--cc=mkoutny@suse.com \
--cc=neeraj.upadhyay@kernel.org \
--cc=paulmck@kernel.org \
--cc=peterz@infradead.org \
--cc=qiang.zhang@linux.dev \
--cc=qyousef@layalina.io \
--cc=rcu@vger.kernel.org \
--cc=rdunlap@infradead.org \
--cc=rostedt@goodmis.org \
--cc=skhan@linuxfoundation.org \
--cc=tj@kernel.org \
--cc=urezki@gmail.com \
--cc=vincent.guittot@linaro.org \
--cc=vschneid@redhat.com \
--cc=yurand2000@gmail.com \
--cc=yuri.andriaccio@santannapisa.it \
/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®