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

Add Runtime_events.EV_FUTEX_WAIT and EV_EMPTY_MINOR #13407

Open
wants to merge 1 commit into
base: trunk
Choose a base branch
from

Conversation

talex5
Copy link
Contributor

@talex5 talex5 commented Aug 28, 2024

EV_OS_WAIT is useful to see in traces when OCaml asked the OS to suspend a domain. If the domain is waiting for another domain on the same CPU, this is the point where it is likely to be scheduled.

EV_EMPTY_MINOR shows when a domain is trying to empty its minor heap. It may be a long time between starting this process and actually performing a minor GC if, for example, another domain is holding the platform lock. Without this event, profiling tools tend to under-report the amount of time spent on GC.

/cc @sadiqj @kayceesrk (https://discuss.ocaml.org/t/ocaml-5-performance/15014/19?u=talex5)

Example trace showing the new events:

Trace showing new events

| EV_OS_WAIT
(**
Event spanning calls to the OS to wait for another domain.
@since 5.3
Copy link
Contributor

Choose a reason for hiding this comment

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

This should be 5.4, as 5.3 has already branched.

@@ -285,7 286,9 @@ void caml_plat_futex_free(caml_plat_futex* ftx) {
void caml_plat_futex_wait(caml_plat_futex* ftx,
caml_plat_futex_value undesired) {
while (atomic_load_acquire(&ftx->value) == undesired) {
CAML_EV_BEGIN(EV_OS_WAIT);
Copy link
Contributor

Choose a reason for hiding this comment

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

OS_WAIT seems too general for what's happening here. For example, waiting on select or accept call would also be "waiting on the OS". Would FUTEX_WAIT be more appropriate?

EV_FUTEX_WAIT is useful to see in traces when OCaml asked the OS to
suspend a domain. If the domain is waiting for another domain on the
same CPU, this is the point where it is likely to be scheduled.

EV_EMPTY_MINOR shows when a domain is trying to empty its minor heap. It
may be a long time between starting this process and actually performing
a minor GC if, for example, another domain is holding the platform lock.
Without this event, profiling tools tend to under-report the amount of
time spent on GC.
@talex5 talex5 changed the title Add Runtime_events.EV_OS_WAIT and EV_EMPTY_MINOR Add Runtime_events.EV_FUTEX_WAIT and EV_EMPTY_MINOR Aug 30, 2024
Copy link
Contributor

@kayceesrk kayceesrk left a comment

Choose a reason for hiding this comment

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

LGTM.

@talex5
Copy link
Contributor Author

talex5 commented Aug 30, 2024

The "MSVC 32 bits" test tests/lib-runtime-events/test_dropped_events.ml is failing in CI. However, I see that it is also failing in the unrelated PR #13408 (MSVC 64 bits), so I assume this test is known to be flaky?

@sadiqj
Copy link
Contributor

sadiqj commented Aug 30, 2024

Thanks @talex5 , these look good to have.

The only thing I'm worried about is the FUTEX_WAIT event being inside the loop - if for some reason it spins frequently it will cause lots of other events in the ring to be dropped. Does it make sense to move it outside of the while loop?

@talex5
Copy link
Contributor Author

talex5 commented Aug 30, 2024

The only thing I'm worried about is the FUTEX_WAIT event being inside the loop - if for some reason it spins frequently it will cause lots of other events in the ring to be dropped. Does it make sense to move it outside of the while loop?

I don't mind either way. My thinking was that if it keeps being woken up unnecessarily then that's interesting to see.

@talex5
Copy link
Contributor Author

talex5 commented Aug 30, 2024

Also, I guess putting it outside the loop would need some extra logic to avoid tracing the fast path where we never suspend.

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.

None yet

3 participants