summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRichard Braun <rbraun@sceen.net>2012-12-11 21:42:09 +0100
committerRichard Braun <rbraun@sceen.net>2012-12-11 21:42:09 +0100
commit13ec72e8ae44308a1340f6f17641bddfe61b072d (patch)
treef865a9e3e91a4ebeea9ec9813b5600d74f8eb25d
parent49e0754e29947dbed6f9cb40a8ef881efaac0e00 (diff)
kern/thread: statically allocate idle thread structures
Preemption control is implemented using a thread-local counter. The global dummy thread structure must be replaced with per-CPU ones, which will be used later for the idle threads.
-rw-r--r--kern/thread.c19
-rw-r--r--kern/thread.h2
2 files changed, 11 insertions, 10 deletions
diff --git a/kern/thread.c b/kern/thread.c
index 236c6145..463c4416 100644
--- a/kern/thread.c
+++ b/kern/thread.c
@@ -31,10 +31,11 @@
struct thread_runq thread_runqs[MAX_CPUS];
/*
- * Statically allocated thread which prevents initialization code from
- * crashing when implicitely using preemption control operations.
+ * Statically allocating the idle thread structures enables their use as
+ * "current" threads during system bootstrap, which prevents preemption
+ * control functions from crashing.
*/
-static struct thread thread_dummy __initdata;
+static struct thread thread_idles[MAX_CPUS] __initdata;
/*
* Caches for allocated threads and their stacks.
@@ -43,9 +44,12 @@ static struct kmem_cache thread_cache;
static struct kmem_cache thread_stack_cache;
static void __init
-thread_runq_init(struct thread_runq *runq)
+thread_runq_init(struct thread_runq *runq, struct thread *idle)
{
- runq->current = &thread_dummy;
+ /* Consider preemption disabled during initialization */
+ idle->flags = 0;
+ idle->preempt = 1;
+ runq->current = idle;
list_init(&runq->threads);
}
@@ -75,11 +79,8 @@ thread_bootstrap(void)
{
size_t i;
- thread_dummy.flags = 0;
- thread_dummy.preempt = 0;
-
for (i = 0; i < ARRAY_SIZE(thread_runqs); i++)
- thread_runq_init(&thread_runqs[i]);
+ thread_runq_init(&thread_runqs[i], &thread_idles[i]);
}
void __init
diff --git a/kern/thread.h b/kern/thread.h
index fe441e01..b7debddc 100644
--- a/kern/thread.h
+++ b/kern/thread.h
@@ -50,7 +50,7 @@ struct thread {
char name[THREAD_NAME_SIZE];
void (*fn)(void *);
void *arg;
-};
+} __aligned(CPU_L1_SIZE);
/*
* Per processor run queue.