[PATCH 1/2] sched_ext: Specialize the TID hashtable compare
From: Usama Arif
Date: Mon Sep 21 2026 - 15:21:53 EST
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@xxxxxxxxxx>
Signed-off-by: Usama Arif <usama.arif@xxxxxxxxx>
---
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