On Mon, Oct 9, 2023 at 9:57 PM Namhyung Kim <namhyung@xxxxxxxxxx> wrote: > > Hi Peter, > > On Mon, Oct 9, 2023 at 2:04 PM Peter Zijlstra <peterz@xxxxxxxxxxxxx> wrote: > > > > On Wed, Oct 04, 2023 at 09:32:24AM -0700, Namhyung Kim wrote: > > > > > Yeah, I know.. but I couldn't come up with a better solution. > > > > Not been near a compiler, and haven't fully thought it through, but > > could something like the work work? > > Thanks for the patch, I think it'd work. Let me test it > and get back to you. I worked well but contained a typo. See below. Which way do you want to process this change? Do I send it again with your S-o-b or will you apply it by yourself? Either is fine, just let me know. In case of latter, you can add Tested-by: Namhyung Kim <namhyung@xxxxxxxxxx> > > > > > > --- > > include/linux/perf_event.h | 1 + > > kernel/events/core.c | 115 +++++++++++++++++++++++---------------------- > > 2 files changed, 61 insertions(+), 55 deletions(-) > > > > diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h > > index f31f962a6445..0367d748fae0 100644 > > --- a/include/linux/perf_event.h > > +++ b/include/linux/perf_event.h > > @@ -878,6 +878,7 @@ struct perf_event_pmu_context { > > unsigned int embedded : 1; > > > > unsigned int nr_events; > > + unsigned int nr_cgroups; > > > > atomic_t refcount; /* event <-> epc */ > > struct rcu_head rcu_head; > > diff --git a/kernel/events/core.c b/kernel/events/core.c > > index 708d474c2ede..f3d5d47ecdfc 100644 > > --- a/kernel/events/core.c > > +++ b/kernel/events/core.c > > @@ -375,6 +375,7 @@ enum event_type_t { > > EVENT_TIME = 0x4, > > /* see ctx_resched() for details */ > > EVENT_CPU = 0x8, > > + EVENT_CGROUP = 0x10, > > EVENT_ALL = EVENT_FLEXIBLE | EVENT_PINNED, > > }; > > > > @@ -684,20 +685,26 @@ do { \ > > ___p; \ > > }) > > > > -static void perf_ctx_disable(struct perf_event_context *ctx) > > +static void perf_ctx_disable(struct perf_event_context *ctx, bool cgroup) > > { > > struct perf_event_pmu_context *pmu_ctx; > > > > - list_for_each_entry(pmu_ctx, &ctx->pmu_ctx_list, pmu_ctx_entry) > > + list_for_each_entry(pmu_ctx, &ctx->pmu_ctx_list, pmu_ctx_entry) { > > + if (cgroup && !pmu_ctx->nr_cgroups) > > + continue; > > perf_pmu_disable(pmu_ctx->pmu); > > + } > > } > > > > -static void perf_ctx_enable(struct perf_event_context *ctx) > > +static void perf_ctx_enable(struct perf_event_context *ctx. bool cgroup) s/./,/ Thanks, Namhyung > > { > > struct perf_event_pmu_context *pmu_ctx; > > > > - list_for_each_entry(pmu_ctx, &ctx->pmu_ctx_list, pmu_ctx_entry) > > + list_for_each_entry(pmu_ctx, &ctx->pmu_ctx_list, pmu_ctx_entry) { > > + if (cgroup && !pmu_ctx->nr_cgroups) > > + continue; > > perf_pmu_enable(pmu_ctx->pmu); > > + } > > }