Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F170839762
D59457.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
4 KB
Referenced Files
None
Subscribers
None
D59457.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"
.Ft void
.Fn buf_ring_free "struct buf_ring *br" "struct malloc_type *type"
.Ft int
@@ -74,7 +74,12 @@
and memory flags
.Fa flags .
The single consumer interface is protected by
-.Fa sc_lock .
+.Fa lock .
+Supported lock types are
+.Xr mutex 9 ,
+.Xr rwlock 9 ,
+and
+.Xr rmlock 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,8 @@
#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,
+ struct lock_object *lo)
{
struct buf_ring *br;
@@ -43,9 +44,7 @@
type, flags | M_ZERO);
if (br == NULL)
return (NULL);
-#ifdef DEBUG_BUFRING
- br->br_lock = lock;
-#endif
+ br->br_lock = 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);
@@ -355,8 +354,18 @@
}
#ifdef _KERNEL
-struct buf_ring *buf_ring_alloc(int count, struct malloc_type *type, int flags,
- struct mtx *);
+struct buf_ring *_buf_ring_alloc(int count, struct malloc_type *type,
+ int flags, struct lock_object *);
+#define buf_ring_alloc(c, mt, f, lk) _Generic((lk), \
+ void *: _buf_ring_alloc((c), (mt), (f), NULL), \
+ struct mtx *: _buf_ring_alloc((c), (mt), (f), \
+ &((struct mtx *)(lk))->lock_object), \
+ struct mtx_padalign *: _buf_ring_alloc((c), (mt), (f), \
+ &((struct mtx_padalign *)(lk))->lock_object), \
+ struct rwlock *: _buf_ring_alloc((c), (mt), (f), \
+ &((struct rwlock *)(lk))->lock_object), \
+ struct rmlock *: _buf_ring_alloc((c), (mt), (f), \
+ &((struct rmlock *)(lk))->lock_object))
void buf_ring_free(struct buf_ring *br, struct malloc_type *type);
#else
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Mon, Sep 7, 11:23 PM (4 h, 59 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
38491903
Default Alt Text
D59457.diff (4 KB)
Attached To
Mode
D59457: buf_ring: support different lock classes
Attached
Detach File
Event Timeline
Log In to Comment