Skip to content

bpf: add two helpers to read perf event enabled/running time

Yonghong Song lkml netdev 7 versions – In review

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v7 Latest5 patches 2 repliesIn review
  2. v64 patches 3 repliesSuperseded
  3. v54 patches 4 repliesSuperseded
Earlier versions · 4
VersionPostedPatchesRepliesStatus
v44 patches2 repliesSuperseded
v34 patches0 repliesSuperseded
v24 patches1 replySuperseded
v14 patches4 repliesSuperseded

Changes in v7 from the cover letter

. restructure the patch set so that all perf related changes are
in the first one to make cherry-pick easier,
. address Daniel's comments to clear user buffer in all error cases
for both helpers.

Patches in v7 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/5bpf: perf event change needed for subsequent bpf helpersinclude/linux/perf_event.h kernel/bpf/arraymap.c kernel/events/core.c +1 more+20 -61 reply
2/5bpf: add helper bpf_perf_event_read_value for perf event array mapinclude/uapi/linux/bpf.h kernel/bpf/verifier.c kernel/trace/bpf_trace.c+63 -70 replies
3/5bpf: add a test case for helper bpf_perf_event_read_valuesamples/bpf/tracex6_kern.c samples/bpf/tracex6_user.c tools/include/uapi/linux/bpf.h +1 more+43 -20 replies
4/5bpf: add helper bpf_perf_prog_read_valueinclude/uapi/linux/bpf.h kernel/trace/bpf_trace.c+37 -10 replies
5/5bpf: add a test case for helper bpf_perf_prog_read_valuesamples/bpf/trace_event_kern.c samples/bpf/trace_event_user.c tools/include/uapi/linux/bpf.h +1 more+23 -60 replies

Reviews trailers per patch

All 5 patches have a Reviewed-by or Acked-by.

PatchAlexei StarovoitovDaniel BorkmannPeter Zijlstra (Intel)
1/5A-b
2/5A-b A-b
3/5A-b A-b
4/5A-b A-b
5/5A-b A-b

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes. Scroll the table sideways for all 3 reviewers.

Read the v7 thread

Cover letter [PATCH net-next v7 0/5] bpf: add two helpers to read perf event enabled/running time

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 set implements two helper functions.
The helper bpf_perf_event_read_value reads counter/time_enabled/time_running for perf event array map. The helper bpf_perf_prog_read_value read counter/time_enabled/time_running for bpf prog with type BPF_PROG_TYPE_PERF_EVENT.

[Dave, Peter,

Patch set has been restructured such that all perf (non-bpf) related changes are in the first commit. The whole patch set should be merged into net-next and the first commit cherry-picked to tip to avoid conflicts during the merge window.

Thanks!
]

Changelogs:
v6->v7:
. restructure the patch set so that all perf related changes are
in the first one to make cherry-pick easier,
. address Daniel's comments to clear user buffer in all error cases
for both helpers.
v5->v6:
. rebase on top of net-next.
v4->v5:
. fix some coding style issues,
. memset the input buffer in case of error for ARG_PTR_TO_UNINIT_MEM
type of argument.
v3->v4:
. fix a build failure.
v2->v3:
. counters should be read in order to read enabled/running time. This is to
prevent that counters and enabled/running time may be read separately.
v1->v2:
. reading enabled/running time should be together with reading counters
which contains the logic to ensure the result is valid.

Yonghong Song (5):
bpf: perf event change needed for subsequent bpf helpers
bpf: add helper bpf_perf_event_read_value for perf event array map
bpf: add a test case for helper bpf_perf_event_read_value
bpf: add helper bpf_perf_prog_read_value
bpf: add a test case for helper bpf_perf_prog_read_value

 include/linux/perf_event.h                |  7 ++-
 include/uapi/linux/bpf.h                  | 29 +++++++++++-
 kernel/bpf/arraymap.c                     |  2 +-
 kernel/bpf/verifier.c                     |  4 +-
 kernel/events/core.c                      | 15 ++++++-
 kernel/trace/bpf_trace.c                  | 73 +++++++++++++++++++++++++++++--
 samples/bpf/trace_event_kern.c            | 10 +++++
 samples/bpf/trace_event_user.c            | 13 +++---
 samples/bpf/tracex6_kern.c                | 26 +++++++++++
 samples/bpf/tracex6_user.c                | 13 +++++-
 tools/include/uapi/linux/bpf.h            |  4 +-
 tools/testing/selftests/bpf/bpf_helpers.h |  6 +++
 12 files changed, 183 insertions(+), 19 deletions(-)
Signature · 1 line
2.9.5