Skip to content

Add support for heterogenous cpus to PerfListener #46

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

Merged
merged 2 commits into from
Apr 14, 2024

Conversation

otargowski
Copy link
Contributor

@otargowski otargowski commented Mar 22, 2024

Related issue: sio2project/sinol-make#158.

This is achieved by opening a raw perf event for every cpu core type, quite similiarly to the perf userspace tool.
The values needed to open the proper raw events are gathered from /sys/devices/cpu*/{type,events/instructions,format/*}.
This solution should work as long as the sysfs interface doesn't drastically change while maintaining compatibility with older kernels, as the mentioned interface seems to be the same as in at least 2014, when there was a failed effort to document the interface as stable.

I tested on:

  • linux 6.8 with Intel 12700k (both hybrid and with e-cores disabled in bios settings)
  • the above, but with a perf event that has a more complex config
  • linux 6.6 with Intel core 2 duo T9600 (cpu from 2008)
  • linux 4.15 with some AMD EPYC processor (a vps)
  • linux 6.8 with AMD Ryzen 7 7735HS

Alternative approaches that I considered:

  • use libpfm4. This would probably need to be updated semi-often to support future cpus.
  • hardcode the config value for the perf event, as both Intel and AMD seem to use 0xc0 for counting instructions at the moment.
  • utilize a new config layout for PERF_TYPE_HARDWARE event type (see "INTEL HYBRID SUPPORT" in perf-stat(1)). This would require some separate logic for handling older kernels which don't support this.

I think that using raw perf events based on data from sysfs is more robust than the above methods.

Copy link
Contributor

@DietPawel DietPawel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The logic is a little messy, but so is the interface, so the complexity is adequate.
I proposed 2 cosmetic changes.
Thank You for this contribution to make our tool support newer CPUs!

This is achieved by opening a raw perf event for every cpu core type,
quite similiarly to the perf userspace tool.
The values needed to open the proper raw events are gathered from
/sys/devices/cpu*/{type,events/instructions,format/*}
This solution should work as long as the sysfs interface doesn't
drastically change while maintaining compatibility with older kernels,
as the mentioned interface seems to be the same as in at least 2014.
@DietPawel DietPawel merged commit 66e9be7 into sio2project:master Apr 14, 2024
@otargowski otargowski deleted the intel-hybrid-PR branch April 14, 2024 17:43
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.

2 participants