[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-ID: <20230801204121.929256934@infradead.org>
Date: Tue, 01 Aug 2023 22:41:21 +0200
From: Peter Zijlstra <peterz@...radead.org>
To: mingo@...hat.com
Cc: peterz@...radead.org, juri.lelli@...hat.com,
vincent.guittot@...aro.org, dietmar.eggemann@....com,
rostedt@...dmis.org, bsegall@...gle.com, mgorman@...e.de,
bristot@...hat.com, vschneid@...hat.com,
linux-kernel@...r.kernel.org
Subject: [PATCH 0/9] sched: Use lock guards, wave 1
Hi,
This is the first of two series converting kernel/sched/core.c to use the shiny
new Scope-Based Resource Management machinery that has recently been merged:
https://lkml.kernel.org/r/20230612093537.614161713%40infradead.org
TL;DR:
void foo()
{
raw_spin_lock(&lock);
if (!cond)
goto unlock;
...
unlock:
raw_spin_unlock(&lock);
}
can now be written like:
void foo()
{
guard(raw_spinlock)(&lock);
if (!cond)
return;
...
}
or:
void foo()
{
scoped_guard (raw_spinlock, &lock) {
if (!cond)
break;
...
}
}
Where guard() instantiates a 'cleanup' variable that is initialized by an
expression that locks and returns the lock pointer. When this variable goes out
of scope, the cleanup does the unlock. And scoped_guard() does the same but
creates an explicit scope (using for).
By having the unlock be implicit, the code becomes simpler since it is no
longer needed to manually track the various exit/error cases and many goto's
just go away.
Specifically, every patch in this series is aimed at removing an out/unlock
label and it's corresponding gotos.
If there are no objections / comments, I'm aiming to post the second batch at
the end of the week.
Also available at:
git://git.kernel.org/pub/scm/linux/kernel/git/peterz/queue.git sched/guards
Powered by blists - more mailing lists