svn commit: r332388 - in head/sys: kern net

Stephen Hurd shurd at FreeBSD.org
Tue Apr 10 19:42:51 UTC 2018


Author: shurd
Date: Tue Apr 10 19:42:50 2018
New Revision: 332388
URL: https://svnweb.freebsd.org/changeset/base/332388

Log:
  Make BPF global lock an SX
  
  This allows NIC drivers to sleep on polling config operations.
  
  Submitted by:	Matthew Macy <mmacy at mattmacy.io>
  Reviewed by:	shurd
  Sponsored by:	Limelight Networks
  Differential Revision:	https://reviews.freebsd.org/D14982

Modified:
  head/sys/kern/subr_witness.c
  head/sys/net/bpf.c
  head/sys/net/bpfdesc.h

Modified: head/sys/kern/subr_witness.c
==============================================================================
--- head/sys/kern/subr_witness.c	Tue Apr 10 19:18:16 2018	(r332387)
+++ head/sys/kern/subr_witness.c	Tue Apr 10 19:42:50 2018	(r332388)
@@ -569,7 +569,7 @@ static struct witness_order_list_entry order_lists[] =
 	/*
 	 * BPF
 	 */
-	{ "bpf global lock", &lock_class_mtx_sleep },
+	{ "bpf global lock", &lock_class_sx },
 	{ "bpf interface lock", &lock_class_rw },
 	{ "bpf cdev lock", &lock_class_mtx_sleep },
 	{ NULL, NULL },

Modified: head/sys/net/bpf.c
==============================================================================
--- head/sys/net/bpf.c	Tue Apr 10 19:18:16 2018	(r332387)
+++ head/sys/net/bpf.c	Tue Apr 10 19:42:50 2018	(r332388)
@@ -159,6 +159,9 @@ struct bpf_dltlist32 {
 #define	BIOCSETFNR32	_IOW('B', 130, struct bpf_program32)
 #endif
 
+#define BPF_LOCK()	   sx_xlock(&bpf_sx)
+#define BPF_UNLOCK()		sx_xunlock(&bpf_sx)
+#define BPF_LOCK_ASSERT()	sx_assert(&bpf_sx, SA_XLOCKED)
 /*
  * bpf_iflist is a list of BPF interface structures, each corresponding to a
  * specific DLT.  The same network interface might have several BPF interface
@@ -166,7 +169,7 @@ struct bpf_dltlist32 {
  * frames, ethernet frames, etc).
  */
 static LIST_HEAD(, bpf_if)	bpf_iflist, bpf_freelist;
-static struct mtx	bpf_mtx;		/* bpf global lock */
+static struct sx	bpf_sx;		/* bpf global lock */
 static int		bpf_bpfd_cnt;
 
 static void	bpf_attachd(struct bpf_d *, struct bpf_if *);
@@ -2821,7 +2824,7 @@ bpf_drvinit(void *unused)
 {
 	struct cdev *dev;
 
-	mtx_init(&bpf_mtx, "bpf global lock", NULL, MTX_DEF);
+	sx_init(&bpf_sx, "bpf global lock");
 	LIST_INIT(&bpf_iflist);
 	LIST_INIT(&bpf_freelist);
 

Modified: head/sys/net/bpfdesc.h
==============================================================================
--- head/sys/net/bpfdesc.h	Tue Apr 10 19:18:16 2018	(r332387)
+++ head/sys/net/bpfdesc.h	Tue Apr 10 19:42:50 2018	(r332388)
@@ -118,9 +118,6 @@ struct bpf_d {
 #define BPF_PID_REFRESH(bd, td)	(bd)->bd_pid = (td)->td_proc->p_pid
 #define BPF_PID_REFRESH_CUR(bd)	(bd)->bd_pid = curthread->td_proc->p_pid
 
-#define BPF_LOCK()		mtx_lock(&bpf_mtx)
-#define BPF_UNLOCK()		mtx_unlock(&bpf_mtx)
-#define BPF_LOCK_ASSERT()	mtx_assert(&bpf_mtx, MA_OWNED)
 /*
  * External representation of the bpf descriptor
  */


More information about the svn-src-head mailing list