Netdev List
 help / color / mirror / Atom feed
From: Alexei Starovoitov <ast@fb.com>
To: Yonghong Song <yhs@fb.com>, <peterz@infradead.org>,
	<rostedt@goodmis.org>, <daniel@iogearbox.net>,
	<netdev@vger.kernel.org>
Cc: <kernel-team@fb.com>
Subject: Re: [PATCH net-next 1/4] bpf: add helper bpf_perf_read_counter_time for perf event array map
Date: Fri, 1 Sep 2017 13:29:17 -0700	[thread overview]
Message-ID: <a1905aeb-b49f-d4e8-91ee-a28a92869da1@fb.com> (raw)
In-Reply-To: <20170901165357.465121-2-yhs@fb.com>

On 9/1/17 9:53 AM, Yonghong Song wrote:
> Hardware pmu counters are limited resources. When there are more
> pmu based perf events opened than available counters, kernel will
> multiplex these events so each event gets certain percentage
> (but not 100%) of the pmu time. In case that multiplexing happens,
> the number of samples or counter value will not reflect the
> case compared to no multiplexing. This makes comparison between
> different runs difficult.
>
> Typically, the number of samples or counter value should be
> normalized before comparing to other experiments. The typical
> normalization is done like:
>   normalized_num_samples = num_samples * time_enabled / time_running
>   normalized_counter_value = counter_value * time_enabled / time_running
> where time_enabled is the time enabled for event and time_running is
> the time running for event since last normalization.
>
> This patch adds helper bpf_perf_read_counter_time for kprobed based perf
> event array map, to read perf counter and enabled/running time.
> The enabled/running time is accumulated since the perf event open.
> To achieve scaling factor between two bpf invocations, users
> can can use cpu_id as the key (which is typical for perf array usage model)
> to remember the previous value and do the calculation inside the
> bpf program.
>
> Signed-off-by: Yonghong Song <yhs@fb.com>

...

> +BPF_CALL_4(bpf_perf_read_counter_time, struct bpf_map *, map, u64, flags,
> +	struct bpf_perf_counter_time *, buf, u32, size)
> +{
> +	struct perf_event *pe;
> +	u64 now;
> +	int err;
> +
> +	if (unlikely(size != sizeof(struct bpf_perf_counter_time)))
> +		return -EINVAL;
> +	err = get_map_perf_counter(map, flags, &buf->counter, &pe);
> +	if (err)
> +		return err;
> +
> +	calc_timer_values(pe, &now, &buf->time.enabled, &buf->time.running);
> +	return 0;
> +}

Peter,
I believe we're doing it correctly above.
It's a copy paste of the same logic as in total_time_enabled/running.
We cannot expose total_time_enabled/running to bpf, since they are
different counters. The above two are specific to bpf usage.
See commit log.

for the whole set:
Acked-by: Alexei Starovoitov <ast@kernel.org>

  reply	other threads:[~2017-09-01 20:30 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 [this message]
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 ` [PATCH net-next 4/4] bpf: add a test case for " Yonghong Song

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=a1905aeb-b49f-d4e8-91ee-a28a92869da1@fb.com \
    --to=ast@fb.com \
    --cc=daniel@iogearbox.net \
    --cc=kernel-team@fb.com \
    --cc=netdev@vger.kernel.org \
    --cc=peterz@infradead.org \
    --cc=rostedt@goodmis.org \
    --cc=yhs@fb.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox