dendibakh / perf-book

The book "Performance Analysis and Tuning on Modern CPU"
https://book.easyperf.net/perf_book
Creative Commons Zero v1.0 Universal
2.12k stars 156 forks source link

Lally/marker api #17

Closed dendibakh closed 1 year ago

lally commented 1 year ago

Odd, the {} should zero-initialize that, and works on my machine. I wonder if it's a compiler version thing.

On Fri, Apr 14, 2023, 6:56 AM Denis Bakhvalov @.***> wrote:

@.**** commented on this pull request.

In chapters/5-Power-And-Performance/5-1 Code Instrumentation.md https://github.com/dendibakh/perf-book/pull/17#discussion_r1166689154:

+ +// The flags to perf_event_open() determine which fields are returned +// from the resulting FD. +struct read_format { uint64_t nr, time_enabled, time_running, values[2]; }; +void require_pfm(int value) { assert(value == PFM_SUCCESS); } +void require_nonneg(int value) { assert(value >= 0); } + +int main(int argc, char **argv) {

  • double value = uintptr_t(argv) % 50000; // Avoid compiler precomputation
  • int event_fd;
  • perf_event_attr perf_attr{};
  • perf_attr.size = sizeof(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 perf_setup{};
  • perf_setup.size = sizeof(pfm_perf_encode_arg_t);

BTW, the memset here is also needed :)

memset(&perf_setup, 0, sizeof(pfm_perf_encode_arg_t));

— Reply to this email directly, view it on GitHub https://github.com/dendibakh/perf-book/pull/17#pullrequestreview-1385238353, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAAK4S3R6KECDKVVQFOQYYTXBEUPHANCNFSM6AAAAAAUPFPOB4 . You are receiving this because you were mentioned.Message ID: @.***>

dendibakh commented 1 year ago

Odd, the {} should zero-initialize that, and works on my machine. I wonder if it's a compiler version thing.

Ah, OK, I see what's going on now. I compiled it with GCC 11.3.0, and it complained (because it's C-compilation, not C++) about {}:

c-ray-f-mod.c:247:37: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘{’ token
  247 |     pfm_perf_encode_arg_t perf_setup{};
      |                                     ^
c-ray-f-mod.c:249:5: error: ‘perf_setup’ undeclared (first use in this function)
  249 |     perf_setup.size = sizeof(pfm_perf_encode_arg_t);
      |     ^~~~~~~~~~

That's why I deleted it but didn't add memset. :)

lally commented 1 year ago

Ah. It's a c++-ism.

On Fri, Apr 14, 2023, 9:50 AM Denis Bakhvalov @.***> wrote:

Odd, the {} should zero-initialize that, and works on my machine. I wonder if it's a compiler version thing.

Ah, OK, I see what's going on now. I compiled it with GCC 11.3.0, and it complained about {}:

c-ray-f-mod.c:247:37: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘attribute’ before ‘{’ token 247 | pfm_perf_encode_arg_t perf_setup{}; | ^ c-ray-f-mod.c:249:5: error: ‘perf_setup’ undeclared (first use in this function) 249 | perf_setup.size = sizeof(pfm_perf_encode_arg_t); | ^~~~~~

That's why I deleted it but didn't add memset. :)

— Reply to this email directly, view it on GitHub https://github.com/dendibakh/perf-book/pull/17#issuecomment-1508540091, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAAK4S7VUSSHWIA6NW4P5EDXBFI3XANCNFSM6AAAAAAUPFPOB4 . You are receiving this because you were mentioned.Message ID: @.***>

dendibakh commented 1 year ago

Merged with #20.