[PATCH 0/2] sched_ext: Specialize TID and scheduler hashtable compares
From: Usama Arif
Date: Mon Sep 21 2026 - 15:08:39 EST
scx_tid_hash and scx_sched_hash both use naturally aligned u64 keys but
do not provide obj_cmpfn callbacks. As a result, rhashtable falls back
to rhashtable_compare() for each object visited during a lookup:
memcmp(ptr + ht->p.key_offset, arg->key, ht->p.key_len)
Although only eight bytes are compared, the generic path loads the key
offset and length at runtime and emits an out-of-line memcmp() call.
The first patch adds a specialized comparison for scx_tid_hash. This
turns comparisons in scx_bpf_tid_to_task() into direct equality tests
against scx->tid. The kfunc can be used from hot scheduling paths, so
avoiding the generic comparison is particularly useful there. The
specialized comparison also covers duplicate checks during insertion.
The second patch specializes scx_sched_hash by comparing keys directly
against ops.sub_cgroup_id. This removes the generic comparison from
scx_find_sub_sched(), which is used when dispatching child schedulers
and by the sub-scheduler capability and management kfuncs.
In both cases, the const rhashtable parameters allow the compiler to
inline the callback and reduce each object comparison to a single u64
compare. Disassembly confirms that the lookup loops no longer call
memcmp() or an out-of-line comparator.
No functional change intended.
Usama Arif (2):
sched_ext: Specialize the TID hashtable compare
sched_ext: Specialize the scheduler hashtable compare
kernel/sched/ext/ext.c | 22 ++++++++++++++++++++++
1 file changed, 22 insertions(+)
--
2.53.0-Meta