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

Mio build broken on Haiku, no kpoll/kqueue #1472

Closed
kallisti5 opened this issue Mar 10, 2021 · 18 comments · Fixed by #1807
Closed

Mio build broken on Haiku, no kpoll/kqueue #1472

kallisti5 opened this issue Mar 10, 2021 · 18 comments · Fixed by #1807

Comments

@kallisti5
Copy link

   Compiling parking_lot v0.9.0
   Compiling hyper v0.12.35
   Compiling aho-corasick v0.7.15
   Compiling addr2line v0.14.0
   Compiling idna v0.1.5
   Compiling idna v0.2.0
   Compiling mime_guess v2.0.3
   Compiling futures-cpupool v0.1.8
   Compiling bytes v0.4.12
   Compiling mio v0.6.23
error[E0432]: unresolved imports `self::unix::Events`, `self::unix::Selector`
 --> /boot/home/.cargo/registry/src/github.com-1ecc6299db9ec823/mio-0.6.23/src/sys/mod.rs:5:5
  |
5 |     Events,
  |     ^^^^^^ no `Events` in `sys::unix`
6 |     Io,
7 |     Selector,
  |     ^^^^^^^^ no `Selector` in `sys::unix`

error: aborting due to previous error

For more information about this error, try `rustc --explain E0432`.
error: could not compile `mio`
@Thomasdezeeuw
Copy link
Collaborator

Thomasdezeeuw commented Mar 10, 2021

We don't really support Haiku. Is there any support for epoll or kqueue?

@kallisti5
Copy link
Author

Nope. No support for either. We follow a pretty strict posix model

@kallisti5
Copy link
Author

actually it looks like mio 0.8.0 just works. The error above is on 0.6.23

/Data/Code/mio> cargo build
   Compiling libc v0.2.88
   Compiling log v0.4.11
   Compiling cfg-if v0.1.10
   Compiling mio v0.8.0 (/Data/Code/mio)
    Finished dev [unoptimized + debuginfo] target(s) in 2.63s
/Data/Code/mio> cargo test
   Compiling env_logger v0.6.2
   Compiling rand v0.4.6
   Compiling mio v0.8.0 (/Data/Code/mio)
    Finished test [unoptimized + debuginfo] target(s) in 5.95s
     Running target/debug/deps/mio-753c3d872fa80196

running 0 tests

test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s

     Running target/debug/deps/aio-ddb6b9e09505d866

running 0 tests

test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s

     Running target/debug/deps/close_on_drop-6b57ddb8ed3d603e

running 0 tests

test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s

     Running target/debug/deps/events-87c06669cab39f2d

running 0 tests

test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s

     Running target/debug/deps/interest-5f7b72ee86b2086e

running 4 tests
test add ... ok
test bit_or ... ok
test fmt_debug ... ok
test is_tests ... ok

test result: ok. 4 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s

     Running target/debug/deps/poll-27c9e6654b4bc8ce

running 0 tests

test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s

     Running target/debug/deps/registering-9d474f45d2be8765

running 0 tests

test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s

     Running target/debug/deps/regressions-c6f11f684f3ee713

running 0 tests

test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s

     Running target/debug/deps/tcp-0f512657bc44fcb5

running 0 tests

test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s

     Running target/debug/deps/tcp_listener-0f8dda3615537eed

running 0 tests

test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s

     Running target/debug/deps/tcp_socket-7044b995f8501b4c

running 0 tests

test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s

     Running target/debug/deps/tcp_stream-97680294a5416030

running 0 tests

test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s

     Running target/debug/deps/udp_socket-2ac819aa49a263c1

running 0 tests

test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s

     Running target/debug/deps/unix_datagram-b6c07085797ca71d

running 0 tests

test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s

     Running target/debug/deps/unix_listener-757d9ceb365003bb

running 0 tests

test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s

     Running target/debug/deps/unix_pipe-c589c7bae56441bb

running 0 tests

test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s

     Running target/debug/deps/unix_stream-08968abdd23a4436

running 0 tests

