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
This commit is contained in:
ozaki-r 2018-01-19 07:53:01 +00:00
parent fd8bca6477
commit be75d649ea
4 changed files with 48 additions and 14 deletions

View File

@ -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 = MOWNER_INIT("tcp", "sock rx");
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;
}

View File

@ -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,v 1.92 2017/07/28 19:16:41 maxv Exp $");
#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 probes */
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.
*/

View File

@ -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 for TCP segs */
extern const int tcp_backoff[];
void tcp_timer_init(void);
void tcp_slowtimo_init(void);
#endif
#endif /* !_NETINET_TCP_TIMER_H_ */

View File

@ -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 *);