HomeFreeBSD

bhyve: Implement the libslirp notify callback

Description

bhyve: Implement the libslirp notify callback

libslirp can invoke a callback when received data is removed from a
socket buffer, generally because the guest ACKed some data. Previously
it didn't do anything, but it needs to wake up the poll thread to get
reasonable throughput.

Suppose one is using scp to copy data into a guest filesystem via the
slirp backend. Data is received on libslirp's socket, which we poll for
data in slirp_pollfd_td_loop(). That data gets buffered in priv->pipe,
and eventually is placed in the device model's RX rings by the backend's
mevent handler. When implementing TCP, libslirp holds on to a copy of
data until it's ACKed by the guest via slirp_send(), at which point it
drops that data and invokes the notify callback.

The initial implementation of this backend didn't take into account the
fact that slirp_pollfds_fill() will not add libslirp's socket to the
pollfd set if more than a threshold amount of data is already buffered.
Then poll() needs to time out before the backend sends more data to the
guest. With a default timeout of 500ms, this kills throughput.

Use a pipe to implement a simple in-band signal to the poll thread so
that it reacts quickly when more buffer space becomes available.

MFC after: 1 month
Differential Revision: https://reviews.freebsd.org/D48192

Details

Provenance
markjAuthored on Jan 7 2025, 2:33 PM
Differential Revision
D48192: bhyve: Implement the libslirp notify callback
Parents
rGd3bdfa583044: bhyve: Use a non-blocking read in slirp_recv()
Branches
Unknown
Tags
Unknown