From: Daniel Borkmann <daniel@iogearbox.net>
To: Kaixu Xia <xiakaixu@huawei.com>,
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
Date: Thu, 30 Jul 2015 01:56:41 +0200 [thread overview]
Message-ID: <55B96839.1040209@iogearbox.net> (raw)
In-Reply-To: <1438082255-60683-5-git-send-email-xiakaixu@huawei.com>
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 <xiakaixu@huawei.com>
...
> 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 <stdio.h>
> +#include <unistd.h>
> +#include <stdlib.h>
> +#include <stdbool.h>
> +#include <string.h>
> +#include <fcntl.h>
> +#include <poll.h>
> +#include <sys/ioctl.h>
> +#include <linux/perf_event.h>
> +#include <linux/bpf.h>
> +#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);
> + }
next prev parent reply other threads:[~2015-07-29 23:56 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-07-28 11:17 [PATCH v4 0/4] bpf: Introduce the new ability of eBPF programs to access hardware PMU counter Kaixu Xia
2015-07-28 11:17 ` [PATCH v4 1/4] bpf: Make the bpf_prog_array_map more generic Kaixu Xia
2015-07-29 23:17 ` Daniel Borkmann
2015-07-30 1:44 ` Alexei Starovoitov
2015-07-31 8:50 ` xiakaixu
2015-07-31 15:46 ` Alexei Starovoitov
2015-07-28 11:17 ` [PATCH v4 2/4] bpf: Add new bpf map type to store the pointer to struct perf_event Kaixu Xia
2015-07-29 23:30 ` Daniel Borkmann
2015-07-30 1:45 ` Alexei Starovoitov
2015-07-28 11:17 ` [PATCH v4 3/4] bpf: Implement function bpf_perf_event_read() that get the selected hardware PMU conuter Kaixu Xia
2015-07-29 23:51 ` Daniel Borkmann
2015-07-28 11:17 ` [PATCH v4 4/4] samples/bpf: example of get selected PMU counter value Kaixu Xia
2015-07-29 23:56 ` Daniel Borkmann [this message]
2015-07-30 0:08 ` [PATCH v4 0/4] bpf: Introduce the new ability of eBPF programs to access hardware PMU counter Daniel Borkmann
2015-07-30 1:50 ` Alexei Starovoitov
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=55B96839.1040209@iogearbox.net \
--to=daniel@iogearbox.net \
--cc=a.p.zijlstra@chello.nl \
--cc=acme@kernel.org \
--cc=ast@plumgrid.com \
--cc=davem@davemloft.net \
--cc=hekuang@huawei.com \
--cc=jolsa@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=masami.hiramatsu.pt@hitachi.com \
--cc=mingo@redhat.com \
--cc=pi3orama@163.com \
--cc=wangnan0@huawei.com \
--cc=xiakaixu@huawei.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.