public inbox for netdev@vger.kernel.org 
 help / color / mirror / Atom feed
From: Yonghong Song <yhs@fb•com>
To: <peterz@infradead•org>, <rostedt@goodmis•org>, <ast@fb•com>,
	<daniel@iogearbox•net>, <netdev@vger•kernel.org>
Cc: <kernel-team@fb•com>
Subject: [PATCH net-next 4/4] bpf: add a test case for helper bpf_perf_prog_read_time
Date: Fri, 1 Sep 2017 09:53:57 -0700	[thread overview]
Message-ID: <20170901165357.465121-5-yhs@fb.com> (raw)
In-Reply-To: <20170901165357.465121-1-yhs@fb.com>

The bpf sample program trace_event is enhanced to use the new
helper to print out enabled/running time.

Signed-off-by: Yonghong Song <yhs@fb•com>
---
 samples/bpf/trace_event_kern.c            | 5 +++++
 tools/testing/selftests/bpf/bpf_helpers.h | 3 +++
 2 files changed, 8 insertions(+)

diff --git a/samples/bpf/trace_event_kern.c b/samples/bpf/trace_event_kern.c
index 41b6115..f372660 100644
--- a/samples/bpf/trace_event_kern.c
+++ b/samples/bpf/trace_event_kern.c
@@ -37,8 +37,10 @@ struct bpf_map_def SEC("maps") stackmap = {
 SEC("perf_event")
 int bpf_prog1(struct bpf_perf_event_data *ctx)
 {
+	char time_fmt[] = "Time Enabled: %lld, Time Running: %lld";
 	char fmt[] = "CPU-%d period %lld ip %llx";
 	u32 cpu = bpf_get_smp_processor_id();
+	struct bpf_perf_time time_buf;
 	struct key_t key;
 	u64 *val, one = 1;
 
@@ -54,6 +56,9 @@ int bpf_prog1(struct bpf_perf_event_data *ctx)
 		return 0;
 	}
 
+	bpf_perf_prog_read_time(ctx, (void *)&time_buf, sizeof(struct bpf_perf_time));
+	bpf_trace_printk(time_fmt, sizeof(time_fmt), time_buf.enabled, time_buf.running);
+
 	val = bpf_map_lookup_elem(&counts, &key);
 	if (val)
 		(*val)++;
diff --git a/tools/testing/selftests/bpf/bpf_helpers.h b/tools/testing/selftests/bpf/bpf_helpers.h
index fe41852..ddad690 100644
--- a/tools/testing/selftests/bpf/bpf_helpers.h
+++ b/tools/testing/selftests/bpf/bpf_helpers.h
@@ -74,6 +74,9 @@ static int (*bpf_perf_read_counter_time)(void *map, unsigned long long flags,
 				       void *counter_time_buf,
 				       unsigned int buf_size) =
 	(void *) BPF_FUNC_perf_read_counter_time;
+static int (*bpf_perf_prog_read_time)(void *ctx, void *time_buf,
+				      unsigned int size) =
+	(void *) BPF_FUNC_perf_prog_read_time;
 
 
 /* llvm builtin functions that eBPF C program may use to
-- 
2.9.5

      parent reply	other threads:[~2017-09-01 16:53 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-09-01 16:53 [PATCH net-next 0/4] bpf: add two helpers to read perf event enabled/running time Yonghong Song
2017-09-01 16:53 ` [PATCH net-next 1/4] bpf: add helper bpf_perf_read_counter_time for perf event array map Yonghong Song
2017-09-01 20:29   ` Alexei Starovoitov
2017-09-01 20:50     ` Peter Zijlstra
2017-09-01 21:01       ` Yonghong Song
2017-09-01 20:41   ` Peter Zijlstra
2017-09-01 16:53 ` [PATCH net-next 2/4] bpf: add a test case for helper bpf_perf_read_counter_time Yonghong Song
2017-09-01 16:53 ` [PATCH net-next 3/4] bpf: add helper bpf_perf_prog_read_time Yonghong Song
2017-09-01 16:53 ` Yonghong Song [this message]

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=20170901165357.465121-5-yhs@fb.com \
    --to=yhs@fb$(echo .)com \
    --cc=ast@fb$(echo .)com \
    --cc=daniel@iogearbox$(echo .)net \
    --cc=kernel-team@fb$(echo .)com \
    --cc=netdev@vger$(echo .)kernel.org \
    --cc=peterz@infradead$(echo .)org \
    --cc=rostedt@goodmis$(echo .)org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox