Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F171486647
D59457.id185946.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
3 KB
Referenced Files
None
Subscribers
None
D59457.id185946.diff
View Options
diff --git a/share/man/man9/buf_ring.9 b/share/man/man9/buf_ring.9
--- a/share/man/man9/buf_ring.9
+++ b/share/man/man9/buf_ring.9
@@ -42,7 +42,7 @@
.In sys/param.h
.In sys/buf_ring.h
.Ft struct buf_ring *
-.Fn buf_ring_alloc "int count" "struct malloc_type *type" "int flags" "struct mtx *sc_lock"
+.Fn buf_ring_alloc "int count" "struct malloc_type *type" "int flags" "lock_object_t lock"
.Ft void
.Fn buf_ring_free "struct buf_ring *br" "struct malloc_type *type"
.Ft int
@@ -74,7 +74,11 @@
and memory flags
.Fa flags .
The single consumer interface is protected by
-.Fa sc_lock .
+.Fa lock .
+Supported lock types are
+.Xr mutex 9
+and
+.Xr rwlock 9 .
.Pp
The
.Fn buf_ring_free
diff --git a/sys/kern/subr_bufring.c b/sys/kern/subr_bufring.c
--- a/sys/kern/subr_bufring.c
+++ b/sys/kern/subr_bufring.c
@@ -33,7 +33,7 @@
#include <sys/buf_ring.h>
struct buf_ring *
-buf_ring_alloc(int count, struct malloc_type *type, int flags, struct mtx *lock)
+buf_ring_alloc(int count, struct malloc_type *type, int flags, lock_object_t lo)
{
struct buf_ring *br;
@@ -43,9 +43,7 @@
type, flags | M_ZERO);
if (br == NULL)
return (NULL);
-#ifdef DEBUG_BUFRING
- br->br_lock = lock;
-#endif
+ br->br_lock = lo.lo;
br->br_prod_size = br->br_cons_size = count;
br->br_prod_mask = br->br_cons_mask = count-1;
br->br_prod_head = br->br_cons_head = 0;
diff --git a/sys/net/if_ovpn.c b/sys/net/if_ovpn.c
--- a/sys/net/if_ovpn.c
+++ b/sys/net/if_ovpn.c
@@ -2744,7 +2744,7 @@
rm_init_flags(&sc->lock, "if_ovpn_lock", RM_RECURSE);
sc->refcount = 0;
- sc->notifring = buf_ring_alloc(32, M_OVPN, M_WAITOK, NULL);
+ sc->notifring = buf_ring_alloc(32, M_OVPN, M_WAITOK, &sc->lock);
COUNTER_ARRAY_ALLOC(sc->counters, OVPN_COUNTER_SIZE, M_WAITOK);
diff --git a/sys/sys/buf_ring.h b/sys/sys/buf_ring.h
--- a/sys/sys/buf_ring.h
+++ b/sys/sys/buf_ring.h
@@ -36,9 +36,8 @@
#include <machine/atomic.h>
#include <machine/cpu.h>
-#if defined(DEBUG_BUFRING) && defined(_KERNEL)
+#if defined(_KERNEL)
#include <sys/lock.h>
-#include <sys/mutex.h>
#endif
/*
@@ -60,8 +59,12 @@
uint32_t br_cons_tail;
int br_cons_size;
int br_cons_mask;
-#if defined(DEBUG_BUFRING) && defined(_KERNEL)
- struct mtx *br_lock;
+#if defined(_KERNEL)
+ struct lock_object *br_lock;
+#define BR_LOCK_ASSERT(br) \
+ LOCK_CLASS((br)->br_lock)->lc_assert((br)->br_lock, LA_XLOCKED)
+#else
+#define BR_LOCK_ASSERT(br) do {} while (0)
#endif
void *br_ring[0] __aligned(CACHE_LINE_SIZE);
};
@@ -195,6 +198,8 @@
uint32_t prod_tail, mask;
void *buf;
+ BR_LOCK_ASSERT(br);
+
mask = br->br_cons_mask;
cons_head = atomic_load_32(&br->br_cons_head);
prod_tail = atomic_load_acq_32(&br->br_prod_tail);
@@ -210,10 +215,6 @@
#ifdef DEBUG_BUFRING
br->br_ring[cons_idx] = NULL;
-#ifdef _KERNEL
- if (!mtx_owned(br->br_lock))
- panic("lock not held on single consumer dequeue");
-#endif
if (atomic_load_32(&br->br_cons_tail) != cons_head)
panic("inconsistent list cons_tail=%d cons_head=%d",
atomic_load_32(&br->br_cons_tail), cons_head);
@@ -287,10 +288,11 @@
{
uint32_t cons_head, prod_tail, mask;
-#if defined(DEBUG_BUFRING) && defined(_KERNEL)
- if ((br->br_lock != NULL) && !mtx_owned(br->br_lock))
- panic("lock not held on single consumer dequeue");
-#endif
+#ifdef _KERNEL
+ if (br->br_lock != NULL)
+ BR_LOCK_ASSERT(br);
+#endif
+
mask = br->br_cons_mask;
prod_tail = atomic_load_acq_32(&br->br_prod_tail);
cons_head = atomic_load_32(&br->br_cons_head);
@@ -307,10 +309,7 @@
uint32_t cons_head, prod_tail, mask;
void *buf;
-#if defined(DEBUG_BUFRING) && defined(_KERNEL)
- if (!mtx_owned(br->br_lock))
- panic("lock not held on single consumer dequeue");
-#endif
+ BR_LOCK_ASSERT(br);
mask = br->br_cons_mask;
prod_tail = atomic_load_acq_32(&br->br_prod_tail);
@@ -356,7 +355,7 @@
#ifdef _KERNEL
struct buf_ring *buf_ring_alloc(int count, struct malloc_type *type, int flags,
- struct mtx *);
+ lock_object_t);
void buf_ring_free(struct buf_ring *br, struct malloc_type *type);
#else
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sat, Sep 12, 10:05 AM (8 h, 18 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
38784291
Default Alt Text
D59457.id185946.diff (3 KB)
Attached To
Mode
D59457: buf_ring: support different lock classes
Attached
Detach File
Event Timeline
Log In to Comment