Re: [PATCH v6 3/4] perf-stat: enable counting events for BPF programs

From: Song Liu
Date: Tue Dec 29 2020 - 13:00:32 EST




> On Dec 29, 2020, at 9:46 AM, Song Liu <songliubraving@xxxxxx> wrote:
>
>>>

[...]

>
> [...]
>
>>> +static inline bool target__has_bpf(struct target *target)
>>> +{
>>> + return target->bpf_str;
>>> +}
>>> +
>>> static inline bool target__none(struct target *target)
>>> {
>>> return !target__has_task(target) && !target__has_cpu(target);
>>
>> Shouldn't it have && !target__has_bpf() too?

Actually, we don't need target__has_bpf() here. As -b requires setting up counters
system wide (in setup_system_wide()). If we add target__has_bpf() here, we will
need something like below, which I think it not necessary.

diff --git i/tools/perf/builtin-stat.c w/tools/perf/builtin-stat.c
index 09bffb3fbcdd4..853cec040191b 100644
--- i/tools/perf/builtin-stat.c
+++ w/tools/perf/builtin-stat.c
@@ -2081,7 +2081,7 @@ static void setup_system_wide(int forks)
* - there is workload specified but all requested
* events are system wide events
*/
- if (!target__none(&target))
+ if (!target__none(&target) && !target__has_bpf(&target))
return;

if (!forks)
diff --git i/tools/perf/util/target.h w/tools/perf/util/target.h
index f132c6c2eef81..295fb11f4daff 100644
--- i/tools/perf/util/target.h
+++ w/tools/perf/util/target.h
@@ -71,7 +71,8 @@ static inline bool target__has_bpf(struct target *target)

static inline bool target__none(struct target *target)
{
- return !target__has_task(target) && !target__has_cpu(target);
+ return !target__has_task(target) && !target__has_cpu(target) &&
+ !target__has_bpf(target);
}

static inline bool target__has_per_thread(struct target *target)