test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s

     Running target/debug/deps/waker-6870a9f6e4095fa0

running 0 tests

test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s

     Running target/debug/deps/win_named_pipe-ba42cb257be0764f

running 0 tests

test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s

   Doc-tests mio

running 21 tests
test src/event/events.rs - event::events::Events (line 20) ... ignored
test src/event/events.rs - event::events::Events::capacity (line 100) ... ok
test src/event/events.rs - event::events::Events::clear (line 164) ... ignored
test src/event/events.rs - event::events::Events::is_empty (line 114) ... ok
test src/event/events.rs - event::events::Events::iter (line 128) ... ignored
test src/event/events.rs - event::events::Events::with_capacity (line 86) ... ok
test src/event/events.rs - event::events::Iter (line 55) ... ignored
test src/event/source.rs - event::source::Source (line 41) ... ignored
test src/interest.rs - interest::Interest::add (line 61) ... ok
test src/interest.rs - interest::Interest::remove (line 77) ... ok
test src/lib.rs - guide (line 142) ... ignored
test src/lib.rs - guide (line 176) ... ignored
test src/lib.rs - guide (line 214) ... ignored
test src/poll.rs - poll::Poll (line 129) ... ignored
test src/poll.rs - poll::Poll (line 33) ... ignored
test src/poll.rs - poll::Poll::poll (line 263) ... ignored
test src/poll.rs - poll::Registry::deregister (line 573) ... ignored
test src/poll.rs - poll::Registry::register (line 428) ... ignored
test src/poll.rs - poll::Registry::reregister (line 506) ... ignored
test src/token.rs - token::Token (line 20) ... ignored
test src/waker.rs - waker::Waker (line 37) ... ignored

test result: ok. 5 passed; 0 failed; 16 ignored; 0 measured; 0 filtered out; finished in 0.97s

soo.. I guess close issue waiting on folks to update :-)

@kallisti5
Copy link
Author

Scratch that. While mio 0.8.0 (and 0.7.9) builds on their own... building tokio 1.3.0 fails with similar errors from mio.

rustc --version --verbose
rustc 1.50.0 (46a359dc5 2021-02-11)
binary: rustc
commit-hash: 46a359dc5f62663d36831fe2f13e310273c4bd72
commit-date: 2021-02-11
host: x86_64-unknown-haiku
release: 1.50.0
   Compiling signal-hook-registry v1.3.0
error: unsupported target for `mio::unix::pipe`
   --> /boot/home/.cargo/registry/src/github.com-1ecc6299db9ec823/mio-0.7.9/src/sys/unix/pipe.rs:198:5
    |
198 |     compile_error!("unsupported target for `mio::unix::pipe`");
    |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error[E0432]: unresolved imports `self::selector::event`, `self::selector::Event`, `self::selector::Events`, `self::selector::Selector`
  --> /boot/home/.cargo/registry/src/github.com-1ecc6299db9ec823/mio-0.7.9/src/sys/unix/mod.rs:18:37
   |
18 |     pub(crate) use self::selector::{event, Event, Events, Selector};
   |                                     ^^^^^  ^^^^^  ^^^^^^  ^^^^^^^^ no `Selector` in `sys::unix::selector`
   |                                     |      |      |
   |                                     |      |      no `Events` in `sys::unix::selector`
   |                                     |      no `Event` in `sys::unix::selector`
   |                                     no `event` in `sys::unix::selector`

error[E0432]: unresolved import `self::waker::Waker`
  --> /boot/home/.cargo/registry/src/github.com-1ecc6299db9ec823/mio-0.7.9/src/sys/unix/mod.rs:24:20
   |
24 |     pub(crate) use self::waker::Waker;
   |                    ^^^^^^^^^^^^^^^^^^ no `Waker` in `sys::unix::waker`

   Compiling parking_lot v0.11.1
error[E0425]: cannot find value `stream` in this scope
   --> /boot/home/.cargo/registry/src/github.com-1ecc6299db9ec823/mio-0.7.9/src/sys/unix/tcp.rs:487:58
    |
