mirror of
https://github.com/DragonOS-Community/DragonOS.git
synced 2025-06-23 20:33:23 +00:00
增加getrusage,并把apic timer的频率调整为系统HZ (#435)
This commit is contained in:
@ -61,6 +61,7 @@ pub mod init;
|
||||
pub mod kthread;
|
||||
pub mod pid;
|
||||
pub mod process;
|
||||
pub mod resource;
|
||||
pub mod syscall;
|
||||
|
||||
/// 系统中所有进程的pcb
|
||||
|
85
kernel/src/process/resource.rs
Normal file
85
kernel/src/process/resource.rs
Normal file
@ -0,0 +1,85 @@
|
||||
use crate::{syscall::SystemError, time::TimeSpec};
|
||||
|
||||
use super::ProcessControlBlock;
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
|
||||
#[repr(C)]
|
||||
pub struct RUsage {
|
||||
/// User time used
|
||||
pub ru_utime: TimeSpec,
|
||||
/// System time used
|
||||
pub ru_stime: TimeSpec,
|
||||
|
||||
// 以下是linux的rusage结构体扩展
|
||||
/// Maximum resident set size
|
||||
pub ru_maxrss: usize,
|
||||
/// Integral shared memory size
|
||||
pub ru_ixrss: usize,
|
||||
/// Integral unshared data size
|
||||
pub ru_idrss: usize,
|
||||
/// Integral unshared stack size
|
||||
pub ru_isrss: usize,
|
||||
/// Page reclaims (soft page faults)
|
||||
pub ru_minflt: usize,
|
||||
/// Page faults (hard page faults)
|
||||
pub ru_majflt: usize,
|
||||
/// Swaps
|
||||
pub ru_nswap: usize,
|
||||
/// Block input operations
|
||||
pub ru_inblock: usize,
|
||||
/// Block output operations
|
||||
pub ru_oublock: usize,
|
||||
/// IPC messages sent
|
||||
pub ru_msgsnd: usize,
|
||||
/// IPC messages received
|
||||
pub ru_msgrcv: usize,
|
||||
/// Signals received
|
||||
pub ru_nsignals: usize,
|
||||
/// Voluntary context switches
|
||||
pub ru_nvcsw: usize,
|
||||
/// Involuntary context switches
|
||||
pub ru_nivcsw: usize,
|
||||
}
|
||||
|
||||
///
|
||||
/// Definition of struct rusage taken from BSD 4.3 Reno
|
||||
///
|
||||
/// We don't support all of these yet, but we might as well have them....
|
||||
/// Otherwise, each time we add new items, programs which depend on this
|
||||
/// structure will lose. This reduces the chances of that happening.
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
pub enum RUsageWho {
|
||||
RUsageSelf = 0,
|
||||
RUsageChildren = -1,
|
||||
/// sys_wait4() uses this
|
||||
RUsageBoth = -2,
|
||||
/// only the calling thread
|
||||
RusageThread = 1,
|
||||
}
|
||||
|
||||
impl TryFrom<i32> for RUsageWho {
|
||||
type Error = SystemError;
|
||||
|
||||
fn try_from(value: i32) -> Result<Self, Self::Error> {
|
||||
match value {
|
||||
0 => Ok(RUsageWho::RUsageSelf),
|
||||
-1 => Ok(RUsageWho::RUsageChildren),
|
||||
-2 => Ok(RUsageWho::RUsageBoth),
|
||||
1 => Ok(RUsageWho::RusageThread),
|
||||
_ => Err(SystemError::EINVAL),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl ProcessControlBlock {
|
||||
/// 获取进程资源使用情况
|
||||
///
|
||||
/// ## TODO
|
||||
///
|
||||
/// 当前函数尚未实现,只是返回了一个默认的RUsage结构体
|
||||
pub fn get_rusage(&self, _who: RUsageWho) -> Option<RUsage> {
|
||||
let rusage = RUsage::default();
|
||||
|
||||
Some(rusage)
|
||||
}
|
||||
}
|
@ -9,6 +9,7 @@ use alloc::{
|
||||
use super::{
|
||||
abi::WaitOption,
|
||||
fork::{CloneFlags, KernelCloneArgs},
|
||||
resource::{RUsage, RUsageWho},
|
||||
KernelStack, Pid, ProcessManager, ProcessState,
|
||||
};
|
||||
use crate::{
|
||||
@ -320,4 +321,16 @@ impl Syscall {
|
||||
// todo: 增加credit功能之后,需要修改
|
||||
return Ok(0);
|
||||
}
|
||||
|
||||
pub fn get_rusage(who: i32, rusage: *mut RUsage) -> Result<usize, SystemError> {
|
||||
let who = RUsageWho::try_from(who)?;
|
||||
let mut writer = UserBufferWriter::new(rusage, core::mem::size_of::<RUsage>(), true)?;
|
||||
let pcb = ProcessManager::current_pcb();
|
||||
let rusage = pcb.get_rusage(who).ok_or(SystemError::EINVAL)?;
|
||||
|
||||
let ubuf = writer.buffer::<RUsage>(0).unwrap();
|
||||
ubuf.copy_from_slice(&[rusage]);
|
||||
|
||||
return Ok(0);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user