diff options
| author | Miquel Sabaté Solà <mikisabate@gmail.com> | 2024-12-03 14:34:43 +0100 |
|---|---|---|
| committer | Miquel Sabaté Solà <mikisabate@gmail.com> | 2024-12-03 14:34:43 +0100 |
| commit | 2eead36f97faf5bdad1abd60a220c0af72a5526c (patch) | |
| tree | b3a058db55deaffc9555d4f2955a89ae7da40bea /kernel/main.c | |
| parent | 95c4b00e90e24d3bcb5d3b6e56f0e29b725ba9ce (diff) | |
| download | fbos-2eead36f97faf5bdad1abd60a220c0af72a5526c.tar.gz fbos-2eead36f97faf5bdad1abd60a220c0af72a5526c.zip | |
Run a hart lottery on SMP
On systems with SMP multiple harts will try to run the kernel, and they
will appear at random. But in this kernel, in order to keep things
simple, we want to make sure that *only one* hart is running the show,
as it greatly simplifies things on these kinds of systems.
The solution is similar to what Linux does, which is to allow the first
hart to initialize things, but then (and different to what Linux does),
it will infinitely stall all the other harts that arrive at a random
later point in time.
In order to make this more apparent, I have also added a print message
showing which hart is being used to run the whole thing.
Signed-off-by: Miquel Sabaté Solà <mikisabate@gmail.com>
Diffstat (limited to 'kernel/main.c')
| -rw-r--r-- | kernel/main.c | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/kernel/main.c b/kernel/main.c index a2e4d13..822d638 100644 --- a/kernel/main.c +++ b/kernel/main.c @@ -5,6 +5,12 @@ #include <fbos/string.h> #include <fbos/dt.h> +/* + * Data related to harts and set by kernel/head.S. Defined in fbos/init.h. + */ +atomic32_t hart_lottery __section(".sdata"); +uint32_t hart_id; + // Stack to be used by our processes, which is initialized in head.S. // "Blasphemy!" I hear you say. "How dare you use the same stack for kernel and // user space?" It's not like this is some sort of utopian system in which @@ -52,6 +58,11 @@ __noreturn __kernel void start_kernel(void *dtb) write("\n", 1); } + // And print the hart ID where this is being run. + printk("Running on Hart ID: "); + print_digit(hart_id); + write("\n", 1); + // At this point everything has already been handled: setup the interrupt // vector and enable the timer to start ticking and scheduling the three // tasks at hand. |
