Module Name: src Committed By: ozaki-r Date: Fri Jan 19 07:53:01 UTC 2018
Modified Files: src/sys/netinet: tcp_subr.c tcp_timer.c tcp_timer.h tcp_var.h Log Message: Run tcp_slowtimo in workqueue if NET_MPSAFE If NET_MPSAFE is enabled, we have to avoid taking softnet_lock in softint as much as possible to prevent any softint handlers including callout handlers such as tcp_slowtimo from sticking on softnet_lock because it results in undesired delays of executing subsequent softint handlers. NFCI for !NET_MPSAFE To generate a diff of this commit: cvs rdiff -u -r1.271 -r1.272 src/sys/netinet/tcp_subr.c cvs rdiff -u -r1.92 -r1.93 src/sys/netinet/tcp_timer.c cvs rdiff -u -r1.28 -r1.29 src/sys/netinet/tcp_timer.h cvs rdiff -u -r1.181 -r1.182 src/sys/netinet/tcp_var.h Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/sys/netinet/tcp_subr.c diff -u src/sys/netinet/tcp_subr.c:1.271 src/sys/netinet/tcp_subr.c:1.272 --- src/sys/netinet/tcp_subr.c:1.271 Sat Jul 29 05:08:48 2017 +++ src/sys/netinet/tcp_subr.c Fri Jan 19 07:53:01 2018 @@ -1,4 +1,4 @@ -/* $NetBSD: tcp_subr.c,v 1.271 2017/07/29 05:08:48 maxv Exp $ */ +/* $NetBSD: tcp_subr.c,v 1.272 2018/01/19 07:53:01 ozaki-r Exp $ */ /* * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. @@ -91,7 +91,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: tcp_subr.c,v 1.271 2017/07/29 05:08:48 maxv Exp $"); +__KERNEL_RCSID(0, "$NetBSD: tcp_subr.c,v 1.272 2018/01/19 07:53:01 ozaki-r Exp $"); #ifdef _KERNEL_OPT #include "opt_inet.h" @@ -382,8 +382,6 @@ struct mowner tcp_sock_rx_mowner = MOWNE struct mowner tcp_sock_tx_mowner = MOWNER_INIT("tcp", "sock tx"); #endif -callout_t tcp_slowtimo_ch; - static int do_tcpinit(void) { @@ -424,8 +422,7 @@ do_tcpinit(void) vtw_earlyinit(); - callout_init(&tcp_slowtimo_ch, CALLOUT_MPSAFE); - callout_reset(&tcp_slowtimo_ch, 1, tcp_slowtimo, NULL); + tcp_slowtimo_init(); return 0; } Index: src/sys/netinet/tcp_timer.c diff -u src/sys/netinet/tcp_timer.c:1.92 src/sys/netinet/tcp_timer.c:1.93 --- src/sys/netinet/tcp_timer.c:1.92 Fri Jul 28 19:16:41 2017 +++ src/sys/netinet/tcp_timer.c Fri Jan 19 07:53:01 2018 @@ -1,4 +1,4 @@ -/* $NetBSD: tcp_timer.c,v 1.92 2017/07/28 19:16:41 maxv Exp $ */ +/* $NetBSD: tcp_timer.c,v 1.93 2018/01/19 07:53:01 ozaki-r Exp $ */ /* * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. @@ -93,11 +93,12 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: tcp_timer.c,v 1.92 2017/07/28 19:16:41 maxv Exp $"); +__KERNEL_RCSID(0, "$NetBSD: tcp_timer.c,v 1.93 2018/01/19 07:53:01 ozaki-r Exp $"); #ifdef _KERNEL_OPT #include "opt_inet.h" #include "opt_tcp_debug.h" +#include "opt_net_mpsafe.h" #endif #include <sys/param.h> @@ -108,6 +109,8 @@ __KERNEL_RCSID(0, "$NetBSD: tcp_timer.c, #include <sys/protosw.h> #include <sys/errno.h> #include <sys/kernel.h> +#include <sys/callout.h> +#include <sys/workqueue.h> #include <net/if.h> @@ -149,6 +152,15 @@ u_int tcp_keepcnt = 0; /* max idle prob int tcp_maxpersistidle = 0; /* max idle time in persist */ +static callout_t tcp_slowtimo_ch; +#ifdef NET_MPSAFE +static struct workqueue *tcp_slowtimo_wq; +static struct work tcp_slowtimo_wk; +#endif + +static void tcp_slowtimo_work(struct work *, void *); +static void tcp_slowtimo(void *); + /* * Time to delay the ACK. This is initialized in tcp_init(), unless * its patched. @@ -193,6 +205,21 @@ tcp_timer_init(void) tcp_delack_ticks = TCP_DELACK_TICKS; } +void +tcp_slowtimo_init(void) +{ +#ifdef NET_MPSAFE + int error; + + error = workqueue_create(&tcp_slowtimo_wq, "tcp_slowtimo", + tcp_slowtimo_work, NULL, PRI_SOFTNET, IPL_SOFTNET, WQ_MPSAFE); + if (error != 0) + panic("%s: workqueue_create failed (%d)\n", __func__, error); +#endif + callout_init(&tcp_slowtimo_ch, CALLOUT_MPSAFE); + callout_reset(&tcp_slowtimo_ch, 1, tcp_slowtimo, NULL); +} + /* * Callout to process delayed ACKs for a TCPCB. */ @@ -229,8 +256,8 @@ tcp_delack(void *arg) * Updates the timers in all active tcb's and * causes finite state machine actions if timers expire. */ -void -tcp_slowtimo(void *arg) +static void +tcp_slowtimo_work(struct work *wk, void *arg) { mutex_enter(softnet_lock); @@ -241,6 +268,17 @@ tcp_slowtimo(void *arg) callout_schedule(&tcp_slowtimo_ch, hz / PR_SLOWHZ); } +static void +tcp_slowtimo(void *arg) +{ + +#ifdef NET_MPSAFE + workqueue_enqueue(tcp_slowtimo_wq, &tcp_slowtimo_wk, NULL); +#else + tcp_slowtimo_work(NULL, NULL); +#endif +} + /* * Cancel all timers for TCP tp. */ Index: src/sys/netinet/tcp_timer.h diff -u src/sys/netinet/tcp_timer.h:1.28 src/sys/netinet/tcp_timer.h:1.29 --- src/sys/netinet/tcp_timer.h:1.28 Tue May 24 18:37:52 2011 +++ src/sys/netinet/tcp_timer.h Fri Jan 19 07:53:01 2018 @@ -1,4 +1,4 @@ -/* $NetBSD: tcp_timer.h,v 1.28 2011/05/24 18:37:52 gdt Exp $ */ +/* $NetBSD: tcp_timer.h,v 1.29 2018/01/19 07:53:01 ozaki-r Exp $ */ /*- * Copyright (c) 2001, 2005 The NetBSD Foundation, Inc. @@ -190,6 +190,7 @@ extern int tcp_ttl; /* time to live fo extern const int tcp_backoff[]; void tcp_timer_init(void); +void tcp_slowtimo_init(void); #endif #endif /* !_NETINET_TCP_TIMER_H_ */ Index: src/sys/netinet/tcp_var.h diff -u src/sys/netinet/tcp_var.h:1.181 src/sys/netinet/tcp_var.h:1.182 --- src/sys/netinet/tcp_var.h:1.181 Wed Nov 15 09:55:22 2017 +++ src/sys/netinet/tcp_var.h Fri Jan 19 07:53:01 2018 @@ -1,4 +1,4 @@ -/* $NetBSD: tcp_var.h,v 1.181 2017/11/15 09:55:22 ozaki-r Exp $ */ +/* $NetBSD: tcp_var.h,v 1.182 2018/01/19 07:53:01 ozaki-r Exp $ */ /* * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. @@ -928,8 +928,6 @@ void tcp_setpersist(struct tcpcb *); int tcp_signature_compute(struct mbuf *, struct tcphdr *, int, int, int, u_char *, u_int); #endif -void tcp_slowtimo(void *); -extern callout_t tcp_slowtimo_ch; void tcp_fasttimo(void); struct mbuf * tcp_template(struct tcpcb *);