Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rdpmc topdown #238

Open
wants to merge 22 commits into
base: master
Choose a base branch
from
Open

Rdpmc topdown #238

wants to merge 22 commits into from

Conversation

willowec
Copy link

Pull Request Description

This PR fixes #207

Intel's topdown events, if opened using perf_event's perf_event_open() behave differently when read using read() than when they are read using rdpmc(). This has a few unfortunate consequences. When a topdown event is read using read() you get a value that is the number of slots recorded for that topdown category. So to get, for example, the percentage of slots that were retiring, you divide the value of TOPDOWN:RETIRING_SLOTS by the value of TOPDOWN:SLOTS and multiply the result by 100.

However, when any topdown event is read using rdpmc(), the result is always one value containing eight 8-bit percentages, no matter which event was read:

     | mem_bound | fetch_lat | br_mispred | heavy_ops | be_bound | fe_bound | bad_spec | retiring
0x   | XX        | XX        | XX         | XX        | XX       | XX       | XX       | XX

In order to extract a percentage from this, you would instead do some shifting and masking as described in tools/perf/Documentation/topdown.txt

This means that storing and accumulating the values of topdown events makes sense only when rdpmc is disabled in PAPI. In order to account for this, an additional metric field was added to perf_event component's pe_event_info_t struct, and is set during initialization for events matching the TOPDOWN base event. Events with this field set no longer have their reset flag cleared when rdpmc is enabled.

A new validation test, topdown_validation.c is added to verify that the results PAPI obtains agree with a direct call to rdpmc()

Because this patch was developed on an Intel Raptorlake machine, some other additions were also necessary to enable the development of this PR:

  • Missing topdown events were added to the adl_glc events header file in libpfm4 (we are still waiting to hear back having this patch added to libpfm4 officially)
  • Preset events were added to papi_events.csv for the adl_glc architecture

Author Checklist

  • Description
    Why this PR exists. Reference all relevant information, including background, issues, test failures, etc
  • Commits
    Commits are self contained and only do one thing
    Commits have a header of the form: module: short description
    Commits have a body (whenever relevant) containing a detailed description of the addressed problem and its solution
  • Tests
    The PR needs to pass all the tests

Willow Cunningham and others added 21 commits September 17, 2024 14:34
… with papi results

As using the rdpmc instruction directly has consistently reported
reasonable results, it is used as the ground truth for this test
…_validation

While investigating the topdown rdpmc issues, it made sense to have more
than one type of code to test. This was later removed once the issue
was identified and resolved.
The tolerance for percentage comparisons was also raised to +-2.5, as
there is often a decent amount of error when rdpmc is disabled.
2.5 percentage points is wide enough to account for that noise while
still being tight enough to ensure the values are reasonable.
Added three missing topdown events to libpfm4 in order to enable
level 2 event collection with rdpmc disabled. The missing events
were TOPDOWN.FRONTEND_BOUND_SLOTS, TOPDOWN.HEAVY_OPS_SLOTS,
and TOPDOWN.FETCH_LAT_SLOTS. This commit has also been submitted
to libpfm4 as a patch.
…papi_events.csv

Because this fix for topdown events was developed on an intel raptorlake
machine, preset events needed to be added in order to run the validation
tests with make fulltest
…OPDOWN events and ensures reset

when rdpmc is enabled, if topdown events are allowed to accumulate they
produce innacurate results. Therefore, a new field needs to be added
for topdown events that ensures their reset flag is not disabled.

The field is named 'metric' instead of 'topdown' so that in case events
are developed in the future with similar behavior to topdown events,
the name will still make sense.
@willowec
Copy link
Author

Converting to a draft as not all of the tests are passing for raptorlake

@willowec willowec marked this pull request as ready for review September 30, 2024 18:15
@willowec
Copy link
Author

Un-drafting as the failing tests are in the sysdetect component and are due to the heterogeneity of the Raptorlake architecture, unrelated to the contributions of this patch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Negative/large values in topdown perf counters
1 participant