Skip to content

Commit

Permalink
Add lock in condvar in wait_queue.rs
Browse files Browse the repository at this point in the history
  • Loading branch information
hky1999 committed Sep 10, 2024
1 parent 7d49310 commit b96c02c
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 281 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ on: [push, pull_request]
env:
qemu-version: 8.2.0
rust-toolchain: nightly-2024-05-02
arceos-apps: '68054e8'
arceos-apps: 'b25b7e2'

jobs:
unit-test:
Expand Down
10 changes: 0 additions & 10 deletions modules/axtask/src/run_queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -268,9 +268,6 @@ impl AxRunQueue {
where
F: FnOnce(AxTaskRef),
{
// We do not own an `SpinNoIrq` lock here, so we need to disable IRQ and preempt manually.
let _kernel_guard = kernel_guard::NoPreemptIrqSave::new();

let curr = crate::current();
debug!("task block: {}", curr.id_name());
assert!(curr.is_running());
Expand Down Expand Up @@ -482,13 +479,6 @@ pub(crate) fn init_secondary() {
i.init_once(idle_task.clone());
});
unsafe { CurrentTask::init_current(idle_task) }

info!(
"Initialize secondary RUN_QUEUES {}/{}",
cpu_id,
axconfig::SMP
);

RUN_QUEUE.with_current(|rq| {
rq.init_once(AxRunQueue::new(cpu_id));
});
Expand Down
17 changes: 12 additions & 5 deletions modules/axtask/src/wait_queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,11 @@ impl WaitQueue {
/// Blocks the current task and put it into the wait queue, until other task
/// notifies it.
pub fn wait(&self) {
debug!("task wait: {}", crate::current().id_name());
let mut wq_locked = self.queue.lock();
current_run_queue().block_current(|task| {
task.set_in_wait_queue(true);
self.queue.lock().push_back(task)
wq_locked.push_back(task);
drop(wq_locked)
});
self.cancel_events(crate::current());
}
Expand All @@ -83,12 +84,14 @@ impl WaitQueue {
{
loop {
// let mut rq_locked = .scheduler().lock();
let mut wq_locked = self.queue.lock();
if condition() {
break;
}
current_run_queue().block_current(|task| {
task.set_in_wait_queue(true);
self.queue.lock().push_back(task);
wq_locked.push_back(task);
drop(wq_locked)
});
}
self.cancel_events(crate::current());
Expand All @@ -98,6 +101,7 @@ impl WaitQueue {
/// notify it, or the given duration has elapsed.
#[cfg(feature = "irq")]
pub fn wait_timeout(&self, dur: core::time::Duration) -> bool {
let mut wq_locked = self.queue.lock();
let curr = crate::current();
let deadline = axhal::time::wall_time() + dur;
debug!(
Expand All @@ -109,7 +113,8 @@ impl WaitQueue {

current_run_queue().block_current(|task| {
task.set_in_wait_queue(true);
self.queue.lock().push_back(task)
wq_locked.push_back(task);
drop(wq_locked)
});
let timeout = curr.in_wait_queue(); // still in the wait queue, must have timed out
self.cancel_events(curr);
Expand Down Expand Up @@ -137,13 +142,15 @@ impl WaitQueue {

let mut timeout = true;
while axhal::time::wall_time() < deadline {
let mut wq_locked = self.queue.lock();
if condition() {
timeout = false;
break;
}
current_run_queue().block_current(|task| {
task.set_in_wait_queue(true);
self.queue.lock().push_back(task);
wq_locked.push_back(task);
drop(wq_locked)
});
}
self.cancel_events(curr);
Expand Down
67 changes: 0 additions & 67 deletions test_aarch64_deadlock.txt

This file was deleted.

198 changes: 0 additions & 198 deletions test_x86_deadlock.txt

This file was deleted.

0 comments on commit b96c02c

Please sign in to comment.