2019-11-15 16:14:28 +03:00
|
|
|
module runtime
|
|
|
|
|
2021-07-17 17:07:59 +03:00
|
|
|
fn C.sysconf(name int) i64
|
|
|
|
|
2020-12-27 21:14:43 +03:00
|
|
|
// nr_cpus returns the number of virtual CPU cores found on the system.
|
2020-07-20 17:36:44 +03:00
|
|
|
pub fn nr_cpus() int {
|
2022-01-19 20:29:29 +03:00
|
|
|
return int(C.sysconf(C._SC_NPROCESSORS_ONLN))
|
2020-12-27 21:14:43 +03:00
|
|
|
}
|
2023-06-24 14:15:15 +03:00
|
|
|
|
|
|
|
// total_memory returns total physical memory found on the system.
|
|
|
|
pub fn total_memory() usize {
|
|
|
|
page_size := usize(C.sysconf(C._SC_PAGESIZE))
|
|
|
|
phys_pages := usize(C.sysconf(C._SC_PHYS_PAGES))
|
|
|
|
return page_size * phys_pages
|
|
|
|
}
|
|
|
|
|
|
|
|
// free_memory returns free physical memory found on the system.
|
|
|
|
pub fn free_memory() usize {
|
|
|
|
return free_memory_impl()
|
|
|
|
}
|