kqueue: save space by using only one func pointer for assertions

This commit is contained in:
Mateusz Guzik 2020-11-09 00:04:35 +00:00
parent dc0800a9ad
commit e90afaa015
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=367498
6 changed files with 71 additions and 116 deletions

View File

@ -422,22 +422,15 @@ linux_kq_unlock(void *arg)
}
static void
linux_kq_lock_owned(void *arg)
linux_kq_assert_lock(void *arg, int what)
{
#ifdef INVARIANTS
spinlock_t *s = arg;
mtx_assert(&s->m, MA_OWNED);
#endif
}
static void
linux_kq_lock_unowned(void *arg)
{
#ifdef INVARIANTS
spinlock_t *s = arg;
mtx_assert(&s->m, MA_NOTOWNED);
if (what == LA_LOCKED)
mtx_assert(&s->m, MA_OWNED);
else
mtx_assert(&s->m, MA_NOTOWNED);
#endif
}
@ -457,8 +450,7 @@ linux_file_alloc(void)
/* setup fields needed by kqueue support */
spin_lock_init(&filp->f_kqlock);
knlist_init(&filp->f_selinfo.si_note, &filp->f_kqlock,
linux_kq_lock, linux_kq_unlock,
linux_kq_lock_owned, linux_kq_lock_unowned);
linux_kq_lock, linux_kq_unlock, linux_kq_assert_lock);
return (filp);
}

View File

@ -145,17 +145,13 @@ uinput_knlunlock(void *arg)
}
static void
uinput_knl_assert_locked(void *arg)
uinput_knl_assert_lock(void *arg, int what)
{
sx_assert((struct sx*)arg, SA_XLOCKED);
}
static void
uinput_knl_assert_unlocked(void *arg)
{
sx_assert((struct sx*)arg, SA_UNLOCKED);
if (what == LA_LOCKED)
sx_assert((struct sx*)arg, SA_XLOCKED);
else
sx_assert((struct sx*)arg, SA_UNLOCKED);
}
static void
@ -212,8 +208,7 @@ uinput_open(struct cdev *dev, int oflags, int devtype, struct thread *td)
sx_init(&state->ucs_lock, "uinput");
knlist_init(&state->ucs_selp.si_note, &state->ucs_lock, uinput_knllock,
uinput_knlunlock, uinput_knl_assert_locked,
uinput_knl_assert_unlocked);
uinput_knlunlock, uinput_knl_assert_lock);
devfs_set_cdevpriv(state, uinput_dtor);
return (0);

View File

