* [PATCH 1/2] sched_ext: Specialize the TID hashtable compare
2026-09-21 18:59 [PATCH 0/2] sched_ext: Specialize TID and scheduler hashtable compares Usama Arif
@ 2026-09-21 18:59 ` Usama Arif
2026-09-21 18:59 ` [PATCH 2/2] sched_ext: Specialize the scheduler " Usama Arif
2026-09-21 19:15 ` [PATCH 0/2] sched_ext: Specialize TID and scheduler hashtable compares Tejun Heo
2 siblings, 0 replies; 5+ messages in thread
From: Usama Arif @ 2026-09-21 18:59 UTC (permalink / raw)
To: arighi, bpf, bsegall, changwoo, dietmar.eggemann, etsal,
juri.lelli, kprateek.nayak, linux-kernel, mgorman, mingo, peterz,
rostedt, sched-ext, tj, vincent.guittot, void, vschneid,
yphbchou0911
Cc: Usama Arif
scx_tid_hash_params does not provide an object comparison function, so
rhashtable falls back to rhashtable_compare(). Although the key is one
naturally aligned u64, the generic comparison reads the key offset and
length from the table parameters at runtime and emits an out-of-line
memcmp() for each element walked.
scx_bpf_tid_to_task() can sit on hot scheduling paths. Supply an
obj_cmpfn so the const parameters passed into the inlined rhashtable
lookup specialize the comparison to a single equality test against
scx->tid.
The result is only tested against zero, so the ordering provided by
memcmp() is not observable. No functional change intended.
Suggested-by: Tejun Heo <tj@kernel.org>
Signed-off-by: Usama Arif <usama.arif@linux.dev>
---
kernel/sched/ext/ext.c | 11 +++++++++++
1 file changed, 11 insertions(+)
diff --git a/kernel/sched/ext/ext.c b/kernel/sched/ext/ext.c
index 646affba4e3c4..288d6b80bbca0 100644
--- a/kernel/sched/ext/ext.c
+++ b/kernel/sched/ext/ext.c
@@ -52,10 +52,21 @@ struct rhashtable scx_sched_hash;
#endif
/* see SCX_OPS_TID_TO_TASK */
+static __always_inline int scx_tid_cmpfn(struct rhashtable_compare_arg *arg,
+ const void *ptr)
+{
+ const struct sched_ext_entity *scx = ptr;
+
+ BUILD_BUG_ON(sizeof_field(struct sched_ext_entity, tid) != sizeof(u64));
+
+ return scx->tid != *(const u64 *)arg->key;
+}
+
static const struct rhashtable_params scx_tid_hash_params = {
.key_len = sizeof_field(struct sched_ext_entity, tid),
.key_offset = offsetof(struct sched_ext_entity, tid),
.head_offset = offsetof(struct sched_ext_entity, tid_hash_node),
+ .obj_cmpfn = scx_tid_cmpfn,
.insecure_elasticity = true, /* inserted/removed under scx_tasks_lock */
};
static struct rhashtable scx_tid_hash;
--
2.53.0-Meta
^ permalink raw reply [flat|nested] 5+ messages in thread* [PATCH 2/2] sched_ext: Specialize the scheduler hashtable compare
2026-09-21 18:59 [PATCH 0/2] sched_ext: Specialize TID and scheduler hashtable compares Usama Arif
2026-09-21 18:59 ` [PATCH 1/2] sched_ext: Specialize the TID hashtable compare Usama Arif
@ 2026-09-21 18:59 ` Usama Arif
2026-09-22 2:15 ` bot+bpf-ci
2026-09-21 19:15 ` [PATCH 0/2] sched_ext: Specialize TID and scheduler hashtable compares Tejun Heo
2 siblings, 1 reply; 5+ messages in thread
From: Usama Arif @ 2026-09-21 18:59 UTC (permalink / raw)
To: arighi, bpf, bsegall, changwoo, dietmar.eggemann, etsal,
juri.lelli, kprateek.nayak, linux-kernel, mgorman, mingo, peterz,
rostedt, sched-ext, tj, vincent.guittot, void, vschneid,
yphbchou0911
Cc: Usama Arif
scx_sched_hash_params does not provide an object comparison function,
so rhashtable falls back to rhashtable_compare(). Although the
sub-cgroup ID key is one naturally aligned u64, the generic comparison
reads the key offset and length from the table parameters at runtime and
emits an out-of-line memcmp() for each element walked.
Supply an obj_cmpfn so lookups specialize to a single equality test
against ops.sub_cgroup_id. ext.c and sub.c are included in the same
build_policy.c translation unit, so the compiler can fold the const
callback into scx_find_sub_sched() even though its source is in sub.c.
The result is only tested against zero, so the ordering provided by
memcmp() is not observable. No functional change intended.
Suggested-by: Tejun Heo <tj@kernel.org>
Signed-off-by: Usama Arif <usama.arif@linux.dev>
---
kernel/sched/ext/ext.c | 11 +++++++++++
1 file changed, 11 insertions(+)
diff --git a/kernel/sched/ext/ext.c b/kernel/sched/ext/ext.c
index 288d6b80bbca0..87fa09c71eb0f 100644
--- a/kernel/sched/ext/ext.c
+++ b/kernel/sched/ext/ext.c
@@ -41,10 +41,21 @@ struct scx_sched __rcu *scx_root;
LIST_HEAD(scx_sched_all);
#ifdef CONFIG_EXT_SUB_SCHED
+static __always_inline int scx_sched_cmpfn(struct rhashtable_compare_arg *arg,
+ const void *ptr)
+{
+ const struct scx_sched *sch = ptr;
+
+ BUILD_BUG_ON(sizeof_field(struct scx_sched, ops.sub_cgroup_id) != sizeof(u64));
+
+ return sch->ops.sub_cgroup_id != *(const u64 *)arg->key;
+}
+
const struct rhashtable_params scx_sched_hash_params = {
.key_len = sizeof_field(struct scx_sched, ops.sub_cgroup_id),
.key_offset = offsetof(struct scx_sched, ops.sub_cgroup_id),
.head_offset = offsetof(struct scx_sched, hash_node),
+ .obj_cmpfn = scx_sched_cmpfn,
.insecure_elasticity = true, /* inserted under scx_sched_lock */
};
--
2.53.0-Meta
^ permalink raw reply [flat|nested] 5+ messages in thread* Re: [PATCH 2/2] sched_ext: Specialize the scheduler hashtable compare
2026-09-21 18:59 ` [PATCH 2/2] sched_ext: Specialize the scheduler " Usama Arif
@ 2026-09-22 2:15 ` bot+bpf-ci
0 siblings, 0 replies; 5+ messages in thread
From: bot+bpf-ci @ 2026-09-22 2:15 UTC (permalink / raw)
To: usama.arif, arighi, bpf, bsegall, changwoo, dietmar.eggemann,
etsal, juri.lelli, kprateek.nayak, linux-kernel, mgorman, mingo,
peterz, rostedt, sched-ext, tj, vincent.guittot, void, vschneid,
yphbchou0911
Cc: usama.arif, ast, andrii, daniel, martin.lau, eddyz87,
yonghong.song, mason, ihor.solodrai
[-- Attachment #1: Type: text/plain, Size: 1477 bytes --]
> diff --git a/kernel/sched/ext/ext.c b/kernel/sched/ext/ext.c
> index 124bf827791ed..705a937268505 100644
> --- a/kernel/sched/ext/ext.c
> +++ b/kernel/sched/ext/ext.c
> @@ -41,10 +41,21 @@ struct scx_sched __rcu *scx_root;
> LIST_HEAD(scx_sched_all);
>
> #ifdef CONFIG_EXT_SUB_SCHED
> +static __always_inline int scx_sched_cmpfn(struct rhashtable_compare_arg *arg,
> + const void *ptr)
> +{
> + const struct scx_sched *sch = ptr;
> +
> + BUILD_BUG_ON(sizeof_field(struct scx_sched, ops.sub_cgroup_id) != sizeof(u64));
> +
> + return sch->ops.sub_cgroup_id != *(const u64 *)arg->key;
> +}
> +
This isn't a bug, but scx_sched_cmpfn() and scx_tid_cmpfn() (added in
the preceding patch, twenty lines below in this file) differ only in the
container type and field -- would a small generator macro be worth it
here, or is spelling both out clearer at two instances?
> const struct rhashtable_params scx_sched_hash_params = {
> .key_len = sizeof_field(struct scx_sched, ops.sub_cgroup_id),
> .key_offset = offsetof(struct scx_sched, ops.sub_cgroup_id),
> .head_offset = offsetof(struct scx_sched, hash_node),
> + .obj_cmpfn = scx_sched_cmpfn,
> .insecure_elasticity = true, /* inserted under scx_sched_lock */
> };
---
AI reviewed your patch. Please fix the bug or email reply why it's not a bug.
See: https://github.com/kernel-patches/vmtest/blob/master/ci/claude/README.md
CI run summary: https://github.com/kernel-patches/bpf/actions/runs/35676595280
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH 0/2] sched_ext: Specialize TID and scheduler hashtable compares
2026-09-21 18:59 [PATCH 0/2] sched_ext: Specialize TID and scheduler hashtable compares Usama Arif
2026-09-21 18:59 ` [PATCH 1/2] sched_ext: Specialize the TID hashtable compare Usama Arif
2026-09-21 18:59 ` [PATCH 2/2] sched_ext: Specialize the scheduler " Usama Arif
@ 2026-09-21 19:15 ` Tejun Heo
2 siblings, 0 replies; 5+ messages in thread
From: Tejun Heo @ 2026-09-21 19:15 UTC (permalink / raw)
To: Usama Arif
Cc: arighi, bpf, bsegall, changwoo, dietmar.eggemann, etsal,
juri.lelli, kprateek.nayak, linux-kernel, mgorman, mingo, peterz,
rostedt, sched-ext, tj, vincent.guittot, void, vschneid,
yphbchou0911
> Usama Arif (2):
> sched_ext: Specialize the TID hashtable compare
> sched_ext: Specialize the scheduler hashtable compare
Applied 1-2 to sched_ext/for-7.4 with the scx_tid_cmpfn() signature joined
onto one line.
Thanks.
--
tejun
^ permalink raw reply [flat|nested] 5+ messages in thread