From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754478AbbGWW5C (ORCPT ); Thu, 23 Jul 2015 18:57:02 -0400 Received: from mail-yk0-f170.google.com ([209.85.160.170]:34088 "EHLO mail-yk0-f170.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753990AbbGWW47 (ORCPT ); Thu, 23 Jul 2015 18:56:59 -0400 Subject: Re: [PATCH v3 2/3] bpf: Implement function bpf_perf_event_read() that get the selected hardware PMU conuter 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 References: <1437644562-84431-1-git-send-email-xiakaixu@huawei.com> <1437644562-84431-3-git-send-email-xiakaixu@huawei.com> Cc: wangnan0@huawei.com, linux-kernel@vger.kernel.org, pi3orama@163.com, hekuang@huawei.com From: Alexei Starovoitov Message-ID: <55B17139.2070707@plumgrid.com> Date: Thu, 23 Jul 2015 15:56:57 -0700 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.10; rv:38.0) Gecko/20100101 Thunderbird/38.0.1 MIME-Version: 1.0 In-Reply-To: <1437644562-84431-3-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 7/23/15 2:42 AM, Kaixu Xia wrote: > According to the perf_event_map_fd and index, the function > bpf_perf_event_read() can convert the corresponding map > value to the pointer to struct perf_event and return the > Hardware PMU counter value. > > Signed-off-by: Kaixu Xia ... > +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; probably ENOENT makes more sense here. > + > + if (event->state != PERF_EVENT_STATE_ACTIVE) > + return -ENOENT; and -EINVAL here?