2023-08-01 22:25:41

by Peter Zijlstra

[permalink] [raw]
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




2023-08-09 17:24:28

by Valentin Schneider

[permalink] [raw]
Subject: Re: [PATCH 0/9] sched: Use lock guards, wave 1

On 01/08/23 22:41, Peter Zijlstra wrote:
> If there are no objections / comments, I'm aiming to post the second batch at
> the end of the week.
>

Other than the nitpick on 5/9, the conversions LGTM.

Reviewed-by: Valentin Schneider <[email protected]>