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]
Date:   Wed, 14 Oct 2020 18:14:18 +0200
From:   Jiri Olsa <jolsa@...hat.com>
To:     Ian Rogers <irogers@...gle.com>
Cc:     Peter Zijlstra <peterz@...radead.org>,
        Ingo Molnar <mingo@...hat.com>,
        Arnaldo Carvalho de Melo <acme@...nel.org>,
        Mark Rutland <mark.rutland@....com>,
        Alexander Shishkin <alexander.shishkin@...ux.intel.com>,
        Namhyung Kim <namhyung@...nel.org>,
        Alexander Gordeev <agordeev@...ux.ibm.com>,
        Srikar Dronamraju <srikar@...ux.vnet.ibm.com>,
        Peng Fan <fanpeng@...ngson.cn>,
        LKML <linux-kernel@...r.kernel.org>,
        Stephane Eranian <eranian@...gle.com>
Subject: Re: [PATCH v2] perf bench: Use condition variables in numa.

On Wed, Oct 14, 2020 at 08:39:51AM -0700, Ian Rogers wrote:
> On Wed, Oct 14, 2020 at 4:45 AM Jiri Olsa <jolsa@...hat.com> wrote:
> >
> > On Mon, Oct 12, 2020 at 09:16:11AM -0700, Ian Rogers wrote:
> >
> > SNIP
> >
> > > @@ -483,6 +484,18 @@ static void init_global_mutex(pthread_mutex_t *mutex)
> > >       pthread_mutex_init(mutex, &attr);
> > >  }
> > >
> > > +/*
> > > + * Return a process-shared (global) condition variable:
> > > + */
> > > +static void init_global_cond(pthread_cond_t *cond)
> > > +{
> > > +     pthread_condattr_t attr;
> > > +
> > > +     pthread_condattr_init(&attr);
> > > +     pthread_condattr_setpshared(&attr, PTHREAD_PROCESS_SHARED);
> > > +     pthread_cond_init(cond, &attr);
> > > +}
> > > +
> > >  static int parse_cpu_list(const char *arg)
> > >  {
> > >       p0.cpu_list_str = strdup(arg);
> > > @@ -1136,15 +1149,18 @@ static void *worker_thread(void *__tdata)
> > >       if (g->p.serialize_startup) {
> > >               pthread_mutex_lock(&g->startup_mutex);
> > >               g->nr_tasks_started++;
> > > +             /* The last thread wakes the main process. */
> > > +             if (g->nr_tasks_started == g->p.nr_tasks)
> > > +                     pthread_cond_signal(&g->startup_cond);
> >
> > should you remove the condition? it's not necessary
> > and making this racy, no?
> >
> > just single pthread_cond_signal should be enough,
> > because the wait code is checking the number of tasks
> 
> The pthread_mutex_lock avoids any race on g->nr_tasks_started and
> g->p.nr_tasks is set up in init() along with all the global state. I
> don't think there's any race on g->nr_tasks_started and doing a signal
> for every thread starting will just cause unnecessary wake-ups for the
> main thread. I think it is better to keep it. I added loops on all the
> pthread_cond_waits so the code is robust against spurious wake ups.

ah, I missed that mutex call

Acked-by: Jiri Olsa <jolsa@...hat.com>

thanks,
jirka

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