lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAEXW_YRZE7goE+KpoV5zkj=fLY3q33bf8HVMs0vWggZnxmdb5A@mail.gmail.com>
Date:   Fri, 11 Aug 2023 03:35:23 -0400
From:   Joel Fernandes <joel@...lfernandes.org>
To:     Peter Zijlstra <peterz@...radead.org>
Cc:     mingo@...hat.com, juri.lelli@...hat.com,
        vincent.guittot@...aro.org, dietmar.eggemann@....com,
        rostedt@...dmis.org, bsegall@...gle.com, mgorman@...e.de,
        bristot@...hat.com, vschneid@...hat.com,
        linux-kernel@...r.kernel.org
Subject: Re: [PATCH 1/9] sched: Simplify get_nohz_timer_target()

On Wed, Aug 9, 2023 at 3:48 PM Peter Zijlstra <peterz@...radead.org> wrote:
>
> On Sun, Aug 06, 2023 at 05:39:24PM -0400, Joel Fernandes wrote:
> > On Sun, Aug 6, 2023 at 9:52 AM Peter Zijlstra <peterz@...radead.org> wrote:
> > >
> > > Use guards to reduce gotos and simplify control flow.
> > >
> > > Signed-off-by: Peter Zijlstra (Intel) <peterz@...radead.org>
> > > ---
> > >  kernel/sched/core.c |   15 ++++++---------
> > >  1 file changed, 6 insertions(+), 9 deletions(-)
> > >
> > > --- a/kernel/sched/core.c
> > > +++ b/kernel/sched/core.c
> > > @@ -1097,25 +1097,22 @@ int get_nohz_timer_target(void)
> > >
> > >         hk_mask = housekeeping_cpumask(HK_TYPE_TIMER);
> > >
> > > -       rcu_read_lock();
> > > +       guard(rcu)();
> > > +
> > >         for_each_domain(cpu, sd) {
> > >                 for_each_cpu_and(i, sched_domain_span(sd), hk_mask) {
> > >                         if (cpu == i)
> > >                                 continue;
> > >
> > > -                       if (!idle_cpu(i)) {
> > > -                               cpu = i;
> > > -                               goto unlock;
> > > -                       }
> > > +                       if (!idle_cpu(i))
> > > +                               return i;
> > >                 }
> > >         }
> > >
> > >         if (default_cpu == -1)
> > >                 default_cpu = housekeeping_any_cpu(HK_TYPE_TIMER);
> > > -       cpu = default_cpu;
> > > -unlock:
> > > -       rcu_read_unlock();
> > > -       return cpu;
> > > +
> > > +       return default_cpu;
> > >  }
> >
> > Reviewed-by: Joel Fernandes (Google) <joel@...lfernandes.org>
> >
> > I haven't looked into the actual implementation of the guard stuff,
> > but rcu_read_lock_guarded() is less of an eyesore to me than
> > guard(rcu)(); TBH.
>
> I readily admit it isn't the prettiest construct, my brain is warped by
> many years of C++ and I can read it as: guard<rcu>(), but I'm not sure
> that's actually better :-)
>
> The advantage of all this is that you also get:
>
>         scoped_guard (rcu) {
>         }
>
> for 'free'.

Yes, overall the readability improvement is quite appealing. Thank you Peter!

 - Joel

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