Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753906AbbGXB5c (ORCPT ); Thu, 23 Jul 2015 21:57:32 -0400 Received: from szxga01-in.huawei.com ([58.251.152.64]:45016 "EHLO szxga01-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752723AbbGXB5a (ORCPT ); Thu, 23 Jul 2015 21:57:30 -0400 Message-ID: <55B19B7A.4030400@huawei.com> Date: Fri, 24 Jul 2015 09:57:14 +0800 From: xiakaixu User-Agent: Mozilla/5.0 (Windows NT 6.1; rv:17.0) Gecko/20130801 Thunderbird/17.0.8 MIME-Version: 1.0 To: Alexei Starovoitov CC: , , , , , , , , , Subject: Re: [PATCH v3 2/3] bpf: Implement function bpf_perf_event_read() that get the selected hardware PMU conuter References: <1437644562-84431-1-git-send-email-xiakaixu@huawei.com> <1437644562-84431-3-git-send-email-xiakaixu@huawei.com> <55B17139.2070707@plumgrid.com> In-Reply-To: <55B17139.2070707@plumgrid.com> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8bit X-Originating-IP: [10.111.101.23] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1240 Lines: 44 于 2015/7/24 6:56, Alexei Starovoitov 写道: > 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? Yeah, the errno is better. Thanks! > > > . > -- 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/