Skip to content

Commit

Permalink
perf bpf-filter: Fix sample flag check with ||
Browse files Browse the repository at this point in the history
[ Upstream commit dc7f01f ]

For logical OR operator, the actual sample_flags are in the 'groups'
list so it needs to check entries in the list instead.  Otherwise it
would show the following error message.

  $ sudo perf record -a -e cycles:p --filter 'period > 100 || weight > 0' sleep 1
  Error: cycles:p event does not have sample flags 0
  failed to set filter "BPF" on event cycles:p with 2 (No such file or directory)

Actually it should warn on 'weight' is used without WEIGHT flag.

  Error: cycles:p event does not have PERF_SAMPLE_WEIGHT
   Hint: please add -W option to perf record
  failed to set filter "BPF" on event cycles:p with 2 (No such file or directory)

Fixes: 4310551 ("perf bpf filter: Show warning for missing sample flags")
Reviewed-by: Ian Rogers <irogers@google.com>
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: https://lore.kernel.org/r/20230811025822.3859771-1-namhyung@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
  • Loading branch information
namhyung authored and gregkh committed Sep 19, 2023
1 parent 6125d4c commit cc91cf1
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions tools/perf/util/bpf-filter.c
Expand Up @@ -62,6 +62,16 @@ static int check_sample_flags(struct evsel *evsel, struct perf_bpf_filter_expr *
if (evsel->core.attr.sample_type & expr->sample_flags)
return 0;

if (expr->op == PBF_OP_GROUP_BEGIN) {
struct perf_bpf_filter_expr *group;

list_for_each_entry(group, &expr->groups, list) {
if (check_sample_flags(evsel, group) < 0)
return -1;
}
return 0;
}

info = get_sample_info(expr->sample_flags);
if (info == NULL) {
pr_err("Error: %s event does not have sample flags %lx\n",
Expand Down

0 comments on commit cc91cf1

Please sign in to comment.