This repository was archived by the owner on Nov 26, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 5 files changed +92
-4
lines changed
Expand file tree Collapse file tree 5 files changed +92
-4
lines changed Original file line number Diff line number Diff line change 11use arceos_posix_api:: { self as api, ctypes:: timeval} ;
22use axerrno:: LinuxResult ;
3- use axhal:: time:: { monotonic_time_nanos, nanos_to_ticks} ;
4- use starry_core:: { ctypes:: Tms , task:: time_stat_output} ;
3+ use axhal:: time:: { monotonic_time_nanos, nanos_to_ticks, NANOS_PER_SEC } ;
4+ use starry_core:: { ctypes:: Tms , task:: time_stat_output, ctypes :: SysInfo } ;
55
66use crate :: ptr:: { PtrWrapper , UserPtr } ;
77
@@ -25,3 +25,33 @@ pub fn sys_times(tms: UserPtr<Tms>) -> LinuxResult<isize> {
2525 }
2626 Ok ( nanos_to_ticks ( monotonic_time_nanos ( ) ) as _ )
2727}
28+
29+ /// get the system uptime and memory information.
30+ /// # Arguments
31+ /// * `info` - *mut SysInfo
32+ pub fn sys_sysinfo ( sysinfo : UserPtr < SysInfo > ) -> LinuxResult < isize > {
33+ // let sysinfo = sysinfo.address().as_mut_ptr();
34+ // check if the pointer is valid
35+ // if sysinfo.is_null() {
36+ // return Err(axerrno::LinuxError::EFAULT);
37+ // }
38+ // get the system uptime
39+ unsafe {
40+ * sysinfo. get ( ) ? = SysInfo {
41+ uptime : ( monotonic_time_nanos ( ) / NANOS_PER_SEC ) as isize ,
42+ loads : [ 0 ; 3 ] ,
43+ totalram : 0 ,
44+ freeram : 0 ,
45+ sharedram : 0 ,
46+ bufferram : 0 ,
47+ totalswap : 0 ,
48+ freeswap : 0 ,
49+ procs : 0 ,
50+ totalhigh : 0 ,
51+ freehigh : 0 ,
52+ mem_unit : 1 ,
53+ } ;
54+ }
55+
56+ Ok ( 0 )
57+ }
Original file line number Diff line number Diff line change 1- /musl/runtest.exe -w entry-static.exe argv
2- /musl/runtest.exe -w entry-static.exe qsort
1+
Original file line number Diff line number Diff line change 1+ #include <stdio.h>
2+ #include <sys/sysinfo.h> // 包含 sysinfo 结构体定义
3+
4+ int main () {
5+ struct sysinfo info ;
6+
7+ // 调用 sysinfo 系统调用
8+ if (sysinfo (& info ) != 0 ) {
9+ perror ("sysinfo failed" );
10+ return 1 ;
11+ }
12+
13+ // 打印系统信息
14+ printf ("System Uptime: %lu seconds\n" , info .uptime ); // 系统启动时间(秒)
15+ printf ("Total RAM: %lu KB\n" , info .totalram ); // 总物理内存(以字节为单位)
16+ printf ("Free RAM: %lu KB\n" , info .freeram ); // 空闲物理内存(以字节为单位)
17+ printf ("Shared RAM: %lu KB\n" , info .sharedram ); // 共享内存(以字节为单位)
18+ printf ("Buffer RAM: %lu KB\n" , info .bufferram ); // 缓冲区内存(以字节为单位)
19+ printf ("Total Swap: %lu KB\n" , info .totalswap ); // 总交换空间(以字节为单位)
20+ printf ("Free Swap: %lu KB\n" , info .freeswap ); // 空闲交换空间(以字节为单位)
21+ printf ("Number of Processors: %d\n" , info .procs ); // 当前运行的进程数
22+ printf ("Total High Memory: %lu KB\n" , info .totalhigh ); // 总高位内存(以字节为单位)
23+ printf ("Free High Memory: %lu KB\n" , info .freehigh ); // 空闲高位内存(以字节为单位)
24+ printf ("Memory Unit Size: %u bytes\n" , info .mem_unit ); // 内存单位大小(字节)
25+
26+ return 0 ;
27+ }
Original file line number Diff line number Diff line change 11/prlimit64
22/fork
3+ /sysinfo
Original file line number Diff line number Diff line change @@ -98,6 +98,37 @@ pub const RLIMIT_NOFILE: i32 = 7;
9898/// 用户地址空间的最大大小
9999pub const RLIMIT_AS : i32 = 9 ;
100100
101+ /// syscall_info 用到的 结构体
102+ #[ repr( C ) ]
103+ #[ derive( Debug ) ]
104+ pub struct SysInfo {
105+ /// 启动时间(以秒计)
106+ pub uptime : isize ,
107+ /// 1 / 5 / 15 分钟平均负载
108+ pub loads : [ usize ; 3 ] ,
109+ /// 内存总量,单位为 mem_unit Byte(见下)
110+ pub totalram : usize ,
111+ /// 当前可用内存,单位为 mem_unit Byte(见下)
112+ pub freeram : usize ,
113+ /// 共享内存大小,单位为 mem_unit Byte(见下)
114+ pub sharedram : usize ,
115+ /// 用于缓存的内存大小,单位为 mem_unit Byte(见下)
116+ pub bufferram : usize ,
117+ /// swap空间大小,即主存上用于替换内存中非活跃部分的空间大小,单位为 mem_unit Byte(见下)
118+ pub totalswap : usize ,
119+ /// 可用的swap空间大小,单位为 mem_unit Byte(见下)
120+ pub freeswap : usize ,
121+ /// 当前进程数,单位为 mem_unit Byte(见下)
122+ pub procs : u16 ,
123+ /// 高地址段的内存大小,单位为 mem_unit Byte(见下)
124+ pub totalhigh : usize ,
125+ /// 可用的高地址段的内存大小,单位为 mem_unit Byte(见下)
126+ pub freehigh : usize ,
127+ /// 指定 sys_info 的结构中用到的内存值的单位。
128+ /// 如 mem_unit = 1024, totalram = 100, 则指示总内存为 100K
129+ pub mem_unit : u32 ,
130+ }
131+
101132numeric_enum_macro:: numeric_enum! {
102133 #[ repr( i32 ) ]
103134 #[ allow( non_camel_case_types) ]
You can’t perform that action at this time.
0 commit comments