From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752959AbbHCJe4 (ORCPT ); Mon, 3 Aug 2015 05:34:56 -0400 Received: from casper.infradead.org ([85.118.1.10]:47203 "EHLO casper.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752761AbbHCJey (ORCPT ); Mon, 3 Aug 2015 05:34:54 -0400 Date: Mon, 3 Aug 2015 11:34:37 +0200 From: Peter Zijlstra To: Kaixu Xia Cc: ast@plumgrid.com, davem@davemloft.net, acme@kernel.org, mingo@redhat.com, masami.hiramatsu.pt@hitachi.com, jolsa@kernel.org, wangnan0@huawei.com, linux-kernel@vger.kernel.org, pi3orama@163.com, hekuang@huawei.com Subject: Re: [PATCH v3 2/3] bpf: Implement function bpf_perf_event_read() that get the selected hardware PMU conuter Message-ID: <20150803093437.GE19282@twins.programming.kicks-ass.net> References: <1437644562-84431-1-git-send-email-xiakaixu@huawei.com> <1437644562-84431-3-git-send-email-xiakaixu@huawei.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1437644562-84431-3-git-send-email-xiakaixu@huawei.com> User-Agent: Mutt/1.5.21 (2012-12-30) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Jul 23, 2015 at 09:42:41AM +0000, Kaixu Xia wrote: > +static u64 bpf_perf_event_read(u64 r1, u64 index, u64 r3, 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 (index >= array->map.max_entries) > + return -E2BIG; > + > + event = array->events[index]; > + if (!event) > + return -EBADF; > + > + if (event->state != PERF_EVENT_STATE_ACTIVE) > + return -ENOENT; > + > + if (event->oncpu != raw_smp_processor_id() && > + event->ctx->task != current) > + return -EINVAL; > + > + if (event->attr.inherit) > + return -EINVAL; > + > + __perf_event_read(event); > + > + return perf_event_count(event); > +} Please no poking of event internal state outside of perf code.