change netmap global lock to sx?
Navdeep Parhar
np at FreeBSD.org
Tue May 27 23:49:51 UTC 2014
I'd like to change the netmap global lock from a mutex into a sleepable
shared/exclusive lock. This will allow a driver's nm_register hook
(which is called with the global lock held) to sleep if it has to. I've
casually used pkt-gen after this conversion (patch attached) and the
witness hasn't complained about it.
Thoughts?
Regards,
Navdeep
diff -r 0300d80260f4 sys/dev/netmap/netmap_kern.h
--- a/sys/dev/netmap/netmap_kern.h Fri May 23 19:00:56 2014 -0700
+++ b/sys/dev/netmap/netmap_kern.h Sat May 24 12:49:15 2014 -0700
@@ -43,13 +43,13 @@
#define unlikely(x) __builtin_expect((long)!!(x), 0L)
#define NM_LOCK_T struct mtx
-#define NMG_LOCK_T struct mtx
-#define NMG_LOCK_INIT() mtx_init(&netmap_global_lock, \
- "netmap global lock", NULL, MTX_DEF)
-#define NMG_LOCK_DESTROY() mtx_destroy(&netmap_global_lock)
-#define NMG_LOCK() mtx_lock(&netmap_global_lock)
-#define NMG_UNLOCK() mtx_unlock(&netmap_global_lock)
-#define NMG_LOCK_ASSERT() mtx_assert(&netmap_global_lock, MA_OWNED)
+#define NMG_LOCK_T struct sx
+#define NMG_LOCK_INIT() sx_init(&netmap_global_lock, \
+ "netmap global lock")
+#define NMG_LOCK_DESTROY() sx_destroy(&netmap_global_lock)
+#define NMG_LOCK() sx_xlock(&netmap_global_lock)
+#define NMG_UNLOCK() sx_xunlock(&netmap_global_lock)
+#define NMG_LOCK_ASSERT() sx_assert(&netmap_global_lock, SA_XLOCKED)
#define NM_SELINFO_T struct selinfo
#define MBUF_LEN(m) ((m)->m_pkthdr.len)
More information about the freebsd-net
mailing list