[PATCH v2 02/12] sched/core: Introduce rq_drop_lock()

From: Peter Zijlstra

Date: Sat Nov 07 2026 - 07:05:04 EST


Currently rq_unpin_lock() serves a dual purpose, it pairs with both
rq_pin_lock() and rq_repin_lock(). That is:

rq_pin_lock()
rq_unpin_lock()
rq_repin_lock()
rq_unpin_lock()

In prepration of making the temporary drop and the final drop
distinct, this needs another function. Introduce and use
rq_drop_lock() for the temporary drop, like:

rq_pin_lock()
rq_drop_lock()
rq_repin_lock()
rq_unpin_lock()

Signed-off-by: Peter Zijlstra (Intel) <peterz@xxxxxxxxxxxxx>
---
kernel/sched/core.c | 8 ++++----
kernel/sched/deadline.c | 4 ++--
kernel/sched/ext/ext.c | 4 ++--
kernel/sched/fair.c | 2 +-
kernel/sched/rt.c | 2 +-
kernel/sched/sched.h | 5 +++++
6 files changed, 15 insertions(+), 10 deletions(-)

--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -3910,7 +3910,7 @@ ttwu_do_activate(struct rq *rq, struct t
* Our task @p is fully woken up and running; so it's safe to
* drop the rq->lock, hereafter rq is only used for statistics.
*/
- rq_unpin_lock(rq, rf);
+ rq_drop_lock(rq, rf);
p->sched_class->task_woken(rq, p);
rq_repin_lock(rq, rf);
}
@@ -5042,7 +5042,7 @@ void wake_up_new_task(struct task_struct
* Nothing relies on rq->lock after this, so it's fine to
* drop it.
*/
- rq_unpin_lock(rq, &rf);
+ rq_drop_lock(rq, &rf);
p->sched_class->task_woken(rq, p);
rq_repin_lock(rq, &rf);
}
@@ -5260,7 +5260,7 @@ struct balance_callback *splice_balance_
void __balance_callbacks(struct rq *rq, struct rq_flags *rf)
{
if (rf)
- rq_unpin_lock(rq, rf);
+ rq_drop_lock(rq, rf);
do_balance_callbacks(rq, __splice_balance_callbacks(rq, false));
if (rf)
rq_repin_lock(rq, rf);
@@ -6929,7 +6929,7 @@ static inline void proxy_release_rq_lock
* to pick_again, so the callbacks will get re-established.
*/
zap_balance_callbacks(rq);
- rq_unpin_lock(rq, rf);
+ rq_drop_lock(rq, rf);
raw_spin_rq_unlock(rq);
}

--- a/kernel/sched/deadline.c
+++ b/kernel/sched/deadline.c
@@ -1129,7 +1129,7 @@ static void __push_dl_task(struct rq *rq
* Nothing relies on rq->lock after this, so its safe to drop
* rq->lock.
*/
- rq_unpin_lock(rq, rf);
+ rq_drop_lock(rq, rf);
push_dl_task(rq);
rq_repin_lock(rq, rf);
}
@@ -2720,7 +2720,7 @@ static int balance_dl(struct rq *rq, str
* disabled avoiding further scheduler activity on it and we've
* not yet started the picking loop.
*/
- rq_unpin_lock(rq, rf);
+ rq_drop_lock(rq, rf);
pull_dl_task(rq);
rq_repin_lock(rq, rf);
}
--- a/kernel/sched/ext/ext.c
+++ b/kernel/sched/ext/ext.c
@@ -3924,7 +3924,7 @@ static enum scx_dsp_verdict dispatch_pic
{
enum scx_dsp_verdict verdict;

- rq_unpin_lock(rq, rf);
+ rq_drop_lock(rq, rf);
verdict = dispatch_one(rq, prev);
rq_repin_lock(rq, rf);

@@ -3949,7 +3949,7 @@ static enum scx_dsp_verdict dispatch_cor
if (rq->scx.flags & SCX_RQ_IN_DISPATCH)
return SCX_DSP_NONE;

- rq_unpin_lock(rq, rf);
+ rq_drop_lock(rq, rf);

verdict = dispatch_one(rq, prev);

--- a/kernel/sched/fair.c
+++ b/kernel/sched/fair.c
@@ -14907,7 +14907,7 @@ static int sched_balance_newidle(struct
* further scheduler activity on it and we're being very careful to
* re-start the picking loop.
*/
- rq_unpin_lock(this_rq, rf);
+ rq_drop_lock(this_rq, rf);

sd = rcu_dereference_sched_domain(this_rq->sd);
if (!sd)
--- a/kernel/sched/rt.c
+++ b/kernel/sched/rt.c
@@ -1611,7 +1611,7 @@ static int balance_rt(struct rq *rq, str
* disabled avoiding further scheduler activity on it and we've
* not yet started the picking loop.
*/
- rq_unpin_lock(rq, rf);
+ rq_drop_lock(rq, rf);
pull_rt_task(rq);
rq_repin_lock(rq, rf);
}
--- a/kernel/sched/sched.h
+++ b/kernel/sched/sched.h
@@ -1991,6 +1991,11 @@ static inline void rq_unpin_lock(struct
lockdep_unpin_lock(__rq_lockp(rq), rf->cookie);
}

+static inline void rq_drop_lock(struct rq *rq, struct rq_flags *rf)
+{
+ rq_unpin_lock(rq, rf);
+}
+
static inline void rq_repin_lock(struct rq *rq, struct rq_flags *rf)
{
lockdep_repin_lock(__rq_lockp(rq), rf->cookie);