Files
linuxkit/alpine/packages/tap-vsockd/ring.h
David Scott 3fc0d994b5 tap-vsockd: add buffering
This patch adds a simple ring buffer implementation and uses it to buffer
the reads and writes to/from the AF_HYPERV socket and tap file descriptor.

This removes the need to perform small reads and writes for the per-packet
headers and allows a read on the Hyper-V socket to block at the same time
as a write to the tap device (and vice-versa)

The configuration in the init.d script is:

- a max message size (individual read or write) of 8192. Experimentally
  this seems to be the largest completely reliable size across the Windows
  versions we can support. Messages of length 16384 sometimes fail.
- a buffer size of 256KiB in each direction.

Single stream TCP throughput as measured by iperf increases modestly, by
another 100Mbit/sec.

Signed-off-by: David Scott <dave.scott@docker.com>
2017-01-23 12:17:52 +00:00

36 lines
1.3 KiB
C

#include <unistd.h>
#include <sys/uio.h>
/* A fixed-size circular buffer */
struct ring;
/* Allocate a circular buffer with the given payload size.
Size must be < INT_MAX / 2. */
extern struct ring *ring_allocate(int size);
/* Signal that new data is been produced */
extern void ring_producer_advance(struct ring *ring, int n);
/* Signal that data has been consumed */
extern void ring_consumer_advance(struct ring *ring, int n);
/* The producer sends Eof. This will cause ring_consumer_wait_available
and ring_producer_wait_available to return an error. */
extern void ring_producer_eof(struct ring *ring);
/* Wait for n bytes of space for new data to become available. If
ring_producer_eof has been called, return non-zero. If space is available
then fill the first *iovec_len entries of the iovec and set *iovec_len to
the number of iovecs used. */
extern int ring_producer_wait_available(
struct ring *ring, size_t n, struct iovec *iovec, int *iovec_len
);
/* Wait for n bytes to become available for reading. If ring_producer_eof has
been called, return non-zero. If data is available then fill the first
*iovec_len entries of the iovec and set *iovec_len to the number of iovecs
used. */
extern int ring_consumer_wait_available(
struct ring *ring, size_t n, struct iovec *iovec, int *iovec_len
);