From fb7518e554b2d765fd754b5d0e50f404bd437a7d Mon Sep 17 00:00:00 2001 From: Matthew Dillon Date: Tue, 10 Feb 2004 07:34:43 +0000 Subject: [PATCH] Use a globaldata_t instead of a cpuid in the lwkt_token structure. The LWKT subsystem already uses globaldata_t instead of cpuid for its thread td_gd reference, and the IPI messaging code will soon be converted to take a globaldata_t instead of a cpuid as well. This reduces the number of memory indirections we have to make to access the per-cpu globaldata space in various procedures. --- sys/kern/lwkt_token.c | 55 +++++++++++++++++++++---------------------- sys/kern/vfs_subr.c | 4 +++- sys/sys/thread.h | 6 ++--- sys/sys/thread2.h | 4 ++-- 4 files changed, 35 insertions(+), 34 deletions(-) diff --git a/sys/kern/lwkt_token.c b/sys/kern/lwkt_token.c index 60274d0536..af55217a3a 100644 --- a/sys/kern/lwkt_token.c +++ b/sys/kern/lwkt_token.c @@ -23,7 +23,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $DragonFly: src/sys/kern/lwkt_token.c,v 1.1 2004/02/09 21:13:18 dillon Exp $ + * $DragonFly: src/sys/kern/lwkt_token.c,v 1.2 2004/02/10 07:34:42 dillon Exp $ */ #ifdef _KERNEL @@ -89,7 +89,7 @@ SYSCTL_INT(_lwkt, OID_AUTO, token_debug, CTLFLAG_RW, &token_debug, 0, ""); typedef struct lwkt_gettoken_req { lwkt_token_t tok; - int cpu; + globaldata_t cpu; } lwkt_gettoken_req; /* @@ -105,7 +105,7 @@ typedef struct lwkt_gettoken_req { * a token, but do we really only need to disable IPIs ? * * YYY certain tokens could be made to act like mutexes when performance - * would be better (e.g. t_cpu == -1). This is not yet implemented. + * would be better (e.g. t_cpu == NULL). This is not yet implemented. * * YYY the tokens replace 4.x's simplelocks for the most part, but this * means that 4.x does not expect a switch so for now we cannot switch @@ -125,10 +125,10 @@ void lwkt_gettoken_remote(void *arg) { lwkt_gettoken_req *req = arg; - if (req->tok->t_cpu == mycpu->gd_cpuid) { + if (req->tok->t_cpu == mycpu) { #ifdef INVARIANTS if (token_debug) - printf("GT(%d,%d) ", req->tok->t_cpu, req->cpu); + printf("GT(%d,%d) ", req->tok->t_cpu->gd_cpuid, req->cpu->gd_cpuid); #endif req->tok->t_cpu = req->cpu; req->tok->t_reqcpu = req->cpu; /* YYY leave owned by target cpu */ @@ -160,24 +160,23 @@ lwkt_gettoken(lwkt_token_t tok) } #endif #ifdef SMP - while (tok->t_cpu != mycpu->gd_cpuid) { + while (tok->t_cpu != mycpu) { struct lwkt_gettoken_req req; int seq; - int dcpu; + globaldata_t dcpu; - req.cpu = mycpu->gd_cpuid; + req.cpu = mycpu; req.tok = tok; - dcpu = (volatile int)tok->t_cpu; - KKASSERT(dcpu >= 0 && dcpu < ncpus); + dcpu = tok->t_cpu; #ifdef INVARIANTS if (token_debug) - printf("REQT%d ", dcpu); + printf("REQT%d ", dcpu->gd_cpuid); #endif - seq = lwkt_send_ipiq(dcpu, lwkt_gettoken_remote, &req); - lwkt_wait_ipiq(dcpu, seq); + seq = lwkt_send_ipiq(dcpu->gd_cpuid, lwkt_gettoken_remote, &req); + lwkt_wait_ipiq(dcpu->gd_cpuid, seq); #ifdef INVARIANTS if (token_debug) - printf("REQR%d ", tok->t_cpu); + printf("REQR%d ", tok->t_cpu->gd_cpuid); #endif } #endif @@ -197,7 +196,7 @@ lwkt_trytoken(lwkt_token_t tok) { crit_enter(); #ifdef SMP - if (tok->t_cpu != mycpu->gd_cpuid) { + if (tok->t_cpu != mycpu) { crit_exit(); return(0); } @@ -226,7 +225,7 @@ lwkt_reltoken(lwkt_token_t tok) { int gen; - if (tok->t_cpu == mycpu->gd_cpuid) { + if (tok->t_cpu == mycpu) { tok->t_cpu = tok->t_reqcpu; } gen = tok->t_gen; @@ -246,7 +245,7 @@ lwkt_reltoken(lwkt_token_t tok) int lwkt_gentoken(lwkt_token_t tok, int *gen) { - if (tok->t_cpu == mycpu->gd_cpuid && tok->t_gen == *gen) + if (tok->t_cpu == mycpu && tok->t_gen == *gen) return(0); *gen = lwkt_regettoken(tok); return(-1); @@ -262,26 +261,25 @@ int lwkt_regettoken(lwkt_token_t tok) { /* assert we are in a critical section */ - if (tok->t_cpu != mycpu->gd_cpuid) { + if (tok->t_cpu != mycpu) { #ifdef SMP - while (tok->t_cpu != mycpu->gd_cpuid) { + while (tok->t_cpu != mycpu) { struct lwkt_gettoken_req req; int seq; - int dcpu; + globaldata_t dcpu; - req.cpu = mycpu->gd_cpuid; + req.cpu = mycpu; req.tok = tok; - dcpu = (volatile int)tok->t_cpu; - KKASSERT(dcpu >= 0 && dcpu < ncpus); + dcpu = tok->t_cpu; #ifdef INVARIANTS if (token_debug) - printf("REQT%d ", dcpu); + printf("REQT%d ", dcpu->gd_cpuid); #endif - seq = lwkt_send_ipiq(dcpu, lwkt_gettoken_remote, &req); - lwkt_wait_ipiq(dcpu, seq); + seq = lwkt_send_ipiq(dcpu->gd_cpuid, lwkt_gettoken_remote, &req); + lwkt_wait_ipiq(dcpu->gd_cpuid, seq); #ifdef INVARIATNS if (token_debug) - printf("REQR%d ", tok->t_cpu); + printf("REQR%d ", tok->t_cpu->gd_cpuid); #endif } #endif @@ -296,6 +294,7 @@ lwkt_inittoken(lwkt_token_t tok) /* * Zero structure and set cpu owner and reqcpu to cpu 0. */ - bzero(tok, sizeof(*tok)); + tok->t_cpu = tok->t_reqcpu = mycpu; + tok->t_gen = 0; } diff --git a/sys/kern/vfs_subr.c b/sys/kern/vfs_subr.c index 6d47096150..543acee409 100644 --- a/sys/kern/vfs_subr.c +++ b/sys/kern/vfs_subr.c @@ -37,7 +37,7 @@ * * @(#)vfs_subr.c 8.31 (Berkeley) 5/26/95 * $FreeBSD: src/sys/kern/vfs_subr.c,v 1.249.2.30 2003/04/04 20:35:57 tegge Exp $ - * $DragonFly: src/sys/kern/vfs_subr.c,v 1.24 2004/01/27 23:56:48 dillon Exp $ + * $DragonFly: src/sys/kern/vfs_subr.c,v 1.25 2004/02/10 07:34:42 dillon Exp $ */ /* @@ -195,6 +195,7 @@ vntblinit() (5 * (sizeof(struct vm_object) + sizeof(struct vnode)))); minvnodes = desiredvnodes / 4; + lwkt_inittoken(&mountlist_token); lwkt_inittoken(&mntvnode_token); lwkt_inittoken(&mntid_token); lwkt_inittoken(&spechash_token); @@ -737,6 +738,7 @@ getnewvnode(tag, mp, vops, vpp) vp = (struct vnode *) zalloc(vnode_zone); bzero((char *) vp, sizeof *vp); lwkt_inittoken(&vp->v_interlock); + lwkt_inittoken(&vp->v_pollinfo.vpi_token); vp->v_dd = vp; cache_purge(vp); TAILQ_INIT(&vp->v_namecache); diff --git a/sys/sys/thread.h b/sys/sys/thread.h index dfe1ddadb0..f1850f8979 100644 --- a/sys/sys/thread.h +++ b/sys/sys/thread.h @@ -7,7 +7,7 @@ * Types which must already be defined when this header is included by * userland: struct md_thread * - * $DragonFly: src/sys/sys/thread.h,v 1.40 2004/01/30 05:42:18 dillon Exp $ + * $DragonFly: src/sys/sys/thread.h,v 1.41 2004/02/10 07:34:43 dillon Exp $ */ #ifndef _SYS_THREAD_H_ @@ -76,8 +76,8 @@ struct intrframe; * token you are requesting. */ typedef struct lwkt_token { - int t_cpu; /* the current owner of the token */ - int t_reqcpu; /* return ownership to this cpu on release */ + struct globaldata *t_cpu; /* the current owner of the token */ + struct globaldata *t_reqcpu;/* return ownership to this cpu on release */ int t_gen; /* generation number */ } lwkt_token; diff --git a/sys/sys/thread2.h b/sys/sys/thread2.h index aa68ad449d..48f763bc8e 100644 --- a/sys/sys/thread2.h +++ b/sys/sys/thread2.h @@ -8,7 +8,7 @@ * on a different cpu will not be immediately scheduled by a yield() on * this cpu. * - * $DragonFly: src/sys/sys/thread2.h,v 1.11 2004/01/01 00:31:46 dillon Exp $ + * $DragonFly: src/sys/sys/thread2.h,v 1.12 2004/02/10 07:34:43 dillon Exp $ */ #ifndef _SYS_THREAD2_H_ @@ -105,7 +105,7 @@ crit_panic_restore(int cpri) static __inline int lwkt_havetoken(lwkt_token_t tok) { - return (tok->t_cpu == mycpu->gd_cpuid); + return (tok->t_cpu == mycpu); } /* -- 2.41.0