Skip to content

Commit

Permalink
Replace irqsave with direct call to hermit-sync
Browse files Browse the repository at this point in the history
  • Loading branch information
mkroening committed Nov 20, 2022
1 parent c44f921 commit 035844b
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 28 deletions.
8 changes: 4 additions & 4 deletions src/arch/x86_64/kernel/apic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use core::{cmp, fmt, mem, u32};
use arch::x86_64::kernel::percore::*;
use arch::x86_64::kernel::{idt, irq, processor};
use crossbeam_utils::CachePadded;
use hermit_sync::without_interrupts;
#[cfg(feature = "smp")]
use x86::controlregs::*;
use x86::msr::*;
Expand All @@ -23,7 +24,6 @@ use crate::arch::x86_64::mm::paging::{
BasePageSize, PageSize, PageTableEntryFlags, PageTableEntryFlagsExt,
};
use crate::arch::x86_64::mm::{paging, virtualmem, PhysAddr, VirtAddr};
use crate::collections::irqsave;
use crate::config::*;
use crate::scheduler::CoreId;
use crate::{arch, env, mm, scheduler};
Expand Down Expand Up @@ -719,7 +719,7 @@ fn __set_oneshot_timer(wakeup_time: Option<u64>) {
}

pub fn set_oneshot_timer(wakeup_time: Option<u64>) {
irqsave(|| {
without_interrupts(|| {
__set_oneshot_timer(wakeup_time);
});
}
Expand Down Expand Up @@ -889,7 +889,7 @@ pub fn ipi_tlb_flush() {
}

// Send an IPI with our TLB Flush interrupt number to all other CPUs.
irqsave(|| {
without_interrupts(|| {
for (core_id_to_interrupt, &apic_id) in apic_ids.iter().enumerate() {
if core_id_to_interrupt != core_id.try_into().unwrap() {
let destination = u64::from(apic_id) << 32;
Expand All @@ -910,7 +910,7 @@ pub fn ipi_tlb_flush() {
pub fn wakeup_core(core_id_to_wakeup: CoreId) {
#[cfg(feature = "smp")]
if core_id_to_wakeup != core_id() {
irqsave(|| {
without_interrupts(|| {
let apic_ids = unsafe { CPU_LOCAL_APIC_IDS.as_ref().unwrap() };
let local_apic_id = apic_ids[core_id_to_wakeup as usize];
let destination = u64::from(local_apic_id) << 32;
Expand Down
5 changes: 3 additions & 2 deletions src/arch/x86_64/kernel/mmio.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
use alloc::vec::Vec;
use core::str;

use hermit_sync::without_interrupts;

use crate::arch::x86_64::mm::paging::{
BasePageSize, PageSize, PageTableEntryFlags, PageTableEntryFlagsExt,
};
use crate::arch::x86_64::mm::{paging, PhysAddr};
use crate::collections::irqsave;
use crate::drivers::net::virtio_net::VirtioNetDriver;
use crate::drivers::net::NetworkInterface;
use crate::drivers::virtio::transport::mmio as mmio_virtio;
Expand Down Expand Up @@ -127,7 +128,7 @@ pub fn get_network_driver() -> Option<&'static SpinlockIrqSave<dyn NetworkInterf

pub fn init_drivers() {
// virtio: MMIO Device Discovery
irqsave(|| {
without_interrupts(|| {
if let Ok(mmio) = detect_network() {
warn!(
"Found MMIO device, but we guess the interrupt number {}!",
Expand Down
4 changes: 2 additions & 2 deletions src/arch/x86_64/kernel/pci.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use alloc::vec::Vec;
use core::{fmt, u32, u8};

use hermit_sync::without_interrupts;
use num_derive::{FromPrimitive, ToPrimitive};
use x86::io::*;

use crate::arch::x86_64::mm::{PhysAddr, VirtAddr};
use crate::collections::irqsave;
use crate::drivers::net::rtl8139::{self, RTL8139Driver};
use crate::drivers::net::virtio_net::VirtioNetDriver;
use crate::drivers::net::NetworkInterface;
Expand Down Expand Up @@ -477,7 +477,7 @@ pub fn init_drivers() {
let mut nic_available = false;

// virtio: 4.1.2 PCI Device Discovery
irqsave(|| {
without_interrupts(|| {
for adapter in unsafe {
PCI_ADAPTERS
.iter()
Expand Down
4 changes: 2 additions & 2 deletions src/arch/x86_64/kernel/systemtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ use core::hint::spin_loop;
use core::num::NonZeroU64;

use hermit_entry::boot_info::PlatformInfo;
use hermit_sync::without_interrupts;
use time::OffsetDateTime;
use x86::io::*;

use crate::arch::x86_64::kernel::{boot_info, processor};
use crate::collections::irqsave;

const CMOS_COMMAND_PORT: u16 = 0x70;
const CMOS_DATA_PORT: u16 = 0x71;
Expand Down Expand Up @@ -182,7 +182,7 @@ pub fn init() {
PlatformInfo::Multiboot { .. } => {
// Get the current time in microseconds since the epoch (1970-01-01) from the x86 RTC.
// Subtract the timer ticks to get the actual time when HermitCore-rs was booted.
let current_time = irqsave(|| Rtc::new().get_microseconds_since_epoch());
let current_time = without_interrupts(|| Rtc::new().get_microseconds_since_epoch());
let boot_time = current_time - processor::get_timer_ticks();
OffsetDateTime::from_unix_timestamp_nanos(boot_time as i128 * 1000).unwrap()
}
Expand Down
1 change: 0 additions & 1 deletion src/collections/mod.rs

This file was deleted.

1 change: 0 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ mod macros;
mod logging;

mod arch;
mod collections;
mod config;
mod console;
mod drivers;
Expand Down
32 changes: 16 additions & 16 deletions src/scheduler/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ use core::cell::RefCell;
use core::sync::atomic::{AtomicU32, Ordering};

use crossbeam_utils::Backoff;
use hermit_sync::without_interrupts;

use crate::arch;
use crate::arch::irq;
use crate::arch::percore::*;
use crate::arch::switch::{switch_to_fpu_owner, switch_to_task};
use crate::collections::irqsave;
use crate::kernel::scheduler::TaskStacks;
use crate::scheduler::task::*;
use crate::synch::spinlock::*;
Expand Down Expand Up @@ -159,7 +159,7 @@ impl PerCoreScheduler {
NO_TASKS.fetch_sub(1, Ordering::SeqCst);
};

irqsave(closure);
without_interrupts(closure);

self.scheduler();

Expand Down Expand Up @@ -234,7 +234,7 @@ impl PerCoreScheduler {

#[cfg(feature = "newlib")]
pub fn clone(&self, func: extern "C" fn(usize), arg: usize) -> TaskId {
irqsave(|| self.clone_impl(func, arg))
without_interrupts(|| self.clone_impl(func, arg))
}

/// Returns `true` if a reschedule is required
Expand All @@ -246,18 +246,18 @@ impl PerCoreScheduler {

#[inline]
pub fn handle_waiting_tasks(&mut self) {
irqsave(|| self.blocked_tasks.handle_waiting_tasks());
without_interrupts(|| self.blocked_tasks.handle_waiting_tasks());
}

#[cfg(not(feature = "smp"))]
pub fn custom_wakeup(&mut self, task: TaskHandle) {
irqsave(|| self.blocked_tasks.custom_wakeup(task));
without_interrupts(|| self.blocked_tasks.custom_wakeup(task));
}

#[cfg(feature = "smp")]
pub fn custom_wakeup(&mut self, task: TaskHandle) {
if task.get_core_id() == self.core_id {
irqsave(|| self.blocked_tasks.custom_wakeup(task));
without_interrupts(|| self.blocked_tasks.custom_wakeup(task));
} else {
get_scheduler(task.get_core_id())
.input
Expand All @@ -271,7 +271,7 @@ impl PerCoreScheduler {

#[inline]
pub fn block_current_task(&mut self, wakeup_time: Option<u64>) {
irqsave(|| {
without_interrupts(|| {
self.blocked_tasks
.add(self.current_task.clone(), wakeup_time)
});
Expand All @@ -280,12 +280,12 @@ impl PerCoreScheduler {
#[cfg(feature = "tcp")]
#[inline]
pub fn add_network_timer(&mut self, wakeup_time: u64) {
irqsave(|| self.blocked_tasks.add_network_timer(wakeup_time));
without_interrupts(|| self.blocked_tasks.add_network_timer(wakeup_time));
}

#[inline]
pub fn get_current_task_handle(&self) -> TaskHandle {
irqsave(|| {
without_interrupts(|| {
let current_task_borrowed = self.current_task.borrow();

TaskHandle::new(
Expand All @@ -300,23 +300,23 @@ impl PerCoreScheduler {
#[cfg(feature = "newlib")]
#[inline]
pub fn set_lwip_errno(&self, errno: i32) {
irqsave(|| self.current_task.borrow_mut().lwip_errno = errno);
without_interrupts(|| self.current_task.borrow_mut().lwip_errno = errno);
}

#[cfg(feature = "newlib")]
#[inline]
pub fn get_lwip_errno(&self) -> i32 {
irqsave(|| self.current_task.borrow().lwip_errno)
without_interrupts(|| self.current_task.borrow().lwip_errno)
}

#[inline]
pub fn get_current_task_id(&self) -> TaskId {
irqsave(|| self.current_task.borrow().id)
without_interrupts(|| self.current_task.borrow().id)
}

#[inline]
pub fn get_current_task_prio(&self) -> Priority {
irqsave(|| self.current_task.borrow().prio)
without_interrupts(|| self.current_task.borrow().prio)
}

#[cfg(target_arch = "x86_64")]
Expand All @@ -336,7 +336,7 @@ impl PerCoreScheduler {
}

pub fn set_current_task_priority(&mut self, prio: Priority) {
irqsave(|| {
without_interrupts(|| {
trace!("Change priority of the current task");
self.current_task.borrow_mut().prio = prio;
});
Expand All @@ -345,7 +345,7 @@ impl PerCoreScheduler {
pub fn set_priority(&mut self, id: TaskId, prio: Priority) -> Result<(), ()> {
trace!("Change priority of task {} to priority {}", id, prio);

irqsave(|| {
without_interrupts(|| {
let task = get_task_handle(id).ok_or(())?;
#[cfg(feature = "smp")]
let other_core = task.get_core_id() != self.core_id;
Expand Down Expand Up @@ -420,7 +420,7 @@ impl PerCoreScheduler {
/// Triggers the scheduler to reschedule the tasks.
/// Interrupt flag will be cleared during the reschedule
pub fn reschedule(&mut self) {
irqsave(|| self.scheduler());
without_interrupts(|| self.scheduler());
}

/// Only the idle task should call this function.
Expand Down

0 comments on commit 035844b

Please sign in to comment.