-
Notifications
You must be signed in to change notification settings - Fork 5.3k
[Level Events] manage level events registration mask #13787
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
Merged
Merged
Changes from all 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 hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -12,7 +12,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), | ||
| activation_cb_(dispatcher.createSchedulableCallback([this]() { | ||
| ASSERT(injected_activation_events_ != 0); | ||
| mergeInjectedEventsAndRunCb(0); | ||
|
|
@@ -21,9 +21,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); | ||
| } | ||
|
|
@@ -48,9 +52,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), | ||
|
|
@@ -75,6 +80,16 @@ void FileEventImpl::assignEvents(uint32_t events, event_base* base) { | |
| this); | ||
| } | ||
|
|
||
| void FileEventImpl::updateEvents(uint32_t events) { | ||
|
||
| 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 (injected_activation_events_ != 0) { | ||
| // Clear pending events on updates to the fd event mask to avoid delivering events that are no | ||
|
|
@@ -84,19 +99,62 @@ 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; | ||
| } | ||
| updateEvents(new_event_mask); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| void FileEventImpl::mergeInjectedEventsAndRunCb(uint32_t events) { | ||
| if (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 && injected_activation_events_ & 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.
Outdated
Show resolved
Hide resolved
|
||
| if constexpr (PlatformDefaultTriggerType == FileTriggerType::EmulatedEdge) { | ||
| if (trigger_ == FileTriggerType::EmulatedEdge) { | ||
| unregisterEventIfEmulatedEdge(events & | ||
| (Event::FileReadyType::Write | Event::FileReadyType::Read)); | ||
| } | ||
| } | ||
davinci26 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| cb_(events); | ||
| } | ||
|
|
||
|
|
||
This file contains hidden or 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 hidden or 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 hidden or 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.
Uh oh!
There was an error while loading. Please reload this page.