Enable softirq mechanism

This commit is contained in:
Chen Chengjun
2024-05-31 12:24:46 +08:00
committed by Tate, Hongliang Tian
parent c02eacd50c
commit 558248a070
9 changed files with 236 additions and 11 deletions

View File

@ -0,0 +1,13 @@
// SPDX-License-Identifier: MPL-2.0
//! Defines the used IDs of software interrupt (softirq) lines.
/// The corresponding softirq line is used to schedule urgent taskless jobs.
pub const TASKLESS_URGENT_SOFTIRQ_ID: u8 = 0;
/// The corresponding softirq line is used to manage timers and handle
/// time-related jobs.
pub const TIMER_SOFTIRQ_ID: u8 = 1;
/// The corresponding softirq line is used to schedule general taskless jobs.
pub const TASKLESS_SOFTIRQ_ID: u8 = 2;

View File

@ -3,17 +3,14 @@
use alloc::sync::Arc;
use core::time::Duration;
use aster_frame::{
arch::timer::{self, Jiffies},
cpu_local,
sync::SpinLock,
CpuLocal,
};
use aster_frame::{arch::timer::Jiffies, cpu_local, sync::SpinLock, CpuLocal};
use aster_time::read_monotonic_time;
use paste::paste;
use spin::Once;
use crate::time::{system_time::START_TIME_AS_DURATION, timer::TimerManager, Clock, SystemTime};
use crate::time::{
self, system_time::START_TIME_AS_DURATION, timer::TimerManager, Clock, SystemTime,
};
/// The Clock that reads the jiffies, and turn the counter into `Duration`.
pub struct JiffiesClock {
@ -220,7 +217,7 @@ macro_rules! define_timer_managers {
let callback = move || {
clock_manager.process_expired_timers();
};
timer::register_callback(callback);
time::softirq::register_callback(callback);
)*
}
}
@ -258,7 +255,7 @@ fn init_jiffies_clock_manager() {
let callback = move || {
jiffies_timer_manager.process_expired_timers();
};
timer::register_callback(callback);
time::softirq::register_callback(callback);
}
fn update_coarse_clock() {
@ -270,7 +267,7 @@ fn update_coarse_clock() {
fn init_coarse_clock() {
let real_time = RealTimeClock::get().read_time();
RealTimeCoarseClock::current_ref().call_once(|| SpinLock::new(real_time));
timer::register_callback(update_coarse_clock);
time::softirq::register_callback(update_coarse_clock);
}
pub(super) fn init() {

View File

@ -12,6 +12,7 @@ use crate::prelude::*;
pub mod clocks;
mod core;
mod softirq;
mod system_time;
pub mod wait;
@ -23,6 +24,7 @@ pub type clock_t = i64;
pub(super) fn init() {
system_time::init();
clocks::init();
softirq::init();
}
#[repr(C)]

View File

@ -0,0 +1,34 @@
// SPDX-License-Identifier: MPL-2.0
use alloc::{boxed::Box, vec::Vec};
use aster_frame::{arch::timer, sync::RwLock, trap::SoftIrqLine};
use crate::softirq_id::TIMER_SOFTIRQ_ID;
static TIMER_SOFTIRQ_CALLBACKS: RwLock<Vec<Box<dyn Fn() + Sync + Send>>> = RwLock::new(Vec::new());
pub(super) fn init() {
SoftIrqLine::get(TIMER_SOFTIRQ_ID).enable(timer_softirq_handler);
timer::register_callback(|| {
SoftIrqLine::get(TIMER_SOFTIRQ_ID).raise();
});
}
/// Registers a function that will be executed during timer softirq.
pub(super) fn register_callback<F>(func: F)
where
F: Fn() + Sync + Send + 'static,
{
TIMER_SOFTIRQ_CALLBACKS
.write_irq_disabled()
.push(Box::new(func));
}
fn timer_softirq_handler() {
let callbacks = TIMER_SOFTIRQ_CALLBACKS.read_irq_disabled();
for callback in callbacks.iter() {
(callback)();
}
}