Skip to content

Commit

Permalink
extending scheduler tests
Browse files Browse the repository at this point in the history
  • Loading branch information
stlankes committed Sep 3, 2023
1 parent cd1d8e1 commit 2538a6c
Show file tree
Hide file tree
Showing 5 changed files with 362 additions and 304 deletions.
3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ exclude = [
crate-type = ["staticlib", "lib"] # "lib" required for integration tests
name = "hermit"

[build]
profiler = true

[[test]]
name = "basic_math"
harness = true
Expand Down
6 changes: 6 additions & 0 deletions src/arch/x86_64/kernel/apic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -645,12 +645,18 @@ fn __set_oneshot_timer(wakeup_time: Option<u64>) {
}
}

#[cfg(target_os = "none")]
pub fn set_oneshot_timer(wakeup_time: Option<u64>) {
without_interrupts(|| {
__set_oneshot_timer(wakeup_time);
});
}

#[cfg(not(target_os = "none"))]
pub fn set_oneshot_timer(wakeup_time: Option<u64>) {
println!("Mocking : set_oneshot_timer()");
}

pub fn init_x2apic() {
if processor::supports_x2apic() {
debug!("Enable x2APIC support");
Expand Down
7 changes: 7 additions & 0 deletions src/arch/x86_64/kernel/processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1007,12 +1007,19 @@ pub fn shutdown() -> ! {
}
}

#[cfg(target_os = "none")]
pub fn get_timer_ticks() -> u64 {
// We simulate a timer with a 1 microsecond resolution by taking the CPU timestamp
// and dividing it by the CPU frequency in MHz.
get_timestamp() / u64::from(get_frequency())
}

#[cfg(not(target_os = "none"))]
pub fn get_timer_ticks() -> u64 {
println!("Mocking get_timer_ticks()");
10
}

pub fn get_frequency() -> u16 {
CPU_FREQUENCY.get()
}
Expand Down
19 changes: 9 additions & 10 deletions src/arch/x86_64/kernel/scheduler.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
//! Architecture dependent interface to initialize a task
use alloc::boxed::Box;
use core::arch::asm;
use core::{mem, ptr, slice};

use align_address::Align;
Expand Down Expand Up @@ -59,18 +58,18 @@ struct State {

pub struct BootStack {
/// stack for kernel tasks
stack: VirtAddr,
pub stack: VirtAddr,
/// stack to handle interrupts
ist1: VirtAddr,
pub ist1: VirtAddr,
}

pub struct CommonStack {
/// start address of allocated virtual memory region
virt_addr: VirtAddr,
pub virt_addr: VirtAddr,
/// start address of allocated virtual memory region
phys_addr: PhysAddr,
pub phys_addr: PhysAddr,
/// total size of all stacks
total_size: usize,
pub total_size: usize,
}

pub enum TaskStacks {
Expand Down Expand Up @@ -202,7 +201,7 @@ impl TaskStacks {
IST_SIZE
}
}

#[cfg(target_os = "none")]
impl Drop for TaskStacks {
fn drop(&mut self) {
// we should never deallocate a boot stack
Expand Down Expand Up @@ -363,10 +362,10 @@ impl TaskFrame for Task {
}

extern "x86-interrupt" fn timer_handler(_stack_frame: interrupts::ExceptionStackFrame) {
increment_irq_counter(apic::TIMER_INTERRUPT_NUMBER);
increment_irq_counter(apic::TIMER_INTERRUPT_NUMBER.into());
core_scheduler().handle_waiting_tasks();
apic::eoi();
core_scheduler().reschedule();
core_scheduler().scheduler();
}

pub fn install_timer_handler() {
Expand All @@ -376,5 +375,5 @@ pub fn install_timer_handler() {
.set_handler_fn(timer_handler)
.set_stack_index(0);
}
interrupts::add_irq_name(apic::TIMER_INTERRUPT_NUMBER - 32, "Timer");
interrupts::add_irq_name((apic::TIMER_INTERRUPT_NUMBER - 32).into(), "Timer");
}
Loading

0 comments on commit 2538a6c

Please sign in to comment.