summaryrefslogtreecommitdiffstats
path: root/src/plugins/af_xdp
diff options
context:
space:
mode:
authorBenoît Ganne <bganne@cisco.com>2021-03-04 14:31:03 +0100
committerDamjan Marion <dmarion@me.com>2021-05-01 11:42:37 +0000
commitf89bbbe300dad7bc479db535e7822199f98aca30 (patch)
tree1163eeac010375a962fcda8c2e0c7a7046161bf1 /src/plugins/af_xdp
parentc8983241b9d93d2c3b60b0705efbc3cdee54c534 (diff)
vlib: refactor trajectory trace debug feature
trajectory trace has been broken for a while because we used to save the buffer trajectory in a vector pointed to in opaque2. This does not work well when opaque2 is copied (eg. because of a clone) as 2 buffers end up sharing the same vector. This dedicates a full cacheline in the buffer metadata instead when trajectory is compiled in. No dynamic allocation, no sharing, no tears. Type: refactor Change-Id: I6a028ca1b48d38f393a36979e5e452c2dd48ad3f Signed-off-by: Benoît Ganne <bganne@cisco.com>
Diffstat (limited to 'src/plugins/af_xdp')
-rw-r--r--src/plugins/af_xdp/device.c12
-rw-r--r--src/plugins/af_xdp/input.c18
2 files changed, 18 insertions, 12 deletions
diff --git a/src/plugins/af_xdp/device.c b/src/plugins/af_xdp/device.c
index fabf85adfa6..35ba617d6e3 100644
--- a/src/plugins/af_xdp/device.c
+++ b/src/plugins/af_xdp/device.c
@@ -208,6 +208,18 @@ af_xdp_create_queue (vlib_main_t * vm, af_xdp_create_if_args_t * args,
umem_config.comp_size = args->txq_size;
umem_config.frame_size =
sizeof (vlib_buffer_t) + vlib_buffer_get_default_data_size (vm);
+ /*
+ * Note about headroom: for some reasons, there seem to be a discrepency
+ * between 0-copy and copy mode:
+ * - 0-copy: XDP_PACKET_HEADROOM will be added to the user headroom
+ * - copy: nothing is added to the user headroom
+ * We privileged 0-copy and set headroom so that frame_headroom +
+ * XDP_PACKET_HEADROOM == sizeof(vlib_buffer_t), ie data will correctly
+ * point to vlib_buffer_t->data for 0-copy. In copy mode, we have to add
+ * XDP_PACKET_HEADROOM to desc offset during refill.
+ */
+ STATIC_ASSERT (sizeof (vlib_buffer_t) >= XDP_PACKET_HEADROOM, "wrong size");
+ umem_config.frame_headroom = sizeof (vlib_buffer_t) - XDP_PACKET_HEADROOM;
umem_config.flags = XDP_UMEM_UNALIGNED_CHUNK_FLAG;
if (xsk_umem__create
(umem, uword_to_pointer (vm->buffer_main->buffer_mem_start, void *),
diff --git a/src/plugins/af_xdp/input.c b/src/plugins/af_xdp/input.c
index 65eee75cb92..da422bdccaf 100644
--- a/src/plugins/af_xdp/input.c
+++ b/src/plugins/af_xdp/input.c
@@ -130,17 +130,11 @@ af_xdp_device_input_refill (vlib_main_t * vm,
/*
* Note about headroom: for some reasons, there seem to be a discrepency
- * between 0-copy and copy mode:
- * - 0-copy: XDP_PACKET_HEADROOM will be added to the user headroom
- * - copy: nothing is added to the user headroom
- * We privileged 0-copy and set headroom to 0. As XDP_PACKET_HEADROOM ==
- * sizeof(vlib_buffer_t), data will correctly point to vlib_buffer_t->data.
- * In copy mode, we have to add sizeof(vlib_buffer_t) to desc offset during
- * refill.
+ * between 0-copy and copy mode. See
+ * src/plugins/af_xdp/device.c:af_xdp_create_queue()
*/
- STATIC_ASSERT (sizeof (vlib_buffer_t) == XDP_PACKET_HEADROOM, "wrong size");
-#define bi2addr(bi) \
- (((bi) << CLIB_LOG2_CACHE_LINE_BYTES) + (copy ? sizeof(vlib_buffer_t) : 0))
+#define bi2addr(bi) \
+ (((bi) << CLIB_LOG2_CACHE_LINE_BYTES) + (copy ? XDP_PACKET_HEADROOM : 0))
wrap_around:
@@ -218,8 +212,8 @@ af_xdp_device_input_bufs (vlib_main_t * vm, const af_xdp_device_t * ad,
const u32 mask = rxq->rx.mask;
u32 n = n_rx, *bi = bis, bytes = 0;
-#define addr2bi(addr) \
- (((addr) - (copy ? sizeof(vlib_buffer_t) : 0)) >> CLIB_LOG2_CACHE_LINE_BYTES)
+#define addr2bi(addr) \
+ (((addr) - (copy ? XDP_PACKET_HEADROOM : 0)) >> CLIB_LOG2_CACHE_LINE_BYTES)
while (n >= 1)
{