Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1247200

Re: [PATCH V2 1/2] bpf: control the trace data output on current cpu when perf sampling

From Alexei Starovoitov <ast@plumgrid.com>
Newsgroups linux.kernel
Subject Re: [PATCH V2 1/2] bpf: control the trace data output on current cpu when perf sampling
Date 2015-10-14 23:30 +0200
Message-ID <qjBMv-2mZ-25@gated-at.bofh.it> (permalink)
References <qjtvA-70U-7@gated-at.bofh.it> <qjtvA-70U-5@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


On 10/14/15 5:37 AM, Kaixu Xia wrote:
> This patch adds the flag sample_disable to control the trace data
> output process when perf sampling. By setting this flag and
> integrating with ebpf, we can control the data output process and
> get the samples we are most interested in.
>
> The bpf helper bpf_perf_event_sample_control() can control the
> perf_event on current cpu.
>
> Signed-off-by: Kaixu Xia <xiakaixu@huawei.com>
...
> --- a/kernel/events/core.c
> +++ b/kernel/events/core.c
> @@ -6337,6 +6337,9 @@ static int __perf_event_overflow(struct perf_event *event,
>   		irq_work_queue(&event->pending);
>   	}
>
> +	if (!atomic_read(&event->sample_disable))
> +		return ret;
> +

the condition check and the name are inconsistent.
It's either
if (!enabled) return
or
if (disabled) return

>   	if (event->overflow_handler)
>   		event->overflow_handler(event, data, regs);
>   	else
> @@ -7709,6 +7712,14 @@ static void account_event(struct perf_event *event)
>   	account_event_cpu(event, event->cpu);
>   }
>
> +static void perf_event_check_sample_flag(struct perf_event *event)
> +{
> +	if (event->attr.sample_disable == 1)
> +		atomic_set(&event->sample_disable, 0);
> +	else
> +		atomic_set(&event->sample_disable, 1);
> +}

why introduce new attribute for this?
we already have 'disabled' flag.

> +static u64 bpf_perf_event_sample_control(u64 r1, u64 index, u64 flag, u64 r4, u64 r5)
> +{
> +	struct bpf_map *map = (struct bpf_map *) (unsigned long) r1;
> +	struct bpf_array *array = container_of(map, struct bpf_array, map);
> +	struct perf_event *event;
> +
> +	if (unlikely(index >= array->map.max_entries))
> +		return -E2BIG;
> +
> +	event = (struct perf_event *)array->ptrs[index];
> +	if (!event)
> +		return -ENOENT;
> +
> +	if (flag)

please check only bit 0 and check that all other bits are zero as well
for future extensibility.

> +		atomic_dec(&event->sample_disable);

it should be atomic_dec_if_positive();

> +	else
> +		atomic_inc(&event->sample_disable);

and atomic_add_unless()
to make sure we don't wrap on either side.

> +const struct bpf_func_proto bpf_perf_event_sample_control_proto = {

static.

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Back to linux.kernel | Previous | NextPrevious in thread | Find similar | Unroll thread


Thread

[PATCH V2 1/2] bpf: control the trace data output on current cpu when perf sampling Kaixu Xia <xiakaixu@huawei.com> - 2015-10-14 14:40 +0200
  [RFC PATCH] bpf: bpf_perf_event_sample_control_proto can be static kbuild test robot <lkp@intel.com> - 2015-10-14 16:00 +0200
  Re: [PATCH V2 1/2] bpf: control the trace data output on current cpu  when perf sampling kbuild test robot <lkp@intel.com> - 2015-10-14 16:00 +0200
  Re: [PATCH V2 1/2] bpf: control the trace data output on current cpu  when perf sampling Alexei Starovoitov <ast@plumgrid.com> - 2015-10-14 23:30 +0200

csiph-web