diff options
author | Namhyung Kim <namhyung@kernel.org> | 2024-07-03 15:30:30 -0700 |
---|---|---|
committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2024-08-01 12:11:33 -0300 |
commit | eb1693b1150d4b99af5241242d6bcd6290cf68a0 (patch) | |
tree | fdef778a5e087053ea94737872b79091a606cb2d /tools/perf/util/bpf_skel | |
parent | 966854e72f6e8a259609ea3c7fd78215e6606c7b (diff) |
perf bpf-filter: Split per-task filter use case
If the target is a list of tasks, it can use a shared hash map for
filter expressions. The key of the filter map is an integer index like
in an array. A separate pid_hash map is added to get the index for the
filter map using the tgid.
For system-wide mode including per-cpu or per-user targets are handled
by the single entry map like before.
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Ian Rogers <irogers@google.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: KP Singh <kpsingh@kernel.org>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Song Liu <song@kernel.org>
Cc: Stephane Eranian <eranian@google.com>
Cc: bpf@vger.kernel.org
Link: https://lore.kernel.org/r/20240703223035.2024586-4-namhyung@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools/perf/util/bpf_skel')
-rw-r--r-- | tools/perf/util/bpf_skel/sample-filter.h | 1 | ||||
-rw-r--r-- | tools/perf/util/bpf_skel/sample_filter.bpf.c | 21 |
2 files changed, 22 insertions, 0 deletions
diff --git a/tools/perf/util/bpf_skel/sample-filter.h b/tools/perf/util/bpf_skel/sample-filter.h index bb6a1b91f1df..e666bfd5fbdd 100644 --- a/tools/perf/util/bpf_skel/sample-filter.h +++ b/tools/perf/util/bpf_skel/sample-filter.h @@ -2,6 +2,7 @@ #define PERF_UTIL_BPF_SKEL_SAMPLE_FILTER_H #define MAX_FILTERS 64 +#define MAX_PIDS (16 * 1024) /* supported filter operations */ enum perf_bpf_filter_op { diff --git a/tools/perf/util/bpf_skel/sample_filter.bpf.c b/tools/perf/util/bpf_skel/sample_filter.bpf.c index 0d56e52b922c..c5273f06fa45 100644 --- a/tools/perf/util/bpf_skel/sample_filter.bpf.c +++ b/tools/perf/util/bpf_skel/sample_filter.bpf.c @@ -15,7 +15,16 @@ struct filters { __uint(max_entries, 1); } filters SEC(".maps"); +/* tgid to filter index */ +struct pid_hash { + __uint(type, BPF_MAP_TYPE_HASH); + __type(key, int); + __type(value, int); + __uint(max_entries, 1); +} pid_hash SEC(".maps"); + int dropped; +volatile const int use_pid_hash; void *bpf_cast_to_kern_ctx(void *) __ksym; @@ -184,6 +193,18 @@ int perf_sample_filter(void *ctx) kctx = bpf_cast_to_kern_ctx(ctx); k = 0; + + if (use_pid_hash) { + int tgid = bpf_get_current_pid_tgid() >> 32; + int *idx; + + idx = bpf_map_lookup_elem(&pid_hash, &tgid); + if (idx) + k = *idx; + else + goto drop; + } + entry = bpf_map_lookup_elem(&filters, &k); if (entry == NULL) goto drop; |