From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754615AbbJNVVP (ORCPT ); Wed, 14 Oct 2015 17:21:15 -0400 Received: from mail-pa0-f41.google.com ([209.85.220.41]:34849 "EHLO mail-pa0-f41.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754111AbbJNVVN (ORCPT ); Wed, 14 Oct 2015 17:21:13 -0400 Subject: Re: [PATCH V2 1/2] bpf: control the trace data output on current cpu when perf sampling To: Kaixu Xia , davem@davemloft.net, acme@kernel.org, mingo@redhat.com, a.p.zijlstra@chello.nl, masami.hiramatsu.pt@hitachi.com, jolsa@kernel.org, daniel@iogearbox.net References: <1444826277-94060-1-git-send-email-xiakaixu@huawei.com> <1444826277-94060-2-git-send-email-xiakaixu@huawei.com> Cc: wangnan0@huawei.com, linux-kernel@vger.kernel.org, pi3orama@163.com, hekuang@huawei.com, netdev@vger.kernel.org From: Alexei Starovoitov Message-ID: <561EC747.8070608@plumgrid.com> Date: Wed, 14 Oct 2015 14:21:11 -0700 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.10; rv:38.0) Gecko/20100101 Thunderbird/38.3.0 MIME-Version: 1.0 In-Reply-To: <1444826277-94060-2-git-send-email-xiakaixu@huawei.com> Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 ... > --- 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.