Skip to content

sched: Use lock guards, wave 1

Peter Zijlstra lkml 1 version Applied

Status from this message: The following commit has been merged into the sched/core branch of tip:

Get series with b4
b4 am [email protected]

Versions newest first

  1. v1 Latest9 patches 7 repliesApplied

Patches in v1 Applied

#Subject and filesSizeRepliesApplied
1/9sched: Simplify get_nohz_timer_target()kernel/sched/core.c+6 -93 replies
2/9sched: Simplify sysctl_sched_uclamp_handler()kernel/sched/core.c+4 -70 replies
3/9sched: Simplify: migrate_swap_stop()kernel/sched/core.c kernel/sched/sched.h+27 -160 replies
4/9sched: Simplify wake_up_if_idle()kernel/sched/core.c kernel/sched/sched.h+21 -140 replies
5/9sched: Simplify ttwu()kernel/sched/core.c+109 -1123 replies
6/9sched: Simplify sched_exec()kernel/sched/core.c+9 -120 replies
7/9sched: Simplify sched_tick_remote()kernel/sched/core.c+18 -250 replies
8/9sched: Simplify try_steal_cookie()kernel/sched/core.c+9 -120 replies
9/9sched: Simplify sched_core_cpu_{starting,deactivate}()kernel/sched/core.c+12 -150 replies

Reviews trailers per patch

1 of 9 patches has a Reviewed-by or Acked-by of their own; the series has one for all of them.

PatchJoel Fernandes (Google)Valentin Schneider
SeriesR-b
1/9R-b
2/9
3/9
4/9
5/9
6/9
7/9
8/9
9/9

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.

Read the v1 thread

Cover letter [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