From 55274adedcabdc3f1e4d66b2c3b77b1612acf20d Mon Sep 17 00:00:00 2001 From: Tobias Klauser Date: Thu, 29 Oct 2015 15:58:05 +0100 Subject: ring: Simplify calculation of number of frames in a tpacket ring The number of frames in a tpacket ring (ring->layout.tp_frame_nr) is currently calculated as: tp_frame_nr = tp_block_size / tp_frame_size * tp_block_nr Substituting tp_block_nr with 'size / tp_block_size' (as calculated in the line above), we get: tp_frame_nr = tp_block_size / tp_frame_size * (size / tp_block_size) and realize that we can omit tp_block_size as it cancels out, leading to: tp_frame_nr = 1 / tp_frame_size * (size / 1) = size / tp_frame_size Adjust the calculation in setup_ring_layout_generic() accordingly. Signed-off-by: Tobias Klauser --- ring.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'ring.c') diff --git a/ring.c b/ring.c index 26de18e..dc58a07 100644 --- a/ring.c +++ b/ring.c @@ -34,10 +34,7 @@ void setup_ring_layout_generic(int sock, struct ring *ring, size_t size, TPACKET_ALIGNMENT << 7); ring->layout.tp_block_nr = size / ring->layout.tp_block_size; - ring->layout.tp_frame_nr = ring->layout.tp_block_size / - ring->layout.tp_frame_size * - ring->layout.tp_block_nr; - + ring->layout.tp_frame_nr = size / ring->layout.tp_frame_size; } void mmap_ring_generic(int sock, struct ring *ring) -- cgit v1.2.3-54-g00ecf