From ca7cb625b9769be2657365e2137197bdc3a9692d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20D=C3=B6rfler?= Date: Wed, 17 Sep 2008 16:27:17 +0000 Subject: [PATCH] * Implemented a (private for now) get_system_info_etc() call, that can retrieve various system information. * Implemented retrieving some VM stats via this call. * The VM now maintains a page fault counter, and sets system_info::page_faults accordingly. * Added a (pretty simple) "vmstat" command line app. * Minor cleanup. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@27597 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- build/jam/HaikuImage | 4 +- .../kernel/{system_info.h => ksystem_info.h} | 8 +- headers/private/kernel/vm.h | 5 +- headers/private/system/syscalls.h | 2 + headers/private/system/system_info.h | 37 ++++++ src/bin/Jamfile | 6 +- src/bin/vmstat.cpp | 109 ++++++++++++++++++ src/system/kernel/debug/debug.cpp | 2 +- src/system/kernel/main.cpp | 2 +- src/system/kernel/syscalls.cpp | 52 ++++----- src/system/kernel/system_info.cpp | 28 +++++ src/system/kernel/vm/VMAnonymousCache.cpp | 14 +++ src/system/kernel/vm/VMAnonymousCache.h | 3 + src/system/kernel/vm/vm.cpp | 35 +++++- src/system/kernel/vm/vm_page.cpp | 1 + src/system/libroot/os/system_info.c | 22 +++- 16 files changed, 282 insertions(+), 48 deletions(-) rename headers/private/kernel/{system_info.h => ksystem_info.h} (61%) create mode 100644 headers/private/system/system_info.h create mode 100644 src/bin/vmstat.cpp diff --git a/build/jam/HaikuImage b/build/jam/HaikuImage index b7270658b2..99dd3d5fc7 100644 --- a/build/jam/HaikuImage +++ b/build/jam/HaikuImage @@ -50,7 +50,7 @@ BEOS_BIN = "[" addattr alert arp base64 basename bc beep bootman bzip2 cal cat traceroute translate true tsort tty uname unchop unexpand unmount uniq unrar unshar unzip unzipsfx updatedb uptime urlwrapper usb_dev_info useradd uudecode uuencode - vdir version vim waitfor wc wget whoami xargs xres yes + vdir version vim vmstat waitfor wc wget whoami xargs xres yes zdiff zforce zgrep zip zipcloak zipgrep zipnote zipsplit zmore znew ; @@ -138,7 +138,7 @@ BEOS_ADD_ONS_DRIVERS_NET = $(X86_ONLY)3com etherpci $(X86_ONLY)ipro1000 ; #BEOS_ADD_ONS_DRIVERS_ACPI = $(X86_ONLY)acpi_button ; BEOS_ADD_ONS_BUS_MANAGERS = pci $(X86_ONLY)ps2 $(X86_ONLY)isa ide scsi - config_manager agp_gart usb firewire + config_manager agp_gart usb firewire #acpi ; BEOS_ADD_ONS_FILE_SYSTEMS = bfs cdda ext2 fat iso9660 $(GPL_ONLY)reiserfs ; #googlefs nfs $(GPL_ONLY)ntfs ; diff --git a/headers/private/kernel/system_info.h b/headers/private/kernel/ksystem_info.h similarity index 61% rename from headers/private/kernel/system_info.h rename to headers/private/kernel/ksystem_info.h index 98bc4fb070..adf9ad76ba 100644 --- a/headers/private/kernel/system_info.h +++ b/headers/private/kernel/ksystem_info.h @@ -1,5 +1,5 @@ /* - * Copyright 2004, Axel Dörfler, axeld@pinc-software.de. All rights reserved. + * Copyright 2004-2008, Axel Dörfler, axeld@pinc-software.de. * Distributed under the terms of the MIT License. */ #ifndef _KERNEL_SYSTEM_INFO_H @@ -16,12 +16,14 @@ extern "C" { #endif extern status_t system_info_init(struct kernel_args *args); -extern uint32 get_haiku_revision(void); +extern uint32 get_haiku_revision(void); extern status_t _user_get_system_info(system_info *userInfo, size_t size); +extern status_t _user_get_system_info_etc(int32 id, void *buffer, + size_t bufferSize); #ifdef __cplusplus } #endif -#endif /* _KRENEL_SYSTEM_INFO_H */ +#endif /* _KERNEL_SYSTEM_INFO_H */ diff --git a/headers/private/kernel/vm.h b/headers/private/kernel/vm.h index 08451dd027..726489b218 100644 --- a/headers/private/kernel/vm.h +++ b/headers/private/kernel/vm.h @@ -1,5 +1,5 @@ /* - * Copyright 2002-2008, Axel Dörfler, axeld@pinc-software.de. All rights reserved. + * Copyright 2002-2008, Axel Dörfler, axeld@pinc-software.de. * Distributed under the terms of the MIT License. * * Copyright 2001-2002, Travis Geiselbrecht. All rights reserved. @@ -16,6 +16,7 @@ struct kernel_args; struct team; +struct system_memory_info; struct vm_page; struct VMCache; struct vm_area; @@ -93,6 +94,8 @@ status_t vm_map_page(struct vm_area *area, struct vm_page *page, addr_t address, status_t vm_get_physical_page(addr_t paddr, addr_t *vaddr, uint32 flags); status_t vm_put_physical_page(addr_t vaddr); +void vm_get_info(struct system_memory_info *info); +uint32 vm_num_page_faults(void); off_t vm_available_memory(void); off_t vm_available_not_needed_memory(void); diff --git a/headers/private/system/syscalls.h b/headers/private/system/syscalls.h index 00d14938f4..923259b8b3 100644 --- a/headers/private/system/syscalls.h +++ b/headers/private/system/syscalls.h @@ -406,6 +406,8 @@ extern int64 _kern_atomic_get64(vint64 *value); /* System informations */ extern status_t _kern_get_system_info(system_info *info, size_t size); +extern status_t _kern_get_system_info_etc(int32 id, void *buffer, + size_t bufferSize); extern status_t _kern_analyze_scheduling(bigtime_t from, bigtime_t until, void* buffer, size_t size, struct scheduling_analysis* analysis); diff --git a/headers/private/system/system_info.h b/headers/private/system/system_info.h new file mode 100644 index 0000000000..574fef5396 --- /dev/null +++ b/headers/private/system/system_info.h @@ -0,0 +1,37 @@ +/* + * Copyright 2008 Haiku, Inc. All rights reserved. + * Distributed under the terms of the MIT License. + */ +#ifndef _SYSTEM_INFO_H +#define _SYSTEM_INFO_H + + +#include + + +#define B_MEMORY_INFO 'memo' + +struct system_memory_info { + uint64 max_memory; + uint64 free_memory; + uint64 needed_memory; + uint64 max_swap_space; + uint64 free_swap_space; + uint64 block_cache_memory; + uint32 page_faults; + + // TODO: add active/inactive page counts, swap in/out, ... +}; + + +#ifdef __cplusplus +extern "C" { +#endif + +extern status_t get_system_info_etc(int32 id, void *buffer, size_t bufferSize); + +#ifdef __cplusplus +} +#endif + +#endif /* _SYSTEM_INFO_H */ diff --git a/src/bin/Jamfile b/src/bin/Jamfile index cb248e3c5c..2fff06894a 100644 --- a/src/bin/Jamfile +++ b/src/bin/Jamfile @@ -2,10 +2,7 @@ SubDir HAIKU_TOP src bin ; SetSubDirSupportedPlatformsBeOSCompatible ; -UsePrivateHeaders app ; -UsePrivateHeaders shared ; -UsePrivateHeaders storage ; -UseLibraryHeaders usb ; +UsePrivateHeaders app shared storage usb ; UsePrivateSystemHeaders ; SubDirHdrs $(HAIKU_TOP) src add-ons kernel file_cache ; @@ -46,6 +43,7 @@ StdBinCommands sysinfo.c unchop.c uptime.cpp + vmstat.cpp waitfor.c # whoami.c : : $(haiku-utils_rsrc) ; diff --git a/src/bin/vmstat.cpp b/src/bin/vmstat.cpp new file mode 100644 index 0000000000..96e2613e49 --- /dev/null +++ b/src/bin/vmstat.cpp @@ -0,0 +1,109 @@ +/* + * Copyright 2008, Axel Dörfler, axeld@pinc-software.de. + * Distributed under the terms of the MIT License. + */ + + +#include +#include +#include +#include + +#include + + +static struct option const kLongOptions[] = { + {"periodic", no_argument, 0, 'p'}, + {"rate", required_argument, 0, 'r'}, + {"help", no_argument, 0, 'h'}, + {NULL} +}; + +extern const char *__progname; +static const char *kProgramName = __progname; + + +void +usage(int status) +{ + fprintf(stderr, "usage: %s [-p] [-r