[PATCH 0/9] sched: Use lock guards, wave 1

From: Peter Zijlstra
Date: Tue Aug 01 2023 - 17:25:00 EST


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