Skip to content
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

Poll support for I/O #7

Merged
merged 2 commits into from
Apr 7, 2013
Merged

Poll support for I/O #7

merged 2 commits into from
Apr 7, 2013

Conversation

vyzo
Copy link
Contributor

@vyzo vyzo commented Apr 6, 2013

Poll Support for I/O

Adds a new compile-time configurable option to use poll/ppoll as the select
mechanism.
This allows the system to use more than 1024 file descriptors.

Implementation Notes

The poll state is maintained in __device_select_state_struct, which has
been augmented to include a pollfd array and count for the i/o selection.
The size of the array is configurable with MAX_POLLFDS, which matches
MAX_CONDVARS unless explicitly defined.

The state also has 2 bitmaps for read and write ready fds, which behave
similar to fd_set used in select -- but their size is not hard-limited
to 1024 fds as in select. Instead, it matches the configured size of the
pollfd array.

The actual poll is implemented in __device_select.
On entry, the ready sets and fd count are cleared in the state.
File descriptors are added in ___device_select_add_fd, which for poll
pushes the file descriptor to the poll set and increments the count.
When the poll completes, the poll set is scanned updating the bitmaps for
the ready file descriptors.

Using a bitmap for marking the ready sets allows the existing device_select
code to work with minimal modifications, without incurring performance
penalty in the rediness checks.
The checks are implemented using __FD_ISSET, which has the same
interface for both select and poll.
When select is used, the macro is defined to FD_ISSET.
When poll is usde, the macro is defined to operate on a poll bitmap.

If the system has ppoll available (GNU/Linux), then ppoll will be used
instead of plain poll, allowing high resolution timeouts.

Configuration Options

A new configure option has been added to enable poll as the select mechanism:
--enable-poll

The maximum number of file descriptors in the poll set is controlled by
the MAX_POLLFDS parameter.
By default it matches MAX_CONDVARS (8192).
If you want to use more file descriptors, configure with
CFLAGS="-DMAX_POLLFDS=XXX"

Using poll

  1. Regenerate configure by running autoconf.
  2. Run configure with --enable-poll
  3. make && make check && make install as usual.

Enables poll for performing i/o selection. 
This allows the system to use more than 1024 file descriptors.
@vyzo
Copy link
Contributor Author

vyzo commented Apr 6, 2013

A couple of additional notes:
I have tested in GNU/Linux.
I am not sure what is the maximum timeout MacOSX can handle in the poll - I check against INT_MAX milliseconds, if the conversion from the timeval would exceed that (leading to an overflow wrap-around), it gets set to -1.
Perhaps I should let it overflow (negative -> infinite timeout) or a smaller max needs to be used for OSX's idiosyncracies.

feeley added a commit that referenced this pull request Apr 7, 2013
@feeley feeley merged commit 8141a23 into gambit:master Apr 7, 2013
@feeley
Copy link
Member

feeley commented May 1, 2013

The poll code was mistakenly enabled by default in v4.6.8 . This is unfortunate because the poll code seems to be incorrect when waiting on a tty. On OS X and idle "gsi" consumes 100% CPU. Could you please check the code and propose a fix.

@vyzo
Copy link
Contributor Author

vyzo commented May 2, 2013

Unfortunately, it appears that OSX doesn't support poll on ttys.

From https://developer.apple.com/library/mac/documentation/Porting/Conceptual/PortingUnix/compiling/compiling.html:
"For example, in OS X, poll does not support device files such as /dev/tty"

So I guess we will have to disable it on OSX -- this can be done in the #if guard in os.h

@feeley
Copy link
Member

feeley commented May 2, 2013

Alternatively, both the select and poll code could be compiled in, and the select code would be used as soon as one of the devices is a tty. But this seems non-trivial to get right and may require two passes on the set of devices.

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.

None yet

2 participants