From ad12a065acabb7916b2c4e8ef65973291a8dda91 Mon Sep 17 00:00:00 2001 From: JiajunDu Date: Mon, 18 Dec 2023 05:59:00 +0000 Subject: [PATCH] rust: rros: remove all redundant comments There are many unnecessary comments in the code, remove them to standardize the code. https://github.com/BUPT-OS/RROS/issues/15 --- kernel/rros/clock.rs | 125 +++++++----------------- kernel/rros/clock_test.rs | 7 +- kernel/rros/control.rs | 2 +- kernel/rros/factory.rs | 153 ++---------------------------- kernel/rros/fifo.rs | 104 +------------------- kernel/rros/fifo_test.rs | 12 +-- kernel/rros/file.rs | 11 +-- kernel/rros/flags.rs | 3 +- kernel/rros/init.rs | 4 +- kernel/rros/list.rs | 8 +- kernel/rros/list_test.rs | 9 +- kernel/rros/memory.rs | 1 - kernel/rros/memory_test.rs | 16 +--- kernel/rros/monitor.rs | 5 +- kernel/rros/mutex.rs | 29 +++--- kernel/rros/net/device.rs | 4 +- kernel/rros/net/ethernet/input.rs | 8 +- kernel/rros/net/output.rs | 4 +- kernel/rros/net/packet.rs | 5 +- kernel/rros/net/skb.rs | 5 +- kernel/rros/net/socket.rs | 16 ++-- kernel/rros/proxy.rs | 93 ------------------ kernel/rros/rros/latmus.rs | 50 ---------- kernel/rros/sched.rs | 89 +++-------------- kernel/rros/stat.rs | 6 +- kernel/rros/stat_test.rs | 3 - kernel/rros/thread.rs | 59 +++--------- kernel/rros/tick.rs | 4 +- kernel/rros/timer.rs | 31 +----- kernel/rros/timer_test.rs | 20 +--- kernel/rros/tp.rs | 12 +-- kernel/rros/types.rs | 2 - kernel/rros/wait.rs | 8 +- kernel/rros/work.rs | 4 +- kernel/rros/xbuf.rs | 68 ------------- rust/kernel/double_linked_list.rs | 17 +--- rust/kernel/memory_rros.rs | 18 +--- rust/kernel/memory_rros_test.rs | 32 +++---- rust/kernel/percpu_defs.rs | 4 +- rust/kernel/pipeline.rs | 5 - rust/kernel/sysfs.rs | 6 -- 41 files changed, 171 insertions(+), 891 deletions(-) delete mode 100644 rust/kernel/pipeline.rs diff --git a/kernel/rros/clock.rs b/kernel/rros/clock.rs index 825ba7874731d..0e61d4598cbf0 100644 --- a/kernel/rros/clock.rs +++ b/kernel/rros/clock.rs @@ -1,7 +1,3 @@ -// #![feature(allocator_api)] -// #![allow(warnings, unused)] -// #![feature(stmt_expr_attributes)] - #![allow(warnings, unused)] #![feature(stmt_expr_attributes)] use crate::{ @@ -15,7 +11,9 @@ use crate::{ tick, timeout::RROS_INFINITE, }; + use alloc::rc::Rc; + use core::{ borrow::{Borrow, BorrowMut}, cell::{RefCell, UnsafeCell}, @@ -24,6 +22,7 @@ use core::{ mem::{align_of, size_of}, todo, }; + use kernel::{ bindings, c_types, cpumask, double_linked_list::*, file_operations::{FileOperations, FileOpener}, ktime::*, percpu, prelude::*, premmpt, spinlock_init, str::CStr, sync::Lock, sync::SpinLock, sysfs, @@ -37,11 +36,12 @@ use kernel::{ static mut CLOCKLIST_LOCK: SpinLock = unsafe { SpinLock::new(1) }; -const CONFIG_RROS_LATENCY_USER: KtimeT = 0; //这里先定义为常量,后面应该从/dev/rros中读取 +// Define it as a constant here first, and then read it from /dev/rros. +const CONFIG_RROS_LATENCY_USER: KtimeT = 0; const CONFIG_RROS_LATENCY_KERNEL: KtimeT = 0; const CONFIG_RROS_LATENCY_IRQ: KtimeT = 0; -// there should be 8 +// There should be 8. pub const CONFIG_RROS_NR_CLOCKS: usize = 16; #[derive(Default)] @@ -86,11 +86,10 @@ impl RrosClockGravity { } } -//定义时钟操作 pub struct RrosClockOps { read: Option KtimeT>, readcycles: Option u64>, - set: Option i32>, //int + set: Option i32>, programlocalshot: Option, programremoteshot: Option, setgravity: Option, @@ -102,7 +101,7 @@ impl RrosClockOps { pub fn new( read: Option KtimeT>, readcycles: Option u64>, - set: Option i32>, //int + set: Option i32>, programlocalshot: Option, programremoteshot: Option, setgravity: Option, @@ -136,9 +135,8 @@ pub struct RrosClock { dispose: Option, #[cfg(CONFIG_SMP)] pub affinity: Option, -} //____cacheline_aligned +} -//RrosClock主方法 impl RrosClock { pub fn new( resolution: KtimeT, @@ -171,14 +169,14 @@ impl RrosClock { } } pub fn read(&self) -> KtimeT { - //错误处理 + // Error handling. if self.ops.read.is_some() { return self.ops.read.unwrap()(&self); } return 0; } pub fn read_cycles(&self) -> u64 { - //错误处理 + // Error handling. if self.ops.readcycles.is_some() { return self.ops.readcycles.unwrap()(&self); } @@ -188,7 +186,8 @@ impl RrosClock { if self.ops.set.is_some() { self.ops.set.unwrap()(self, time); } else { - return Err(kernel::Error::EFAULT); //阻止函数为null情况的执行 + // Prevent the execution of the function if it is null. + return Err(kernel::Error::EFAULT); } Ok(0) } @@ -218,7 +217,7 @@ impl RrosClock { } } pub fn get_timerdata_addr(&self) -> *mut RrosTimerbase { - //错误处理 + // Error handling. return self.timerdata as *mut RrosTimerbase; } @@ -243,7 +242,6 @@ impl RrosClock { } } -//测试通过 pub fn adjust_timer( clock: &RrosClock, timer: Arc>, @@ -295,12 +293,11 @@ pub fn adjust_timer( rros_enqueue_timer(timer.clone(), tq); } -//简单测过 -//调整当前clock各个CPU tmb中List中的所有timer pub fn rros_adjust_timers(clock: &mut RrosClock, delta: KtimeT) { - //raw_spin_lock_irqsave(&tmb->lock, flags); + // Adjust all timers in the List in each CPU tmb of the current clock. + // raw_spin_lock_irqsave(&tmb->lock, flags); let cpu = 0; - //for_each_online_cpu(cpu) { + // for_each_online_cpu(cpu) { let rq = rros_cpu_rq(cpu); let tmb = rros_percpu_timers(clock, cpu); let tq = unsafe { &mut (*tmb).q }; @@ -322,7 +319,6 @@ pub fn rros_adjust_timers(clock: &mut RrosClock, delta: KtimeT) { //} } -//测试通过 pub fn rros_stop_timers(clock: &RrosClock) { let cpu = 0; let mut tmb = rros_percpu_timers(&clock, cpu); @@ -336,30 +332,9 @@ pub fn rros_stop_timers(clock: &RrosClock) { } } -/* - void inband_clock_was_set(void) -{ - struct rros_clock *clock; - - if (!rros_is_enabled()) - return; - - mutex_lock(&clocklist_lock); - - list_for_each_entry(clock, &clock_list, next) { - if (clock->ops.adjust) - clock->ops.adjust(clock); - } - - mutex_unlock(&clocklist_lock); -} - */ - -//打印clock的初始化log +// Print the initialization log of the clock. fn rros_clock_log() {} -/*mono时钟操作 */ - fn read_mono_clock(clock: &RrosClock) -> KtimeT { timekeeping::ktime_get_mono_fast_ns() } @@ -369,13 +344,15 @@ fn read_mono_clock_cycles(clock: &RrosClock) -> u64 { } fn set_mono_clock(clock: &mut RrosClock, time: KtimeT) -> i32 { - //mono无法设置,后面应该为错误类型 + // mono cannot be set, the following should be an error type. 0 } fn adjust_mono_clock(clock: &mut RrosClock) {} -/*realtime时钟操作 */ +/** + * The following functions are the realtime clock operations. + */ fn read_realtime_clock(clock: &RrosClock) -> KtimeT { timekeeping::ktime_get_real_fast_ns() @@ -397,7 +374,9 @@ fn adjust_realtime_clock(clock: &mut RrosClock) { // rros_adjust_timers(clock, clock.offset - old_offset) } -/*通用clock操作 */ +/** + * The following functions are universal clock operations. + */ fn get_default_gravity() -> RrosClockGravity { RrosClockGravity { @@ -417,9 +396,9 @@ fn reset_coreclk_gravity(clock: &mut RrosClock) { set_coreclk_gravity(clock, get_default_gravity()); } -//两个全局变量MONO和REALTIME static RROS_MONO_CLOCK_NAME: &CStr = unsafe { CStr::from_bytes_with_nul_unchecked("RROS_CLOCK_MONOTONIC_DEV\0".as_bytes()) }; + pub static mut RROS_MONO_CLOCK: RrosClock = RrosClock { name: RROS_MONO_CLOCK_NAME, resolution: 1, @@ -454,6 +433,7 @@ pub static mut RROS_MONO_CLOCK: RrosClock = RrosClock { static RROS_REALTIME_CLOCK_NAME: &CStr = unsafe { CStr::from_bytes_with_nul_unchecked("RROS_CLOCK_REALTIME_DEV\0".as_bytes()) }; + pub static mut RROS_REALTIME_CLOCK: RrosClock = RrosClock { name: RROS_REALTIME_CLOCK_NAME, resolution: 1, @@ -545,30 +525,6 @@ impl FileOperations for ClockOps { pub fn clock_factory_dispose(ele: factory::RrosElement) {} -/* -void rros_core_tick(struct clock_event_device *dummy) /* hard irqs off */ -{ - struct rros_rq *this_rq = this_rros_rq(); - struct rros_timerbase *tmb; - - if (RROS_WARN_ON_ONCE(CORE, !is_rros_cpu(rros_rq_cpu(this_rq)))) - return; - - tmb = rros_this_cpu_timers(&rros_mono_clock); - do_clock_tick(&rros_mono_clock, tmb); - - /* - * If an RROS thread was preempted by this clock event, any - * transition to the in-band context will cause a pending - * in-band tick to be propagated by rros_schedule() called from - * rros_exit_irq(), so we may have to propagate the in-band - * tick immediately only if the in-band context was preempted. - */ - if ((this_rq->local_flags & RQ_TPROXY) && (this_rq->curr->state & T_ROOT)) - rros_notify_proxy_tick(this_rq); -} -*/ - fn timer_needs_enqueuing(timer: *mut RrosTimer) -> bool { unsafe { return ((*timer).get_status() @@ -580,7 +536,7 @@ fn timer_needs_enqueuing(timer: *mut RrosTimer) -> bool { } } -//rq相关未测试,其余测试通过 +// `rq` related tests haven't been tested, other tests passed. pub fn do_clock_tick(clock: &mut RrosClock, tmb: *mut RrosTimerbase) { let rq = this_rros_rq(); // #[cfg(CONFIG_RROS_DEBUG_CORE)] @@ -670,7 +626,7 @@ impl clockchips::CoreTick for RrosCoreTick { let rq_has_tproxy = ((*this_rq).local_flags & RQ_TPROXY != 0x0); let assd = (*(*this_rq).get_curr().locked_data().get()).state; let curr_state_is_t_root = (assd & (T_ROOT as u32) != 0x0); - //这个if进不去有问题!! + // This `if` won't enter, so there is a problem. // let a = ((*this_rq).local_flags & RQ_TPROXY != 0x0); // if rq_has_tproxy { // pr_debug!("in rros_core_tick"); @@ -701,7 +657,6 @@ impl clockchips::CoreTick for RrosCoreTick { } } -//初始化时钟 fn init_clock(clock: *mut RrosClock, master: *mut RrosClock) -> Result { // unsafe{ // if (*clock).element.is_none(){ @@ -726,11 +681,10 @@ fn init_clock(clock: *mut RrosClock, master: *mut RrosClock) -> Result { Ok(0) } -//初始化时钟slave fn rros_init_slave_clock(clock: &mut RrosClock, master: &mut RrosClock) -> Result { premmpt::running_inband()?; - //这里为什么会报错,timer就可以跑?为什么卧槽 + // TODO: Check if there is a problem here, even if the timer can run. // #[cfg(CONFIG_SMP)] // clock.affinity = master.affinity; @@ -740,13 +694,13 @@ fn rros_init_slave_clock(clock: &mut RrosClock, master: &mut RrosClock) -> Resul Ok(0) } -//rros初始化时钟 fn rros_init_clock(clock: &mut RrosClock, affinity: &cpumask::CpumaskT) -> Result { premmpt::running_inband()?; + // 8 byte alignment let tmb = percpu::alloc_per_cpu( size_of::() as usize, align_of::() as usize, - ) as *mut RrosTimerbase; //8字节对齐 + ) as *mut RrosTimerbase; if tmb == 0 as *mut RrosTimerbase { return Err(kernel::Error::ENOMEM); } @@ -767,7 +721,6 @@ fn rros_init_clock(clock: &mut RrosClock, affinity: &cpumask::CpumaskT) -> Resul Ok(0) } -//时钟系统初始化 pub fn rros_clock_init() -> Result { let pinned = unsafe { Pin::new_unchecked(&mut CLOCKLIST_LOCK) }; spinlock_init!(pinned, "CLOCKLIST_LOCK"); @@ -798,17 +751,3 @@ pub fn rros_read_clock(clock: &RrosClock) -> KtimeT { fn rros_ktime_monotonic() -> KtimeT { timekeeping::ktime_get_mono_fast_ns() } - -// static inline ktime_t rros_read_clock(struct rros_clock *clock) -// { -// /* -// * In many occasions on the fast path, rros_read_clock() is -// * explicitly called with &rros_mono_clock which resolves as -// * a constant. Skip the clock trampoline handler, branching -// * immediately to the final code for such clock. -// */ -// if (clock == &rros_mono_clock) -// return rros_ktime_monotonic(); - -// return clock->ops.read(clock); -// } diff --git a/kernel/rros/clock_test.rs b/kernel/rros/clock_test.rs index e2f9116d35bc4..251cb6b103d9e 100644 --- a/kernel/rros/clock_test.rs +++ b/kernel/rros/clock_test.rs @@ -1,9 +1,7 @@ -//clock.rs测试文件 -//用于测试clock.rs里的函数正确&性 use crate::{clock::*, timer::*}; + use kernel::{ktime::*, prelude::*, spinlock_init, sync::SpinLock}; -//测试通过 #[allow(dead_code)] pub fn test_do_clock_tick() -> Result { pr_debug!("~~~test_do_clock_tick begin~~~"); @@ -30,7 +28,6 @@ pub fn test_do_clock_tick() -> Result { Ok(0) } -//测试通过 #[allow(dead_code)] pub fn test_adjust_timer() -> Result { pr_debug!("~~~test_adjust_timer begin~~~"); @@ -57,7 +54,6 @@ pub fn test_adjust_timer() -> Result { Ok(0) } -//测试通过 #[allow(dead_code)] pub fn test_rros_adjust_timers() -> Result { pr_debug!("~~~test_rros_adjust_timers begin~~~"); @@ -103,7 +99,6 @@ pub fn test_rros_adjust_timers() -> Result { Ok(0) } -//测试通过 #[allow(dead_code)] pub fn test_rros_stop_timers() -> Result { pr_debug!("~~~test_rros_stop_timers begin~~~"); diff --git a/kernel/rros/control.rs b/kernel/rros/control.rs index 2f67f0b772832..10be763bda438 100644 --- a/kernel/rros/control.rs +++ b/kernel/rros/control.rs @@ -130,7 +130,7 @@ fn control_ioctl(file: &File, cmd: &mut IoctlCommand) -> Result { info.abi_base = RROS_ABI_BASE; info.abi_current = RROS_ABI_LEVEL; // in arch/arm64/include/asm/rros/fptest.h - // TODO There should be a function rros_detect_fpu() related to the arm64 architecture, the result of the function is 0. + // TODO: There should be a function rros_detect_fpu() related to the arm64 architecture, the result of the function is 0. info.fpu_features = 0; unsafe { pr_debug!( diff --git a/kernel/rros/factory.rs b/kernel/rros/factory.rs index bfe234edcc06b..f6629ec564bd4 100644 --- a/kernel/rros/factory.rs +++ b/kernel/rros/factory.rs @@ -71,7 +71,7 @@ const RROS_HANDLE_INDEX_MASK: FundleT = RROS_MUTEX_FLCEIL | RROS_MUTEX_FLCLAIM; pub struct RrosIndex { #[allow(dead_code)] - rbroot: rbtree::RBTree, // Todo: modify the u32. + rbroot: rbtree::RBTree, // TODO: modify the u32. lock: SpinLock, #[allow(dead_code)] generator: FundleT, @@ -159,7 +159,7 @@ pub struct RrosFactory { ) -> Rc>, >, pub dispose: Option, - pub attrs: Option, //此处暂时option了 + pub attrs: Option, // Use an `Option` for the time being. pub flags: RrosFactoryType, pub inside: Option, // pub fops: PhantomData, @@ -211,7 +211,7 @@ pub struct RrosElement { pub rcu_head: types::RcuHead, pub factory: &'static mut SpinLock, pub cdev: Option, - pub dev: Option, // dev + pub dev: Option, pub devname: Option, pub minor: u64, pub refs: i32, @@ -219,7 +219,7 @@ pub struct RrosElement { pub ref_lock: SpinLock, pub fundle: FundleT, pub clone_flags: i32, - // pub struct rb_node index_node;// Todo: in rfl rb_node is not embedded in the struct. + // pub struct rb_node index_node;// TODO: in rfl rb_node is not embedded in the struct. pub irq_work: irq_work::IrqWork, pub work: workqueue::Work, pub hash: types::HlistNode, @@ -368,38 +368,6 @@ fn create_element_device( Ok(0) } -// static struct device *create_sys_device(dev_t rdev, struct rros_factory *fac, -// void *drvdata, const char *name) -// { -// struct device *dev; -// int ret; - -// dev = kzalloc(sizeof(*dev), GFP_KERNEL); -// if (dev == NULL) -// return ERR_PTR(-ENOMEM); - -// dev->devt = rdev; -// dev->class = fac->class; -// dev->type = &fac->type; -// dev->groups = fac->attrs; -// dev->release = release_sys_device; -// dev_set_drvdata(dev, drvdata); - -// ret = dev_set_name(dev, "%s", name); -// if (ret) -// goto fail; - -// ret = device_register(dev); -// if (ret) -// goto fail; - -// return dev; - -// fail: -// put_device(dev); /* ->release_sys_device() */ -// return ERR_PTR(ret); -// } - #[allow(dead_code)] fn rros_element_is_public(e: Rc>) -> bool { let e_clone = e.clone(); @@ -651,86 +619,6 @@ fn bind_file_to_element(filp: *mut bindings::file, e: Rc>) // } } -// static int create_element_device(struct rros_element *e, -// struct rros_factory *fac) -// { -// struct rros_element *n; -// struct device *dev; -// dev_t rdev; -// u64 hlen; -// int ret; - -// /* -// * Do a quick hash check on the new element name, to make sure -// * device_register() won't trigger a kernel log splash because -// * of a naming conflict. -// */ -// hlen = hashlen_string("RROS", e->devname->name); - -// mutex_lock(&fac->hash_lock); - -// hash_for_each_possible(fac->name_hash, n, hash, hlen) -// if (!strcmp(n->devname->name, e->devname->name)) { -// mutex_unlock(&fac->hash_lock); -// goto fail_hash; -// } - -// hash_add(fac->name_hash, &e->hash, hlen); - -// mutex_unlock(&fac->hash_lock); - -// ret = do_element_visibility(e, fac, &rdev); -// if (ret) -// goto fail_visibility; - -// dev = create_sys_device(rdev, fac, e, rros_element_name(e)); -// if (IS_ERR(dev)) { -// ret = PTR_ERR(dev); -// goto fail_device; -// } - -// /* -// * Install fd on a private user element file only when we -// * cannot fail creating the device anymore. First take a -// * reference then install fd (which is a membar). -// */ -// if (!rros_element_is_public(e) && !rros_element_has_coredev(e)) { -// e->refs++; -// fd_install(e->fpriv.efd, e->fpriv.filp); -// } - -// e->dev = dev; - -// return 0; - -// /* -// * On error, public and/or core-owned elements should be -// * discarded by the caller. Private user elements must be -// * disposed of in this routine if we cannot give them a -// * device. -// */ -// fail_hash: -// if (!rros_element_is_public(e) && !rros_element_has_coredev(e)) -// fac->dispose(e); - -// return -EEXIST; - -// fail_device: -// if (rros_element_is_public(e)) { -// cdev_del(&e->cdev); -// } else if (!rros_element_has_coredev(e)) { -// put_unused_fd(e->fpriv.efd); -// filp_close(e->fpriv.filp, current->files); -// } - -// fail_visibility: -// mutex_lock(&fac->hash_lock); -// hash_del(&e->hash); -// mutex_unlock(&fac->hash_lock); - -// return ret; -// } - #[allow(dead_code)] fn rros_create_core_element_device( e: Rc>, @@ -780,7 +668,7 @@ fn rros_create_core_element_device( // } // } -// todo: The global variable should not use *mut to pass the value. +// TODO: The global variable should not use *mut to pass the value. pub fn rros_init_element( e: Rc>, fac: &'static mut SpinLock, @@ -877,7 +765,7 @@ fn rros_create_factory( let mut idevname = CStr::from_bytes_with_nul("clone\0".as_bytes())?; match flag { RrosFactoryType::SINGLE => { - //RROS_FACTORY_SINGLE + // RROS_FACTORY_SINGLE idevname = name; inside.class = Some(rros_class.clone()); inside.minor_map = Some(0); @@ -899,7 +787,6 @@ fn rros_create_factory( } // We use cdev_alloc to replace cdev_init. alloc_chrdev + cdev_alloc + cdev_add // chrdev_reg.as_mut().register::()?; - // } RrosFactoryType::CLONE => { // RROS_FACTORY_CLONE // create_element_class @@ -1166,7 +1053,7 @@ pub fn rros_early_init_factories( this_module, CStr::from_bytes_with_nul("rros\0".as_bytes())?.as_char_ptr(), )?)?; - // TODO: 创建一个结构体,实现rros_devnode + // TODO: create a structure to implement rros_devnode. Arc::get_mut(&mut rros_class) .unwrap() .set_devnode::(); @@ -1316,27 +1203,9 @@ impl RrosCloneReq { } } } -// struct rros_element_ids { -// __u32 minor; -// __u32 fundle; -// __u32 state_offset; -// }; - -// struct rros_clone_req { -// __u64 name_ptr; /* (const char __user *name) */ -// __u64 attrs_ptr; /* (void __user *attrs) */ -// __u32 clone_flags; -// /* Output on success: */ -// struct rros_element_ids eids; -// __u32 efd; -// }; #[allow(dead_code)] fn rros_index_factory_element() {} -// static inline void rros_index_factory_element(struct rros_element *e) -// { -// rros_index_element(&e->factory->index, e); -// } extern "C" { pub fn rust_helper_copy_from_user( @@ -1549,11 +1418,3 @@ pub fn rros_element_name(e: &RrosElement) -> *const c_types::c_char { } 0 as *const c_types::c_char } -// static inline const char * -// rros_element_name(struct rros_element *e) -// { -// if (e->devname) -// return e->devname->name; - -// return NULL; -// } diff --git a/kernel/rros/fifo.rs b/kernel/rros/fifo.rs index 4aeab908763a5..98f3dfebe8084 100644 --- a/kernel/rros/fifo.rs +++ b/kernel/rros/fifo.rs @@ -164,7 +164,7 @@ fn __rros_get_fifo_schedparam( p.unwrap().lock().fifo.prio = thread.unwrap().lock().cprio; } -//逻辑完整,未测试 +// The logic is complete, but haven't been tested. fn __rros_chk_fifo_schedparam( thread: Option>>, p: Option>>, @@ -204,7 +204,6 @@ fn __rros_ceil_fifo_priority(thread: Arc>, prio: i32 unsafe { (*thread.locked_data().get()).cprio = prio }; } -//测试通过 pub fn __rros_dequeue_fifo_thread(thread: Arc>) -> Result { let rq_next = thread.lock().rq_next.clone(); if rq_next.is_none() { @@ -213,14 +212,13 @@ pub fn __rros_dequeue_fifo_thread(thread: Arc>) -> R unsafe { // thread.lock().rq_next.clone().as_mut().unwrap().remove(); thread.lock().rq_next.as_mut().unwrap().as_mut().remove(); - //这里是否要释放? + // need a release here? } } Ok(0) } -//按优先级大小入队,注意这里要赋值rq_next---这个变量在出队的时候使用 -//测试通过 +// Enter the queue according to the priority. Note that rq_next must be assigned here---this variable is used when dequeuing. pub fn __rros_enqueue_fifo_thread(thread: Arc>) -> Result { let rq_ptr; match thread.lock().rq.clone() { @@ -236,7 +234,7 @@ pub fn __rros_enqueue_fifo_thread(thread: Arc>) -> R // pr_debug!("addr: {:p}", thread.lock().rq_next.clone().as_mut().unwrap()); } else { let mut p = q.head.prev; - //倒序遍历 + // Traverse in reverse order. loop { unsafe { let pos_cprio = p.unwrap().as_ref().value.lock().cprio; @@ -261,9 +259,6 @@ pub fn __rros_enqueue_fifo_thread(thread: Arc>) -> R Ok(0) } -//enqueue_fifo_thread是new_cprio <= pos_cprio -//requeue_fifo_thread是new_cprio < pos_cprio -//默认测试通过 pub fn __rros_requeue_fifo_thread(thread: Arc>) -> Result { unsafe { let rq_ptr; @@ -280,7 +275,7 @@ pub fn __rros_requeue_fifo_thread(thread: Arc>) -> R // pr_debug!("addr: {:p}", (*thread.locked_data().get()).rq_next.clone().as_mut().unwrap()); } else { let mut p = q.head.prev; - //倒序遍历 + // Traverse in reverse order. loop { let pos_cprio = (*(p.unwrap().as_ref().value).locked_data().get()).cprio; if p.unwrap().as_ptr() == &mut q.head as *mut Node>> @@ -305,92 +300,3 @@ pub fn __rros_requeue_fifo_thread(thread: Arc>) -> R Ok(0) } } - -// pub fn __rros_enqueue_fifo_thread(thread: Arc>) -> Result { -// let rq_ptr; -// match thread.lock().rq.clone() { -// Some(rq) => rq_ptr = rq, -// None => return Err(kernel::Error::EINVAL), -// } - -// let mut q = unsafe { (*rq_ptr).fifo.runnable.head.as_mut().unwrap() }; -// let new_cprio = thread.lock().cprio; -// if q.is_empty() { -// q.add_head(thread.clone()); -// unsafe { -// thread.lock().rq_next = Some(Node::new(q.head.prev.clone().unwrap().as_ref().value.clone())); -// } -// pr_debug!("addr: {:p}", thread.lock().rq_next.clone().as_mut().unwrap()); -// } else { -// let mut p = q.head.prev; -// //倒序遍历 -// while true { -// unsafe { -// let pos_cprio = p.unwrap().as_ref().value.lock().cprio; -// if p.unwrap().as_ptr() -// == &mut q.head as *mut Node>> -// || new_cprio <= pos_cprio -// { -// p.unwrap() -// .as_mut() -// .add(p.unwrap().as_ref().next.unwrap().as_ptr(), thread.clone()); -// thread.lock().rq_next = Some(Node::new(p.unwrap().as_ref().next.clone().unwrap().as_ref().value.clone())); -// break; -// } else { -// p = p.unwrap().as_ref().prev; -// } -// } -// if p.unwrap().as_ptr() == q.head.prev.unwrap().as_ptr() { -// break; -// } -// } -// } -// Ok(0) -// } - -// //enqueue_fifo_thread是new_cprio <= pos_cprio -// //requeue_fifo_thread是new_cprio < pos_cprio -// //默认测试通过 -// pub fn __rros_requeue_fifo_thread(thread: Arc>) -> Result { -// unsafe { -// let rq_ptr; -// match (*thread.locked_data().get()).rq.clone() { -// Some(rq) => rq_ptr = rq, -// None => return Err(kernel::Error::EINVAL), -// } -// let mut q = unsafe { (*rq_ptr).fifo.runnable.head.as_mut().unwrap() }; -// let new_cprio = (*thread.locked_data().get()).cprio; -// if q.is_empty() { -// q.add_head(thread.clone()); -// unsafe { -// (*thread.locked_data().get()).rq_next = Some(Node::new(q.head.prev.clone().unwrap().as_ref().value.clone())); -// } -// pr_debug!("addr: {:p}", (*thread.locked_data().get()).rq_next.clone().as_mut().unwrap()); -// } else { -// let mut p = q.head.prev; -// //倒序遍历 -// while true { -// unsafe { -// let pos_cprio = (*(p.unwrap().as_ref().value).locked_data().get()).cprio; -// if p.unwrap().as_ptr() -// == &mut q.head as *mut Node>> -// || new_cprio < pos_cprio -// { -// p.unwrap() -// .as_mut() -// .add(p.unwrap().as_ref().next.unwrap().as_ptr(), thread.clone()); -// (*thread.locked_data().get()).rq_next = -// Some(Node::new(p.unwrap().as_ref().next.clone().unwrap().as_ref().value.clone())); -// break; -// } else { -// p = p.unwrap().as_ref().prev; -// } -// } -// if p.unwrap().as_ptr() == q.head.prev.unwrap().as_ptr() { -// break; -// } -// } -// } -// Ok(0) -// } -// } diff --git a/kernel/rros/fifo_test.rs b/kernel/rros/fifo_test.rs index 10a8b85ecdf12..c6f78b5929f5e 100644 --- a/kernel/rros/fifo_test.rs +++ b/kernel/rros/fifo_test.rs @@ -1,5 +1,3 @@ -//fifo_test.rs测试文件 -//用于测试fifo.rs里的函数正确性 use crate::{fifo::*, sched::*, thread::*, timer::*, RROS_OOB_CPUS}; use core::clone::Clone; use kernel::{c_str, cpumask::CpumaskT, prelude::*, spinlock_init, sync::Lock, sync::SpinLock}; @@ -20,14 +18,13 @@ pub fn test_init_thread(thread: Arc>, prio: i32) -> Result< Ok(0) } -//测试通过 #[allow(dead_code)] pub fn test_rros_enqueue_fifo_thread() -> Result { pr_debug!("~~~test_rros_enqueue_fifo_thread begin~~~"); unsafe { let mut length; - //创建thread1 + // create thread1 let mut t1 = SpinLock::new(RrosThread::new().unwrap()); let pinned = Pin::new_unchecked(&mut t1); spinlock_init!(pinned, "create_thread1"); @@ -44,7 +41,7 @@ pub fn test_rros_enqueue_fifo_thread() -> Result { test_init_thread(thread1.clone(), 22)?; - //创建thread2 + // create thread2 let mut t2 = SpinLock::new(RrosThread::new().unwrap()); let pinned = Pin::new_unchecked(&mut t2); spinlock_init!(pinned, "create_thread1"); @@ -61,7 +58,7 @@ pub fn test_rros_enqueue_fifo_thread() -> Result { test_init_thread(thread2.clone(), 33)?; - // //创建thread3 + // // create thread3 let mut t3 = SpinLock::new(RrosThread::new().unwrap()); let pinned = Pin::new_unchecked(&mut t3); spinlock_init!(pinned, "create_thread1"); @@ -100,7 +97,7 @@ pub fn test_rros_enqueue_fifo_thread() -> Result { pr_debug!("test_rros_enqueue_fifo_thread: length is {}", length); pr_debug!("~~~test_rros_enqueue_fifo_thread end~~~"); - //__rros_dequeue_fifo_thread测试通过 + //__rros_dequeue_fifo_thread passed test. pr_debug!("~~~test_rros_dequeue_fifo_thread begin~~~"); __rros_dequeue_fifo_thread(thread1.clone())?; @@ -121,7 +118,6 @@ pub fn test_rros_enqueue_fifo_thread() -> Result { } // TODO: Add a config for test functions. -//测试通过,在上面 #[allow(dead_code)] pub fn test_rros_dequeue_fifo_thread() -> Result { Ok(0) diff --git a/kernel/rros/file.rs b/kernel/rros/file.rs index af4a483e4713a..5bd107cabb4ad 100644 --- a/kernel/rros/file.rs +++ b/kernel/rros/file.rs @@ -156,7 +156,7 @@ pub fn index_rfd(rfd: RrosFd, _filp: *mut bindings::file) -> Result { /// Returns a reference to the rfd corresponding to the fd. pub fn lookup_rfd(fd: u32, _files: &mut FilesStruct) -> Option<*mut RrosFd> { let flags = FD_TREE.irq_lock_noguard(); - // get_mut和锁的get_mut重名了,所以用unsafe了 + // `get_mut` has the same name as the lock's `get_mut`, so unsafe is used. if let Some(rfd) = unsafe { (*FD_TREE.locked_data().get()).get_mut(&fd) } { FD_TREE.irq_unlock_noguard(flags); return Some(rfd as *mut RrosFd); @@ -213,13 +213,6 @@ no_mangle_function_declaration! { } } -// fdt_lock held, irqs off. CAUTION: resched required on exit. -// static void drop_watchpoints(struct rros_fd *efd) -// { -// if (!list_empty(&efd->poll_nodes)) -// rros_drop_watchpoints(&efd->poll_nodes); -// } - // in-band, caller holds files->file_lock no_mangle_function_declaration! { pub fn rust_uninstall_inband_fd(fd: u32, filp: *mut bindings::file, files: FilesStruct) { @@ -281,7 +274,7 @@ pub fn rros_get_fileref(rfilp: &mut RrosFile) -> Result { } pub fn rros_get_file(fd: u32) -> Option> { - // TODO: 暂时改成NonNull + // TODO: Temporarily changed to NonNull. let rfd = lookup_rfd(fd, &mut FilesStruct::from_ptr(unsafe { (*Task::current_ptr()).files })); match rfd { diff --git a/kernel/rros/flags.rs b/kernel/rros/flags.rs index 6344385bd211b..d4384ee0e8424 100644 --- a/kernel/rros/flags.rs +++ b/kernel/rros/flags.rs @@ -45,6 +45,7 @@ impl RrosFlag { // } // self.raised // } + #[inline] pub fn read(&self) -> bool { if self.raised.get() { @@ -55,7 +56,7 @@ impl RrosFlag { } #[inline] pub fn wait(&mut self) -> i32 { - // TODO:尝试绕开不可变借用的限制 + // TODO: Try to get around the limitations of immutable borrowing. let mut x = unsafe { NonNull::new_unchecked(&self.wait as *const _ as *mut RrosWaitQueue) }; unsafe { x.as_mut() diff --git a/kernel/rros/init.rs b/kernel/rros/init.rs index 33e8f3d8924bd..523667b8cdf8c 100644 --- a/kernel/rros/init.rs +++ b/kernel/rros/init.rs @@ -11,8 +11,6 @@ //! This file is the entry point of the rros kernel module. //! Importing necessary features and modules -// use alloc::vec; -// use alloc::vec; use kernel::{ bindings, c_types, chrdev, cpumask, dovetail, irqstage, percpu, prelude::*, str::CStr, task, }; @@ -343,7 +341,7 @@ impl KernelModule for Rros { } let cpu_online_mask = unsafe { cpumask::read_cpu_online_mask() }; - //size_of 为0,align_of为4,alloc报错 + // When size_of is 0, align_of is 4, alloc reports an error. // unsafe {RROS_MACHINE_CPUDATA = // percpu::alloc_per_cpu(size_of::() as usize, // align_of::() as usize) as *mut RrosMachineCpuData}; diff --git a/kernel/rros/list.rs b/kernel/rros/list.rs index b6b6853d79b59..9dcff3195439f 100644 --- a/kernel/rros/list.rs +++ b/kernel/rros/list.rs @@ -15,7 +15,7 @@ impl Default for ListHead { } impl ListHead { - //添加节点到self和next之间 + // Add node between self and next. #[allow(dead_code)] pub fn add(&mut self, new: *mut ListHead) { if self.is_empty() { @@ -34,19 +34,19 @@ impl ListHead { self.next = new; } - //空双向链表next和prev都指向自己 + // The empty doubly linked list next and prev both point to themselves. #[allow(dead_code)] pub fn is_empty(&self) -> bool { self.next == null_mut() && self.prev == null_mut() } - //list是不是head的最后一个节点 + // Just whether list the last node of head. #[allow(dead_code)] pub fn last_is(&self, list: *mut ListHead) -> bool { self.prev == list } - //释放本身节点 + // Release own node. pub fn list_drop(&mut self) { if !self.is_empty() { if self.next == self.prev { diff --git a/kernel/rros/list_test.rs b/kernel/rros/list_test.rs index 5c99339211bbc..34e81d9313c52 100644 --- a/kernel/rros/list_test.rs +++ b/kernel/rros/list_test.rs @@ -1,4 +1,3 @@ -//list.rs测试文件! use crate::list::*; use crate::{list_entry, list_first_entry, list_last_entry}; use kernel::prelude::*; @@ -41,7 +40,7 @@ fn test_list_method() { let mut t1 = ListHead::default(); let mut t2 = ListHead::default(); - //测试add + // Test add. head.add(&mut t1 as *mut ListHead); head.add(&mut t2 as *mut ListHead); if traverse_list(&head) == 3 { @@ -50,7 +49,7 @@ fn test_list_method() { pr_debug!("test_list_add failed"); } - //测试list_drop + // Test list_drop. unsafe { (*head.next).list_drop(); } @@ -61,7 +60,7 @@ fn test_list_method() { pr_debug!("test_list_drop failed"); } - //测试last_is + // Test last_is. if head.last_is(&mut t1 as *mut ListHead) { pr_debug!("test_list_last_is success"); } else { @@ -72,7 +71,7 @@ fn test_list_method() { (*head.next).list_drop(); } - //测试empty + // Test empty. if head.is_empty() { pr_debug!("test_list_is_empty success"); } else { diff --git a/kernel/rros/memory.rs b/kernel/rros/memory.rs index 1c6d9eede139d..15a380f2e4e20 100644 --- a/kernel/rros/memory.rs +++ b/kernel/rros/memory.rs @@ -194,7 +194,6 @@ fn init_shared_heap(heap: Arc>) -> Result { Ok(0) } -// #[allow(dead_code)] fn rros_init_heap(heap: Arc>, membase: *mut u8, size: usize) -> Result { let nrpages; diff --git a/kernel/rros/memory_test.rs b/kernel/rros/memory_test.rs index f26cedf1490e1..4fb70410fbe1d 100644 --- a/kernel/rros/memory_test.rs +++ b/kernel/rros/memory_test.rs @@ -116,7 +116,8 @@ struct MemTestxy { z: i32, } -//测试申请到的内存直接转换为结构体指针:结论是可以直接使用 +// The memory requested by the test is directly converted into a structure pointer: +// the conclusion is that it can be used directly. #[allow(dead_code)] pub fn mem_test2() -> Result { let vmalloc_res = vmalloc::c_vmalloc(1024 as u64); @@ -144,7 +145,6 @@ struct Pageinfo { size: u32, } -//测试完成: #[allow(dead_code)] fn test_rbtree() -> Result { pr_debug!("~~~test_rbtree begin~~~"); @@ -170,7 +170,7 @@ fn test_rbtree() -> Result { root.insert(node1); root.insert(node2); root.insert(node3); - //遍历红黑树方式: + // Traverse a red-black tree: for item in root.iter() { pr_debug!("item.0 is {}", item.0); pr_debug!("item.1.size is {}", item.1.size); @@ -179,13 +179,11 @@ fn test_rbtree() -> Result { Ok(0) } -//测试初始化系统堆 #[allow(dead_code)] fn test_init_system_heap() { let _ret = init_system_heap(); } -//测试系统堆插入节点——测试通过 #[allow(dead_code)] fn test_insert_system_heap() -> Result { pr_debug!("~~~test_insert_system_heap begin~~~"); @@ -215,11 +213,9 @@ fn test_insert_system_heap() -> Result { Ok(0) } -//测试小内存的分配与回收 #[allow(dead_code)] fn test_small_chunk() {} -//多次分配回收 #[allow(dead_code)] fn test_chunk() { pr_debug!("~~~test_chunk: begin~~~"); @@ -229,12 +225,11 @@ fn test_chunk() { pr_debug!("~~~test_chunk: end~~~"); } -//测试分配chunk #[allow(dead_code)] fn test_alloc_chunk() { pr_debug!("~~~test_alloc_chunk begin~~~"); unsafe { - //查看当前RROS_SYSTEM_HEAP size树的根 + // View the root of the current RROS_SYSTEM_HEAP size tree. let rb_node = RROS_SYSTEM_HEAP.size_tree.clone().unwrap().rb_node; let mut p = container_of!(rb_node, RrosHeapRange, size_node); let raw_size = (*p).size; @@ -265,7 +260,7 @@ fn test_alloc_chunk() { "test_alloc_chunk: raw_size - new_size = {}", raw_size - new_size ); - //测试回收 + // Test recycle. pr_debug!("~~~test_alloc_chunk: test free begin~~~"); RROS_SYSTEM_HEAP.rros_free_chunk(addr); p = container_of!(rb_node, RrosHeapRange, size_node); @@ -276,7 +271,6 @@ fn test_alloc_chunk() { pr_debug!("~~~test_alloc_chunk end~~~"); } -//测试box的自定义分配器 #[allow(dead_code)] fn test_box_allocator() { pr_debug!("test_box_allocator: begin"); diff --git a/kernel/rros/monitor.rs b/kernel/rros/monitor.rs index 0ec366b7ad918..81198b7e72959 100644 --- a/kernel/rros/monitor.rs +++ b/kernel/rros/monitor.rs @@ -100,7 +100,6 @@ impl RrosMonitor { } } -// #[derive(Copy, Clone)] pub struct RrosMonitorStateItemGate { #[allow(dead_code)] owner: AtomicUsize, @@ -112,7 +111,6 @@ pub struct RrosMonitorStateItemGate { nesting: u32, } -// #[derive(Copy, Clone)] pub struct RrosMonitorStateItemEvent { #[allow(dead_code)] value: AtomicUsize, @@ -126,6 +124,7 @@ pub struct RrosMonitorStateItemEvent { // gate: RrosMonitorState_item_gate, // event: RrosMonitorState_item_event, // } + #[allow(dead_code)] pub enum RrosMonitorStateItem { Gate(RrosMonitorStateItemGate), @@ -187,7 +186,7 @@ pub const CLOCK_MONOTONIC: u32 = 1; pub const CLOCK_REALTIME: u32 = 0; #[allow(dead_code)] -const CONFIG_RROS_MONITOR: usize = 0; //未知 +const CONFIG_RROS_MONITOR: usize = 0; // Unknown. #[allow(dead_code)] pub fn monitor_factory_build( diff --git a/kernel/rros/mutex.rs b/kernel/rros/mutex.rs index 115417b4192d4..54526cdc68db4 100644 --- a/kernel/rros/mutex.rs +++ b/kernel/rros/mutex.rs @@ -102,9 +102,6 @@ pub fn raw_spin_unlock(lock: *mut bindings::hard_spinlock_t) { unsafe { rust_helper_raw_spin_unlock }; } -// #define for_each_rros_mutex_waiter(__pos, __mutex) \ -// list_for_each_entry(__pos, &(__mutex)->wchan.wait_list, wait_next) - pub fn get_ceiling_value(mutex: *mut RrosMutex) -> u32 { let ceiling_ref = unsafe { (*mutex).ceiling_ref }; if ceiling_ref < 1 { @@ -279,14 +276,14 @@ pub fn ceil_owner_priority( if (*boosters).is_empty() { (*boosters).add_head((*(*mutex).next_booster).value.clone()); } else { - let mut flag = 1; // flag指示是否到头 + let mut flag = 1; for i in (*boosters).len()..=1 { let wprio_in_list = (*(*(*boosters).get_by_index(i).unwrap()) .value .clone() .locked_data() .get()) - .wprio; + .wprio; if (*mutex).wprio <= wprio_in_list { flag = 0; (*boosters).enqueue_by_index(i, (*(*mutex).next_booster).value.clone()); @@ -671,7 +668,7 @@ pub fn finish_mutex_wait(mutex: *mut RrosMutex) { if (*boosters).is_empty() { (*boosters).add_head((*(*mutex).next_booster).value.clone()); } else { - let mut flag = 1; // flag指示是否到头 + let mut flag = 1; for i in (*boosters).len()..=1 { let wprio_in_list = (*(*boosters) .get_by_index(i) @@ -851,7 +848,7 @@ pub fn rros_lock_mutex_timeout( let wait_next = (*curr.locked_data().get()).wait_next; (*(*mutex).wchan.wait_list).add_head((*wait_next).value.clone()); } else { - let mut flag = 1; // flag指示是否到头 + let mut flag = 1; for i in (*(*mutex).wchan.wait_list).len()..=1 { let curr_wprio = (*(*curr).locked_data().get()).wprio; let wprio_in_list = (*(*(*mutex).wchan.wait_list) @@ -861,7 +858,7 @@ pub fn rros_lock_mutex_timeout( .clone() .locked_data() .get()) - .wprio; + .wprio; if curr_wprio <= wprio_in_list { flag = 0; let wait_next = (*curr.locked_data().get()).wait_next; @@ -889,7 +886,7 @@ pub fn rros_lock_mutex_timeout( if (*boosters).is_empty() { (*boosters).add_head((*((*mutex).next_booster)).value.clone()); } else { - let mut flag = 1; // flag指示是否到头 + let mut flag = 1; for i in (*boosters).len()..=1 { let wprio_in_list = (*(*boosters) .get_by_index(i) @@ -898,7 +895,7 @@ pub fn rros_lock_mutex_timeout( .clone() .locked_data() .get()) - .wprio; + .wprio; if (*mutex).wprio <= wprio_in_list { flag = 0; (*boosters) @@ -921,7 +918,7 @@ pub fn rros_lock_mutex_timeout( let wait_next = (*curr.locked_data().get()).wait_next; (*(*mutex).wchan.wait_list).add_head((*wait_next).value.clone()); } else { - let mut flag = 1; // flag指示是否到头 + let mut flag = 1; for i in (*(*mutex).wchan.wait_list).len()..=1 { let curr_wprio = (*curr.locked_data().get()).wprio; let wprio_in_list = (*(*(*mutex).wchan.wait_list) @@ -931,7 +928,7 @@ pub fn rros_lock_mutex_timeout( .clone() .locked_data() .get()) - .wprio; + .wprio; if curr_wprio <= wprio_in_list { flag = 0; let wait_next = (*curr.locked_data().get()).wait_next; @@ -1168,7 +1165,7 @@ pub fn rros_reorder_mutex_wait( if (*(*mutex).wchan.wait_list).is_empty() { (*(*mutex).wchan.wait_list).add_head((*((*waiter_ptr).wait_next)).value.clone()); } else { - let mut flag = 1; // flag指示是否到头 + let mut flag = 1; for i in (*(*mutex).wchan.wait_list).len()..=1 { let wprio_in_list = (*(*(*mutex).wchan.wait_list) .get_by_index(i) @@ -1177,7 +1174,7 @@ pub fn rros_reorder_mutex_wait( .clone() .locked_data() .get()) - .wprio; + .wprio; if (*waiter_ptr).wprio <= wprio_in_list { flag = 0; (*(*mutex).wchan.wait_list) @@ -1210,7 +1207,7 @@ pub fn rros_reorder_mutex_wait( if (*boosters).is_empty() { (*boosters).add_head((*((*mutex).next_booster)).value.clone()); } else { - let mut flag = 1; // flag指示是否到头 + let mut flag = 1; for i in (*boosters).len()..=1 { let wprio_in_list = (*(*boosters) .get_by_index(i) @@ -1219,7 +1216,7 @@ pub fn rros_reorder_mutex_wait( .clone() .locked_data() .get()) - .wprio; + .wprio; if (*mutex).wprio <= wprio_in_list { flag = 0; (*boosters).enqueue_by_index(i, (*((*mutex).next_booster)).value.clone()); diff --git a/kernel/rros/net/device.rs b/kernel/rros/net/device.rs index ed99e0a61c9b1..e87598cd098ca 100644 --- a/kernel/rros/net/device.rs +++ b/kernel/rros/net/device.rs @@ -285,7 +285,7 @@ impl NetDevice { .unwrap(); est.rx_handler = start_handler_thread(func, c_str!("rros oob net rx handler")).unwrap(); - // 只有有带外能力的才需要 + // Only those with out-of-band capabilities are required. if real_dev.is_oob_capable() { // rros_init_flag(&est->tx_flag); @@ -312,7 +312,7 @@ impl NetDevice { pr_crit!("enable oob port success"); return 0; - // TODO: 优雅地处理一下异常 + // TODO: Handle exceptions gracefully. // rros_stop_kthread(est->rx_handler); // rros_destroy_flag(&est->tx_flag); // fail_start_rx: diff --git a/kernel/rros/net/ethernet/input.rs b/kernel/rros/net/ethernet/input.rs index 01d51bd7aee3b..3f905163100de 100644 --- a/kernel/rros/net/ethernet/input.rs +++ b/kernel/rros/net/ethernet/input.rs @@ -54,7 +54,7 @@ fn untag(mut skb: RrosSkBuff, ehdr: &mut VlanEthhdr, mac_hdr: *mut u8) -> bool { pub fn rros_net_ether_accept(skb: RrosSkBuff) -> bool { extern "C" { - fn rust_helper_test_bit(nr: i32, addr: *const usize) -> bool; // TODO: 这里addr应该是volatile的 + fn rust_helper_test_bit(nr: i32, addr: *const usize) -> bool; // TODO: The addr here should be volatile. fn rust_helper_eth_type_vlan(ethertype: be16) -> bool; #[allow(improper_ctypes)] fn rust_helper__vlan_hwaccel_get_tag( @@ -78,7 +78,7 @@ pub fn rros_net_ether_accept(skb: RrosSkBuff) -> bool { pr_debug!("tag && test_bit\n"); return pick(skb); } - // TODO:下面这条路径没有测试过 + // TODO: The following path has not been tested. if skb.vlan_present() == 0 && unsafe { rust_helper_eth_type_vlan(be16::new(skb.protocol)) } { pr_debug!("this path is not tested\n"); let mac_hdr = unsafe { skb.head.offset(skb.mac_header as isize) as *mut u8 }; @@ -150,10 +150,6 @@ pub fn rros_net_store_vlans(buf: *const u8, len: usize) -> i32 { return len as i32; } -// ssize_t rros_net_show_vlans(char *buf, SizeT len) -// { -// return scnprintf(buf, len, "%*pbl\n", VLAN_N_VID, VLAN_MAP); -// } #[allow(unused)] pub fn rros_show_vlans() { diff --git a/kernel/rros/net/output.rs b/kernel/rros/net/output.rs index d4a5c8fb2b0f8..e63ae465d73c2 100644 --- a/kernel/rros/net/output.rs +++ b/kernel/rros/net/output.rs @@ -16,7 +16,7 @@ use kernel::{ use super::skb::RrosSkBuff; // NOTE:initialize in rros_net_init_tx -// TODO: 这里的实现没用DEFINE_PER_CPU,因为Rust还没有支持静态定义的percpu变量 +// TODO: The implementation here does not use DEFINE_PER_CPU because Rust does not yet support statically defined percpu variables. init_static_sync! { static OOB_TX_RELAY : SpinLock = RrosSkbQueueInner::default(); } @@ -105,7 +105,7 @@ fn skb_inband_xmit_backlog() { } let mut list = bindings::list_head::default(); init_list_head!(&mut list); - let flags = OOB_TX_RELAY.irq_lock_noguard(); // TODO: 是否需要lock + let flags = OOB_TX_RELAY.irq_lock_noguard(); // TODO: Whether lock is required. if unsafe { (*OOB_TX_RELAY.locked_data().get()).move_queue(&mut list) } { list_for_each_entry_safe!( diff --git a/kernel/rros/net/packet.rs b/kernel/rros/net/packet.rs index 856e5d0ef059a..4c8e0e5c33c2b 100644 --- a/kernel/rros/net/packet.rs +++ b/kernel/rros/net/packet.rs @@ -354,7 +354,7 @@ impl RrosNetProto for EthernetRrosNetProto { msg: *mut UserOobMsghdr, iov_vec: &mut [Iovec], ) -> isize { - // 用户态 + // User mode. extern "C" { fn rust_helper_raw_get_user(result: *mut u32, addr: *const u32) -> isize; fn rust_helper_raw_copy_from_user(dst: *mut u8, src: *const u8, size: usize) -> usize; @@ -521,7 +521,7 @@ fn __packet_deliver(rxq: &mut RrosNetRxqueue, skb: &mut RrosSkBuff, protocol: be let dev = skb.dev().unwrap(); let mut delivered = false; - // list_for_each_entry,这里有continue和break,因此直接写了 + // list_for_each_entry, there are `continue` and `break` here, so write it directly. let mut rsk = list_first_entry!(&mut rxq.subscribers, RrosSocket, next_sub); while !list_entry_is_head!(rsk, &mut rxq.subscribers, next_sub) { let ref_rsk = unsafe { &mut *rsk }; @@ -591,7 +591,6 @@ pub fn rros_net_packet_deliver(skb: &mut RrosSkBuff) -> bool { // return packet_deliver(skb, be16::new(skb.protocol)); false } -// deliver fn find_xmit_device(rsk: &mut RrosSocket, msghdr: &mut UserOobMsghdr) -> Result { extern "C" { diff --git a/kernel/rros/net/skb.rs b/kernel/rros/net/skb.rs index e24bf2ded4fd9..a7a8ea905f92f 100644 --- a/kernel/rros/net/skb.rs +++ b/kernel/rros/net/skb.rs @@ -356,7 +356,7 @@ impl RrosSkBuff { // // rros_signal_poll_events(&est->poll_head, POLLOUT|POLLWRNORM); // rros poll } fn free_skb(&mut self) { - // 对应 free_skb + // Corresponds to free_skb. extern "C" { #[allow(improper_ctypes)] fn skb_release_oob_skb(skb: *mut bindings::sk_buff, dref: *mut i32) -> bool; @@ -458,7 +458,7 @@ pub fn free_skb_list(list: *mut bindings::list_head) { // pub struct RROSNetSkbQueue{ // pub queue : bindings::list_head, -// pub lock : SpinLock<()>, //不直接封装在上面是因为不够灵活,以后可以重新封装下 +// pub lock : SpinLock<()>, // It is not packaged directly because it is not flexible enough. It can be re-encapsulated later. // // phantom : core::marker::PhantomData, // } @@ -634,7 +634,6 @@ fn skb_recycler(_work: &mut RrosWork) -> i32 { 0 } -/// 初始化函数 pub fn rros_net_init_pools() -> Result<()> { extern "C" { fn rust_helper_list_add(new: *mut bindings::list_head, head: *mut bindings::list_head); diff --git a/kernel/rros/net/socket.rs b/kernel/rros/net/socket.rs index 300228f1b641a..1405222d95283 100644 --- a/kernel/rros/net/socket.rs +++ b/kernel/rros/net/socket.rs @@ -185,7 +185,7 @@ impl RrosSocket { return 0; } let arg = unsafe { NonNull::new_unchecked(skb) }; - // TODO: 绕开mutable borrow检查 + // TODO: Bypass mutable borrow check let wmem_wait = unsafe { &mut *(&self.wmem_wait as *const _ as *mut RrosWaitQueue) }; return wmem_wait.wait_timeout(timeout, tmode, || self.charge_socket_wmem(arg)); } @@ -307,7 +307,7 @@ impl CreateSocket for CreateRrosSocket { // * attached to the out-of-band core in sock_oob_attach(). // */ // unsafe{(*sock).sk_protocol = protocol}; -// // sk_refcnt_debug_inc(sk); TODO: 用于Debug的东西 +// // sk_refcnt_debug_inc(sk); TODO: Stuff for Debug // unsafe{(*sock).sk_destruct = &destroy_rros_socket as ::core::option::Option}; // // unsafe{local_bh_disable();} @@ -600,10 +600,10 @@ pub fn rros_export_iov(iov_vec: &mut [Iovec], mut data: *mut u8, len: usize) -> // // bindings::local_bh_disable(); // // unsafe{bindings::sock_prot_inuse_add(rust_helper_sock_net(sk),sk_prot!(sk), -1 as c_types::c_int)}; // // bindings::local_bh_enable(); -// // sk_refcnt_debug_dec(sk); // TODO: 没有实现,rros中用于debug +// // sk_refcnt_debug_dec(sk); // TODO: Not implemented, used for debugging in rros. // } -// // todo: 字符串用什么格式? +// // TODO: What format is used for strings? // #[no_mangle] // fn sock_oob_read(flip:File, buf:*mut u8, count:usize, pos:off_t) -> SsizeT // { @@ -621,7 +621,7 @@ pub fn rros_export_iov(iov_vec: &mut [Iovec], mut data: *mut u8, len: usize) -> // } // let rsk = rsk.unwrap(); // let proto = rsk.proto.as_mut().unwrap(); -// // TODO: 接口 +// // TODO: Interface // proto.oob_receive(rsk,proto,core::ptr::null(),&iov as *const bindings::iovec,1 as c_types::c_int) // } @@ -641,7 +641,7 @@ pub fn rros_export_iov(iov_vec: &mut [Iovec], mut data: *mut u8, len: usize) -> // iov.iov_len = count as u64; // } // let proto = rsk.proto.as_mut(); -// // TODO: oob_send接口 +// // TODO: Interface `oob_send`. // proto.oob_send() // } @@ -677,7 +677,7 @@ pub fn rros_export_iov(iov_vec: &mut [Iovec], mut data: *mut u8, len: usize) -> // #[inline] // fn get_domain_hash(af_domain : i32) -> u32{ -// /// 计算协议哈希 +// /// Calculate protocol hash. // let hsrc : u32 = af_domain as u32; // extern "C"{ // fn rust_helper_jhash2(k :*const u32, length:u32, initval:u32) -> u32; @@ -696,7 +696,7 @@ fn find_oob_proto( _type_: i32, _protocol: be16, ) -> Option<&'static impl RrosNetProto> { - // TODO: 支持更多协议 + // TODO: Support more protocols. // let hkey = get_domain_hash(domain); // let gurad = domain_hash.lock(); // drop(gurad); diff --git a/kernel/rros/proxy.rs b/kernel/rros/proxy.rs index 9388eb8b6d04f..16257612b8b7d 100644 --- a/kernel/rros/proxy.rs +++ b/kernel/rros/proxy.rs @@ -78,7 +78,6 @@ impl ProxyRing { } } -// oob_write -> write pub struct ProxyOut { pub ring: ProxyRing, } @@ -641,41 +640,6 @@ pub fn proxy_oob_read(filp: &File, data: &mut T) -> isize { } } -// static __poll_t proxy_oob_poll(struct file *filp, -// struct oob_poll_wait *wait) -// { -// struct rros_proxy *proxy = element_of(filp, struct rros_proxy); -// struct proxy_ring *oring = &proxy->output.ring; -// struct proxy_ring *iring = &proxy->input.ring; -// __poll_t ret = 0; -// int peek; - -// if (!(proxy_is_readable(proxy) || proxy_is_writable(proxy))) -// return POLLERR; - -// rros_poll_watch(&proxy->poll_head, wait, NULL); - -// if (proxy_is_writable(proxy) && -// atomic_read(&oring->fillsz) < oring->bufsz) -// ret = POLLOUT|POLLWRNORM; - -// /* -// * If the input ring is empty, kick the worker to perform a -// * readahead as a last resort. -// */ -// if (proxy_is_readable(proxy)) { -// if (atomic_read(&iring->fillsz) > 0) -// ret |= POLLIN|POLLRDNORM; -// else if (atomic_read(&proxy->input.reqsz) == 0) { -// peek = iring->granularity ?: 1; -// atomic_add(peek, &proxy->input.reqsz); -// rros_call_inband_from(&iring->relay_work, iring->wq); -// } -// } - -// return ret; -// } - pub fn proxy_write(filp: &File, data: &mut T) -> isize { let fbind: *const RrosFileBinding = unsafe { (*filp.get_ptr()).private_data as *const RrosFileBinding }; let proxy = unsafe { (*((*fbind).element)).pointer as *mut RrosProxy }; @@ -743,63 +707,6 @@ pub fn proxy_read(filp: &File, data: &mut T) -> isize { ret } -// static __poll_t proxy_poll(struct file *filp, poll_table *wait) -// { -// struct rros_proxy *proxy = element_of(filp, struct rros_proxy); -// struct proxy_ring *oring = &proxy->output.ring; -// struct proxy_ring *iring = &proxy->input.ring; -// __poll_t ret = 0; - -// if (!(proxy_is_readable(proxy) || proxy_is_writable(proxy))) -// return POLLERR; - -// if (proxy_is_writable(proxy)) { -// poll_wait(filp, &oring->inband_wait, wait); -// if (atomic_read(&oring->fillsz) < oring->bufsz) -// ret = POLLOUT|POLLWRNORM; -// } - -// if (proxy_is_readable(proxy)) { -// poll_wait(filp, &iring->inband_wait, wait); -// if (atomic_read(&iring->fillsz) > 0) -// ret |= POLLIN|POLLRDNORM; -// else if (proxy->filp->f_op->poll) { -// ret = proxy->filp->f_op->poll(proxy->filp, wait); -// ret &= POLLIN|POLLRDNORM; -// } -// } - -// return ret; -// } - -// static int proxy_mmap(struct file *filp, struct vm_area_struct *vma) -// { -// struct rros_proxy *proxy = element_of(filp, struct rros_proxy); -// struct file *mapfilp = proxy->filp; -// int ret; - -// if (mapfilp->f_op->mmap == NULL) -// return -ENODEV; - -// vma->vm_file = get_file(mapfilp); - -// /* -// * Since the mapper element impersonates a different file, we -// * need to swap references: if the mapping call fails, we have -// * to drop the reference on the target file we just took on -// * entry; if it succeeds, then we have to drop the reference -// * on the mapper file do_mmap_pgoff() acquired before calling -// * us. -// */ -// ret = call_mmap(mapfilp, vma); -// if (ret) -// fput(mapfilp); -// else -// fput(filp); - -// return ret; -// } - pub fn init_output_ring(proxy: &mut RrosProxy, bufsz: u32, granularity: u32) -> Result { let ring = &mut proxy.output.ring; let bufmem = c_kzalloc(bufsz as u64); diff --git a/kernel/rros/rros/latmus.rs b/kernel/rros/rros/latmus.rs index 6d4a5e49e38eb..2baabd9d5166c 100644 --- a/kernel/rros/rros/latmus.rs +++ b/kernel/rros/rros/latmus.rs @@ -4,7 +4,6 @@ use crate::{ }; use kernel::prelude::*; use kernel::{c_str, c_types, ktime}; -// use rros::thread_test::KthreadRunner; static mut KTHREAD_RUNNER_1: KthreadRunner = KthreadRunner::new_empty(); @@ -171,55 +170,6 @@ fn add_measurement_sample(runner: &mut KthreadRunner, timestamp: ktime::KtimeT) 0 } -// static int add_measurement_sample(struct latmus_runner *runner, -// ktime_t timestamp) -// { -// struct runner_state *state = &runner->state; -// ktime_t period = runner->period; -// int delta, cell, offset_delta; - -// /* Skip samples in warmup time. */ -// if (runner->warmup_samples < runner->warmup_limit) { -// runner->warmup_samples++; -// state->ideal = ktime_add(state->ideal, period); -// return 0; -// } - -// delta = (int)ktime_to_ns(ktime_sub(timestamp, state->ideal)); -// offset_delta = delta - state->offset; -// if (offset_delta < state->min_lat) -// state->min_lat = offset_delta; -// if (offset_delta > state->max_lat) -// state->max_lat = offset_delta; -// if (offset_delta > state->allmax_lat) { -// state->allmax_lat = offset_delta; -// trace_rros_latspot(offset_delta); -// trace_rros_trigger("latmus"); -// } - -// if (runner->histogram) { -// cell = (offset_delta < 0 ? -offset_delta : offset_delta) / 1000; /* us */ -// if (cell >= runner->hcells) -// cell = runner->hcells - 1; -// runner->histogram[cell]++; -// } - -// state->sum += offset_delta; -// state->ideal = ktime_add(state->ideal, period); - -// while (delta > 0 && -// (unsigned int)delta > ktime_to_ns(period)) { /* period > 0 */ -// state->overruns++; -// state->ideal = ktime_add(state->ideal, period); -// delta -= ktime_to_ns(period); -// } - -// if (++state->cur_samples >= state->max_samples) -// send_measurement(runner); - -// return 0; /* Always keep going. */ -// } - // TODO: move this to a file // struct Latmus; diff --git a/kernel/rros/sched.rs b/kernel/rros/sched.rs index 3fcf1ccc5ba01..84602c0955b3a 100644 --- a/kernel/rros/sched.rs +++ b/kernel/rros/sched.rs @@ -200,7 +200,6 @@ pub fn rros_set_self_resched(rq: Option<*mut rros_rq>) -> Result { Ok(0) } -//测试通过 #[cfg(CONFIG_SMP)] pub fn rros_rq_cpu(rq: *mut rros_rq) -> i32 { unsafe { (*rq).get_cpu() } @@ -236,7 +235,6 @@ pub fn rros_protect_thread_priority(thread: Arc>, prio: i32 } } -//测试通过 #[cfg(CONFIG_SMP)] pub fn rros_set_resched(rq_op: Option<*mut rros_rq>) { let rq; @@ -266,14 +264,12 @@ pub fn rros_set_resched(rq: Option<*mut rros_rq>) { rros_set_self_resched(rq_clone) } -//暂时不用 #[cfg(CONFIG_SMP)] pub fn is_threading_cpu(_cpu: i32) -> bool { //return !!cpumask_test_cpu(cpu, &rros_cpu_affinity); return false; } -//测试通过 #[cfg(not(CONFIG_SMP))] pub fn is_threading_cpu(cpu: i32) -> bool { return true; @@ -284,25 +280,21 @@ pub fn is_rros_cpu(cpu: i32) -> bool { return true; } -//void rros_migrate_thread(struct RrosThread *thread, -// struct rros_rq *dst_rq); #[cfg(CONFIG_SMP)] #[allow(dead_code)] pub fn rros_migrate_thread(_thread: Arc>, _dst_rq: *mut rros_rq) { - //todo + // TODO: } #[cfg(not(CONFIG_SMP))] pub fn rros_migrate_thread(thread: Arc>, dst_rq: *mut rros_rq) {} -//简单函数未测试 #[allow(dead_code)] pub fn rros_in_irq() -> bool { let rq = this_rros_rq(); unsafe { (*rq).get_local_flags() & RQ_IRQ != 0 } } -//简单函数未测试 pub fn rros_is_inband() -> bool { let thread_op = this_rros_rq_thread(); let state; @@ -313,7 +305,6 @@ pub fn rros_is_inband() -> bool { state & T_ROOT != 0x0 } -//简单函数未测试 #[allow(dead_code)] pub fn rros_cannot_block() -> bool { rros_in_irq() || rros_is_inband() @@ -366,7 +357,6 @@ unsafe extern "C" fn this_rros_rq_exit_irq_local_flags() -> c_types::c_int { 0 as c_types::c_int } -//#[derive(Copy,Clone)] pub struct RrosSchedFifo { pub runnable: RrosSchedQueue, } @@ -378,7 +368,6 @@ impl RrosSchedFifo { } } -//#[derive(Copy,Clone)] pub struct RrosSchedWeak { pub runnable: Option>>, } @@ -388,7 +377,6 @@ impl RrosSchedWeak { } } -// #[derive(Copy,Clone)] pub struct RrosSchedQueue { pub head: Option>>>, } @@ -403,7 +391,6 @@ impl RrosSchedQueue { pub type SsizeT = bindings::__kernel_ssize_t; -// #[derive(Copy,Clone)] pub struct RrosSchedClass { pub sched_init: Option Result>, pub sched_enqueue: Option>) -> Result>, @@ -452,7 +439,7 @@ pub struct RrosSchedClass { pub weight: i32, pub policy: i32, pub name: &'static str, - pub flag: i32, // 标识调度类 1:RROS_SCHED_IDLE 3:RrosSchedFifo 4:RROS_SCHED_TP + pub flag: i32, // Identify the scheduling class: 1:RROS_SCHED_IDLE 3:RrosSchedFifo 4:RROS_SCHED_TP } impl RrosSchedClass { #[allow(dead_code)] @@ -544,7 +531,6 @@ impl RrosWeakParam { } } -//#[derive(Copy,Clone)] pub struct RrosSchedCtlparam { pub quota: RrosQuotaCtlparam, pub tp: RrosTpCtlparam, @@ -559,7 +545,6 @@ impl RrosSchedCtlparam { } } -//#[derive(Copy,Clone)] pub struct RrosSchedCtlinfo { pub quota: RrosQuotaCtlinfo, pub tp: RrosTpCtlinfo, @@ -574,7 +559,6 @@ impl RrosSchedCtlinfo { } } -//#[derive(Copy,Clone)] pub struct RrosQuotaCtlparam { pub op: RrosQuotaCtlop, pub u: U, @@ -586,7 +570,6 @@ impl RrosQuotaCtlparam { } } -//#[derive(Copy,Clone)] pub struct RrosTpCtlparam { pub op: RrosTpCtlop, pub nr_windows: i32, @@ -603,7 +586,6 @@ impl RrosTpCtlparam { } } -//#[derive(Copy,Clone)] pub struct RrosQuotaCtlinfo { pub tgid: i32, pub quota: i32, @@ -622,7 +604,6 @@ impl RrosQuotaCtlinfo { } } -//#[derive(Copy,Clone)] pub struct RrosTpCtlinfo { pub nr_windows: i32, pub windows: *mut RrosSchedTpWindow, @@ -650,7 +631,6 @@ pub type RrosQuotaCtlop = c_types::c_uint; // pub const RROS_TP_CTLOP_RROS_TP_GET: RrosTpCtlop = 4; pub type RrosTpCtlop = c_types::c_uint; -//#[derive(Copy,Clone)] pub struct U { pub remove: Remove, pub set: Set, @@ -666,7 +646,6 @@ impl U { } } } -//#[derive(Copy,Clone)] pub struct Remove { #[allow(dead_code)] tgid: i32, @@ -676,7 +655,6 @@ impl Remove { Remove { tgid: 0 } } } -//#[derive(Copy,Clone)] pub struct Set { #[allow(dead_code)] tgid: i32, @@ -694,7 +672,6 @@ impl Set { } } } -//#[derive(Copy,Clone)] pub struct Get { #[allow(dead_code)] tgid: i32, @@ -705,7 +682,6 @@ impl Get { } } -//#[derive(Copy,Clone)] pub struct RrosSchedTpWindow { pub offset: *mut Timespec64, pub duration: *mut Timespec64, @@ -725,7 +701,6 @@ use crate::timer::RrosTimer as rros_timer; type KtimeT = i64; use crate::clock::{RrosClock as rros_clock, RROS_MONO_CLOCK}; -//#[derive(Copy,Clone)] #[allow(dead_code)] pub struct RrosTqueue { pub q: ListHead, @@ -742,7 +717,6 @@ impl RrosTqueue { } } -//#[derive(Copy,Clone)] #[allow(dead_code)] pub struct Ops { pub read: Option>) -> KtimeT>, @@ -770,7 +744,6 @@ impl Ops { } } -//#[derive(Copy,Clone)] #[allow(dead_code)] pub struct RrosClockGravity { pub irq: KtimeT, @@ -840,7 +813,6 @@ impl GetLinks for RrosThreadWithLock { } } -//#[derive(Copy,Clone)] pub struct RrosThread { pub lock: HardSpinlock, @@ -1010,7 +982,6 @@ impl RrosThread { // } // } -//#[derive(Copy,Clone)] pub struct PollContext { pub table: Option>>, pub generation: u32, @@ -1028,7 +999,6 @@ impl PollContext { } } -//#[derive(Copy,Clone)] pub struct RrosPollWatchpoint { pub fd: u32, pub events_polled: i32, @@ -1051,7 +1021,6 @@ impl RrosPollWatchpoint { } } -//#[derive(Copy,Clone)] pub struct RrosValue { pub val: i32, pub lval: i64, @@ -1097,7 +1066,6 @@ impl RrosUserWindow { } } -// #[derive(Copy,Clone)] pub struct RrosObservable { // pub element:rros_element, pub observers: ListHead, @@ -1140,7 +1108,6 @@ impl RrosObservable { } } -//#[derive(Copy,Clone)] pub struct RrosPollHead { pub watchpoints: ListHead, // FIXME: use ptr here not directly object @@ -1530,7 +1497,7 @@ fn register_classes() -> Result { Ok(0) } -// todo等全局变量实现后,去掉index和topmost +// TODO: After the global variables are implemented, remove `index` and `topmost`. fn register_one_class(sched_class: &mut RrosSchedClass, index: i32) -> Result { // let mut sched_class_lock = sched_class.lock(); // let index = sched_class_lock.flag; @@ -1541,7 +1508,7 @@ fn register_one_class(sched_class: &mut RrosSchedClass, index: i32) -> Result Result Result { let mut iattr = RrosInitThreadAttr::new(); let name_fmt: &'static CStr = c_str!("ROOT"); @@ -1641,11 +1608,11 @@ fn init_rq(rq: *mut rros_rq, cpu: i32) -> Result { // rros_set_current_account(rq, &rq->root_thread.stat.account); iattr.flags = T_ROOT as i32; iattr.affinity = cpumask_of(cpu); - // todo等全局变量 + // TODO: Wait for global variables. unsafe { iattr.sched_class = Some(&idle::RROS_SCHED_IDLE); } - // 下面多数注释的都是由于rros_init_thread未完成导致的 + // Most of the comments below are caused by rros_init_thread not being completed. // let sched_param_clone; // let mut sched_param_ptr; // match iattr.sched_param { @@ -1834,7 +1801,6 @@ pub fn rros_putback_thread(thread: Arc>) -> Result { Ok(0) } -//未测试,应该可行 pub fn rros_dequeue_thread(thread: Arc>) -> Result { let sched_class; match thread.lock().sched_class.clone() { @@ -1854,7 +1820,6 @@ pub fn rros_dequeue_thread(thread: Arc>) -> Result { Ok(0) } -//未测试,应该可行 pub fn rros_enqueue_thread(thread: Arc>) -> Result { let sched_class; match thread.lock().sched_class.clone() { @@ -1874,7 +1839,6 @@ pub fn rros_enqueue_thread(thread: Arc>) -> Result { Ok(0) } -//未测试,应该可行 pub fn rros_requeue_thread(thread: Arc>) -> Result { let sched_class; unsafe { @@ -1899,10 +1863,6 @@ pub fn rros_requeue_thread(thread: Arc>) -> Result { // fn rros_need_resched(rq: *mut rros_rq) -> bool { // unsafe{(*rq).flags & RQ_SCHED != 0x0} // } -// static inline int rros_need_resched(struct rros_rq *rq) -// { -// return rq->flags & RQ_SCHED; -// } /* hard irqs off. */ fn test_resched(rq: *mut rros_rq) -> bool { @@ -1922,25 +1882,7 @@ fn test_resched(rq: *mut rros_rq) -> bool { need_resched } -// static __always_inline bool test_resched(struct rros_rq *this_rq) -// { -// bool need_resched = rros_need_resched(this_rq); - -// #ifdef CONFIG_SMP -// /* Send resched IPI to remote CPU(s). */ -// if (unlikely(!cpumask_empty(&this_rq->resched_cpus))) { -// irq_send_oob_ipi(RESCHEDULE_OOB_IPI, &this_rq->resched_cpus); -// cpumask_clear(&this_rq->resched_cpus); -// this_rq->local_flags &= ~RQ_SCHED; -// } -// #endif -// if (need_resched) -// this_rq->flags &= ~RQ_SCHED; - -// return need_resched; -// } -//逻辑完整,未测试 #[no_mangle] pub unsafe extern "C" fn rros_schedule() { unsafe { @@ -2014,7 +1956,7 @@ unsafe extern "C" fn __rros_schedule(_arg: *mut c_types::c_void) -> i32 { //rros_commit_monitor_ceiling(); } - //这里可以不用自旋锁,因为只有一个cpu,理论上来说没有问题 + // There is no need for a spin lock here because there is only one CPU, so in theory there is no problem. // raw_spin_lock(&curr->lock); // raw_spin_lock(&this_rq->lock); @@ -2140,7 +2082,6 @@ pub fn pick_next_thread(rq: Option<*mut rros_rq>) -> Option) -> Option>> { let curr = unsafe { (*rq.clone().unwrap()).curr.clone().unwrap() }; @@ -2165,8 +2106,8 @@ pub fn __pick_next_thread(rq: Option<*mut rros_rq>) -> Option) -> Option) -> Option>> { let q = &mut unsafe { (*rq.clone().unwrap()).fifo.runnable.head.as_mut().unwrap() }; if q.is_empty() { @@ -2222,7 +2162,6 @@ pub fn lookup_fifo_class(rq: Option<*mut rros_rq>) -> Option, next: Option>>) { let next = next.unwrap(); unsafe { (*next.locked_data().get()).state &= !T_READY }; @@ -2289,7 +2228,7 @@ pub fn rros_put_thread_rq( rust_helper_hard_local_irq_restore(flags); // rust_helper_preempt_enable(); } - // TODO raw_spin_unlock and raw_spin_unlock_irqrestore + // TODO: raw_spin_unlock and raw_spin_unlock_irqrestore Ok(0) } @@ -2365,7 +2304,6 @@ pub fn rros_set_thread_policy_locked( Ok(0) } -//逻辑完整,未测试 fn rros_check_schedparams( thread: Option>>, sched_class: Option<&'static RrosSchedClass>, @@ -2424,7 +2362,7 @@ fn rros_set_schedparam( // return ; } -//逻辑完整,未测试,待重构 +// TODO: Remain to be refactored. fn rros_declare_thread( thread: Option>>, sched_class: Option<&'static RrosSchedClass>, @@ -2549,7 +2487,6 @@ extern "C" { fn rust_helper_hard_local_irq_enable(); } -//基本完整 pub fn rros_switch_inband(cause: i32) { pr_debug!("rros_switch_inband: in"); let curr = unsafe { &mut *rros_current() }; diff --git a/kernel/rros/stat.rs b/kernel/rros/stat.rs index 1cf8cc0766089..2f00a86b5cf0b 100644 --- a/kernel/rros/stat.rs +++ b/kernel/rros/stat.rs @@ -1,6 +1,6 @@ use crate::sched::rros_rq; use kernel::ktime::*; -// #[cfg(not(CONFIG_RROS_RUNSTATS))] struct不能加cfg + pub struct RrosAccount { #[cfg(CONFIG_RROS_RUNSTATS)] start: KtimeT, @@ -56,7 +56,7 @@ fn rros_get_timestamp() -> KtimeT { } #[cfg(CONFIG_RROS_RUNSTATS)] -//todo +// TODO: pub fn rros_update_account(rq: Option<*mut rros_rq>) { match rq { None => return, @@ -67,7 +67,7 @@ pub fn rros_update_account(rq: Option<*mut rros_rq>) { (*x).current_account .set_account_total(total + now - (*x).last_account_switch); (*x).last_account_switch = now; - // smp_wmb();未实现 + // smp_wmb();Not implemented } } } diff --git a/kernel/rros/stat_test.rs b/kernel/rros/stat_test.rs index 6ec46e1ec0793..6429ee042cc3b 100644 --- a/kernel/rros/stat_test.rs +++ b/kernel/rros/stat_test.rs @@ -1,5 +1,3 @@ -//stat.rs测试文件 -//用于测试stat.rs里的函数正确性 use crate::{ clock::*, factory::RrosElement, factory::RrosFactory, factory::RustFile, lock::*, sched::*, timer::*, RROS_OOB_CPUS, factory, list::*, @@ -17,4 +15,3 @@ use kernel::{ sync::Lock, sync::SpinLock, sysfs, timekeeping, }; -// CFG为!CONFIG_RROS_RUNSTATS未测试,理论可行 diff --git a/kernel/rros/thread.rs b/kernel/rros/thread.rs index f5b4eeaa0aebb..fcf0eca429216 100644 --- a/kernel/rros/thread.rs +++ b/kernel/rros/thread.rs @@ -350,7 +350,7 @@ pub fn rros_init_thread( thread.clone().unwrap().lock().deref_mut().inband_work.init_irq_work(inband_task_wakeup)?; // pr_debug!("yinyongcishu is {}", Arc::strong_count(&thread.clone().unwrap())); - //tp设置gps + //tp set gps // let mut gps = unsafe{RROS_SYSTEM_HEAP.rros_alloc_chunk((size_of::() + 4 * size_of::()) as usize)}; // if gps == None{ // return Err(kernel::Error::ENOMEM); @@ -573,7 +573,7 @@ unsafe extern "C" fn kthread_trampoline(arg: *mut c_types::c_void) -> c_types::c } if sched_class.flag != 3 { - //curr的调度类不是rros_sched_fifo + // The scheduling class of curr is not rros_sched_fifo. policy = SCHED_NORMAL; prio = 0; } else { @@ -635,7 +635,7 @@ fn rros_cancel_thread(thread: Arc>) { pr_debug!(" in rros_cancel_thread"); let mut flags: c_types::c_ulong = 0; - //关中断 + // Turn off interrupts. let rq = rros_get_thread_rq(Some(thread.clone()), &mut flags); let mut state = thread.lock().state; @@ -718,13 +718,6 @@ fn __rros_test_cancel(curr_ptr: *mut SpinLock) { kernelh::do_exit(kernelh::ThreadExitCode::Successfully); } -// static void wakeup_kthread_parent(struct irq_work *irq_work) -// { -// struct rros_kthread *kthread; -// kthread = container_of(irq_work, struct rros_kthread, irq_work); -// complete(&kthread->done); -// } - unsafe extern "C" fn wakeup_kthread_parent(irq_work: *mut IrqWork) { let kthread = kernel::container_of!(irq_work, RrosKthread, irq_work); unsafe { @@ -802,7 +795,7 @@ fn map_kthread_self(kthread: &mut RrosKthread) -> Result { kthread.irq_work.init_irq_work(wakeup_kthread_parent)?; kthread.irq_work.irq_work_queue()?; } - // enqueue_new_thread(curr);//这个函数影响不大 + // enqueue_new_thread(curr);// This function has little impact. rros_hold_thread(kthread, T_DORMANT); return ret; } @@ -948,15 +941,13 @@ extern "C" { // bindings::_raw_spin_unlock_irq() // } -//逻辑完整,未测试 pub fn rros_release_thread(thread: Arc>, mask: u32, info: u32) { let mut flags: c_types::c_ulong = 0; let rq = rros_get_thread_rq(Some(thread.clone()), &mut flags); - rros_release_thread_locked(thread.clone(), mask, info); //对于smp这里需要改,现在没问题 + rros_release_thread_locked(thread.clone(), mask, info); // For smp, this needs to be changed, but now there is no problem. let _ret = rros_put_thread_rq(Some(thread.clone()), rq, flags); } -//逻辑完整,未测试 pub fn rros_release_thread_locked(thread: Arc>, mask: u32, info: u32) { let rq = thread.lock().rq.unwrap(); let oldstate = thread.lock().state; @@ -989,14 +980,13 @@ pub fn rros_release_thread_locked(thread: Arc>, mask: u32, } } -// fn rros_hold_thread(thread: Arc>, mask: u32) { fn rros_hold_thread(kthread: &mut RrosKthread, mask: u32) { // rros_hold_thread(kthread.thread.clone().unwrap(), T_DORMANT); // as_mut().unwrap() let thread = kthread.thread.clone().unwrap(); let mut flags: c_types::c_ulong = 0; - //关中断 + // Turn off interrupts. let rq_op = rros_get_thread_rq(Some(thread.clone()), &mut flags); let rq = rq_op.unwrap(); @@ -1041,24 +1031,11 @@ pub fn set_oob_threadinfo(curr: *mut c_types::c_void) { // unsafe{Arc::decrement_strong_count(curr);} } -// static inline void set_oob_threadinfo(struct RrosThread *thread) -// { -// struct oob_thread_state *p; - -// p = dovetail_current_state(); -// p->thread = thread; -// } - pub fn set_oob_mminfo(thread: Arc>) { // pr_debug!("set_oob_mminfo: in"); unsafe { (*thread.locked_data().get()).oob_mm = dovetail::dovetail_mm_state(); } } -// static inline void set_oob_mminfo(struct RrosThread *thread) -// { -// thread->oob_mm = dovetail_mm_state(); -// } - pub fn kthread_run_on_cpu( threadfn: Option c_types::c_int>, data: *mut c_types::c_void, @@ -1326,7 +1303,7 @@ pub fn rros_sleep_on_locked( #[allow(dead_code)] pub fn rros_propagate_schedparam_change(curr: &mut SpinLock) { - // 这里没法写curr_lock = curr.lock() + // Can't write here: curr_lock = curr.lock() // cannot borrow `*curr` as mutable because it is also borrowed as immutable if curr.lock().info & T_SCHEDP != 0x0 { __rros_propagate_schedparam_change(curr); @@ -1348,7 +1325,7 @@ unsafe extern "C" fn rust_handle_inband_event( // break; bindings::inband_event_type_INBAND_TASK_EXIT => { // pr_debug!("{}",rust_helper_dovetail_current_state().subscriber); - // rros_drop_subscriptions(rros_get_subscriber()); //rros中的sbr为NULL,这里先注释 + // rros_drop_subscriptions(rros_get_subscriber()); // sbr in rros is NULL, comment here first. if rros_current() != 0 as *mut SpinLock { let _ret = put_current_thread(); } @@ -1423,7 +1400,7 @@ fn do_cleanup_current(curr: Arc>) -> Result { let mut flags: c_types::c_ulong = 0; let rq: Option<*mut rros_rq>; - // 这里的if暂时是进不去的,observable为空 + // The if here cannot be entered temporarily, and the observable is empty. // let observable = curr.lock().observable.clone(); // if observable.is_some(){ // rros_flush_observable(curr->observable); @@ -1488,7 +1465,6 @@ fn dequeue_old_thread(_thread: Arc>) -> Result { Ok(0) } -// fn uninit_thread(thread: &mut SpinLock) { fn uninit_thread(thread: Arc>) { pr_debug!("the thread address is {:p}", thread); // pr_debug!("the UTHREAD address is {:p}", UTHREAD.clone().unwrap()); @@ -1930,15 +1906,7 @@ fn add_u_cap(thread: Arc>, new_cap: *mut cred::Credential, } } } -// static inline void add_u_cap(struct RrosThread *thread, -// struct cred *newcap, -// int cap) -// { -// if (!capable(cap)) { -// cap_raise(newcap->cap_effective, cap); -// cap_raise(thread->raised_cap, cap); -// } -// } + pub fn rros_notify_thread(thread: *mut RrosThread, tag: u32, _details: RrosValue) -> Result { unsafe { if (*thread).state & T_HMSIG != 0 { @@ -2206,7 +2174,7 @@ pub fn rros_find_sched_class( // sched_class = &rros_sched_fifo; param.fifo.prio = 47; - // TODO 目前policy这里只写了tp + // TODO: Currently, only tp is written here in the policy. // switch (policy) { // case SCHED_NORMAL: // if (prio) @@ -2255,10 +2223,10 @@ pub fn rros_find_sched_class( // return ERR_PTR(-EINVAL); // } - // 按照librros写的,prio+ptid应为50,part取3 + // According to what librros wrote, prio + ptid should be 50, and part should be 3. param.tp.prio = 47; param.tp.ptid = 3; - //FIXME: tp未实现 + //FIXME: tp haven't been implemented. // sched_class = unsafe{&RROS_SCHED_TP}; // panic!(); sched_class @@ -2328,7 +2296,6 @@ pub fn get_sched_attrs(thread: *mut RrosThread, attrs: &mut RrosSchedAttrs) -> R Ok(0) } -// 目前只写了tp pub fn __get_sched_attrs( sched_class: Option<&'static RrosSchedClass>, thread: *mut RrosThread, diff --git a/kernel/rros/tick.rs b/kernel/rros/tick.rs index ea3a080d4532d..f55f2516589f3 100644 --- a/kernel/rros/tick.rs +++ b/kernel/rros/tick.rs @@ -44,7 +44,6 @@ pub fn rros_notify_proxy_tick(rq: *mut RrosRq) { pub struct RrosProxySetNextKtime; impl clockchips::ProxySetNextKtime for RrosProxySetNextKtime { - // 未测试 fn proxy_set_next_ktime(expires: KtimeT, _arg1: clockchips::ClockEventDevice) -> i32 { //pr_debug!("proxy_set_next_ktime: in"); let delta = ktime_sub(expires, ktime_get()); @@ -70,7 +69,6 @@ impl clockchips::ProxySetNextKtime for RrosProxySetNextKtime { pub struct RrosProxySetOneShotStopped; impl clockchips::ProxySetOneshotStopped for RrosProxySetOneShotStopped { - // 未测试 fn proxy_set_oneshot_stopped(dev: clockchips::ClockProxyDevice) -> c_types::c_int { pr_debug!("proxy_set_oneshot_stopped: in"); let flags = unsafe { rust_helper_hard_local_irq_save() }; @@ -149,7 +147,7 @@ pub fn rros_enable_tick() -> Result { pub struct RrosSetupProxy; impl clockchips::SetupProxy for RrosSetupProxy { - // 新的setup + // new setup fn setup_proxy(dev: clockchips::ClockProxyDevice) { let _real_dev: ClockEventDevice; match clockchips::ClockEventDevice::from_proxy_device(dev.get_real_device()) { diff --git a/kernel/rros/timer.rs b/kernel/rros/timer.rs index 468ac201a9316..d0f213aedff5c 100644 --- a/kernel/rros/timer.rs +++ b/kernel/rros/timer.rs @@ -35,7 +35,7 @@ pub fn rros_timer_null_handler(timer: *mut RrosTimer) { pub struct RrosTimer { clock: *mut RrosClock, date: KtimeT, - //adjlink: list_head,//调整时用到 + //adjlink: list_head,// Used when adjusting status: i32, pub interval: KtimeT, /* 0 == oneshot */ pub start_date: KtimeT, @@ -204,7 +204,6 @@ pub fn rros_insert_tnode(tq: &mut List>>, timer: Arc>>, timer: Arc>) { let mut l = tq.len(); @@ -221,7 +220,6 @@ pub fn rros_insert_tnode(tq: &mut List>>, timer: Arc>) -> KtimeT { let status = unsafe { (*timer.locked_data().get()).get_status() }; if status & RROS_TIMER_KGRAVITY != 0 { @@ -235,7 +233,6 @@ pub fn rros_get_timer_gravity(timer: Arc>) -> KtimeT { return unsafe { (*(*timer.locked_data().get()).get_clock()).get_gravity_irq() }; } -//测试通过 pub fn rros_update_timer_date(timer: Arc>) { unsafe { let start_date = (*timer.locked_data().get()).get_start_date(); @@ -249,7 +246,6 @@ pub fn rros_update_timer_date(timer: Arc>) { } } -//测试通过 pub fn rros_get_timer_next_date(timer: Arc>) -> KtimeT { let start_date = unsafe { (*timer.locked_data().get()).get_start_date() }; let periodic_ticks = unsafe { (*timer.locked_data().get()).get_periodic_ticks() }; @@ -259,7 +255,7 @@ pub fn rros_get_timer_next_date(timer: Arc>) -> KtimeT { #[cfg(CONFIG_RROS_RUNSTATS)] pub fn rros_reset_timer_stats(timer: Arc>) { - //条件不足未修改 + // Insufficient conditions, so no modification timer.lock().get_scheduled().set_counter(0); timer.lock().get_fired().set_counter(0); } @@ -275,7 +271,7 @@ pub fn rros_account_timer_fired(timer: Arc>) { } #[cfg(not(CONFIG_RROS_RUNSTATS))] -pub fn rros_reset_timer_stats(timer: Arc>) {} //条件不足未修改 +pub fn rros_reset_timer_stats(timer: Arc>) {} // Insufficient conditions, so no modification #[cfg(not(CONFIG_RROS_RUNSTATS))] pub fn rros_account_timer_scheduled(timer: Arc>) {} @@ -283,7 +279,6 @@ pub fn rros_account_timer_scheduled(timer: Arc>) {} #[cfg(not(CONFIG_RROS_RUNSTATS))] pub fn rros_account_timer_fired(timer: Arc>) {} -//测试通过 pub fn rros_timer_deactivate(timer: Arc>) -> bool { let mut heading = true; let tmb = unsafe { (*timer.locked_data().get()).get_base() }; @@ -308,7 +303,6 @@ pub fn rros_timer_on_rq(timer: Arc>, rq: *mut RrosRq) -> boo return true; } -//测试通过 pub fn stop_timer_locked(timer: Arc>) { // let timer_lock = timer.lock(); let is_running = unsafe { (*timer.locked_data().get()).is_running() }; @@ -321,14 +315,12 @@ pub fn stop_timer_locked(timer: Arc>) { } } -//默认通过 pub fn __rros_stop_timer(timer: Arc>) { //base = lock_timer_base(timer, &flags); stop_timer_locked(timer); //unlock_timer_base(base, flags); } -//默认通过 pub fn rros_stop_timer(timer: Arc>) { unsafe { let is_running = (*timer.locked_data().get()).is_running(); @@ -374,7 +366,6 @@ fn unlock_timer_base(timer: Arc>, flags: &mut u32) { pr_err!("!!!!!!!!!!!! this is wrong. lock_timer_base"); } -//测试通过 pub fn rros_dequeue_timer( timer: Arc>, tq: &mut List>>, @@ -397,14 +388,12 @@ pub fn rros_dequeue_timer( } } -//测试通过 pub fn rros_get_timer_expiry(timer: Arc>) -> KtimeT { let date = unsafe { (*timer.locked_data().get()).get_date() }; let gravity = rros_get_timer_gravity(timer.clone()); return ktime_add(date, gravity); } -//测试通过 pub fn __rros_get_timer_delta(timer: Arc>) -> KtimeT { let expiry = rros_get_timer_expiry(timer.clone()); let now = unsafe { (*timer.lock().get_clock()).read() }; @@ -415,7 +404,6 @@ pub fn __rros_get_timer_delta(timer: Arc>) -> KtimeT { return ktime_sub(expiry, now); } -//测试通过 pub fn rros_get_timer_delta(timer: Arc>) -> KtimeT { let timer_clone = timer.clone(); let is_running = unsafe { (*timer_clone.locked_data().get()).is_running() }; @@ -425,14 +413,12 @@ pub fn rros_get_timer_delta(timer: Arc>) -> KtimeT { return __rros_get_timer_delta(timer.clone()); } -//测试通过 pub fn rros_percpu_timers(clock: &RrosClock, cpu: i32) -> *mut RrosTimerbase { unsafe { percpu_defs::per_cpu_ptr(clock.get_timerdata_addr() as *mut u8, cpu) as *mut RrosTimerbase } } -//测试通过 #[cfg(CONFIG_SMP)] fn get_clock_cpu(clock: &RrosClock, cpu: i32) -> i32 { return 0; @@ -478,7 +464,7 @@ pub fn rros_init_timer_on_rq( } timer.lock().set_interval(RROS_INFINITE); let mut cpu = 0; - // if rq.clone().borrow().is_some(){//Smp相关 + // if rq.clone().borrow().is_some(){ // Smp related // cpu = unsafe{get_clock_cpu(clock,rros_rq_cpu(&rq.clone().borrow()))}; // }else{ // //cpumask_first(&RROS_CPU_AFFINITY); @@ -492,7 +478,6 @@ pub fn rros_init_timer_on_rq( rros_reset_timer_stats(timer.clone()); } -//测试通过 pub fn program_timer(timer: Arc>, tq: &mut List>>) { rros_enqueue_timer(timer.clone(), tq); let rq = unsafe { (*timer.locked_data().get()).get_rq() }; @@ -508,7 +493,6 @@ pub fn program_timer(timer: Arc>, tq: &mut List>, value: KtimeT, interval: KtimeT) { // pr_debug!("yinyongcishu is {}",Arc::strong_count(&timer)); // pr_debug!("rros_start_timer: 1"); @@ -543,7 +527,6 @@ pub fn rros_start_timer(timer: Arc>, value: KtimeT, interval } } -//测试通过 pub fn timer_at_front(timer: Arc>) -> bool { unsafe { let tmb = (*timer.locked_data().get()).get_base(); @@ -575,7 +558,6 @@ pub fn timer_at_front(timer: Arc>) -> bool { } } -//测试通过 pub fn rros_get_timer_date(timer: Arc>) -> KtimeT { let mut expiry = 0; let is_running = unsafe { (*timer.locked_data().get()).is_running() }; @@ -587,12 +569,10 @@ pub fn rros_get_timer_date(timer: Arc>) -> KtimeT { return expiry; } -//默认通过 pub fn __rros_get_stopped_timer_delta(timer: Arc>) -> KtimeT { return __rros_get_timer_delta(timer.clone()); } -//默认通过 pub fn rros_get_stopped_timer_delta(timer: Arc>) -> KtimeT { let t = __rros_get_stopped_timer_delta(timer.clone()); @@ -603,7 +583,6 @@ pub fn rros_get_stopped_timer_delta(timer: Arc>) -> KtimeT { return t; } -//测试通过 pub fn rros_enqueue_timer( timer: Arc>, tq: &mut List>>, @@ -615,7 +594,6 @@ pub fn rros_enqueue_timer( rros_account_timer_scheduled(timer.clone()); } -//测试通过 pub fn rros_destroy_timer(timer: Arc>) { rros_stop_timer(timer.clone()); timer.lock().add_status(RROS_TIMER_KILLED); @@ -625,7 +603,6 @@ pub fn rros_destroy_timer(timer: Arc>) { timer.lock().set_base(0 as *mut RrosTimerbase); } -//未测试,默认通过 pub fn rros_abs_timeout(timer: Arc>, delta: KtimeT) -> KtimeT { unsafe { ktime_add((*(*timer.locked_data().get()).get_clock()).read(), delta) } } diff --git a/kernel/rros/timer_test.rs b/kernel/rros/timer_test.rs index cf699b87ba522..32d81849fda94 100644 --- a/kernel/rros/timer_test.rs +++ b/kernel/rros/timer_test.rs @@ -1,9 +1,6 @@ -//timer.rs测试文件 -//用于测试timer.rs里的函数正确性 use crate::{clock::*, sched::*, timer::*}; use kernel::{prelude::*, spinlock_init, sync::SpinLock}; -//测试通过 #[allow(dead_code)] pub fn test_rros_insert_tnode() -> Result { pr_debug!("~~~test_rros_insert_tnode begin~~~"); @@ -44,7 +41,6 @@ pub fn test_rros_insert_tnode() -> Result { Ok(0) } -//测试通过 #[allow(dead_code)] pub fn test_rros_enqueue_timer() -> Result { pr_debug!("~~~test_rros_insert_tnode begin~~~"); @@ -86,7 +82,6 @@ pub fn test_rros_enqueue_timer() -> Result { Ok(0) } -//测试通过 #[allow(dead_code)] pub fn test_rros_get_timer_gravity() -> Result { pr_debug!("~~~test_rros_get_timer_gravity begin~~~"); @@ -110,7 +105,6 @@ pub fn test_rros_get_timer_gravity() -> Result { Ok(0) } -//测试通过 #[allow(dead_code)] pub fn test_rros_update_timer_date() -> Result { pr_debug!("~~~test_rros_update_timer_date begin~~~"); @@ -133,7 +127,6 @@ pub fn test_rros_update_timer_date() -> Result { Ok(0) } -//测试通过 #[allow(dead_code)] pub fn test_rros_get_timer_next_date() -> Result { pr_debug!("~~~test_rros_get_timer_next_date begin~~~"); @@ -153,7 +146,6 @@ pub fn test_rros_get_timer_next_date() -> Result { Ok(0) } -//测试通过 #[allow(dead_code)] pub fn test_timer_at_front() -> Result { unsafe { @@ -185,14 +177,14 @@ pub fn test_timer_at_front() -> Result { (*tmb).q.add_head(yy.clone()); (*tmb).q.add_head(zz.clone()); - //测试第一个if分支 + // Test the first if branch. if timer_at_front(zz.clone()) == true { pr_debug!("test_timer_at_front if1 true"); } else { pr_debug!("test_timer_at_front if1 false"); } - //测试第二个if分支 + // Test the second if branch. if timer_at_front(yy.clone()) == true { pr_debug!("test_timer_at_front if2 true"); } else { @@ -202,7 +194,6 @@ pub fn test_timer_at_front() -> Result { Ok(0) } -//测试通过 #[allow(dead_code)] pub fn test_rros_timer_deactivate() -> Result { unsafe { @@ -251,7 +242,6 @@ pub fn test_rros_timer_deactivate() -> Result { Ok(0) } -//测试通过 #[allow(dead_code)] pub fn test_rros_get_timer_expiry() -> Result { pr_debug!("~~~test_rros_get_timer_expiry begin~~~"); @@ -271,7 +261,6 @@ pub fn test_rros_get_timer_expiry() -> Result { Ok(0) } -//测试通过 #[allow(dead_code)] pub fn test_rros_get_timer_delta() -> Result { pr_debug!("~~~test_rros_get_timer_delta begin~~~"); @@ -296,7 +285,6 @@ pub fn test_rros_get_timer_delta() -> Result { Ok(0) } -//测试通过 #[allow(dead_code)] pub fn test_rros_get_timer_date() -> Result { pr_debug!("~~~test_rros_get_timer_date begin~~~"); @@ -319,7 +307,6 @@ pub fn test_rros_get_timer_date() -> Result { Ok(0) } -//测试通过 #[allow(dead_code)] pub fn test_program_timer() -> Result { pr_debug!("~~~test_program_timer begin~~~"); @@ -347,7 +334,6 @@ pub fn test_program_timer() -> Result { Ok(0) } -//测试通过 #[allow(dead_code)] pub fn test_rros_start_timer() -> Result { pr_debug!("~~~test_rros_start_timer begin~~~"); @@ -379,7 +365,6 @@ pub fn test_rros_start_timer() -> Result { Ok(0) } -//测试通过 #[allow(dead_code)] pub fn test_stop_timer_locked() -> Result { pr_debug!("~~~test_stop_timer_locked begin~~~"); @@ -406,7 +391,6 @@ pub fn test_stop_timer_locked() -> Result { Ok(0) } -//测试通过 #[allow(dead_code)] pub fn test_rros_destroy_timer() -> Result { pr_debug!("~~~test_rros_destroy_timer begin~~~"); diff --git a/kernel/rros/tp.rs b/kernel/rros/tp.rs index 9d624796f8cf5..0ef183f791d84 100644 --- a/kernel/rros/tp.rs +++ b/kernel/rros/tp.rs @@ -48,7 +48,7 @@ pub static mut RROS_SCHED_TP: RrosSchedClass = RrosSchedClass { flag: 4, }; -pub const CONFIG_RROS_SCHED_TP_NR_PART: i32 = 5; // 先默认设置为5 +pub const CONFIG_RROS_SCHED_TP_NR_PART: i32 = 5; // Set to 5 by default temporarily. pub const RROS_TP_MAX_PRIO: i32 = RROS_FIFO_MAX_PRIO; pub const RROS_TP_MIN_PRIO: i32 = RROS_FIFO_MIN_PRIO; #[allow(dead_code)] @@ -145,7 +145,7 @@ pub fn tp_schedule_next(tp: &mut RrosSchedTp) -> Result { pub fn tp_tick_handler(timer: *mut RrosTimer) { unsafe { - // 这里的container_of有问题 + // There is a problem with `container_of` here. let rq = kernel::container_of!(timer, rros_rq, tp.tf_timer) as *mut rros_rq; let mut tp = &mut (*rq).tp; @@ -372,7 +372,7 @@ pub fn tp_enqueue(thread: Arc>) -> Result { let rq_next = (*thread.locked_data().get()).rq_next.clone(); head.add_head(rq_next.clone().as_mut().unwrap().as_mut().value.clone()); } else { - let mut flag = 1; // flag指示是否到头 + let mut flag = 1; for i in head.len()..=1 { let thread_cprio = (*thread.locked_data().get()).cprio; let cprio_in_list = (*head @@ -382,7 +382,7 @@ pub fn tp_enqueue(thread: Arc>) -> Result { .clone() .locked_data() .get()) - .cprio; + .cprio; if thread_cprio <= cprio_in_list { flag = 0; let rq_next = (*thread.locked_data().get()).rq_next.clone(); @@ -424,7 +424,7 @@ pub fn tp_requeue(thread: Arc>) { let rq_next = (*thread.locked_data().get()).rq_next.clone(); head.add_head(rq_next.clone().as_mut().unwrap().as_mut().value.clone()); } else { - let mut flag = 1; // flag指示是否到头 + let mut flag = 1; for i in head.len()..=1 { let thread_cprio = (*thread.locked_data().get()).cprio; let cprio_in_list = (*head @@ -434,7 +434,7 @@ pub fn tp_requeue(thread: Arc>) { .clone() .locked_data() .get()) - .cprio; + .cprio; if thread_cprio < cprio_in_list { flag = 0; let rq_next = (*thread.locked_data().get()).rq_next.clone(); diff --git a/kernel/rros/types.rs b/kernel/rros/types.rs index cae10d97e3019..60af3d55e8f59 100644 --- a/kernel/rros/types.rs +++ b/kernel/rros/types.rs @@ -130,7 +130,6 @@ macro_rules! list_del_init { }; } -// 获取当前链表节点,并将其从链表中移出去 /// Macro to get the first entry from a list and remove it from the list. /// This macro takes a pointer to the list head, a type, and a field, and returns a pointer to the first entry in the list. /// The entry is also removed from the list. @@ -187,7 +186,6 @@ macro_rules! list_add { }; } -// 常规实现 /// Macro to iterate over a list of given type. /// This macro takes an identifier for the loop cursor, a list head, a type, a block of code to execute for each entry, and a list of fields. /// It starts from the first entry and continues until it reaches the head of the list, executing the block of code for each entry. diff --git a/kernel/rros/wait.rs b/kernel/rros/wait.rs index 5da2ade12954e..7dd7cbb3cbc8e 100644 --- a/kernel/rros/wait.rs +++ b/kernel/rros/wait.rs @@ -66,7 +66,7 @@ impl RrosWaitQueue { wait.init(clock, flags); wait } - // 删掉了key:*mut bindings::lock_class_key,和name:&'static CStr + // delete `key:*mut bindings::lock_class_key`, and `name:&'static CStr`. pub fn init(&mut self, clock: *mut RrosClock, flags: i32) { self.flags = flags; self.clock = clock; @@ -75,7 +75,7 @@ impl RrosWaitQueue { // self.wchan.wait_list. // init_list_head!(&self.wchan.wait_list); // lockdep_set_class_and_name(&wq->lock, key, name); - // 这个是调试时候用的 + // This is used during debugging. } pub fn flush(&mut self, reason: i32) { // rros_flush_wait @@ -153,7 +153,7 @@ impl RrosWaitQueue { let current = unsafe { RrosThreadWithLock::new_from_curr_thread() }; self.wchan.wait_list.push_back(current) } else { - // 按优先级加入,可以看下types_test.rs的add_by_prio + // To join according to priority, you can look at `add_by_prio` in types_test.rs. let prio = curr.wprio; let mut last = self.wchan.wait_list.cursor_back_mut(); let mut stop_flag = false; @@ -182,7 +182,7 @@ impl RrosWaitQueue { timeout_mode, unsafe { &*self.clock }, &mut self.wchan as *mut RrosWaitChannel, - ); // 必须保证wchan不会被释放 + ); // It must be ensured that wchan will not be released. } pub fn wait_schedule(&mut self) -> i32 { diff --git a/kernel/rros/work.rs b/kernel/rros/work.rs index ab85a91cfc828..7a326bbce6787 100644 --- a/kernel/rros/work.rs +++ b/kernel/rros/work.rs @@ -41,7 +41,7 @@ unsafe extern "C" fn do_irq_work(irq_work: *mut IrqWork) { } { pr_debug!("uncompleted rros_put_element()"); } - // TODO: 没有实现rros_put_element + // TODO: rros_put_element is not implemented // if unsafe{rust_helper_queue_work((*work).wq,&mut (*work).wq_work)} && unsafe{(*)} // if (!queue_work(work->wq, &work->wq_work) && work->element) // rros_put_element(work->element); @@ -89,7 +89,7 @@ impl RrosWork { } pub fn call_inband_from(&mut self, wq: *mut bindings::workqueue_struct) { self.wq = wq; - // TODO: 没有实现rros_put_element + // TODO: rros_put_element is not implemented // if (work->element) if self.element.is_some() { pr_debug!("uncompleted rros_get_element()"); diff --git a/kernel/rros/xbuf.rs b/kernel/rros/xbuf.rs index 841dd3f028d4d..1bcd09170de80 100644 --- a/kernel/rros/xbuf.rs +++ b/kernel/rros/xbuf.rs @@ -190,7 +190,6 @@ impl XbufRing { } } -// oob_write -> read pub struct XbufInbound { pub i_event: waitqueue::WaitQueueHead, pub o_event: RrosFlag, @@ -211,7 +210,6 @@ impl XbufInbound { } } -// write -> oob_read pub struct XbufOutbound { pub i_event: RrosWaitQueue, pub o_event: waitqueue::WaitQueueHead, @@ -699,34 +697,6 @@ pub fn xbuf_ioctl(_filp: &File, _cmd: u32, _arg: u32) -> i32 { -(bindings::ENOTTY as i32) } -// static __poll_t xbuf_poll(struct file *filp, poll_table *wait) -// { -// struct rros_xbuf *xbuf = element_of(filp, struct rros_xbuf); -// struct xbuf_outbound *obnd = &xbuf->obnd; -// struct xbuf_inbound *ibnd = &xbuf->ibnd; -// unsigned long flags; -// __poll_t ready = 0; - -// poll_wait(filp, &ibnd->i_event, wait); -// poll_wait(filp, &obnd->o_event, wait); - -// flags = ibnd->ring.lock(&ibnd->ring); - -// if (ibnd->ring.fillsz > 0) -// ready |= POLLIN|POLLRDNORM; - -// ibnd->ring.unlock(&ibnd->ring, flags); - -// flags = obnd->ring.lock(&obnd->ring); - -// if (obnd->ring.fillsz < obnd->ring.bufsz) -// ready |= POLLOUT|POLLWRNORM; - -// obnd->ring.unlock(&obnd->ring, flags); - -// return ready; -// } - #[allow(dead_code)] pub fn xbuf_oob_ioctl(_filp: &File, _cmd: u32, _arg: u32) -> i32 { -(bindings::ENOTTY as i32) @@ -769,7 +739,6 @@ pub fn resume_inband_writer(work: *mut IrqWork) { } } -// obnd.i_event locked, hard irqs off pub fn outbound_signal_input(ring: &XbufRing, sigpoll: bool) { let xbuf = kernel::container_of!(ring, RrosXbuf, obnd.ring) as *mut RrosXbuf; @@ -839,43 +808,6 @@ pub fn xbuf_oob_write(filp: &File, data: &mut T) -> i32 { } } -// static __poll_t xbuf_oob_poll(struct file *filp, struct oob_poll_wait *wait) -// { -// struct rros_xbuf *xbuf = element_of(filp, struct rros_xbuf); -// struct xbuf_outbound *obnd = &xbuf->obnd; -// struct xbuf_inbound *ibnd = &xbuf->ibnd; -// unsigned long flags; -// __poll_t ready = 0; - -// rros_poll_watch(&xbuf->poll_head, wait, NULL); - -// flags = obnd->ring.lock(&obnd->ring); - -// if (obnd->ring.fillsz > 0) -// ready |= POLLIN|POLLRDNORM; - -// obnd->ring.unlock(&obnd->ring, flags); - -// flags = ibnd->ring.lock(&ibnd->ring); - -// if (ibnd->ring.fillsz < ibnd->ring.bufsz) -// ready |= POLLOUT|POLLWRNORM; - -// ibnd->ring.unlock(&ibnd->ring, flags); - -// return ready; -// } - -// static int xbuf_release(struct inode *inode, struct file *filp) -// { -// struct rros_xbuf *xbuf = element_of(filp, struct rros_xbuf); - -// rros_flush_wait(&xbuf->obnd.i_event, T_RMID); -// rros_flush_flag(&xbuf->ibnd.o_event, T_RMID); - -// return rros_release_element(inode, filp); -// } - #[allow(dead_code)] pub fn rros_get_xbuf(rfd: u32, rfilpp: &mut *mut RrosFile) -> Option> { let rfilp = rros_get_file(rfd); diff --git a/rust/kernel/double_linked_list.rs b/rust/kernel/double_linked_list.rs index 7f91d66fb63f5..d9d2377aa4660 100644 --- a/rust/kernel/double_linked_list.rs +++ b/rust/kernel/double_linked_list.rs @@ -48,7 +48,7 @@ impl Node { let next = self.next.unwrap().as_ptr(); let prev = self.prev.unwrap().as_ptr(); if next == prev { - //处理list中只有一个元素的情况 + // Handle the case where there is only one element in the list. (*next).prev = None; (*next).next = None; } else { @@ -79,11 +79,10 @@ impl List { /// The `new` method is a constructor for `List`. It takes a value of type `T` and creates a new `List` with a head `Node` that holds the provided value. pub fn new(v: T) -> Self { List { - head: Node::new(v), //头节点 + head: Node::new(v), } } - // 从队头入队 /// The `add_head` method adds a new node at the head of the list. It takes a value of type `T` for the new node. If the list is empty, it adds the new node after the head. Otherwise, it adds the new node after the node currently following the head. pub fn add_head(&mut self, v: T) { if self.is_empty() { @@ -94,7 +93,6 @@ impl List { } } - //入队尾 /// The `add_tail` method adds a new node at the tail of the list. It takes a value of type `T` for the new node. If the list is empty, it adds the new node after the head. Otherwise, it adds the new node after the last node in the list. After adding the new node, it prints the new length of the list. pub fn add_tail(&mut self, v: T) { if self.is_empty() { @@ -109,7 +107,6 @@ impl List { // pr_info!("after add tail, the length is {}", self.len()); } - //得到队头 /// The `get_head` method returns a mutable reference to the first node in the list. If the list is empty, it returns `None`. Otherwise, it returns the node following the head. pub fn get_head<'a>(&self) -> Option<&'a mut Node> { if self.is_empty() { @@ -119,7 +116,6 @@ impl List { } } - //得到队尾 /// The `get_tail` method returns a mutable reference to the last node in the list. If the list is empty, it returns `None`. Otherwise, it returns the node preceding the head. pub fn get_tail<'a>(&self) -> Option<&'a mut Node> { if self.is_empty() { @@ -129,7 +125,6 @@ impl List { } } - //按index取node /// The `get_by_index` method returns a mutable reference to the node at a specific index in the list. It takes an index of type `u32`. The implementation of this method is not shown in the provided code. pub fn get_by_index<'a>(&mut self, index: u32) -> Option<&'a mut Node> { if index <= self.len() { @@ -143,10 +138,8 @@ impl List { } } - //入到index之后 0表示队头 /// The `enqueue_by_index` method inserts a new node at a specific index in the list. It takes an index of type `u32` and a value of type `T` for the new node. If the index is 0, it adds the new node at the head of the list. If the index is equal to the length of the list, it adds the new node at the tail of the list. Otherwise, it adds the new node after the node at the specified index. pub fn enqueue_by_index(&mut self, index: u32, v: T) { - //测试通过 if index <= self.len() { if index == 0 { self.add_head(v); @@ -160,7 +153,6 @@ impl List { } } - //按index出队 /// The `dequeue` method removes the node at a specific index from the list. It takes an index of type `u32`. If the list has only one node and the index is 1, it removes the head node. Otherwise, if the index is less than or equal to the length of the list, it removes the node at the specified index. pub fn dequeue(&mut self, index: u32) { if self.len() == 1 && index == 1 { @@ -174,19 +166,16 @@ impl List { } } - //出队头 /// The `de_head` method removes the head node from the list. It does this by calling the `dequeue` method with an index of 1. pub fn de_head(&mut self) { self.dequeue(1); } - //出队尾 /// The `de_tail` method removes the tail node from the list. It does this by calling the `dequeue` method with an index equal to the length of the list. pub fn de_tail(&mut self) { self.dequeue(self.len()); } - // 计算链表长度 /// The `len` method calculates and returns the length of the list. If the list is not empty, it initializes a counter to 1 and then traverses the list, incrementing the counter for each node until it reaches the node preceding the head. If the list is empty, it returns 0. pub fn len(&self) -> u32 { let mut ans = 0; @@ -203,14 +192,12 @@ impl List { ans } - //判空 /// The `is_empty` method checks if the list is empty. It does this by checking if both the `next` and `prev` fields of the head node are `None`. If they are, the list is empty and the method returns `true`. Otherwise, it returns `false`. pub fn is_empty(&self) -> bool { self.head.next.is_none() && self.head.prev.is_none() } } -//用于测试 impl List { /// The `traverse` method is used for testing. It traverses the list and prints each node. If the list is empty, it returns immediately. Otherwise, it starts from the node following the head and continues until it reaches the node preceding the head. pub fn traverse(&self) { diff --git a/rust/kernel/memory_rros.rs b/rust/kernel/memory_rros.rs index 870a01c209b54..5df054c0170b3 100644 --- a/rust/kernel/memory_rros.rs +++ b/rust/kernel/memory_rros.rs @@ -437,7 +437,7 @@ impl RrosHeap { } } pr_debug!("rros_alloc_chunk: time2 is {}", ktime_get_real_fast_ns()); - //上锁 + // Lock. if bsize >= (RROS_HEAP_PAGE_SIZE as usize) { block = self.add_free_range(bsize, 0); pr_debug!("rros_alloc_chunk: time2.1 is {}", ktime_get_real_fast_ns()); @@ -482,12 +482,11 @@ impl RrosHeap { } pr_debug!("rros_alloc_chunk: time4 is {}", ktime_get_real_fast_ns()); } - //解锁 + // Unlock. pr_debug!("rros_alloc_chunk: time5 is {}", ktime_get_real_fast_ns()); return block; } - //将申请的内存空间初始化为0 /// Method `rros_alloc_chunk_zeroed` allocates a chunk of memory from the `RrosHeap` and initializes it to zero. /// It takes a size as a parameter and returns an `Option<*mut u8>`. /// It first calls `rros_alloc_chunk` to allocate a memory block. @@ -504,7 +503,6 @@ impl RrosHeap { } } - //重新分配空间 /// Method `rros_realloc_chunk` reallocates a chunk of memory in the `RrosHeap`. /// It takes a pointer to the old memory block, the old size, and the new size as parameters, and returns an `Option<*mut u8>`. /// It first calls `rros_alloc_chunk` to allocate a new memory block. @@ -515,7 +513,6 @@ impl RrosHeap { old_size: SizeT, new_size: SizeT, ) -> Option<*mut u8> { - //开辟新空间 let ptr_op = self.rros_alloc_chunk(new_size); match ptr_op { Some(ptr) => { @@ -546,7 +543,6 @@ impl RrosHeap { /// It first reserves a page range with a size aligned to `RROS_HEAP_PAGE_SIZE`. /// If the reservation is successful, it gets the page map of the page and sets the page type and map or block size based on `log2size`. /// If `log2size` is not zero, it sets the page type to `log2size`, the map to the bitwise OR of the bitwise NOT of the block mask and 1, and adds the page to the front of the page list. - //检查、无误 fn add_free_range(&mut self, bsize: SizeT, log2size: i32) -> Option<*mut u8> { let pg_op = self .reserve_page_range(unsafe { rust_helper_align(bsize, RROS_HEAP_PAGE_SIZE) } as SizeT); @@ -594,7 +590,6 @@ impl RrosHeap { /// If it finds a node with a size equal to the given size, it returns a pointer to the range of that node. /// If it doesn't find a node with a size equal to the given size, it sets `rb` to `deepest` and iterates over the size tree again. /// This time, if it finds a node with a size greater than or equal to the given size, it returns a pointer to the range of that node. - //检查:逻辑完整、暂未找到优化点 检查2、无误 fn search_size_ge(&mut self, size: SizeT) -> Option<*mut RrosHeapRange> { let mut rb = self.size_tree.as_mut().unwrap().rb_node; let mut deepest = core::ptr::null_mut(); @@ -632,7 +627,6 @@ impl RrosHeap { /// If it finds such a range, it removes the range from the size tree. /// If the size of the range is equal to the given size, it also removes the range from the address tree and returns the page number of the range. /// If the size of the range is greater than the given size, it splits the range into two ranges, inserts the smaller range back into the size tree, and returns the page number of the larger range. - //检查、无误 fn reserve_page_range(&mut self, size: SizeT) -> Option { let new_op = self.search_size_ge(size); let mut new; @@ -735,7 +729,6 @@ impl RrosHeap { /// It first calculates `ilog` as the difference between `log2size` and `RROS_HEAP_MIN_LOG2`. /// If the bucket is empty, it sets the bucket to the page number and sets the previous and next pointers of the page map to the page number. /// Otherwise, it gets the page map of the first page in the bucket, sets the previous pointer of the new page map to the first page, sets the next pointer of the new page map to the second page, sets the previous pointer of the second page to the new page, sets the next pointer of the first page to the new page, and sets the bucket to the new page. - //检查、无误 fn add_page_front(&mut self, pg: i32, log2size: i32) { let ilog = ((log2size as u32) - RROS_HEAP_MIN_LOG2) as usize; pr_debug!("add_page_front: ilog is {}", ilog); @@ -797,15 +790,14 @@ impl RrosHeap { } else { let log2size = page_type as i32; bsize = 1 << log2size; - let boff = pgoff & !RROS_HEAP_PAGE_MASK; //页内偏移 + let boff = pgoff & !RROS_HEAP_PAGE_MASK; // In-page offset if (boff & ((bsize - 1) as u32)) != 0 { return; - //解锁 //raw_spin_unlock_irqrestore(&heap->lock, flags); } let n = boff >> log2size; let oldmap = unsafe { (*pagemap).pginfo.map }; - unsafe { (*pagemap).pginfo.map &= !((1 as u32) << n) }; //置原map对应的位置为0,表示释放 + unsafe { (*pagemap).pginfo.map &= !((1 as u32) << n) }; // Set the corresponding position of the original map to 0, indicating release. unsafe { pr_debug!( "rros_free_chunk: pg is {}, log2size is {}, oldmap is {}, newmap is {}", @@ -816,7 +808,7 @@ impl RrosHeap { ); } if unsafe { (*pagemap).pginfo.map == !gen_block_mask(log2size) } { - //释放后页为空 + // The page is empty after release. pr_debug!("rros_free_chunk: 1"); self.remove_page(pg, log2size); pr_debug!("rros_free_chunk: 1.2"); diff --git a/rust/kernel/memory_rros_test.rs b/rust/kernel/memory_rros_test.rs index 424d7a8cd5247..b77ec9de8f354 100644 --- a/rust/kernel/memory_rros_test.rs +++ b/rust/kernel/memory_rros_test.rs @@ -1,10 +1,6 @@ // SPDX-License-Identifier: GPL-2.0 -//! Rros Memory Allocator Tests. - -/* -测试内存分配的正确性 -*/ +//! Rros Memory Allocator Tests. Test the correctness of memory allocation. use crate::memory_rros::*; use crate::random; @@ -22,7 +18,6 @@ pub fn main_memory_rros_test() { /// Function `test_addr_valid` checks if an address is valid. /// It takes an address and a size as parameters and returns a boolean. /// It currently always returns false. -//判断某个地址是否有效 #[allow(dead_code)] fn test_addr_valid(_addr: *mut u8, _size: SizeT) -> bool { return false; @@ -33,7 +28,6 @@ fn test_addr_valid(_addr: *mut u8, _size: SizeT) -> bool { /// It first generates a random number using the `getrandom` function. /// If the generation is successful, it calculates the final number as the start plus the random number modulo the difference between the end and the start. /// If the generation fails, it prints an error message and returns 0. -//得到随机数,左闭右开 //[1,16) fn get_random(start: u32, end: u32) -> u32 { let mut t: [u8; 4] = [1, 2, 3, 4]; @@ -74,7 +68,7 @@ impl Pair { } #[allow(dead_code)] -//计算当前buckets中的pg链表的数量 +// Calculate the number of pg linked lists in the current buckets. fn calcuate_buckets() { unsafe { for i in 0..5 { @@ -103,7 +97,7 @@ fn calcuate_buckets() { } } -//输入分配范围,进行连续分配测试 +// Enter the allocation range for continuous allocation testing. fn mem_alloc_range(start: u32, end: u32, repeat: u32) { pr_debug!("mem_alloc_range: begin"); let base = Pair::new(1 as *mut u8, 0); @@ -116,7 +110,7 @@ fn mem_alloc_range(start: u32, end: u32, repeat: u32) { RROS_SYSTEM_HEAP.used_size ); } - //进行分配 + // alloc for i in 0..repeat { let num = get_random(start, end); sum += num; @@ -142,7 +136,7 @@ fn mem_alloc_range(start: u32, end: u32, repeat: u32) { ); } // calcuate_buckets(); - //进行回收 + // recycle let length = link_head.len() + 1; for i in 1..length { let x = link_head.get_by_index(i).unwrap().value.addr; @@ -172,7 +166,7 @@ fn mem_alloc_range(start: u32, end: u32, repeat: u32) { pr_debug!("mem_alloc_range: end"); } -//随机分配与回收 +// Random allocation and recycling. fn random_mem_alloc_range(start: u32, end: u32, repeat: u32) { pr_debug!("random_mem_alloc_range: begin"); let base = Pair::new(1 as *mut u8, 0); @@ -184,11 +178,11 @@ fn random_mem_alloc_range(start: u32, end: u32, repeat: u32) { RROS_SYSTEM_HEAP.used_size ); } - //进行分配 + // allocate for i in 1..repeat { let r = get_random(0, 2); if r == 0 { - //0表示分配 + // 0 means allocation let num = get_random(start, end); let x = unsafe { RROS_SYSTEM_HEAP.rros_alloc_chunk(num as usize) }; match x { @@ -207,7 +201,7 @@ fn random_mem_alloc_range(start: u32, end: u32, repeat: u32) { num ); } else { - //1表示回收 + // 1 means recycling let length = link_head.len(); if length > 0 { let x = link_head.get_by_index(1).unwrap().value.addr; @@ -227,7 +221,7 @@ fn random_mem_alloc_range(start: u32, end: u32, repeat: u32) { ); } - //进行回收 + // recycle let length = link_head.len() + 1; for i in 1..length { let x = link_head.get_by_index(i).unwrap().value.addr; @@ -258,7 +252,7 @@ fn random_mem_alloc_range(start: u32, end: u32, repeat: u32) { } fn small_chunk_alloc_test() { - mem_alloc_range(1, 257, 100); //连续分配小内存 - mem_alloc_range(257, 2048, 100); //连续分配大内存 - random_mem_alloc_range(1, 2049, 100); //随机分配内存 + mem_alloc_range(1, 257, 100); // allocate small memory continuously + mem_alloc_range(257, 2048, 100); // allocate large memory continuously + random_mem_alloc_range(1, 2049, 100); // randomly allocate memory } diff --git a/rust/kernel/percpu_defs.rs b/rust/kernel/percpu_defs.rs index 640ba42a40281..648d54458d49f 100644 --- a/rust/kernel/percpu_defs.rs +++ b/rust/kernel/percpu_defs.rs @@ -16,9 +16,9 @@ extern "C" { fn rust_helper_smp_processor_id() -> c_types::c_int; } -//per_cpu原型: +// per_cpu prototype: //#define per_cpu(var, cpu) (*per_cpu_ptr(&(var), cpu)) -//per_cpu返回具体值无法实现,因此只能用per_cpu_ptr来返回指针 +// It is not possible to return a specific value per_cpu, so per_cpu_ptr can only be used to return a pointer. /// Function `per_cpu_ptr` gets a per-CPU pointer. /// It takes a variable and a CPU ID as parameters and returns a per-CPU pointer. diff --git a/rust/kernel/pipeline.rs b/rust/kernel/pipeline.rs deleted file mode 100644 index 47bb7af6c54c5..0000000000000 --- a/rust/kernel/pipeline.rs +++ /dev/null @@ -1,5 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0 - -//! pipeline -//! -//! C header: [`include/linux/pipeline.h`](../../../../include/linux/pipeline.h) diff --git a/rust/kernel/sysfs.rs b/rust/kernel/sysfs.rs index e0fdf000225f1..69dd3fc0420ee 100644 --- a/rust/kernel/sysfs.rs +++ b/rust/kernel/sysfs.rs @@ -35,9 +35,3 @@ impl AttributeGroup { unsafe { core::mem::zeroed() } } } - -// struct rros_clock_gravity { -// ktime_t irq; -// ktime_t kernel; -// ktime_t user; -// };