From 44a4bc5fd6d2bf7a0cfbaf303f6ec4b3f46f7142 Mon Sep 17 00:00:00 2001 From: Kyle Ambroff-Kao Date: Fri, 22 May 2020 19:09:09 -0700 Subject: [PATCH] tcp: Remove sanity checks from BufferQueue in release builds Each TCPEndpoint has two BufferQueue members, one for the send queue and one for the receive queue. If DEBUG_BUFFER_QUEUE is enabled, then most methods of BufferQueue call BufferQueue::Verify(), sometimes twice. This member function performs some sanity checking which requires iterating through every net_buffer in the queue. Disabling this in a debug build improved throughput by a factor of 5x over the loopback interface on my laptop. Using iperf the measured throughput went from 900Mbps to around 4.8Gbps. This patch turns this sanity checking off for release builds. * Rename DEBUG_BUFFER_QUEUE to DEBUG_TCP_BUFFER_QUEUE * Change the default in BufferQueue.h to disabled * Set DEBUG_TCP_BUFFER_QUEUE to KDEBUG_LEVEL_2 in kernel_debug_config.h Change-Id: I262dac5d7e2889d2942bbdcf6b667cc0cbafa4c8 Reviewed-on: https://review.haiku-os.org/c/haiku/+/2780 Reviewed-by: waddlesplash --- build/config_headers/kernel_debug_config.h | 6 ++++++ src/add-ons/kernel/network/protocols/tcp/BufferQueue.cpp | 6 +++--- src/add-ons/kernel/network/protocols/tcp/BufferQueue.h | 6 +----- src/add-ons/kernel/network/protocols/tcp/TCPEndpoint.cpp | 4 ++-- src/tests/system/network/tcp_shell/BufferQueueTest.cpp | 2 +- 5 files changed, 13 insertions(+), 11 deletions(-) diff --git a/build/config_headers/kernel_debug_config.h b/build/config_headers/kernel_debug_config.h index 1dcc08f2c5..2a0b4d653f 100644 --- a/build/config_headers/kernel_debug_config.h +++ b/build/config_headers/kernel_debug_config.h @@ -140,4 +140,10 @@ #define SYSTEM_PROFILE_INTERVAL 10000 +// Network + +// Enables additional assertions in the tcp add-on. +#define DEBUG_TCP_BUFFER_QUEUE KDEBUG_LEVEL_2 + + #endif // KERNEL_DEBUG_CONFIG_H diff --git a/src/add-ons/kernel/network/protocols/tcp/BufferQueue.cpp b/src/add-ons/kernel/network/protocols/tcp/BufferQueue.cpp index de83ba3b31..4d5ada0a27 100644 --- a/src/add-ons/kernel/network/protocols/tcp/BufferQueue.cpp +++ b/src/add-ons/kernel/network/protocols/tcp/BufferQueue.cpp @@ -19,7 +19,7 @@ # define TRACE(x) #endif -#if DEBUG_BUFFER_QUEUE +#if DEBUG_TCP_BUFFER_QUEUE # define VERIFY() Verify(); #else # define VERIFY() ; @@ -436,7 +436,7 @@ BufferQueue::SetPushPointer() fPushPointer = fList.Tail()->sequence + fList.Tail()->size; } -#if DEBUG_BUFFER_QUEUE +#if DEBUG_TCP_BUFFER_QUEUE /*! Perform a sanity check of the whole queue. */ @@ -486,4 +486,4 @@ BufferQueue::Dump() const } } -#endif // DEBUG_BUFFER_QUEUE +#endif // DEBUG_TCP_BUFFER_QUEUE diff --git a/src/add-ons/kernel/network/protocols/tcp/BufferQueue.h b/src/add-ons/kernel/network/protocols/tcp/BufferQueue.h index 73986a880c..f428ae921b 100644 --- a/src/add-ons/kernel/network/protocols/tcp/BufferQueue.h +++ b/src/add-ons/kernel/network/protocols/tcp/BufferQueue.h @@ -13,10 +13,6 @@ #include -#ifndef DEBUG_BUFFER_QUEUE -# define DEBUG_BUFFER_QUEUE 1 -#endif - typedef DoublyLinkedList > SegmentList; @@ -55,7 +51,7 @@ public: tcp_sequence NextSequence() const { return fFirstSequence + fContiguousBytes; } -#if DEBUG_BUFFER_QUEUE +#if DEBUG_TCP_BUFFER_QUEUE void Verify() const; void Dump() const; #endif diff --git a/src/add-ons/kernel/network/protocols/tcp/TCPEndpoint.cpp b/src/add-ons/kernel/network/protocols/tcp/TCPEndpoint.cpp index 9640f8b065..0c4d9cae6a 100644 --- a/src/add-ons/kernel/network/protocols/tcp/TCPEndpoint.cpp +++ b/src/add-ons/kernel/network/protocols/tcp/TCPEndpoint.cpp @@ -2533,7 +2533,7 @@ TCPEndpoint::Dump() const kprintf(" max segment size: %" B_PRIu32 "\n", fSendMaxSegmentSize); kprintf(" queue: %" B_PRIuSIZE " / %" B_PRIuSIZE "\n", fSendQueue.Used(), fSendQueue.Size()); -#if DEBUG_BUFFER_QUEUE +#if DEBUG_TCP_BUFFER_QUEUE fSendQueue.Dump(); #endif kprintf(" last acknowledge sent: %" B_PRIu32 "\n", @@ -2549,7 +2549,7 @@ TCPEndpoint::Dump() const kprintf(" max segment size: %" B_PRIu32 "\n", fReceiveMaxSegmentSize); kprintf(" queue: %" B_PRIuSIZE " / %" B_PRIuSIZE "\n", fReceiveQueue.Available(), fReceiveQueue.Size()); -#if DEBUG_BUFFER_QUEUE +#if DEBUG_TCP_BUFFER_QUEUE fReceiveQueue.Dump(); #endif kprintf(" initial sequence: %" B_PRIu32 "\n", diff --git a/src/tests/system/network/tcp_shell/BufferQueueTest.cpp b/src/tests/system/network/tcp_shell/BufferQueueTest.cpp index ef8cbe01b4..ed54d35aa0 100644 --- a/src/tests/system/network/tcp_shell/BufferQueueTest.cpp +++ b/src/tests/system/network/tcp_shell/BufferQueueTest.cpp @@ -3,7 +3,7 @@ * Distributed under the terms of the MIT License. */ -#define DEBUG_BUFFER_QUEUE 1 +#define DEBUG_TCP_BUFFER_QUEUE 1 #include "BufferQueue.h"