15 |
along with this program; if not, write to the Free Software |
along with this program; if not, write to the Free Software |
16 |
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ |
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ |
17 |
|
|
18 |
|
#include <rtmk/host-info.h> |
19 |
|
#include <rtmk/vm-param.h> |
20 |
|
|
21 |
#include "tm.h" |
#include "tm.h" |
22 |
#include "host.h" |
#include "host.h" |
23 |
#include "trace.h" |
#include "trace.h" |
24 |
#include "vm-object.h" |
#include "vm-object.h" |
25 |
#include "vm-pager.h" |
#include "vm-pager.h" |
26 |
#include "eventcnt.h" |
#include "eventcnt.h" |
27 |
|
#include "ipc-object.h" |
28 |
|
#include "thread.h" |
29 |
|
|
30 |
|
/* Information structures. Used by system to keep track of |
31 |
|
statistics that can be reported to the user/application. */ |
32 |
|
struct host_info_basic host_info_basic; |
33 |
|
struct host_info_processor host_info_processor [NCPUS]; |
34 |
|
|
35 |
/* Array of event counters attached to interrupts. */ |
/* Array of event counters attached to interrupts. */ |
36 |
struct eventcnt * host_intr_evcs [N_MACHINE_INTRS]; |
struct eventcnt * host_intr_evcs [N_MACHINE_INTRS]; |
44 |
{ |
{ |
45 |
master_host_port = ipc_port_create_kernel (); |
master_host_port = ipc_port_create_kernel (); |
46 |
assert (master_host_port); |
assert (master_host_port); |
47 |
} |
ipc_port_set_kobject (master_host_port, IPC_KOBJECT_TYPE_HOST, 0); |
48 |
|
|
49 |
|
/* Initialize some of the fields in host_info_basic. */ |
50 |
|
host_info_basic.max_processors = NCPUS; |
51 |
|
host_info_basic.page_size = VM_PAGE_SIZE; |
52 |
|
#if NCPUS == 1 |
53 |
|
host_info_basic.available_processors = 1; |
54 |
|
#endif |
55 |
|
} |
56 |
|
|
57 |
/* Reboot host. HOST_PORT must be master host port. */ |
/* Reboot host. HOST_PORT must be master host port. */ |
58 |
kern_return_t |
kern_return_t |
65 |
return 0; |
return 0; |
66 |
} |
} |
67 |
|
|
68 |
|
/* Allocate a new host port. Host port can be used to fetch |
69 |
|
information and statistics about the system. */ |
70 |
|
rtmk_port_t |
71 |
|
syscall_host_self (void) |
72 |
|
{ |
73 |
|
struct ipc_port *host_port; |
74 |
|
rtmk_port_t host_name; |
75 |
|
kern_return_t kr; |
76 |
|
|
77 |
|
host_port = ipc_port_create_kernel (); |
78 |
|
ipc_port_set_kobject (host_port, IPC_KOBJECT_TYPE_HOST, 0); |
79 |
|
|
80 |
|
/* Insert right into tasks IPC object. */ |
81 |
|
ipc_object_lock (THREAD_CURRENT()->task->ipc_object); |
82 |
|
kr = ipc_object_copyout (THREAD_CURRENT()->task->ipc_object, host_port, |
83 |
|
RTMK_MSG_TYPE_MAKE_SEND, & host_name); |
84 |
|
ipc_object_unlock (THREAD_CURRENT()->task->ipc_object); |
85 |
|
assert (kr == KERN_SUCCESS); |
86 |
|
|
87 |
|
return host_name; |
88 |
|
} |
89 |
|
|
90 |
/* Create a new host memory object. OFFSET is offset into physical |
/* Create a new host memory object. OFFSET is offset into physical |
91 |
memory. SIZE should be page aligned. Right to object is returned |
memory. SIZE should be page aligned. Right to object is returned |
139 |
PERMIT_INTERRUPT (intr_no); |
PERMIT_INTERRUPT (intr_no); |
140 |
return KERN_SUCCESS; |
return KERN_SUCCESS; |
141 |
} |
} |
142 |
|
|
143 |
|
|
144 |
|
/* Get information about HOST. HOST must not be the |
145 |
|
systems priviledged host port. Info is but in BUF. */ |
146 |
|
kern_return_t |
147 |
|
host_info (struct ipc_port *host, int flavor, char *buf, |
148 |
|
int *data_len) |
149 |
|
{ |
150 |
|
int i, size; |
151 |
|
|
152 |
|
if (! host || host->kobject.type != IPC_KOBJECT_TYPE_HOST) |
153 |
|
return KERN_INVALID_HOST; |
154 |
|
|
155 |
|
switch (flavor) |
156 |
|
{ |
157 |
|
case HOST_INFO_FLAVOR_BASIC: |
158 |
|
if (*data_len != HOST_INFO_BASIC_COUNT) |
159 |
|
return KERN_FAILURE; /* ??? better return code please */ |
160 |
|
|
161 |
|
memcpy (buf, &host_info_basic, HOST_INFO_BASIC_COUNT); |
162 |
|
return 0; |
163 |
|
|
164 |
|
case HOST_INFO_FLAVOR_PROCESSOR: |
165 |
|
if (*data_len < HOST_INFO_PROCESSOR_COUNT) |
166 |
|
return KERN_FAILURE; /* ??? same here. */ |
167 |
|
size = *data_len; |
168 |
|
if (size > HOST_INFO_PROCESSOR_COUNT * NCPUS) |
169 |
|
size = HOST_INFO_PROCESSOR_COUNT * NCPUS; |
170 |
|
|
171 |
|
for (i = 0, *data_len = 0; size >= HOST_INFO_PROCESSOR_COUNT; i++) |
172 |
|
{ |
173 |
|
memcpy (buf, &host_info_processor [i], |
174 |
|
HOST_INFO_PROCESSOR_COUNT); |
175 |
|
size = size - HOST_INFO_PROCESSOR_COUNT; |
176 |
|
*data_len = *data_len + HOST_INFO_PROCESSOR_COUNT; |
177 |
|
} |
178 |
|
return 0; |
179 |
|
} |
180 |
|
return KERN_INVALID_ARGUMENT; |
181 |
|
} |