[421] | 1 | /* |
---|
| 2 | * sys_display.c - display the current state of a kernel structure on TXT0 |
---|
| 3 | * |
---|
[440] | 4 | * Author Alain Greiner (2016,2017,2018) |
---|
[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> |
---|
| 26 | #include <errno.h> |
---|
[433] | 27 | #include <vmm.h> |
---|
[421] | 28 | #include <cluster.h> |
---|
| 29 | #include <thread.h> |
---|
| 30 | #include <process.h> |
---|
[433] | 31 | #include <string.h> |
---|
[443] | 32 | #include <shared_syscalls.h> |
---|
[421] | 33 | |
---|
[506] | 34 | #include <syscalls.h> |
---|
| 35 | |
---|
[443] | 36 | ///////////////////////////////////////////////////////////////////////////////// |
---|
| 37 | // This static function returns a printable string for the type of display. |
---|
| 38 | ///////////////////////////////////////////////////////////////////////////////// |
---|
[421] | 39 | |
---|
[443] | 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"; |
---|
[580] | 50 | else if( type == DISPLAY_DQDT ) return "DQDT"; |
---|
| 51 | else if( type == DISPLAY_BUSYLOCKS ) return "BUSYLOCKS"; |
---|
[443] | 52 | } |
---|
| 53 | #endif |
---|
| 54 | |
---|
[421] | 55 | ///////////////////////////// |
---|
| 56 | int sys_display( reg_t type, |
---|
| 57 | reg_t arg0, |
---|
| 58 | reg_t arg1 ) |
---|
| 59 | { |
---|
[433] | 60 | |
---|
[440] | 61 | error_t error; |
---|
| 62 | vseg_t * vseg; |
---|
| 63 | |
---|
| 64 | thread_t * this = CURRENT_THREAD; |
---|
| 65 | process_t * process = this->process; |
---|
| 66 | |
---|
[438] | 67 | #if DEBUG_SYS_DISPLAY |
---|
[433] | 68 | uint64_t tm_start; |
---|
| 69 | uint64_t tm_end; |
---|
| 70 | tm_start = hal_get_cycles(); |
---|
[438] | 71 | if( DEBUG_SYS_DISPLAY < tm_start ) |
---|
[443] | 72 | printk("\n[DBG] %s : thread %d enter / process %x / type %s / cycle = %d\n", |
---|
| 73 | __FUNCTION__, this, this->process->pid, display_type_str(type), (uint32_t)tm_start ); |
---|
[433] | 74 | #endif |
---|
| 75 | |
---|
[440] | 76 | //////////////////////////// |
---|
[421] | 77 | if( type == DISPLAY_STRING ) |
---|
| 78 | { |
---|
| 79 | char kbuf[256]; |
---|
[433] | 80 | uint32_t length; |
---|
[421] | 81 | |
---|
| 82 | char * string = (char *)arg0; |
---|
[440] | 83 | |
---|
[421] | 84 | // check string in user space |
---|
[440] | 85 | error = vmm_get_vseg( process , (intptr_t)arg0 , &vseg ); |
---|
| 86 | |
---|
| 87 | if( error ) |
---|
[433] | 88 | { |
---|
[440] | 89 | |
---|
| 90 | #if DEBUG_SYSCALLS_ERROR |
---|
[580] | 91 | printk("\n[ERROR] in %s for STRING : string buffer %x unmapped\n", |
---|
| 92 | __FUNCTION__ , (intptr_t)arg0 ); |
---|
[440] | 93 | #endif |
---|
| 94 | this->errno = EINVAL; |
---|
[433] | 95 | return -1; |
---|
| 96 | } |
---|
[421] | 97 | |
---|
| 98 | // ckeck string length |
---|
[433] | 99 | length = hal_strlen_from_uspace( string ); |
---|
[440] | 100 | |
---|
[433] | 101 | if( length >= 256 ) |
---|
| 102 | { |
---|
[440] | 103 | |
---|
| 104 | #if DEBUG_SYSCALLS_ERROR |
---|
[580] | 105 | printk("\n[ERROR] in %s for STRING : string length %d too large\n", |
---|
| 106 | __FUNCTION__ , length ); |
---|
[440] | 107 | #endif |
---|
| 108 | this->errno = EINVAL; |
---|
[433] | 109 | return -1; |
---|
| 110 | } |
---|
[421] | 111 | |
---|
[440] | 112 | // copy string to kernel space |
---|
[421] | 113 | hal_strcpy_from_uspace( kbuf , string , 256 ); |
---|
| 114 | |
---|
| 115 | // print message on TXT0 kernel terminal |
---|
[440] | 116 | printk("\n%s / cycle %d\n", kbuf, (uint32_t)hal_get_cycles() ); |
---|
[421] | 117 | } |
---|
[440] | 118 | ////////////////////////////// |
---|
[421] | 119 | else if( type == DISPLAY_VMM ) |
---|
| 120 | { |
---|
[443] | 121 | cxy_t cxy = (cxy_t)arg0; |
---|
| 122 | pid_t pid = (pid_t)arg1; |
---|
[421] | 123 | |
---|
[443] | 124 | // check cxy argument |
---|
| 125 | if( cluster_is_undefined( cxy ) ) |
---|
| 126 | { |
---|
[421] | 127 | |
---|
[443] | 128 | #if DEBUG_SYSCALLS_ERROR |
---|
[580] | 129 | printk("\n[ERROR] in %s for VMM : process %x in cluster %x not found\n", |
---|
| 130 | __FUNCTION__ , pid , cxy ); |
---|
[443] | 131 | #endif |
---|
| 132 | this->errno = EINVAL; |
---|
| 133 | return -1; |
---|
| 134 | } |
---|
| 135 | |
---|
| 136 | // get extended pointer on process PID in cluster CXY |
---|
| 137 | xptr_t process_xp = cluster_get_process_from_pid_in_cxy( cxy , pid ); |
---|
| 138 | |
---|
[433] | 139 | if( process_xp == XPTR_NULL ) |
---|
| 140 | { |
---|
[440] | 141 | |
---|
| 142 | #if DEBUG_SYSCALLS_ERROR |
---|
[580] | 143 | printk("\n[ERROR] in %s for VMM : process %x in cluster %x not found\n", |
---|
| 144 | __FUNCTION__ , pid , cxy ); |
---|
[440] | 145 | #endif |
---|
| 146 | this->errno = EINVAL; |
---|
[433] | 147 | return -1; |
---|
| 148 | } |
---|
[421] | 149 | |
---|
[443] | 150 | // get local pointer on process |
---|
| 151 | process_t * process = (process_t *)GET_PTR( process_xp ); |
---|
[421] | 152 | |
---|
| 153 | // call kernel function |
---|
[443] | 154 | if( cxy == local_cxy ) |
---|
[421] | 155 | { |
---|
[443] | 156 | vmm_display( process , true ); |
---|
[421] | 157 | } |
---|
| 158 | else |
---|
| 159 | { |
---|
[443] | 160 | rpc_vmm_display_client( cxy , process , true ); |
---|
[421] | 161 | } |
---|
| 162 | } |
---|
[440] | 163 | //////////////////////////////// |
---|
[421] | 164 | else if( type == DISPLAY_SCHED ) |
---|
| 165 | { |
---|
| 166 | cxy_t cxy = (cxy_t)arg0; |
---|
| 167 | lid_t lid = (lid_t)arg1; |
---|
| 168 | |
---|
[440] | 169 | // check cxy argument |
---|
[433] | 170 | if( cluster_is_undefined( cxy ) ) |
---|
| 171 | { |
---|
[440] | 172 | |
---|
| 173 | #if DEBUG_SYSCALLS_ERROR |
---|
[580] | 174 | printk("\n[ERROR] in %s for SCHED : illegal cxy argument %x\n", |
---|
| 175 | __FUNCTION__ , cxy ); |
---|
[440] | 176 | #endif |
---|
| 177 | this->errno = EINVAL; |
---|
[433] | 178 | return -1; |
---|
| 179 | } |
---|
[421] | 180 | |
---|
[440] | 181 | // check lid argument |
---|
[433] | 182 | if( lid >= LOCAL_CLUSTER->cores_nr ) |
---|
| 183 | { |
---|
[440] | 184 | |
---|
| 185 | #if DEBUG_SYSCALLS_ERROR |
---|
[580] | 186 | printk("\n[ERROR] in %s for SCHED : illegal lid argument %x\n", |
---|
| 187 | __FUNCTION__ , lid ); |
---|
[440] | 188 | #endif |
---|
| 189 | this->errno = EINVAL; |
---|
[433] | 190 | return -1; |
---|
| 191 | } |
---|
[421] | 192 | |
---|
| 193 | if( cxy == local_cxy ) |
---|
| 194 | { |
---|
| 195 | sched_display( lid ); |
---|
| 196 | } |
---|
| 197 | else |
---|
| 198 | { |
---|
[450] | 199 | sched_remote_display( cxy , lid ); |
---|
[421] | 200 | } |
---|
| 201 | } |
---|
[440] | 202 | //////////////////////////////////////////// |
---|
[435] | 203 | else if( type == DISPLAY_CLUSTER_PROCESSES ) |
---|
[421] | 204 | { |
---|
| 205 | cxy_t cxy = (cxy_t)arg0; |
---|
| 206 | |
---|
[440] | 207 | // check cxy argument |
---|
[433] | 208 | if( cluster_is_undefined( cxy ) ) |
---|
| 209 | { |
---|
[440] | 210 | |
---|
| 211 | #if DEBUG_SYSCALLS_ERROR |
---|
[580] | 212 | printk("\n[ERROR] in %s for CLUSTER_PROCESSES : illegal cxy argument %x\n", |
---|
| 213 | __FUNCTION__ , cxy ); |
---|
[440] | 214 | #endif |
---|
| 215 | this->errno = EINVAL; |
---|
[433] | 216 | return -1; |
---|
| 217 | } |
---|
[421] | 218 | |
---|
| 219 | cluster_processes_display( cxy ); |
---|
| 220 | } |
---|
[580] | 221 | ////////////////////////////// |
---|
| 222 | else if( type == DISPLAY_VFS ) |
---|
| 223 | { |
---|
| 224 | vfs_display( process->vfs_root_xp ); |
---|
| 225 | } |
---|
| 226 | //////////////////////////////// |
---|
| 227 | else if( type == DISPLAY_CHDEV ) |
---|
| 228 | { |
---|
| 229 | chdev_dir_display(); |
---|
| 230 | } |
---|
[440] | 231 | //////////////////////////////////////// |
---|
[435] | 232 | else if( type == DISPLAY_TXT_PROCESSES ) |
---|
| 233 | { |
---|
| 234 | uint32_t txt_id = (uint32_t)arg0; |
---|
| 235 | |
---|
| 236 | // check argument |
---|
| 237 | if( txt_id >= LOCAL_CLUSTER->nb_txt_channels ) |
---|
| 238 | { |
---|
[440] | 239 | |
---|
| 240 | #if DEBUG_SYSCALLS_ERROR |
---|
[580] | 241 | printk("\n[ERROR] in %s for TXT_PROCESSES : illegal txt_id argument %d\n", |
---|
| 242 | __FUNCTION__ , txt_id ); |
---|
[440] | 243 | #endif |
---|
| 244 | this->errno = EINVAL; |
---|
[435] | 245 | return -1; |
---|
| 246 | } |
---|
| 247 | |
---|
| 248 | process_txt_display( txt_id ); |
---|
| 249 | } |
---|
[580] | 250 | /////////////////////////////// |
---|
| 251 | else if( type == DISPLAY_DQDT ) |
---|
[421] | 252 | { |
---|
[580] | 253 | dqdt_display(); |
---|
[421] | 254 | } |
---|
[580] | 255 | //////////////////////////////////// |
---|
| 256 | else if( type == DISPLAY_BUSYLOCKS ) |
---|
[421] | 257 | { |
---|
[580] | 258 | pid_t pid = (cxy_t)arg0; |
---|
| 259 | trdid_t trdid = (trdid_t)arg1; |
---|
| 260 | |
---|
| 261 | // get extended pointer on target thread |
---|
| 262 | xptr_t thread_xp = thread_get_xptr( pid , trdid ); |
---|
| 263 | |
---|
| 264 | if( thread_xp == XPTR_NULL ) |
---|
| 265 | { |
---|
| 266 | |
---|
| 267 | #if DEBUG_SYSCALLS_ERROR |
---|
| 268 | printk("\n[ERROR] in %s for BUSYLOCKS : thread %x in process %x not found\n", |
---|
| 269 | __FUNCTION__ , trdid , pid ); |
---|
| 270 | #endif |
---|
| 271 | this->errno = EINVAL; |
---|
| 272 | return -1; |
---|
| 273 | } |
---|
| 274 | |
---|
| 275 | thread_display_busylocks( thread_xp ); |
---|
[421] | 276 | } |
---|
[440] | 277 | //// |
---|
[433] | 278 | else |
---|
| 279 | { |
---|
[440] | 280 | |
---|
| 281 | #if DEBUG_SYSCALLS_ERROR |
---|
[580] | 282 | printk("\n[ERROR] in %s : undefined display type %d\n", |
---|
| 283 | __FUNCTION__ , type ); |
---|
[440] | 284 | #endif |
---|
| 285 | this->errno = EINVAL; |
---|
[433] | 286 | return -1; |
---|
| 287 | } |
---|
[421] | 288 | |
---|
[438] | 289 | #if DEBUG_SYS_DISPLAY |
---|
[433] | 290 | tm_end = hal_get_cycles(); |
---|
[438] | 291 | if( DEBUG_SYS_DISPLAY < tm_end ) |
---|
[433] | 292 | printk("\n[DBG] %s : thread %x exit / process %x / cost = %d / cycle %d\n", |
---|
[436] | 293 | __FUNCTION__, this, this->process->pid, (uint32_t)(tm_end - tm_start) , (uint32_t)tm_end ); |
---|
[433] | 294 | #endif |
---|
| 295 | |
---|
| 296 | return 0; |
---|
| 297 | |
---|
| 298 | } // end sys_display() |
---|