summaryrefslogtreecommitdiff
path: root/arch/x86
diff options
context:
space:
mode:
authorRichard Braun <rbraun@sceen.net>2017-09-05 20:34:47 +0200
committerRichard Braun <rbraun@sceen.net>2017-09-05 20:43:59 +0200
commit5b0abe6834fe3ab57dec2de7277452f2ebed4b76 (patch)
treedff89a6daaa5569431c0e1b6cee34dcb04fe153b /arch/x86
parente217d5566ac8c5ffef9924a56a8d3e4cae9d47f5 (diff)
x86/{pmap,tcb}: don't use tsd for the update oplist
Diffstat (limited to 'arch/x86')
-rw-r--r--arch/x86/machine/pmap.c35
-rw-r--r--arch/x86/machine/pmap.h5
-rw-r--r--arch/x86/machine/tcb.c10
-rw-r--r--arch/x86/machine/tcb.h27
4 files changed, 58 insertions, 19 deletions
diff --git a/arch/x86/machine/pmap.c b/arch/x86/machine/pmap.c
index 7ab70bf..f8c6d03 100644
--- a/arch/x86/machine/pmap.c
+++ b/arch/x86/machine/pmap.c
@@ -42,6 +42,7 @@
#include <machine/lapic.h>
#include <machine/page.h>
#include <machine/pmap.h>
+#include <machine/tcb.h>
#include <machine/trap.h>
#include <machine/types.h>
#include <vm/vm_kmem.h>
@@ -191,8 +192,6 @@ struct pmap_update_oplist {
struct pmap_update_op ops[PMAP_UPDATE_MAX_OPS];
};
-static unsigned int pmap_oplist_tsd_key __read_mostly;
-
/*
* Statically allocated data for the main booter thread.
*/
@@ -676,11 +675,8 @@ pmap_update_oplist_create(struct pmap_update_oplist **oplistp)
}
static void
-pmap_update_oplist_destroy(void *arg)
+pmap_update_oplist_destroy(struct pmap_update_oplist *oplist)
{
- struct pmap_update_oplist *oplist;
-
- oplist = arg;
kmem_cache_free(&pmap_update_oplist_cache, oplist);
}
@@ -689,7 +685,7 @@ pmap_update_oplist_get(void)
{
struct pmap_update_oplist *oplist;
- oplist = thread_get_specific(pmap_oplist_tsd_key);
+ oplist = tcb_get_pmap_update_oplist(tcb_current());
assert(oplist != NULL);
return oplist;
}
@@ -855,8 +851,7 @@ pmap_bootstrap(void)
pmap_syncer_init(cpu_local_ptr(pmap_syncer), 0);
pmap_update_oplist_ctor(&pmap_booter_oplist);
- thread_key_create(&pmap_oplist_tsd_key, pmap_update_oplist_destroy);
- thread_set_specific(pmap_oplist_tsd_key, &pmap_booter_oplist);
+ tcb_set_pmap_update_oplist(tcb_current(), &pmap_booter_oplist);
cpumap_zero(&pmap_booter_cpumap);
cpumap_set(&pmap_booter_cpumap, 0);
@@ -1035,6 +1030,7 @@ pmap_mp_setup(void)
struct thread_attr attr;
struct pmap_syncer *syncer;
struct cpumap *cpumap;
+ struct tcb *tcb;
unsigned int cpu;
int error;
@@ -1064,8 +1060,9 @@ pmap_mp_setup(void)
panic("pmap: unable to create syncer thread");
}
- oplist = thread_tsd_get(syncer->thread, pmap_oplist_tsd_key);
- thread_tsd_set(syncer->thread, pmap_oplist_tsd_key, NULL);
+ tcb = thread_get_tcb(syncer->thread);
+ oplist = tcb_get_pmap_update_oplist(tcb);
+ tcb_set_pmap_update_oplist(tcb, NULL);
kmem_cache_free(&pmap_update_oplist_cache, oplist);
}
@@ -1079,7 +1076,7 @@ pmap_mp_setup(void)
}
int
-pmap_thread_init(struct thread *thread)
+pmap_thread_build(struct thread *thread)
{
struct pmap_update_oplist *oplist;
int error;
@@ -1090,10 +1087,22 @@ pmap_thread_init(struct thread *thread)
return error;
}
- thread_tsd_set(thread, pmap_oplist_tsd_key, oplist);
+ tcb_set_pmap_update_oplist(thread_get_tcb(thread), oplist);
return 0;
}
+void
+pmap_thread_cleanup(struct thread *thread)
+{
+ struct pmap_update_oplist *oplist;
+
+ oplist = tcb_get_pmap_update_oplist(thread_get_tcb(thread));
+
+ if (oplist) {
+ pmap_update_oplist_destroy(oplist);
+ }
+}
+
int
pmap_kextract(uintptr_t va, phys_addr_t *pap)
{
diff --git a/arch/x86/machine/pmap.h b/arch/x86/machine/pmap.h
index 114dcda..8ef28c7 100644
--- a/arch/x86/machine/pmap.h
+++ b/arch/x86/machine/pmap.h
@@ -221,9 +221,10 @@ void pmap_ap_setup(void);
void pmap_mp_setup(void);
/*
- * Initialize pmap thread-specific data for the given thread.
+ * Build/clean up pmap thread-local data for the given thread.
*/
-int pmap_thread_init(struct thread *thread);
+int pmap_thread_build(struct thread *thread);
+void pmap_thread_cleanup(struct thread *thread);
/*
* Extract a mapping from the kernel map.
diff --git a/arch/x86/machine/tcb.c b/arch/x86/machine/tcb.c
index b54945c..6978811 100644
--- a/arch/x86/machine/tcb.c
+++ b/arch/x86/machine/tcb.c
@@ -74,11 +74,11 @@ tcb_stack_forge(struct tcb *tcb, void (*fn)(void *), void *arg)
#endif /* __LP64__ */
int
-tcb_init(struct tcb *tcb, void *stack, void (*fn)(void *), void *arg)
+tcb_build(struct tcb *tcb, void *stack, void (*fn)(void *), void *arg)
{
int error;
- error = pmap_thread_init(thread_from_tcb(tcb));
+ error = pmap_thread_build(thread_from_tcb(tcb));
if (error) {
return error;
@@ -90,6 +90,12 @@ tcb_init(struct tcb *tcb, void *stack, void (*fn)(void *), void *arg)
return 0;
}
+void
+tcb_cleanup(struct tcb *tcb)
+{
+ pmap_thread_cleanup(thread_from_tcb(tcb));
+}
+
void __init
tcb_load(struct tcb *tcb)
{
diff --git a/arch/x86/machine/tcb.h b/arch/x86/machine/tcb.h
index 9107f7c..004cf92 100644
--- a/arch/x86/machine/tcb.h
+++ b/arch/x86/machine/tcb.h
@@ -35,22 +35,33 @@
#define TCB_STACK_SIZE PAGE_SIZE
/*
+ * Forward declaration.
+ */
+struct pmap_update_oplist;
+
+/*
* Thread control block.
*/
struct tcb {
uintptr_t bp;
uintptr_t sp;
+ struct pmap_update_oplist *oplist;
};
/*
- * Initialize a TCB.
+ * Build a TCB.
*
* Prepare the given stack for execution. The context is defined so that it
* will call thread_main(fn, arg) with interrupts disabled when loaded.
*
* In addition, initialize any thread-local machine-specific data.
*/
-int tcb_init(struct tcb *tcb, void *stack, void (*fn)(void *), void *arg);
+int tcb_build(struct tcb *tcb, void *stack, void (*fn)(void *), void *arg);
+
+/*
+ * Release all resources held by a TCB.
+ */
+void tcb_cleanup(struct tcb *tcb);
static inline struct tcb *
tcb_current(void)
@@ -66,6 +77,18 @@ tcb_set_current(struct tcb *tcb)
cpu_local_assign(tcb_current_ptr, tcb);
}
+static inline void
+tcb_set_pmap_update_oplist(struct tcb *tcb, struct pmap_update_oplist *oplist)
+{
+ tcb->oplist = oplist;
+}
+
+static inline struct pmap_update_oplist *
+tcb_get_pmap_update_oplist(struct tcb *tcb)
+{
+ return tcb->oplist;
+}
+
/*
* Load a TCB.
*