Skip to content

Commit b4e1fa1

Browse files
author
Peter Zijlstra
committed
sched: Simplify try_steal_cookie()
Use guards to reduce gotos and simplify control flow. Signed-off-by: Peter Zijlstra (Intel) <[email protected]> Reviewed-by: Valentin Schneider <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 6dafc71 commit b4e1fa1

File tree

1 file changed

+9
-12
lines changed

1 file changed

+9
-12
lines changed

kernel/sched/core.c

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6298,19 +6298,19 @@ static bool try_steal_cookie(int this, int that)
62986298
unsigned long cookie;
62996299
bool success = false;
63006300

6301-
local_irq_disable();
6302-
double_rq_lock(dst, src);
6301+
guard(irq)();
6302+
guard(double_rq_lock)(dst, src);
63036303

63046304
cookie = dst->core->core_cookie;
63056305
if (!cookie)
6306-
goto unlock;
6306+
return false;
63076307

63086308
if (dst->curr != dst->idle)
6309-
goto unlock;
6309+
return false;
63106310

63116311
p = sched_core_find(src, cookie);
63126312
if (!p)
6313-
goto unlock;
6313+
return false;
63146314

63156315
do {
63166316
if (p == src->core_pick || p == src->curr)
@@ -6322,9 +6322,10 @@ static bool try_steal_cookie(int this, int that)
63226322
if (p->core_occupation > dst->idle->core_occupation)
63236323
goto next;
63246324
/*
6325-
* sched_core_find() and sched_core_next() will ensure that task @p
6326-
* is not throttled now, we also need to check whether the runqueue
6327-
* of the destination CPU is being throttled.
6325+
* sched_core_find() and sched_core_next() will ensure
6326+
* that task @p is not throttled now, we also need to
6327+
* check whether the runqueue of the destination CPU is
6328+
* being throttled.
63286329
*/
63296330
if (sched_task_is_throttled(p, this))
63306331
goto next;
@@ -6342,10 +6343,6 @@ static bool try_steal_cookie(int this, int that)
63426343
p = sched_core_next(p, cookie);
63436344
} while (p);
63446345

6345-
unlock:
6346-
double_rq_unlock(dst, src);
6347-
local_irq_enable();
6348-
63496346
return success;
63506347
}
63516348

0 commit comments

Comments
 (0)