From waddlesplash <waddlesplash@xxxxxxxxx>:
waddlesplash has uploaded this change for review. (
https://review.haiku-os.org/c/haiku/+/1742 ;)
Change subject: [WIP!] kernel: Overhaul select() implementation and surrounding
code.
......................................................................
[WIP!] kernel: Overhaul select() implementation and surrounding code.
This change does a lot of similar things to hamishm's version, but
in a much cleaner way (or at least I think so :). About 1/5 of the
changes are from that commit, the rest are mine.
Most significantly:
* The select hooks (with the exception of the legacy driver hooks)
now take "uint32* events" instead of "uint8 event" as an argument,
which specifies the events in B_EVENT_* format instead of B_SELECT_*
format, and then is modified by the calling driver to indicate what
events there already are. This eliminates the need to invoke the
notifiers within the select hooks themselves, and cleans up
a good number of code paths.
* A number of drivers that did not properly "notify immediately"
(the socket module is the biggest culprit here ... there are
some open tickets about this problem, actually) now do so.
* The select structs have been overhauled and rearranged. There is now
- select_pool, which holds selectsyncs in a linked list, and has
utility functions to notify all the selects in it. Its functionalites
have been tweaked to the point where all other storage mechanisms
for selectsyncs have been replaced with it (except in userlandfs,
more on that later.)
- select_set, which contains a set of selectsyncs, and is what
select/wait_for_objects/poll use to store their select objects.
It contains the semaphore used to wake up the waiting thread.
- selectsync, a single select wait entry which is passed to
one driver, and is a member of one select_set.
Only selectsync is defined in a header, and there it is only used
inside the kernel itself. All other modules interact with these
via API calls.
* select_pools now lock themselves independently of the structure they
are a part of.
* Double storages of selectsyncs (most notably in VFS) have been
eliminated. This formally makes the "bottom-most" driver that
receives the selectsync responsible for storing and dealing with
it (this was already true in practice, so I'm not sure why VFS
stored the selectsyncs, anyway.)
TODO/FIXME:
* hamishm went the route of "deprecating" the fd_deselect hooks but
not removing them. I've mostly removed them here, as events are
now deselected directly by removing the selectsync from the
select_pool it was added to. This breaks userlandfs (I have a
half baked solution to fix that...) and out-of-tree/BeOS drivers
using the old no-pool system.
In thinking about this carefully, I'm not so sure removing the
deselect hooks is such a good idea. It does remove an awful
lot of overhead, but it seems like the benefits and clarity
of having the deselect hooks outweight whatever downsides
there may be. So depending on what reviewers think, I'll
revise this patch to reinstate them, most likely (which will
make the changes to userlandfs much easier, too.)
Tested with the @minimum image. Terminal works, as does curl/ping/etc.
So it seems this is at least functioning as things did before.
---
D headers/build/os/drivers/Select.h
M headers/os/drivers/device_manager.h
M headers/os/drivers/fs_interface.h
M headers/os/drivers/tty/tty_module.h
M headers/private/kernel/fs/fd.h
D headers/private/kernel/fs/select_sync_pool.h
M headers/private/kernel/port.h
A headers/private/kernel/select_pool.h
M headers/private/kernel/sem.h
M headers/private/kernel/thread.h
M headers/private/kernel/thread_types.h
M headers/private/kernel/vfs.h
M headers/private/kernel/wait_for_objects.h
M headers/private/net/net_socket.h
M headers/private/net/net_stack_interface.h
M src/add-ons/kernel/bus_managers/random/driver.cpp
M src/add-ons/kernel/bus_managers/tty/tty.cpp
M src/add-ons/kernel/drivers/ports/pc_serial/Driver.cpp
M src/add-ons/kernel/drivers/ports/pc_serial/SerialDevice.cpp
M src/add-ons/kernel/drivers/ports/pc_serial/SerialDevice.h
M src/add-ons/kernel/drivers/ports/usb_serial/Driver.cpp
M src/add-ons/kernel/drivers/ports/usb_serial/SerialDevice.cpp
M src/add-ons/kernel/drivers/ports/usb_serial/SerialDevice.h
M src/add-ons/kernel/drivers/power/acpi_button/acpi_button.cpp
M src/add-ons/kernel/drivers/power/acpi_lid/acpi_lid.cpp
M src/add-ons/kernel/drivers/tty/master.cpp
M src/add-ons/kernel/drivers/tty/slave.cpp
M src/add-ons/kernel/drivers/tty/tty.cpp
M src/add-ons/kernel/drivers/tty/tty_private.h
M src/add-ons/kernel/generic/tty/module.cpp
M src/add-ons/kernel/generic/tty/tty.cpp
M src/add-ons/kernel/generic/tty/tty_private.h
M src/add-ons/kernel/network/stack/net_socket.cpp
M src/add-ons/kernel/network/stack/stack_interface.cpp
M src/system/kernel/device_manager/AbstractModuleDevice.cpp
M src/system/kernel/device_manager/AbstractModuleDevice.h
M src/system/kernel/device_manager/BaseDevice.cpp
M src/system/kernel/device_manager/BaseDevice.h
M src/system/kernel/device_manager/FileDevice.cpp
M src/system/kernel/device_manager/FileDevice.h
M src/system/kernel/device_manager/devfs.cpp
M src/system/kernel/device_manager/legacy_drivers.cpp
M src/system/kernel/fs/fd.cpp
M src/system/kernel/fs/fifo.cpp
M src/system/kernel/fs/socket.cpp
M src/system/kernel/fs/vfs.cpp
M src/system/kernel/port.cpp
M src/system/kernel/sem.cpp
M src/system/kernel/thread.cpp
M src/system/kernel/wait_for_objects.cpp
M src/tools/fs_shell/fd.cpp
M src/tools/fs_shell/fd.h
M src/tools/fs_shell/vfs.cpp
53 files changed, 538 insertions(+), 1,211 deletions(-)
git pull ssh://git.haiku-os.org:22/haiku refs/changes/42/1742/1
--
To view, visit https://review.haiku-os.org/c/haiku/+/1742
To unsubscribe, or for help writing mail filters, visit
https://review.haiku-os.org/settings
Gerrit-Project: haiku
Gerrit-Branch: master
Gerrit-Change-Id: Ie835ac8285be2bcd1bea9b1e345dd872e481b5d2
Gerrit-Change-Number: 1742
Gerrit-PatchSet: 1
Gerrit-Owner: waddlesplash <waddlesplash@xxxxxxxxx>
Gerrit-MessageType: newchange