@ -305,10 +305,10 @@ kn_leave_flux(struct knote *kn)
} while (0)
#ifdef INVARIANTS
#define KNL_ASSERT_LOCKED(knl) do { \
knl->kl_assert_locked((knl)->kl_lockarg); \
knl->kl_assert_lock((knl)->kl_lockarg, LA_LOCKED); \
} while (0)
#define KNL_ASSERT_UNLOCKED(knl) do { \
knl->kl_assert_unlocked((knl)->kl_lockarg); \
knl->kl_assert_lock((knl)->kl_lockarg, LA_UNLOCKED); \
} while (0)
#else /* !INVARIANTS */
#define KNL_ASSERT_LOCKED(knl) do {} while(0)
@ -2375,17 +2375,13 @@ knlist_mtx_unlock(void *arg)
}
static void
knlist_mtx_assert_locked(void *arg)
knlist_mtx_assert_lock(void *arg, int what)
{
mtx_assert((struct mtx *)arg, MA_OWNED);
}
static void
knlist_mtx_assert_unlocked(void *arg)
{
mtx_assert((struct mtx *)arg, MA_NOTOWNED);
if (what == LA_LOCKED)
mtx_assert((struct mtx *)arg, MA_OWNED);
else
mtx_assert((struct mtx *)arg, MA_NOTOWNED);
}
static void
@ -2403,23 +2399,19 @@ knlist_rw_runlock(void *arg)
}
static void
knlist_rw_assert_locked(void *arg)
knlist_rw_assert_lock(void *arg, int what)
{
rw_assert((struct rwlock *)arg, RA_LOCKED);
}
static void
knlist_rw_assert_unlocked(void *arg)
{
rw_assert((struct rwlock *)arg, RA_UNLOCKED);
if (what == LA_LOCKED)
rw_assert((struct rwlock *)arg, RA_LOCKED);
else
rw_assert((struct rwlock *)arg, RA_UNLOCKED);
}
void
knlist_init(struct knlist *knl, void *lock, void (*kl_lock)(void *),
void (*kl_unlock)(void *),
void (*kl_assert_locked)(void *), void (*kl_assert_unlocked)(void *))
void (*kl_assert_lock)(void *, int))
{
if (lock == NULL)
@ -2435,14 +2427,10 @@ knlist_init(struct knlist *knl, void *lock, void (*kl_lock)(void *),
knl->kl_unlock = knlist_mtx_unlock;
else
knl->kl_unlock = kl_unlock;
if (kl_assert_locked == NULL)
knl->kl_assert_locked = knlist_mtx_assert_locked;
if (kl_assert_lock == NULL)
knl->kl_assert_lock = knlist_mtx_assert_lock;
else
knl->kl_assert_locked = kl_assert_locked;
if (kl_assert_unlocked == NULL)
knl->kl_assert_unlocked = knlist_mtx_assert_unlocked;
else
knl->kl_assert_unlocked = kl_assert_unlocked;
knl->kl_assert_lock = kl_assert_lock;
knl->kl_autodestroy = 0;
SLIST_INIT(&knl->kl_list);
@ -2452,7 +2440,7 @@ void
knlist_init_mtx(struct knlist *knl, struct mtx *lock)
{
knlist_init(knl, lock, NULL, NULL, NULL, NULL);
knlist_init(knl, lock, NULL, NULL, NULL);
}
struct knlist *
@ -2470,7 +2458,7 @@ knlist_init_rw_reader(struct knlist *knl, struct rwlock *lock)
{
knlist_init(knl, lock, knlist_rw_rlock, knlist_rw_runlock,
knlist_rw_assert_locked, knlist_rw_assert_unlocked);
knlist_rw_assert_lock);
}
void

View File

@ -165,12 +165,10 @@ static int soreceive_rcvoob(struct socket *so, struct uio *uio,
int flags);
static void so_rdknl_lock(void *);
static void so_rdknl_unlock(void *);
static void so_rdknl_assert_locked(void *);
static void so_rdknl_assert_unlocked(void *);
static void so_rdknl_assert_lock(void *, int);
static void so_wrknl_lock(void *);
static void so_wrknl_unlock(void *);
static void so_wrknl_assert_locked(void *);
static void so_wrknl_assert_unlocked(void *);
static void so_wrknl_assert_lock(void *, int);
static void filt_sordetach(struct knote *kn);
static int filt_soread(struct knote *kn, long hint);
@ -550,9 +548,9 @@ socreate(int dom, struct socket **aso, int type, int proto,
mac_socket_create(cred, so);
#endif
knlist_init(&so->so_rdsel.si_note, so, so_rdknl_lock, so_rdknl_unlock,
so_rdknl_assert_locked, so_rdknl_assert_unlocked);
so_rdknl_assert_lock);
knlist_init(&so->so_wrsel.si_note, so, so_wrknl_lock, so_wrknl_unlock,
so_wrknl_assert_locked, so_wrknl_assert_unlocked);
so_wrknl_assert_lock);
/*
* Auto-sizing of socket buffers is managed by the protocols and
* the appropriate flags must be set in the pru_attach function.
@ -729,9 +727,9 @@ sonewconn(struct socket *head, int connstatus)
mac_socket_newconn(head, so);
#endif
knlist_init(&so->so_rdsel.si_note, so, so_rdknl_lock, so_rdknl_unlock,
so_rdknl_assert_locked, so_rdknl_assert_unlocked);
so_rdknl_assert_lock);
knlist_init(&so->so_wrsel.si_note, so, so_wrknl_lock, so_wrknl_unlock,
so_wrknl_assert_locked, so_wrknl_assert_unlocked);
so_wrknl_assert_lock);
VNET_SO_ASSERT(head);
if (soreserve(so, head->sol_sbsnd_hiwat, head->sol_sbrcv_hiwat)) {
sodealloc(so);
@ -823,9 +821,9 @@ sopeeloff(struct socket *head)
mac_socket_newconn(head, so);
#endif
knlist_init(&so->so_rdsel.si_note, so, so_rdknl_lock, so_rdknl_unlock,
so_rdknl_assert_locked, so_rdknl_assert_unlocked);
so_rdknl_assert_lock);
knlist_init(&so->so_wrsel.si_note, so, so_wrknl_lock, so_wrknl_unlock,
so_wrknl_assert_locked, so_wrknl_assert_unlocked);
so_wrknl_assert_lock);
VNET_SO_ASSERT(head);
if (soreserve(so, head->so_snd.sb_hiwat, head->so_rcv.sb_hiwat)) {
sodealloc(so);
@ -4189,25 +4187,21 @@ so_rdknl_unlock(void *arg)
}
static void
so_rdknl_assert_locked(void *arg)
so_rdknl_assert_lock(void *arg, int what)
{
struct socket *so = arg;
if (SOLISTENING(so))
SOCK_LOCK_ASSERT(so);
else
SOCKBUF_LOCK_ASSERT(&so->so_rcv);
}
static void
so_rdknl_assert_unlocked(void *arg)
{
struct socket *so = arg;
if (SOLISTENING(so))
SOCK_UNLOCK_ASSERT(so);
else
SOCKBUF_UNLOCK_ASSERT(&so->so_rcv);
if (what == LA_LOCKED) {
if (SOLISTENING(so))
SOCK_LOCK_ASSERT(so);
else
SOCKBUF_LOCK_ASSERT(&so->so_rcv);
} else {
if (SOLISTENING(so))
SOCK_UNLOCK_ASSERT(so);
else
SOCKBUF_UNLOCK_ASSERT(&so->so_rcv);
}
}
static void
@ -4233,25 +4227,21 @@ so_wrknl_unlock(void *arg)
}
static void
so_wrknl_assert_locked(void *arg)
so_wrknl_assert_lock(void *arg, int what)
{
struct socket *so = arg;
if (SOLISTENING(so))
SOCK_LOCK_ASSERT(so);
else
SOCKBUF_LOCK_ASSERT(&so->so_snd);
}
static void
so_wrknl_assert_unlocked(void *arg)
{
struct socket *so = arg;
if (SOLISTENING(so))
SOCK_UNLOCK_ASSERT(so);
else
SOCKBUF_UNLOCK_ASSERT(&so->so_snd);
if (what == LA_LOCKED) {
if (SOLISTENING(so))
SOCK_LOCK_ASSERT(so);
else
SOCKBUF_LOCK_ASSERT(&so->so_snd);
} else {
if (SOLISTENING(so))
SOCK_UNLOCK_ASSERT(so);
else
SOCKBUF_UNLOCK_ASSERT(&so->so_snd);
}
}
/*

View File

@ -112,8 +112,7 @@ static void vgonel(struct vnode *);
static bool vhold_recycle_free(struct vnode *);
static void vfs_knllock(void *arg);
static void vfs_knlunlock(void *arg);
static void vfs_knl_assert_locked(void *arg);
static void vfs_knl_assert_unlocked(void *arg);
static void vfs_knl_assert_lock(void *arg, int what);
static void destroy_vpollinfo(struct vpollinfo *vi);
static int v_inval_buf_range_locked(struct vnode *vp, struct bufobj *bo,
daddr_t startlbn, daddr_t endlbn);
@ -4811,7 +4810,7 @@ v_addpollinfo(struct vnode *vp)
vi = malloc(sizeof(*vi), M_VNODEPOLL, M_WAITOK | M_ZERO);
mtx_init(&vi->vpi_lock, "vnode pollinfo", NULL, MTX_DEF);
knlist_init(&vi->vpi_selinfo.si_note, vp, vfs_knllock,
vfs_knlunlock, vfs_knl_assert_locked, vfs_knl_assert_unlocked);
vfs_knlunlock, vfs_knl_assert_lock);
VI_LOCK(vp);
if (vp->v_pollinfo != NULL) {
VI_UNLOCK(vp);
@ -6060,22 +6059,15 @@ vfs_knlunlock(void *arg)
}
static void
vfs_knl_assert_locked(void *arg)
vfs_knl_assert_lock(void *arg, int what)
{
#ifdef DEBUG_VFS_LOCKS
struct vnode *vp = arg;
ASSERT_VOP_LOCKED(vp, "vfs_knl_assert_locked");
#endif
}
static void
vfs_knl_assert_unlocked(void *arg)
{
#ifdef DEBUG_VFS_LOCKS
struct vnode *vp = arg;
ASSERT_VOP_UNLOCKED(vp, "vfs_knl_assert_unlocked");
if (what == LA_LOCKED)
ASSERT_VOP_LOCKED(vp, "vfs_knl_assert_locked");
else
ASSERT_VOP_UNLOCKED(vp, "vfs_knl_assert_unlocked");
#endif
}

View File

@ -224,8 +224,7 @@ struct knlist {
struct klist kl_list;
void (*kl_lock)(void *); /* lock function */
void (*kl_unlock)(void *);
void (*kl_assert_locked)(void *);
void (*kl_assert_unlocked)(void *);
void (*kl_assert_lock)(void *, int);
void *kl_lockarg; /* argument passed to lock functions */
int kl_autodestroy;
};
@ -334,8 +333,7 @@ void knlist_add(struct knlist *knl, struct knote *kn, int islocked);
void knlist_remove(struct knlist *knl, struct knote *kn, int islocked);
int knlist_empty(struct knlist *knl);
void knlist_init(struct knlist *knl, void *lock, void (*kl_lock)(void *),
void (*kl_unlock)(void *), void (*kl_assert_locked)(void *),
void (*kl_assert_unlocked)(void *));
void (*kl_unlock)(void *), void (*kl_assert_lock)(void *, int));
void knlist_init_mtx(struct knlist *knl, struct mtx *lock);
void knlist_init_rw_reader(struct knlist *knl, struct rwlock *lock);
void knlist_destroy(struct knlist *knl);