Re: [PATCH 01/11] sched: Trigger warning if ->migration_disabled counter underflows.
From: Peter Zijlstra
Date: Thu Dec 02 2021 - 16:02:55 EST
On Mon, Nov 29, 2021 at 06:46:44PM +0100, Sebastian Andrzej Siewior wrote:
> If migrate_enable() is used more often than its counter part then it
> remains undetected and rq::nr_pinned will underflow, too.
>
> Add a warning if migrate_enable() is attempted if without a matching a
> migrate_disable().
>
> Signed-off-by: Sebastian Andrzej Siewior <bigeasy@xxxxxxxxxxxxx>
> ---
> kernel/sched/core.c | 2 ++
> 1 file changed, 2 insertions(+)
>
> diff --git a/kernel/sched/core.c b/kernel/sched/core.c
> index 76f9deeaa9420..02be3f6144e97 100644
> --- a/kernel/sched/core.c
> +++ b/kernel/sched/core.c
> @@ -2171,6 +2171,8 @@ void migrate_enable(void)
> if (p->migration_disabled > 1) {
> p->migration_disabled--;
> return;
Due to return there ^
> + } else if (WARN_ON_ONCE(p->migration_disabled == 0)) {
> + return;
> }
we can do away with else and simply write:
if (WARN_ON_ONCE(!p->migration_disabled))
return;