diff options
| author | Usama Arif <usama.arif@linux.dev> | 2026-09-21 11:59:11 -0700 |
|---|---|---|
| committer | Tejun Heo <tj@kernel.org> | 2026-09-21 09:12:04 -1000 |
| commit | daaab0f42e2eec54a8fe585b2fa3f5408a9b3585 (patch) | |
| tree | db617953ade6e945861d27b732540f7674210a5e /kernel | |
| parent | e4c5ba819d3ce8c146a3a2d68f507e1845fdaafb (diff) | |
| download | linux-next-daaab0f42e2eec54a8fe585b2fa3f5408a9b3585.tar.gz linux-next-daaab0f42e2eec54a8fe585b2fa3f5408a9b3585.zip | |
sched_ext: Specialize the TID hashtable compare
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>
Signed-off-by: Tejun Heo <tj@kernel.org>
Diffstat (limited to 'kernel')
| -rw-r--r-- | kernel/sched/ext/ext.c | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/kernel/sched/ext/ext.c b/kernel/sched/ext/ext.c index fe7e07d72a69..f5887542b502 100644 --- a/kernel/sched/ext/ext.c +++ b/kernel/sched/ext/ext.c @@ -52,10 +52,20 @@ 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; |
