google / google/benchmark

[BUG] Perf counters not multiplexed

Open
#1,813 0 comments 0 reactions 1 assignee Claimed by @dmah42 View on GitHub
Dominant language
C++
Stars
10.4k
Forks
1.8k
Avg merge
2d 4h
Merged PRs (30d)
8

Description

**Describe the bug**

We do not seem to fully support multiplexing in benchmark perf_counters, which can result in undercounting by a factor of 2..3.

There is an attempt to have multiple 'leaders' and we do specify `PERF_FORMAT_GROUP`, but not `PERF_FORMAT_TOTAL_TIME_ENABLED` nor `PERF_FORMAT_TOTAL_TIME_RUNNING`. The latter two are required to extrapolate the counter values according to how long they are running.

**System**
- OS: Linux
- Compiler and version: clang near trunk

**To reproduce**
Request many (>6) counters.

**Expected behavior**
Values are scaled according to the relative time during which the counter was enabled/bound to HW.

**Additional context**

From the [manual](https://man7.org/linux/man-pages/man2/perf_event_open.2.html):

If PERF_FORMAT_GROUP was specified to allow reading all events
in a group at once:

struct read_format {
u64 nr; /* The number of events */
u64 time_enabled; /* if PERF_FORMAT_TOTAL_TIME_ENABLED */
u64 time_running; /* if PERF_FORMAT_TOTAL_TIME_RUNNING */
struct {
u64 value; /* The value of the event */

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.