Commit 33581847 authored by Namhyung Kim's avatar Namhyung Kim Committed by Arnaldo Carvalho de Melo

perf bpf filter: Add 'pid' sample data support

The pid is special because it's saved in the PERF_SAMPLE_TID together.
So it needs to differenciate tid and pid using the 'part' field in the
perf bpf filter entry struct.
Signed-off-by: default avatarNamhyung Kim <namhyung@kernel.org>
Acked-by: default avatarJiri Olsa <jolsa@kernel.org>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: Hao Luo <haoluo@google.com>
Cc: Ian Rogers <irogers@google.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: James Clark <james.clark@arm.com>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Leo Yan <leo.yan@linaro.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Ravi Bangoria <ravi.bangoria@amd.com>
Cc: Song Liu <song@kernel.org>
Cc: Stephane Eranian <eranian@google.com>
Cc: bpf@vger.kernel.org
Link: https://lore.kernel.org/r/20230314234237.3008956-2-namhyung@kernel.orgSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
parent 27c6f245
...@@ -36,6 +36,7 @@ int perf_bpf_filter__prepare(struct evsel *evsel) ...@@ -36,6 +36,7 @@ int perf_bpf_filter__prepare(struct evsel *evsel)
list_for_each_entry(expr, &evsel->bpf_filters, list) { list_for_each_entry(expr, &evsel->bpf_filters, list) {
struct perf_bpf_filter_entry entry = { struct perf_bpf_filter_entry entry = {
.op = expr->op, .op = expr->op,
.part = expr->part,
.flags = expr->sample_flags, .flags = expr->sample_flags,
.value = expr->val, .value = expr->val,
}; };
...@@ -76,7 +77,7 @@ u64 perf_bpf_filter__lost_count(struct evsel *evsel) ...@@ -76,7 +77,7 @@ u64 perf_bpf_filter__lost_count(struct evsel *evsel)
return skel ? skel->bss->dropped : 0; return skel ? skel->bss->dropped : 0;
} }
struct perf_bpf_filter_expr *perf_bpf_filter_expr__new(unsigned long sample_flags, struct perf_bpf_filter_expr *perf_bpf_filter_expr__new(unsigned long sample_flags, int part,
enum perf_bpf_filter_op op, enum perf_bpf_filter_op op,
unsigned long val) unsigned long val)
{ {
...@@ -85,6 +86,7 @@ struct perf_bpf_filter_expr *perf_bpf_filter_expr__new(unsigned long sample_flag ...@@ -85,6 +86,7 @@ struct perf_bpf_filter_expr *perf_bpf_filter_expr__new(unsigned long sample_flag
expr = malloc(sizeof(*expr)); expr = malloc(sizeof(*expr));
if (expr != NULL) { if (expr != NULL) {
expr->sample_flags = sample_flags; expr->sample_flags = sample_flags;
expr->part = part;
expr->op = op; expr->op = op;
expr->val = val; expr->val = val;
} }
......
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
struct perf_bpf_filter_expr { struct perf_bpf_filter_expr {
struct list_head list; struct list_head list;
enum perf_bpf_filter_op op; enum perf_bpf_filter_op op;
int part;
unsigned long sample_flags; unsigned long sample_flags;
unsigned long val; unsigned long val;
}; };
...@@ -16,7 +17,7 @@ struct perf_bpf_filter_expr { ...@@ -16,7 +17,7 @@ struct perf_bpf_filter_expr {
struct evsel; struct evsel;
#ifdef HAVE_BPF_SKEL #ifdef HAVE_BPF_SKEL
struct perf_bpf_filter_expr *perf_bpf_filter_expr__new(unsigned long sample_flags, struct perf_bpf_filter_expr *perf_bpf_filter_expr__new(unsigned long sample_flags, int part,
enum perf_bpf_filter_op op, enum perf_bpf_filter_op op,
unsigned long val); unsigned long val);
int perf_bpf_filter__parse(struct list_head *expr_head, const char *str); int perf_bpf_filter__parse(struct list_head *expr_head, const char *str);
......
...@@ -11,7 +11,15 @@ ...@@ -11,7 +11,15 @@
static int sample(unsigned long sample_flag) static int sample(unsigned long sample_flag)
{ {
perf_bpf_filter_lval.sample = sample_flag; perf_bpf_filter_lval.sample.type = sample_flag;
perf_bpf_filter_lval.sample.part = 0;
return BFT_SAMPLE;
}
static int sample_part(unsigned long sample_flag, int part)
{
perf_bpf_filter_lval.sample.type = sample_flag;
perf_bpf_filter_lval.sample.part = part;
return BFT_SAMPLE; return BFT_SAMPLE;
} }
...@@ -56,6 +64,7 @@ ident [_a-zA-Z][_a-zA-Z0-9]+ ...@@ -56,6 +64,7 @@ ident [_a-zA-Z][_a-zA-Z0-9]+
ip { return sample(PERF_SAMPLE_IP); } ip { return sample(PERF_SAMPLE_IP); }
id { return sample(PERF_SAMPLE_ID); } id { return sample(PERF_SAMPLE_ID); }
tid { return sample(PERF_SAMPLE_TID); } tid { return sample(PERF_SAMPLE_TID); }
pid { return sample_part(PERF_SAMPLE_TID, 1); }
cpu { return sample(PERF_SAMPLE_CPU); } cpu { return sample(PERF_SAMPLE_CPU); }
time { return sample(PERF_SAMPLE_TIME); } time { return sample(PERF_SAMPLE_TIME); }
addr { return sample(PERF_SAMPLE_ADDR); } addr { return sample(PERF_SAMPLE_ADDR); }
......
...@@ -20,7 +20,10 @@ static void perf_bpf_filter_error(struct list_head *expr __maybe_unused, ...@@ -20,7 +20,10 @@ static void perf_bpf_filter_error(struct list_head *expr __maybe_unused,
%union %union
{ {
unsigned long num; unsigned long num;
unsigned long sample; struct {
unsigned long type;
int part;
} sample;
enum perf_bpf_filter_op op; enum perf_bpf_filter_op op;
struct perf_bpf_filter_expr *expr; struct perf_bpf_filter_expr *expr;
} }
...@@ -48,7 +51,7 @@ filter_term ...@@ -48,7 +51,7 @@ filter_term
filter_term: filter_term:
BFT_SAMPLE BFT_OP BFT_NUM BFT_SAMPLE BFT_OP BFT_NUM
{ {
$$ = perf_bpf_filter_expr__new($1, $2, $3); $$ = perf_bpf_filter_expr__new($1.type, $1.part, $2, $3);
} }
%% %%
...@@ -17,7 +17,8 @@ enum perf_bpf_filter_op { ...@@ -17,7 +17,8 @@ enum perf_bpf_filter_op {
/* BPF map entry for filtering */ /* BPF map entry for filtering */
struct perf_bpf_filter_entry { struct perf_bpf_filter_entry {
enum perf_bpf_filter_op op; enum perf_bpf_filter_op op;
__u64 flags; __u32 part; /* sub-sample type info when it has multiple values */
__u64 flags; /* perf sample type flags */
__u64 value; __u64 value;
}; };
......
...@@ -40,7 +40,10 @@ static inline __u64 perf_get_sample(struct bpf_perf_event_data_kern *kctx, ...@@ -40,7 +40,10 @@ static inline __u64 perf_get_sample(struct bpf_perf_event_data_kern *kctx,
case PERF_SAMPLE_ID: case PERF_SAMPLE_ID:
return kctx->data->id; return kctx->data->id;
case PERF_SAMPLE_TID: case PERF_SAMPLE_TID:
return kctx->data->tid_entry.tid; if (entry->part)
return kctx->data->tid_entry.pid;
else
return kctx->data->tid_entry.tid;
case PERF_SAMPLE_CPU: case PERF_SAMPLE_CPU:
return kctx->data->cpu_entry.cpu; return kctx->data->cpu_entry.cpu;
case PERF_SAMPLE_TIME: case PERF_SAMPLE_TIME:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment