-
Notifications
You must be signed in to change notification settings - Fork 1
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
erts: Make select message into a non-msg signal #157
base: master
Are you sure you want to change the base?
Conversation
bdf7979
to
59c4a7e
Compare
@sourcery-ai review |
Reviewer's Guide by SourceryThis pull request modifies the ERTS check I/O subsystem to optimize NIF select message handling by introducing a non-message signal mechanism and scheduler pollset optimizations. The changes aim to improve performance by reducing message copying and better handling of I/O events in scheduler pollsets. Sequence diagram for NIF select message handlingsequenceDiagram
participant NIF
participant Scheduler
participant Process
participant IO
NIF->>Scheduler: enif_select
Scheduler->>IO: erts_io_handle_nif_select
IO->>Scheduler: Return message
Scheduler->>Process: Send signal
Process->>Scheduler: Acknowledge signal
Scheduler->>NIF: Signal processed
Class diagram for ERTS check I/O subsystem changesclassDiagram
class ErtsNifSelectSignalData {
Eterm message
ErlNifEvent evt
}
class erts_nif_select_event {
ErtsMessage* mp
Eterm pid
}
class ErtsSchedulerData {
ErtsSysFdType nif_select_fds[5]
}
class ErtsMessage {
ErlHeapFragment hfrag
}
class ErlHeapFragment {
size_t used_size
size_t alloc_size
}
ErtsNifSelectSignalData --> erts_nif_select_event : used in
erts_nif_select_event --> ErtsMessage : contains
ErtsSchedulerData --> ErtsSysFdType : uses
ErtsMessage --> ErlHeapFragment : contains
ErlHeapFragment : used_size
ErlHeapFragment : alloc_size
ErtsSchedulerData : nif_select_fds[5]
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
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.
Hey @garazdawi - I've reviewed your changes and they look great!
Here's what I looked at during the review
- 🟡 General issues: 3 issues found
- 🟢 Security: all looks good
- 🟡 Testing: 1 issue found
- 🟡 Complexity: 1 issue found
- 🟢 Documentation: all looks good
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
else if (n == 0 || errno == ECONNRESET) { | ||
return atom_eof; |
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.
issue (testing): Test needed for ECONNRESET error condition in read_nif
A new test case should be added to verify that ECONNRESET is properly handled and returns atom_eof. This is an important edge case that should be explicitly tested.
and by NIFs through [`enif_select`](erl_nif.md#enif_select). | ||
|
||
The main user of the check I/O subsystem is network communication though `m:gen_tcp`, `m:gen_udp`, `m:gen_sctp` and `m:socket` (On Unix, on Windows `m:socket` used its own internal check I/O implementation based on completion ports.), | ||
but it is also used by various other parts such as when doing `os:cmd/1` or readying from the terminal. |
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.
issue (typo): Fix typo: 'readying' should be 'reading'
At the writing of this document they are: [epoll] (Linux), [kqueue] (MacOS + *Bsd), [/dev/poll] (Solaris), [poll] and [select]. [epoll]+[kqueue]+[/dev/poll] are referred to as | ||
"kernel polling" methods, as the information about which FDs are currently monitored | ||
lives in the OS kernel, while [poll]+[select] are "user polling" methods as the | ||
caller needs to supply all FDs of interest to the kernel everything `erts_poll_wait` |
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.
issue (typo): Fix typo: 'everything' should be 'everytime'
caller needs to supply all FDs of interest to the kernel everything `erts_poll_wait` | ||
is called. | ||
|
||
By default all Unix'es use a "kernel polling" method, but has a fallback pollset that |
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.
issue (typo): Correct the plural form of 'Unix'
The plural form should be 'Unixes' rather than 'Unix'es'
if (op == ERTS_POLL_OP_DEL && (flags & ERTS_EV_FLAG_SCHEDULER)) { | ||
erts_poll_control(get_scheduler_pollset(fd), fd, op, pe, wake_poller); | ||
flags &= ~ERTS_EV_FLAG_IN_SCHEDULER; | ||
if (!(flags & ERTS_EV_FLAG_SCHEDULER) |
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.
issue (complexity): Consider extracting helper functions for scheduler polling and NIF select handling logic
The scheduler polling and NIF select handling logic adds significant complexity through nested flag manipulation. Consider extracting helper functions to improve readability:
static ERTS_INLINE void
update_scheduler_state(ErtsDrvEventState *state, ErtsPollEvents pe, ErtsPollOp op)
{
if (state->flags & ERTS_EV_FLAG_SCHEDULER) {
if (!(state->flags & ERTS_EV_FLAG_IN_SCHEDULER))
op = ERTS_POLL_OP_ADD;
ErtsPollEvents res = erts_poll_control(get_scheduler_pollset(),
state->fd, op, pe & ERTS_POLL_EV_IN, NULL);
if (op == ERTS_POLL_OP_ADD && res & ERTS_POLL_EV_IN)
state->flags |= ERTS_EV_FLAG_IN_SCHEDULER;
else if (op == ERTS_POLL_OP_DEL)
state->flags &= ~ERTS_EV_FLAG_IN_SCHEDULER;
}
}
This would simplify erts_io_control_wakeup() by encapsulating the scheduler state transitions. Similar helper functions could be extracted for NIF select handling to reduce the overall complexity while maintaining functionality.
1693960
to
e78e1de
Compare
21b97d2
to
b119aa9
Compare
389ba04
to
9cc5222
Compare
89fc8b6
to
0a3cb7f
Compare
0a3cb7f
to
7dfda88
Compare
f40a3df
to
6b2d431
Compare
Summary by Sourcery
Enhance the I/O event handling by converting select messages into non-message signals, improving the efficiency of the system. Update the internal documentation to include a detailed overview of the check I/O subsystem. Add new test cases to ensure the correct functionality of the scheduler polling mechanism for NIFs.
Enhancements:
Documentation:
Tests: