Make all perCPU mappings available in all contexts - this will allow APs to pick up threads

This commit is contained in:
Jeremy Soller 2016-10-23 09:13:12 -06:00
parent 790c32b0bc
commit a715e157d4
5 changed files with 29 additions and 45 deletions

View file

@ -133,6 +133,13 @@ pub fn cpu_id() -> usize {
CPU_ID.load(Ordering::Relaxed)
}
static CPU_COUNT : AtomicUsize = ATOMIC_USIZE_INIT;
#[inline(always)]
pub fn cpu_count() -> usize {
CPU_COUNT.load(Ordering::Relaxed)
}
pub extern fn userspace_init() {
assert_eq!(syscall::chdir(b"initfs:bin"), Ok(0));
@ -146,13 +153,14 @@ pub extern fn userspace_init() {
}
#[no_mangle]
pub extern fn kmain() {
pub extern fn kmain(cpus: usize) {
CPU_ID.store(0, Ordering::SeqCst);
CPU_COUNT.store(cpus, Ordering::SeqCst);
context::init();
let pid = syscall::getpid();
println!("BSP: {:?}", pid);
println!("BSP: {:?} {}", pid, cpus);
match context::contexts_mut().spawn(userspace_init) {
Ok(context_lock) => {

View file

@ -346,7 +346,7 @@ pub fn clone(flags: usize, stack_base: usize) -> Result<usize> {
context.grants = grants;
} else {
// Copy percpu mapping
{
for cpu_id in 0..::cpu_count() {
extern {
/// The starting byte of the thread data segment
static mut __tdata_start: u8;
@ -356,7 +356,7 @@ pub fn clone(flags: usize, stack_base: usize) -> Result<usize> {
let size = unsafe { & __tbss_end as *const _ as usize - & __tdata_start as *const _ as usize };
let start = arch::KERNEL_PERCPU_OFFSET + arch::KERNEL_PERCPU_SIZE * ::cpu_id();
let start = arch::KERNEL_PERCPU_OFFSET + arch::KERNEL_PERCPU_SIZE * cpu_id;
let end = start + size;
let start_page = Page::containing_address(VirtualAddress::new(start));