•  


Make rr work with `perf_event_paranoid`=2 · Issue #3659 · rr-debugger/rr · GitHub
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

Make rr work with perf_event_paranoid =2 #3659

Open
rocallahan opened this issue Dec 1, 2023 · 9 comments
Open

Make rr work with perf_event_paranoid =2 #3659

rocallahan opened this issue Dec 1, 2023 · 9 comments

Comments

@rocallahan
Copy link
Collaborator

I think this might be possible. It would make using rr a bit simpler for most users, and there are environments where changing perf_event_paranoid is really hard.

The basic idea is:

  • Make the desched event be PERF_COUNT_SW_DUMMY (i.e. counts nothing).
  • Set the context_switch flag to generate PERF_RECORD_SWITCH records in the sampling ring buffer.
  • Set the watermark flag and the wakeup_watermark field to trigger an overflow notification when a PERF_CONTEXT_SWITCH record has been written to the ring buffer. Might need to accommodate two records ("switch in", "switch out")... not sure yet.
  • We may need to map the sample buffer and reset the ring-buffer each time it overflows to ensure we keep getting overflow events.
@rocallahan
Copy link
Collaborator Author

A potential issue with this approach is that each sample buffer consumes at least one page of locked memory and some users might have RLIMIT_MEMLOCK limits that rr could run into. However the distros I've looked at so far either default to unlimited mlocked memory, or have a low soft limit but a very high hard limit (1TB on Fedora).

@GitMensch
Copy link
Contributor

What would that result in, performance-wise? Would that be the single implementation or would there be an initial check (which we already have) and an option to switch to this handling?

@rocallahan
Copy link
Collaborator Author

I'm planning to have it always enabled. That simplifies things.

@rocallahan
Copy link
Collaborator Author

Unfortunately it looks like this doesn't work because the kernel does not generate SIGIO for ring-buffer watermark overflows... it marks the event fd readable (generating poll events), but not the signal.

@rocallahan
Copy link
Collaborator Author

Arguably this is a kernel bug. The man page says

Overflow conditions can be  captured  by
       monitoring the event file descriptor with poll(2), select(2), or epoll(7).  Alternatively, the overflow events can be cap?
       tured via sa signal handler, by enabling I/O signaling on the file descriptor
...
       There are two ways to generate overflow notifications.

       The  first  is  to set a wakeup_events or wakeup_watermark value that will trigger if a certain number of samples or bytes
       have been written to the mmap ring buffer.  In this case, POLL_IN is indicated.

@rocallahan
Copy link
Collaborator Author

@rocallahan
Copy link
Collaborator Author

@rocallahan
Copy link
Collaborator Author

It's sort of maddening that "trigger FASYNC signals" and "notify poll waiters" require separate code instead of going through a utility function that does both.

@rocallahan
Copy link
Collaborator Author

With that kernel bug fixed, the following branch pretty much works:
https://github.com/rr-debugger/rr/tree/watermark
The changes are simple.

If/when that kernel fix lands upstream and becomes available, I'll land the rr side. TODO:

  • Dynamically configure rr to use PERF_RECORD_SWITCH if the kernel supports it
  • Investigate using PERF_EVENT_IOC_SET_OUTPUT to share mmap buffers

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

No branches or pull requests

2 participants
- "漢字路" 한글한자자동변환 서비스는 교육부 고전문헌국역지원사업의 지원으로 구축되었습니다.
- "漢字路" 한글한자자동변환 서비스는 전통문화연구회 "울산대학교한국어처리연구실 옥철영(IT융합전공)교수팀"에서 개발한 한글한자자동변환기를 바탕하여 지속적으로 공동 연구 개발하고 있는 서비스입니다.
- 현재 고유명사(인명, 지명등)을 비롯한 여러 변환오류가 있으며 이를 해결하고자 많은 연구 개발을 진행하고자 하고 있습니다. 이를 인지하시고 다른 곳에서 인용시 한자 변환 결과를 한번 더 검토하시고 사용해 주시기 바랍니다.
- 변환오류 및 건의,문의사항은 juntong@juntong.or.kr로 메일로 보내주시면 감사하겠습니다. .
Copyright ⓒ 2020 By '전통문화연구회(傳統文化硏究會)' All Rights reserved.
 한국   대만   중국   일본