From: Peter Zijlstra <peterz@infradead.org>
To: mingo@redhat.com
Cc: peterz@infradead.org, juri.lelli@redhat.com,
vincent.guittot@linaro.org, dietmar.eggemann@arm.com,
rostedt@goodmis.org, bsegall@google.com, mgorman@suse.de,
bristot@redhat.com, vschneid@redhat.com,
linux-kernel@vger.kernel.org
Subject: [PATCH 9/9] sched: Simplify sched_core_cpu_{starting,deactivate}()
Date: Tue, 01 Aug 2023 22:41:30 +0200 [thread overview]
Message-ID: <20230801211812.371787909@infradead.org> (raw)
In-Reply-To: <20230801204121.929256934@infradead.org>
Use guards to reduce gotos and simplify control flow.
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
---
kernel/sched/core.c | 27 ++++++++++++---------------
1 file changed, 12 insertions(+), 15 deletions(-)
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -6331,20 +6331,24 @@ static void queue_core_balance(struct rq
queue_balance_callback(rq, &per_cpu(core_balance_head, rq->cpu), sched_core_balance);
}
+DEFINE_LOCK_GUARD_1(core_lock, int,
+ sched_core_lock(*_T->lock, &_T->flags),
+ sched_core_unlock(*_T->lock, &_T->flags),
+ unsigned long flags)
+
static void sched_core_cpu_starting(unsigned int cpu)
{
const struct cpumask *smt_mask = cpu_smt_mask(cpu);
struct rq *rq = cpu_rq(cpu), *core_rq = NULL;
- unsigned long flags;
int t;
- sched_core_lock(cpu, &flags);
+ guard(core_lock)(&cpu);
WARN_ON_ONCE(rq->core != rq);
/* if we're the first, we'll be our own leader */
if (cpumask_weight(smt_mask) == 1)
- goto unlock;
+ return;
/* find the leader */
for_each_cpu(t, smt_mask) {
@@ -6358,7 +6362,7 @@ static void sched_core_cpu_starting(unsi
}
if (WARN_ON_ONCE(!core_rq)) /* whoopsie */
- goto unlock;
+ return;
/* install and validate core_rq */
for_each_cpu(t, smt_mask) {
@@ -6369,29 +6373,25 @@ static void sched_core_cpu_starting(unsi
WARN_ON_ONCE(rq->core != core_rq);
}
-
-unlock:
- sched_core_unlock(cpu, &flags);
}
static void sched_core_cpu_deactivate(unsigned int cpu)
{
const struct cpumask *smt_mask = cpu_smt_mask(cpu);
struct rq *rq = cpu_rq(cpu), *core_rq = NULL;
- unsigned long flags;
int t;
- sched_core_lock(cpu, &flags);
+ guard(core_lock)(&cpu);
/* if we're the last man standing, nothing to do */
if (cpumask_weight(smt_mask) == 1) {
WARN_ON_ONCE(rq->core != rq);
- goto unlock;
+ return;
}
/* if we're not the leader, nothing to do */
if (rq->core != rq)
- goto unlock;
+ return;
/* find a new leader */
for_each_cpu(t, smt_mask) {
@@ -6402,7 +6402,7 @@ static void sched_core_cpu_deactivate(un
}
if (WARN_ON_ONCE(!core_rq)) /* impossible */
- goto unlock;
+ return;
/* copy the shared state to the new leader */
core_rq->core_task_seq = rq->core_task_seq;
@@ -6424,9 +6424,6 @@ static void sched_core_cpu_deactivate(un
rq = cpu_rq(t);
rq->core = core_rq;
}
-
-unlock:
- sched_core_unlock(cpu, &flags);
}
static inline void sched_core_cpu_dying(unsigned int cpu)
next prev parent reply other threads:[~2023-08-01 21:25 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-08-01 20:41 [PATCH 0/9] sched: Use lock guards, wave 1 Peter Zijlstra
2023-08-01 20:41 ` [PATCH 1/9] sched: Simplify get_nohz_timer_target() Peter Zijlstra
2023-08-06 21:39 ` Joel Fernandes
2023-08-09 19:48 ` Peter Zijlstra
2023-08-11 7:35 ` Joel Fernandes
2023-08-14 15:08 ` [tip: sched/core] " tip-bot2 for Peter Zijlstra
2023-08-01 20:41 ` [PATCH 2/9] sched: Simplify sysctl_sched_uclamp_handler() Peter Zijlstra
2023-08-14 15:08 ` [tip: sched/core] " tip-bot2 for Peter Zijlstra
2023-08-01 20:41 ` [PATCH 3/9] sched: Simplify: migrate_swap_stop() Peter Zijlstra
2023-08-14 15:08 ` [tip: sched/core] " tip-bot2 for Peter Zijlstra
2023-08-01 20:41 ` [PATCH 4/9] sched: Simplify wake_up_if_idle() Peter Zijlstra
2023-08-14 15:08 ` [tip: sched/core] " tip-bot2 for Peter Zijlstra
2023-08-01 20:41 ` [PATCH 5/9] sched: Simplify ttwu() Peter Zijlstra
2023-08-09 15:21 ` Valentin Schneider
2023-08-09 19:26 ` Peter Zijlstra
2023-08-10 8:03 ` Valentin Schneider
2023-08-14 15:08 ` [tip: sched/core] " tip-bot2 for Peter Zijlstra
2023-08-01 20:41 ` [PATCH 6/9] sched: Simplify sched_exec() Peter Zijlstra
2023-08-14 15:08 ` [tip: sched/core] " tip-bot2 for Peter Zijlstra
2023-08-01 20:41 ` [PATCH 7/9] sched: Simplify sched_tick_remote() Peter Zijlstra
2023-08-14 15:08 ` [tip: sched/core] " tip-bot2 for Peter Zijlstra
2023-08-01 20:41 ` [PATCH 8/9] sched: Simplify try_steal_cookie() Peter Zijlstra
2023-08-14 15:08 ` [tip: sched/core] " tip-bot2 for Peter Zijlstra
2023-08-01 20:41 ` Peter Zijlstra [this message]
2023-08-14 15:08 ` [tip: sched/core] sched: Simplify sched_core_cpu_{starting,deactivate}() tip-bot2 for Peter Zijlstra
2023-08-09 15:35 ` [PATCH 0/9] sched: Use lock guards, wave 1 Valentin Schneider
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230801211812.371787909@infradead.org \
--to=peterz@infradead.org \
--cc=bristot@redhat.com \
--cc=bsegall@google.com \
--cc=dietmar.eggemann@arm.com \
--cc=juri.lelli@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mgorman@suse.de \
--cc=mingo@redhat.com \
--cc=rostedt@goodmis.org \
--cc=vincent.guittot@linaro.org \
--cc=vschneid@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®