Skip to content

Commit 4eb054f

Browse files
author
Peter Zijlstra
committed
sched: Simplify wake_up_if_idle()
Use guards to reduce gotos and simplify control flow. Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> Reviewed-by: Valentin Schneider <vschneid@redhat.com> Link: https://lore.kernel.org/r/20230801211812.032678917@infradead.org
1 parent 5bb76f1 commit 4eb054f

File tree

2 files changed

+21
-14
lines changed

2 files changed

+21
-14
lines changed

kernel/sched/core.c

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3939,21 +3939,13 @@ static void __ttwu_queue_wakelist(struct task_struct *p, int cpu, int wake_flags
39393939
void wake_up_if_idle(int cpu)
39403940
{
39413941
struct rq *rq = cpu_rq(cpu);
3942-
struct rq_flags rf;
3943-
3944-
rcu_read_lock();
39453942

3946-
if (!is_idle_task(rcu_dereference(rq->curr)))
3947-
goto out;
3948-
3949-
rq_lock_irqsave(rq, &rf);
3950-
if (is_idle_task(rq->curr))
3951-
resched_curr(rq);
3952-
/* Else CPU is not idle, do nothing here: */
3953-
rq_unlock_irqrestore(rq, &rf);
3954-
3955-
out:
3956-
rcu_read_unlock();
3943+
guard(rcu)();
3944+
if (is_idle_task(rcu_dereference(rq->curr))) {
3945+
guard(rq_lock_irqsave)(rq);
3946+
if (is_idle_task(rq->curr))
3947+
resched_curr(rq);
3948+
}
39573949
}
39583950

39593951
bool cpus_share_cache(int this_cpu, int that_cpu)

kernel/sched/sched.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1705,6 +1705,21 @@ rq_unlock(struct rq *rq, struct rq_flags *rf)
17051705
raw_spin_rq_unlock(rq);
17061706
}
17071707

1708+
DEFINE_LOCK_GUARD_1(rq_lock, struct rq,
1709+
rq_lock(_T->lock, &_T->rf),
1710+
rq_unlock(_T->lock, &_T->rf),
1711+
struct rq_flags rf)
1712+
1713+
DEFINE_LOCK_GUARD_1(rq_lock_irq, struct rq,
1714+
rq_lock_irq(_T->lock, &_T->rf),
1715+
rq_unlock_irq(_T->lock, &_T->rf),
1716+
struct rq_flags rf)
1717+
1718+
DEFINE_LOCK_GUARD_1(rq_lock_irqsave, struct rq,
1719+
rq_lock_irqsave(_T->lock, &_T->rf),
1720+
rq_unlock_irqrestore(_T->lock, &_T->rf),
1721+
struct rq_flags rf)
1722+
17081723
static inline struct rq *
17091724
this_rq_lock_irq(struct rq_flags *rf)
17101725
__acquires(rq->lock)

0 commit comments

Comments
 (0)