mirror of
https://github.com/asterinas/asterinas.git
synced 2025-06-26 10:53:25 +00:00
Don't preempt without good reason
This commit is contained in:
committed by
Tate, Hongliang Tian
parent
19b13d88e2
commit
5233827160
@ -93,8 +93,6 @@ pub fn main() {
|
||||
ThreadOptions::new(init_thread)
|
||||
.priority(Priority::new(PriorityRange::new(PriorityRange::MAX))),
|
||||
);
|
||||
// Spawning functions in the bootstrap context will not return.
|
||||
unreachable!()
|
||||
}
|
||||
|
||||
pub fn init() {
|
||||
@ -110,7 +108,7 @@ pub fn init() {
|
||||
process::init();
|
||||
}
|
||||
|
||||
fn ap_init() -> ! {
|
||||
fn ap_init() {
|
||||
fn ap_idle_thread() {
|
||||
let preempt_guard = ostd::task::disable_preempt();
|
||||
let cpu_id = preempt_guard.current_cpu();
|
||||
@ -129,8 +127,6 @@ fn ap_init() -> ! {
|
||||
.cpu_affinity(cpu_id.into())
|
||||
.priority(Priority::new(PriorityRange::new(PriorityRange::MAX))),
|
||||
);
|
||||
// Spawning functions in the bootstrap context will not return.
|
||||
unreachable!()
|
||||
}
|
||||
|
||||
fn init_thread() {
|
||||
|
@ -104,6 +104,9 @@ impl<T: Sync + Send + PreemptSchedInfo + FromTask<U>, U: Sync + Send + CommonSch
|
||||
if still_in_rq && let Err(_) = entity.task.cpu().set_if_is_none(target_cpu) {
|
||||
return None;
|
||||
}
|
||||
|
||||
let new_priority = entity.thread.priority();
|
||||
|
||||
if entity.thread.is_real_time() {
|
||||
rq.real_time_entities.push_back(entity);
|
||||
} else if entity.thread.is_lowest() {
|
||||
@ -112,7 +115,17 @@ impl<T: Sync + Send + PreemptSchedInfo + FromTask<U>, U: Sync + Send + CommonSch
|
||||
rq.normal_entities.push_back(entity);
|
||||
}
|
||||
|
||||
Some(target_cpu)
|
||||
// Preempt the current task, but only if the newly queued task has a strictly higher
|
||||
// priority (i.e., a lower value returned by the `priority` method) than the current task.
|
||||
if rq
|
||||
.current
|
||||
.as_ref()
|
||||
.is_some_and(|current| new_priority < current.thread.priority())
|
||||
{
|
||||
Some(target_cpu)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
fn local_rq_with(&self, f: &mut dyn FnMut(&dyn LocalRunQueue<U>)) {
|
||||
|
Reference in New Issue
Block a user