mirror of
https://github.com/DragonOS-Community/DragonOS.git
synced 2025-06-20 10:06:31 +00:00
Patch sched rust (#139)
* update * 添加rt调度器的rust初步实现 * 完善rt调度逻辑 * 调试rt调度器 * 修改sched的返回值 * cargo fmt 格式化 * 删除无用代码,修补rt bug * 删除无用的代码,和重复的逻辑 * 软中断bugfix * 删除一些代码 * 添加kthread_run_rt文档 * 解决sphinix警告_static目录不存在的问题 Co-authored-by: longjin <longjin@RinGoTek.cn>
This commit is contained in:
@ -13,8 +13,8 @@ pub fn atomic_read(ato: *const atomic_t) -> i64 {
|
||||
|
||||
/// @brief 原子的设置原子变量的值
|
||||
#[inline]
|
||||
pub fn atomic_set(ato: *mut atomic_t, value:i64) {
|
||||
unsafe{
|
||||
pub fn atomic_set(ato: *mut atomic_t, value: i64) {
|
||||
unsafe {
|
||||
write_volatile(&mut (*ato).value, value);
|
||||
}
|
||||
}
|
||||
|
@ -6,24 +6,10 @@ pub trait FFIBind2Rust<T> {
|
||||
fn convert_mut(src: *mut T) -> Option<&'static mut Self>;
|
||||
}
|
||||
|
||||
|
||||
|
||||
pub fn __convert_mut<'a, S, D>(src:*mut S) ->Option<&'a mut D>{
|
||||
return unsafe {
|
||||
core::mem::transmute::<
|
||||
*mut S,
|
||||
*mut D,
|
||||
>(src)
|
||||
.as_mut()
|
||||
};
|
||||
pub fn __convert_mut<'a, S, D>(src: *mut S) -> Option<&'a mut D> {
|
||||
return unsafe { core::mem::transmute::<*mut S, *mut D>(src).as_mut() };
|
||||
}
|
||||
|
||||
pub fn __convert_ref<'a, S, D>(src:*const S) ->Option<&'a D>{
|
||||
return unsafe {
|
||||
core::mem::transmute::<
|
||||
*const S,
|
||||
*const D,
|
||||
>(src)
|
||||
.as_ref()
|
||||
};
|
||||
pub fn __convert_ref<'a, S, D>(src: *const S) -> Option<&'a D> {
|
||||
return unsafe { core::mem::transmute::<*const S, *const D>(src).as_ref() };
|
||||
}
|
||||
|
@ -3,13 +3,16 @@ use crate::include::bindings::bindings::List;
|
||||
/// @brief 初始化链表
|
||||
#[inline]
|
||||
pub fn list_init(list: *mut List) {
|
||||
unsafe{*list}.prev = list;
|
||||
unsafe{*list}.next = list;
|
||||
unsafe { *list }.prev = list;
|
||||
unsafe { *list }.next = list;
|
||||
}
|
||||
|
||||
impl Default for List{
|
||||
impl Default for List {
|
||||
fn default() -> Self {
|
||||
let x= Self { prev: 0 as *mut List, next: 0 as *mut List };
|
||||
return x;
|
||||
let x = Self {
|
||||
prev: 0 as *mut List,
|
||||
next: 0 as *mut List,
|
||||
};
|
||||
return x;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -324,32 +324,32 @@ impl LockRef {
|
||||
}
|
||||
|
||||
/*
|
||||
* 您可以使用以下代码测试lockref
|
||||
* 您可以使用以下代码测试lockref
|
||||
|
||||
let mut lockref = LockRef::new();
|
||||
kdebug!("lockref={:?}", lockref);
|
||||
lockref.inc();
|
||||
assert_eq!(lockref.count, 1);
|
||||
kdebug!("lockref={:?}", lockref);
|
||||
assert!(lockref.dec().is_ok());
|
||||
assert_eq!(lockref.count, 0);
|
||||
let mut lockref = LockRef::new();
|
||||
kdebug!("lockref={:?}", lockref);
|
||||
lockref.inc();
|
||||
assert_eq!(lockref.count, 1);
|
||||
kdebug!("lockref={:?}", lockref);
|
||||
assert!(lockref.dec().is_ok());
|
||||
assert_eq!(lockref.count, 0);
|
||||
|
||||
assert!(lockref.dec().is_err());
|
||||
assert_eq!(lockref.count, 0);
|
||||
assert!(lockref.dec().is_err());
|
||||
assert_eq!(lockref.count, 0);
|
||||
|
||||
lockref.inc();
|
||||
assert_eq!(lockref.count, 1);
|
||||
lockref.inc();
|
||||
assert_eq!(lockref.count, 1);
|
||||
|
||||
assert!(lockref.dec_not_zero().is_err());
|
||||
assert!(lockref.dec_not_zero().is_err());
|
||||
|
||||
lockref.inc();
|
||||
assert_eq!(lockref.count, 2);
|
||||
lockref.inc();
|
||||
assert_eq!(lockref.count, 2);
|
||||
|
||||
assert!(lockref.dec_not_zero().is_ok());
|
||||
assert!(lockref.dec_not_zero().is_ok());
|
||||
|
||||
lockref.mark_dead();
|
||||
assert!(lockref.count < 0);
|
||||
|
||||
assert!(lockref.inc_not_dead().is_err());
|
||||
kdebug!("lockref={:?}", lockref);
|
||||
*/
|
||||
lockref.mark_dead();
|
||||
assert!(lockref.count < 0);
|
||||
|
||||
assert!(lockref.inc_not_dead().is_err());
|
||||
kdebug!("lockref={:?}", lockref);
|
||||
*/
|
||||
|
@ -1,9 +1,9 @@
|
||||
pub mod ffi_convert;
|
||||
pub mod printk;
|
||||
pub mod spinlock;
|
||||
pub mod ffi_convert;
|
||||
#[macro_use]
|
||||
pub mod refcount;
|
||||
pub mod atomic;
|
||||
pub mod wait_queue;
|
||||
pub mod list;
|
||||
pub mod lockref;
|
||||
pub mod lockref;
|
||||
pub mod wait_queue;
|
||||
|
@ -1,20 +1,28 @@
|
||||
use crate::{include::bindings::bindings::{atomic_inc, atomic_t, atomic_dec}, kwarn};
|
||||
use crate::{
|
||||
include::bindings::bindings::{atomic_dec, atomic_inc, atomic_t},
|
||||
kwarn,
|
||||
};
|
||||
|
||||
use super::{ffi_convert::{FFIBind2Rust, __convert_mut, __convert_ref}, atomic::atomic_read};
|
||||
use super::{
|
||||
atomic::atomic_read,
|
||||
ffi_convert::{FFIBind2Rust, __convert_mut, __convert_ref},
|
||||
};
|
||||
|
||||
#[derive(Debug, Copy, Clone)]
|
||||
pub struct RefCount {
|
||||
pub refs: atomic_t,
|
||||
}
|
||||
|
||||
impl Default for RefCount{
|
||||
impl Default for RefCount {
|
||||
fn default() -> Self {
|
||||
Self { refs: atomic_t { value: 1 }}
|
||||
Self {
|
||||
refs: atomic_t { value: 1 },
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// @brief 将给定的来自bindgen的refcount_t解析为Rust的RefCount的引用
|
||||
impl FFIBind2Rust<crate::include::bindings::bindings::refcount_struct> for RefCount{
|
||||
impl FFIBind2Rust<crate::include::bindings::bindings::refcount_struct> for RefCount {
|
||||
fn convert_mut(
|
||||
src: *mut crate::include::bindings::bindings::refcount_struct,
|
||||
) -> Option<&'static mut Self> {
|
||||
@ -23,7 +31,7 @@ impl FFIBind2Rust<crate::include::bindings::bindings::refcount_struct> for RefCo
|
||||
fn convert_ref(
|
||||
src: *const crate::include::bindings::bindings::refcount_struct,
|
||||
) -> Option<&'static Self> {
|
||||
return __convert_ref(src)
|
||||
return __convert_ref(src);
|
||||
}
|
||||
}
|
||||
|
||||
@ -40,10 +48,10 @@ macro_rules! REFCOUNT_INIT {
|
||||
#[allow(dead_code)]
|
||||
#[inline]
|
||||
pub fn refcount_inc(r: &mut RefCount) {
|
||||
if atomic_read(&r.refs) == 0{
|
||||
if atomic_read(&r.refs) == 0 {
|
||||
kwarn!("Refcount increased from 0, may be use-after free");
|
||||
}
|
||||
|
||||
|
||||
unsafe {
|
||||
atomic_inc(&mut r.refs);
|
||||
}
|
||||
@ -52,10 +60,8 @@ pub fn refcount_inc(r: &mut RefCount) {
|
||||
/// @brief 引用计数自减1
|
||||
#[allow(dead_code)]
|
||||
#[inline]
|
||||
pub fn refcount_dec(r: &mut RefCount){
|
||||
unsafe{
|
||||
pub fn refcount_dec(r: &mut RefCount) {
|
||||
unsafe {
|
||||
atomic_dec(&mut r.refs);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -1,12 +1,14 @@
|
||||
use crate::include::bindings::bindings::{wait_queue_head_t};
|
||||
use crate::include::bindings::bindings::wait_queue_head_t;
|
||||
|
||||
use super::{list::list_init};
|
||||
use super::list::list_init;
|
||||
|
||||
|
||||
impl Default for wait_queue_head_t{
|
||||
impl Default for wait_queue_head_t {
|
||||
fn default() -> Self {
|
||||
let mut x = Self { wait_list: Default::default(), lock: Default::default() };
|
||||
let mut x = Self {
|
||||
wait_list: Default::default(),
|
||||
lock: Default::default(),
|
||||
};
|
||||
list_init(&mut x.wait_list);
|
||||
return x;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user