-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
[Level Events] manage level events registration mask #13787
Merged
Merged
Changes from 30 commits
Commits
Show all changes
40 commits
Select commit
Hold shift + click to select a range
7c6055f
Initial implementation for optimized file events
a5f71d2
format changes
00f76fc
fix format + make linux run level events to get a bigger sample on CI
5a5fcf6
improve implementation with new event trigger type
5b67c40
fix udp, hot restart and proxy listener
bb201bd
rename function names
29b9ba4
format changes
5473250
spelling
55843d4
fix file event test
cbb6f81
fix format
18bb1f2
attempt to fix windows comp
49597fe
fix formatting
3795281
fix ssl tests
b1713b6
format changes
43ccec1
revert file_event testt
4ca4422
no need to merge events with mode EVLOOP_ONCE
804f747
Remove EVLOOP_ONCE from windows + enable event tests
524826b
format change
8f450f1
fix simulated_time_system_test
d5a43f8
ci failures + comments
9482e16
format changes
65c1a43
fix asan
bced31d
small improvements
c5bb3d0
pr comments
de29321
handle case with early close and read on activated events
95de340
fix format
50ef019
increase coverage
f7e5741
constexpr guarding
af5ab9c
fix formatting
342fe73
fix pr comments
ee2b6e0
optimize events for winodws
da34cb0
More constexpr guarding
54bff41
Merge remote-tracking branch 'upstream/master' into eventsOptimized
5d135e9
fix merge conflict
a730507
more constexpr guards vol2
bc4278d
PR comments by Matt and per file coverage
afb62cb
spelling
48f9376
expand comments on event types
bf30da3
spelling
3e9ca9c
drop coverage for events to 93.5
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,7 +13,7 @@ namespace Event { | |
|
||
FileEventImpl::FileEventImpl(DispatcherImpl& dispatcher, os_fd_t fd, FileReadyCb cb, | ||
FileTriggerType trigger, uint32_t events) | ||
: cb_(cb), fd_(fd), trigger_(trigger), | ||
: cb_(cb), fd_(fd), trigger_(trigger), enabled_events_(events), | ||
activate_fd_events_next_event_loop_( | ||
// Only read the runtime feature if the runtime loader singleton has already been created. | ||
// Attempts to access runtime features too early in the initialization sequence triggers | ||
|
@@ -28,9 +28,13 @@ FileEventImpl::FileEventImpl(DispatcherImpl& dispatcher, os_fd_t fd, FileReadyCb | |
// an OOM condition and just crash. | ||
RELEASE_ASSERT(SOCKET_VALID(fd), ""); | ||
#ifdef WIN32 | ||
RELEASE_ASSERT(trigger_ == FileTriggerType::Level, | ||
"libevent does not support edge triggers on Windows"); | ||
ASSERT(trigger_ != FileTriggerType::Edge, "libevent does not support edge triggers on Windows"); | ||
#endif | ||
if constexpr (PlatformDefaultTriggerType != FileTriggerType::EmulatedEdge) { | ||
ASSERT(trigger_ != FileTriggerType::EmulatedEdge, | ||
"Cannot use EmulatedEdge events if they are not the default platform type"); | ||
} | ||
|
||
assignEvents(events, &dispatcher.base()); | ||
event_add(&raw_event_, nullptr); | ||
if (activate_fd_events_next_event_loop_) { | ||
|
@@ -81,9 +85,10 @@ void FileEventImpl::activate(uint32_t events) { | |
|
||
void FileEventImpl::assignEvents(uint32_t events, event_base* base) { | ||
ASSERT(base != nullptr); | ||
enabled_events_ = events; | ||
event_assign( | ||
&raw_event_, base, fd_, | ||
EV_PERSIST | (trigger_ == FileTriggerType::Level ? 0 : EV_ET) | | ||
EV_PERSIST | (trigger_ == FileTriggerType::Edge ? EV_ET : 0) | | ||
(events & FileReadyType::Read ? EV_READ : 0) | | ||
(events & FileReadyType::Write ? EV_WRITE : 0) | | ||
(events & FileReadyType::Closed ? EV_CLOSED : 0), | ||
|
@@ -108,6 +113,16 @@ void FileEventImpl::assignEvents(uint32_t events, event_base* base) { | |
this); | ||
} | ||
|
||
void FileEventImpl::updateEvents(uint32_t events) { | ||
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. Consider adding: 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. fixed in c5bb3d0 |
||
if (events == enabled_events_) { | ||
return; | ||
} | ||
auto* base = event_get_base(&raw_event_); | ||
event_del(&raw_event_); | ||
assignEvents(events, base); | ||
event_add(&raw_event_, nullptr); | ||
} | ||
|
||
void FileEventImpl::setEnabled(uint32_t events) { | ||
if (activate_fd_events_next_event_loop_ && injected_activation_events_ != 0) { | ||
// Clear pending events on updates to the fd event mask to avoid delivering events that are no | ||
|
@@ -117,19 +132,64 @@ void FileEventImpl::setEnabled(uint32_t events) { | |
injected_activation_events_ = 0; | ||
activation_cb_->cancel(); | ||
} | ||
updateEvents(events); | ||
} | ||
|
||
auto* base = event_get_base(&raw_event_); | ||
event_del(&raw_event_); | ||
assignEvents(events, base); | ||
event_add(&raw_event_, nullptr); | ||
void FileEventImpl::unregisterEventIfEmulatedEdge(uint32_t event) { | ||
// This constexpr if allows the compiler to optimize away the function on POSIX | ||
if constexpr (PlatformDefaultTriggerType == FileTriggerType::EmulatedEdge) { | ||
ASSERT((event & (FileReadyType::Read | FileReadyType::Write)) == event); | ||
if (trigger_ == FileTriggerType::EmulatedEdge) { | ||
auto new_event_mask = enabled_events_ & ~event; | ||
updateEvents(new_event_mask); | ||
} | ||
} | ||
} | ||
|
||
void FileEventImpl::registerEventIfEmulatedEdge(uint32_t event) { | ||
// This constexpr if allows the compiler to optimize away the function on POSIX | ||
if constexpr (PlatformDefaultTriggerType == FileTriggerType::EmulatedEdge) { | ||
ASSERT((event & (FileReadyType::Read | FileReadyType::Write)) == event); | ||
if (trigger_ == FileTriggerType::EmulatedEdge) { | ||
auto new_event_mask = enabled_events_ | event; | ||
if (event & FileReadyType::Read && (enabled_events_ & FileReadyType::Closed)) { | ||
// We never ask for both early close and read at the same time. | ||
new_event_mask = new_event_mask & ~FileReadyType::Read; | ||
} | ||
if (event == 0) { | ||
return; | ||
} | ||
davinci26 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
updateEvents(new_event_mask); | ||
} | ||
} | ||
} | ||
|
||
void FileEventImpl::mergeInjectedEventsAndRunCb(uint32_t events) { | ||
if (activate_fd_events_next_event_loop_ && injected_activation_events_ != 0) { | ||
// TODO(antoniovicente) remove this adjustment to activation events once ConnectionImpl can | ||
// handle Read and Close events delivered together. | ||
if constexpr (PlatformDefaultTriggerType == FileTriggerType::EmulatedEdge) { | ||
if (events & FileReadyType::Closed && | ||
activate_fd_events_next_event_loop_ & FileReadyType::Read) { | ||
// We never ask for both early close and read at the same time. If close is requested | ||
// keep that instead. | ||
injected_activation_events_ = injected_activation_events_ & ~FileReadyType::Read; | ||
} | ||
} | ||
|
||
events |= injected_activation_events_; | ||
injected_activation_events_ = 0; | ||
activation_cb_->cancel(); | ||
} | ||
|
||
// TODO(davinci26): This can be optimized further in (w)epoll backends using the `EPOLLONESHOT` | ||
davinci26 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// flag. With this flag `EPOLLIN`/`EPOLLOUT` are automatically disabled when the event is | ||
// activated. | ||
antoniovicente marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if (trigger_ == FileTriggerType::EmulatedEdge) { | ||
davinci26 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
unregisterEventIfEmulatedEdge(events & | ||
(Event::FileReadyType::Write | Event::FileReadyType::Read)); | ||
} | ||
davinci26 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
cb_(events); | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Can we get rid of Level now? Windows is the only platform its needed and we fully intend to use the "optimized" flavor anyhow. Or are you using it for testing/comparison?
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.
Level events are used by listeners and DNS ( on all platforms), so we cant really remove it.
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.
Ah I did not know that. Have you played with trying to move listeners and DNS to EmulatedEdge? Just curious. This is something that can certainly be done later if there is interest
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.
Can you add some comments now above each trigger type with what they do and what they are used for? I think now it's less clear what all of these do and are for and it would be good to have a comment trail.
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 added a block of comments for
EmulatedEdge
and some comments with the current use cases of the other event types