1 | /* |
---|
2 | * sys_display.c - display the current state of a kernel structure on TXT0 |
---|
3 | * |
---|
4 | * Author Alain Greiner (2016,2017,2018) |
---|
5 | * |
---|
6 | * Copyright (c) UPMC Sorbonne Universites |
---|
7 | * |
---|
8 | * This file is part of ALMOS-MKH. |
---|
9 | * |
---|
10 | * ALMOS-MKH is free software; you can redistribute it and/or modify it |
---|
11 | * under the terms of the GNU General Public License as published by |
---|
12 | * the Free Software Foundation; version 2.0 of the License. |
---|
13 | * |
---|
14 | * ALMOS-MKH is distributed in the hope that it will be useful, but |
---|
15 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
---|
17 | * General Public License for more details. |
---|
18 | * |
---|
19 | * You should have received a copy of the GNU General Public License |
---|
20 | * along with ALMOS-MKH; if not, write to the Free Software Foundation, |
---|
21 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
---|
22 | */ |
---|
23 | |
---|
24 | #include <hal_kernel_types.h> |
---|
25 | #include <hal_uspace.h> |
---|
26 | #include <errno.h> |
---|
27 | #include <vmm.h> |
---|
28 | #include <cluster.h> |
---|
29 | #include <thread.h> |
---|
30 | #include <process.h> |
---|
31 | #include <string.h> |
---|
32 | #include <shared_syscalls.h> |
---|
33 | |
---|
34 | #include <syscalls.h> |
---|
35 | |
---|
36 | ///////////////////////////////////////////////////////////////////////////////// |
---|
37 | // This static function returns a printable string for the type of display. |
---|
38 | ///////////////////////////////////////////////////////////////////////////////// |
---|
39 | |
---|
40 | #if DEBUG_SYS_DISPLAY |
---|
41 | static char* display_type_str( uint32_t type ) |
---|
42 | { |
---|
43 | if ( type == DISPLAY_STRING ) return "STRING"; |
---|
44 | else if( type == DISPLAY_VMM ) return "VMM"; |
---|
45 | else if( type == DISPLAY_SCHED ) return "SCHED"; |
---|
46 | else if( type == DISPLAY_CLUSTER_PROCESSES ) return "CLUSTER_PROCESSES"; |
---|
47 | else if( type == DISPLAY_VFS ) return "VFS"; |
---|
48 | else if( type == DISPLAY_CHDEV ) return "CHDEV"; |
---|
49 | else if( type == DISPLAY_TXT_PROCESSES ) return "TXT_PROCESSES"; |
---|
50 | else if( type == DISPLAY_DQDT ) return "DQDT"; |
---|
51 | else if( type == DISPLAY_BUSYLOCKS ) return "BUSYLOCKS"; |
---|
52 | } |
---|
53 | #endif |
---|
54 | |
---|
55 | ///////////////////////////// |
---|
56 | int sys_display( reg_t type, |
---|
57 | reg_t arg0, |
---|
58 | reg_t arg1 ) |
---|
59 | { |
---|
60 | |
---|
61 | error_t error; |
---|
62 | vseg_t * vseg; |
---|
63 | |
---|
64 | thread_t * this = CURRENT_THREAD; |
---|
65 | process_t * process = this->process; |
---|
66 | |
---|
67 | #if (DEBUG_SYS_DISPLAY || CONFIG_INSTRUMENTATION_SYSCALLS) |
---|
68 | uint64_t tm_start = hal_get_cycles(); |
---|
69 | #endif |
---|
70 | |
---|
71 | #if DEBUG_SYS_DISPLAY |
---|
72 | tm_start = hal_get_cycles(); |
---|
73 | if( DEBUG_SYS_DISPLAY < tm_start ) |
---|
74 | printk("\n[DBG] %s : thread[%x,%x] enter / type %s / cycle = %d\n", |
---|
75 | __FUNCTION__, process->pid, this->trdid, display_type_str(type), (uint32_t)tm_start ); |
---|
76 | #endif |
---|
77 | |
---|
78 | //////////////////////////// |
---|
79 | if( type == DISPLAY_STRING ) |
---|
80 | { |
---|
81 | char kbuf[256]; |
---|
82 | uint32_t length; |
---|
83 | |
---|
84 | char * string = (char *)arg0; |
---|
85 | |
---|
86 | // check string in user space |
---|
87 | error = vmm_get_vseg( process , (intptr_t)arg0 , &vseg ); |
---|
88 | |
---|
89 | if( error ) |
---|
90 | { |
---|
91 | |
---|
92 | #if DEBUG_SYSCALLS_ERROR |
---|
93 | printk("\n[ERROR] in %s for STRING : string buffer %x unmapped\n", |
---|
94 | __FUNCTION__ , (intptr_t)arg0 ); |
---|
95 | #endif |
---|
96 | this->errno = EINVAL; |
---|
97 | return -1; |
---|
98 | } |
---|
99 | |
---|
100 | // ckeck string length |
---|
101 | length = hal_strlen_from_uspace( string ); |
---|
102 | |
---|
103 | if( length >= 256 ) |
---|
104 | { |
---|
105 | |
---|
106 | #if DEBUG_SYSCALLS_ERROR |
---|
107 | printk("\n[ERROR] in %s for STRING : string length %d too large\n", |
---|
108 | __FUNCTION__ , length ); |
---|
109 | #endif |
---|
110 | this->errno = EINVAL; |
---|
111 | return -1; |
---|
112 | } |
---|
113 | |
---|
114 | // copy string to kernel space |
---|
115 | hal_strcpy_from_uspace( kbuf , string , 256 ); |
---|
116 | |
---|
117 | // print message on TXT0 kernel terminal |
---|
118 | printk("\n%s / cycle %d\n", kbuf, (uint32_t)hal_get_cycles() ); |
---|
119 | } |
---|
120 | ////////////////////////////// |
---|
121 | else if( type == DISPLAY_VMM ) |
---|
122 | { |
---|
123 | cxy_t cxy = (cxy_t)arg0; |
---|
124 | pid_t pid = (pid_t)arg1; |
---|
125 | |
---|
126 | // check cxy argument |
---|
127 | if( cluster_is_undefined( cxy ) ) |
---|
128 | { |
---|
129 | |
---|
130 | #if DEBUG_SYSCALLS_ERROR |
---|
131 | printk("\n[ERROR] in %s for VMM : process %x in cluster %x not found\n", |
---|
132 | __FUNCTION__ , pid , cxy ); |
---|
133 | #endif |
---|
134 | this->errno = EINVAL; |
---|
135 | return -1; |
---|
136 | } |
---|
137 | |
---|
138 | // get extended pointer on process PID in cluster CXY |
---|
139 | xptr_t process_xp = cluster_get_process_from_pid_in_cxy( cxy , pid ); |
---|
140 | |
---|
141 | if( process_xp == XPTR_NULL ) |
---|
142 | { |
---|
143 | |
---|
144 | #if DEBUG_SYSCALLS_ERROR |
---|
145 | printk("\n[ERROR] in %s for VMM : process %x in cluster %x not found\n", |
---|
146 | __FUNCTION__ , pid , cxy ); |
---|
147 | #endif |
---|
148 | this->errno = EINVAL; |
---|
149 | return -1; |
---|
150 | } |
---|
151 | |
---|
152 | // get local pointer on process |
---|
153 | process_t * process = (process_t *)GET_PTR( process_xp ); |
---|
154 | |
---|
155 | // call kernel function |
---|
156 | if( cxy == local_cxy ) |
---|
157 | { |
---|
158 | vmm_display( process , true ); |
---|
159 | } |
---|
160 | else |
---|
161 | { |
---|
162 | rpc_vmm_display_client( cxy , process , true ); |
---|
163 | } |
---|
164 | } |
---|
165 | //////////////////////////////// |
---|
166 | else if( type == DISPLAY_SCHED ) |
---|
167 | { |
---|
168 | cxy_t cxy = (cxy_t)arg0; |
---|
169 | lid_t lid = (lid_t)arg1; |
---|
170 | |
---|
171 | // check cxy argument |
---|
172 | if( cluster_is_undefined( cxy ) ) |
---|
173 | { |
---|
174 | |
---|
175 | #if DEBUG_SYSCALLS_ERROR |
---|
176 | printk("\n[ERROR] in %s for SCHED : illegal cxy argument %x\n", |
---|
177 | __FUNCTION__ , cxy ); |
---|
178 | #endif |
---|
179 | this->errno = EINVAL; |
---|
180 | return -1; |
---|
181 | } |
---|
182 | |
---|
183 | // check lid argument |
---|
184 | if( lid >= LOCAL_CLUSTER->cores_nr ) |
---|
185 | { |
---|
186 | |
---|
187 | #if DEBUG_SYSCALLS_ERROR |
---|
188 | printk("\n[ERROR] in %s for SCHED : illegal lid argument %x\n", |
---|
189 | __FUNCTION__ , lid ); |
---|
190 | #endif |
---|
191 | this->errno = EINVAL; |
---|
192 | return -1; |
---|
193 | } |
---|
194 | |
---|
195 | if( cxy == local_cxy ) |
---|
196 | { |
---|
197 | sched_display( lid ); |
---|
198 | } |
---|
199 | else |
---|
200 | { |
---|
201 | sched_remote_display( cxy , lid ); |
---|
202 | } |
---|
203 | } |
---|
204 | //////////////////////////////////////////// |
---|
205 | else if( type == DISPLAY_CLUSTER_PROCESSES ) |
---|
206 | { |
---|
207 | cxy_t cxy = (cxy_t)arg0; |
---|
208 | bool_t owned = (bool_t)arg1; |
---|
209 | |
---|
210 | // check cxy argument |
---|
211 | if( cluster_is_undefined( cxy ) ) |
---|
212 | { |
---|
213 | |
---|
214 | #if DEBUG_SYSCALLS_ERROR |
---|
215 | printk("\n[ERROR] in %s for CLUSTER_PROCESSES : illegal cxy argument %x\n", |
---|
216 | __FUNCTION__ , cxy ); |
---|
217 | #endif |
---|
218 | this->errno = EINVAL; |
---|
219 | return -1; |
---|
220 | } |
---|
221 | |
---|
222 | cluster_processes_display( cxy , owned ); |
---|
223 | } |
---|
224 | ////////////////////////////// |
---|
225 | else if( type == DISPLAY_VFS ) |
---|
226 | { |
---|
227 | vfs_display( process->vfs_root_xp ); |
---|
228 | } |
---|
229 | //////////////////////////////// |
---|
230 | else if( type == DISPLAY_CHDEV ) |
---|
231 | { |
---|
232 | chdev_dir_display(); |
---|
233 | } |
---|
234 | //////////////////////////////////////// |
---|
235 | else if( type == DISPLAY_TXT_PROCESSES ) |
---|
236 | { |
---|
237 | uint32_t txt_id = (uint32_t)arg0; |
---|
238 | |
---|
239 | // check argument |
---|
240 | if( txt_id >= LOCAL_CLUSTER->nb_txt_channels ) |
---|
241 | { |
---|
242 | |
---|
243 | #if DEBUG_SYSCALLS_ERROR |
---|
244 | printk("\n[ERROR] in %s for TXT_PROCESSES : illegal txt_id argument %d\n", |
---|
245 | __FUNCTION__ , txt_id ); |
---|
246 | #endif |
---|
247 | this->errno = EINVAL; |
---|
248 | return -1; |
---|
249 | } |
---|
250 | |
---|
251 | process_txt_display( txt_id ); |
---|
252 | } |
---|
253 | /////////////////////////////// |
---|
254 | else if( type == DISPLAY_DQDT ) |
---|
255 | { |
---|
256 | dqdt_display(); |
---|
257 | } |
---|
258 | //////////////////////////////////// |
---|
259 | else if( type == DISPLAY_BUSYLOCKS ) |
---|
260 | { |
---|
261 | pid_t pid = (pid_t)arg0; |
---|
262 | trdid_t trdid = (trdid_t)arg1; |
---|
263 | |
---|
264 | // get extended pointer on target thread |
---|
265 | xptr_t thread_xp = thread_get_xptr( pid , trdid ); |
---|
266 | |
---|
267 | if( thread_xp == XPTR_NULL ) |
---|
268 | { |
---|
269 | |
---|
270 | #if DEBUG_SYSCALLS_ERROR |
---|
271 | printk("\n[ERROR] in %s for BUSYLOCKS : thread[%x,%x] not found\n", |
---|
272 | __FUNCTION__ , pid, trdid ); |
---|
273 | #endif |
---|
274 | this->errno = EINVAL; |
---|
275 | return -1; |
---|
276 | } |
---|
277 | |
---|
278 | thread_display_busylocks( thread_xp ); |
---|
279 | } |
---|
280 | //// |
---|
281 | else |
---|
282 | { |
---|
283 | |
---|
284 | #if DEBUG_SYSCALLS_ERROR |
---|
285 | printk("\n[ERROR] in %s : undefined display type %d\n", |
---|
286 | __FUNCTION__ , type ); |
---|
287 | #endif |
---|
288 | this->errno = EINVAL; |
---|
289 | return -1; |
---|
290 | } |
---|
291 | |
---|
292 | #if (DEBUG_SYS_DISPLAY || CONFIG_INSTRUMENTATION_SYSCALLS) |
---|
293 | uint64_t tm_end = hal_get_cycles(); |
---|
294 | #endif |
---|
295 | |
---|
296 | #if DEBUG_SYS_DISPLAY |
---|
297 | if( DEBUG_SYS_DISPLAY < tm_end ) |
---|
298 | printk("\n[DBG] %s : thread[%x,%x] exit / cycle %d\n", |
---|
299 | __FUNCTION__, process->pid, this->trdid, (uint32_t)tm_end ); |
---|
300 | #endif |
---|
301 | |
---|
302 | #if CONFIG_INSTRUMENTATION_SYSCALLS |
---|
303 | hal_atomic_add( &syscalls_cumul_cost[SYS_DISPLAY] , tm_end - tm_start ); |
---|
304 | hal_atomic_add( &syscalls_occurences[SYS_DISPLAY] , 1 ); |
---|
305 | #endif |
---|
306 | |
---|
307 | return 0; |
---|
308 | |
---|
309 | } // end sys_display() |
---|