使用rust重写了apic的驱动 (#425)

* 使用rust重写了apic的驱动。

* 修正signal和调度器的部分加锁逻辑,增加回退策略。

* 把pcb的flags字段替换为无锁的

* 使用cargo管理apic的编译

* 删除makefile中指定PIC的变量

---------

Co-authored-by: Gou Ngai <ymd7823@outlook.com>
Co-authored-by: 櫻井桃華 <89176634+TihayaKousaka@users.noreply.github.com>
This commit is contained in:
LoGin
2023-11-07 20:32:06 +08:00
committed by GitHub
parent 4935c74f32
commit 70a4e5550a
63 changed files with 2638 additions and 1367 deletions

View File

@ -9,7 +9,7 @@ ECHO:
@echo "$@"
$(kernel_lib_subdirs): ECHO
$(MAKE) -C $@ all CFLAGS="$(CFLAGS)" ASFLAGS="$(ASFLAGS)" PIC="$(PIC)"
$(MAKE) -C $@ all CFLAGS="$(CFLAGS)" ASFLAGS="$(ASFLAGS)"
$(kernel_lib_objs): ECHO
$(CC) $(CFLAGS) -c $@ -o $@.o

View File

@ -0,0 +1,46 @@
use core::{cell::UnsafeCell, fmt::Debug};
/// 一个无锁的标志位
///
/// 可与bitflags配合使用以实现无锁的标志位
///
/// ## Safety
///
/// 由于标识位的修改是无锁,且不保证原子性,因此需要使用者自行在别的机制中,确保
/// 哪怕标识位的值是老的,执行动作也不会有问题(或者有状态恢复机制)。
pub struct LockFreeFlags<T> {
inner: UnsafeCell<T>,
}
impl<T> LockFreeFlags<T> {
pub unsafe fn new(inner: T) -> Self {
Self {
inner: UnsafeCell::new(inner),
}
}
pub fn get_mut(&self) -> &mut T {
unsafe { &mut *self.inner.get() }
}
pub fn get(&self) -> &T {
unsafe { &*self.inner.get() }
}
}
unsafe impl<T: Sync> Sync for LockFreeFlags<T> {}
unsafe impl<T: Send> Send for LockFreeFlags<T> {}
impl<T: Clone> Clone for LockFreeFlags<T> {
fn clone(&self) -> Self {
unsafe { Self::new(self.get().clone()) }
}
}
impl<T: Debug> Debug for LockFreeFlags<T> {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
f.debug_struct("LockFreeFlags")
.field("inner", self.get())
.finish()
}
}

View File

@ -8,6 +8,7 @@ pub mod int_like;
pub mod keyboard_parser;
pub mod lazy_init;
pub mod lib_ui;
pub mod lock_free_flags;
pub mod mutex;
pub mod notifier;
pub mod once;

View File

@ -265,6 +265,20 @@ impl<T> RwLock<T> {
return r;
}
#[allow(dead_code)]
pub fn try_upgradeable_read_irqsave(&self) -> Option<RwLockUpgradableGuard<T>> {
let irq_guard = unsafe { CurrentIrqArch::save_and_disable_irq() };
ProcessManager::preempt_disable();
let mut r = self.inner_try_upgradeable_read();
if r.is_none() {
ProcessManager::preempt_enable();
} else {
r.as_mut().unwrap().irq_guard = Some(irq_guard);
}
return r;
}
fn inner_try_upgradeable_read(&self) -> Option<RwLockUpgradableGuard<T>> {
// 获得UPGRADER守卫不需要查看读者位
// 如果获得读者锁失败,不需要撤回fetch_or的原子操作