[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <YH6s3P/3hQxI21eO@hirez.programming.kicks-ass.net>
Date: Tue, 20 Apr 2021 12:28:44 +0200
From: Peter Zijlstra <peterz@...radead.org>
To: Namhyung Kim <namhyung@...nel.org>
Cc: Ingo Molnar <mingo@...nel.org>,
Arnaldo Carvalho de Melo <acme@...nel.org>,
Jiri Olsa <jolsa@...hat.com>,
Mark Rutland <mark.rutland@....com>,
Alexander Shishkin <alexander.shishkin@...ux.intel.com>,
LKML <linux-kernel@...r.kernel.org>,
Stephane Eranian <eranian@...gle.com>,
Andi Kleen <ak@...ux.intel.com>,
Ian Rogers <irogers@...gle.com>,
Song Liu <songliubraving@...com>, Tejun Heo <tj@...nel.org>,
kernel test robot <lkp@...el.com>,
Thomas Gleixner <tglx@...utronix.de>
Subject: Re: [PATCH v3 1/2] perf/core: Share an event with multiple cgroups
On Fri, Apr 16, 2021 at 06:49:09PM +0900, Namhyung Kim wrote:
> On Thu, Apr 15, 2021 at 11:51 PM Peter Zijlstra <peterz@...radead.org> wrote:
> > > +static void perf_update_cgroup_node(struct perf_event *event, struct cgroup *cgrp)
> > > +{
> > > + u64 delta_count, delta_time_enabled, delta_time_running;
> > > + int i;
> > > +
> > > + if (event->cgrp_node_count == 0)
> > > + goto out;
> > > +
> > > + delta_count = local64_read(&event->count) - event->cgrp_node_count;
>From here...
> > > + delta_time_enabled = event->total_time_enabled - event->cgrp_node_time_enabled;
> > > + delta_time_running = event->total_time_running - event->cgrp_node_time_running;
> > > +
> > > + /* account delta to all ancestor cgroups */
> > > + for (i = 0; i <= cgrp->level; i++) {
> > > + struct perf_cgroup_node *node;
> > > +
> > > + node = find_cgroup_node(event, cgrp->ancestor_ids[i]);
> > > + if (node) {
> > > + node->count += delta_count;
> > > + node->time_enabled += delta_time_enabled;
> > > + node->time_running += delta_time_running;
> > > + }
> > > + }
... till here, NMI could hit and increment event->count, which then
means that:
> > > +
> > > +out:
> > > + event->cgrp_node_count = local64_read(&event->count);
This load doesn't match the delta_count load and events will go missing.
Obviously correct solution is:
event->cgrp_node_count += delta_count;
> > > + event->cgrp_node_time_enabled = event->total_time_enabled;
> > > + event->cgrp_node_time_running = event->total_time_running;
And while total_time doesn't have that problem, consistency would then
have you do:
event->cgrp_node_time_foo += delta_time_foo;
> >
> > This is wrong; there's no guarantee these are the same values you read
> > at the begin, IOW you could be loosing events.
>
> Could you please elaborate?
You forgot NMI.
Powered by blists - more mailing lists