Skip to content

Commit fd5081a

Browse files
Implement per-CPU variables via CPU-local storage (#917)
* Only supported on x86_64 currently; aarch64 support to come. * x86_64 implementation is based on the GS segment register and the GsBase MSR, as typically used on other OSes. * Tested working, but not yet used anywhere in Theseus. Co-authored-by: Klim Tsoutsman <[email protected]>
1 parent d2ed7ac commit fd5081a

File tree

12 files changed

+561
-1
lines changed

12 files changed

+561
-1
lines changed

Cargo.lock

Lines changed: 37 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

kernel/ap_start/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ scheduler = { path = "../scheduler" }
1616
spawn = { path = "../spawn" }
1717
kernel_config = { path = "../kernel_config" }
1818
cpu = { path = "../cpu" }
19+
per_cpu = { path = "../per_cpu" }
1920
no_drop = { path = "../no_drop" }
2021
early_tls = { path = "../early_tls" }
2122

kernel/ap_start/src/lib.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,11 @@ pub fn kstart_ap(
106106
}
107107

108108
// Now that the Local APIC has been initialized for this CPU, we can initialize the
109-
// task management subsystem and create the idle task for this CPU.
109+
// per-CPU storage, tasking, and create the idle task for this CPU.
110+
111+
#[cfg(target_arch = "x86_64")] // not yet supported on aarch64
112+
per_cpu::init(cpu_id).unwrap();
113+
110114
let bootstrap_task = spawn::init(kernel_mmi_ref.clone(), cpu_id, this_ap_stack).unwrap();
111115
spawn::create_idle_task().unwrap();
112116

kernel/captain/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ spawn = { path = "../spawn" }
2323
stack = { path = "../stack" }
2424
task = { path = "../task" }
2525
cpu = { path = "../cpu" }
26+
per_cpu = { path = "../per_cpu" }
2627

2728
[target.'cfg(target_arch = "x86_64")'.dependencies]
2829
logger_x86_64 = { path = "../logger_x86_64" }

kernel/captain/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,8 @@ pub fn init(
121121

122122
// get BSP's CPU ID
123123
let bsp_id = cpu::bootstrap_cpu().ok_or("captain::init(): couldn't get ID of bootstrap CPU!")?;
124+
#[cfg(target_arch = "x86_64")] // not yet supported on aarch64
125+
per_cpu::init(bsp_id)?;
124126

125127
// Initialize the scheduler and create the initial `Task`,
126128
// which is bootstrapped from this current execution context.

kernel/cpu_local/Cargo.toml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
[package]
2+
authors = ["Kevin Boos <[email protected]>"]
3+
name = "cpu_local"
4+
description = "Support for accessing CPU-local storage via per-CPU variables"
5+
version = "0.1.0"
6+
edition = "2021"
7+
8+
[dependencies]
9+
crossbeam-utils = { version = "0.8.12", default-features = false }
10+
log = "0.4.8"
11+
spin = "0.9.0"
12+
13+
irq_safety = { git = "https://github.com/theseus-os/irq_safety" }
14+
memory = { path = "../memory" }
15+
preemption = { path = "../preemption" }
16+
17+
[target.'cfg(target_arch = "x86_64")'.dependencies]
18+
x86_64 = "0.14.8"

0 commit comments

Comments
 (0)