-
Couldn't load subscription status.
- Fork 3.4k
Fix select didn't work with pipes and the timeout argument
#25523
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
base: main
Are you sure you want to change the base?
Conversation
89b85b8 to
05bd5fd
Compare
|
Thanks for the PR @ktock. This looks like a fairly large and complex PR, and I'm out sick right now I'm afraid so I'm not sure when I will have time to go through it. CC'ing @atrosinenko who wrote the original pipefs back in #4935. Also @kripken and @tlively who might be interesting the multithreaded event stuff. |
1de2917 to
5fce398
Compare
Signed-off-by: Kohei Tokunaga <[email protected]>
This commit enables the select syscall to handle timeout with multiple event sources. PROXY_TO_PTHREAD is needed to prevent blocking the main worker. When a thread worker invokes the select syscall with non-zero timeout and no fd is ready, it blocks using Atmoics.wait until it receives a readiness notification. On the main worker, the underlying stream implementation can trigger readiness using Atomics.notify through a callback. A notification also issued automatically once the specified timeout expires. Communication between the thread worker and the main worker occurs via a shared memory region. To prevent a select invocation being unblocked by the callbacks of a previous invocation, all active callbacks are tracked in a list. See the comments in activeSelectCallbacks for details. Usage of the notification callback is optional. If the stream implementation doesn't support it, the "poll" method can still synchronously return the event status. Signed-off-by: Kohei Tokunaga <[email protected]>
This commit adds the registerCleanupFunc method for the callback passed to the stream implementation. It allows the stream implementation to optionally register a cleanup function that will be invoked when select is no longer interested in the stream events. This enables the stream implementation to perform additional cleanups such as discarding the reference to the event callback. Signed-off-by: Kohei Tokunaga <[email protected]>
Signed-off-by: Kohei Tokunaga <[email protected]>
The poll method of PIPEFS receives a notification callback from the caller. PIPEFS notifies the caller when the fd becomes readable using that callback. Signed-off-by: Kohei Tokunaga <[email protected]>
Signed-off-by: Kohei Tokunaga <[email protected]>
Signed-off-by: Kohei Tokunaga <[email protected]>
Signed-off-by: Kohei Tokunaga <[email protected]>
This is needed to avoid the following test failure. > AssertionError: Expected to NOT find 'eval. Signed-off-by: Kohei Tokunaga <[email protected]>
In addition to the existing OFFSCREENCANVAS_SUPPORT configuration, PROXY_TO_PTHREAD now also performs memory allocation internally for use by activeSelectCallbacks. Signed-off-by: Kohei Tokunaga <[email protected]>
|
Rebased. Could we move this forward? |
This PR fixes an issue that the timeout argument for the select syscall wasn't applied to pipes and it returned immedeately instead of waiting for events.
Although the select syscall passes the timeout value to the
pollmethod of the stream implementations, this can't handle multiple fds because a fd can't notify readiness while another is blocking inpoll. As a result, using the select syscall with a combination of pipes and other streams (e.g. PTY) can be problematic.To address this, this PR implements a callback-based event notification. Each stream implementation's
pollinvocation receives a callback, allowing it asynchronously notify the select syscall when it becomes ready. The select syscall blocks until one of these callbacks is triggered or the timeout expires. This behviour is enabled only when PROXY_TO_PTHREAD is enabled to avoid blocking the main worker.To maintain compatibility with non-pipefs streams, the select syscall allows stream implementations to ignore the callback and synchronously return the event status instead. In such cases, the select syscall still updates the flags accordingly.