refactor: unsafe only in adapter + libkos; forbid(unsafe_code) everywhere else; libkos Window (volatile, bounds-checked MMIO/DMA/shared mem), entry!, thread::spawn; MapRegion returns pages; kernel const-built (with_cores/install_platform); newtype addrs
This commit is contained in:
@@ -21,11 +21,23 @@ pub struct MultiCoreScheduler {
|
||||
}
|
||||
|
||||
impl MultiCoreScheduler {
|
||||
pub fn new(num_cores: u8) -> Self {
|
||||
let cores = core::array::from_fn(|i| PerCoreScheduler::new(CoreId::from_raw(i as u8)));
|
||||
pub const fn new(num_cores: u8) -> Self {
|
||||
let mut cores = [const { PerCoreScheduler::new(CoreId::from_raw(0)) }; MAX_CORES];
|
||||
// Each core numbered by its place (a const fn cannot index or map).
|
||||
let mut rest: &mut [PerCoreScheduler] = &mut cores;
|
||||
let mut id = 0u8;
|
||||
while let Some((core, tail)) = rest.split_first_mut() {
|
||||
*core = PerCoreScheduler::new(CoreId::from_raw(id));
|
||||
rest = tail;
|
||||
id += 1;
|
||||
}
|
||||
Self {
|
||||
cores,
|
||||
num_cores: num_cores.min(MAX_CORES as u8),
|
||||
num_cores: if num_cores < MAX_CORES as u8 {
|
||||
num_cores
|
||||
} else {
|
||||
MAX_CORES as u8
|
||||
},
|
||||
placements: [const { None }; MAX_SCHEDULED_THREADS],
|
||||
}
|
||||
}
|
||||
@@ -47,6 +59,12 @@ impl MultiCoreScheduler {
|
||||
self.placements.get(thread.raw() as usize)?.as_ref()
|
||||
}
|
||||
|
||||
/// How many cores to schedule on, once the platform knows; before any
|
||||
/// thread is placed.
|
||||
pub fn set_num_cores(&mut self, num_cores: u8) {
|
||||
self.num_cores = num_cores.min(MAX_CORES as u8);
|
||||
}
|
||||
|
||||
pub fn num_cores(&self) -> u8 {
|
||||
self.num_cores
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user