-
Notifications
You must be signed in to change notification settings - Fork 373
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 profiler helper for detecting if we're on the main Ractor #2350
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -690,3 +690,28 @@ int ruby_thread_has_gvl_p(void) { | |
return 0; | ||
} | ||
#endif // NO_THREAD_HAS_GVL | ||
|
||
#ifndef NO_RACTORS | ||
// This API and definition are exported as a public symbol by the VM BUT the function header is not defined in any public header, so we | ||
// repeat it here to be able to use in our code. | ||
Comment on lines
+695
to
+696
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does it make sense to request/perform this change upstream? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this "public-ish" is actually on purpose. That is, the missing header is not a "oops we forgot", it's a "this isn't really a public API, but some things outside of Ruby make good use of it, and we don't mind exposing it for now but you're on your own". For instance in ruby/ruby@15476c6 you see a similar API that was published so that (Out of curiosity, there was some openness during a few chats with core team members recently to perhaps promote a few more APIs that would be really useful for profilers to this "public-ish" state). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. But... maybe I'm just assuming too much. I've been hesitating a bit on asking for these kinds of things from upstream because I wanted to first come up with our most important asks and then go down the list from there, rather than asking for all of them. |
||
bool rb_ractor_main_p_(void); | ||
extern struct rb_ractor_struct *ruby_single_main_ractor; | ||
|
||
// Taken from upstream ractor_core.h at commit d9cf0388599a3234b9f3c06ddd006cd59a58ab8b (November 2022, Ruby 3.2 trunk) | ||
// to allow us to ensure that we're always operating on the main ractor (if Ruby has ractors) | ||
// Modifications: | ||
// * None | ||
bool ddtrace_rb_ractor_main_p(void) | ||
{ | ||
if (ruby_single_main_ractor) { | ||
return true; | ||
} | ||
else { | ||
return rb_ractor_main_p_(); | ||
} | ||
} | ||
#else | ||
// Simplify callers on older Rubies, instead of having them probe if the VM supports Ractors we just tell them that yes | ||
// they're always on the main Ractor | ||
bool ddtrace_rb_ractor_main_p(void) { return true; } | ||
#endif // NO_RACTORS |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's no built in
define
around this? Interesting...There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did a quick search and there isn't any -- the closest I found has
HAVE_RUBY_RACTOR_H
which can maybe thought of as a way of doing that but... I decided to keep this one for now ;) (Unless you think it's a really bad idea)I think the reason why there is no define is because you can't disable Ractors (that I know of), and thus you can always probe them by looking at the Ruby version, so that's probably why they don't have a more specific
#define
.On our side, as you can kinda tell by this file, I've been somewhat avoiding doing something like
$defs << "-DRUBY_#{RUBY_VERSION}"
and then doing#ifdef RUBY_3.1
in the code, in favor of being a bit more semantic -- e.g. rather than saying "this is the codepath for Ruby 3.1", say "this is the codepath for when this structure has a member calledfoo
".