Skip to content

Commit d18b96c

Browse files
committed
sched_ext: Factor out abbreviated dispatch dequeue into dispatch_dequeue_locked()
move_task_between_dsqs() contains open-coded abbreviated dequeue logic when moving tasks between non-local DSQs. Factor this out into dispatch_dequeue_locked() which can be used when both the task's rq and dsq locks are already held. Add lockdep assertions to both dispatch_dequeue() and the new helper to verify locking requirements. This prepares for the load balancer which will need the same abbreviated dequeue pattern. Cc: Andrea Righi <arighi@nvidia.com> Cc: Dan Schatzberg <schatzberg.dan@gmail.com> Cc: Emil Tsalapatis <etsal@meta.com> Signed-off-by: Tejun Heo <tj@kernel.org>
1 parent d2974cc commit d18b96c

1 file changed

Lines changed: 17 additions & 2 deletions

File tree

kernel/sched/ext.c

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1106,6 +1106,8 @@ static void dispatch_dequeue(struct rq *rq, struct task_struct *p)
11061106
struct scx_dispatch_q *dsq = p->scx.dsq;
11071107
bool is_local = dsq == &rq->scx.local_dsq;
11081108

1109+
lockdep_assert_rq_held(rq);
1110+
11091111
if (!dsq) {
11101112
/*
11111113
* If !dsq && on-list, @p is on @rq's ddsp_deferred_locals.
@@ -1152,6 +1154,20 @@ static void dispatch_dequeue(struct rq *rq, struct task_struct *p)
11521154
raw_spin_unlock(&dsq->lock);
11531155
}
11541156

1157+
/*
1158+
* Abbreviated version of dispatch_dequeue() that can be used when both @p's rq
1159+
* and dsq are locked.
1160+
*/
1161+
static void dispatch_dequeue_locked(struct task_struct *p,
1162+
struct scx_dispatch_q *dsq)
1163+
{
1164+
lockdep_assert_rq_held(task_rq(p));
1165+
lockdep_assert_held(&dsq->lock);
1166+
1167+
task_unlink_from_dsq(p, dsq);
1168+
p->scx.dsq = NULL;
1169+
}
1170+
11551171
static struct scx_dispatch_q *find_dsq_for_dispatch(struct scx_sched *sch,
11561172
struct rq *rq, u64 dsq_id,
11571173
struct task_struct *p)
@@ -1812,8 +1828,7 @@ static struct rq *move_task_between_dsqs(struct scx_sched *sch,
18121828
* @p is going from a non-local DSQ to a non-local DSQ. As
18131829
* $src_dsq is already locked, do an abbreviated dequeue.
18141830
*/
1815-
task_unlink_from_dsq(p, src_dsq);
1816-
p->scx.dsq = NULL;
1831+
dispatch_dequeue_locked(p, src_dsq);
18171832
raw_spin_unlock(&src_dsq->lock);
18181833

18191834
dispatch_enqueue(sch, dst_dsq, p, enq_flags);

0 commit comments

Comments
 (0)