-
Notifications
You must be signed in to change notification settings - Fork 5.4k
GVL Instrumentation: pass thread_id as part of event data #6189
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
Conversation
Some hooks may want to collect data on a per thread basis. Right now the only way to identified the concerned thread is to use `rb_nativethread_self()` or similar, but even then because of the thread cache, two distinct Ruby thread may report the same native thread id. This patch pass a `thread_id` as part of the `event_data` struct. It's a serial id generated when the thread is created.
+1, I think we'll need this when MaNy is merged. See https://bugs.ruby-lang.org/issues/19842 |
btw, I would like a C API to fetch the thread id from the thread. I am working on a profiling API where you pass the thread (VALUE, not |
Sorry for late response. I understand the motivation so I'm happy to accept this feature, but this patch conflicts with my MN scheduler patch so please wait. other concerns:
So we need to clear the specification. They are clear:
They are not clear:
My proposal:
But I can missed the requests. |
Yes.
I presume you mean, shouldn't? It probably isn't a a big deal if in rare case the ID is re-used. But ideally it wouldn't.
64 bit is better indeed.
It's not strictly necessary, but in profiler context that makes for easier to read IDs, but profilers can attribute serial ids based on that later if it wants to.
Yes.
We can make them non-unique across ractors, but in this case we'll also need to pass a "ractor id". To make it more clear, the goal is to render graphs such as this one |
I think this would work if we pass the
I assume Also, will Ractors fire |
They already do.
Yes absolutely. |
Sorry, I mean in the MaNy world. If a Ractor is independently allowed to make a thread at any time (in parallel with other Ractors), then the GVL doesn't help anything as the GVL should be local to that particular Ractor (the way I understand the MaNy proposal is that the GVL becomes a Ractor level lock, rather than Global). The callback passed to |
From my understanding, it's already the case today. But perhaps we should jut have a chat because I think I'm still unclear about what you mean. |
If I may "butt in" ;) yeah there's already a Ractor-level GVL, as can be seen in these examples from using the GVL instrumentation API. |
Closing in favor of #8885 |
Context: ivoanjo/gvl-tracing#4
Some hooks may want to collect data on a per thread basis. Right now the only way to identified the concerned thread is to
use
rb_nativethread_self()
or similar, but even then because of the thread cache, two distinct Ruby thread may report the same native thread id.This patch pass a
thread_id
as part of theevent_data
struct. It's a serial id generated when the thread is created.cc @ivoanjo
@ko1 what do you think? Would this be acceptable? There is an atomic operation an overhead even if the API is not in use, but that's on thread creation, I assume it's minor compared to the overall thread creation cost?