Re: [PATCH sched_ext/for-7.2] sched_ext: add p->scx.tid and SCX_OPS_TID_TO_TASK lookup
From: Cheng-Yang Chou
Date: Sun Apr 19 2026 - 14:11:09 EST
Hi Tejun, sorry for the noise
On Sun, Apr 19, 2026 at 06:18:46AM -1000, Tejun Heo wrote:
[snipped]
> void scx_pre_fork(struct task_struct *p)
> {
> /*
> @@ -3682,6 +3732,8 @@ int scx_fork(struct task_struct *p, stru
>
> percpu_rwsem_assert_held(&scx_fork_rwsem);
>
> + p->scx.tid = scx_alloc_tid();
> +
> if (scx_init_task_enabled) {
> #ifdef CONFIG_EXT_SUB_SCHED
> struct scx_sched *sch = kargs->cset->dfl_cgrp->scx_sched;
> @@ -3717,9 +3769,13 @@ void scx_post_fork(struct task_struct *p
> }
> }
>
> - raw_spin_lock_irq(&scx_tasks_lock);
> - list_add_tail(&p->scx.tasks_node, &scx_tasks);
> - raw_spin_unlock_irq(&scx_tasks_lock);
> + scoped_guard(raw_spinlock_irq, &scx_tasks_lock) {
> + list_add_tail(&p->scx.tasks_node, &scx_tasks);
> + if (scx_tid_to_task_enabled())
> + rhashtable_lookup_insert_fast(&scx_tid_hash,
After reading the review from Sashiko [1], should we handle insertion
failures here?
ret = rhashtable_lookup_insert_fast()
if(unlikely(ret))
scx_error(...)
> + &p->scx.tid_hash_node,
> + scx_tid_hash_params);
> + }
>
> percpu_up_read(&scx_fork_rwsem);
> }
[...]
> + /*
> + * Insert into the tid hash under scx_tasks_lock so we can't
> + * race sched_ext_dead() and leave a stale entry for an already
> + * exited task.
> + */
> + if (scx_tid_to_task_enabled()) {
> + guard(raw_spinlock_irq)(&scx_tasks_lock);
> + if (!list_empty(&p->scx.tasks_node))
> + rhashtable_lookup_insert_fast(&scx_tid_hash,
Same here, thanks.
> + &p->scx.tid_hash_node,
> + scx_tid_hash_params);
> + }
> +
> put_task_struct(p);
> }
[1]: https://sashiko.dev/#/patchset/a19c8c74d7c767bc9865b75d6de7c723%40kernel.org
--
Cheers,
Cheng-Yang