Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rust: rros: fix warnings #14

Merged
merged 2 commits into from
Dec 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion drivers/android/process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -823,7 +823,7 @@ impl IoctlHandler for Process {
}

impl FileOpener<Ref<Context>> for Process {
fn open(ctx: &Ref<Context>, fileref: &File) -> Result<Self::Wrapper> {
fn open(ctx: &Ref<Context>, _fileref: &File) -> Result<Self::Wrapper> {
Self::new(ctx.clone())
}
}
Expand Down
8 changes: 5 additions & 3 deletions kernel/rros/arch/arm64/syscall.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
use kernel::bindings;
use kernel::prelude::*;
use kernel::ptrace::{IrqStage, PtRegs};
use kernel::{
bindings,
prelude::*,
ptrace::PtRegs,
};

/// Returns the first register value from the given out-of-bounds pointer.
#[macro_export]
Expand Down
164 changes: 52 additions & 112 deletions kernel/rros/clock.rs
Original file line number Diff line number Diff line change
@@ -1,46 +1,47 @@
// #![feature(allocator_api)]
// #![allow(warnings, unused)]
// #![feature(stmt_expr_attributes)]

#![allow(warnings, unused)]
#![feature(stmt_expr_attributes)]
use crate::factory;
use crate::list::*;
use crate::sched::{rros_cpu_rq, this_rros_rq, RQ_TDEFER, RQ_TIMER, RQ_TPROXY};
use crate::thread::T_ROOT;
use crate::tick;
use crate::timeout::RROS_INFINITE;
use crate::{
factory::CloneData, factory::RrosElement, factory::RrosFactory, factory::RustFile, lock::*,
factory::{CloneData, RrosElement, RrosFactory, RustFile, RROS_CLONE_PUBLIC},
factory,
lock::*,
tick::*, timer::*, RROS_OOB_CPUS,
list::*,
sched::{rros_cpu_rq, this_rros_rq, RQ_TDEFER, RQ_TIMER, RQ_TPROXY},
thread::T_ROOT,
tick,
timeout::RROS_INFINITE,
};

use alloc::rc::Rc;
use core::borrow::{Borrow, BorrowMut};
use core::cell::RefCell;
use core::cell::UnsafeCell;
use core::clone::Clone;
use core::ops::Deref;
use core::ops::DerefMut;
use core::{mem::align_of, mem::size_of, todo};
use factory::RROS_CLONE_PUBLIC;
use kernel::device::DeviceType;
use kernel::file::File;
use kernel::io_buffer::IoBufferWriter;

use core::{
borrow::{Borrow, BorrowMut},
cell::{RefCell, UnsafeCell},
clone::Clone,
ops::{DerefMut, Deref},
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,
timekeeping,
clockchips,
uidgid::{KgidT, KuidT},
file::File,
io_buffer::IoBufferWriter,
device::DeviceType,
};

static mut CLOCKLIST_LOCK: SpinLock<i32> = 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)]
Expand Down Expand Up @@ -85,11 +86,10 @@ impl RrosClockGravity {
}
}

//定义时钟操作
pub struct RrosClockOps {
read: Option<fn(&RrosClock) -> KtimeT>,
readcycles: Option<fn(&RrosClock) -> u64>,
set: Option<fn(&mut RrosClock, KtimeT) -> i32>, //int
set: Option<fn(&mut RrosClock, KtimeT) -> i32>,
programlocalshot: Option<fn(&RrosClock)>,
programremoteshot: Option<fn(&RrosClock, *mut RrosRq)>,
setgravity: Option<fn(&mut RrosClock, RrosClockGravity)>,
Expand All @@ -101,7 +101,7 @@ impl RrosClockOps {
pub fn new(
read: Option<fn(&RrosClock) -> KtimeT>,
readcycles: Option<fn(&RrosClock) -> u64>,
set: Option<fn(&mut RrosClock, KtimeT) -> i32>, //int
set: Option<fn(&mut RrosClock, KtimeT) -> i32>,
programlocalshot: Option<fn(&RrosClock)>,
programremoteshot: Option<fn(&RrosClock, *mut RrosRq)>,
setgravity: Option<fn(&mut RrosClock, RrosClockGravity)>,
Expand Down Expand Up @@ -135,9 +135,8 @@ pub struct RrosClock {
dispose: Option<fn(&mut RrosClock)>,
#[cfg(CONFIG_SMP)]
pub affinity: Option<cpumask::CpumaskT>,
} //____cacheline_aligned
}

//RrosClock主方法
impl RrosClock {
pub fn new(
resolution: KtimeT,
Expand Down Expand Up @@ -170,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);
}
Expand All @@ -187,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)
}
Expand Down Expand Up @@ -217,7 +217,7 @@ impl RrosClock {
}
}
pub fn get_timerdata_addr(&self) -> *mut RrosTimerbase {
//错误处理
// Error handling.
return self.timerdata as *mut RrosTimerbase;
}

Expand All @@ -242,7 +242,6 @@ impl RrosClock {
}
}

//测试通过
pub fn adjust_timer(
clock: &RrosClock,
timer: Arc<SpinLock<RrosTimer>>,
Expand Down Expand Up @@ -294,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 };
Expand All @@ -321,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);
Expand All @@ -335,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()
}
Expand All @@ -368,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()
Expand All @@ -396,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 {
Expand All @@ -416,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,
Expand Down Expand Up @@ -453,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,
Expand Down Expand Up @@ -544,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()
Expand All @@ -579,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)]
Expand Down Expand Up @@ -662,14 +619,14 @@ impl clockchips::CoreTick for RrosCoreTick {
// pr_debug!("in rros_core_tick");
let this_rq = this_rros_rq();
// if (RROS_WARN_ON_ONCE(CORE, !is_rros_cpu(rros_rq_cpu(this_rq))))
// pr_debug!("in rros_core_tick");
// pr_info!("in rros_core_tick");
unsafe {
do_clock_tick(&mut RROS_MONO_CLOCK, rros_this_cpu_timers(&RROS_MONO_CLOCK));

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");
Expand Down Expand Up @@ -700,7 +657,6 @@ impl clockchips::CoreTick for RrosCoreTick {
}
}

//初始化时钟
fn init_clock(clock: *mut RrosClock, master: *mut RrosClock) -> Result<usize> {
// unsafe{
// if (*clock).element.is_none(){
Expand All @@ -725,11 +681,10 @@ fn init_clock(clock: *mut RrosClock, master: *mut RrosClock) -> Result<usize> {
Ok(0)
}

//初始化时钟slave
fn rros_init_slave_clock(clock: &mut RrosClock, master: &mut RrosClock) -> Result<usize> {
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;

Expand All @@ -739,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<usize> {
premmpt::running_inband()?;
// 8 byte alignment
let tmb = percpu::alloc_per_cpu(
size_of::<RrosTimerbase>() as usize,
align_of::<RrosTimerbase>() as usize,
) as *mut RrosTimerbase; //8字节对齐
) as *mut RrosTimerbase;
if tmb == 0 as *mut RrosTimerbase {
return Err(kernel::Error::ENOMEM);
}
Expand All @@ -766,7 +721,6 @@ fn rros_init_clock(clock: &mut RrosClock, affinity: &cpumask::CpumaskT) -> Resul
Ok(0)
}

//时钟系统初始化
pub fn rros_clock_init() -> Result<usize> {
let pinned = unsafe { Pin::new_unchecked(&mut CLOCKLIST_LOCK) };
spinlock_init!(pinned, "CLOCKLIST_LOCK");
Expand Down Expand Up @@ -797,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);
// }
Loading