Skip to content

Commit

Permalink
[WIP] feat(core_local): statically allocate first CoreLocal
Browse files Browse the repository at this point in the history
Signed-off-by: Martin Kröning <[email protected]>
  • Loading branch information
mkroening committed Aug 24, 2023
1 parent 17f766d commit a33b984
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 3 deletions.
12 changes: 12 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ qemu-exit = "3.0"
rand_chacha = { version = "0.3", default-features = false }
shell-words = { version = "1.1", default-features = false }
smallvec = { version = "1", features = ["const_new"] }
take-static = { path = "../../exclusive_cell" }
talc = { version = "2" }
time = { version = "0.3", default-features = false }
zerocopy = "0.6"
Expand Down
24 changes: 21 additions & 3 deletions src/arch/x86_64/kernel/core_local.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,12 @@ impl CoreLocal {

let core_id = CPU_ONLINE.load(Ordering::Relaxed);

let irq_statistics = &*Box::leak(Box::new(IrqStatistics::new()));
IRQ_COUNTERS.lock().insert(core_id, irq_statistics);
let irq_statistics = if core_id == 0 {
static FIRST_IRQ_STATISTICS: IrqStatistics = IrqStatistics::new();
&FIRST_IRQ_STATISTICS
} else {
&*Box::leak(Box::new(IrqStatistics::new()))
};

let this = Self {
this: ptr::null_mut(),
Expand All @@ -49,7 +53,15 @@ impl CoreLocal {
irq_statistics,
async_tasks: RefCell::new(Vec::new()),
};
let this = Box::leak(Box::new(this));
let this = if core_id == 0 {
take_static::take_static! {
static FIRST_CORE_LOCAL: TakeStatic<Option<CoreLocal>> = TakeStatic::new(None);
}
FIRST_CORE_LOCAL.take().unwrap().insert(this)
} else {
this.add_irq_counter();
Box::leak(Box::new(this))
};
this.this = &*this;

GsBase::write(VirtAddr::from_ptr(this));
Expand All @@ -64,6 +76,12 @@ impl CoreLocal {
&*raw
}
}

pub fn add_irq_counter(&self) {
IRQ_COUNTERS
.lock()
.insert(self.core_id, self.irq_statistics);
}
}

pub(crate) fn core_id() -> CoreId {
Expand Down
1 change: 1 addition & 0 deletions src/arch/x86_64/kernel/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@ pub fn boot_processor_init() {

crate::mm::init();
crate::mm::print_information();
CoreLocal::get().add_irq_counter();
env::init();
gdt::add_current_core();
interrupts::load_idt();
Expand Down

0 comments on commit a33b984

Please sign in to comment.