1
0
mirror of https://github.com/rcore-os/rCore.git synced 2024-11-22 16:16:16 +04:00

Allow page fault handler to bypass process lock and fix thread pool wakeup for exited process

This commit is contained in:
Jiajie Chen 2019-03-23 23:50:30 +08:00
parent 9f03bfc849
commit 0edfc07939
12 changed files with 28 additions and 16 deletions

View File

@ -190,7 +190,14 @@ impl ThreadPool {
}
pub fn wakeup(&self, tid: Tid) {
self.set_status(tid, Status::Ready);
let mut proc_lock = self.threads[tid].lock();
if let Some(mut proc) = proc_lock.as_mut() {
trace!("thread {} {:?} -> {:?}", tid, proc.status, status);
if let Status::Sleeping = proc.status {
proc.status = Status::Ready;
self.scheduler.push(tid);
}
}
}
pub fn exit(&self, tid: Tid, code: ExitCode) {

View File

@ -1,5 +1,4 @@
use once::*;
use crate::arch::interrupt::{consts, enable_irq};
pub mod vga;
pub mod serial;

View File

@ -1,6 +1,5 @@
//! Driver for x86 CMOS RTC clock
use crate::arch::interrupt;
use log::*;
use x86_64::instructions::port::Port;
const CMOS_ADDR: u16 = 0x70;

View File

@ -11,19 +11,16 @@ use rcore_memory::paging::PageTable;
use rcore_memory::PAGE_SIZE;
use smoltcp::iface::*;
use smoltcp::phy::{self, Checksum, DeviceCapabilities};
use smoltcp::socket::*;
use smoltcp::time::Instant;
use smoltcp::wire::EthernetAddress;
use smoltcp::wire::*;
use smoltcp::Result;
use volatile::Volatile;
use crate::memory::active_table;
use crate::net::SOCKETS;
use crate::sync::FlagsGuard;
use crate::sync::SpinNoIrqLock as Mutex;
use crate::sync::{MutexGuard, SpinNoIrq};
use crate::HEAP_ALLOCATOR;
use super::super::{provider::Provider, DeviceType, Driver, DRIVERS, NET_DRIVERS, SOCKET_ACTIVITY};

View File

@ -12,7 +12,6 @@ use log::*;
use rcore_memory::paging::PageTable;
use rcore_memory::PAGE_SIZE;
use smoltcp::phy::{self, DeviceCapabilities};
use smoltcp::socket::SocketSet;
use smoltcp::time::Instant;
use smoltcp::wire::{EthernetAddress, Ipv4Address};
use smoltcp::Result;
@ -20,7 +19,6 @@ use volatile::{ReadOnly, Volatile};
use crate::memory::active_table;
use crate::sync::SpinNoIrqLock as Mutex;
use crate::sync::{MutexGuard, SpinNoIrq};
use crate::HEAP_ALLOCATOR;
use super::super::bus::virtio_mmio::*;

View File

@ -4,7 +4,7 @@ use crate::consts::MEMORY_OFFSET;
use super::HEAP_ALLOCATOR;
use rcore_memory::*;
pub use rcore_memory::memory_set::{MemoryArea, MemoryAttr, handler::*};
use crate::process::{process};
use crate::process::process_unsafe;
use crate::sync::SpinNoIrqLock;
use lazy_static::*;
use log::*;
@ -102,7 +102,11 @@ impl Drop for KernelStack {
#[cfg(not(feature = "no_mmu"))]
pub fn handle_page_fault(addr: usize) -> bool {
debug!("page fault @ {:#x}", addr);
process().vm.handle_page_fault(addr)
// This is safe as long as page fault never happens in page fault handler
unsafe {
process_unsafe().vm.handle_page_fault(addr)
}
}
pub fn init_heap() {

View File

@ -1,9 +1,6 @@
use alloc::sync::Arc;
use core::fmt;
use crate::arch::rand;
use crate::drivers::{NET_DRIVERS, SOCKET_ACTIVITY};
use crate::process::structs::Process;
use crate::sync::SpinNoIrqLock as Mutex;
use crate::syscall::*;

View File

@ -1,4 +1,3 @@
use crate::drivers::Driver;
use crate::drivers::NET_DRIVERS;
use crate::net::SOCKETS;
use crate::thread;

View File

@ -32,6 +32,14 @@ pub fn process() -> MutexGuard<'static, Process> {
current_thread().proc.lock()
}
/// Get current process, ignoring its lock
/// Only use this when necessary
pub unsafe fn process_unsafe() -> MutexGuard<'static, Process> {
let thread = current_thread();
thread.proc.force_unlock();
thread.proc.lock()
}
/// Get current thread
///
/// FIXME: It's obviously unsafe to get &mut !

View File

@ -6,7 +6,6 @@ use spin::{Mutex, RwLock};
use xmas_elf::{ElfFile, header, program::{Flags, Type}};
use rcore_memory::PAGE_SIZE;
use rcore_thread::Tid;
use rcore_fs::vfs::FileType;
use core::str;
use crate::arch::interrupt::{Context, TrapFrame};

View File

@ -66,7 +66,8 @@ pub fn sys_mmap(
let file = proc.get_file(fd)?;
let read_len = file.read_at(offset, data)?;
if read_len != data.len() {
data[read_len..].iter_mut().map(|x| *x = 0);
// use count() to consume the iterator
data[read_len..].iter_mut().map(|x| *x = 0).count();
}
return Ok(addr);
}

View File

@ -184,6 +184,10 @@ pub fn syscall(id: usize, args: [usize; 6], tf: &mut TrapFrame) -> isize {
warn!("mount is unimplemented");
Err(SysError::EACCES)
}
SYS_UMOUNT2 => {
warn!("umount2 is unimplemented");
Err(SysError::EACCES)
}
SYS_REBOOT => sys_reboot(args[0] as u32, args[1] as u32, args[2] as u32, args[3] as *const u8),
SYS_GETTID => sys_gettid(),
SYS_FUTEX => sys_futex(args[0], args[1] as u32, args[2] as i32, args[3] as *const TimeSpec),