mirror of
https://passt.top/passt
synced 2025-09-02 01:43:13 +02:00

Currently we attempt to size pool_tap[46] so they have room for the maximum possible number of packets that could fit in pkt_buf (TAP_MSGS). However, the calculation isn't quite correct: TAP_MSGS is based on ETH_ZLEN (60) as the minimum possible L2 frame size. But ETH_ZLEN is based on physical constraints of Ethernet, which don't apply to our virtual devices. It is possible to generate a legitimate frame smaller than this, for example an empty payload UDP/IPv4 frame on the 'pasta' backend is only 42 bytes long. Further more, the same limit applies for vhost-user, which is not limited by the size of pkt_buf like the other backends. In that case we don't even have full control of the maximum buffer size, so we can't really calculate how many packets could fit in there. If we exceed do TAP_MSGS we'll drop packets, not just use more batches, which is moderately bad. The fact that this needs to be sized just so for correctness not merely for tuning is a fairly non-obvious coupling between different parts of the code. To make this more robust, alter the tap code so it doesn't rely on everything fitting in a single batch of TAP_MSGS packets, instead breaking into multiple batches as necessary. This leaves TAP_MSGS as purely a tuning parameter, which we can freely adjust based on performance measures. Signed-off-by: David Gibson <david@gibson.dropbear.id.au> Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
81 lines
2.4 KiB
C
81 lines
2.4 KiB
C
/* SPDX-License-Identifier: GPL-2.0-or-later
|
|
* Copyright (c) 2022 Red Hat GmbH
|
|
* Author: Stefano Brivio <sbrivio@redhat.com>
|
|
*/
|
|
|
|
#ifndef PACKET_H
|
|
#define PACKET_H
|
|
|
|
#include <stdbool.h>
|
|
|
|
/* Maximum size of a single packet stored in pool, including headers */
|
|
#define PACKET_MAX_LEN UINT16_MAX
|
|
|
|
/**
|
|
* struct pool - Generic pool of packets stored in a buffer
|
|
* @buf: Buffer storing packet descriptors,
|
|
* a struct vu_dev_region array for passt vhost-user mode
|
|
* @buf_size: Total size of buffer,
|
|
* 0 for passt vhost-user mode
|
|
* @size: Number of usable descriptors for the pool
|
|
* @count: Number of used descriptors for the pool
|
|
* @pkt: Descriptors: see macros below
|
|
*/
|
|
struct pool {
|
|
char *buf;
|
|
size_t buf_size;
|
|
size_t size;
|
|
size_t count;
|
|
struct iovec pkt[];
|
|
};
|
|
|
|
int vu_packet_check_range(void *buf, const char *ptr, size_t len);
|
|
void packet_add_do(struct pool *p, size_t len, const char *start,
|
|
const char *func, int line);
|
|
void *packet_get_do(const struct pool *p, const size_t idx,
|
|
size_t offset, size_t len, size_t *left,
|
|
const char *func, int line);
|
|
bool pool_full(const struct pool *p);
|
|
void pool_flush(struct pool *p);
|
|
|
|
#define packet_add(p, len, start) \
|
|
packet_add_do(p, len, start, __func__, __LINE__)
|
|
|
|
#define packet_get(p, idx, offset, len, left) \
|
|
packet_get_do(p, idx, offset, len, left, __func__, __LINE__)
|
|
|
|
#define packet_get_try(p, idx, offset, len, left) \
|
|
packet_get_do(p, idx, offset, len, left, NULL, 0)
|
|
|
|
#define PACKET_POOL_DECL(_name, _size, _buf) \
|
|
struct _name ## _t { \
|
|
char *buf; \
|
|
size_t buf_size; \
|
|
size_t size; \
|
|
size_t count; \
|
|
struct iovec pkt[_size]; \
|
|
}
|
|
|
|
#define PACKET_POOL_INIT_NOCAST(_size, _buf, _buf_size) \
|
|
{ \
|
|
.buf_size = _buf_size, \
|
|
.buf = _buf, \
|
|
.size = _size, \
|
|
}
|
|
|
|
#define PACKET_POOL(name, size, buf, buf_size) \
|
|
PACKET_POOL_DECL(name, size, buf) name = \
|
|
PACKET_POOL_INIT_NOCAST(size, buf, buf_size)
|
|
|
|
#define PACKET_INIT(name, size, buf, buf_size) \
|
|
(struct name ## _t) PACKET_POOL_INIT_NOCAST(size, buf, buf_size)
|
|
|
|
#define PACKET_POOL_NOINIT(name, size, buf) \
|
|
PACKET_POOL_DECL(name, size, buf) name ## _storage; \
|
|
static struct pool *name = (struct pool *)&name ## _storage
|
|
|
|
#define PACKET_POOL_P(name, size, buf, buf_size) \
|
|
PACKET_POOL(name ## _storage, size, buf, buf_size); \
|
|
struct pool *name = (struct pool *)&name ## _storage
|
|
|
|
#endif /* PACKET_H */
|