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

Lally/marker api #20

Merged
merged 13 commits into from
May 15, 2023
Merged

Lally/marker api #20

merged 13 commits into from
May 15, 2023

Conversation

dendibakh
Copy link
Owner

Hey @lally, for some reason I couldn't push changes into your branch (protected branch?), so I opened a new PR here. Previous PR is here: #17.

@dendibakh
Copy link
Owner Author

@lally, please review. Notice TODO: @Lally comments, feel free to edit and send your patches.

@dendibakh
Copy link
Owner Author

@lally, ping

@lally
Copy link

lally commented May 5, 2023 via email

@lally
Copy link

lally commented May 7, 2023

@dendibakh this is getting confusing. I couldn't push to the branch for this PR. I've pushed to this branch: https://github.com/lally/perf-book/tree/upstream/lally/marker-api

@dendibakh
Copy link
Owner Author

dendibakh commented May 9, 2023

@lally, I pulled your changes and made some more edits. From my perspective, we are good to go.
Please review one last time and let me know if you have any comments. Anything you would like to add/change?

@lally
Copy link

lally commented May 13, 2023

I'll put in 2 comments here instead of ping-ponging with branches. I think this is good.

  1. "It is possible to detect when the thread wasn't running by requesting CPU cycles consumed (UNHALTED_CORE_CYCLES, only counts when the thread is running) and comparing against wall-clock. " is missing a word. Perhaps "the wall-clock" or "wall-clock time?"

  2. The setup code in render() between pfm_initialize() and the declaration of read_format should really be called only once. Say in main() or some other setup_render_instrumentation() function? Something like:

static int s_event_fd = -1;
void setup_render_instrumentation() {
  if (s_event_fd < 0) {
   pfm_initialize();
   struct perf_event_attr perf_attr;
   memset(&perf_attr, 0, sizeof(perf_attr));
   perf_attr.size = sizeof(struct perf_event_attr);
   perf_attr.read_format = PERF_FORMAT_TOTAL_TIME_ENABLED | 
                           PERF_FORMAT_TOTAL_TIME_RUNNING | PERF_FORMAT_GROUP;
   
   pfm_perf_encode_arg_t arg;
   memset(&arg, 0, sizeof(pfm_perf_encode_arg_t));
   arg.size = sizeof(pfm_perf_encode_arg_t);
   arg.attr = &perf_attr;
    
   pfm_get_os_event_encoding("instructions", PFM_PLM3, PFM_OS_PERF_EVENT_EXT, &arg);
   int leader_fd = perf_event_open(&perf_attr, 0, -1, -1, 0);
   pfm_get_os_event_encoding("cycles", PFM_PLM3, PFM_OS_PERF_EVENT_EXT, &arg);
   s_event_fd = perf_event_open(&perf_attr, 0, -1, leader_fd, 0);
   pfm_get_os_event_encoding("branches", PFM_PLM3, PFM_OS_PERF_EVENT_EXT, &arg);
   s_event_fd = perf_event_open(&perf_attr, 0, -1, leader_fd, 0);
   pfm_get_os_event_encoding("branch-misses", PFM_PLM3, PFM_OS_PERF_EVENT_EXT, &arg);
   s_event_fd = perf_event_open(&perf_attr, 0, -1, leader_fd, 0);
  }
}

struct read_format { uint64_t nr, time_enabled, time_running, values[4]; };

And then call setup_render_instrumentation() at the head of render() instead of all that code that's other now and use s_event_fd instead of event_fd in the read() calls.

@dendibakh
Copy link
Owner Author

I'll put in 2 comments here instead of ping-ponging with branches. I think this is good.

  1. "It is possible to detect when the thread wasn't running by requesting CPU cycles consumed (UNHALTED_CORE_CYCLES, only counts when the thread is running) and comparing against wall-clock. " is missing a word. Perhaps "the wall-clock" or "wall-clock time?"

Thanks. Will fix.

  1. The setup code in render() between pfm_initialize() and the declaration of read_format should really be called only once. Say in main() or some other setup_render_instrumentation() function? Something like:

Good catch. In this case, render() is called once, so it should be OK. But I will leave a note in the text.

@dendibakh dendibakh merged commit 37225fc into main May 15, 2023
@dendibakh dendibakh mentioned this pull request May 16, 2023
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