Skip to content

Commit

Permalink
refactor: modify some statement for specifications
Browse files Browse the repository at this point in the history
  • Loading branch information
AuYang261 committed Sep 15, 2023
1 parent 9754800 commit daa56a8
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 30 deletions.
2 changes: 1 addition & 1 deletion api/arceos_posix_api/src/imp/sys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ pub unsafe extern "C" fn sys_sysinfo(info: *mut ctypes::sysinfo) -> c_int {
info_mut.loads = [0; 3];
#[cfg(feature = "axtask")]
{
axtask::loadavg::get_avenrun(&mut info_mut.loads);
axtask::get_avenrun(&mut info_mut.loads);
}

info_mut.sharedram = 0;
Expand Down
5 changes: 2 additions & 3 deletions api/arceos_posix_api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ extern crate axruntime;
#[cfg(feature = "alloc")]
extern crate alloc;

pub use memory_addr::PAGE_SIZE_4K;

#[macro_use]
mod utils;

Expand All @@ -35,6 +33,7 @@ mod imp;
/// Platform-specific constants and parameters.
pub mod config {
pub use axconfig::*;
pub use memory_addr::PAGE_SIZE_4K;
}

/// POSIX C types.
Expand All @@ -50,7 +49,7 @@ pub use imp::task::{sys_exit, sys_getpid, sys_sched_yield};
pub use imp::time::{sys_clock_gettime, sys_nanosleep};

#[cfg(feature = "fd")]
pub use imp::fd_ops::{sys_close, sys_dup, sys_dup2, sys_fcntl, AX_FILE_LIMIT};
pub use imp::fd_ops::{sys_close, sys_dup, sys_dup2, sys_fcntl};
#[cfg(feature = "fs")]
pub use imp::fs::{sys_fstat, sys_getcwd, sys_lseek, sys_lstat, sys_open, sys_rename, sys_stat};
#[cfg(feature = "select")]
Expand Down
13 changes: 13 additions & 0 deletions modules/axtask/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,21 @@ cfg_if::cfg_if! {
mod task;
mod api;
mod wait_queue;
#[cfg(feature = "irq")]
/// load average
pub mod loadavg;
// TODO: if irq is disabled, what value should AVENRUN be?
static mut AVENRUN: [u64; 3] = [0, 0, 0];

/// Get the load average
pub fn get_avenrun(loads: &mut [u64; 3]) {
for i in 0..3 {
unsafe {
// TODO: disable irq for safety
loads[i] = AVENRUN[i];
}
}
}

#[cfg(feature = "irq")]
mod timers;
Expand Down
24 changes: 2 additions & 22 deletions modules/axtask/src/loadavg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,42 +7,23 @@
* See the Mulan PSL v2 for more details.
*/

#[cfg(feature = "irq")]
use core::sync::atomic::{AtomicU64, Ordering};

#[cfg(feature = "irq")]
use crate::AVENRUN;

const FSHIFT: u64 = 11;
#[cfg(feature = "irq")]
const FIXED_1: u64 = 1 << FSHIFT;
#[cfg(feature = "irq")]
const LOAD_FREQ: u64 = 5 * axhal::time::NANOS_PER_SEC + 1;

#[cfg(feature = "irq")]
/* 1/exp(5sec/1min) as fixed-point */
/* 1/exp(5sec/5min) */
/* 1/exp(5sec/15min) */
const EXP: [u64; 3] = [1884, 2014, 2037];

#[cfg(feature = "irq")]
static mut IDLE_CNT: AtomicU64 = AtomicU64::new(0);
#[cfg(feature = "irq")]
static mut ALL_CNT: AtomicU64 = AtomicU64::new(0);
#[cfg(feature = "irq")]
static mut LAST_UPDATE: AtomicU64 = AtomicU64::new(0);
// TODO: if irq is disabled, what value should AVENRUN be?
static mut AVENRUN: [u64; 3] = [0, 0, 0];

/// Get the load average
pub fn get_avenrun(loads: &mut [u64; 3]) {
for i in 0..3 {
unsafe {
// TODO: disable irq for safety
loads[i] = AVENRUN[i];
}
}
}

#[cfg(feature = "irq")]
/*
* a1 = a0 * e + a * (1 - e)
*/
Expand All @@ -54,7 +35,6 @@ fn calc_load(load: u64, exp: u64, active: u64) -> u64 {
newload / FIXED_1
}

#[cfg(feature = "irq")]
/*
* calc_load - update the avenrun load estimates 10 ticks after the
* CPUs have updated calc_load_tasks.
Expand Down
8 changes: 4 additions & 4 deletions ulib/axlibc/src/sys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* See the Mulan PSL v2 for more details.
*/

use arceos_posix_api::{config, ctypes, sys_getrlimit, PAGE_SIZE_4K};
use arceos_posix_api::{config, ctypes, sys_getrlimit};
use core::ffi::{c_int, c_long};

/// Return system configuration infomation
Expand All @@ -23,16 +23,16 @@ pub unsafe extern "C" fn sysconf(name: c_int) -> c_long {
rl.rlim_max as c_long
}
// Page size
ctypes::_SC_PAGE_SIZE => PAGE_SIZE_4K as c_long,
ctypes::_SC_PAGE_SIZE => config::PAGE_SIZE_4K as c_long,
// Total physical pages
ctypes::_SC_PHYS_PAGES => (config::PHYS_MEMORY_SIZE / PAGE_SIZE_4K) as c_long,
ctypes::_SC_PHYS_PAGES => (config::PHYS_MEMORY_SIZE / config::PAGE_SIZE_4K) as c_long,
// Number of processors in use
ctypes::_SC_NPROCESSORS_ONLN => config::SMP as c_long,
// Avaliable physical pages
ctypes::_SC_AVPHYS_PAGES => {
let mut info: arceos_posix_api::ctypes::sysinfo = core::mem::zeroed();
arceos_posix_api::sys_sysinfo(&mut info);
(info.freeram / PAGE_SIZE_4K as u64) as c_long
(info.freeram / config::PAGE_SIZE_4K as u64) as c_long
}
// Maximum number of files per process
#[cfg(feature = "fd")]
Expand Down

0 comments on commit daa56a8

Please sign in to comment.