[1] | 1 | /* |
---|
| 2 | * rpc.c - RPC related operations implementation. |
---|
| 3 | * |
---|
| 4 | * Authors Mohamed Lamine Karaoui (2015) |
---|
| 5 | * Alain Greiner (2016) |
---|
| 6 | * |
---|
| 7 | * Copyright (c) UPMC Sorbonne Universites |
---|
| 8 | * |
---|
| 9 | * This file is part of ALMOS-MKH. |
---|
| 10 | * |
---|
| 11 | * ALMOS-MKH is free software; you can redistribute it and/or modify it |
---|
| 12 | * under the terms of the GNU General Public License as published by |
---|
| 13 | * the Free Software Foundation; version 2.0 of the License. |
---|
| 14 | * |
---|
| 15 | * ALMOS-MKH is distributed in the hope that it will be useful, but |
---|
| 16 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
---|
| 18 | * General Public License for more details. |
---|
| 19 | * |
---|
| 20 | * You should have received a copy of the GNU General Public License |
---|
| 21 | * along with ALMOS-MKH; if not, write to the Free Software Foundation, |
---|
| 22 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
---|
| 23 | */ |
---|
| 24 | |
---|
| 25 | #include <almos_config.h> |
---|
| 26 | #include <hal_types.h> |
---|
| 27 | #include <hal_atomic.h> |
---|
| 28 | #include <hal_remote.h> |
---|
| 29 | #include <hal_irqmask.h> |
---|
| 30 | #include <hal_special.h> |
---|
| 31 | #include <printk.h> |
---|
| 32 | #include <remote_sem.h> |
---|
| 33 | #include <core.h> |
---|
| 34 | #include <mapper.h> |
---|
[5] | 35 | #include <chdev.h> |
---|
[1] | 36 | #include <bits.h> |
---|
| 37 | #include <thread.h> |
---|
| 38 | #include <cluster.h> |
---|
| 39 | #include <process.h> |
---|
| 40 | #include <vfs.h> |
---|
| 41 | #include <fatfs.h> |
---|
| 42 | #include <dev_icu.h> |
---|
| 43 | #include <rpc.h> |
---|
| 44 | |
---|
| 45 | ///////////////////////////////////////////////////////////////////////////////////////// |
---|
| 46 | // array of function pointers (must be consistent with enum in rpc.h) |
---|
| 47 | ///////////////////////////////////////////////////////////////////////////////////////// |
---|
| 48 | |
---|
| 49 | rpc_server_t * rpc_server[RPC_MAX_INDEX] = |
---|
| 50 | { |
---|
| 51 | &rpc_pmem_get_pages_server, // 0 |
---|
| 52 | &rpc_process_pid_alloc_server, // 1 |
---|
| 53 | &rpc_process_exec_server, // 2 |
---|
| 54 | &rpc_process_kill_server, // 3 |
---|
| 55 | &rpc_thread_user_create_server, // 4 |
---|
| 56 | &rpc_thread_kernel_create_server, // 5 |
---|
[5] | 57 | &rpc_undefined, // 6 |
---|
| 58 | &rpc_undefined, // 7 |
---|
[1] | 59 | &rpc_undefined, // 8 |
---|
| 60 | &rpc_undefined, // 9 |
---|
| 61 | |
---|
| 62 | &rpc_vfs_inode_create_server, // 10 |
---|
| 63 | &rpc_vfs_inode_destroy_server, // 11 |
---|
| 64 | &rpc_vfs_dentry_create_server, // 12 |
---|
| 65 | &rpc_vfs_dentry_destroy_server, // 13 |
---|
| 66 | &rpc_undefined, // 14 |
---|
| 67 | &rpc_undefined, // 15 |
---|
| 68 | &rpc_undefined, // 16 |
---|
| 69 | &rpc_undefined, // 17 |
---|
| 70 | &rpc_undefined, // 18 |
---|
| 71 | &rpc_undefined, // 19 |
---|
| 72 | |
---|
| 73 | &rpc_vmm_get_ref_vseg_server, // 20 |
---|
| 74 | &rpc_vmm_get_pte_server, // 21 |
---|
| 75 | &rpc_semaphore_alloc_server, // 22 |
---|
| 76 | &rpc_semaphore_free_server, // 23 |
---|
| 77 | &rpc_mapper_move_server, // 24 |
---|
| 78 | &rpc_undefined, // 25 |
---|
| 79 | &rpc_undefined, // 26 |
---|
| 80 | &rpc_undefined, // 27 |
---|
| 81 | &rpc_undefined, // 28 |
---|
| 82 | &rpc_undefined, // 29 |
---|
| 83 | |
---|
| 84 | &rpc_fatfs_get_cluster_server // 30 |
---|
| 85 | }; |
---|
| 86 | |
---|
| 87 | ////////////////////////////////////////////// |
---|
| 88 | void __attribute__((noinline)) rpc_undefined() |
---|
| 89 | { |
---|
| 90 | printk("\n[PANIC] ‰s called in cluster %x\n", __FUNCTION__ , local_cxy ); |
---|
| 91 | hal_core_sleep(); |
---|
| 92 | } |
---|
| 93 | |
---|
| 94 | ///////////////////////////////////////////////////////////////////////////////////////// |
---|
| 95 | // Marshaling functions attached to RPC_PMEM_GET_PAGES |
---|
| 96 | ///////////////////////////////////////////////////////////////////////////////////////// |
---|
| 97 | |
---|
| 98 | /////////////////////////////////////////////// |
---|
| 99 | void rpc_pmem_get_pages_client( cxy_t cxy, |
---|
| 100 | uint32_t order, // in |
---|
| 101 | error_t * error, // out |
---|
| 102 | uint32_t * ppn ) // out |
---|
| 103 | { |
---|
| 104 | // any RPC must be remote |
---|
| 105 | if( cxy == local_cxy ) |
---|
| 106 | { |
---|
| 107 | printk("PANIC in %s : target is not remote\n", __FUNCTION__ ); |
---|
| 108 | hal_core_sleep(); |
---|
| 109 | } |
---|
| 110 | |
---|
| 111 | // initialise RPC descriptor header |
---|
| 112 | rpc_desc_t rpc; |
---|
| 113 | rpc.index = RPC_PMEM_GET_PAGES; |
---|
| 114 | rpc.response = 1; |
---|
| 115 | |
---|
| 116 | // set input arguments in RPC descriptor |
---|
| 117 | rpc.args[0] = (uint64_t)order; |
---|
| 118 | |
---|
| 119 | // register RPC request in remote RPC fifo (blocking function) |
---|
| 120 | rpc_send_sync( cxy , &rpc ); |
---|
| 121 | |
---|
| 122 | // get output arguments RPC descriptor |
---|
| 123 | *error = (error_t)rpc.args[0]; |
---|
| 124 | *ppn = (uint32_t)rpc.args[1]; |
---|
| 125 | } |
---|
| 126 | |
---|
| 127 | /////////////////////////////////////////// |
---|
| 128 | void rpc_pmem_get_pages_server( xptr_t xp ) |
---|
| 129 | { |
---|
| 130 | uint32_t order; // input |
---|
| 131 | error_t error; // output |
---|
| 132 | uint32_t ppn; // output |
---|
| 133 | |
---|
| 134 | // get client cluster identifier and pointer on RPC descriptor |
---|
| 135 | cxy_t cxy = (cxy_t)GET_CXY( xp ); |
---|
| 136 | rpc_desc_t * desc = (rpc_desc_t *)GET_PTR( xp ); |
---|
| 137 | |
---|
| 138 | // get input arguments from client RPC descriptor |
---|
| 139 | order = hal_remote_lw( XPTR( cxy , &desc->args[0] ) ); |
---|
| 140 | |
---|
| 141 | // call local pmem allocator |
---|
| 142 | page_t * page = ppm_alloc_pages( order ); |
---|
| 143 | error = ( page == NULL ) ? ENOMEM : 0; |
---|
| 144 | ppn = ppm_page2ppn( page ); |
---|
| 145 | |
---|
| 146 | // set output arguments into client RPC descriptor |
---|
| 147 | hal_remote_sw( XPTR( cxy , &desc->args[0] ) , error ); |
---|
| 148 | hal_remote_sw( XPTR( cxy , &desc->args[1] ) , ppn ); |
---|
| 149 | } |
---|
| 150 | |
---|
| 151 | ///////////////////////////////////////////////////////////////////////////////////////// |
---|
| 152 | // Marshaling functions attached to RPC_PROCESS_PID_ALLOC |
---|
| 153 | ///////////////////////////////////////////////////////////////////////////////////////// |
---|
| 154 | |
---|
| 155 | ////////////////////////////////////////////////// |
---|
| 156 | void rpc_process_pid_alloc_client( cxy_t cxy, |
---|
| 157 | process_t * process, // in |
---|
| 158 | error_t * error, // out |
---|
| 159 | pid_t * pid ) // out |
---|
| 160 | { |
---|
| 161 | // RPC must be remote |
---|
| 162 | if( cxy == local_cxy ) |
---|
| 163 | { |
---|
| 164 | printk("PANIC in %s : target is not remote\n", __FUNCTION__ ); |
---|
| 165 | hal_core_sleep(); |
---|
| 166 | } |
---|
| 167 | |
---|
| 168 | // initialise RPC descriptor header |
---|
| 169 | rpc_desc_t rpc; |
---|
| 170 | rpc.index = RPC_PROCESS_PID_ALLOC; |
---|
| 171 | rpc.response = 1; |
---|
| 172 | |
---|
| 173 | // set input arguments in RPC descriptor |
---|
| 174 | rpc.args[0] = (uint64_t)(intptr_t)process; |
---|
| 175 | |
---|
| 176 | // register RPC request in remote RPC fifo (blocking function) |
---|
| 177 | rpc_send_sync( cxy , &rpc ); |
---|
| 178 | |
---|
| 179 | // get output arguments RPC descriptor |
---|
| 180 | *pid = (pid_t)rpc.args[1]; |
---|
| 181 | *error = (error_t)rpc.args[2]; |
---|
| 182 | } |
---|
| 183 | |
---|
| 184 | ////////////////////////////////////////////// |
---|
| 185 | void rpc_process_pid_alloc_server( xptr_t xp ) |
---|
| 186 | { |
---|
| 187 | process_t * process; // input : client process descriptor |
---|
| 188 | error_t error; // output : error status |
---|
| 189 | pid_t pid; // output : process identifier |
---|
| 190 | |
---|
| 191 | // get client cluster identifier and pointer on RPC descriptor |
---|
| 192 | cxy_t client_cxy = (cxy_t)GET_CXY( xp ); |
---|
| 193 | rpc_desc_t * desc = (rpc_desc_t *)GET_PTR( xp ); |
---|
| 194 | |
---|
| 195 | // get input argument from client RPC descriptor |
---|
| 196 | process = (process_t*)(intptr_t)hal_remote_lwd( XPTR( client_cxy , &desc->args[0] ) ); |
---|
| 197 | |
---|
| 198 | // call local pid allocator |
---|
| 199 | xptr_t xp_process = XPTR( client_cxy , process ); |
---|
| 200 | error = cluster_pid_alloc( xp_process , &pid ); |
---|
| 201 | |
---|
| 202 | // set output arguments into client RPC descriptor |
---|
| 203 | hal_remote_sw( XPTR( client_cxy , &desc->args[0] ) , (uint64_t)error ); |
---|
| 204 | hal_remote_sw( XPTR( client_cxy , &desc->args[1] ) , (uint64_t)pid ); |
---|
| 205 | } |
---|
| 206 | |
---|
| 207 | |
---|
| 208 | ///////////////////////////////////////////////////////////////////////////////////////// |
---|
| 209 | // Marshaling functions attached to RPC_PROCESS_EXEC |
---|
| 210 | ///////////////////////////////////////////////////////////////////////////////////////// |
---|
| 211 | |
---|
| 212 | //////////////////////////////////////////////// |
---|
| 213 | void rpc_process_exec_client( cxy_t cxy, |
---|
| 214 | exec_info_t * info, // in |
---|
| 215 | error_t * error ) // out |
---|
| 216 | { |
---|
| 217 | // RPC must be remote |
---|
| 218 | if( cxy == local_cxy ) |
---|
| 219 | { |
---|
| 220 | printk("PANIC in %s : target is not remote\n", __FUNCTION__ ); |
---|
| 221 | hal_core_sleep(); |
---|
| 222 | } |
---|
| 223 | |
---|
| 224 | // initialise RPC descriptor header |
---|
| 225 | rpc_desc_t rpc; |
---|
| 226 | rpc.index = RPC_PROCESS_EXEC; |
---|
| 227 | rpc.response = 1; |
---|
| 228 | |
---|
| 229 | // set input arguments in RPC descriptor |
---|
| 230 | rpc.args[0] = (uint64_t)(intptr_t)info; |
---|
| 231 | |
---|
| 232 | // register RPC request in remote RPC fifo (blocking function) |
---|
| 233 | rpc_send_sync( cxy , &rpc ); |
---|
| 234 | |
---|
| 235 | // get output arguments from RPC descriptor |
---|
| 236 | *error = (error_t)rpc.args[1]; |
---|
| 237 | } |
---|
| 238 | |
---|
| 239 | ///////////////////////////////////////// |
---|
| 240 | void rpc_process_exec_server( xptr_t xp ) |
---|
| 241 | { |
---|
| 242 | exec_info_t * ptr; // local pointer on remote exec_info structure |
---|
| 243 | exec_info_t info; // local copy of exec_info structure |
---|
| 244 | error_t error; // local error error status |
---|
| 245 | |
---|
| 246 | // get client cluster identifier and pointer on RPC descriptor |
---|
| 247 | cxy_t client_cxy = (cxy_t)GET_CXY( xp ); |
---|
| 248 | rpc_desc_t * desc = (rpc_desc_t *)GET_PTR( xp ); |
---|
| 249 | |
---|
| 250 | // get pointer on exec_info structure in client cluster from RPC descriptor |
---|
| 251 | ptr = (exec_info_t*)(intptr_t)hal_remote_lwd( XPTR( client_cxy , &desc->args[0] ) ); |
---|
| 252 | |
---|
| 253 | // copy exec_info structure from client buffer to server buffer |
---|
| 254 | hal_remote_memcpy( XPTR( client_cxy , ptr ), |
---|
| 255 | XPTR( local_cxy , &info ), |
---|
| 256 | sizeof(exec_info_t) ); |
---|
| 257 | |
---|
| 258 | // call local kernel function |
---|
| 259 | error = process_make_exec( &info ); |
---|
| 260 | |
---|
| 261 | // set output argument into client RPC descriptor |
---|
| 262 | hal_remote_swd( XPTR( client_cxy , &desc->args[1] ) , (uint64_t)error ); |
---|
| 263 | } |
---|
| 264 | |
---|
| 265 | |
---|
| 266 | ///////////////////////////////////////////////////////////////////////////////////////// |
---|
| 267 | // Marshaling functions attached to RPC_PROCESS_KILL |
---|
| 268 | ///////////////////////////////////////////////////////////////////////////////////////// |
---|
| 269 | |
---|
| 270 | /////////////////////////////////////////////////// |
---|
| 271 | void rpc_process_kill_client( process_t * process ) |
---|
| 272 | { |
---|
| 273 | // only reference cluster can send this RPC |
---|
| 274 | if( !process->is_ref ) |
---|
| 275 | { |
---|
| 276 | printk("PANIC in %s : caller is not the reference process\n", __FUNCTION__ ); |
---|
| 277 | hal_core_sleep(); |
---|
| 278 | } |
---|
| 279 | |
---|
| 280 | // get local process index in reference cluster |
---|
| 281 | lpid_t lpid = LPID_FROM_PID( process->pid ); |
---|
| 282 | |
---|
| 283 | // get local process manager pointer |
---|
| 284 | pmgr_t * pmgr = &LOCAL_CLUSTER->pmgr; |
---|
| 285 | |
---|
| 286 | // get number of copies |
---|
| 287 | uint32_t copies = pmgr->copies_nr[lpid]; |
---|
| 288 | |
---|
| 289 | // initialise RPC descriptor |
---|
| 290 | rpc_desc_t rpc; |
---|
| 291 | rpc.index = RPC_PROCESS_KILL; |
---|
| 292 | rpc.response = copies; |
---|
| 293 | rpc.args[0] = (uint64_t)process->pid; |
---|
| 294 | |
---|
| 295 | // loop on list of copies to send RPC |
---|
| 296 | xptr_t iter; |
---|
| 297 | XLIST_FOREACH( XPTR( local_cxy , &pmgr->copies_root[lpid] ) , iter ) |
---|
| 298 | { |
---|
| 299 | // get cluster_identifier for current copy |
---|
| 300 | cxy_t target_cxy = GET_CXY( iter ); |
---|
| 301 | |
---|
| 302 | // register RPC request in remote RPC fifo ... but the reference |
---|
| 303 | if( target_cxy != local_cxy ) rpc_send_sync( target_cxy , &rpc ); |
---|
| 304 | } |
---|
| 305 | } |
---|
| 306 | |
---|
| 307 | ///////////////////////////////////////// |
---|
| 308 | void rpc_process_kill_server( xptr_t xp ) |
---|
| 309 | { |
---|
| 310 | pid_t pid; |
---|
| 311 | process_t * process; |
---|
| 312 | |
---|
| 313 | // get client cluster identifier and pointer on RPC descriptor |
---|
| 314 | cxy_t client_cxy = (cxy_t)GET_CXY( xp ); |
---|
| 315 | rpc_desc_t * desc = (rpc_desc_t *)GET_PTR( xp ); |
---|
| 316 | |
---|
| 317 | // get pid argument from RPC descriptor |
---|
| 318 | pid = (pid_t)hal_remote_lwd( XPTR( client_cxy , &desc->args[0] ) ); |
---|
| 319 | |
---|
| 320 | // get process pointer to call local kernel function |
---|
| 321 | process = cluster_get_local_process_from_pid( pid ); |
---|
| 322 | |
---|
| 323 | if( process == NULL ) // process not found => do nothing |
---|
| 324 | { |
---|
| 325 | printk("\n[WARNING] in %s : process %x not found in cluster %x\n", |
---|
| 326 | __FUNCTION__ , pid , local_cxy ); |
---|
| 327 | } |
---|
| 328 | else // destroy process |
---|
| 329 | { |
---|
| 330 | process_kill( process ); |
---|
| 331 | } |
---|
| 332 | } |
---|
| 333 | |
---|
| 334 | |
---|
| 335 | ///////////////////////////////////////////////////////////////////////////////////////// |
---|
| 336 | // Marshaling functions attached to RPC_THREAD_USER_CREATE |
---|
| 337 | ///////////////////////////////////////////////////////////////////////////////////////// |
---|
| 338 | |
---|
| 339 | ///////////////////////////////////////////////////////// |
---|
| 340 | void rpc_thread_user_create_client( cxy_t cxy, |
---|
| 341 | pthread_attr_t * attr, // in |
---|
| 342 | xptr_t * thread_xp, // out |
---|
| 343 | error_t * error ) // out |
---|
| 344 | { |
---|
| 345 | // RPC must be remote |
---|
| 346 | if( cxy == local_cxy ) |
---|
| 347 | { |
---|
| 348 | printk("\n[PANIC] in %s : target is not remote\n", __FUNCTION__ ); |
---|
| 349 | hal_core_sleep(); |
---|
| 350 | } |
---|
| 351 | |
---|
| 352 | // initialise RPC descriptor header |
---|
| 353 | rpc_desc_t rpc; |
---|
| 354 | rpc.index = RPC_THREAD_USER_CREATE; |
---|
| 355 | rpc.response = 1; |
---|
| 356 | |
---|
| 357 | // set input arguments in RPC descriptor |
---|
| 358 | rpc.args[0] = (uint64_t)(intptr_t)attr; |
---|
| 359 | |
---|
| 360 | // register RPC request in remote RPC fifo |
---|
| 361 | rpc_send_sync( cxy , &rpc ); |
---|
| 362 | |
---|
| 363 | // get output arguments from RPC descriptor |
---|
| 364 | *thread_xp = (xptr_t)rpc.args[1]; |
---|
| 365 | *error = (error_t)rpc.args[2]; |
---|
| 366 | } |
---|
| 367 | |
---|
| 368 | /////////////////////////////////////////////// |
---|
| 369 | void rpc_thread_user_create_server( xptr_t xp ) |
---|
| 370 | { |
---|
| 371 | pthread_attr_t * attr_ptr; // pointer on attributes structure in client cluster |
---|
| 372 | pthread_attr_t attr_copy; // attributes structure copy in server cluster |
---|
| 373 | thread_t * thread_ptr; // local pointer on thread descriptor |
---|
| 374 | xptr_t thread_xp; // extended pointer on thread descriptor |
---|
| 375 | pid_t pid; // process identifier |
---|
| 376 | process_t * process; // local pointer on process descriptor |
---|
| 377 | vseg_t * vseg; // local pointer on stack vseg |
---|
| 378 | |
---|
| 379 | error_t error = 0; |
---|
| 380 | |
---|
| 381 | // get client cluster identifier and pointer on RPC descriptor |
---|
| 382 | cxy_t client_cxy = (cxy_t)GET_CXY( xp ); |
---|
| 383 | rpc_desc_t * desc = (rpc_desc_t *)GET_PTR( xp ); |
---|
| 384 | |
---|
| 385 | // get pointer on attributes structure in client cluster from RPC descriptor |
---|
| 386 | attr_ptr = (pthread_attr_t *)(intptr_t)hal_remote_lwd( XPTR(client_cxy , &desc->args[0]) ); |
---|
| 387 | |
---|
| 388 | // makes a local copy of attributes structure |
---|
| 389 | hal_remote_memcpy( XPTR( local_cxy , &attr_copy ), |
---|
| 390 | XPTR( client_cxy , attr_ptr ), |
---|
| 391 | sizeof(pthread_attr_t) ); |
---|
| 392 | |
---|
| 393 | if( attr_copy.cxy != local_cxy ) |
---|
| 394 | { |
---|
| 395 | printk("\n[PANIC] in %s : target cluster = %X / local_cluster = %x\n", |
---|
| 396 | __FUNCTION__ , attr_copy.cxy , local_cxy ); |
---|
| 397 | hal_core_sleep(); |
---|
| 398 | } |
---|
| 399 | |
---|
| 400 | // get local process descriptor |
---|
| 401 | pid = attr_copy.pid; |
---|
| 402 | process = cluster_get_local_process_from_pid( pid ); |
---|
| 403 | |
---|
| 404 | if( process == NULL ) |
---|
| 405 | { |
---|
| 406 | printk("\n[ERROR] in %s : no process descriptor in cluster %x for pid = %x\n", |
---|
| 407 | __FUNCTION__ , local_cxy , pid ); |
---|
| 408 | error = ENOMEM; |
---|
| 409 | |
---|
| 410 | } |
---|
| 411 | |
---|
| 412 | // allocate a stack from local VMM |
---|
| 413 | vseg = vmm_create_vseg( process, |
---|
| 414 | 0, |
---|
| 415 | 0, |
---|
| 416 | VSEG_TYPE_STACK ); |
---|
| 417 | if( vseg == NULL ) |
---|
| 418 | { |
---|
| 419 | printk("\n[ERROR] in %s : cannot create stack vseg in cluster %x for pid %x\n", |
---|
| 420 | __FUNCTION__ , local_cxy , pid ); |
---|
| 421 | error = ENOMEM; |
---|
| 422 | } |
---|
| 423 | |
---|
| 424 | // create thread in local cluster |
---|
| 425 | if( thread_user_create( &thread_ptr, |
---|
| 426 | &attr_copy, |
---|
| 427 | vseg->min, |
---|
| 428 | vseg->max - vseg->min ) ) error = ENOMEM; |
---|
| 429 | |
---|
| 430 | |
---|
| 431 | // set output arguments |
---|
| 432 | thread_xp = XPTR( local_cxy , thread_ptr ); |
---|
| 433 | hal_remote_swd( XPTR( client_cxy , &desc->args[1] ) , (uint64_t)error ); |
---|
| 434 | hal_remote_swd( XPTR( client_cxy , &desc->args[2] ) , (uint64_t)thread_xp ); |
---|
| 435 | } |
---|
| 436 | |
---|
| 437 | ///////////////////////////////////////////////////////////////////////////////////////// |
---|
| 438 | // Marshaling functions attached to RPC_THREAD_KERNEL_CREATE |
---|
| 439 | ///////////////////////////////////////////////////////////////////////////////////////// |
---|
| 440 | |
---|
| 441 | //////////////////////////////////////////////////// |
---|
| 442 | void rpc_thread_kernel_create_client( cxy_t cxy, |
---|
| 443 | uint32_t type, // in |
---|
| 444 | void * func, // in |
---|
| 445 | void * args, // in |
---|
| 446 | xptr_t * thread_xp, // out |
---|
| 447 | error_t * error ) // out |
---|
| 448 | { |
---|
| 449 | // RPC must be remote |
---|
| 450 | if( cxy == local_cxy ) |
---|
| 451 | { |
---|
| 452 | printk("PANIC in %s : target is not remote\n", __FUNCTION__ ); |
---|
| 453 | hal_core_sleep(); |
---|
| 454 | } |
---|
| 455 | |
---|
| 456 | // initialise RPC descriptor header |
---|
| 457 | rpc_desc_t rpc; |
---|
| 458 | rpc.index = RPC_THREAD_KERNEL_CREATE; |
---|
| 459 | rpc.response = 1; |
---|
| 460 | |
---|
| 461 | // set input arguments in RPC descriptor |
---|
| 462 | rpc.args[0] = (uint64_t)type; |
---|
| 463 | rpc.args[1] = (uint64_t)(intptr_t)func; |
---|
| 464 | rpc.args[2] = (uint64_t)(intptr_t)args; |
---|
| 465 | |
---|
| 466 | // register RPC request in remote RPC fifo |
---|
| 467 | rpc_send_sync( cxy , &rpc ); |
---|
| 468 | |
---|
| 469 | // get output arguments from RPC descriptor |
---|
| 470 | *thread_xp = (xptr_t)rpc.args[3]; |
---|
| 471 | *error = (error_t)rpc.args[4]; |
---|
| 472 | } |
---|
| 473 | |
---|
| 474 | ///////////////////////////////////////////////// |
---|
| 475 | void rpc_thread_kernel_create_server( xptr_t xp ) |
---|
| 476 | { |
---|
| 477 | thread_t * thread_ptr; // local pointer on thread descriptor |
---|
| 478 | xptr_t thread_xp; // extended pointer on thread descriptor |
---|
| 479 | lid_t core_lid; // core local index |
---|
| 480 | error_t error; |
---|
| 481 | |
---|
| 482 | // get client cluster identifier and pointer on RPC descriptor |
---|
| 483 | cxy_t client_cxy = (cxy_t)GET_CXY( xp ); |
---|
| 484 | rpc_desc_t * desc = (rpc_desc_t *)GET_PTR( xp ); |
---|
| 485 | |
---|
| 486 | // get attributes from RPC descriptor |
---|
| 487 | uint32_t type = (uint32_t) hal_remote_lwd( XPTR( client_cxy , &desc->args[0] ) ); |
---|
| 488 | void * func = (void*)(intptr_t)hal_remote_lwd( XPTR( client_cxy , &desc->args[1] ) ); |
---|
| 489 | void * args = (void*)(intptr_t)hal_remote_lwd( XPTR( client_cxy , &desc->args[2] ) ); |
---|
| 490 | |
---|
| 491 | // select one core |
---|
| 492 | core_lid = cluster_select_local_core(); |
---|
| 493 | |
---|
| 494 | // call local kernel function |
---|
| 495 | error = thread_kernel_create( &thread_ptr , type , func , args , core_lid ); |
---|
| 496 | |
---|
| 497 | // set output arguments |
---|
| 498 | thread_xp = XPTR( local_cxy , thread_ptr ); |
---|
| 499 | hal_remote_swd( XPTR( client_cxy , &desc->args[1] ) , (uint64_t)error ); |
---|
| 500 | hal_remote_swd( XPTR( client_cxy , &desc->args[2] ) , (uint64_t)thread_xp ); |
---|
| 501 | } |
---|
| 502 | |
---|
| 503 | ///////////////////////////////////////////////////////////////////////////////////////// |
---|
| 504 | // Marshaling functions attached to RPC_VFS_INODE_CREATE |
---|
| 505 | ///////////////////////////////////////////////////////////////////////////////////////// |
---|
| 506 | |
---|
| 507 | ///////////////////////////////////////////////////// |
---|
| 508 | void rpc_vfs_inode_create_client( cxy_t cxy, |
---|
| 509 | xptr_t dentry_xp, // in |
---|
| 510 | uint32_t type, // in |
---|
| 511 | uint32_t attr, // in |
---|
| 512 | uint32_t mode, // in |
---|
| 513 | uint32_t uid, // in |
---|
| 514 | uint32_t gid, // in |
---|
| 515 | xptr_t * inode_xp, // out |
---|
| 516 | error_t * error ) // out |
---|
| 517 | { |
---|
| 518 | // RPC must be remote |
---|
| 519 | if( cxy == local_cxy ) |
---|
| 520 | { |
---|
| 521 | printk("PANIC in %s : target cluster is not remote\n", __FUNCTION__ ); |
---|
| 522 | hal_core_sleep(); |
---|
| 523 | } |
---|
| 524 | |
---|
| 525 | // initialise RPC descriptor header |
---|
| 526 | rpc_desc_t rpc; |
---|
| 527 | rpc.index = RPC_VFS_INODE_CREATE; |
---|
| 528 | rpc.response = 1; |
---|
| 529 | |
---|
| 530 | // set input arguments in RPC descriptor |
---|
| 531 | rpc.args[0] = (uint64_t)dentry_xp; |
---|
| 532 | rpc.args[1] = (uint64_t)type; |
---|
| 533 | rpc.args[2] = (uint64_t)attr; |
---|
| 534 | rpc.args[3] = (uint64_t)mode; |
---|
| 535 | rpc.args[4] = (uint64_t)uid; |
---|
| 536 | rpc.args[5] = (uint64_t)gid; |
---|
| 537 | |
---|
| 538 | // register RPC request in remote RPC fifo (blocking function) |
---|
| 539 | rpc_send_sync( cxy , &rpc ); |
---|
| 540 | |
---|
| 541 | // get output values from RPC descriptor |
---|
| 542 | *inode_xp = (xptr_t)rpc.args[6]; |
---|
| 543 | *error = (error_t)rpc.args[7]; |
---|
| 544 | } |
---|
| 545 | |
---|
| 546 | ///////////////////////////////////////////// |
---|
| 547 | void rpc_vfs_inode_create_server( xptr_t xp ) |
---|
| 548 | { |
---|
| 549 | xptr_t dentry_xp; |
---|
| 550 | uint32_t type; |
---|
| 551 | uint32_t attr; |
---|
| 552 | uint32_t mode; |
---|
| 553 | uint32_t uid; |
---|
| 554 | uint32_t gid; |
---|
| 555 | xptr_t inode_xp; |
---|
| 556 | error_t error; |
---|
| 557 | |
---|
| 558 | // get client cluster identifier and pointer on RPC descriptor |
---|
| 559 | cxy_t client_cxy = (cxy_t)GET_CXY( xp ); |
---|
| 560 | rpc_desc_t * desc = (rpc_desc_t *)GET_PTR( xp ); |
---|
| 561 | |
---|
| 562 | // get input arguments from client rpc descriptor |
---|
| 563 | dentry_xp = (xptr_t) hal_remote_lwd( XPTR( client_cxy , &desc->args[0] ) ); |
---|
| 564 | type = (uint32_t)hal_remote_lwd( XPTR( client_cxy , &desc->args[1] ) ); |
---|
| 565 | attr = (uint32_t)hal_remote_lwd( XPTR( client_cxy , &desc->args[2] ) ); |
---|
| 566 | mode = (uint32_t)hal_remote_lwd( XPTR( client_cxy , &desc->args[3] ) ); |
---|
| 567 | uid = (uid_t) hal_remote_lwd( XPTR( client_cxy , &desc->args[4] ) ); |
---|
| 568 | gid = (gid_t) hal_remote_lwd( XPTR( client_cxy , &desc->args[5] ) ); |
---|
| 569 | |
---|
| 570 | // call local kernel function |
---|
| 571 | error = vfs_inode_create( dentry_xp, |
---|
| 572 | type, |
---|
| 573 | attr, |
---|
| 574 | mode, |
---|
| 575 | uid, |
---|
| 576 | gid, |
---|
| 577 | &inode_xp ); |
---|
| 578 | |
---|
| 579 | // set output arguments |
---|
| 580 | hal_remote_swd( XPTR( client_cxy , &desc->args[6] ) , (uint64_t)inode_xp ); |
---|
| 581 | hal_remote_swd( XPTR( client_cxy , &desc->args[7] ) , (uint64_t)error ); |
---|
| 582 | } |
---|
| 583 | |
---|
| 584 | ///////////////////////////////////////////////////////////////////////////////////////// |
---|
| 585 | // Marshaling functions attached to RPC_VFS_INODE_DESTROY |
---|
| 586 | ///////////////////////////////////////////////////////////////////////////////////////// |
---|
| 587 | |
---|
| 588 | ///////////////////////////////////////////////////////////// |
---|
| 589 | void rpc_vfs_inode_destroy_client( cxy_t cxy, |
---|
| 590 | struct vfs_inode_s * inode ) |
---|
| 591 | { |
---|
| 592 | // RPC must be remote |
---|
| 593 | if( cxy == local_cxy ) |
---|
| 594 | { |
---|
| 595 | printk("PANIC in %s : target cluster is not remote\n", __FUNCTION__ ); |
---|
| 596 | hal_core_sleep(); |
---|
| 597 | } |
---|
| 598 | |
---|
| 599 | // initialise RPC descriptor header |
---|
| 600 | rpc_desc_t rpc; |
---|
| 601 | rpc.index = RPC_VFS_INODE_DESTROY; |
---|
| 602 | rpc.response = 1; |
---|
| 603 | |
---|
| 604 | // set input arguments in RPC descriptor |
---|
| 605 | rpc.args[0] = (uint64_t)(intptr_t)inode; |
---|
| 606 | |
---|
| 607 | // register RPC request in remote RPC fifo (blocking function) |
---|
| 608 | rpc_send_sync( cxy , &rpc ); |
---|
| 609 | } |
---|
| 610 | |
---|
| 611 | ////////////////////////////////////////////// |
---|
| 612 | void rpc_vfs_inode_destroy_server( xptr_t xp ) |
---|
| 613 | { |
---|
| 614 | vfs_inode_t * inode; |
---|
| 615 | |
---|
| 616 | // get client cluster identifier and pointer on RPC descriptor |
---|
| 617 | cxy_t client_cxy = (cxy_t)GET_CXY( xp ); |
---|
| 618 | rpc_desc_t * desc = (rpc_desc_t *)GET_PTR( xp ); |
---|
| 619 | |
---|
| 620 | // get arguments "inode" from client RPC descriptor |
---|
| 621 | inode = (vfs_inode_t *)(intptr_t)hal_remote_lwd( XPTR( client_cxy , &desc->args[0] ) ); |
---|
| 622 | |
---|
| 623 | // call local kernel function |
---|
| 624 | vfs_inode_destroy( inode ); |
---|
| 625 | } |
---|
| 626 | |
---|
| 627 | ///////////////////////////////////////////////////////////////////////////////////////// |
---|
| 628 | // Marshaling functions attached to RPC_VFS_DENTRY_CREATE |
---|
| 629 | ///////////////////////////////////////////////////////////////////////////////////////// |
---|
| 630 | |
---|
| 631 | ////////////////////////////////////////////////////////////// |
---|
| 632 | void rpc_vfs_dentry_create_client( cxy_t cxy, |
---|
| 633 | uint32_t type, // in |
---|
| 634 | char * name, // in |
---|
| 635 | struct vfs_inode_s * parent, // in |
---|
| 636 | xptr_t * dentry_xp, // out |
---|
| 637 | error_t * error ) // out |
---|
| 638 | { |
---|
| 639 | // RPC must be remote |
---|
| 640 | if( cxy == local_cxy ) |
---|
| 641 | { |
---|
| 642 | printk("PANIC in %s : target cluster is not remote\n", __FUNCTION__ ); |
---|
| 643 | hal_core_sleep(); |
---|
| 644 | } |
---|
| 645 | |
---|
| 646 | // initialise RPC descriptor header |
---|
| 647 | rpc_desc_t rpc; |
---|
| 648 | rpc.index = RPC_VFS_DENTRY_CREATE; |
---|
| 649 | rpc.response = 1; |
---|
| 650 | |
---|
| 651 | // set input arguments in RPC descriptor |
---|
| 652 | rpc.args[0] = (uint64_t)type; |
---|
| 653 | rpc.args[1] = (uint64_t)(intptr_t)name; |
---|
| 654 | rpc.args[2] = (uint64_t)strlen( name ); |
---|
| 655 | rpc.args[3] = (uint64_t)(intptr_t)parent; |
---|
| 656 | |
---|
| 657 | // register RPC request in remote RPC fifo (blocking function) |
---|
| 658 | rpc_send_sync( cxy , &rpc ); |
---|
| 659 | |
---|
| 660 | // get output values from RPC descriptor |
---|
| 661 | *dentry_xp = (xptr_t)rpc.args[4]; |
---|
| 662 | *error = (error_t)rpc.args[5]; |
---|
| 663 | } |
---|
| 664 | |
---|
| 665 | ////////////////////////////////////////////// |
---|
| 666 | void rpc_vfs_dentry_create_server( xptr_t xp ) |
---|
| 667 | { |
---|
| 668 | uint32_t type; |
---|
| 669 | char * name; |
---|
| 670 | vfs_inode_t * parent; |
---|
| 671 | xptr_t dentry_xp; |
---|
| 672 | char name_copy[CONFIG_VFS_MAX_NAME_LENGTH]; |
---|
| 673 | uint32_t length; |
---|
| 674 | error_t error; |
---|
| 675 | |
---|
| 676 | // get client cluster identifier and pointer on RPC descriptor |
---|
| 677 | cxy_t client_cxy = (cxy_t)GET_CXY( xp ); |
---|
| 678 | rpc_desc_t * desc = (rpc_desc_t *)GET_PTR( xp ); |
---|
| 679 | |
---|
| 680 | // get argument "name" & "length" from client RPC descriptor and makes a local copy |
---|
| 681 | name = (char *)(intptr_t)hal_remote_lwd( XPTR( client_cxy , &desc->args[1] ) ); |
---|
| 682 | length = (uint32_t) hal_remote_lwd( XPTR( client_cxy , &desc->args[2] ) ); |
---|
| 683 | hal_remote_memcpy( XPTR( local_cxy , name_copy ), |
---|
| 684 | XPTR( client_cxy , name ), |
---|
| 685 | length + 1 ); // +1 for the NUL char |
---|
| 686 | |
---|
| 687 | // get arguments "type" and "parent" from client RPC descriptor |
---|
| 688 | type = (uint32_t) hal_remote_lwd( XPTR( client_cxy , &desc->args[0] ) ); |
---|
| 689 | parent = (vfs_inode_t *)(intptr_t)hal_remote_lwd( XPTR( client_cxy , &desc->args[3] ) ); |
---|
| 690 | |
---|
| 691 | // call local kernel function |
---|
| 692 | error = vfs_dentry_create( type, |
---|
| 693 | name_copy, |
---|
| 694 | parent, |
---|
| 695 | &dentry_xp ); |
---|
| 696 | |
---|
| 697 | // set output arguments |
---|
| 698 | hal_remote_swd( XPTR( client_cxy , &desc->args[4] ) , (uint64_t)dentry_xp ); |
---|
| 699 | hal_remote_swd( XPTR( client_cxy , &desc->args[5] ) , (uint64_t)error ); |
---|
| 700 | } |
---|
| 701 | |
---|
| 702 | ///////////////////////////////////////////////////////////////////////////////////////// |
---|
| 703 | // Marshaling functions attached to RPC_VFS_DENTRY_DESTROY |
---|
| 704 | ///////////////////////////////////////////////////////////////////////////////////////// |
---|
| 705 | |
---|
| 706 | /////////////////////////////////////////////////////// |
---|
| 707 | void rpc_vfs_dentry_destroy_client( cxy_t cxy, |
---|
| 708 | vfs_dentry_t * dentry ) |
---|
| 709 | { |
---|
| 710 | // RPC must be remote |
---|
| 711 | if( cxy == local_cxy ) |
---|
| 712 | { |
---|
| 713 | printk("PANIC in %s : target cluster is not remote\n", __FUNCTION__ ); |
---|
| 714 | hal_core_sleep(); |
---|
| 715 | } |
---|
| 716 | |
---|
| 717 | // initialise RPC descriptor header |
---|
| 718 | rpc_desc_t rpc; |
---|
| 719 | rpc.index = RPC_VFS_DENTRY_DESTROY; |
---|
| 720 | rpc.response = 1; |
---|
| 721 | |
---|
| 722 | // set input arguments in RPC descriptor |
---|
| 723 | rpc.args[0] = (uint64_t)(intptr_t)dentry; |
---|
| 724 | |
---|
| 725 | // register RPC request in remote RPC fifo (blocking function) |
---|
| 726 | rpc_send_sync( cxy , &rpc ); |
---|
| 727 | } |
---|
| 728 | |
---|
| 729 | /////////////////////////////////////////////// |
---|
| 730 | void rpc_vfs_dentry_destroy_server( xptr_t xp ) |
---|
| 731 | { |
---|
| 732 | vfs_dentry_t * dentry; |
---|
| 733 | |
---|
| 734 | // get client cluster identifier and pointer on RPC descriptor |
---|
| 735 | cxy_t client_cxy = (cxy_t)GET_CXY( xp ); |
---|
| 736 | rpc_desc_t * desc = (rpc_desc_t *)GET_PTR( xp ); |
---|
| 737 | |
---|
| 738 | // get arguments "dentry" from client RPC descriptor |
---|
| 739 | dentry = (vfs_dentry_t *)(intptr_t)hal_remote_lwd( XPTR( client_cxy , &desc->args[0] ) ); |
---|
| 740 | |
---|
| 741 | // call local kernel function |
---|
| 742 | vfs_dentry_destroy( dentry ); |
---|
| 743 | } |
---|
| 744 | |
---|
| 745 | |
---|
| 746 | ///////////////////////////////////////////////////////////////////////////////////////// |
---|
| 747 | // Marshaling functions attached to RPC_VMM_GET_VSEG |
---|
| 748 | ///////////////////////////////////////////////////////////////////////////////////////// |
---|
| 749 | |
---|
| 750 | ////////////////////////////////////////////////// |
---|
| 751 | void rpc_vmm_get_ref_vseg_client( cxy_t cxy, |
---|
| 752 | process_t * process, // in |
---|
| 753 | intptr_t vaddr, // in |
---|
| 754 | xptr_t * vseg_xp ) // out |
---|
| 755 | { |
---|
| 756 | // RPC must be remote |
---|
| 757 | if( cxy == local_cxy ) |
---|
| 758 | { |
---|
| 759 | printk("PANIC in %s : target is not remote\n", __FUNCTION__ ); |
---|
| 760 | hal_core_sleep(); |
---|
| 761 | } |
---|
| 762 | |
---|
| 763 | // initialise RPC descriptor header |
---|
| 764 | rpc_desc_t rpc; |
---|
| 765 | rpc.index = RPC_VMM_GET_REF_VSEG; |
---|
| 766 | rpc.response = 1; |
---|
| 767 | |
---|
| 768 | // set input arguments in RPC descriptor |
---|
| 769 | rpc.args[0] = (uint64_t)(intptr_t)process; |
---|
| 770 | rpc.args[1] = (uint64_t)vaddr; |
---|
| 771 | |
---|
| 772 | // register RPC request in remote RPC fifo (blocking function) |
---|
| 773 | rpc_send_sync( cxy , &rpc ); |
---|
| 774 | |
---|
| 775 | // get output argument from rpc descriptor |
---|
| 776 | *vseg_xp = rpc.args[2]; |
---|
| 777 | } |
---|
| 778 | |
---|
| 779 | ///////////////////////////////////////////// |
---|
| 780 | void rpc_vmm_get_ref_vseg_server( xptr_t xp ) |
---|
| 781 | { |
---|
| 782 | process_t * process; |
---|
| 783 | intptr_t vaddr; |
---|
| 784 | vseg_t * vseg_ptr; |
---|
| 785 | xptr_t vseg_xp; |
---|
| 786 | |
---|
| 787 | // get client cluster identifier and pointer on RPC descriptor |
---|
| 788 | cxy_t client_cxy = (cxy_t)GET_CXY( xp ); |
---|
| 789 | rpc_desc_t * desc = (rpc_desc_t *)GET_PTR( xp ); |
---|
| 790 | |
---|
| 791 | // get input argument from client RPC descriptor |
---|
| 792 | process = (process_t *)(intptr_t)hal_remote_lwd( XPTR( client_cxy , &desc->args[0] ) ); |
---|
| 793 | vaddr = (intptr_t)hal_remote_lwd( XPTR( client_cxy , &desc->args[1] ) ); |
---|
| 794 | |
---|
| 795 | // call local kernel function |
---|
| 796 | vseg_ptr = vmm_get_vseg( process , vaddr ); |
---|
| 797 | |
---|
| 798 | // set output argument to client RPC descriptor |
---|
| 799 | vseg_xp = XPTR( local_cxy , vseg_ptr ); |
---|
| 800 | hal_remote_swd( XPTR( client_cxy , &desc->args[2] ) , (uint64_t)vseg_xp ); |
---|
| 801 | } |
---|
| 802 | |
---|
| 803 | |
---|
| 804 | ///////////////////////////////////////////////////////////////////////////////////////// |
---|
| 805 | // Marshaling functions attached to RPC_VMM_GET_PTE |
---|
| 806 | ///////////////////////////////////////////////////////////////////////////////////////// |
---|
| 807 | |
---|
| 808 | //////////////////////////////////////////// |
---|
| 809 | void rpc_vmm_get_pte_client( cxy_t cxy, |
---|
| 810 | process_t * process, // in |
---|
| 811 | vpn_t vpn, // in |
---|
| 812 | uint32_t * attr, // out |
---|
| 813 | ppn_t * ppn, // out |
---|
| 814 | error_t * error ) // out |
---|
| 815 | { |
---|
| 816 | // RPC must be remote |
---|
| 817 | if( cxy == local_cxy ) |
---|
| 818 | { |
---|
| 819 | printk("PANIC in %s : target is not remote\n", __FUNCTION__ ); |
---|
| 820 | hal_core_sleep(); |
---|
| 821 | } |
---|
| 822 | |
---|
| 823 | // initialise RPC descriptor header |
---|
| 824 | rpc_desc_t rpc; |
---|
| 825 | rpc.index = RPC_VMM_GET_PTE; |
---|
| 826 | rpc.response = 1; |
---|
| 827 | |
---|
| 828 | // set input arguments in RPC descriptor |
---|
| 829 | rpc.args[0] = (uint64_t)(intptr_t)process; |
---|
| 830 | rpc.args[1] = (uint64_t)vpn; |
---|
| 831 | |
---|
| 832 | // register RPC request in remote RPC fifo (blocking function) |
---|
| 833 | rpc_send_sync( cxy , &rpc ); |
---|
| 834 | |
---|
| 835 | // get output argument from rpc descriptor |
---|
| 836 | *attr = (uint32_t)rpc.args[2]; |
---|
| 837 | *ppn = (ppn_t)rpc.args[3]; |
---|
| 838 | *error = (error_t)rpc.args[4]; |
---|
| 839 | } |
---|
| 840 | |
---|
| 841 | //////////////////////////////////////// |
---|
| 842 | void rpc_vmm_get_pte_server( xptr_t xp ) |
---|
| 843 | { |
---|
| 844 | process_t * process; |
---|
| 845 | vpn_t vpn; |
---|
| 846 | uint32_t attr; |
---|
| 847 | ppn_t ppn; |
---|
| 848 | error_t error; |
---|
| 849 | |
---|
| 850 | // get client cluster identifier and pointer on RPC descriptor |
---|
| 851 | cxy_t client_cxy = (cxy_t)GET_CXY( xp ); |
---|
| 852 | rpc_desc_t * desc = (rpc_desc_t *)GET_PTR( xp ); |
---|
| 853 | |
---|
| 854 | // get input argument "process" & "vpn" from client RPC descriptor |
---|
| 855 | process = (process_t *)(intptr_t)hal_remote_lwd( XPTR( client_cxy , &desc->args[0] ) ); |
---|
| 856 | vpn = (vpn_t) hal_remote_lwd( XPTR( client_cxy , &desc->args[1] ) ); |
---|
| 857 | |
---|
| 858 | // call local kernel function |
---|
| 859 | error = vmm_get_pte( process , vpn , &attr , &ppn ); |
---|
| 860 | |
---|
| 861 | // set output argument "attr" & "ppn" to client RPC descriptor |
---|
| 862 | hal_remote_swd( XPTR( client_cxy , &desc->args[2] ) , (uint64_t)attr ); |
---|
| 863 | hal_remote_swd( XPTR( client_cxy , &desc->args[3] ) , (uint64_t)ppn ); |
---|
| 864 | hal_remote_swd( XPTR( client_cxy , &desc->args[4] ) , (uint64_t)error ); |
---|
| 865 | } |
---|
| 866 | |
---|
| 867 | ///////////////////////////////////////////////////////////////////////////////////////// |
---|
| 868 | // Marshaling functions attached to RPC_SEMAPHORE_ALLOC |
---|
| 869 | ///////////////////////////////////////////////////////////////////////////////////////// |
---|
| 870 | |
---|
| 871 | ////////////////////////////////////////////// |
---|
| 872 | void rpc_semaphore_alloc_client( cxy_t cxy, |
---|
| 873 | xptr_t * sem_xp ) // out |
---|
| 874 | { |
---|
| 875 | // RPC must be remote |
---|
| 876 | if( cxy == local_cxy ) |
---|
| 877 | { |
---|
| 878 | printk("PANIC in %s : target is not remote\n", __FUNCTION__ ); |
---|
| 879 | hal_core_sleep(); |
---|
| 880 | } |
---|
| 881 | |
---|
| 882 | // initialise RPC descriptor header |
---|
| 883 | rpc_desc_t rpc; |
---|
| 884 | rpc.index = RPC_THREAD_USER_CREATE; |
---|
| 885 | rpc.response = 1; |
---|
| 886 | |
---|
| 887 | // register RPC request in remote RPC fifo |
---|
| 888 | rpc_send_sync( cxy , &rpc ); |
---|
| 889 | |
---|
| 890 | // get output arguments from RPC descriptor |
---|
| 891 | *sem_xp = (xptr_t)rpc.args[0]; |
---|
| 892 | } |
---|
| 893 | |
---|
| 894 | //////////////////////////////////////////// |
---|
| 895 | void rpc_semaphore_alloc_server( xptr_t xp ) |
---|
| 896 | { |
---|
| 897 | // get client cluster identifier and pointer on RPC descriptor |
---|
| 898 | cxy_t client_cxy = (cxy_t)GET_CXY( xp ); |
---|
| 899 | rpc_desc_t * desc = (rpc_desc_t *)GET_PTR( xp ); |
---|
| 900 | |
---|
| 901 | // allocates memory for semaphore |
---|
| 902 | kmem_req_t req; |
---|
| 903 | req.type = KMEM_SEM; |
---|
| 904 | req.flags = AF_ZERO; |
---|
| 905 | remote_sem_t * sem_ptr = kmem_alloc( &req ); |
---|
| 906 | |
---|
| 907 | // set output argument |
---|
| 908 | xptr_t sem_xp = XPTR( local_cxy , sem_ptr ); |
---|
| 909 | hal_remote_swd( XPTR( client_cxy , &desc->args[0] ) , (uint64_t)sem_xp ); |
---|
| 910 | } |
---|
| 911 | |
---|
| 912 | ///////////////////////////////////////////////////////////////////////////////////////// |
---|
| 913 | // Marshaling functions attached to RPC_SEMAPHORE_FREE |
---|
| 914 | ///////////////////////////////////////////////////////////////////////////////////////// |
---|
| 915 | |
---|
| 916 | /////////////////////////////////////////////////// |
---|
| 917 | void rpc_semaphore_free_client( cxy_t cxy, |
---|
| 918 | remote_sem_t * sem ) // in |
---|
| 919 | { |
---|
| 920 | // RPC must be remote |
---|
| 921 | if( cxy == local_cxy ) |
---|
| 922 | { |
---|
| 923 | printk("PANIC in %s : target is not remote\n", __FUNCTION__ ); |
---|
| 924 | hal_core_sleep(); |
---|
| 925 | } |
---|
| 926 | |
---|
| 927 | // initialise RPC descriptor header |
---|
| 928 | rpc_desc_t rpc; |
---|
| 929 | rpc.index = RPC_THREAD_USER_CREATE; |
---|
| 930 | rpc.response = 1; |
---|
| 931 | |
---|
| 932 | // set input arguments in RPC descriptor |
---|
| 933 | rpc.args[0] = (uint64_t)(intptr_t)sem; |
---|
| 934 | |
---|
| 935 | // register RPC request in remote RPC fifo |
---|
| 936 | rpc_send_sync( cxy , &rpc ); |
---|
| 937 | } |
---|
| 938 | |
---|
| 939 | /////////////////////////////////////////// |
---|
| 940 | void rpc_semaphore_free_server( xptr_t xp ) |
---|
| 941 | { |
---|
| 942 | // get client cluster identifier and pointer on RPC descriptor |
---|
| 943 | cxy_t client_cxy = (cxy_t)GET_CXY( xp ); |
---|
| 944 | rpc_desc_t * desc = (rpc_desc_t *)GET_PTR( xp ); |
---|
| 945 | |
---|
| 946 | // get input argument "sem_ptr" from client RPC descriptor |
---|
| 947 | void * sem = (void *)(intptr_t)hal_remote_lwd( XPTR( client_cxy , &desc->args[0] ) ); |
---|
| 948 | |
---|
| 949 | // releases memory |
---|
| 950 | kmem_req_t req; |
---|
| 951 | req.type = KMEM_SEM; |
---|
| 952 | req.ptr = sem; |
---|
| 953 | kmem_free(&req); |
---|
| 954 | } |
---|
| 955 | |
---|
| 956 | ///////////////////////////////////////////////////////////////////////////////////////// |
---|
| 957 | // Marshaling functions attached to RPC_MAPPER_MOVE |
---|
| 958 | ///////////////////////////////////////////////////////////////////////////////////////// |
---|
| 959 | |
---|
| 960 | ////////////////////////////////////////////// |
---|
| 961 | void rpc_mapper_move_client( cxy_t cxy, |
---|
| 962 | mapper_t * mapper, // in |
---|
| 963 | bool_t read, // in |
---|
| 964 | uint32_t nb_frags, // in |
---|
| 965 | fragment_t * frags, // in |
---|
| 966 | error_t * error ) // out |
---|
| 967 | { |
---|
| 968 | // RPC must be remote |
---|
| 969 | if( cxy == local_cxy ) |
---|
| 970 | { |
---|
| 971 | printk("PANIC in %s : target is not remote\n", __FUNCTION__ ); |
---|
| 972 | hal_core_sleep(); |
---|
| 973 | } |
---|
| 974 | |
---|
| 975 | // initialise RPC descriptor header |
---|
| 976 | rpc_desc_t rpc; |
---|
| 977 | rpc.index = RPC_MAPPER_MOVE; |
---|
| 978 | rpc.response = 1; |
---|
| 979 | |
---|
| 980 | // set input arguments in RPC descriptor |
---|
| 981 | rpc.args[0] = (uint64_t)(intptr_t)mapper; |
---|
| 982 | rpc.args[1] = (uint64_t)read; |
---|
| 983 | rpc.args[2] = (uint64_t)nb_frags; |
---|
| 984 | rpc.args[3] = (uint64_t)(intptr_t)frags; |
---|
| 985 | |
---|
| 986 | // register RPC request in remote RPC fifo |
---|
| 987 | rpc_send_sync( cxy , &rpc ); |
---|
| 988 | |
---|
| 989 | // get output argument from rpc descriptor |
---|
| 990 | *error = (error_t)rpc.args[4]; |
---|
| 991 | } |
---|
| 992 | |
---|
| 993 | //////////////////////////////////////// |
---|
| 994 | void rpc_mapper_move_server( xptr_t xp ) |
---|
| 995 | { |
---|
| 996 | mapper_t * mapper; |
---|
| 997 | bool_t read; |
---|
| 998 | uint32_t nb; |
---|
| 999 | void * frags; |
---|
| 1000 | error_t error; |
---|
| 1001 | |
---|
| 1002 | // get client cluster identifier and pointer on RPC descriptor |
---|
| 1003 | cxy_t client_cxy = (cxy_t)GET_CXY( xp ); |
---|
| 1004 | rpc_desc_t * desc = (rpc_desc_t *)GET_PTR( xp ); |
---|
| 1005 | |
---|
| 1006 | // get input arguments |
---|
| 1007 | mapper = (mapper_t*)(intptr_t)hal_remote_lpt( XPTR( client_cxy , &desc->args[0] ) ); |
---|
| 1008 | read = (bool_t) hal_remote_lw ( XPTR( client_cxy , &desc->args[1] ) ); |
---|
| 1009 | nb = (uint32_t) hal_remote_lw ( XPTR( client_cxy , &desc->args[2] ) ); |
---|
| 1010 | frags = (void*)(intptr_t) hal_remote_lpt( XPTR( client_cxy , &desc->args[3] ) ); |
---|
| 1011 | |
---|
| 1012 | // call the mapper_move_fragments() function |
---|
| 1013 | error = mapper_move_fragments( mapper , read , nb , XPTR( client_cxy , frags ) ); |
---|
| 1014 | |
---|
| 1015 | // set output argument |
---|
| 1016 | hal_remote_swd( XPTR( client_cxy , &desc->args[4] ) , (uint64_t)error ); |
---|
| 1017 | } |
---|
| 1018 | |
---|
| 1019 | ///////////////////////////////////////////////////////////////////////////////////////// |
---|
| 1020 | // Marshaling functions attached to RPC_FATFS_GET_CLUSTER |
---|
| 1021 | ///////////////////////////////////////////////////////////////////////////////////////// |
---|
| 1022 | |
---|
| 1023 | ////////////////////////////////////////////////// |
---|
| 1024 | void rpc_fatfs_get_cluster_client( cxy_t cxy, |
---|
| 1025 | mapper_t * mapper, // in |
---|
| 1026 | uint32_t first, // in |
---|
| 1027 | uint32_t page, // in |
---|
| 1028 | uint32_t * cluster, // out |
---|
| 1029 | error_t * error ) // out |
---|
| 1030 | { |
---|
| 1031 | // RPC must be remote |
---|
| 1032 | if( cxy == local_cxy ) |
---|
| 1033 | { |
---|
| 1034 | printk("PANIC in %s : target is not remote\n", __FUNCTION__ ); |
---|
| 1035 | hal_core_sleep(); |
---|
| 1036 | } |
---|
| 1037 | |
---|
| 1038 | // initialise RPC descriptor header |
---|
| 1039 | rpc_desc_t rpc; |
---|
| 1040 | rpc.index = RPC_FATFS_GET_CLUSTER; |
---|
| 1041 | rpc.response = 1; |
---|
| 1042 | |
---|
| 1043 | // set input arguments in RPC descriptor |
---|
| 1044 | rpc.args[0] = (uint64_t)(intptr_t)mapper; |
---|
| 1045 | rpc.args[1] = (uint64_t)first; |
---|
| 1046 | rpc.args[2] = (uint64_t)page; |
---|
| 1047 | |
---|
| 1048 | // register RPC request in remote RPC fifo |
---|
| 1049 | rpc_send_sync( cxy , &rpc ); |
---|
| 1050 | |
---|
| 1051 | // get output argument from rpc descriptor |
---|
| 1052 | *cluster = (uint32_t)rpc.args[3]; |
---|
| 1053 | *error = (error_t)rpc.args[4]; |
---|
| 1054 | } |
---|
| 1055 | |
---|
| 1056 | ////////////////////////////////////////////// |
---|
| 1057 | void rpc_fatfs_get_cluster_server( xptr_t xp ) |
---|
| 1058 | { |
---|
| 1059 | mapper_t * mapper; |
---|
| 1060 | uint32_t first; |
---|
| 1061 | uint32_t page; |
---|
| 1062 | uint32_t cluster; |
---|
| 1063 | error_t error; |
---|
| 1064 | |
---|
| 1065 | // get client cluster identifier and pointer on RPC descriptor |
---|
| 1066 | cxy_t client_cxy = (cxy_t)GET_CXY( xp ); |
---|
| 1067 | rpc_desc_t * desc = (rpc_desc_t *)GET_PTR( xp ); |
---|
| 1068 | |
---|
| 1069 | // get input arguments |
---|
| 1070 | mapper = (mapper_t*)(intptr_t)hal_remote_lpt( XPTR( client_cxy , &desc->args[0] ) ); |
---|
| 1071 | first = (uint32_t) hal_remote_lw ( XPTR( client_cxy , &desc->args[1] ) ); |
---|
| 1072 | page = (uint32_t) hal_remote_lw ( XPTR( client_cxy , &desc->args[2] ) ); |
---|
| 1073 | |
---|
| 1074 | // call the kernel function |
---|
| 1075 | error = fatfs_get_cluster( mapper , first , page , &cluster ); |
---|
| 1076 | |
---|
| 1077 | // set output argument |
---|
| 1078 | hal_remote_swd( XPTR( client_cxy , &desc->args[3] ) , (uint64_t)cluster ); |
---|
| 1079 | hal_remote_swd( XPTR( client_cxy , &desc->args[4] ) , (uint64_t)error ); |
---|
| 1080 | } |
---|
| 1081 | |
---|
| 1082 | /***************************************************************************************/ |
---|
| 1083 | /************ Generic functions supporting RPCs : client side **************************/ |
---|
| 1084 | /***************************************************************************************/ |
---|
| 1085 | |
---|
| 1086 | //////////////////////////////////////////// |
---|
| 1087 | void rpc_send_sync( cxy_t server_cxy, |
---|
| 1088 | rpc_desc_t * rpc ) |
---|
| 1089 | { |
---|
| 1090 | thread_t * this = CURRENT_THREAD; |
---|
| 1091 | uint32_t cores; |
---|
| 1092 | error_t error; |
---|
| 1093 | bool_t first; |
---|
| 1094 | reg_t sr_save; |
---|
| 1095 | |
---|
[5] | 1096 | printk("\n@@@ coucou 0\n"); |
---|
| 1097 | |
---|
[1] | 1098 | // get client CPU and cluster coordinates |
---|
| 1099 | cxy_t client_cxy = local_cxy; |
---|
| 1100 | lid_t client_lid = CURRENT_CORE->lid; |
---|
| 1101 | |
---|
| 1102 | // allocate and initialise an extended pointer on the RPC descriptor |
---|
| 1103 | xptr_t xp = XPTR( client_cxy , rpc ); |
---|
| 1104 | |
---|
| 1105 | // get local pointer on rpc_fifo in remote cluster with the |
---|
| 1106 | // assumption that addresses are identical in all clusters |
---|
| 1107 | rpc_fifo_t * rf = &LOCAL_CLUSTER->rpc_fifo; |
---|
| 1108 | |
---|
| 1109 | // try to post an item in remote fifo |
---|
| 1110 | // deschedule and retry if remote fifo full |
---|
| 1111 | do |
---|
| 1112 | { |
---|
| 1113 | error = remote_fifo_put_item( XPTR( server_cxy , &rf->fifo ), |
---|
| 1114 | (void *)&xp, |
---|
| 1115 | sizeof(xptr_t), |
---|
| 1116 | &first ); |
---|
| 1117 | |
---|
| 1118 | if ( error ) |
---|
| 1119 | { |
---|
| 1120 | printk("\n[WARNING] %s : core %d in cluster %x cannot post RPC to cluster %x\n", |
---|
| 1121 | __FUNCTION__ , client_lid , client_cxy , server_cxy ); |
---|
| 1122 | if( thread_can_yield() ) sched_yield(); |
---|
| 1123 | } |
---|
| 1124 | } |
---|
| 1125 | while( error ); |
---|
| 1126 | |
---|
[5] | 1127 | printk("\n@@@ coucou 1\n"); |
---|
| 1128 | |
---|
[1] | 1129 | rpc_dmsg("\n[INFO] %s on core %d in cluster %x sent RPC %p to cluster %x\n", |
---|
| 1130 | __FUNCTION__ , client_lid , client_cxy , rpc , server_cxy ); |
---|
| 1131 | |
---|
| 1132 | // send IPI if this is the first RPC in remote FIFO |
---|
| 1133 | // and no CPU is in kernel mode in server cluster. |
---|
| 1134 | // the selected CPU in server has the same lid as the client CPU. |
---|
| 1135 | if( first ) |
---|
| 1136 | { |
---|
| 1137 | // get number of cores in kernel mode in server cluster |
---|
| 1138 | cores = hal_remote_lw( XPTR( server_cxy , &LOCAL_CLUSTER->cores_in_kernel ) ); |
---|
| 1139 | |
---|
| 1140 | if( cores == 0 ) // no core in kernel mode in server |
---|
| 1141 | { |
---|
| 1142 | dev_icu_send_ipi( server_cxy , client_lid ); |
---|
| 1143 | |
---|
| 1144 | rpc_dmsg("\n[INFO] %s : core %d in cluster %x send IPI to core %d in cluster %x\n", |
---|
| 1145 | __FUNCTION__, client_lid , client_cxy , client_lid , server_cxy ); |
---|
| 1146 | } |
---|
| 1147 | } |
---|
| 1148 | |
---|
[5] | 1149 | printk("\n@@@ coucou 2\n"); |
---|
| 1150 | |
---|
[1] | 1151 | // activate preemption to allow incoming RPC and avoid deadlock |
---|
| 1152 | if( this->type == THREAD_RPC ) hal_enable_irq( &sr_save ); |
---|
| 1153 | |
---|
| 1154 | // the sending thread poll the response slot until RPC completed |
---|
| 1155 | while( 1 ) |
---|
| 1156 | { |
---|
| 1157 | if( rpc->response == 0 ) break; |
---|
| 1158 | } |
---|
| 1159 | |
---|
[5] | 1160 | printk("\n@@@ coucou 3\n"); |
---|
| 1161 | |
---|
[1] | 1162 | // restore preemption |
---|
| 1163 | if( this->type == THREAD_RPC ) hal_restore_irq( sr_save ); |
---|
| 1164 | |
---|
| 1165 | } // end rpc_send_sync() |
---|
| 1166 | |
---|
| 1167 | |
---|
| 1168 | |
---|
| 1169 | /***************************************************************************************/ |
---|
| 1170 | /************ Generic functions supporting RPCs : server side **************************/ |
---|
| 1171 | /***************************************************************************************/ |
---|
| 1172 | |
---|
| 1173 | /////////////////////////////////////////// |
---|
| 1174 | void rpc_fifo_init( rpc_fifo_t * rpc_fifo ) |
---|
| 1175 | { |
---|
| 1176 | rpc_fifo->count = 0; |
---|
| 1177 | rpc_fifo->owner = 0; |
---|
| 1178 | local_fifo_init( &rpc_fifo->fifo ); |
---|
| 1179 | } |
---|
| 1180 | |
---|
| 1181 | //////////////////////////////////////////////// |
---|
| 1182 | error_t rpc_execute_all( rpc_fifo_t * rpc_fifo ) |
---|
| 1183 | { |
---|
| 1184 | xptr_t xp; // extended pointer on RPC descriptor |
---|
| 1185 | uint32_t count; // handled RPC request counter |
---|
| 1186 | thread_t * this; // pointer on this RPC thread |
---|
| 1187 | core_t * core; // pointer on core running this thread |
---|
| 1188 | rpc_desc_t * desc; // pointer on RPC descriptor |
---|
| 1189 | uint32_t index; // RPC index |
---|
| 1190 | uint32_t expected; // number of expected responses |
---|
| 1191 | cxy_t client_cxy; // client cluster identifier |
---|
| 1192 | error_t error; |
---|
| 1193 | |
---|
| 1194 | this = CURRENT_THREAD; |
---|
| 1195 | core = this->core; |
---|
| 1196 | |
---|
| 1197 | |
---|
| 1198 | // handle up to CONFIG_RPC_PENDING_MAX requests before exit |
---|
| 1199 | count = 0; |
---|
| 1200 | do |
---|
| 1201 | { |
---|
| 1202 | error = local_fifo_get_item( &rpc_fifo->fifo, |
---|
| 1203 | &xp, |
---|
| 1204 | sizeof(xptr_t) ); |
---|
| 1205 | |
---|
| 1206 | if ( error == 0 ) // One RPC request successfully extracted from RPC_FIFO |
---|
| 1207 | { |
---|
| 1208 | rpc_dmsg("\n[INFO] %s : RPC_THREAD %x on core %x in cluster %x handles RPC %d\n" |
---|
| 1209 | __FUNCTION__ , this->trdid , core->lid , local_cxy , count ); |
---|
| 1210 | |
---|
| 1211 | // get client cluster identifier and pointer on RPC descriptor |
---|
| 1212 | client_cxy = (cxy_t)GET_CXY( xp ); |
---|
| 1213 | desc = (rpc_desc_t *)GET_PTR( xp ); |
---|
| 1214 | |
---|
| 1215 | // get rpc index and expected responses from RPC descriptor |
---|
| 1216 | index = hal_remote_lw( XPTR( client_cxy , &desc->index ) ); |
---|
| 1217 | expected = hal_remote_lw( XPTR( client_cxy , &desc->response ) ); |
---|
| 1218 | |
---|
| 1219 | // call the relevant server function |
---|
| 1220 | rpc_server[index]( xp ); |
---|
| 1221 | |
---|
| 1222 | // increment handled RPC counter |
---|
| 1223 | count++; |
---|
| 1224 | |
---|
| 1225 | // notify RPC completion as required |
---|
| 1226 | if( expected == 1 ) hal_remote_sw( XPTR(client_cxy,&desc->response) , 0 ); |
---|
| 1227 | if( expected > 1 ) hal_remote_atomic_add( XPTR(client_cxy,&desc->response) , -1 ); |
---|
| 1228 | } |
---|
| 1229 | |
---|
| 1230 | // exit loop in three cases: |
---|
| 1231 | // - fifo is empty |
---|
| 1232 | // - look has been released (because descheduling) |
---|
| 1233 | // - max number of RPCs has been reached |
---|
| 1234 | if( error || |
---|
| 1235 | (rpc_fifo->owner != this->trdid) || |
---|
| 1236 | (count > CONFIG_RPC_PENDING_MAX) ) break; |
---|
| 1237 | } |
---|
| 1238 | while( 1 ) |
---|
| 1239 | |
---|
| 1240 | rpc_dmsg("\n[INFO] %s running on core %d in cluster %x exit\n" |
---|
| 1241 | __FUNCTION__ , CURRENT_CORE->lid , local_cxy ); |
---|
| 1242 | |
---|
| 1243 | // update RPC_FIFO global counter |
---|
| 1244 | rpc_fifo->count += count; |
---|
| 1245 | |
---|
| 1246 | return 0; |
---|
| 1247 | } // end rpc_execute_all() |
---|
| 1248 | |
---|
| 1249 | //////////////////////////////////////////////////// |
---|
| 1250 | error_t rpc_activate_thread( rpc_fifo_t * rpc_fifo ) |
---|
| 1251 | { |
---|
| 1252 | core_t * core; |
---|
| 1253 | thread_t * thread; |
---|
| 1254 | thread_t * this; |
---|
| 1255 | scheduler_t * sched; |
---|
| 1256 | error_t error; |
---|
| 1257 | bool_t found; |
---|
| 1258 | reg_t sr_save; |
---|
| 1259 | |
---|
| 1260 | this = CURRENT_THREAD; |
---|
| 1261 | core = this->core; |
---|
| 1262 | sched = &core->scheduler; |
---|
| 1263 | found = false; |
---|
| 1264 | |
---|
| 1265 | // calling thread must be the RPC_FIFO owner |
---|
| 1266 | if( this->trdid != rpc_fifo->owner ) |
---|
| 1267 | { |
---|
| 1268 | printk("\n[PANIC] in %s : calling thread is not RPC_FIFO owner\n", __FUNCTION__ ); |
---|
| 1269 | hal_core_sleep(); |
---|
| 1270 | } |
---|
| 1271 | |
---|
| 1272 | // makes the calling thread not preemptable |
---|
| 1273 | // during activation / creation of the RPC thread |
---|
| 1274 | hal_disable_irq( &sr_save ); |
---|
| 1275 | |
---|
| 1276 | // search a free RPC thread (must be in THREAD_BLOCKED_IDLE state) |
---|
| 1277 | list_entry_t * iter; |
---|
| 1278 | LIST_FOREACH( &sched->k_root , iter ) |
---|
| 1279 | { |
---|
| 1280 | thread = LIST_ELEMENT( iter , thread_t , sched_list ); |
---|
| 1281 | if( (thread->type == THREAD_RPC) && (thread->blocked == THREAD_BLOCKED_IDLE ) ) |
---|
| 1282 | { |
---|
| 1283 | found = true; |
---|
| 1284 | break; |
---|
| 1285 | } |
---|
| 1286 | } |
---|
| 1287 | |
---|
| 1288 | if( found ) // activate this idle RPC thread |
---|
| 1289 | { |
---|
| 1290 | thread->blocked = 0; |
---|
| 1291 | } |
---|
| 1292 | else // create a new RPC thread |
---|
| 1293 | { |
---|
| 1294 | error = thread_kernel_create( &thread, |
---|
| 1295 | THREAD_RPC, |
---|
| 1296 | &rpc_thread_func, |
---|
| 1297 | NULL, |
---|
| 1298 | core->lid ); |
---|
| 1299 | if( error ) |
---|
| 1300 | { |
---|
| 1301 | hal_restore_irq( sr_save ); |
---|
| 1302 | printk("\n[ERROR] in %s : no memory for new RPC thread in cluster %x\n", |
---|
| 1303 | __FUNCTION__ , local_cxy ); |
---|
| 1304 | return ENOMEM; |
---|
| 1305 | } |
---|
| 1306 | |
---|
| 1307 | rpc_dmsg("\n[INFO] %s creates RPC thread %x on core %x in cluster %x at cycle %d\n", |
---|
| 1308 | __FUNCTION__ , thread , core->gid , local_cxy , hal_time_stamp() ); |
---|
| 1309 | |
---|
| 1310 | // update core descriptor counter |
---|
| 1311 | core->rpc_threads++; |
---|
| 1312 | } |
---|
| 1313 | |
---|
| 1314 | // update owner in rpc_fifo |
---|
| 1315 | rpc_fifo->owner = thread->trdid; |
---|
| 1316 | |
---|
| 1317 | rpc_dmsg ("\n[INFO] %s activates RPC thread %x on core %x in cluster %x at cycle %d\n", |
---|
| 1318 | __FUNCTION__ , thread , core->gid , local_cxy , hal_time_stamp() ); |
---|
| 1319 | |
---|
| 1320 | // current thread deschedules / RPC thread start execution |
---|
| 1321 | sched_switch_to( thread ); |
---|
| 1322 | |
---|
| 1323 | // restore IRQs for the calling thread |
---|
| 1324 | hal_restore_irq( sr_save ); |
---|
| 1325 | |
---|
| 1326 | // return success |
---|
| 1327 | return 0; |
---|
| 1328 | |
---|
| 1329 | } // end rpc_activate_thread() |
---|
| 1330 | |
---|
| 1331 | ////////////////// |
---|
| 1332 | bool_t rpc_check() |
---|
| 1333 | { |
---|
| 1334 | thread_t * this = CURRENT_THREAD; |
---|
| 1335 | rpc_fifo_t * rpc_fifo = &LOCAL_CLUSTER->rpc_fifo; |
---|
| 1336 | error_t error; |
---|
| 1337 | |
---|
[5] | 1338 | // calling thread does nothing if light lock already taken or FIFO empty |
---|
[1] | 1339 | if( (rpc_fifo->owner != 0) || (local_fifo_is_empty( &rpc_fifo->fifo )) ) |
---|
| 1340 | { |
---|
| 1341 | return false; |
---|
| 1342 | } |
---|
| 1343 | |
---|
[5] | 1344 | // calling thread tries to take the light lock, |
---|
| 1345 | // and activates an RPC thread if success |
---|
[1] | 1346 | if( hal_atomic_test_set( &rpc_fifo->owner , this->trdid ) ) |
---|
| 1347 | { |
---|
| 1348 | error = rpc_activate_thread( rpc_fifo ); |
---|
| 1349 | |
---|
| 1350 | if( error ) // cannot activate an RPC_THREAD |
---|
| 1351 | { |
---|
| 1352 | rpc_fifo->owner = 0; |
---|
| 1353 | |
---|
| 1354 | printk("\n[ERROR] in %s : no memory to create a RPC thread for core %d" |
---|
| 1355 | " in cluster %x => do nothing\n", |
---|
| 1356 | __FUNCTION__ , CURRENT_CORE->lid , local_cxy ); |
---|
| 1357 | } |
---|
| 1358 | |
---|
| 1359 | return true; |
---|
| 1360 | } |
---|
| 1361 | else // light lock taken by another thread |
---|
| 1362 | { |
---|
| 1363 | return false; |
---|
| 1364 | } |
---|
[5] | 1365 | } // end rpc_check() |
---|
[1] | 1366 | |
---|
| 1367 | |
---|
| 1368 | ////////////////////// |
---|
| 1369 | void rpc_thread_func() |
---|
| 1370 | { |
---|
| 1371 | // makes the calling thread not preemptable |
---|
| 1372 | hal_disable_irq( NULL ); |
---|
| 1373 | |
---|
| 1374 | thread_t * this = CURRENT_THREAD; |
---|
| 1375 | rpc_fifo_t * rpc_fifo = &LOCAL_CLUSTER->rpc_fifo; |
---|
| 1376 | |
---|
| 1377 | rpc_dmsg("\n[INFO] RPC thread %x created on core %d in cluster %x at cycle %d\n", |
---|
| 1378 | this->trdid , this->core->lid , local_cxy , hal_time_stamp() ); |
---|
| 1379 | |
---|
| 1380 | // this infinite loop is not preemptable |
---|
| 1381 | // the RPC thread deschedule when the RPC_FIFO is empty |
---|
| 1382 | while(1) |
---|
| 1383 | { |
---|
| 1384 | // check fifo ownership (ownership should be given by rpc_activate() |
---|
| 1385 | if( this->trdid != rpc_fifo->owner ) |
---|
| 1386 | { |
---|
| 1387 | printk("\n[PANIC] in %s : RPC_THREAD %x not owner of RPC_FIFO in cluster %x\n", |
---|
| 1388 | __FUNCTION__ , this->trdid , local_cxy ); |
---|
| 1389 | hal_core_sleep(); |
---|
| 1390 | } |
---|
| 1391 | |
---|
| 1392 | // executes pending RPC(s) |
---|
| 1393 | rpc_execute_all( rpc_fifo ); |
---|
| 1394 | |
---|
| 1395 | // release rpc_fifo ownership (can be lost during RPC execution) |
---|
| 1396 | if( rpc_fifo->owner == this->trdid ) rpc_fifo->owner = 0; |
---|
| 1397 | |
---|
| 1398 | |
---|
| 1399 | // suicide if too much RPC threads for this core |
---|
| 1400 | if( this->core->rpc_threads > CONFIG_RPC_THREADS_MAX ) |
---|
| 1401 | { |
---|
| 1402 | rpc_dmsg("\n[INFO] RPC thread %x suicide on core %d in cluster %x at cycle %d\n", |
---|
| 1403 | this->trdid , this->core->lid , local_cxy , hal_time_stamp() ); |
---|
| 1404 | |
---|
| 1405 | // update core descriptor counter |
---|
| 1406 | this->core->rpc_threads--; |
---|
| 1407 | |
---|
| 1408 | // suicide |
---|
| 1409 | thread_exit(); |
---|
| 1410 | } |
---|
| 1411 | |
---|
| 1412 | // block and deschedule |
---|
| 1413 | rpc_dmsg("\n[INFO] RPC thread %x deschedule on core %d in cluster %x at cycle %d\n", |
---|
| 1414 | this->trdid , this->core->lid , local_cxy , hal_time_stamp() ); |
---|
| 1415 | |
---|
| 1416 | thread_block( this , THREAD_BLOCKED_IDLE ); |
---|
| 1417 | sched_yield(); |
---|
| 1418 | |
---|
| 1419 | rpc_dmsg("\n[INFO] RPC thread %x wake up on core %d in cluster %x at cycle %d\n", |
---|
| 1420 | this->trdid , this->core->lid , local_cxy , hal_time_stamp() ); |
---|
| 1421 | } |
---|
| 1422 | } // end rpc_thread_func() |
---|
| 1423 | |
---|