487 |     unsafe { to_socket_addr(addr.as_ptr()) }.map(|addr| (stream, addr))
    |                                                          ^^^^^^ not found in this scope

error[E0425]: cannot find value `SOCK_NONBLOCK` in crate `libc`
    --> /boot/home/.cargo/registry/src/github.com-1ecc6299db9ec823/mio-0.7.9/src/sys/unix/uds/listener.rs:54:27
     |
54   |         let flags = libc::SOCK_NONBLOCK | libc::SOCK_CLOEXEC;
     |                           ^^^^^^^^^^^^^ help: a constant with a similar name exists: `SO_NONBLOCK`
     | 
    ::: /boot/home/.cargo/registry/src/github.com-1ecc6299db9ec823/libc-0.2.88/src/unix/haiku/mod.rs:1038:1
     |
1038 | pub const SO_NONBLOCK: ::c_int = 0x40000009;
     | -------------------------------------------- similarly named constant `SO_NONBLOCK` defined here

error[E0425]: cannot find value `SOCK_CLOEXEC` in crate `libc`
   --> /boot/home/.cargo/registry/src/github.com-1ecc6299db9ec823/mio-0.7.9/src/sys/unix/uds/listener.rs:54:49
    |
54  |         let flags = libc::SOCK_NONBLOCK | libc::SOCK_CLOEXEC;
    |                                                 ^^^^^^^^^^^^ help: a constant with a similar name exists: `O_CLOEXEC`
    | 
   ::: /boot/home/.cargo/registry/src/github.com-1ecc6299db9ec823/libc-0.2.88/src/unix/haiku/mod.rs:567:1
    |
567 | pub const O_CLOEXEC: ::c_int = 0x00000040;
    | ------------------------------------------ similarly named constant `O_CLOEXEC` defined here

error[E0425]: cannot find function `accept4` in crate `libc`
   --> /boot/home/.cargo/registry/src/github.com-1ecc6299db9ec823/mio-0.7.9/src/sys/unix/uds/listener.rs:55:18
    |
