2 * Copyright 2013, Paweł Dziepak, pdziepak@quarnos.org.
3 * Copyright 2002-2008, Axel Dörfler, axeld@pinc-software.de.
4 * Distributed under the terms of the MIT License.
15 #include <system_info.h>
18 #if _BEOS_R5_COMPATIBLE_
21 #define LEGACY_B_CPU_X86 15
23 #define LEGACY_B_AT_CLONE_PLATFORM 2
26 bigtime_t active_time
; /* usec of doing useful work since boot */
30 int32 id
[2]; /* unique machine ID */
31 bigtime_t boot_time
; /* time of boot (usecs since 1/1/1970) */
33 int32 cpu_count
; /* number of cpus */
34 int32 cpu_type
; /* type of cpu */
35 int32 cpu_revision
; /* revision # of cpu */
36 legacy_cpu_info cpu_infos
[8]; /* info about individual cpus */
37 int64 cpu_clock_speed
; /* processor clock speed (Hz) */
38 int64 bus_clock_speed
; /* bus clock speed (Hz) */
39 int32 platform_type
; /* type of machine we're on */
41 int32 max_pages
; /* total # of accessible pages */
42 int32 used_pages
; /* # of accessible pages in use */
43 int32 page_faults
; /* # of page faults */
53 char kernel_name
[256];
54 char kernel_build_date
[32];
55 char kernel_build_time
[32];
58 bigtime_t _busy_wait_time
; /* reserved for whatever */
61 uint32 abi
; /* the system API */
62 int32 ignored_pages
; /* # of ignored/inaccessible pages */
68 _get_system_info(legacy_system_info
* info
, size_t size
)
70 if (info
== NULL
|| size
!= sizeof(legacy_system_info
))
72 memset(info
, 0, sizeof(legacy_system_info
));
74 system_info systemInfo
;
75 status_t error
= _kern_get_system_info(&systemInfo
);
80 error
= _kern_get_cpu_info(0, std::min(systemInfo
.cpu_count
, uint32(8)),
85 info
->boot_time
= systemInfo
.boot_time
;
86 info
->cpu_count
= std::min(systemInfo
.cpu_count
, uint32(8));
87 for (int32 i
= 0; i
< info
->cpu_count
; i
++)
88 info
->cpu_infos
[i
].active_time
= cpuInfos
[i
].active_time
;
90 info
->platform_type
= LEGACY_B_AT_CLONE_PLATFORM
;
91 info
->cpu_type
= LEGACY_B_CPU_X86
;
93 uint32 topologyNodeCount
= 0;
94 cpu_topology_node_info
* topology
= NULL
;
95 error
= get_cpu_topology_info(NULL
, &topologyNodeCount
);
98 if (topologyNodeCount
!= 0) {
99 topology
= new(std::nothrow
) cpu_topology_node_info
[topologyNodeCount
];
100 if (topology
== NULL
)
103 error
= get_cpu_topology_info(topology
, &topologyNodeCount
);
109 for (uint32 i
= 0; i
< topologyNodeCount
; i
++) {
110 if (topology
[i
].type
== B_TOPOLOGY_CORE
) {
111 info
->cpu_clock_speed
= topology
[i
].data
.core
.default_frequency
;
115 info
->bus_clock_speed
= info
->cpu_clock_speed
;
118 info
->max_pages
= std::min(systemInfo
.max_pages
, uint64(INT32_MAX
));
119 info
->used_pages
= std::min(systemInfo
.used_pages
, uint64(INT32_MAX
));
120 info
->cached_pages
= std::min(systemInfo
.cached_pages
, uint64(INT32_MAX
));
121 info
->ignored_pages
= std::min(systemInfo
.ignored_pages
, uint64(INT32_MAX
));
122 info
->page_faults
= std::min(systemInfo
.page_faults
, uint32(INT32_MAX
));
123 info
->max_sems
= std::min(systemInfo
.max_sems
, uint32(INT32_MAX
));
124 info
->used_sems
= std::min(systemInfo
.used_sems
, uint32(INT32_MAX
));
125 info
->max_ports
= std::min(systemInfo
.max_ports
, uint32(INT32_MAX
));
126 info
->used_ports
= std::min(systemInfo
.used_ports
, uint32(INT32_MAX
));
127 info
->max_threads
= std::min(systemInfo
.max_threads
, uint32(INT32_MAX
));
128 info
->used_threads
= std::min(systemInfo
.used_threads
, uint32(INT32_MAX
));
129 info
->max_teams
= std::min(systemInfo
.max_teams
, uint32(INT32_MAX
));
130 info
->used_teams
= std::min(systemInfo
.used_teams
, uint32(INT32_MAX
));
132 strlcpy(info
->kernel_name
, systemInfo
.kernel_name
,
133 sizeof(info
->kernel_name
));
134 strlcpy(info
->kernel_build_date
, systemInfo
.kernel_build_date
,
135 sizeof(info
->kernel_build_date
));
136 strlcpy(info
->kernel_build_time
, systemInfo
.kernel_build_time
,
137 sizeof(info
->kernel_build_time
));
138 info
->kernel_version
= systemInfo
.kernel_version
;
140 info
->abi
= systemInfo
.abi
;
146 #endif // _BEOS_R5_COMPATIBLE_
150 __get_system_info(system_info
* info
)
152 return _kern_get_system_info(info
);
157 __get_cpu_info(uint32 firstCPU
, uint32 cpuCount
, cpu_info
* info
)
159 return _kern_get_cpu_info(firstCPU
, cpuCount
, info
);
164 __get_cpu_topology_info(cpu_topology_node_info
* topologyInfos
,
165 uint32
* topologyInfoCount
)
167 return _kern_get_cpu_topology_info(topologyInfos
, topologyInfoCount
);
172 __start_watching_system(int32 object
, uint32 flags
, port_id port
, int32 token
)
174 return _kern_start_watching_system(object
, flags
, port
, token
);
179 __stop_watching_system(int32 object
, uint32 flags
, port_id port
, int32 token
)
181 return _kern_stop_watching_system(object
, flags
, port
, token
);
188 return _kern_is_computer_on();
193 is_computer_on_fire(void)
199 B_DEFINE_WEAK_ALIAS(__get_system_info
, get_system_info
);
200 B_DEFINE_WEAK_ALIAS(__get_cpu_info
, get_cpu_info
);
201 B_DEFINE_WEAK_ALIAS(__get_cpu_topology_info
, get_cpu_topology_info
);