Fix code sample at perf_event_open.md#3313
Merged
Merged
Conversation
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
Contributor
There was a problem hiding this comment.
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].valueintope_val[j](matched event index) instead ofpe_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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
Please do not include any confidential information in your contribution. This includes confidential microarchitecture details and unannounced product 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.