File: dynamic-tcp-backlog.patch

package info (click to toggle)
lmbench 3.0-a9%2Bdebian.1-10
  • links: PTS, VCS
  • area: non-free
  • in suites: forky, sid
  • size: 3,028 kB
  • sloc: ansic: 12,328; perl: 6,531; sh: 2,784; makefile: 733
file content (43 lines) | stat: -rw-r--r-- 1,217 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
Description: Dynamically increase the TCP backlog on high core-count systems
Author: Shay Gal-On <sgalon@caviumnetworks.com>
Origin: other, https://bugs.launchpad.net/ubuntu/+source/lmbench/+bug/1706735
Bug-Ubuntu: https://bugs.launchpad.net/bugs/1706735
Forwarded: no
Last-Update: 2017-09-13
---
This patch header follows DEP-3: http://dep.debian.net/deps/dep3/
Index: lmbench/src/lib_tcp.c
===================================================================
--- lmbench.orig/src/lib_tcp.c
+++ lmbench/src/lib_tcp.c
@@ -7,6 +7,7 @@
  */
 #define		_LIB /* bench.h needs this */
 #include	"bench.h"
+#include	<unistd.h>
 
 /*
  * Get a TCP socket, bind it, figure out the port,
@@ -17,7 +18,7 @@
 int
 tcp_server(int prog, int rdwr)
 {
-	int	sock;
+	int	sock, np, backlog = 100;
 	struct	sockaddr_in s;
 
 #ifdef	LIBTCP_VERBOSE
@@ -37,7 +38,12 @@ tcp_server(int prog, int rdwr)
 		perror("bind");
 		exit(2);
 	}
-	if (listen(sock, 100) < 0) {
+	/* Increase the backlog dynamically if we're on a system with a
+           large number of cores to avoid hangs. */
+	np = sysconf(_SC_NPROCESSORS_ONLN);
+	if (np * 4 > backlog)
+		backlog = np * 4;
+	if (listen(sock, backlog) < 0) {
 		perror("listen");
 		exit(4);
 	}