[421] | 1 | /* |
---|
| 2 | * sys_display.c - display the current state of a kernel structure on TXT0 |
---|
| 3 | * |
---|
[624] | 4 | * Author Alain Greiner (2016,2017,2018, 2019) |
---|
[421] | 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 | |
---|
[457] | 24 | #include <hal_kernel_types.h> |
---|
[421] | 25 | #include <hal_uspace.h> |
---|
[624] | 26 | #include <hal_vmm.h> |
---|
[421] | 27 | #include <errno.h> |
---|
[433] | 28 | #include <vmm.h> |
---|
[421] | 29 | #include <cluster.h> |
---|
| 30 | #include <thread.h> |
---|
| 31 | #include <process.h> |
---|
[433] | 32 | #include <string.h> |
---|
[443] | 33 | #include <shared_syscalls.h> |
---|
[623] | 34 | #include <remote_barrier.h> |
---|
[611] | 35 | #include <vfs.h> |
---|
| 36 | #include <mapper.h> |
---|
[421] | 37 | |
---|
[506] | 38 | #include <syscalls.h> |
---|
| 39 | |
---|
[443] | 40 | ///////////////////////////////////////////////////////////////////////////////// |
---|
| 41 | // This static function returns a printable string for the type of display. |
---|
| 42 | ///////////////////////////////////////////////////////////////////////////////// |
---|
[421] | 43 | |
---|
[443] | 44 | #if DEBUG_SYS_DISPLAY |
---|
| 45 | static char* display_type_str( uint32_t type ) |
---|
| 46 | { |
---|
| 47 | if ( type == DISPLAY_STRING ) return "STRING"; |
---|
| 48 | else if( type == DISPLAY_VMM ) return "VMM"; |
---|
| 49 | else if( type == DISPLAY_SCHED ) return "SCHED"; |
---|
| 50 | else if( type == DISPLAY_CLUSTER_PROCESSES ) return "CLUSTER_PROCESSES"; |
---|
| 51 | else if( type == DISPLAY_VFS ) return "VFS"; |
---|
| 52 | else if( type == DISPLAY_CHDEV ) return "CHDEV"; |
---|
| 53 | else if( type == DISPLAY_TXT_PROCESSES ) return "TXT_PROCESSES"; |
---|
[580] | 54 | else if( type == DISPLAY_DQDT ) return "DQDT"; |
---|
| 55 | else if( type == DISPLAY_BUSYLOCKS ) return "BUSYLOCKS"; |
---|
[612] | 56 | else if( type == DISPLAY_MAPPER ) return "MAPPER"; |
---|
[623] | 57 | else if( type == DISPLAY_BARRIER ) return "BARRIER"; |
---|
[612] | 58 | else return "undefined"; |
---|
[443] | 59 | } |
---|
| 60 | #endif |
---|
| 61 | |
---|
[421] | 62 | ///////////////////////////// |
---|
| 63 | int sys_display( reg_t type, |
---|
| 64 | reg_t arg0, |
---|
[611] | 65 | reg_t arg1, |
---|
| 66 | reg_t arg2 ) |
---|
[421] | 67 | { |
---|
[433] | 68 | |
---|
[440] | 69 | error_t error; |
---|
| 70 | vseg_t * vseg; |
---|
| 71 | |
---|
| 72 | thread_t * this = CURRENT_THREAD; |
---|
| 73 | process_t * process = this->process; |
---|
| 74 | |
---|
[594] | 75 | #if (DEBUG_SYS_DISPLAY || CONFIG_INSTRUMENTATION_SYSCALLS) |
---|
| 76 | uint64_t tm_start = hal_get_cycles(); |
---|
| 77 | #endif |
---|
| 78 | |
---|
[438] | 79 | #if DEBUG_SYS_DISPLAY |
---|
[433] | 80 | tm_start = hal_get_cycles(); |
---|
[438] | 81 | if( DEBUG_SYS_DISPLAY < tm_start ) |
---|
[619] | 82 | printk("\n[%s] thread[%x,%x] enter / type %s / cycle = %d\n", |
---|
[594] | 83 | __FUNCTION__, process->pid, this->trdid, display_type_str(type), (uint32_t)tm_start ); |
---|
[433] | 84 | #endif |
---|
| 85 | |
---|
[623] | 86 | switch( type ) |
---|
[421] | 87 | { |
---|
[623] | 88 | //////////////////// |
---|
| 89 | case DISPLAY_STRING: |
---|
| 90 | { |
---|
| 91 | char kbuf[512]; |
---|
| 92 | uint32_t length; |
---|
[421] | 93 | |
---|
[623] | 94 | char * string = (char *)arg0; |
---|
[440] | 95 | |
---|
[623] | 96 | // check string in user space |
---|
| 97 | error = vmm_get_vseg( process , (intptr_t)arg0 , &vseg ); |
---|
| 98 | if( error ) |
---|
| 99 | { |
---|
[440] | 100 | |
---|
| 101 | #if DEBUG_SYSCALLS_ERROR |
---|
[580] | 102 | printk("\n[ERROR] in %s for STRING : string buffer %x unmapped\n", |
---|
| 103 | __FUNCTION__ , (intptr_t)arg0 ); |
---|
[440] | 104 | #endif |
---|
[623] | 105 | this->errno = EINVAL; |
---|
| 106 | return -1; |
---|
| 107 | } |
---|
[421] | 108 | |
---|
[623] | 109 | // ckeck string length |
---|
| 110 | length = hal_strlen_from_uspace( string ); |
---|
| 111 | if( length >= 512 ) |
---|
| 112 | { |
---|
[440] | 113 | |
---|
| 114 | #if DEBUG_SYSCALLS_ERROR |
---|
[580] | 115 | printk("\n[ERROR] in %s for STRING : string length %d too large\n", |
---|
| 116 | __FUNCTION__ , length ); |
---|
[440] | 117 | #endif |
---|
[623] | 118 | this->errno = EINVAL; |
---|
| 119 | return -1; |
---|
| 120 | } |
---|
[421] | 121 | |
---|
[623] | 122 | // copy string to kernel space |
---|
| 123 | hal_strcpy_from_uspace( kbuf , string , 512 ); |
---|
[421] | 124 | |
---|
[623] | 125 | // print message on TXT0 kernel terminal |
---|
| 126 | printk("\n%s / cycle %d\n", kbuf, (uint32_t)hal_get_cycles() ); |
---|
[421] | 127 | |
---|
[623] | 128 | break; |
---|
| 129 | } |
---|
| 130 | ///////////////// |
---|
| 131 | case DISPLAY_VMM: |
---|
[443] | 132 | { |
---|
[623] | 133 | cxy_t cxy = (cxy_t)arg0; |
---|
| 134 | pid_t pid = (pid_t)arg1; |
---|
[421] | 135 | |
---|
[623] | 136 | // check cxy argument |
---|
| 137 | if( cluster_is_undefined( cxy ) ) |
---|
| 138 | { |
---|
| 139 | |
---|
[443] | 140 | #if DEBUG_SYSCALLS_ERROR |
---|
[580] | 141 | printk("\n[ERROR] in %s for VMM : process %x in cluster %x not found\n", |
---|
| 142 | __FUNCTION__ , pid , cxy ); |
---|
[443] | 143 | #endif |
---|
[623] | 144 | this->errno = EINVAL; |
---|
| 145 | return -1; |
---|
| 146 | } |
---|
[443] | 147 | |
---|
[623] | 148 | // get extended pointer on process PID in cluster CXY |
---|
| 149 | xptr_t process_xp = cluster_get_process_from_pid_in_cxy( cxy , pid ); |
---|
| 150 | if( process_xp == XPTR_NULL ) |
---|
| 151 | { |
---|
[440] | 152 | |
---|
| 153 | #if DEBUG_SYSCALLS_ERROR |
---|
[580] | 154 | printk("\n[ERROR] in %s for VMM : process %x in cluster %x not found\n", |
---|
| 155 | __FUNCTION__ , pid , cxy ); |
---|
[440] | 156 | #endif |
---|
[623] | 157 | this->errno = EINVAL; |
---|
| 158 | return -1; |
---|
| 159 | } |
---|
[421] | 160 | |
---|
[623] | 161 | // get local pointer on process |
---|
| 162 | process_t * process = (process_t *)GET_PTR( process_xp ); |
---|
[421] | 163 | |
---|
[623] | 164 | // call kernel function |
---|
| 165 | if( cxy == local_cxy ) |
---|
| 166 | { |
---|
[624] | 167 | hal_vmm_display( process , true ); |
---|
[623] | 168 | } |
---|
| 169 | else |
---|
| 170 | { |
---|
[624] | 171 | rpc_hal_vmm_display_client( cxy , process , true ); |
---|
[623] | 172 | } |
---|
| 173 | |
---|
| 174 | break; |
---|
[421] | 175 | } |
---|
[623] | 176 | /////////////////// |
---|
| 177 | case DISPLAY_SCHED: |
---|
[421] | 178 | { |
---|
[623] | 179 | cxy_t cxy = (cxy_t)arg0; |
---|
| 180 | lid_t lid = (lid_t)arg1; |
---|
[421] | 181 | |
---|
[623] | 182 | // check cxy argument |
---|
| 183 | if( cluster_is_undefined( cxy ) ) |
---|
| 184 | { |
---|
[440] | 185 | |
---|
| 186 | #if DEBUG_SYSCALLS_ERROR |
---|
[580] | 187 | printk("\n[ERROR] in %s for SCHED : illegal cxy argument %x\n", |
---|
| 188 | __FUNCTION__ , cxy ); |
---|
[440] | 189 | #endif |
---|
[623] | 190 | this->errno = EINVAL; |
---|
| 191 | return -1; |
---|
| 192 | } |
---|
[421] | 193 | |
---|
[623] | 194 | // check lid argument |
---|
| 195 | if( lid >= LOCAL_CLUSTER->cores_nr ) |
---|
| 196 | { |
---|
[440] | 197 | |
---|
| 198 | #if DEBUG_SYSCALLS_ERROR |
---|
[580] | 199 | printk("\n[ERROR] in %s for SCHED : illegal lid argument %x\n", |
---|
| 200 | __FUNCTION__ , lid ); |
---|
[440] | 201 | #endif |
---|
[623] | 202 | this->errno = EINVAL; |
---|
| 203 | return -1; |
---|
| 204 | } |
---|
[421] | 205 | |
---|
[623] | 206 | if( cxy == local_cxy ) |
---|
| 207 | { |
---|
| 208 | sched_display( lid ); |
---|
| 209 | } |
---|
| 210 | else |
---|
| 211 | { |
---|
| 212 | sched_remote_display( cxy , lid ); |
---|
| 213 | } |
---|
| 214 | |
---|
| 215 | break; |
---|
[421] | 216 | } |
---|
[623] | 217 | /////////////////////////////// |
---|
| 218 | case DISPLAY_CLUSTER_PROCESSES: |
---|
[421] | 219 | { |
---|
[623] | 220 | cxy_t cxy = (cxy_t)arg0; |
---|
| 221 | bool_t owned = (bool_t)arg1; |
---|
[421] | 222 | |
---|
[623] | 223 | // check cxy argument |
---|
| 224 | if( cluster_is_undefined( cxy ) ) |
---|
| 225 | { |
---|
[440] | 226 | |
---|
| 227 | #if DEBUG_SYSCALLS_ERROR |
---|
[580] | 228 | printk("\n[ERROR] in %s for CLUSTER_PROCESSES : illegal cxy argument %x\n", |
---|
| 229 | __FUNCTION__ , cxy ); |
---|
[440] | 230 | #endif |
---|
[623] | 231 | this->errno = EINVAL; |
---|
| 232 | return -1; |
---|
| 233 | } |
---|
| 234 | |
---|
| 235 | cluster_processes_display( cxy , owned ); |
---|
| 236 | |
---|
| 237 | break; |
---|
[433] | 238 | } |
---|
[623] | 239 | ///////////////// |
---|
| 240 | case DISPLAY_VFS: |
---|
| 241 | { |
---|
| 242 | vfs_display( process->vfs_root_xp ); |
---|
[421] | 243 | |
---|
[623] | 244 | break; |
---|
| 245 | } |
---|
| 246 | /////////////////// |
---|
| 247 | case DISPLAY_CHDEV: |
---|
| 248 | { |
---|
| 249 | chdev_dir_display(); |
---|
[435] | 250 | |
---|
[623] | 251 | break; |
---|
| 252 | } |
---|
| 253 | /////////////////////////// |
---|
| 254 | case DISPLAY_TXT_PROCESSES: |
---|
[435] | 255 | { |
---|
[623] | 256 | uint32_t txt_id = (uint32_t)arg0; |
---|
[440] | 257 | |
---|
[623] | 258 | // check argument |
---|
| 259 | if( txt_id >= LOCAL_CLUSTER->nb_txt_channels ) |
---|
| 260 | { |
---|
| 261 | |
---|
[440] | 262 | #if DEBUG_SYSCALLS_ERROR |
---|
[580] | 263 | printk("\n[ERROR] in %s for TXT_PROCESSES : illegal txt_id argument %d\n", |
---|
| 264 | __FUNCTION__ , txt_id ); |
---|
[440] | 265 | #endif |
---|
[623] | 266 | this->errno = EINVAL; |
---|
| 267 | return -1; |
---|
| 268 | } |
---|
[435] | 269 | |
---|
[623] | 270 | process_txt_display( txt_id ); |
---|
[580] | 271 | |
---|
[623] | 272 | break; |
---|
| 273 | } |
---|
| 274 | ////////////////// |
---|
| 275 | case DISPLAY_DQDT: |
---|
| 276 | { |
---|
| 277 | dqdt_display(); |
---|
[580] | 278 | |
---|
[623] | 279 | break; |
---|
| 280 | } |
---|
| 281 | /////////////////////// |
---|
| 282 | case DISPLAY_BUSYLOCKS: |
---|
[580] | 283 | { |
---|
[623] | 284 | pid_t pid = (pid_t)arg0; |
---|
| 285 | trdid_t trdid = (trdid_t)arg1; |
---|
[580] | 286 | |
---|
[623] | 287 | // get extended pointer on target thread |
---|
| 288 | xptr_t thread_xp = thread_get_xptr( pid , trdid ); |
---|
| 289 | |
---|
| 290 | if( thread_xp == XPTR_NULL ) |
---|
| 291 | { |
---|
| 292 | |
---|
[580] | 293 | #if DEBUG_SYSCALLS_ERROR |
---|
[594] | 294 | printk("\n[ERROR] in %s for BUSYLOCKS : thread[%x,%x] not found\n", |
---|
| 295 | __FUNCTION__ , pid, trdid ); |
---|
[580] | 296 | #endif |
---|
[623] | 297 | this->errno = EINVAL; |
---|
| 298 | return -1; |
---|
| 299 | } |
---|
| 300 | |
---|
| 301 | thread_display_busylocks( thread_xp , __FUNCTION__ ); |
---|
| 302 | |
---|
| 303 | break; |
---|
[580] | 304 | } |
---|
[623] | 305 | //////////////////// |
---|
| 306 | case DISPLAY_MAPPER: |
---|
| 307 | { |
---|
| 308 | xptr_t root_inode_xp; |
---|
| 309 | xptr_t inode_xp; |
---|
| 310 | cxy_t inode_cxy; |
---|
| 311 | vfs_inode_t * inode_ptr; |
---|
| 312 | xptr_t mapper_xp; |
---|
| 313 | mapper_t * mapper_ptr; |
---|
[580] | 314 | |
---|
[623] | 315 | char kbuf[CONFIG_VFS_MAX_PATH_LENGTH]; |
---|
[611] | 316 | |
---|
[623] | 317 | char * path = (char *)arg0; |
---|
| 318 | uint32_t page_id = (uint32_t)arg1; |
---|
| 319 | uint32_t nbytes = (uint32_t)arg2; |
---|
[611] | 320 | |
---|
[623] | 321 | // check pathname length |
---|
| 322 | if( hal_strlen_from_uspace( path ) >= CONFIG_VFS_MAX_PATH_LENGTH ) |
---|
| 323 | { |
---|
[611] | 324 | |
---|
| 325 | #if DEBUG_SYSCALLS_ERROR |
---|
| 326 | printk("\n[ERROR] in %s for MAPPER : pathname too long\n", |
---|
| 327 | __FUNCTION__ ); |
---|
| 328 | #endif |
---|
[623] | 329 | this->errno = ENFILE; |
---|
| 330 | return -1; |
---|
| 331 | } |
---|
[611] | 332 | |
---|
[623] | 333 | // copy pathname in kernel space |
---|
| 334 | hal_strcpy_from_uspace( kbuf , path , CONFIG_VFS_MAX_PATH_LENGTH ); |
---|
[611] | 335 | |
---|
[623] | 336 | // compute root inode for pathname |
---|
| 337 | if( kbuf[0] == '/' ) // absolute path |
---|
| 338 | { |
---|
| 339 | // use extended pointer on VFS root inode |
---|
| 340 | root_inode_xp = process->vfs_root_xp; |
---|
| 341 | } |
---|
| 342 | else // relative path |
---|
| 343 | { |
---|
| 344 | // get cluster and local pointer on reference process |
---|
| 345 | xptr_t ref_xp = process->ref_xp; |
---|
| 346 | process_t * ref_ptr = (process_t *)GET_PTR( ref_xp ); |
---|
| 347 | cxy_t ref_cxy = GET_CXY( ref_xp ); |
---|
[611] | 348 | |
---|
[623] | 349 | // get extended pointer on CWD inode |
---|
| 350 | root_inode_xp = hal_remote_l64( XPTR( ref_cxy , &ref_ptr->cwd_xp ) ); |
---|
| 351 | } |
---|
[611] | 352 | |
---|
[623] | 353 | // get extended pointer on target inode |
---|
| 354 | error = vfs_lookup( root_inode_xp, |
---|
| 355 | kbuf, |
---|
| 356 | 0, |
---|
| 357 | &inode_xp, |
---|
| 358 | NULL ); |
---|
| 359 | if( error ) |
---|
| 360 | { |
---|
[611] | 361 | |
---|
| 362 | #if DEBUG_SYSCALLS_ERROR |
---|
| 363 | printk("\n[ERROR] in %s for MAPPER : cannot found inode <%s>\n", |
---|
| 364 | __FUNCTION__ , kbuf ); |
---|
| 365 | #endif |
---|
[623] | 366 | this->errno = ENFILE; |
---|
| 367 | return -1; |
---|
| 368 | } |
---|
[611] | 369 | |
---|
[623] | 370 | // get target inode cluster and local pointer |
---|
| 371 | inode_cxy = GET_CXY( inode_xp ); |
---|
| 372 | inode_ptr = GET_PTR( inode_xp ); |
---|
[611] | 373 | |
---|
[623] | 374 | // get extended pointer on target mapper |
---|
| 375 | mapper_ptr = hal_remote_lpt( XPTR( inode_cxy , &inode_ptr->mapper ) ); |
---|
| 376 | mapper_xp = XPTR( inode_cxy , mapper_ptr ); |
---|
[611] | 377 | |
---|
[623] | 378 | // display mapper |
---|
| 379 | error = mapper_display_page( mapper_xp , page_id , nbytes ); |
---|
[611] | 380 | |
---|
[623] | 381 | if( error ) |
---|
| 382 | { |
---|
[611] | 383 | |
---|
| 384 | #if DEBUG_SYSCALLS_ERROR |
---|
| 385 | printk("\n[ERROR] in %s for MAPPER : cannot display page %d\n", |
---|
| 386 | __FUNCTION__ , page_id ); |
---|
| 387 | #endif |
---|
[623] | 388 | this->errno = ENFILE; |
---|
| 389 | return -1; |
---|
| 390 | } |
---|
[440] | 391 | |
---|
[623] | 392 | break; |
---|
| 393 | } |
---|
| 394 | ///////////////////// |
---|
| 395 | case DISPLAY_BARRIER: |
---|
| 396 | { |
---|
| 397 | // get target process PID |
---|
| 398 | pid_t pid = (pid_t)arg0; |
---|
| 399 | |
---|
| 400 | // get pointers on owner process |
---|
| 401 | xptr_t process_xp = cluster_get_reference_process_from_pid( pid ); |
---|
| 402 | process_t * process_ptr = GET_PTR( process_xp ); |
---|
| 403 | cxy_t process_cxy = GET_CXY( process_xp ); |
---|
| 404 | |
---|
| 405 | if( process_xp == XPTR_NULL ) |
---|
| 406 | { |
---|
| 407 | |
---|
[440] | 408 | #if DEBUG_SYSCALLS_ERROR |
---|
[623] | 409 | printk("\n[ERROR] in %s for BARRIER : process %x not found\n", |
---|
| 410 | __FUNCTION__ , pid ); |
---|
| 411 | #endif |
---|
| 412 | this->errno = EINVAL; |
---|
| 413 | return -1; |
---|
| 414 | } |
---|
| 415 | |
---|
| 416 | // get extended pointer on root of list of barriers |
---|
| 417 | xptr_t root_xp = XPTR( process_cxy , &process_ptr->barrier_root ); |
---|
| 418 | |
---|
| 419 | if( xlist_is_empty( root_xp ) ) |
---|
| 420 | { |
---|
| 421 | |
---|
| 422 | #if DEBUG_SYSCALLS_ERROR |
---|
| 423 | printk("\n[ERROR] in %s for BARRIER : no registered barrier in process %x\n", |
---|
| 424 | __FUNCTION__ , pid ); |
---|
| 425 | #endif |
---|
| 426 | this->errno = EINVAL; |
---|
| 427 | return -1; |
---|
| 428 | } |
---|
| 429 | |
---|
| 430 | // get extended pointer on first registered generic barrier descriptor |
---|
| 431 | xptr_t gen_barrier_xp = XLIST_FIRST( root_xp , generic_barrier_t , list ); |
---|
| 432 | |
---|
| 433 | // display barrier state |
---|
| 434 | generic_barrier_display( gen_barrier_xp ); |
---|
| 435 | |
---|
| 436 | break; |
---|
| 437 | } |
---|
| 438 | //////// |
---|
| 439 | default: |
---|
| 440 | { |
---|
| 441 | |
---|
| 442 | #if DEBUG_SYSCALLS_ERROR |
---|
[580] | 443 | printk("\n[ERROR] in %s : undefined display type %d\n", |
---|
| 444 | __FUNCTION__ , type ); |
---|
[440] | 445 | #endif |
---|
[623] | 446 | this->errno = EINVAL; |
---|
| 447 | return -1; |
---|
| 448 | } |
---|
| 449 | } // end switch on type |
---|
[421] | 450 | |
---|
[594] | 451 | #if (DEBUG_SYS_DISPLAY || CONFIG_INSTRUMENTATION_SYSCALLS) |
---|
| 452 | uint64_t tm_end = hal_get_cycles(); |
---|
| 453 | #endif |
---|
| 454 | |
---|
[438] | 455 | #if DEBUG_SYS_DISPLAY |
---|
| 456 | if( DEBUG_SYS_DISPLAY < tm_end ) |
---|
[619] | 457 | printk("\n[%s] thread[%x,%x] exit / cycle %d\n", |
---|
[594] | 458 | __FUNCTION__, process->pid, this->trdid, (uint32_t)tm_end ); |
---|
[433] | 459 | #endif |
---|
| 460 | |
---|
[594] | 461 | #if CONFIG_INSTRUMENTATION_SYSCALLS |
---|
| 462 | hal_atomic_add( &syscalls_cumul_cost[SYS_DISPLAY] , tm_end - tm_start ); |
---|
| 463 | hal_atomic_add( &syscalls_occurences[SYS_DISPLAY] , 1 ); |
---|
| 464 | #endif |
---|
| 465 | |
---|
[433] | 466 | return 0; |
---|
| 467 | |
---|
| 468 | } // end sys_display() |
---|