mirror of
https://github.com/opnsense/src.git
synced 2026-06-05 06:42:56 -04:00
linuxkpi: spinlock: Simplify code
Just use a typedef for spinlock_t, no need to create a useless structure. Reviewed by: bz, emaste Sponsored by: Beckhoff Automation GmbH & Co. KG Differential Revision: https://reviews.freebsd.org/D45205
This commit is contained in:
parent
21ccdb4119
commit
ae38a1a1bf
5 changed files with 20 additions and 34 deletions
|
|
@ -41,9 +41,7 @@
|
|||
#include <linux/bottom_half.h>
|
||||
#include <linux/lockdep.h>
|
||||
|
||||
typedef struct {
|
||||
struct mtx m;
|
||||
} spinlock_t;
|
||||
typedef struct mtx spinlock_t;
|
||||
|
||||
/*
|
||||
* By defining CONFIG_SPIN_SKIP LinuxKPI spinlocks and asserts will be
|
||||
|
|
@ -59,7 +57,7 @@ typedef struct {
|
|||
#define spin_lock(_l) do { \
|
||||
if (SPIN_SKIP()) \
|
||||
break; \
|
||||
mtx_lock(&(_l)->m); \
|
||||
mtx_lock(_l); \
|
||||
local_bh_disable(); \
|
||||
} while (0)
|
||||
|
||||
|
|
@ -76,7 +74,7 @@ typedef struct {
|
|||
if (SPIN_SKIP()) \
|
||||
break; \
|
||||
local_bh_enable(); \
|
||||
mtx_unlock(&(_l)->m); \
|
||||
mtx_unlock(_l); \
|
||||
} while (0)
|
||||
|
||||
#define spin_unlock_bh(_l) do { \
|
||||
|
|
@ -93,7 +91,7 @@ typedef struct {
|
|||
if (SPIN_SKIP()) { \
|
||||
__ret = 1; \
|
||||
} else { \
|
||||
__ret = mtx_trylock(&(_l)->m); \
|
||||
__ret = mtx_trylock(_l); \
|
||||
if (likely(__ret != 0)) \
|
||||
local_bh_disable(); \
|
||||
} \
|
||||
|
|
@ -111,7 +109,7 @@ typedef struct {
|
|||
#define spin_lock_nested(_l, _n) do { \
|
||||
if (SPIN_SKIP()) \
|
||||
break; \
|
||||
mtx_lock_flags(&(_l)->m, MTX_DUPOK); \
|
||||
mtx_lock_flags(_l, MTX_DUPOK); \
|
||||
local_bh_disable(); \
|
||||
} while (0)
|
||||
|
||||
|
|
@ -141,31 +139,19 @@ typedef struct {
|
|||
#define _spin_lock_name(...) __spin_lock_name(__VA_ARGS__)
|
||||
#define spin_lock_name(name) _spin_lock_name(name, __FILE__, __LINE__)
|
||||
|
||||
#define spin_lock_init(lock) linux_spin_lock_init(lock, spin_lock_name("lnxspin"))
|
||||
#define spin_lock_init(lock) mtx_init(lock, spin_lock_name("lnxspin"), \
|
||||
NULL, MTX_DEF | MTX_NOWITNESS)
|
||||
|
||||
static inline void
|
||||
linux_spin_lock_init(spinlock_t *lock, const char *name)
|
||||
{
|
||||
|
||||
memset(lock, 0, sizeof(*lock));
|
||||
mtx_init(&lock->m, name, NULL, MTX_DEF | MTX_NOWITNESS);
|
||||
}
|
||||
|
||||
static inline void
|
||||
spin_lock_destroy(spinlock_t *lock)
|
||||
{
|
||||
|
||||
mtx_destroy(&lock->m);
|
||||
}
|
||||
#define spin_lock_destroy(_l) mtx_destroy(_l)
|
||||
|
||||
#define DEFINE_SPINLOCK(lock) \
|
||||
spinlock_t lock; \
|
||||
MTX_SYSINIT(lock, &(lock).m, spin_lock_name("lnxspin"), MTX_DEF)
|
||||
MTX_SYSINIT(lock, &lock, spin_lock_name("lnxspin"), MTX_DEF)
|
||||
|
||||
#define assert_spin_locked(_l) do { \
|
||||
if (SPIN_SKIP()) \
|
||||
break; \
|
||||
mtx_assert(&(_l)->m, MA_OWNED); \
|
||||
mtx_assert(_l, MA_OWNED); \
|
||||
} while (0)
|
||||
|
||||
#define atomic_dec_and_lock_irqsave(cnt, lock, flags) \
|
||||
|
|
|
|||
|
|
@ -113,7 +113,7 @@ extern wait_queue_func_t default_wake_function;
|
|||
MTX_SYSINIT(name, &(name).lock.m, spin_lock_name("wqhead"), MTX_DEF)
|
||||
|
||||
#define init_waitqueue_head(wqh) do { \
|
||||
mtx_init(&(wqh)->lock.m, spin_lock_name("wqhead"), \
|
||||
mtx_init(&(wqh)->lock, spin_lock_name("wqhead"), \
|
||||
NULL, MTX_DEF | MTX_NEW | MTX_NOWITNESS); \
|
||||
INIT_LIST_HEAD(&(wqh)->task_list); \
|
||||
} while (0)
|
||||
|
|
|
|||
|
|
@ -382,9 +382,9 @@ linux_kq_assert_lock(void *arg, int what)
|
|||
spinlock_t *s = arg;
|
||||
|
||||
if (what == LA_LOCKED)
|
||||
mtx_assert(&s->m, MA_OWNED);
|
||||
mtx_assert(s, MA_OWNED);
|
||||
else
|
||||
mtx_assert(&s->m, MA_NOTOWNED);
|
||||
mtx_assert(s, MA_NOTOWNED);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
|
@ -1094,7 +1094,7 @@ linux_file_kqfilter_read_event(struct knote *kn, long hint)
|
|||
{
|
||||
struct linux_file *filp = kn->kn_hook;
|
||||
|
||||
mtx_assert(&filp->f_kqlock.m, MA_OWNED);
|
||||
mtx_assert(&filp->f_kqlock, MA_OWNED);
|
||||
|
||||
return ((filp->f_kqflags & LINUX_KQ_FLAG_NEED_READ) ? 1 : 0);
|
||||
}
|
||||
|
|
@ -1104,7 +1104,7 @@ linux_file_kqfilter_write_event(struct knote *kn, long hint)
|
|||
{
|
||||
struct linux_file *filp = kn->kn_hook;
|
||||
|
||||
mtx_assert(&filp->f_kqlock.m, MA_OWNED);
|
||||
mtx_assert(&filp->f_kqlock, MA_OWNED);
|
||||
|
||||
return ((filp->f_kqflags & LINUX_KQ_FLAG_NEED_WRITE) ? 1 : 0);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -69,7 +69,7 @@ idr_preload_dequeue_locked(struct linux_idr_cache *lic)
|
|||
struct idr_layer *retval;
|
||||
|
||||
/* check if wrong thread is trying to dequeue */
|
||||
if (mtx_owned(&lic->lock.m) == 0)
|
||||
if (mtx_owned(&lic->lock) == 0)
|
||||
return (NULL);
|
||||
|
||||
retval = lic->head;
|
||||
|
|
|
|||
|
|
@ -91,8 +91,8 @@ int mlx4_en_create_tx_ring(struct mlx4_en_priv *priv,
|
|||
ring->size_mask = size - 1;
|
||||
ring->stride = stride;
|
||||
ring->inline_thold = MAX(MIN_PKT_LEN, MIN(priv->prof->inline_thold, MAX_INLINE));
|
||||
mtx_init(&ring->tx_lock.m, "mlx4 tx", NULL, MTX_DEF);
|
||||
mtx_init(&ring->comp_lock.m, "mlx4 comp", NULL, MTX_DEF);
|
||||
mtx_init(&ring->tx_lock, "mlx4 tx", NULL, MTX_DEF);
|
||||
mtx_init(&ring->comp_lock, "mlx4 comp", NULL, MTX_DEF);
|
||||
|
||||
tmp = size * sizeof(struct mlx4_en_tx_info);
|
||||
ring->tx_info = kzalloc_node(tmp, GFP_KERNEL, node);
|
||||
|
|
@ -205,8 +205,8 @@ void mlx4_en_destroy_tx_ring(struct mlx4_en_priv *priv,
|
|||
for (x = 0; x != ring->size; x++)
|
||||
bus_dmamap_destroy(ring->dma_tag, ring->tx_info[x].dma_map);
|
||||
vfree(ring->tx_info);
|
||||
mtx_destroy(&ring->tx_lock.m);
|
||||
mtx_destroy(&ring->comp_lock.m);
|
||||
mtx_destroy(&ring->tx_lock);
|
||||
mtx_destroy(&ring->comp_lock);
|
||||
bus_dma_tag_destroy(ring->dma_tag);
|
||||
kfree(ring);
|
||||
*pring = NULL;
|
||||
|
|
|
|||
Loading…
Reference in a new issue