Cache a number of execution contexts instead of re-initializing

them every time.  Speeds up pure in-memory file systems such as
sysctlfs or dtfs quite a bit.  For actual I/O-workhorses the result
is of course less tasty.
This commit is contained in:
pooka 2008-01-16 21:29:59 +00:00
parent 56143d3b3c
commit 614c59fcb2
4 changed files with 61 additions and 30 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: callcontext.c,v 1.17 2008/01/16 00:29:42 pooka Exp $ */
/* $NetBSD: callcontext.c,v 1.18 2008/01/16 21:29:59 pooka Exp $ */
/*
* Copyright (c) 2006 Antti Kantee. All Rights Reserved.
@ -27,7 +27,7 @@
#include <sys/cdefs.h>
#if !defined(lint)
__RCSID("$NetBSD: callcontext.c,v 1.17 2008/01/16 00:29:42 pooka Exp $");
__RCSID("$NetBSD: callcontext.c,v 1.18 2008/01/16 21:29:59 pooka Exp $");
#endif /* !lint */
#include <sys/types.h>
@ -95,7 +95,7 @@ puffs_cc_schedule(struct puffs_cc *pcc)
struct puffs_usermount *pu = pcc->pcc_pu;
assert(pu->pu_state & PU_INLOOP);
TAILQ_INSERT_TAIL(&pu->pu_sched, pcc, entries);
TAILQ_INSERT_TAIL(&pu->pu_sched, pcc, pcc_schedent);
}
int
@ -136,6 +136,16 @@ puffs_cc_create(struct puffs_usermount *pu, struct puffs_framebuf *pb,
stacksize = pthread__stacksize;
#endif
/* Do we have a cached copy? */
if (pu->pu_cc_nstored) {
pcc = LIST_FIRST(&pu->pu_ccmagazin);
assert(pcc != NULL);
LIST_REMOVE(pcc, pcc_rope);
pu->pu_cc_nstored--;
goto finalize;
}
/*
* There are two paths and in the long run we don't have time to
* change the one we're on. For non-real cc's, we just simply use
@ -162,11 +172,9 @@ puffs_cc_create(struct puffs_usermount *pu, struct puffs_framebuf *pb,
memset(pcc, 0, sizeof(struct puffs_cc));
pcc->pcc_pu = pu;
pcc->pcc_pb = pb;
pcc->pcc_flags = type;
/* Not a real cc? Don't need to init more */
if (pcc->pcc_flags != PCC_REALCC)
if (type != PCC_REALCC)
goto out;
/* initialize both ucontext's */
@ -178,15 +186,6 @@ puffs_cc_create(struct puffs_usermount *pu, struct puffs_framebuf *pb,
munmap(pcc, stacksize);
return -1;
}
/* return here. it won't actually be "here" due to swapcontext() */
pcc->pcc_uc.uc_link = &pcc->pcc_uc_ret;
/* allocate stack for execution */
st = &pcc->pcc_uc.uc_stack;
st->ss_sp = pcc->pcc_stack = sp;
st->ss_size = stacksize;
st->ss_flags = 0;
#ifdef PUFFS_WITH_THREADS
{
@ -197,6 +196,24 @@ puffs_cc_create(struct puffs_usermount *pu, struct puffs_framebuf *pb,
}
#endif
finalize:
assert(pcc->pcc_pu == pu);
pcc->pcc_pb = pb;
pcc->pcc_flags = type;
/* return here. it won't actually be "here" due to swapcontext() */
pcc->pcc_uc.uc_link = &pcc->pcc_uc_ret;
/* setup stack
*
* XXX: I guess this should theoretically be preserved by
* swapcontext(). However, it gets lost. So reinit it.
*/
st = &pcc->pcc_uc.uc_stack;
st->ss_sp = pcc;
st->ss_size = stacksize;
st->ss_flags = 0;
/*
* Give us an initial context to jump to.
*
@ -204,8 +221,7 @@ puffs_cc_create(struct puffs_usermount *pu, struct puffs_framebuf *pb,
* being able to pass pointers through makecontext(). kjk says
* that NetBSD code doesn't need to worry about this. uwe says
* it would be like putting a "keep away from children" sign on a
* box of toys. I didn't ask what simon says; he's probably busy
* "fixing" typos in comments.
* box of toys.
*/
makecontext(&pcc->pcc_uc, (void *)puffs_calldispatcher,
1, (uintptr_t)pcc);
@ -230,6 +246,16 @@ puffs_cc_destroy(struct puffs_cc *pcc)
struct puffs_usermount *pu = pcc->pcc_pu;
size_t stacksize = 1<<pu->pu_cc_stackshift;
/* not over limit? stuff away in the store */
if (pu->pu_cc_nstored < PUFFS_CCMAXSTORE) {
pcc->pcc_flags &= ~PCC_DONE;
LIST_INSERT_HEAD(&pu->pu_ccmagazin, pcc, pcc_rope);
pu->pu_cc_nstored++;
return;
}
/* else: just dump it */
#ifdef PUFFS_WITH_THREADS
extern size_t pthread__stacksize;
stacksize = pthread__stacksize;

View File

@ -1,4 +1,4 @@
/* $NetBSD: dispatcher.c,v 1.27 2007/12/16 20:02:57 pooka Exp $ */
/* $NetBSD: dispatcher.c,v 1.28 2008/01/16 21:30:00 pooka Exp $ */
/*
* Copyright (c) 2006, 2007 Antti Kantee. All Rights Reserved.
@ -30,7 +30,7 @@
#include <sys/cdefs.h>
#if !defined(lint)
__RCSID("$NetBSD: dispatcher.c,v 1.27 2007/12/16 20:02:57 pooka Exp $");
__RCSID("$NetBSD: dispatcher.c,v 1.28 2008/01/16 21:30:00 pooka Exp $");
#endif /* !lint */
#include <sys/types.h>
@ -236,7 +236,7 @@ puffs_docc(void *arg)
/* can't do this above due to PCC_BORROWED */
while ((pcc_iter = LIST_FIRST(&pu->pu_ccnukelst)) != NULL) {
LIST_REMOVE(pcc_iter, nlst_entries);
LIST_REMOVE(pcc_iter, pcc_rope);
puffs_cc_destroy(pcc_iter);
}
PU_UNLOCK();
@ -1035,7 +1035,7 @@ processresult(struct puffs_usermount *pu, int how)
case PUFFCALL_IGNORE:
PU_LOCK();
LIST_INSERT_HEAD(&pu->pu_ccnukelst, pcc, nlst_entries);
LIST_INSERT_HEAD(&pu->pu_ccnukelst, pcc, pcc_rope);
PU_UNLOCK();
break;

View File

@ -1,4 +1,4 @@
/* $NetBSD: puffs.c,v 1.87 2008/01/16 00:29:42 pooka Exp $ */
/* $NetBSD: puffs.c,v 1.88 2008/01/16 21:30:00 pooka Exp $ */
/*
* Copyright (c) 2005, 2006, 2007 Antti Kantee. All Rights Reserved.
@ -31,7 +31,7 @@
#include <sys/cdefs.h>
#if !defined(lint)
__RCSID("$NetBSD: puffs.c,v 1.87 2008/01/16 00:29:42 pooka Exp $");
__RCSID("$NetBSD: puffs.c,v 1.88 2008/01/16 21:30:00 pooka Exp $");
#endif /* !lint */
#include <sys/param.h>
@ -210,7 +210,7 @@ puffs_setstacksize(struct puffs_usermount *pu, size_t ss)
if (bonus > 1) {
stackshift++;
fprintf(stderr, "puffs_setstacksize: using next power of two: "
"%zu\n", 1<<stackshift);
"%d\n", 1<<stackshift);
}
pu->pu_cc_stackshift = stackshift;
@ -619,6 +619,7 @@ _puffs_init(int develv, struct puffs_ops *pops, const char *mntfromname,
LIST_INIT(&pu->pu_pnodelst);
LIST_INIT(&pu->pu_ios);
LIST_INIT(&pu->pu_ios_rmlist);
LIST_INIT(&pu->pu_ccmagazin);
LIST_INIT(&pu->pu_ccnukelst);
TAILQ_INIT(&pu->pu_sched);
TAILQ_INIT(&pu->pu_exq);
@ -846,7 +847,7 @@ puffs_mainloop(struct puffs_usermount *pu)
* Schedule continuations.
*/
while ((pcc = TAILQ_FIRST(&pu->pu_sched)) != NULL) {
TAILQ_REMOVE(&pu->pu_sched, pcc, entries);
TAILQ_REMOVE(&pu->pu_sched, pcc, pcc_schedent);
puffs_goto(pcc);
}

View File

@ -1,7 +1,7 @@
/* $NetBSD: puffs_priv.h,v 1.37 2007/12/25 20:38:01 pooka Exp $ */
/* $NetBSD: puffs_priv.h,v 1.38 2008/01/16 21:30:00 pooka Exp $ */
/*
* Copyright (c) 2006 Antti Kantee. All Rights Reserved.
* Copyright (c) 2006, 2007, 2008 Antti Kantee. All Rights Reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@ -108,6 +108,9 @@ struct puffs_usermount {
uint32_t pu_flags;
int pu_cc_stackshift;
#define PUFFS_CCMAXSTORE 32
int pu_cc_nstored;
int pu_kq;
int pu_state;
#define PU_STATEMASK 0xff
@ -121,6 +124,8 @@ struct puffs_usermount {
struct puffs_node *pu_pn_root;
LIST_HEAD(, puffs_node) pu_pnodelst;
LIST_HEAD(, puffs_cc) pu_ccmagazin;
LIST_HEAD(, puffs_cc) pu_ccnukelst;
TAILQ_HEAD(, puffs_cc) pu_sched;
@ -165,15 +170,14 @@ struct puffs_cc {
ucontext_t pcc_uc; /* "continue" */
ucontext_t pcc_uc_ret; /* "yield" */
void *pcc_stack;
pid_t pcc_pid;
lwpid_t pcc_lid;
int pcc_flags;
TAILQ_ENTRY(puffs_cc) entries;
LIST_ENTRY(puffs_cc) nlst_entries;
TAILQ_ENTRY(puffs_cc) pcc_schedent;
LIST_ENTRY(puffs_cc) pcc_rope;
};
#define PCC_FAKECC 0x01
#define PCC_REALCC 0x02