lkml.org 
[lkml]   [2023]   [Aug]   [1]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
    Patch in this message
    /
    Date
    From
    Subject[PATCH 9/9] sched: Simplify sched_core_cpu_{starting,deactivate}()
    Use guards to reduce gotos and simplify control flow.

    Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
    ---
    kernel/sched/core.c | 27 ++++++++++++---------------
    1 file changed, 12 insertions(+), 15 deletions(-)

    --- a/kernel/sched/core.c
    +++ b/kernel/sched/core.c
    @@ -6331,20 +6331,24 @@ static void queue_core_balance(struct rq
    queue_balance_callback(rq, &per_cpu(core_balance_head, rq->cpu), sched_core_balance);
    }

    +DEFINE_LOCK_GUARD_1(core_lock, int,
    + sched_core_lock(*_T->lock, &_T->flags),
    + sched_core_unlock(*_T->lock, &_T->flags),
    + unsigned long flags)
    +
    static void sched_core_cpu_starting(unsigned int cpu)
    {
    const struct cpumask *smt_mask = cpu_smt_mask(cpu);
    struct rq *rq = cpu_rq(cpu), *core_rq = NULL;
    - unsigned long flags;
    int t;

    - sched_core_lock(cpu, &flags);
    + guard(core_lock)(&cpu);

    WARN_ON_ONCE(rq->core != rq);

    /* if we're the first, we'll be our own leader */
    if (cpumask_weight(smt_mask) == 1)
    - goto unlock;
    + return;

    /* find the leader */
    for_each_cpu(t, smt_mask) {
    @@ -6358,7 +6362,7 @@ static void sched_core_cpu_starting(unsi
    }

    if (WARN_ON_ONCE(!core_rq)) /* whoopsie */
    - goto unlock;
    + return;

    /* install and validate core_rq */
    for_each_cpu(t, smt_mask) {
    @@ -6369,29 +6373,25 @@ static void sched_core_cpu_starting(unsi

    WARN_ON_ONCE(rq->core != core_rq);
    }
    -
    -unlock:
    - sched_core_unlock(cpu, &flags);
    }

    static void sched_core_cpu_deactivate(unsigned int cpu)
    {
    const struct cpumask *smt_mask = cpu_smt_mask(cpu);
    struct rq *rq = cpu_rq(cpu), *core_rq = NULL;
    - unsigned long flags;
    int t;

    - sched_core_lock(cpu, &flags);
    + guard(core_lock)(&cpu);

    /* if we're the last man standing, nothing to do */
    if (cpumask_weight(smt_mask) == 1) {
    WARN_ON_ONCE(rq->core != rq);
    - goto unlock;
    + return;
    }

    /* if we're not the leader, nothing to do */
    if (rq->core != rq)
    - goto unlock;
    + return;

    /* find a new leader */
    for_each_cpu(t, smt_mask) {
    @@ -6402,7 +6402,7 @@ static void sched_core_cpu_deactivate(un
    }

    if (WARN_ON_ONCE(!core_rq)) /* impossible */
    - goto unlock;
    + return;

    /* copy the shared state to the new leader */
    core_rq->core_task_seq = rq->core_task_seq;
    @@ -6424,9 +6424,6 @@ static void sched_core_cpu_deactivate(un
    rq = cpu_rq(t);
    rq->core = core_rq;
    }
    -
    -unlock:
    - sched_core_unlock(cpu, &flags);
    }

    static inline void sched_core_cpu_dying(unsigned int cpu)

    \
     
     \ /
      Last update: 2023-08-01 23:26    [W:4.113 / U:0.124 seconds]
    ©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site