summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTejun Heo <tj@kernel.org>2026-07-13 22:18:43 -1000
committerTejun Heo <tj@kernel.org>2026-07-13 22:18:43 -1000
commit61d564fcdfcd664f623d4175738a6ccee654ca02 (patch)
tree60515a7db233e88ee977942568e1ccf1728ae4f2
parent147d1885f390bcfb929210814f86dc22b24c2631 (diff)
sched_ext: Assign a unique id to each scheduler instance
Neither a scx_sched pointer nor its cgroup id uniquely identifies a scheduler instance. A freed sched's memory can be reallocated, and a cgroup can detach one sched and attach another. Add a monotonic, never-reused u64 id. A later patch compares it to drop a slice request that outlived a change of a task's owning scheduler. Signed-off-by: Tejun Heo <tj@kernel.org> Reviewed-by: Andrea Righi <arighi@nvidia.com>
-rw-r--r--kernel/sched/ext/ext.c4
-rw-r--r--kernel/sched/ext/internal.h3
2 files changed, 7 insertions, 0 deletions
diff --git a/kernel/sched/ext/ext.c b/kernel/sched/ext/ext.c
index 151befdc9602..14775e288a6e 100644
--- a/kernel/sched/ext/ext.c
+++ b/kernel/sched/ext/ext.c
@@ -108,6 +108,9 @@ static bool dsq_is_rq_owned(struct scx_dispatch_q *dsq)
}
}
+/* Cursor for unique scx_sched instance ids. id 0 is reserved. */
+static atomic64_t scx_sched_id_cursor = ATOMIC64_INIT(0);
+
#ifdef CONFIG_EXT_SUB_SCHED
/*
* The sub sched being enabled. Used by scx_disable_and_exit_task() to exit
@@ -6502,6 +6505,7 @@ struct scx_sched *scx_alloc_and_add_sched(struct scx_enable_cmd *cmd,
level * sizeof(parent->ancestors[0]));
sch->ancestors[level] = sch;
sch->level = level;
+ sch->id = atomic64_inc_return(&scx_sched_id_cursor);
if (ops->timeout_ms)
sch->watchdog_timeout = msecs_to_jiffies(ops->timeout_ms);
diff --git a/kernel/sched/ext/internal.h b/kernel/sched/ext/internal.h
index e735812e77a5..ad98e3469b12 100644
--- a/kernel/sched/ext/internal.h
+++ b/kernel/sched/ext/internal.h
@@ -1445,6 +1445,9 @@ struct scx_sched {
struct list_head all;
+ /* unique instance id, monotonic and never reused */
+ u64 id;
+
#ifdef CONFIG_EXT_SUB_SCHED
struct rhash_head hash_node;