Re: [PATCH v7] perf: Sharing PMU counters across compatible events

From: Song Liu
Date: Fri Nov 22 2019 - 14:50:39 EST




> On Nov 22, 2019, at 11:33 AM, Jiri Olsa <jolsa@xxxxxxxxxx> wrote:
>
> On Fri, Nov 15, 2019 at 03:55:04PM -0800, Song Liu wrote:
>> This patch tries to enable PMU sharing. When multiple perf_events are
>> counting the same metric, they can share the hardware PMU counter. We
>> call these events as "compatible events".
>>
>> The PMU sharing are limited to events within the same perf_event_context
>> (ctx). When a event is installed or enabled, search the ctx for compatible
>> events. This is implemented in perf_event_setup_dup(). One of these
>> compatible events are picked as the master (stored in event->dup_master).
>> Similarly, when the event is removed or disabled, perf_event_remove_dup()
>> is used to clean up sharing.
>>
>> A new state PERF_EVENT_STATE_ENABLED is introduced for the master event.
>> This state is used when the slave event is ACTIVE, but the master event
>> is not.
>>
>> On the critical paths (add, del read), sharing PMU counters doesn't
>> increase the complexity. Helper functions event_pmu_[add|del|read]() are
>> introduced to cover these cases. All these functions have O(1) time
>> complexity.
>>
>> Cc: Peter Zijlstra <peterz@xxxxxxxxxxxxx>
>> Cc: Arnaldo Carvalho de Melo <acme@xxxxxxxxxx>
>> Cc: Jiri Olsa <jolsa@xxxxxxxxxx>
>> Cc: Alexey Budankov <alexey.budankov@xxxxxxxxxxxxxxx>
>> Cc: Namhyung Kim <namhyung@xxxxxxxxxx>
>> Cc: Tejun Heo <tj@xxxxxxxxxx>
>> Signed-off-by: Song Liu <songliubraving@xxxxxx>
>>
>> ---
>> Changes in v7:
>> Major rewrite to avoid allocating extra master event.
>
> hi,
> what is this based on? I can't apply it on tip/master:
>
> Applying: perf: Sharing PMU counters across compatible events
> error: patch failed: include/linux/perf_event.h:722
> error: include/linux/perf_event.h: patch does not apply
> Patch failed at 0001 perf: Sharing PMU counters across compatible events
> hint: Use 'git am --show-current-patch' to see the failed patch
> When you have resolved this problem, run "git am --continue".
> If you prefer to skip this patch, run "git am --skip" instead.
> To restore the original branch and stop patching, run "git am --abort".

I was using Linus's master branch. This one is specifically based on

commit 96b95eff4a591dbac582c2590d067e356a18aacb
Merge: 4e84608c7836 80591e61a0f7
Author: Linus Torvalds <torvalds@xxxxxxxxxxxxxxxxxxxx>
Date: 8 days ago

Merge tag 'kbuild-fixes-v5.4-3' of git://git.kernel.org/pub/scm/linux/kernel/git/masahiroy/linux-kbuild

Pull Kbuild fixes from Masahiro Yamada:

- fix build error when compiling SPARC VDSO with CONFIG_COMPAT=y

- pass correct --arch option to Sparse

* tag 'kbuild-fixes-v5.4-3' of git://git.kernel.org/pub/scm/linux/kernel/git/masahiroy/linux-kbuild:
kbuild: tell sparse about the $ARCH
sparc: vdso: fix build error of vdso32

>
> also I'm getting this when trying to see/apply plain text patch:
>
> [jolsa@dell-r440-01 linux-perf]$ git am --show-current-patch | tail
> =09=09for_each_sibling_event(sibling, group_leader) {
> =09=09=09perf_remove_from_context(sibling, 0);
> =09=09=09put_ctx(gctx);
> +=09=09=09WARN_ON_ONCE(sibling->dup_master);
> =09=09}
> =20
> =09=09/*
> --=20


I also get these =09, =20 issues. I am not sure how to fix them. Attaching
the patch here to see whether it fixes it.

Thanks!
Song