Skip to content

Conversation

ktock
Copy link

@ktock ktock commented Oct 8, 2025

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 poll method of the stream implementations, this can't handle multiple fds because a fd can't notify readiness while another is blocking in poll. 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 poll invocation 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.

@ktock ktock marked this pull request as draft October 8, 2025 03:53
Signed-off-by: Kohei Tokunaga <ktokunaga.mail@gmail.com>
ktock added 9 commits October 9, 2025 03:23
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 <ktokunaga.mail@gmail.com>
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 <ktokunaga.mail@gmail.com>
Signed-off-by: Kohei Tokunaga <ktokunaga.mail@gmail.com>
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 <ktokunaga.mail@gmail.com>
Signed-off-by: Kohei Tokunaga <ktokunaga.mail@gmail.com>
Signed-off-by: Kohei Tokunaga <ktokunaga.mail@gmail.com>
Signed-off-by: Kohei Tokunaga <ktokunaga.mail@gmail.com>
This is needed to avoid the following test failure.

> AssertionError: Expected to NOT find 'eval.

Signed-off-by: Kohei Tokunaga <ktokunaga.mail@gmail.com>
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 <ktokunaga.mail@gmail.com>
@ktock ktock marked this pull request as ready for review October 8, 2025 23:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant