Move the lockops together with the interface -- they are needed
only at runtime.
This commit is contained in:
parent
9ae53a340e
commit
50fa67ff5f
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: if_shmem.c,v 1.22 2010/08/15 18:48:38 pooka Exp $ */
|
||||
/* $NetBSD: if_shmem.c,v 1.23 2010/08/15 18:55:03 pooka Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2009 Antti Kantee. All Rights Reserved.
|
||||
|
@ -28,7 +28,7 @@
|
|||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__KERNEL_RCSID(0, "$NetBSD: if_shmem.c,v 1.22 2010/08/15 18:48:38 pooka Exp $");
|
||||
__KERNEL_RCSID(0, "$NetBSD: if_shmem.c,v 1.23 2010/08/15 18:55:03 pooka Exp $");
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/atomic.h>
|
||||
|
@ -79,6 +79,46 @@ static void shmif_rcv(void *);
|
|||
|
||||
static uint32_t numif;
|
||||
|
||||
#define LOCK_UNLOCKED 0
|
||||
#define LOCK_LOCKED 1
|
||||
#define LOCK_COOLDOWN 1001
|
||||
|
||||
/*
|
||||
* This locking needs work and will misbehave severely if:
|
||||
* 1) the backing memory has to be paged in
|
||||
* 2) some lockholder exits while holding the lock
|
||||
*/
|
||||
static void
|
||||
shmif_lockbus(struct shmif_mem *busmem)
|
||||
{
|
||||
int i = 0;
|
||||
|
||||
while (__predict_false(atomic_cas_32(&busmem->shm_lock,
|
||||
LOCK_UNLOCKED, LOCK_LOCKED) == LOCK_LOCKED)) {
|
||||
if (__predict_false(++i > LOCK_COOLDOWN)) {
|
||||
uint64_t sec, nsec;
|
||||
int error;
|
||||
|
||||
sec = 0;
|
||||
nsec = 1000*1000; /* 1ms */
|
||||
rumpuser_nanosleep(&sec, &nsec, &error);
|
||||
i = 0;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
membar_enter();
|
||||
}
|
||||
|
||||
static void
|
||||
shmif_unlockbus(struct shmif_mem *busmem)
|
||||
{
|
||||
unsigned int old;
|
||||
|
||||
membar_exit();
|
||||
old = atomic_swap_32(&busmem->shm_lock, LOCK_UNLOCKED);
|
||||
KASSERT(old == LOCK_LOCKED);
|
||||
}
|
||||
|
||||
int
|
||||
rump_shmif_create(const char *path, int *ifnum)
|
||||
{
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: shmif_busops.c,v 1.3 2010/08/15 18:47:38 pooka Exp $ */
|
||||
/* $NetBSD: shmif_busops.c,v 1.4 2010/08/15 18:55:03 pooka Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2009 Antti Kantee. All Rights Reserved.
|
||||
|
@ -28,7 +28,7 @@
|
|||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__KERNEL_RCSID(0, "$NetBSD: shmif_busops.c,v 1.3 2010/08/15 18:47:38 pooka Exp $");
|
||||
__KERNEL_RCSID(0, "$NetBSD: shmif_busops.c,v 1.4 2010/08/15 18:55:03 pooka Exp $");
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/atomic.h>
|
||||
|
@ -42,46 +42,6 @@ __KERNEL_RCSID(0, "$NetBSD: shmif_busops.c,v 1.3 2010/08/15 18:47:38 pooka Exp $
|
|||
#include <rump/rumpuser.h>
|
||||
#endif
|
||||
|
||||
#define LOCK_UNLOCKED 0
|
||||
#define LOCK_LOCKED 1
|
||||
#define LOCK_COOLDOWN 1001
|
||||
|
||||
/*
|
||||
* This locking needs work and will misbehave severely if:
|
||||
* 1) the backing memory has to be paged in
|
||||
* 2) some lockholder exits while holding the lock
|
||||
*/
|
||||
void
|
||||
shmif_lockbus(struct shmif_mem *busmem)
|
||||
{
|
||||
int i = 0;
|
||||
|
||||
while (__predict_false(atomic_cas_32(&busmem->shm_lock,
|
||||
LOCK_UNLOCKED, LOCK_LOCKED) == LOCK_LOCKED)) {
|
||||
if (__predict_false(++i > LOCK_COOLDOWN)) {
|
||||
uint64_t sec, nsec;
|
||||
int error;
|
||||
|
||||
sec = 0;
|
||||
nsec = 1000*1000; /* 1ms */
|
||||
rumpuser_nanosleep(&sec, &nsec, &error);
|
||||
i = 0;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
membar_enter();
|
||||
}
|
||||
|
||||
void
|
||||
shmif_unlockbus(struct shmif_mem *busmem)
|
||||
{
|
||||
unsigned int old;
|
||||
|
||||
membar_exit();
|
||||
old = atomic_swap_32(&busmem->shm_lock, LOCK_UNLOCKED);
|
||||
KASSERT(old == LOCK_LOCKED);
|
||||
}
|
||||
|
||||
uint32_t
|
||||
shmif_advance(uint32_t oldoff, uint32_t delta)
|
||||
{
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: shmifvar.h,v 1.4 2010/08/13 10:13:44 pooka Exp $ */
|
||||
/* $NetBSD: shmifvar.h,v 1.5 2010/08/15 18:55:03 pooka Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 2009 Antti Kantee. All Rights Reserved.
|
||||
|
@ -71,8 +71,6 @@ struct shmif_pkthdr {
|
|||
#define DPRINTF(x)
|
||||
#endif
|
||||
|
||||
void shmif_lockbus(struct shmif_mem *);
|
||||
void shmif_unlockbus(struct shmif_mem *);
|
||||
uint32_t shmif_advance(uint32_t, uint32_t);
|
||||
uint32_t shmif_busread(struct shmif_mem *,
|
||||
void *, uint32_t, size_t, bool *);
|
||||
|
|
Loading…
Reference in New Issue