Skip to content

Commit c863487

Browse files
committed
reduce hardware dependent code
1 parent 4177295 commit c863487

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
@@ -33,45 +33,6 @@ pub(crate) fn mb() {
3333
}
3434
}
3535

36-
/// Search the most significant bit
37-
#[inline(always)]
38-
pub(crate) fn msb(value: usize) -> Option<usize> {
39-
if value > 0 {
40-
let ret: usize;
41-
42-
unsafe {
43-
asm!("bsr {0}, {1}",
44-
out(reg) ret,
45-
in(reg) value,
46-
options(nomem, nostack)
47-
);
48-
}
49-
Some(ret)
50-
} else {
51-
None
52-
}
53-
}
54-
55-
/// Search the least significant bit
56-
#[allow(dead_code)]
57-
#[inline(always)]
58-
pub(crate) fn lsb(value: usize) -> Option<usize> {
59-
if value > 0 {
60-
let ret: usize;
61-
62-
unsafe {
63-
asm!("bsf {0}, {1}",
64-
out(reg) ret,
65-
in(reg) value,
66-
options(nomem, nostack)
67-
);
68-
}
69-
Some(ret)
70-
} else {
71-
None
72-
}
73-
}
74-
7536
#[allow(dead_code)]
7637
#[inline(always)]
7738
pub(crate) fn halt() {
@@ -80,13 +41,6 @@ pub(crate) fn halt() {
8041
}
8142
}
8243

83-
#[inline(always)]
84-
pub(crate) fn pause() {
85-
unsafe {
86-
asm!("pause", options(nomem, nostack));
87-
}
88-
}
89-
9044
#[allow(unused_variables)]
9145
#[no_mangle]
9246
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)