Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754299AbbG2X4v (ORCPT ); Wed, 29 Jul 2015 19:56:51 -0400 Received: from www62.your-server.de ([213.133.104.62]:40148 "EHLO www62.your-server.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753827AbbG2X4u (ORCPT ); Wed, 29 Jul 2015 19:56:50 -0400 Message-ID: <55B96839.1040209@iogearbox.net> Date: Thu, 30 Jul 2015 01:56:41 +0200 From: Daniel Borkmann User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.4.0 MIME-Version: 1.0 To: Kaixu Xia , ast@plumgrid.com, davem@davemloft.net, acme@kernel.org, mingo@redhat.com, a.p.zijlstra@chello.nl, masami.hiramatsu.pt@hitachi.com, jolsa@kernel.org CC: wangnan0@huawei.com, linux-kernel@vger.kernel.org, pi3orama@163.com, hekuang@huawei.com Subject: Re: [PATCH v4 4/4] samples/bpf: example of get selected PMU counter value References: <1438082255-60683-1-git-send-email-xiakaixu@huawei.com> <1438082255-60683-5-git-send-email-xiakaixu@huawei.com> In-Reply-To: <1438082255-60683-5-git-send-email-xiakaixu@huawei.com> Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit X-Authenticated-Sender: daniel@iogearbox.net Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1775 Lines: 61 On 07/28/2015 01:17 PM, Kaixu Xia wrote: > This is a simple example and shows how to use the new ability > to get the selected Hardware PMU counter value. > > Signed-off-by: Kaixu Xia ... > diff --git a/samples/bpf/tracex6_user.c b/samples/bpf/tracex6_user.c > new file mode 100644 > index 0000000..e607eac > --- /dev/null > +++ b/samples/bpf/tracex6_user.c > @@ -0,0 +1,67 @@ > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include "libbpf.h" > +#include "bpf_load.h" > + > +static void test_bpf_perf_event(void) > +{ > + int nr_cpus = sysconf(_SC_NPROCESSORS_CONF); > + int *pmu_fd = malloc(nr_cpus * sizeof(int)); > + unsigned long value; > + int i; > + > + struct perf_event_attr attr_insn_pmu = { > + .freq = 0, > + .sample_period = 0x7fffffffffffffffULL, Nit: #define ... > + .inherit = 0, > + .type = PERF_TYPE_HARDWARE, > + .read_format = 0, > + .sample_type = 0, > + .config = 0,/* PMU: cycles */ > + }; > + > + for (i = 0; i < nr_cpus; i++) { > + pmu_fd[i] = perf_event_open(&attr_insn_pmu, -1/*pid*/, i/*cpu*/, -1/*group_fd*/, 0); > + if (pmu_fd[i] < 0) > + printf("event syscall failed\n"); > + > + bpf_update_elem(map_fd[0], &i, (pmu_fd + i), BPF_ANY); Nit: you use pmu_fd[i], but here (pmu_fd + i)? Maybe better &pmu_fd[i]? > + ioctl(pmu_fd[i], PERF_EVENT_IOC_ENABLE, 0); > + } -- 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/