Emulate spls by using pthread rwlocks: splfoo() takes a read lock
and when doing processing in an interrupt (effectively when calling biodone()), we take the write lock.
This commit is contained in:
parent
f08b04c841
commit
eabd71f058
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: intr.h,v 1.5 2007/11/07 00:20:22 ad Exp $ */
|
||||
/* $NetBSD: intr.h,v 1.6 2007/11/07 15:41:18 pooka Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2007 Antti Kantee. All Rights Reserved.
|
||||
|
@ -35,14 +35,17 @@ typedef struct {
|
|||
ipl_t _ipl;
|
||||
} ipl_cookie_t;
|
||||
|
||||
int rump_splfoo(void);
|
||||
void rump_splx(int);
|
||||
|
||||
#define spllower(x) ((void)0)
|
||||
#define splraise(x) 0
|
||||
#define splsoftnet() 0
|
||||
#define splhigh() 0
|
||||
#define splclock() 0
|
||||
#define splbio() 0
|
||||
#define splvm() 0
|
||||
#define splx(x) ((void)x)
|
||||
#define splsoftnet() rump_splfoo()
|
||||
#define splhigh() rump_splfoo()
|
||||
#define splclock() rump_splfoo()
|
||||
#define splbio() rump_splfoo()
|
||||
#define splvm() rump_splfoo()
|
||||
#define splx(x) rump_splx(x)
|
||||
|
||||
#define IPL_NONE 0
|
||||
#define IPL_BIO 0
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: rump.c,v 1.17 2007/11/07 12:11:30 pooka Exp $ */
|
||||
/* $NetBSD: rump.c,v 1.18 2007/11/07 15:41:18 pooka Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2007 Antti Kantee. All Rights Reserved.
|
||||
|
@ -551,6 +551,40 @@ rump_get_curlwp()
|
|||
return l;
|
||||
}
|
||||
|
||||
int
|
||||
rump_splfoo()
|
||||
{
|
||||
|
||||
if (!rumpuser_is_intr())
|
||||
rumpuser_rw_enter(&rumpspl, 0);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void
|
||||
rump_intr_enter(void)
|
||||
{
|
||||
|
||||
rumpuser_set_intr();
|
||||
rumpuser_rw_enter(&rumpspl, 1);
|
||||
}
|
||||
|
||||
static void
|
||||
rump_intr_exit(void)
|
||||
{
|
||||
|
||||
rumpuser_rw_exit(&rumpspl);
|
||||
rumpuser_clear_intr();
|
||||
}
|
||||
|
||||
void
|
||||
rump_splx(int dummy)
|
||||
{
|
||||
|
||||
if (!rumpuser_is_intr())
|
||||
rumpuser_rw_exit(&rumpspl);
|
||||
}
|
||||
|
||||
void
|
||||
rump_biodone(void *arg, size_t count, int error)
|
||||
{
|
||||
|
@ -559,5 +593,8 @@ rump_biodone(void *arg, size_t count, int error)
|
|||
bp->b_resid = bp->b_bcount - count;
|
||||
KASSERT(bp->b_resid >= 0);
|
||||
bp->b_error = error;
|
||||
|
||||
rump_intr_enter();
|
||||
biodone(bp);
|
||||
rump_intr_exit();
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: rump.h,v 1.17 2007/11/07 12:08:45 pooka Exp $ */
|
||||
/* $NetBSD: rump.h,v 1.18 2007/11/07 15:41:18 pooka Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2007 Antti Kantee. All Rights Reserved.
|
||||
|
@ -121,4 +121,7 @@ struct lwp *rump_setup_curlwp(pid_t, lwpid_t, int);
|
|||
struct lwp *rump_get_curlwp(void);
|
||||
void rump_clear_curlwp(void);
|
||||
|
||||
int rump_splfoo(void);
|
||||
void rump_splx(int);
|
||||
|
||||
#endif /* _SYS_RUMP_H_ */
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: rumpuser.h,v 1.8 2007/11/04 18:43:55 pooka Exp $ */
|
||||
/* $NetBSD: rumpuser.h,v 1.9 2007/11/07 15:41:18 pooka Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2007 Antti Kantee. All Rights Reserved.
|
||||
|
@ -99,4 +99,10 @@ struct lwp *rumpuser_get_curlwp(void);
|
|||
/* actually part of the rumpkern */
|
||||
void rump_biodone(void *, size_t, int);
|
||||
|
||||
extern struct rumpuser_rw rumpspl;
|
||||
|
||||
void rumpuser_set_intr(void);
|
||||
int rumpuser_is_intr(void);
|
||||
void rumpuser_clear_intr(void);
|
||||
|
||||
#endif /* _SYS_RUMPUSER_H_ */
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: rumpuser_pth.c,v 1.1 2007/10/31 15:57:22 pooka Exp $ */
|
||||
/* $NetBSD: rumpuser_pth.c,v 1.2 2007/11/07 15:41:18 pooka Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2007 Antti Kantee. All Rights Reserved.
|
||||
|
@ -38,15 +38,26 @@
|
|||
|
||||
#include "rumpuser.h"
|
||||
|
||||
pthread_key_t curlwpkey;
|
||||
static pthread_key_t curlwpkey;
|
||||
static pthread_key_t isintr;
|
||||
|
||||
#define NOFAIL(a) do {if (!(a)) abort();} while (/*CONSTCOND*/0)
|
||||
|
||||
struct rumpuser_rw {
|
||||
pthread_rwlock_t pthrw;
|
||||
};
|
||||
|
||||
struct rumpuser_rw rumpspl;
|
||||
|
||||
int
|
||||
rumpuser_thrinit()
|
||||
{
|
||||
|
||||
pthread_key_create(&curlwpkey, NULL);
|
||||
pthread_key_create(&isintr, NULL);
|
||||
|
||||
pthread_rwlock_init(&rumpspl.pthrw, NULL);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -113,10 +124,6 @@ rumpuser_mutex_destroy(struct rumpuser_mtx *mtx)
|
|||
free(mtx);
|
||||
}
|
||||
|
||||
struct rumpuser_rw {
|
||||
pthread_rwlock_t pthrw;
|
||||
};
|
||||
|
||||
void
|
||||
rumpuser_rw_init(struct rumpuser_rw **rw)
|
||||
{
|
||||
|
@ -212,3 +219,28 @@ rumpuser_get_curlwp()
|
|||
|
||||
return pthread_getspecific(curlwpkey);
|
||||
}
|
||||
|
||||
/*
|
||||
* I am the interrupt
|
||||
*/
|
||||
|
||||
void
|
||||
rumpuser_set_intr()
|
||||
{
|
||||
|
||||
pthread_setspecific(isintr, rumpuser_set_intr);
|
||||
}
|
||||
|
||||
int
|
||||
rumpuser_is_intr()
|
||||
{
|
||||
|
||||
return pthread_getspecific(isintr) != NULL;
|
||||
}
|
||||
|
||||
void
|
||||
rumpuser_clear_intr()
|
||||
{
|
||||
|
||||
pthread_setspecific(isintr, NULL);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue