Skip to content

Fix code sample at perf_event_open.md#3313

Merged
jasonrandrews merged 2 commits into
ArmDeveloperEcosystem:mainfrom
rntsoma:patch-1
May 20, 2026
Merged

Fix code sample at perf_event_open.md#3313
jasonrandrews merged 2 commits into
ArmDeveloperEcosystem:mainfrom
rntsoma:patch-1

Conversation

@rntsoma
Copy link
Copy Markdown
Contributor

@rntsoma rntsoma commented May 20, 2026

Fix bug on the code sample for printing the counter values. The original code is storing the counters to the pe_val array while trusting that the events read are coming sequentially from the kernel. The fix is to store the counters in their correct location, that is, using the index of the matched event id.

Before submitting a pull request for a new Learning Path, please review Create a Learning Path

  • I have reviewed Create a Learning Path

Please do not include any confidential information in your contribution. This includes confidential microarchitecture details and unannounced product information.

  • I have checked my contribution for confidential information

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of the Creative Commons Attribution 4.0 International License.

Fix bug on the code sample for printing the counter values.
The original code is storing the counters to the pe_val array while trusting that the events read are coming sequentially from the kernel.
The fix is to store the counters in their correct location, that is, using the index of the matched event id
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes the counter-value mapping logic in the perf_event_open Learning Path code sample by storing each read value into the slot corresponding to its matched event ID (rather than assuming the kernel returns group reads in the same order as the events were opened).

Changes:

  • Store counter_results.values[i].value into pe_val[j] (matched event index) instead of pe_val[i] (read order index).

Comment on lines 212 to 216
for(int i = 0; i < counter_results.nr; i++) {
for(int j = 0; j < TOTAL_EVENTS ;j++){
if(counter_results.values[i].id == id[j]){
pe_val[i] = counter_results.values[i].value;
pe_val[j] = counter_results.values[i].value;
}
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@jasonrandrews jasonrandrews merged commit 7cc6914 into ArmDeveloperEcosystem:main May 20, 2026
1 check passed
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.

3 participants