Skip to content

Commit 472e984

Browse files
committed
reduce hardware dependent code
1 parent c3c89e9 commit 472e984

File tree

4 files changed

+7
-52
lines changed

4 files changed

+7
-52
lines changed

src/arch/x86/kernel/processor.rs

Lines changed: 0 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -12,45 +12,6 @@ pub(crate) fn mb() {
1212
}
1313
}
1414

15-
/// Search the most significant bit
16-
#[inline(always)]
17-
pub(crate) fn msb(value: usize) -> Option<usize> {
18-
if value > 0 {
19-
let ret: usize;
20-
21-
unsafe {
22-
asm!("bsr {0}, {1}",
23-
out(reg) ret,
24-
in(reg) value,
25-
options(nomem, nostack)
26-
);
27-
}
28-
Some(ret)
29-
} else {
30-
None
31-
}
32-
}
33-
34-
/// Search the least significant bit
35-
#[allow(dead_code)]
36-
#[inline(always)]
37-
pub(crate) fn lsb(value: usize) -> Option<usize> {
38-
if value > 0 {
39-
let ret: usize;
40-
41-
unsafe {
42-
asm!("bsf {0}, {1}",
43-
out(reg) ret,
44-
in(reg) value,
45-
options(nomem, nostack)
46-
);
47-
}
48-
Some(ret)
49-
} else {
50-
None
51-
}
52-
}
53-
5415
#[allow(dead_code)]
5516
#[inline(always)]
5617
pub(crate) fn halt() {
@@ -59,13 +20,6 @@ pub(crate) fn halt() {
5920
}
6021
}
6122

62-
#[inline(always)]
63-
pub(crate) fn pause() {
64-
unsafe {
65-
asm!("pause", options(nomem, nostack));
66-
}
67-
}
68-
6923
#[allow(unused_variables)]
7024
#[no_mangle]
7125
pub(crate) extern "C" fn shutdown(error_code: i32) -> ! {

src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#![feature(abi_x86_interrupt)]
22
#![feature(alloc_error_handler)]
33
#![feature(const_trait_impl)]
4+
#![feature(int_lowest_highest_one)]
45
#![allow(clippy::module_inception)]
56
#![allow(static_mut_refs)]
67
#![no_std]

src/scheduler/task.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
use crate::arch::mm::VirtAddr;
2-
use crate::arch::processor::msb;
32
use crate::consts::*;
43
use alloc::boxed::Box;
54
use alloc::collections::VecDeque;
@@ -100,16 +99,17 @@ impl PriorityTaskQueue {
10099

101100
/// Pop the task with the highest priority from the queue
102101
pub fn pop(&mut self) -> Option<Rc<RefCell<Task>>> {
103-
if let Some(i) = msb(self.prio_bitmap) {
104-
return self.pop_from_queue(i);
102+
if let Some(i) = self.prio_bitmap.highest_one() {
103+
return self.pop_from_queue(i.try_into().unwrap());
105104
}
106105

107106
None
108107
}
109108

110109
/// Pop the next task, which has a higher or the same priority as `prio`
111110
pub fn pop_with_prio(&mut self, prio: TaskPriority) -> Option<Rc<RefCell<Task>>> {
112-
if let Some(i) = msb(self.prio_bitmap) {
111+
if let Some(i) = self.prio_bitmap.highest_one() {
112+
let i: usize = i.try_into().unwrap();
113113
if i >= prio.into().into() {
114114
return self.pop_from_queue(i);
115115
}

src/synch/spinlock.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ unsafe impl RawMutex for RawSpinlock {
2424
fn lock(&self) {
2525
let ticket = self.queue.fetch_add(1, Ordering::Relaxed);
2626
while self.dequeue.load(Ordering::Acquire) != ticket {
27-
arch::processor::pause();
27+
core::hint::spin_loop();
2828
}
2929
}
3030

@@ -107,7 +107,7 @@ unsafe impl RawMutex for RawSpinlockIrqSave {
107107

108108
while self.dequeue.load(Ordering::Acquire) != ticket {
109109
arch::irq::irq_nested_enable(irq);
110-
arch::processor::pause();
110+
core::hint::spin_loop();
111111
arch::irq::irq_nested_disable();
112112
}
113113

0 commit comments

Comments
 (0)