Skip to content

Commit f403fe5

Browse files
committed
reduce hardware dependent code
1 parent f139efc commit f403fe5

File tree

4 files changed

+8
-51
lines changed

4 files changed

+8
-51
lines changed

src/arch/x86/kernel/processor.rs

Lines changed: 0 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -39,44 +39,6 @@ pub(crate) fn mb() {
3939
}
4040
}
4141

42-
/// Search the most significant bit
43-
#[inline(always)]
44-
pub(crate) fn msb(value: usize) -> Option<usize> {
45-
if value > 0 {
46-
let ret: usize;
47-
48-
unsafe {
49-
asm!("bsr {0}, {1}",
50-
out(reg) ret,
51-
in(reg) value,
52-
options(nomem, nostack)
53-
);
54-
}
55-
Some(ret)
56-
} else {
57-
None
58-
}
59-
}
60-
61-
/// Search the least significant bit
62-
#[allow(dead_code)]
63-
#[inline(always)]
64-
pub(crate) fn lsb(value: usize) -> Option<usize> {
65-
if value > 0 {
66-
let ret: usize;
67-
unsafe {
68-
asm!("bsf {0}, {1}",
69-
out(reg) ret,
70-
in(reg) value,
71-
options(nomem, nostack)
72-
);
73-
}
74-
Some(ret)
75-
} else {
76-
None
77-
}
78-
}
79-
8042
#[allow(dead_code)]
8143
#[inline(always)]
8244
pub(crate) fn halt() {
@@ -85,13 +47,6 @@ pub(crate) fn halt() {
8547
}
8648
}
8749

88-
#[inline(always)]
89-
pub(crate) fn pause() {
90-
unsafe {
91-
asm!("pause", options(nomem, nostack));
92-
}
93-
}
94-
9550
#[allow(unused_variables)]
9651
#[no_mangle]
9752
pub(crate) extern "C" fn shutdown(error_code: i32) -> ! {

src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
#![feature(alloc_error_handler)]
33
#![feature(abi_x86_interrupt)]
44
#![feature(specialization)]
5+
#![feature(const_trait_impl)]
6+
#![feature(int_lowest_highest_one)]
57
#![allow(clippy::module_inception)]
68
#![allow(incomplete_features)]
79
#![allow(static_mut_refs)]

src/scheduler/task.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
use crate::arch;
44
use crate::arch::mm::PhysAddr;
55
use crate::arch::mm::VirtAddr;
6-
use crate::arch::processor::msb;
76
use crate::arch::{BasePageSize, PageSize};
87
use crate::consts::*;
98
use crate::logging::*;
@@ -106,16 +105,17 @@ impl PriorityTaskQueue {
106105

107106
/// Pop the task with the highest priority from the queue
108107
pub fn pop(&mut self) -> Option<Rc<RefCell<Task>>> {
109-
if let Some(i) = msb(self.prio_bitmap) {
110-
return self.pop_from_queue(i);
108+
if let Some(i) = self.prio_bitmap.highest_one() {
109+
return self.pop_from_queue(i.try_into().unwrap());
111110
}
112111

113112
None
114113
}
115114

116115
/// Pop the next task, which has a higher or the same priority as `prio`
117116
pub fn pop_with_prio(&mut self, prio: TaskPriority) -> Option<Rc<RefCell<Task>>> {
118-
if let Some(i) = msb(self.prio_bitmap) {
117+
if let Some(i) = self.prio_bitmap.highest_one() {
118+
let i: usize = i.try_into().unwrap();
119119
if i >= prio.into().into() {
120120
return self.pop_from_queue(i);
121121
}

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)