55  |           syscall!(accept4(
    |                    ^^^^^^^ help: a function with a similar name exists: `accept`
    | 
   ::: /boot/home/.cargo/registry/src/github.com-1ecc6299db9ec823/libc-0.2.88/src/unix/mod.rs:686:5
    |
686 | /     pub fn accept(
687 | |         socket: ::c_int,
688 | |         address: *mut sockaddr,
689 | |         address_len: *mut socklen_t,
690 | |     ) -> ::c_int;
    | |_________________- similarly named function `accept` defined here

error[E0425]: cannot find value `SOCK_NONBLOCK` in crate `libc`
    --> /boot/home/.cargo/registry/src/github.com-1ecc6299db9ec823/mio-0.7.9/src/sys/unix/uds/mod.rs:81:35
     |
81   |         let flags = flags | libc::SOCK_NONBLOCK | libc::SOCK_CLOEXEC;
     |                                   ^^^^^^^^^^^^^ help: a constant with a similar name exists: `SO_NONBLOCK`
     | 
    ::: /boot/home/.cargo/registry/src/github.com-1ecc6299db9ec823/libc-0.2.88/src/unix/haiku/mod.rs:1038:1
     |
1038 | pub const SO_NONBLOCK: ::c_int = 0x40000009;
     | -------------------------------------------- similarly named constant `SO_NONBLOCK` defined here

error[E0425]: cannot find value `SOCK_CLOEXEC` in crate `libc`
   --> /boot/home/.cargo/registry/src/github.com-1ecc6299db9ec823/mio-0.7.9/src/sys/unix/uds/mod.rs:81:57
    |
81  |         let flags = flags | libc::SOCK_NONBLOCK | libc::SOCK_CLOEXEC;
    |                                                         ^^^^^^^^^^^^ help: a constant with a similar name exists: `O_CLOEXEC`
    | 
   ::: /boot/home/.cargo/registry/src/github.com-1ecc6299db9ec823/libc-0.2.88/src/unix/haiku/mod.rs:567:1
    |
567 | pub const O_CLOEXEC: ::c_int = 0x00000040;
    | ------------------------------------------ similarly named constant `O_CLOEXEC` defined here

error[E0308]: mismatched types
  --> /boot/home/.cargo/registry/src/github.com-1ecc6299db9ec823/mio-0.7.9/src/sys/unix/net.rs:93:27
   |
93 |                 sin_zero: [0; 8],
   |                           ^^^^^^ expected an array with a fixed size of 24 elements, found one with 8 elements

error[E0063]: missing field `sin_len` in initializer of `sockaddr_in`
  --> /boot/home/.cargo/registry/src/github.com-1ecc6299db9ec823/mio-0.7.9/src/sys/unix/net.rs:89:31
   |
89 |             let sockaddr_in = libc::sockaddr_in {
   |                               ^^^^^^^^^^^^^^^^^ missing `sin_len`

error[E0063]: missing field `sin6_len` in initializer of `sockaddr_in6`
   --> /boot/home/.cargo/registry/src/github.com-1ecc6299db9ec823/mio-0.7.9/src/sys/unix/net.rs:110:32
    |
110 |             let sockaddr_in6 = libc::sockaddr_in6 {
    |                                ^^^^^^^^^^^^^^^^^^ missing `sin6_len`

error[E0308]: mismatched types
   --> /boot/home/.cargo/registry/src/github.com-1ecc6299db9ec823/mio-0.7.9/src/sys/unix/pipe.rs:405:33
    |
405 |     if unsafe { libc::ioctl(fd, libc::FIONBIO, &value) } == -1 {
    |                                 ^^^^^^^^^^^^^ expected `u64`, found `i32`
    |
help: you can convert an `i32` to a `u64` and panic if the converted value doesn't fit
    |
405 |     if unsafe { libc::ioctl(fd, libc::FIONBIO.try_into().unwrap(), &value) } == -1 {
    |                                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: aborting due to 13 previous errors

Some errors have detailed explanations: E0063, E0308, E0425, E0432.
For more information about an error, try `rustc --explain E0063`.
error: could not compile `mio`

@Thomasdezeeuw
Copy link
Collaborator

Building Mio without features basically builds everywhere because it's a non-implementation (see https://github.com/tokio-rs/mio/tree/58e589fddeac03453ffe60718c64e2a582c12275/src/sys/shell). But once you enable features we need actual OS support.

So what system calls does Haiku have that we can use? Note that poll and select are not good enough.

@kallisti5
Copy link
Author

kallisti5 commented Mar 11, 2021

Weird.. to help me better determine if alternatives exist.. why are poll / select not good enough? select isn't polling and doesn't really waste CPU time?

We have a pretty unique wait_for_objects call which might be a stand-in for epoll / kqueue:

https://github.com/haiku/haiku/blob/master/headers/os/kernel/OS.h#L634

It's experimental however.. and documentation could be (a lot) better. libuv and libevent both have upstream Haiku support.. and they seem to work fine under our API.

@kallisti5
Copy link
Author

kallisti5 commented Mar 11, 2021

Just found a simple usage example of wait_for_events here:

https://git.haiku-os.org/haiku/tree/src/servers/power/power_daemon.cpp#n118

@Thomasdezeeuw
Copy link
Collaborator

The problem with poll and select is that you need all the file descriptors to make the call. With epoll/kqueue the OS allows us to register an interest in a file descriptor, which is done in mio::Registry::register. That allows us to keep no user-space state about what file descriptor we're actually polling.

If were to support poll/select we need a copy of all file descriptors that are registered. Which is possible, but would require a lot of work to support in Mio.

@Thomasdezeeuw
Copy link
Collaborator

We have a pretty unique wait_for_objects call which might be a stand-in for epoll / kqueue:

https://github.com/haiku/haiku/blob/master/headers/os/kernel/OS.h#L634

Am I correct in thinking you still need to pass all the object_wait_info objects you're interested in for wait_for_objects? Because if so it's not good enough, see my previous comment.

@kallisti5
Copy link
Author

kallisti5 commented Mar 11, 2021

Hm. Yeah. You build the list of objects and operate on them (aka stateless)
tldr; the design of mio assumes stateful file descriptor monitoring.

We have a GSoC session coming up.. one potential task is adding io_uring support to Haiku. This seemingly represents the "future" of fd monitoring on Linux and elsewhere. Any thoughts on the potential for mio to move to that model at some point in the future?

I was linked a great FOSDEM video here:
https://fosdem.org/2021/schedule/event/file_descriptor_monitoring/

@kallisti5
Copy link
Author

Ok. I went ahead and opened this ticket based on some discussions around this stuff:
https://dev.haiku-os.org/ticket/16846

We generally only implement POSIX stuff, but it feels like we're lacking here.

as for us targeting a io_uring API in the future, I feel like any discussions around io_uring would duplicate #923 so I won't bring them up 😁 Part of 16846 above would be offering a epoll/kqueue compatibility API leveraging a native io_uring implementation.

With that said.. feel free to close this one if you deem it impractical for the moment. Feel free to point any future people complaining about mio not working under Haiku here 😆

A lot of crates eventually depend on mio though tokio.. I guess i'm going to have to avoid leveraging anything that uses tokio for a while. Thanks!

@kallisti5 kallisti5 changed the title Mio build broken on Haiku Mio build broken on Haiku, no kpoll/kqueue Mar 11, 2021
@Thomasdezeeuw
Copy link
Collaborator

Feel free to reopen or create a new issue once something like https://dev.haiku-os.org/ticket/16846 is possible on Haiku.

@waddlesplash
Copy link

https://dev.haiku-os.org/ticket/16846 is possible on Haiku.

This has been done by implementing a (subset of) kqueue, and it's now available on nightly builds, so this issue can be reopened.

@Thomasdezeeuw
Copy link
Collaborator

https://dev.haiku-os.org/ticket/16846 is possible on Haiku.

This has been done by implementing a (subset of) kqueue, and it's now available on nightly builds, so this issue can be reopened.

Does Mio test suite pass on Haiku with kqueue?

@waddlesplash
Copy link

I don't know, because I don't have a Rust setup on Haiku at the moment. @nielx or @kallisti5 may be more qualified to investigate.

@pheki
Copy link

pheki commented Aug 1, 2023

Just in case it's helpful in the future, I had prototyped running mio tests on a haiku vm in github actions on #1602 (comment)

Commits and diff on GitHub: 1387b17...d4eef2f

If the commits eventually disappear (I deleted my fork), here's the full ci.yml and diff:

ci.yml
ci-diff.txt

Thomasdezeeuw added a commit that referenced this issue Jun 14, 2024
Uses the poll(2) implementation for Poll and the pipe(2) based
implementation for Waker.

Perhaps we can do better, but I can't find any proper manuals for the OS
outside of a reference to the Posix standard. Hence I only uses APIs
available in said standard.

Closes #1472
Updates #1702
Thomasdezeeuw added a commit that referenced this issue Jun 14, 2024
Uses the poll(2) implementation for Poll and the pipe(2) based
implementation for Waker.

Perhaps we can do better, but I can't find any proper manuals for the OS
outside of a reference to the Posix standard. Hence I only uses APIs
available in said standard.

Closes #1472
Updates #1702
@Thomasdezeeuw
Copy link
Collaborator

For anyone still watching this issue. Mio v1 will support Haiku using the poll(2) and pipe(2) implementations. I don't know the state of epoll/kqueue of Haiku, I find can't find any manual for these kind of system calls other than a reference to the Posix standard. If an API like epoll/kqueue is ever support by Haiku we should switch to that as it would be far more efficient.

@nielx
Copy link

nielx commented Jun 14, 2024

There is a basic kqueue implementation, so it is worth investigating if it has all the features to switch over. I'll add it to my list.

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 a pull request may close this issue.

6 participants
@kallisti5 @nielx @waddlesplash @Thomasdezeeuw @pheki and others