1 /* 2 * Copyright (c) 2004-2008, Haiku, Inc. 3 * Distributed under the terms of the MIT license. 4 * 5 * Authors: 6 * Stefano Ceccherini 7 * Axel Dörfler, axeld@pinc-software.de 8 */ 9 10 11 #include <system_info.h> 12 #include <arch/system_info.h> 13 14 #include <string.h> 15 16 #include <OS.h> 17 #include <KernelExport.h> 18 19 #include <cpu.h> 20 #include <debug.h> 21 #include <kernel.h> 22 #include <port.h> 23 #include <real_time_clock.h> 24 #include <sem.h> 25 #include <smp.h> 26 #include <team.h> 27 #include <thread.h> 28 #include <vm.h> 29 #include <vm_page.h> 30 31 32 const static int64 kKernelVersion = 0x1; 33 const static char *kKernelName = "kernel_" HAIKU_ARCH; 34 35 36 // Haiku SVN revision. Will be set when copying the kernel to the image. 37 // Lives in a separate section so that it can easily be found. 38 static uint32 sHaikuRevision __attribute__((section("_haiku_revision"))); 39 40 41 static int 42 dump_info(int argc, char **argv) 43 { 44 kprintf("kernel build: %s %s\n\n", __DATE__, __TIME__); 45 kprintf("cpu count: %ld, active times:\n", smp_get_num_cpus()); 46 47 for (int32 i = 0; i < smp_get_num_cpus(); i++) 48 kprintf(" [%ld] %Ld\n", i + 1, cpu_get_active_time(i)); 49 50 // ToDo: Add page_faults 51 kprintf("pages:\t\t%ld (%ld max)\n", vm_page_num_pages() - vm_page_num_free_pages(), 52 vm_page_num_pages()); 53 54 kprintf("sems:\t\t%ld (%ld max)\n", sem_used_sems(), sem_max_sems()); 55 kprintf("ports:\t\t%ld (%ld max)\n", port_used_ports(), port_max_ports()); 56 kprintf("threads:\t%ld (%ld max)\n", thread_used_threads(), thread_max_threads()); 57 kprintf("teams:\t\t%ld (%ld max)\n", team_used_teams(), team_max_teams()); 58 59 return 0; 60 } 61 62 63 // #pragma mark - 64 65 66 status_t 67 _get_system_info(system_info *info, size_t size) 68 { 69 if (size != sizeof(system_info)) 70 return B_BAD_VALUE; 71 72 memset(info, 0, sizeof(system_info)); 73 74 info->boot_time = rtc_boot_time(); 75 info->cpu_count = smp_get_num_cpus(); 76 77 for (int32 i = 0; i < info->cpu_count; i++) 78 info->cpu_infos[i].active_time = cpu_get_active_time(i); 79 80 // ToDo: Add page_faults 81 info->max_pages = vm_page_num_pages(); 82 info->used_pages = info->max_pages - vm_page_num_free_pages(); 83 84 /* TODO: return to using these once sAvailableMemory yields correct values. 85 info->used_pages = vm_page_num_pages() - vm_page_num_available_pages(); 86 info->cached_pages = vm_page_num_pages() - vm_page_num_free_pages() 87 - info->used_pages; 88 */ 89 info->used_threads = thread_used_threads(); 90 info->max_threads = thread_max_threads(); 91 info->used_teams = team_used_teams(); 92 info->max_teams = team_max_teams(); 93 info->used_ports = port_used_ports(); 94 info->max_ports = port_max_ports(); 95 info->used_sems = sem_used_sems(); 96 info->max_sems = sem_max_sems(); 97 98 info->kernel_version = kKernelVersion; 99 strlcpy(info->kernel_name, kKernelName, B_FILE_NAME_LENGTH); 100 strlcpy(info->kernel_build_date, __DATE__, B_OS_NAME_LENGTH); 101 strlcpy(info->kernel_build_time, __TIME__, B_OS_NAME_LENGTH); 102 103 // all other stuff is architecture specific 104 return arch_get_system_info(info, size); 105 } 106 107 108 status_t 109 system_info_init(struct kernel_args *args) 110 { 111 add_debugger_command("info", &dump_info, "System info"); 112 113 return arch_system_info_init(args); 114 } 115 116 117 uint32 118 get_haiku_revision(void) 119 { 120 return sHaikuRevision; 121 } 122 123 124 // #pragma mark - 125 126 127 status_t 128 _user_get_system_info(system_info *userInfo, size_t size) 129 { 130 // The BeBook says get_system_info() always returns B_OK, 131 // but that ain't true with invalid addresses 132 if (userInfo == NULL || !IS_USER_ADDRESS(userInfo)) 133 return B_BAD_ADDRESS; 134 135 system_info info; 136 status_t status = _get_system_info(&info, size); 137 if (status == B_OK) { 138 if (user_memcpy(userInfo, &info, sizeof(system_info)) < B_OK) 139 return B_BAD_ADDRESS; 140 141 return B_OK; 142 } 143 144 return status; 145 } 146