[1] | 1 | /* |
---|
| 2 | * rpc.c - RPC related operations implementation. |
---|
| 3 | * |
---|
[23] | 4 | * Author Alain Greiner (2016,2017) |
---|
[1] | 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 | |
---|
[14] | 24 | #include <kernel_config.h> |
---|
[1] | 25 | #include <hal_types.h> |
---|
| 26 | #include <hal_atomic.h> |
---|
| 27 | #include <hal_remote.h> |
---|
| 28 | #include <hal_irqmask.h> |
---|
| 29 | #include <hal_special.h> |
---|
| 30 | #include <printk.h> |
---|
| 31 | #include <remote_sem.h> |
---|
| 32 | #include <core.h> |
---|
| 33 | #include <mapper.h> |
---|
[5] | 34 | #include <chdev.h> |
---|
[1] | 35 | #include <bits.h> |
---|
| 36 | #include <thread.h> |
---|
| 37 | #include <cluster.h> |
---|
| 38 | #include <process.h> |
---|
| 39 | #include <vfs.h> |
---|
| 40 | #include <fatfs.h> |
---|
[23] | 41 | #include <signal.h> |
---|
[1] | 42 | #include <rpc.h> |
---|
| 43 | |
---|
| 44 | ///////////////////////////////////////////////////////////////////////////////////////// |
---|
| 45 | // array of function pointers (must be consistent with enum in rpc.h) |
---|
| 46 | ///////////////////////////////////////////////////////////////////////////////////////// |
---|
| 47 | |
---|
| 48 | rpc_server_t * rpc_server[RPC_MAX_INDEX] = |
---|
| 49 | { |
---|
| 50 | &rpc_pmem_get_pages_server, // 0 |
---|
| 51 | &rpc_process_pid_alloc_server, // 1 |
---|
| 52 | &rpc_process_exec_server, // 2 |
---|
| 53 | &rpc_process_kill_server, // 3 |
---|
| 54 | &rpc_thread_user_create_server, // 4 |
---|
| 55 | &rpc_thread_kernel_create_server, // 5 |
---|
[23] | 56 | &rpc_signal_rise_server, // 6 |
---|
[5] | 57 | &rpc_undefined, // 7 |
---|
[1] | 58 | &rpc_undefined, // 8 |
---|
| 59 | &rpc_undefined, // 9 |
---|
| 60 | |
---|
| 61 | &rpc_vfs_inode_create_server, // 10 |
---|
| 62 | &rpc_vfs_inode_destroy_server, // 11 |
---|
| 63 | &rpc_vfs_dentry_create_server, // 12 |
---|
| 64 | &rpc_vfs_dentry_destroy_server, // 13 |
---|
[23] | 65 | &rpc_vfs_file_create_server, // 14 |
---|
| 66 | &rpc_vfs_file_destroy_server, // 15 |
---|
[238] | 67 | &rpc_vfs_inode_load_server, // 16 |
---|
| 68 | &rpc_vfs_mapper_load_all_server, // 17 |
---|
| 69 | &rpc_fatfs_get_cluster_server, // 18 |
---|
[1] | 70 | &rpc_undefined, // 19 |
---|
| 71 | |
---|
| 72 | &rpc_vmm_get_ref_vseg_server, // 20 |
---|
| 73 | &rpc_vmm_get_pte_server, // 21 |
---|
[23] | 74 | &rpc_kcm_alloc_server, // 22 |
---|
| 75 | &rpc_kcm_free_server, // 23 |
---|
[265] | 76 | &rpc_mapper_move_buffer_server, // 24 |
---|
[313] | 77 | &rpc_mapper_get_page_server, // 25 |
---|
[1] | 78 | &rpc_undefined, // 26 |
---|
| 79 | &rpc_undefined, // 27 |
---|
| 80 | &rpc_undefined, // 28 |
---|
| 81 | &rpc_undefined, // 29 |
---|
| 82 | }; |
---|
| 83 | |
---|
| 84 | ////////////////////////////////////////////// |
---|
| 85 | void __attribute__((noinline)) rpc_undefined() |
---|
| 86 | { |
---|
[374] | 87 | panic("called in cluster %x", local_cxy ); |
---|
[1] | 88 | } |
---|
| 89 | |
---|
| 90 | ///////////////////////////////////////////////////////////////////////////////////////// |
---|
[23] | 91 | // [0] Marshaling functions attached to RPC_PMEM_GET_PAGES |
---|
[1] | 92 | ///////////////////////////////////////////////////////////////////////////////////////// |
---|
| 93 | |
---|
| 94 | /////////////////////////////////////////////// |
---|
| 95 | void rpc_pmem_get_pages_client( cxy_t cxy, |
---|
| 96 | uint32_t order, // in |
---|
[313] | 97 | page_t ** page ) // out |
---|
[1] | 98 | { |
---|
[337] | 99 | rpc_dmsg("\n[INFO] %s : enter / thread %x on core[%x,%d] / cycle %d\n", |
---|
| 100 | __FUNCTION__ , CURRENT_THREAD->trdid , local_cxy, |
---|
| 101 | CURRENT_THREAD->core->lid , hal_time_stamp() ); |
---|
[296] | 102 | |
---|
[238] | 103 | assert( (cxy != local_cxy) , __FUNCTION__ , "target cluster is not remote\n"); |
---|
[1] | 104 | |
---|
| 105 | // initialise RPC descriptor header |
---|
| 106 | rpc_desc_t rpc; |
---|
| 107 | rpc.index = RPC_PMEM_GET_PAGES; |
---|
| 108 | rpc.response = 1; |
---|
| 109 | |
---|
| 110 | // set input arguments in RPC descriptor |
---|
| 111 | rpc.args[0] = (uint64_t)order; |
---|
| 112 | |
---|
| 113 | // register RPC request in remote RPC fifo (blocking function) |
---|
| 114 | rpc_send_sync( cxy , &rpc ); |
---|
| 115 | |
---|
[313] | 116 | // get output arguments from RPC descriptor |
---|
| 117 | *page = (page_t *)(intptr_t)rpc.args[1]; |
---|
[279] | 118 | |
---|
[337] | 119 | rpc_dmsg("\n[INFO] %s : exit / thread %x on core[%x,%d] / cycle %d\n", |
---|
| 120 | __FUNCTION__ , CURRENT_THREAD->trdid , local_cxy, |
---|
| 121 | CURRENT_THREAD->core->lid , hal_time_stamp() ); |
---|
[1] | 122 | } |
---|
| 123 | |
---|
| 124 | /////////////////////////////////////////// |
---|
| 125 | void rpc_pmem_get_pages_server( xptr_t xp ) |
---|
| 126 | { |
---|
[337] | 127 | rpc_dmsg("\n[INFO] %s : enter / thread %x on core[%x,%d] / cycle %d\n", |
---|
| 128 | __FUNCTION__ , CURRENT_THREAD->trdid , local_cxy, |
---|
| 129 | CURRENT_THREAD->core->lid , hal_time_stamp() ); |
---|
[296] | 130 | |
---|
[1] | 131 | // get client cluster identifier and pointer on RPC descriptor |
---|
| 132 | cxy_t cxy = (cxy_t)GET_CXY( xp ); |
---|
| 133 | rpc_desc_t * desc = (rpc_desc_t *)GET_PTR( xp ); |
---|
| 134 | |
---|
| 135 | // get input arguments from client RPC descriptor |
---|
[313] | 136 | uint32_t order = hal_remote_lw( XPTR( cxy , &desc->args[0] ) ); |
---|
[1] | 137 | |
---|
| 138 | // call local pmem allocator |
---|
| 139 | page_t * page = ppm_alloc_pages( order ); |
---|
| 140 | |
---|
| 141 | // set output arguments into client RPC descriptor |
---|
[313] | 142 | hal_remote_swd( XPTR( cxy , &desc->args[1] ) , (uint64_t)(intptr_t)page ); |
---|
[296] | 143 | |
---|
[337] | 144 | rpc_dmsg("\n[INFO] %s : exit / thread %x on core[%x,%d] / cycle %d\n", |
---|
| 145 | __FUNCTION__ , CURRENT_THREAD->trdid , local_cxy, |
---|
| 146 | CURRENT_THREAD->core->lid , hal_time_stamp() ); |
---|
[1] | 147 | } |
---|
| 148 | |
---|
| 149 | ///////////////////////////////////////////////////////////////////////////////////////// |
---|
[23] | 150 | // [1] Marshaling functions attached to RPC_PROCESS_PID_ALLOC |
---|
[1] | 151 | ///////////////////////////////////////////////////////////////////////////////////////// |
---|
| 152 | |
---|
| 153 | ////////////////////////////////////////////////// |
---|
| 154 | void rpc_process_pid_alloc_client( cxy_t cxy, |
---|
| 155 | process_t * process, // in |
---|
| 156 | error_t * error, // out |
---|
| 157 | pid_t * pid ) // out |
---|
| 158 | { |
---|
[337] | 159 | rpc_dmsg("\n[INFO] %s : enter / thread %x on core[%x,%d] / cycle %d\n", |
---|
| 160 | __FUNCTION__ , CURRENT_THREAD->trdid , local_cxy, |
---|
| 161 | CURRENT_THREAD->core->lid , hal_time_stamp() ); |
---|
[296] | 162 | |
---|
[238] | 163 | assert( (cxy != local_cxy) , __FUNCTION__ , "target cluster is not remote\n"); |
---|
[1] | 164 | |
---|
| 165 | // initialise RPC descriptor header |
---|
| 166 | rpc_desc_t rpc; |
---|
| 167 | rpc.index = RPC_PROCESS_PID_ALLOC; |
---|
| 168 | rpc.response = 1; |
---|
| 169 | |
---|
| 170 | // set input arguments in RPC descriptor |
---|
| 171 | rpc.args[0] = (uint64_t)(intptr_t)process; |
---|
| 172 | |
---|
| 173 | // register RPC request in remote RPC fifo (blocking function) |
---|
| 174 | rpc_send_sync( cxy , &rpc ); |
---|
| 175 | |
---|
| 176 | // get output arguments RPC descriptor |
---|
| 177 | *pid = (pid_t)rpc.args[1]; |
---|
| 178 | *error = (error_t)rpc.args[2]; |
---|
[279] | 179 | |
---|
[337] | 180 | rpc_dmsg("\n[INFO] %s : exit / thread %x on core[%x,%d] / cycle %d\n", |
---|
| 181 | __FUNCTION__ , CURRENT_THREAD->trdid , local_cxy, |
---|
| 182 | CURRENT_THREAD->core->lid , hal_time_stamp() ); |
---|
[1] | 183 | } |
---|
| 184 | |
---|
| 185 | ////////////////////////////////////////////// |
---|
| 186 | void rpc_process_pid_alloc_server( xptr_t xp ) |
---|
| 187 | { |
---|
| 188 | process_t * process; // input : client process descriptor |
---|
| 189 | error_t error; // output : error status |
---|
| 190 | pid_t pid; // output : process identifier |
---|
| 191 | |
---|
[337] | 192 | rpc_dmsg("\n[INFO] %s : enter / thread %x on core[%x,%d] / cycle %d\n", |
---|
| 193 | __FUNCTION__ , CURRENT_THREAD->trdid , local_cxy, |
---|
| 194 | CURRENT_THREAD->core->lid , hal_time_stamp() ); |
---|
[296] | 195 | |
---|
[1] | 196 | // get client cluster identifier and pointer on RPC descriptor |
---|
| 197 | cxy_t client_cxy = (cxy_t)GET_CXY( xp ); |
---|
| 198 | rpc_desc_t * desc = (rpc_desc_t *)GET_PTR( xp ); |
---|
| 199 | |
---|
| 200 | // get input argument from client RPC descriptor |
---|
| 201 | process = (process_t*)(intptr_t)hal_remote_lwd( XPTR( client_cxy , &desc->args[0] ) ); |
---|
| 202 | |
---|
| 203 | // call local pid allocator |
---|
| 204 | xptr_t xp_process = XPTR( client_cxy , process ); |
---|
| 205 | error = cluster_pid_alloc( xp_process , &pid ); |
---|
| 206 | |
---|
| 207 | // set output arguments into client RPC descriptor |
---|
| 208 | hal_remote_sw( XPTR( client_cxy , &desc->args[0] ) , (uint64_t)error ); |
---|
| 209 | hal_remote_sw( XPTR( client_cxy , &desc->args[1] ) , (uint64_t)pid ); |
---|
[296] | 210 | |
---|
[337] | 211 | rpc_dmsg("\n[INFO] %s : exit / thread %x on core[%x,%d] / cycle %d\n", |
---|
| 212 | __FUNCTION__ , CURRENT_THREAD->trdid , local_cxy, |
---|
| 213 | CURRENT_THREAD->core->lid , hal_time_stamp() ); |
---|
[1] | 214 | } |
---|
| 215 | |
---|
| 216 | |
---|
| 217 | ///////////////////////////////////////////////////////////////////////////////////////// |
---|
[23] | 218 | // [2] Marshaling functions attached to RPC_PROCESS_EXEC |
---|
[1] | 219 | ///////////////////////////////////////////////////////////////////////////////////////// |
---|
| 220 | |
---|
| 221 | //////////////////////////////////////////////// |
---|
| 222 | void rpc_process_exec_client( cxy_t cxy, |
---|
| 223 | exec_info_t * info, // in |
---|
| 224 | error_t * error ) // out |
---|
| 225 | { |
---|
[337] | 226 | rpc_dmsg("\n[INFO] %s : enter / thread %x on core[%x,%d] / cycle %d\n", |
---|
| 227 | __FUNCTION__ , CURRENT_THREAD->trdid , local_cxy, |
---|
| 228 | CURRENT_THREAD->core->lid , hal_time_stamp() ); |
---|
[296] | 229 | |
---|
[238] | 230 | assert( (cxy != local_cxy) , __FUNCTION__ , "target cluster is not remote\n"); |
---|
[1] | 231 | |
---|
| 232 | // initialise RPC descriptor header |
---|
| 233 | rpc_desc_t rpc; |
---|
| 234 | rpc.index = RPC_PROCESS_EXEC; |
---|
| 235 | rpc.response = 1; |
---|
| 236 | |
---|
| 237 | // set input arguments in RPC descriptor |
---|
| 238 | rpc.args[0] = (uint64_t)(intptr_t)info; |
---|
| 239 | |
---|
| 240 | // register RPC request in remote RPC fifo (blocking function) |
---|
| 241 | rpc_send_sync( cxy , &rpc ); |
---|
| 242 | |
---|
| 243 | // get output arguments from RPC descriptor |
---|
| 244 | *error = (error_t)rpc.args[1]; |
---|
[279] | 245 | |
---|
[337] | 246 | rpc_dmsg("\n[INFO] %s : exit / thread %x on core[%x,%d] / cycle %d\n", |
---|
| 247 | __FUNCTION__ , CURRENT_THREAD->trdid , local_cxy, |
---|
| 248 | CURRENT_THREAD->core->lid , hal_time_stamp() ); |
---|
[1] | 249 | } |
---|
| 250 | |
---|
| 251 | ///////////////////////////////////////// |
---|
| 252 | void rpc_process_exec_server( xptr_t xp ) |
---|
| 253 | { |
---|
| 254 | exec_info_t * ptr; // local pointer on remote exec_info structure |
---|
| 255 | exec_info_t info; // local copy of exec_info structure |
---|
| 256 | error_t error; // local error error status |
---|
| 257 | |
---|
[337] | 258 | rpc_dmsg("\n[INFO] %s : enter / thread %x on core[%x,%d] / cycle %d\n", |
---|
| 259 | __FUNCTION__ , CURRENT_THREAD->trdid , local_cxy, |
---|
| 260 | CURRENT_THREAD->core->lid , hal_time_stamp() ); |
---|
[296] | 261 | |
---|
[1] | 262 | // get client cluster identifier and pointer on RPC descriptor |
---|
| 263 | cxy_t client_cxy = (cxy_t)GET_CXY( xp ); |
---|
| 264 | rpc_desc_t * desc = (rpc_desc_t *)GET_PTR( xp ); |
---|
| 265 | |
---|
| 266 | // get pointer on exec_info structure in client cluster from RPC descriptor |
---|
| 267 | ptr = (exec_info_t*)(intptr_t)hal_remote_lwd( XPTR( client_cxy , &desc->args[0] ) ); |
---|
| 268 | |
---|
| 269 | // copy exec_info structure from client buffer to server buffer |
---|
| 270 | hal_remote_memcpy( XPTR( client_cxy , ptr ), |
---|
| 271 | XPTR( local_cxy , &info ), |
---|
| 272 | sizeof(exec_info_t) ); |
---|
| 273 | |
---|
| 274 | // call local kernel function |
---|
| 275 | error = process_make_exec( &info ); |
---|
| 276 | |
---|
| 277 | // set output argument into client RPC descriptor |
---|
| 278 | hal_remote_swd( XPTR( client_cxy , &desc->args[1] ) , (uint64_t)error ); |
---|
[296] | 279 | |
---|
[337] | 280 | rpc_dmsg("\n[INFO] %s : exit / thread %x on core[%x,%d] / cycle %d\n", |
---|
| 281 | __FUNCTION__ , CURRENT_THREAD->trdid , local_cxy, |
---|
| 282 | CURRENT_THREAD->core->lid , hal_time_stamp() ); |
---|
[1] | 283 | } |
---|
| 284 | |
---|
| 285 | |
---|
| 286 | ///////////////////////////////////////////////////////////////////////////////////////// |
---|
[23] | 287 | // [3] Marshaling functions attached to RPC_PROCESS_KILL |
---|
[1] | 288 | ///////////////////////////////////////////////////////////////////////////////////////// |
---|
| 289 | |
---|
| 290 | /////////////////////////////////////////////////// |
---|
| 291 | void rpc_process_kill_client( process_t * process ) |
---|
| 292 | { |
---|
[337] | 293 | rpc_dmsg("\n[INFO] %s : enter / thread %x on core[%x,%d] / cycle %d\n", |
---|
| 294 | __FUNCTION__ , CURRENT_THREAD->trdid , local_cxy, |
---|
| 295 | CURRENT_THREAD->core->lid , hal_time_stamp() ); |
---|
[296] | 296 | |
---|
[1] | 297 | // only reference cluster can send this RPC |
---|
[238] | 298 | assert( (GET_CXY( process->ref_xp ) == local_cxy) , __FUNCTION__ , |
---|
| 299 | "caller must be reference process cluster\n"); |
---|
[1] | 300 | |
---|
| 301 | // get local process index in reference cluster |
---|
| 302 | lpid_t lpid = LPID_FROM_PID( process->pid ); |
---|
| 303 | |
---|
| 304 | // get local process manager pointer |
---|
| 305 | pmgr_t * pmgr = &LOCAL_CLUSTER->pmgr; |
---|
| 306 | |
---|
| 307 | // get number of copies |
---|
| 308 | uint32_t copies = pmgr->copies_nr[lpid]; |
---|
| 309 | |
---|
| 310 | // initialise RPC descriptor |
---|
| 311 | rpc_desc_t rpc; |
---|
| 312 | rpc.index = RPC_PROCESS_KILL; |
---|
| 313 | rpc.response = copies; |
---|
| 314 | rpc.args[0] = (uint64_t)process->pid; |
---|
| 315 | |
---|
| 316 | // loop on list of copies to send RPC |
---|
| 317 | xptr_t iter; |
---|
| 318 | XLIST_FOREACH( XPTR( local_cxy , &pmgr->copies_root[lpid] ) , iter ) |
---|
| 319 | { |
---|
| 320 | // get cluster_identifier for current copy |
---|
| 321 | cxy_t target_cxy = GET_CXY( iter ); |
---|
| 322 | |
---|
| 323 | // register RPC request in remote RPC fifo ... but the reference |
---|
| 324 | if( target_cxy != local_cxy ) rpc_send_sync( target_cxy , &rpc ); |
---|
| 325 | } |
---|
[279] | 326 | |
---|
[337] | 327 | rpc_dmsg("\n[INFO] %s : exit / thread %x on core[%x,%d] / cycle %d\n", |
---|
| 328 | __FUNCTION__ , CURRENT_THREAD->trdid , local_cxy, |
---|
| 329 | CURRENT_THREAD->core->lid , hal_time_stamp() ); |
---|
[1] | 330 | } |
---|
| 331 | |
---|
| 332 | ///////////////////////////////////////// |
---|
| 333 | void rpc_process_kill_server( xptr_t xp ) |
---|
| 334 | { |
---|
| 335 | pid_t pid; |
---|
| 336 | process_t * process; |
---|
| 337 | |
---|
[337] | 338 | rpc_dmsg("\n[INFO] %s : enter / thread %x on core[%x,%d] / cycle %d\n", |
---|
| 339 | __FUNCTION__ , CURRENT_THREAD->trdid , local_cxy, |
---|
| 340 | CURRENT_THREAD->core->lid , hal_time_stamp() ); |
---|
[296] | 341 | |
---|
[1] | 342 | // get client cluster identifier and pointer on RPC descriptor |
---|
| 343 | cxy_t client_cxy = (cxy_t)GET_CXY( xp ); |
---|
| 344 | rpc_desc_t * desc = (rpc_desc_t *)GET_PTR( xp ); |
---|
| 345 | |
---|
| 346 | // get pid argument from RPC descriptor |
---|
| 347 | pid = (pid_t)hal_remote_lwd( XPTR( client_cxy , &desc->args[0] ) ); |
---|
| 348 | |
---|
| 349 | // get process pointer to call local kernel function |
---|
| 350 | process = cluster_get_local_process_from_pid( pid ); |
---|
| 351 | |
---|
| 352 | if( process == NULL ) // process not found => do nothing |
---|
| 353 | { |
---|
| 354 | printk("\n[WARNING] in %s : process %x not found in cluster %x\n", |
---|
| 355 | __FUNCTION__ , pid , local_cxy ); |
---|
| 356 | } |
---|
| 357 | else // destroy process |
---|
| 358 | { |
---|
| 359 | process_kill( process ); |
---|
| 360 | } |
---|
[296] | 361 | |
---|
[337] | 362 | rpc_dmsg("\n[INFO] %s : exit / thread %x on core[%x,%d] / cycle %d\n", |
---|
| 363 | __FUNCTION__ , CURRENT_THREAD->trdid , local_cxy, |
---|
| 364 | CURRENT_THREAD->core->lid , hal_time_stamp() ); |
---|
[1] | 365 | } |
---|
| 366 | |
---|
| 367 | |
---|
| 368 | ///////////////////////////////////////////////////////////////////////////////////////// |
---|
[23] | 369 | // [4] Marshaling functions attached to RPC_THREAD_USER_CREATE |
---|
[1] | 370 | ///////////////////////////////////////////////////////////////////////////////////////// |
---|
| 371 | |
---|
| 372 | ///////////////////////////////////////////////////////// |
---|
| 373 | void rpc_thread_user_create_client( cxy_t cxy, |
---|
[23] | 374 | pid_t pid, // in |
---|
| 375 | void * start_func, // in |
---|
| 376 | void * start_arg, // in |
---|
[1] | 377 | pthread_attr_t * attr, // in |
---|
| 378 | xptr_t * thread_xp, // out |
---|
| 379 | error_t * error ) // out |
---|
| 380 | { |
---|
[337] | 381 | rpc_dmsg("\n[INFO] %s : enter / thread %x on core[%x,%d] / cycle %d\n", |
---|
| 382 | __FUNCTION__ , CURRENT_THREAD->trdid , local_cxy, |
---|
| 383 | CURRENT_THREAD->core->lid , hal_time_stamp() ); |
---|
[296] | 384 | |
---|
[238] | 385 | assert( (cxy != local_cxy) , __FUNCTION__ , "target cluster is not remote\n"); |
---|
[1] | 386 | |
---|
| 387 | // initialise RPC descriptor header |
---|
| 388 | rpc_desc_t rpc; |
---|
| 389 | rpc.index = RPC_THREAD_USER_CREATE; |
---|
| 390 | rpc.response = 1; |
---|
| 391 | |
---|
| 392 | // set input arguments in RPC descriptor |
---|
[23] | 393 | rpc.args[0] = (uint64_t)pid; |
---|
| 394 | rpc.args[1] = (uint64_t)(intptr_t)start_func; |
---|
| 395 | rpc.args[2] = (uint64_t)(intptr_t)start_arg; |
---|
| 396 | rpc.args[3] = (uint64_t)(intptr_t)attr; |
---|
[1] | 397 | |
---|
| 398 | // register RPC request in remote RPC fifo |
---|
| 399 | rpc_send_sync( cxy , &rpc ); |
---|
| 400 | |
---|
| 401 | // get output arguments from RPC descriptor |
---|
[23] | 402 | *thread_xp = (xptr_t)rpc.args[4]; |
---|
| 403 | *error = (error_t)rpc.args[5]; |
---|
[279] | 404 | |
---|
[337] | 405 | rpc_dmsg("\n[INFO] %s : exit / thread %x on core[%x,%d] / cycle %d\n", |
---|
| 406 | __FUNCTION__ , CURRENT_THREAD->trdid , local_cxy, |
---|
| 407 | CURRENT_THREAD->core->lid , hal_time_stamp() ); |
---|
[1] | 408 | } |
---|
| 409 | |
---|
| 410 | /////////////////////////////////////////////// |
---|
| 411 | void rpc_thread_user_create_server( xptr_t xp ) |
---|
| 412 | { |
---|
| 413 | pthread_attr_t * attr_ptr; // pointer on attributes structure in client cluster |
---|
| 414 | pthread_attr_t attr_copy; // attributes structure copy in server cluster |
---|
| 415 | thread_t * thread_ptr; // local pointer on thread descriptor |
---|
| 416 | xptr_t thread_xp; // extended pointer on thread descriptor |
---|
[23] | 417 | |
---|
[1] | 418 | pid_t pid; // process identifier |
---|
[23] | 419 | void * start_func; |
---|
| 420 | void * start_arg; |
---|
| 421 | error_t error; |
---|
[1] | 422 | |
---|
[337] | 423 | rpc_dmsg("\n[INFO] %s : enter / thread %x on core[%x,%d] / cycle %d\n", |
---|
| 424 | __FUNCTION__ , CURRENT_THREAD->trdid , local_cxy, |
---|
| 425 | CURRENT_THREAD->core->lid , hal_time_stamp() ); |
---|
[296] | 426 | |
---|
[1] | 427 | // get client cluster identifier and pointer on RPC descriptor |
---|
| 428 | cxy_t client_cxy = (cxy_t)GET_CXY( xp ); |
---|
| 429 | rpc_desc_t * desc = (rpc_desc_t *)GET_PTR( xp ); |
---|
| 430 | |
---|
| 431 | // get pointer on attributes structure in client cluster from RPC descriptor |
---|
| 432 | |
---|
[23] | 433 | // get input arguments from RPC descriptor |
---|
| 434 | pid = (pid_t) hal_remote_lwd(XPTR(client_cxy , &desc->args[0])); |
---|
| 435 | start_func = (void *)(intptr_t) hal_remote_lwd(XPTR(client_cxy , &desc->args[1])); |
---|
| 436 | start_arg = (void *)(intptr_t) hal_remote_lwd(XPTR(client_cxy , &desc->args[2])); |
---|
| 437 | attr_ptr = (pthread_attr_t *)(intptr_t)hal_remote_lwd(XPTR(client_cxy , &desc->args[3])); |
---|
| 438 | |
---|
[1] | 439 | // makes a local copy of attributes structure |
---|
| 440 | hal_remote_memcpy( XPTR( local_cxy , &attr_copy ), |
---|
| 441 | XPTR( client_cxy , attr_ptr ), |
---|
| 442 | sizeof(pthread_attr_t) ); |
---|
| 443 | |
---|
[23] | 444 | assert( (attr_copy.cxy == local_cxy) , __FUNCTION__ , "bad target cluster\n" ); |
---|
[1] | 445 | |
---|
[23] | 446 | // call kernel function |
---|
| 447 | error = thread_user_create( pid, |
---|
| 448 | start_func, |
---|
| 449 | start_arg, |
---|
| 450 | &attr_copy, |
---|
| 451 | &thread_ptr ); |
---|
[1] | 452 | |
---|
| 453 | // set output arguments |
---|
| 454 | thread_xp = XPTR( local_cxy , thread_ptr ); |
---|
| 455 | hal_remote_swd( XPTR( client_cxy , &desc->args[1] ) , (uint64_t)error ); |
---|
| 456 | hal_remote_swd( XPTR( client_cxy , &desc->args[2] ) , (uint64_t)thread_xp ); |
---|
[296] | 457 | |
---|
[337] | 458 | rpc_dmsg("\n[INFO] %s : exit / thread %x on core[%x,%d] / cycle %d\n", |
---|
| 459 | __FUNCTION__ , CURRENT_THREAD->trdid , local_cxy, |
---|
| 460 | CURRENT_THREAD->core->lid , hal_time_stamp() ); |
---|
[1] | 461 | } |
---|
| 462 | |
---|
| 463 | ///////////////////////////////////////////////////////////////////////////////////////// |
---|
[23] | 464 | // [5] Marshaling functions attached to RPC_THREAD_KERNEL_CREATE |
---|
[1] | 465 | ///////////////////////////////////////////////////////////////////////////////////////// |
---|
| 466 | |
---|
| 467 | //////////////////////////////////////////////////// |
---|
| 468 | void rpc_thread_kernel_create_client( cxy_t cxy, |
---|
| 469 | uint32_t type, // in |
---|
| 470 | void * func, // in |
---|
| 471 | void * args, // in |
---|
| 472 | xptr_t * thread_xp, // out |
---|
| 473 | error_t * error ) // out |
---|
| 474 | { |
---|
[337] | 475 | rpc_dmsg("\n[INFO] %s : enter / thread %x on core[%x,%d] / cycle %d\n", |
---|
| 476 | __FUNCTION__ , CURRENT_THREAD->trdid , local_cxy, |
---|
| 477 | CURRENT_THREAD->core->lid , hal_time_stamp() ); |
---|
[296] | 478 | |
---|
[238] | 479 | assert( (cxy != local_cxy) , __FUNCTION__ , "target cluster is not remote\n"); |
---|
[1] | 480 | |
---|
| 481 | // initialise RPC descriptor header |
---|
| 482 | rpc_desc_t rpc; |
---|
| 483 | rpc.index = RPC_THREAD_KERNEL_CREATE; |
---|
| 484 | rpc.response = 1; |
---|
| 485 | |
---|
| 486 | // set input arguments in RPC descriptor |
---|
| 487 | rpc.args[0] = (uint64_t)type; |
---|
| 488 | rpc.args[1] = (uint64_t)(intptr_t)func; |
---|
| 489 | rpc.args[2] = (uint64_t)(intptr_t)args; |
---|
| 490 | |
---|
| 491 | // register RPC request in remote RPC fifo |
---|
| 492 | rpc_send_sync( cxy , &rpc ); |
---|
| 493 | |
---|
| 494 | // get output arguments from RPC descriptor |
---|
| 495 | *thread_xp = (xptr_t)rpc.args[3]; |
---|
| 496 | *error = (error_t)rpc.args[4]; |
---|
[279] | 497 | |
---|
[337] | 498 | rpc_dmsg("\n[INFO] %s : exit / thread %x on core[%x,%d] / cycle %d\n", |
---|
| 499 | __FUNCTION__ , CURRENT_THREAD->trdid , local_cxy, |
---|
| 500 | CURRENT_THREAD->core->lid , hal_time_stamp() ); |
---|
[1] | 501 | } |
---|
| 502 | |
---|
| 503 | ///////////////////////////////////////////////// |
---|
| 504 | void rpc_thread_kernel_create_server( xptr_t xp ) |
---|
| 505 | { |
---|
| 506 | thread_t * thread_ptr; // local pointer on thread descriptor |
---|
| 507 | xptr_t thread_xp; // extended pointer on thread descriptor |
---|
| 508 | lid_t core_lid; // core local index |
---|
| 509 | error_t error; |
---|
| 510 | |
---|
[337] | 511 | rpc_dmsg("\n[INFO] %s : enter / thread %x on core[%x,%d] / cycle %d\n", |
---|
| 512 | __FUNCTION__ , CURRENT_THREAD->trdid , local_cxy, |
---|
| 513 | CURRENT_THREAD->core->lid , hal_time_stamp() ); |
---|
[296] | 514 | |
---|
[1] | 515 | // get client cluster identifier and pointer on RPC descriptor |
---|
| 516 | cxy_t client_cxy = (cxy_t)GET_CXY( xp ); |
---|
| 517 | rpc_desc_t * desc = (rpc_desc_t *)GET_PTR( xp ); |
---|
| 518 | |
---|
| 519 | // get attributes from RPC descriptor |
---|
| 520 | uint32_t type = (uint32_t) hal_remote_lwd( XPTR( client_cxy , &desc->args[0] ) ); |
---|
| 521 | void * func = (void*)(intptr_t)hal_remote_lwd( XPTR( client_cxy , &desc->args[1] ) ); |
---|
| 522 | void * args = (void*)(intptr_t)hal_remote_lwd( XPTR( client_cxy , &desc->args[2] ) ); |
---|
| 523 | |
---|
| 524 | // select one core |
---|
| 525 | core_lid = cluster_select_local_core(); |
---|
| 526 | |
---|
| 527 | // call local kernel function |
---|
| 528 | error = thread_kernel_create( &thread_ptr , type , func , args , core_lid ); |
---|
| 529 | |
---|
| 530 | // set output arguments |
---|
| 531 | thread_xp = XPTR( local_cxy , thread_ptr ); |
---|
| 532 | hal_remote_swd( XPTR( client_cxy , &desc->args[1] ) , (uint64_t)error ); |
---|
| 533 | hal_remote_swd( XPTR( client_cxy , &desc->args[2] ) , (uint64_t)thread_xp ); |
---|
[296] | 534 | |
---|
[337] | 535 | rpc_dmsg("\n[INFO] %s : exit / thread %x on core[%x,%d] / cycle %d\n", |
---|
| 536 | __FUNCTION__ , CURRENT_THREAD->trdid , local_cxy, |
---|
| 537 | CURRENT_THREAD->core->lid , hal_time_stamp() ); |
---|
[1] | 538 | } |
---|
| 539 | |
---|
| 540 | ///////////////////////////////////////////////////////////////////////////////////////// |
---|
[23] | 541 | // [6] Marshaling functions attached to RPC_SIGNAL_RISE |
---|
[1] | 542 | ///////////////////////////////////////////////////////////////////////////////////////// |
---|
| 543 | |
---|
[23] | 544 | ///////////////////////////////////////////// |
---|
| 545 | void rpc_signal_rise_client( cxy_t cxy, |
---|
| 546 | process_t * process, // in |
---|
| 547 | uint32_t sig_id ) // in |
---|
| 548 | { |
---|
[337] | 549 | rpc_dmsg("\n[INFO] %s : enter / thread %x on core[%x,%d] / cycle %d\n", |
---|
| 550 | __FUNCTION__ , CURRENT_THREAD->trdid , local_cxy, |
---|
| 551 | CURRENT_THREAD->core->lid , hal_time_stamp() ); |
---|
[296] | 552 | |
---|
[238] | 553 | assert( (cxy != local_cxy) , __FUNCTION__ , "target cluster is not remote\n"); |
---|
[23] | 554 | |
---|
| 555 | // initialise RPC descriptor header |
---|
| 556 | rpc_desc_t rpc; |
---|
| 557 | rpc.index = RPC_SIGNAL_RISE; |
---|
| 558 | rpc.response = 1; |
---|
| 559 | |
---|
| 560 | // set input arguments in RPC descriptor |
---|
| 561 | rpc.args[0] = (uint64_t)(intptr_t)process; |
---|
| 562 | rpc.args[1] = (uint64_t)sig_id; |
---|
| 563 | |
---|
| 564 | // register RPC request in remote RPC fifo |
---|
| 565 | rpc_send_sync( cxy , &rpc ); |
---|
[279] | 566 | |
---|
[337] | 567 | rpc_dmsg("\n[INFO] %s : exit / thread %x on core[%x,%d] / cycle %d\n", |
---|
| 568 | __FUNCTION__ , CURRENT_THREAD->trdid , local_cxy, |
---|
| 569 | CURRENT_THREAD->core->lid , hal_time_stamp() ); |
---|
[23] | 570 | } |
---|
| 571 | |
---|
| 572 | //////////////////////////////////////// |
---|
| 573 | void rpc_signal_rise_server( xptr_t xp ) |
---|
| 574 | { |
---|
| 575 | process_t * process; // local pointer on process descriptor |
---|
| 576 | uint32_t sig_id; // signal index |
---|
| 577 | |
---|
[337] | 578 | rpc_dmsg("\n[INFO] %s : enter / thread %x on core[%x,%d] / cycle %d\n", |
---|
| 579 | __FUNCTION__ , CURRENT_THREAD->trdid , local_cxy, |
---|
| 580 | CURRENT_THREAD->core->lid , hal_time_stamp() ); |
---|
[296] | 581 | |
---|
[23] | 582 | // get client cluster identifier and pointer on RPC descriptor |
---|
| 583 | cxy_t client_cxy = (cxy_t)GET_CXY( xp ); |
---|
| 584 | rpc_desc_t * desc = (rpc_desc_t *)GET_PTR( xp ); |
---|
| 585 | |
---|
| 586 | // get attributes from RPC descriptor |
---|
| 587 | process = (process_t *)(intptr_t)hal_remote_lwd( XPTR( client_cxy , &desc->args[0] ) ); |
---|
| 588 | sig_id = (uint32_t) hal_remote_lwd( XPTR( client_cxy , &desc->args[1] ) ); |
---|
| 589 | |
---|
| 590 | // call local kernel function |
---|
| 591 | signal_rise( process , sig_id ); |
---|
[296] | 592 | |
---|
[337] | 593 | rpc_dmsg("\n[INFO] %s : exit / thread %x on core[%x,%d] / cycle %d\n", |
---|
| 594 | __FUNCTION__ , CURRENT_THREAD->trdid , local_cxy, |
---|
| 595 | CURRENT_THREAD->core->lid , hal_time_stamp() ); |
---|
[23] | 596 | } |
---|
| 597 | |
---|
| 598 | ///////////////////////////////////////////////////////////////////////////////////////// |
---|
| 599 | // [10] Marshaling functions attached to RPC_VFS_INODE_CREATE |
---|
| 600 | ///////////////////////////////////////////////////////////////////////////////////////// |
---|
| 601 | |
---|
[1] | 602 | ///////////////////////////////////////////////////// |
---|
| 603 | void rpc_vfs_inode_create_client( cxy_t cxy, |
---|
| 604 | xptr_t dentry_xp, // in |
---|
[23] | 605 | uint32_t fs_type, // in |
---|
| 606 | uint32_t inode_type, // in |
---|
[188] | 607 | void * extend, // in |
---|
[1] | 608 | uint32_t attr, // in |
---|
[23] | 609 | uint32_t rights, // in |
---|
[1] | 610 | uint32_t uid, // in |
---|
| 611 | uint32_t gid, // in |
---|
| 612 | xptr_t * inode_xp, // out |
---|
| 613 | error_t * error ) // out |
---|
| 614 | { |
---|
[337] | 615 | rpc_dmsg("\n[INFO] %s : enter / thread %x on core[%x,%d] / cycle %d\n", |
---|
| 616 | __FUNCTION__ , CURRENT_THREAD->trdid , local_cxy, |
---|
| 617 | CURRENT_THREAD->core->lid , hal_time_stamp() ); |
---|
[296] | 618 | |
---|
[238] | 619 | assert( (cxy != local_cxy) , __FUNCTION__ , "target cluster is not remote\n"); |
---|
[1] | 620 | |
---|
| 621 | // initialise RPC descriptor header |
---|
| 622 | rpc_desc_t rpc; |
---|
| 623 | rpc.index = RPC_VFS_INODE_CREATE; |
---|
| 624 | rpc.response = 1; |
---|
| 625 | |
---|
| 626 | // set input arguments in RPC descriptor |
---|
| 627 | rpc.args[0] = (uint64_t)dentry_xp; |
---|
[23] | 628 | rpc.args[1] = (uint64_t)fs_type; |
---|
| 629 | rpc.args[2] = (uint64_t)inode_type; |
---|
[188] | 630 | rpc.args[3] = (uint64_t)(intptr_t)extend; |
---|
| 631 | rpc.args[4] = (uint64_t)attr; |
---|
| 632 | rpc.args[5] = (uint64_t)rights; |
---|
| 633 | rpc.args[6] = (uint64_t)uid; |
---|
| 634 | rpc.args[7] = (uint64_t)gid; |
---|
[1] | 635 | |
---|
| 636 | // register RPC request in remote RPC fifo (blocking function) |
---|
| 637 | rpc_send_sync( cxy , &rpc ); |
---|
| 638 | |
---|
| 639 | // get output values from RPC descriptor |
---|
[188] | 640 | *inode_xp = (xptr_t)rpc.args[8]; |
---|
| 641 | *error = (error_t)rpc.args[9]; |
---|
[279] | 642 | |
---|
[337] | 643 | rpc_dmsg("\n[INFO] %s : exit / thread %x on core[%x,%d] / cycle %d\n", |
---|
| 644 | __FUNCTION__ , CURRENT_THREAD->trdid , local_cxy, |
---|
| 645 | CURRENT_THREAD->core->lid , hal_time_stamp() ); |
---|
[1] | 646 | } |
---|
| 647 | |
---|
| 648 | ///////////////////////////////////////////// |
---|
| 649 | void rpc_vfs_inode_create_server( xptr_t xp ) |
---|
| 650 | { |
---|
| 651 | xptr_t dentry_xp; |
---|
[23] | 652 | uint32_t fs_type; |
---|
| 653 | uint32_t inode_type; |
---|
[188] | 654 | void * extend; |
---|
[1] | 655 | uint32_t attr; |
---|
[23] | 656 | uint32_t rights; |
---|
[1] | 657 | uint32_t uid; |
---|
| 658 | uint32_t gid; |
---|
| 659 | xptr_t inode_xp; |
---|
| 660 | error_t error; |
---|
| 661 | |
---|
[337] | 662 | rpc_dmsg("\n[INFO] %s : enter / thread %x on core[%x,%d] / cycle %d\n", |
---|
| 663 | __FUNCTION__ , CURRENT_THREAD->trdid , local_cxy, |
---|
| 664 | CURRENT_THREAD->core->lid , hal_time_stamp() ); |
---|
[296] | 665 | |
---|
[1] | 666 | // get client cluster identifier and pointer on RPC descriptor |
---|
| 667 | cxy_t client_cxy = (cxy_t)GET_CXY( xp ); |
---|
| 668 | rpc_desc_t * desc = (rpc_desc_t *)GET_PTR( xp ); |
---|
| 669 | |
---|
| 670 | // get input arguments from client rpc descriptor |
---|
[188] | 671 | dentry_xp = (xptr_t) hal_remote_lwd( XPTR( client_cxy , &desc->args[0] ) ); |
---|
| 672 | fs_type = (uint32_t) hal_remote_lwd( XPTR( client_cxy , &desc->args[1] ) ); |
---|
| 673 | inode_type = (uint32_t) hal_remote_lwd( XPTR( client_cxy , &desc->args[2] ) ); |
---|
| 674 | extend = (void *)(intptr_t)hal_remote_lwd( XPTR( client_cxy , &desc->args[3] ) ); |
---|
| 675 | attr = (uint32_t) hal_remote_lwd( XPTR( client_cxy , &desc->args[4] ) ); |
---|
| 676 | rights = (uint32_t) hal_remote_lwd( XPTR( client_cxy , &desc->args[5] ) ); |
---|
| 677 | uid = (uid_t) hal_remote_lwd( XPTR( client_cxy , &desc->args[6] ) ); |
---|
| 678 | gid = (gid_t) hal_remote_lwd( XPTR( client_cxy , &desc->args[7] ) ); |
---|
[1] | 679 | |
---|
| 680 | // call local kernel function |
---|
| 681 | error = vfs_inode_create( dentry_xp, |
---|
[23] | 682 | fs_type, |
---|
| 683 | inode_type, |
---|
[188] | 684 | extend, |
---|
[1] | 685 | attr, |
---|
[23] | 686 | rights, |
---|
[1] | 687 | uid, |
---|
| 688 | gid, |
---|
| 689 | &inode_xp ); |
---|
| 690 | |
---|
| 691 | // set output arguments |
---|
[188] | 692 | hal_remote_swd( XPTR( client_cxy , &desc->args[8] ) , (uint64_t)inode_xp ); |
---|
| 693 | hal_remote_swd( XPTR( client_cxy , &desc->args[9] ) , (uint64_t)error ); |
---|
[296] | 694 | |
---|
[337] | 695 | rpc_dmsg("\n[INFO] %s : exit / thread %x on core[%x,%d] / cycle %d\n", |
---|
| 696 | __FUNCTION__ , CURRENT_THREAD->trdid , local_cxy, |
---|
| 697 | CURRENT_THREAD->core->lid , hal_time_stamp() ); |
---|
[1] | 698 | } |
---|
| 699 | |
---|
| 700 | ///////////////////////////////////////////////////////////////////////////////////////// |
---|
[23] | 701 | // [11] Marshaling functions attached to RPC_VFS_INODE_DESTROY |
---|
[1] | 702 | ///////////////////////////////////////////////////////////////////////////////////////// |
---|
| 703 | |
---|
| 704 | ///////////////////////////////////////////////////////////// |
---|
| 705 | void rpc_vfs_inode_destroy_client( cxy_t cxy, |
---|
| 706 | struct vfs_inode_s * inode ) |
---|
| 707 | { |
---|
[337] | 708 | rpc_dmsg("\n[INFO] %s : enter / thread %x on core[%x,%d] / cycle %d\n", |
---|
| 709 | __FUNCTION__ , CURRENT_THREAD->trdid , local_cxy, |
---|
| 710 | CURRENT_THREAD->core->lid , hal_time_stamp() ); |
---|
[296] | 711 | |
---|
[238] | 712 | assert( (cxy != local_cxy) , __FUNCTION__ , "target cluster is not remote\n"); |
---|
[1] | 713 | |
---|
| 714 | // initialise RPC descriptor header |
---|
| 715 | rpc_desc_t rpc; |
---|
| 716 | rpc.index = RPC_VFS_INODE_DESTROY; |
---|
| 717 | rpc.response = 1; |
---|
| 718 | |
---|
| 719 | // set input arguments in RPC descriptor |
---|
| 720 | rpc.args[0] = (uint64_t)(intptr_t)inode; |
---|
| 721 | |
---|
| 722 | // register RPC request in remote RPC fifo (blocking function) |
---|
| 723 | rpc_send_sync( cxy , &rpc ); |
---|
[279] | 724 | |
---|
[337] | 725 | rpc_dmsg("\n[INFO] %s : exit / thread %x on core[%x,%d] / cycle %d\n", |
---|
| 726 | __FUNCTION__ , CURRENT_THREAD->trdid , local_cxy, |
---|
| 727 | CURRENT_THREAD->core->lid , hal_time_stamp() ); |
---|
[1] | 728 | } |
---|
| 729 | |
---|
| 730 | ////////////////////////////////////////////// |
---|
| 731 | void rpc_vfs_inode_destroy_server( xptr_t xp ) |
---|
| 732 | { |
---|
| 733 | vfs_inode_t * inode; |
---|
| 734 | |
---|
[337] | 735 | rpc_dmsg("\n[INFO] %s : enter / thread %x on core[%x,%d] / cycle %d\n", |
---|
| 736 | __FUNCTION__ , CURRENT_THREAD->trdid , local_cxy, |
---|
| 737 | CURRENT_THREAD->core->lid , hal_time_stamp() ); |
---|
[296] | 738 | |
---|
[1] | 739 | // get client cluster identifier and pointer on RPC descriptor |
---|
| 740 | cxy_t client_cxy = (cxy_t)GET_CXY( xp ); |
---|
| 741 | rpc_desc_t * desc = (rpc_desc_t *)GET_PTR( xp ); |
---|
| 742 | |
---|
| 743 | // get arguments "inode" from client RPC descriptor |
---|
| 744 | inode = (vfs_inode_t *)(intptr_t)hal_remote_lwd( XPTR( client_cxy , &desc->args[0] ) ); |
---|
| 745 | |
---|
| 746 | // call local kernel function |
---|
| 747 | vfs_inode_destroy( inode ); |
---|
[296] | 748 | |
---|
[337] | 749 | rpc_dmsg("\n[INFO] %s : exit / thread %x on core[%x,%d] / cycle %d\n", |
---|
| 750 | __FUNCTION__ , CURRENT_THREAD->trdid , local_cxy, |
---|
| 751 | CURRENT_THREAD->core->lid , hal_time_stamp() ); |
---|
[1] | 752 | } |
---|
| 753 | |
---|
| 754 | ///////////////////////////////////////////////////////////////////////////////////////// |
---|
[23] | 755 | // [12] Marshaling functions attached to RPC_VFS_DENTRY_CREATE |
---|
[1] | 756 | ///////////////////////////////////////////////////////////////////////////////////////// |
---|
| 757 | |
---|
| 758 | ////////////////////////////////////////////////////////////// |
---|
| 759 | void rpc_vfs_dentry_create_client( cxy_t cxy, |
---|
| 760 | uint32_t type, // in |
---|
| 761 | char * name, // in |
---|
| 762 | struct vfs_inode_s * parent, // in |
---|
| 763 | xptr_t * dentry_xp, // out |
---|
| 764 | error_t * error ) // out |
---|
| 765 | { |
---|
[337] | 766 | rpc_dmsg("\n[INFO] %s : enter / thread %x on core[%x,%d] / cycle %d\n", |
---|
| 767 | __FUNCTION__ , CURRENT_THREAD->trdid , local_cxy, |
---|
| 768 | CURRENT_THREAD->core->lid , hal_time_stamp() ); |
---|
[296] | 769 | |
---|
[238] | 770 | assert( (cxy != local_cxy) , __FUNCTION__ , "target cluster is not remote\n"); |
---|
[1] | 771 | |
---|
| 772 | // initialise RPC descriptor header |
---|
| 773 | rpc_desc_t rpc; |
---|
| 774 | rpc.index = RPC_VFS_DENTRY_CREATE; |
---|
| 775 | rpc.response = 1; |
---|
| 776 | |
---|
| 777 | // set input arguments in RPC descriptor |
---|
| 778 | rpc.args[0] = (uint64_t)type; |
---|
| 779 | rpc.args[1] = (uint64_t)(intptr_t)name; |
---|
[238] | 780 | rpc.args[2] = (uint64_t)(intptr_t)parent; |
---|
[1] | 781 | |
---|
| 782 | // register RPC request in remote RPC fifo (blocking function) |
---|
| 783 | rpc_send_sync( cxy , &rpc ); |
---|
| 784 | |
---|
| 785 | // get output values from RPC descriptor |
---|
[238] | 786 | *dentry_xp = (xptr_t)rpc.args[3]; |
---|
| 787 | *error = (error_t)rpc.args[4]; |
---|
[279] | 788 | |
---|
[337] | 789 | rpc_dmsg("\n[INFO] %s : exit / thread %x on core[%x,%d] / cycle %d\n", |
---|
| 790 | __FUNCTION__ , CURRENT_THREAD->trdid , local_cxy, |
---|
| 791 | CURRENT_THREAD->core->lid , hal_time_stamp() ); |
---|
[1] | 792 | } |
---|
| 793 | |
---|
| 794 | ////////////////////////////////////////////// |
---|
| 795 | void rpc_vfs_dentry_create_server( xptr_t xp ) |
---|
| 796 | { |
---|
| 797 | uint32_t type; |
---|
| 798 | char * name; |
---|
| 799 | vfs_inode_t * parent; |
---|
| 800 | xptr_t dentry_xp; |
---|
| 801 | error_t error; |
---|
| 802 | |
---|
[238] | 803 | char name_copy[CONFIG_VFS_MAX_NAME_LENGTH]; |
---|
| 804 | |
---|
[337] | 805 | rpc_dmsg("\n[INFO] %s : enter / thread %x on core[%x,%d] / cycle %d\n", |
---|
| 806 | __FUNCTION__ , CURRENT_THREAD->trdid , local_cxy, |
---|
| 807 | CURRENT_THREAD->core->lid , hal_time_stamp() ); |
---|
[296] | 808 | |
---|
[1] | 809 | // get client cluster identifier and pointer on RPC descriptor |
---|
| 810 | cxy_t client_cxy = (cxy_t)GET_CXY( xp ); |
---|
| 811 | rpc_desc_t * desc = (rpc_desc_t *)GET_PTR( xp ); |
---|
| 812 | |
---|
[238] | 813 | // get arguments "name", "type", and "parent" from client RPC descriptor |
---|
[1] | 814 | type = (uint32_t) hal_remote_lwd( XPTR( client_cxy , &desc->args[0] ) ); |
---|
[238] | 815 | name = (char *)(intptr_t) hal_remote_lwd( XPTR( client_cxy , &desc->args[1] ) ); |
---|
| 816 | parent = (vfs_inode_t *)(intptr_t)hal_remote_lwd( XPTR( client_cxy , &desc->args[2] ) ); |
---|
[296] | 817 | |
---|
[238] | 818 | // makes a local copy of name |
---|
| 819 | hal_remote_strcpy( XPTR( local_cxy , name_copy ), |
---|
| 820 | XPTR( client_cxy , name ) ); |
---|
| 821 | |
---|
[1] | 822 | // call local kernel function |
---|
| 823 | error = vfs_dentry_create( type, |
---|
| 824 | name_copy, |
---|
| 825 | parent, |
---|
| 826 | &dentry_xp ); |
---|
| 827 | // set output arguments |
---|
[238] | 828 | hal_remote_swd( XPTR( client_cxy , &desc->args[3] ) , (uint64_t)dentry_xp ); |
---|
| 829 | hal_remote_swd( XPTR( client_cxy , &desc->args[4] ) , (uint64_t)error ); |
---|
[296] | 830 | |
---|
[337] | 831 | rpc_dmsg("\n[INFO] %s : exit / thread %x on core[%x,%d] / cycle %d\n", |
---|
| 832 | __FUNCTION__ , CURRENT_THREAD->trdid , local_cxy, |
---|
| 833 | CURRENT_THREAD->core->lid , hal_time_stamp() ); |
---|
[1] | 834 | } |
---|
| 835 | |
---|
| 836 | ///////////////////////////////////////////////////////////////////////////////////////// |
---|
[23] | 837 | // [13] Marshaling functions attached to RPC_VFS_DENTRY_DESTROY |
---|
[1] | 838 | ///////////////////////////////////////////////////////////////////////////////////////// |
---|
| 839 | |
---|
[296] | 840 | |
---|
[1] | 841 | /////////////////////////////////////////////////////// |
---|
| 842 | void rpc_vfs_dentry_destroy_client( cxy_t cxy, |
---|
| 843 | vfs_dentry_t * dentry ) |
---|
| 844 | { |
---|
[337] | 845 | rpc_dmsg("\n[INFO] %s : enter / thread %x on core[%x,%d] / cycle %d\n", |
---|
| 846 | __FUNCTION__ , CURRENT_THREAD->trdid , local_cxy, |
---|
| 847 | CURRENT_THREAD->core->lid , hal_time_stamp() ); |
---|
[296] | 848 | |
---|
[238] | 849 | assert( (cxy != local_cxy) , __FUNCTION__ , "target cluster is not remote\n"); |
---|
[1] | 850 | |
---|
| 851 | // initialise RPC descriptor header |
---|
| 852 | rpc_desc_t rpc; |
---|
| 853 | rpc.index = RPC_VFS_DENTRY_DESTROY; |
---|
| 854 | rpc.response = 1; |
---|
| 855 | |
---|
| 856 | // set input arguments in RPC descriptor |
---|
| 857 | rpc.args[0] = (uint64_t)(intptr_t)dentry; |
---|
| 858 | |
---|
| 859 | // register RPC request in remote RPC fifo (blocking function) |
---|
| 860 | rpc_send_sync( cxy , &rpc ); |
---|
[279] | 861 | |
---|
[337] | 862 | rpc_dmsg("\n[INFO] %s : exit / thread %x on core[%x,%d] / cycle %d\n", |
---|
| 863 | __FUNCTION__ , CURRENT_THREAD->trdid , local_cxy, |
---|
| 864 | CURRENT_THREAD->core->lid , hal_time_stamp() ); |
---|
[1] | 865 | } |
---|
| 866 | |
---|
| 867 | /////////////////////////////////////////////// |
---|
| 868 | void rpc_vfs_dentry_destroy_server( xptr_t xp ) |
---|
| 869 | { |
---|
| 870 | vfs_dentry_t * dentry; |
---|
| 871 | |
---|
[337] | 872 | rpc_dmsg("\n[INFO] %s : enter / thread %x on core[%x,%d] / cycle %d\n", |
---|
| 873 | __FUNCTION__ , CURRENT_THREAD->trdid , local_cxy, |
---|
| 874 | CURRENT_THREAD->core->lid , hal_time_stamp() ); |
---|
[296] | 875 | |
---|
[1] | 876 | // get client cluster identifier and pointer on RPC descriptor |
---|
| 877 | cxy_t client_cxy = (cxy_t)GET_CXY( xp ); |
---|
| 878 | rpc_desc_t * desc = (rpc_desc_t *)GET_PTR( xp ); |
---|
| 879 | |
---|
| 880 | // get arguments "dentry" from client RPC descriptor |
---|
| 881 | dentry = (vfs_dentry_t *)(intptr_t)hal_remote_lwd( XPTR( client_cxy , &desc->args[0] ) ); |
---|
| 882 | |
---|
| 883 | // call local kernel function |
---|
| 884 | vfs_dentry_destroy( dentry ); |
---|
[296] | 885 | |
---|
[337] | 886 | rpc_dmsg("\n[INFO] %s : exit / thread %x on core[%x,%d] / cycle %d\n", |
---|
| 887 | __FUNCTION__ , CURRENT_THREAD->trdid , local_cxy, |
---|
| 888 | CURRENT_THREAD->core->lid , hal_time_stamp() ); |
---|
[1] | 889 | } |
---|
| 890 | |
---|
| 891 | |
---|
| 892 | ///////////////////////////////////////////////////////////////////////////////////////// |
---|
[23] | 893 | // [14] Marshaling functions attached to RPC_VFS_FILE_CREATE |
---|
[1] | 894 | ///////////////////////////////////////////////////////////////////////////////////////// |
---|
| 895 | |
---|
[23] | 896 | ////////////////////////////////////////////////////////////// |
---|
| 897 | void rpc_vfs_file_create_client( cxy_t cxy, |
---|
| 898 | struct vfs_inode_s * inode, // in |
---|
| 899 | uint32_t file_attr, // in |
---|
| 900 | xptr_t * file_xp, // out |
---|
| 901 | error_t * error ) // out |
---|
| 902 | { |
---|
[337] | 903 | rpc_dmsg("\n[INFO] %s : enter / thread %x on core[%x,%d] / cycle %d\n", |
---|
| 904 | __FUNCTION__ , CURRENT_THREAD->trdid , local_cxy, |
---|
| 905 | CURRENT_THREAD->core->lid , hal_time_stamp() ); |
---|
[296] | 906 | |
---|
[238] | 907 | assert( (cxy != local_cxy) , __FUNCTION__ , "target cluster is not remote\n"); |
---|
[23] | 908 | |
---|
| 909 | // initialise RPC descriptor header |
---|
| 910 | rpc_desc_t rpc; |
---|
| 911 | rpc.index = RPC_VFS_FILE_CREATE; |
---|
| 912 | rpc.response = 1; |
---|
| 913 | |
---|
| 914 | // set input arguments in RPC descriptor |
---|
| 915 | rpc.args[0] = (uint64_t)(intptr_t)inode; |
---|
| 916 | rpc.args[1] = (uint64_t)file_attr; |
---|
| 917 | |
---|
| 918 | // register RPC request in remote RPC fifo (blocking function) |
---|
| 919 | rpc_send_sync( cxy , &rpc ); |
---|
| 920 | |
---|
| 921 | // get output values from RPC descriptor |
---|
| 922 | *file_xp = (xptr_t)rpc.args[2]; |
---|
| 923 | *error = (error_t)rpc.args[3]; |
---|
[279] | 924 | |
---|
[337] | 925 | rpc_dmsg("\n[INFO] %s : exit / thread %x on core[%x,%d] / cycle %d\n", |
---|
| 926 | __FUNCTION__ , CURRENT_THREAD->trdid , local_cxy, |
---|
| 927 | CURRENT_THREAD->core->lid , hal_time_stamp() ); |
---|
[23] | 928 | } |
---|
| 929 | |
---|
| 930 | //////////////////////////////////////////// |
---|
| 931 | void rpc_vfs_file_create_server( xptr_t xp ) |
---|
| 932 | { |
---|
| 933 | uint32_t file_attr; |
---|
| 934 | vfs_inode_t * inode; |
---|
| 935 | xptr_t file_xp; |
---|
| 936 | error_t error; |
---|
| 937 | |
---|
[337] | 938 | rpc_dmsg("\n[INFO] %s : enter / thread %x on core[%x,%d] / cycle %d\n", |
---|
| 939 | __FUNCTION__ , CURRENT_THREAD->trdid , local_cxy, |
---|
| 940 | CURRENT_THREAD->core->lid , hal_time_stamp() ); |
---|
[296] | 941 | |
---|
[23] | 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 arguments "file_attr" and "inode" from client RPC descriptor |
---|
| 947 | inode = (vfs_inode_t *)(intptr_t)hal_remote_lwd( XPTR( client_cxy , &desc->args[0] ) ); |
---|
| 948 | file_attr = (uint32_t) hal_remote_lwd( XPTR( client_cxy , &desc->args[1] ) ); |
---|
| 949 | |
---|
| 950 | // call local kernel function |
---|
| 951 | error = vfs_file_create( inode, |
---|
| 952 | file_attr, |
---|
| 953 | &file_xp ); |
---|
| 954 | |
---|
| 955 | // set output arguments |
---|
| 956 | hal_remote_swd( XPTR( client_cxy , &desc->args[2] ) , (uint64_t)file_xp ); |
---|
| 957 | hal_remote_swd( XPTR( client_cxy , &desc->args[3] ) , (uint64_t)error ); |
---|
[296] | 958 | |
---|
[337] | 959 | rpc_dmsg("\n[INFO] %s : exit / thread %x on core[%x,%d] / cycle %d\n", |
---|
| 960 | __FUNCTION__ , CURRENT_THREAD->trdid , local_cxy, |
---|
| 961 | CURRENT_THREAD->core->lid , hal_time_stamp() ); |
---|
[23] | 962 | } |
---|
| 963 | |
---|
| 964 | ///////////////////////////////////////////////////////////////////////////////////////// |
---|
| 965 | // [15] Marshaling functions attached to RPC_VFS_FILE_DESTROY |
---|
| 966 | ///////////////////////////////////////////////////////////////////////////////////////// |
---|
| 967 | |
---|
| 968 | /////////////////////////////////////////////////// |
---|
| 969 | void rpc_vfs_file_destroy_client( cxy_t cxy, |
---|
| 970 | vfs_file_t * file ) |
---|
| 971 | { |
---|
[337] | 972 | rpc_dmsg("\n[INFO] %s : enter / thread %x on core[%x,%d] / cycle %d\n", |
---|
| 973 | __FUNCTION__ , CURRENT_THREAD->trdid , local_cxy, |
---|
| 974 | CURRENT_THREAD->core->lid , hal_time_stamp() ); |
---|
[296] | 975 | |
---|
[238] | 976 | assert( (cxy != local_cxy) , __FUNCTION__ , "target cluster is not remote\n"); |
---|
[23] | 977 | |
---|
| 978 | // initialise RPC descriptor header |
---|
| 979 | rpc_desc_t rpc; |
---|
| 980 | rpc.index = RPC_VFS_FILE_DESTROY; |
---|
| 981 | rpc.response = 1; |
---|
| 982 | |
---|
| 983 | // set input arguments in RPC descriptor |
---|
| 984 | rpc.args[0] = (uint64_t)(intptr_t)file; |
---|
| 985 | |
---|
| 986 | // register RPC request in remote RPC fifo (blocking function) |
---|
| 987 | rpc_send_sync( cxy , &rpc ); |
---|
[279] | 988 | |
---|
[337] | 989 | rpc_dmsg("\n[INFO] %s : exit / thread %x on core[%x,%d] / cycle %d\n", |
---|
| 990 | __FUNCTION__ , CURRENT_THREAD->trdid , local_cxy, |
---|
| 991 | CURRENT_THREAD->core->lid , hal_time_stamp() ); |
---|
[23] | 992 | } |
---|
| 993 | |
---|
| 994 | ///////////////////////////////////////////// |
---|
| 995 | void rpc_vfs_file_destroy_server( xptr_t xp ) |
---|
| 996 | { |
---|
| 997 | vfs_file_t * file; |
---|
| 998 | |
---|
[337] | 999 | rpc_dmsg("\n[INFO] %s : enter / thread %x on core[%x,%d] / cycle %d\n", |
---|
| 1000 | __FUNCTION__ , CURRENT_THREAD->trdid , local_cxy, |
---|
| 1001 | CURRENT_THREAD->core->lid , hal_time_stamp() ); |
---|
[296] | 1002 | |
---|
[23] | 1003 | // get client cluster identifier and pointer on RPC descriptor |
---|
| 1004 | cxy_t client_cxy = (cxy_t)GET_CXY( xp ); |
---|
| 1005 | rpc_desc_t * desc = (rpc_desc_t *)GET_PTR( xp ); |
---|
| 1006 | |
---|
| 1007 | // get arguments "dentry" from client RPC descriptor |
---|
| 1008 | file = (vfs_file_t *)(intptr_t)hal_remote_lwd( XPTR( client_cxy , &desc->args[0] ) ); |
---|
| 1009 | |
---|
| 1010 | // call local kernel function |
---|
| 1011 | vfs_file_destroy( file ); |
---|
[296] | 1012 | |
---|
[337] | 1013 | rpc_dmsg("\n[INFO] %s : exit / thread %x on core[%x,%d] / cycle %d\n", |
---|
| 1014 | __FUNCTION__ , CURRENT_THREAD->trdid , local_cxy, |
---|
| 1015 | CURRENT_THREAD->core->lid , hal_time_stamp() ); |
---|
[23] | 1016 | } |
---|
| 1017 | |
---|
| 1018 | ///////////////////////////////////////////////////////////////////////////////////////// |
---|
[238] | 1019 | // [16] Marshaling functions attached to RPC_VFS_INODE_LOAD |
---|
[23] | 1020 | ///////////////////////////////////////////////////////////////////////////////////////// |
---|
| 1021 | |
---|
[1] | 1022 | ////////////////////////////////////////////////// |
---|
[238] | 1023 | void rpc_vfs_inode_load_client( cxy_t cxy, |
---|
| 1024 | vfs_inode_t * parent_inode, // in |
---|
| 1025 | char * name, // in |
---|
| 1026 | xptr_t child_inode_xp, // in |
---|
| 1027 | error_t * error ) // out |
---|
| 1028 | { |
---|
[337] | 1029 | rpc_dmsg("\n[INFO] %s : enter / thread %x on core[%x,%d] / cycle %d\n", |
---|
| 1030 | __FUNCTION__ , CURRENT_THREAD->trdid , local_cxy, |
---|
| 1031 | CURRENT_THREAD->core->lid , hal_time_stamp() ); |
---|
[296] | 1032 | |
---|
[238] | 1033 | assert( (cxy != local_cxy) , __FUNCTION__ , "target cluster is not remote\n"); |
---|
| 1034 | |
---|
| 1035 | // initialise RPC descriptor header |
---|
| 1036 | rpc_desc_t rpc; |
---|
| 1037 | rpc.index = RPC_VFS_INODE_LOAD; |
---|
| 1038 | rpc.response = 1; |
---|
| 1039 | |
---|
| 1040 | // set input arguments in RPC descriptor |
---|
| 1041 | rpc.args[0] = (uint64_t)(intptr_t)parent_inode; |
---|
| 1042 | rpc.args[1] = (uint64_t)(intptr_t)name; |
---|
| 1043 | rpc.args[2] = (uint64_t)child_inode_xp; |
---|
| 1044 | |
---|
| 1045 | // register RPC request in remote RPC fifo (blocking function) |
---|
| 1046 | rpc_send_sync( cxy , &rpc ); |
---|
| 1047 | |
---|
| 1048 | // get output values from RPC descriptor |
---|
| 1049 | *error = (error_t)rpc.args[3]; |
---|
[279] | 1050 | |
---|
[337] | 1051 | rpc_dmsg("\n[INFO] %s : exit / thread %x on core[%x,%d] / cycle %d\n", |
---|
| 1052 | __FUNCTION__ , CURRENT_THREAD->trdid , local_cxy, |
---|
| 1053 | CURRENT_THREAD->core->lid , hal_time_stamp() ); |
---|
[238] | 1054 | } |
---|
| 1055 | |
---|
| 1056 | /////////////////////////////////////////// |
---|
| 1057 | void rpc_vfs_inode_load_server( xptr_t xp ) |
---|
| 1058 | { |
---|
| 1059 | error_t error; |
---|
| 1060 | vfs_inode_t * parent; |
---|
| 1061 | xptr_t child_xp; |
---|
| 1062 | char * name; |
---|
| 1063 | |
---|
| 1064 | char name_copy[CONFIG_VFS_MAX_NAME_LENGTH]; |
---|
| 1065 | |
---|
[337] | 1066 | rpc_dmsg("\n[INFO] %s : enter / thread %x on core[%x,%d] / cycle %d\n", |
---|
| 1067 | __FUNCTION__ , CURRENT_THREAD->trdid , local_cxy, |
---|
| 1068 | CURRENT_THREAD->core->lid , hal_time_stamp() ); |
---|
[296] | 1069 | |
---|
[238] | 1070 | // get client cluster identifier and pointer on RPC descriptor |
---|
| 1071 | cxy_t client_cxy = (cxy_t)GET_CXY( xp ); |
---|
| 1072 | rpc_desc_t * desc = (rpc_desc_t *)GET_PTR( xp ); |
---|
| 1073 | |
---|
| 1074 | // get arguments "parent", "name", and "child_xp" |
---|
| 1075 | parent = (vfs_inode_t*)(intptr_t)hal_remote_lwd(XPTR(client_cxy , &desc->args[0])); |
---|
| 1076 | name = (char*)(intptr_t) hal_remote_lwd(XPTR(client_cxy , &desc->args[1])); |
---|
| 1077 | child_xp = (xptr_t) hal_remote_lwd(XPTR(client_cxy , &desc->args[2])); |
---|
| 1078 | |
---|
| 1079 | // get name local copy |
---|
| 1080 | hal_remote_strcpy( XPTR( local_cxy , name_copy ) , |
---|
| 1081 | XPTR( client_cxy , name ) ); |
---|
| 1082 | |
---|
| 1083 | // call the kernel function |
---|
| 1084 | error = vfs_inode_load( parent , name_copy , child_xp ); |
---|
| 1085 | |
---|
| 1086 | // set output argument |
---|
| 1087 | hal_remote_swd( XPTR( client_cxy , &desc->args[3] ) , (uint64_t)error ); |
---|
[296] | 1088 | |
---|
[337] | 1089 | rpc_dmsg("\n[INFO] %s : exit / thread %x on core[%x,%d] / cycle %d\n", |
---|
| 1090 | __FUNCTION__ , CURRENT_THREAD->trdid , local_cxy, |
---|
| 1091 | CURRENT_THREAD->core->lid , hal_time_stamp() ); |
---|
[238] | 1092 | } |
---|
| 1093 | |
---|
| 1094 | ///////////////////////////////////////////////////////////////////////////////////////// |
---|
| 1095 | // [17] Marshaling functions attached to RPC_VFS_MAPPER_LOAD_ALL |
---|
| 1096 | ///////////////////////////////////////////////////////////////////////////////////////// |
---|
| 1097 | |
---|
| 1098 | /////////////////////////////////////////////////////// |
---|
| 1099 | void rpc_vfs_mapper_load_all_client( cxy_t cxy, |
---|
| 1100 | vfs_inode_t * inode, // in |
---|
| 1101 | error_t * error ) // out |
---|
| 1102 | { |
---|
[337] | 1103 | rpc_dmsg("\n[INFO] %s : enter / thread %x on core[%x,%d] / cycle %d\n", |
---|
| 1104 | __FUNCTION__ , CURRENT_THREAD->trdid , local_cxy, |
---|
| 1105 | CURRENT_THREAD->core->lid , hal_time_stamp() ); |
---|
[296] | 1106 | |
---|
[238] | 1107 | assert( (cxy != local_cxy) , __FUNCTION__ , "target cluster is not remote\n"); |
---|
| 1108 | |
---|
| 1109 | // initialise RPC descriptor header |
---|
| 1110 | rpc_desc_t rpc; |
---|
| 1111 | rpc.index = RPC_VFS_INODE_LOAD; |
---|
| 1112 | rpc.response = 1; |
---|
| 1113 | |
---|
| 1114 | // set input arguments in RPC descriptor |
---|
| 1115 | rpc.args[0] = (uint64_t)(intptr_t)inode; |
---|
| 1116 | |
---|
| 1117 | // register RPC request in remote RPC fifo (blocking function) |
---|
| 1118 | rpc_send_sync( cxy , &rpc ); |
---|
| 1119 | |
---|
| 1120 | // get output values from RPC descriptor |
---|
| 1121 | *error = (error_t)rpc.args[1]; |
---|
[279] | 1122 | |
---|
[337] | 1123 | rpc_dmsg("\n[INFO] %s : exit / thread %x on core[%x,%d] / cycle %d\n", |
---|
| 1124 | __FUNCTION__ , CURRENT_THREAD->trdid , local_cxy, |
---|
| 1125 | CURRENT_THREAD->core->lid , hal_time_stamp() ); |
---|
[238] | 1126 | } |
---|
| 1127 | |
---|
| 1128 | //////////////////////////////////////////////// |
---|
| 1129 | void rpc_vfs_mapper_load_all_server( xptr_t xp ) |
---|
| 1130 | { |
---|
| 1131 | error_t error; |
---|
| 1132 | vfs_inode_t * inode; |
---|
| 1133 | |
---|
[337] | 1134 | rpc_dmsg("\n[INFO] %s : enter / thread %x on core[%x,%d] / cycle %d\n", |
---|
| 1135 | __FUNCTION__ , CURRENT_THREAD->trdid , local_cxy, |
---|
| 1136 | CURRENT_THREAD->core->lid , hal_time_stamp() ); |
---|
[296] | 1137 | |
---|
[238] | 1138 | // get client cluster identifier and pointer on RPC descriptor |
---|
| 1139 | cxy_t client_cxy = (cxy_t)GET_CXY( xp ); |
---|
| 1140 | rpc_desc_t * desc = (rpc_desc_t *)GET_PTR( xp ); |
---|
| 1141 | |
---|
| 1142 | // get arguments "parent", "name", and "child_xp" |
---|
| 1143 | inode = (vfs_inode_t*)(intptr_t)hal_remote_lwd(XPTR(client_cxy , &desc->args[0])); |
---|
| 1144 | |
---|
| 1145 | // call the kernel function |
---|
| 1146 | error = vfs_mapper_load_all( inode ); |
---|
| 1147 | |
---|
| 1148 | // set output argument |
---|
| 1149 | hal_remote_swd( XPTR( client_cxy , &desc->args[3] ) , (uint64_t)error ); |
---|
[296] | 1150 | |
---|
[337] | 1151 | rpc_dmsg("\n[INFO] %s : exit / thread %x on core[%x,%d] / cycle %d\n", |
---|
| 1152 | __FUNCTION__ , CURRENT_THREAD->trdid , local_cxy, |
---|
| 1153 | CURRENT_THREAD->core->lid , hal_time_stamp() ); |
---|
[238] | 1154 | } |
---|
| 1155 | |
---|
| 1156 | ///////////////////////////////////////////////////////////////////////////////////////// |
---|
| 1157 | // [18] Marshaling functions attached to RPC_FATFS_GET_CLUSTER |
---|
| 1158 | ///////////////////////////////////////////////////////////////////////////////////////// |
---|
| 1159 | |
---|
| 1160 | ////////////////////////////////////////////////// |
---|
[23] | 1161 | void rpc_fatfs_get_cluster_client( cxy_t cxy, |
---|
| 1162 | mapper_t * mapper, // in |
---|
| 1163 | uint32_t first, // in |
---|
| 1164 | uint32_t page, // in |
---|
| 1165 | uint32_t * cluster, // out |
---|
| 1166 | error_t * error ) // out |
---|
| 1167 | { |
---|
[337] | 1168 | rpc_dmsg("\n[INFO] %s : enter / thread %x on core[%x,%d] / cycle %d\n", |
---|
| 1169 | __FUNCTION__ , CURRENT_THREAD->trdid , local_cxy, |
---|
| 1170 | CURRENT_THREAD->core->lid , hal_time_stamp() ); |
---|
[296] | 1171 | |
---|
[238] | 1172 | assert( (cxy != local_cxy) , __FUNCTION__ , "target cluster is not remote\n"); |
---|
[23] | 1173 | |
---|
| 1174 | // initialise RPC descriptor header |
---|
| 1175 | rpc_desc_t rpc; |
---|
| 1176 | rpc.index = RPC_FATFS_GET_CLUSTER; |
---|
| 1177 | rpc.response = 1; |
---|
| 1178 | |
---|
| 1179 | // set input arguments in RPC descriptor |
---|
| 1180 | rpc.args[0] = (uint64_t)(intptr_t)mapper; |
---|
| 1181 | rpc.args[1] = (uint64_t)first; |
---|
| 1182 | rpc.args[2] = (uint64_t)page; |
---|
| 1183 | |
---|
| 1184 | // register RPC request in remote RPC fifo |
---|
| 1185 | rpc_send_sync( cxy , &rpc ); |
---|
| 1186 | |
---|
| 1187 | // get output argument from rpc descriptor |
---|
| 1188 | *cluster = (uint32_t)rpc.args[3]; |
---|
| 1189 | *error = (error_t)rpc.args[4]; |
---|
[279] | 1190 | |
---|
[337] | 1191 | rpc_dmsg("\n[INFO] %s : exit / thread %x on core[%x,%d] / cycle %d\n", |
---|
| 1192 | __FUNCTION__ , CURRENT_THREAD->trdid , local_cxy, |
---|
| 1193 | CURRENT_THREAD->core->lid , hal_time_stamp() ); |
---|
[23] | 1194 | } |
---|
| 1195 | |
---|
| 1196 | ////////////////////////////////////////////// |
---|
| 1197 | void rpc_fatfs_get_cluster_server( xptr_t xp ) |
---|
| 1198 | { |
---|
| 1199 | mapper_t * mapper; |
---|
| 1200 | uint32_t first; |
---|
| 1201 | uint32_t page; |
---|
| 1202 | uint32_t cluster; |
---|
| 1203 | error_t error; |
---|
| 1204 | |
---|
[337] | 1205 | rpc_dmsg("\n[INFO] %s : enter / thread %x on core[%x,%d] / cycle %d\n", |
---|
| 1206 | __FUNCTION__ , CURRENT_THREAD->trdid , local_cxy, |
---|
| 1207 | CURRENT_THREAD->core->lid , hal_time_stamp() ); |
---|
[296] | 1208 | |
---|
[23] | 1209 | // get client cluster identifier and pointer on RPC descriptor |
---|
| 1210 | cxy_t client_cxy = (cxy_t)GET_CXY( xp ); |
---|
| 1211 | rpc_desc_t * desc = (rpc_desc_t *)GET_PTR( xp ); |
---|
| 1212 | |
---|
| 1213 | // get input arguments |
---|
| 1214 | mapper = (mapper_t *)(intptr_t)hal_remote_lpt( XPTR( client_cxy , &desc->args[0] ) ); |
---|
| 1215 | first = (uint32_t) hal_remote_lw ( XPTR( client_cxy , &desc->args[1] ) ); |
---|
| 1216 | page = (uint32_t) hal_remote_lw ( XPTR( client_cxy , &desc->args[2] ) ); |
---|
| 1217 | |
---|
| 1218 | // call the kernel function |
---|
| 1219 | error = fatfs_get_cluster( mapper , first , page , &cluster ); |
---|
| 1220 | |
---|
| 1221 | // set output argument |
---|
| 1222 | hal_remote_swd( XPTR( client_cxy , &desc->args[3] ) , (uint64_t)cluster ); |
---|
| 1223 | hal_remote_swd( XPTR( client_cxy , &desc->args[4] ) , (uint64_t)error ); |
---|
[296] | 1224 | |
---|
[337] | 1225 | rpc_dmsg("\n[INFO] %s : exit / thread %x on core[%x,%d] / cycle %d\n", |
---|
| 1226 | __FUNCTION__ , CURRENT_THREAD->trdid , local_cxy, |
---|
| 1227 | CURRENT_THREAD->core->lid , hal_time_stamp() ); |
---|
[23] | 1228 | } |
---|
| 1229 | |
---|
| 1230 | ///////////////////////////////////////////////////////////////////////////////////////// |
---|
| 1231 | // [20] Marshaling functions attached to RPC_VMM_GET_REF_VSEG |
---|
| 1232 | ///////////////////////////////////////////////////////////////////////////////////////// |
---|
| 1233 | |
---|
| 1234 | ////////////////////////////////////////////////// |
---|
[1] | 1235 | void rpc_vmm_get_ref_vseg_client( cxy_t cxy, |
---|
| 1236 | process_t * process, // in |
---|
| 1237 | intptr_t vaddr, // in |
---|
| 1238 | xptr_t * vseg_xp ) // out |
---|
| 1239 | { |
---|
[337] | 1240 | rpc_dmsg("\n[INFO] %s : enter / thread %x on core[%x,%d] / cycle %d\n", |
---|
| 1241 | __FUNCTION__ , CURRENT_THREAD->trdid , local_cxy, |
---|
| 1242 | CURRENT_THREAD->core->lid , hal_time_stamp() ); |
---|
[296] | 1243 | |
---|
[238] | 1244 | assert( (cxy != local_cxy) , __FUNCTION__ , "target cluster is not remote\n"); |
---|
[1] | 1245 | |
---|
| 1246 | // initialise RPC descriptor header |
---|
| 1247 | rpc_desc_t rpc; |
---|
| 1248 | rpc.index = RPC_VMM_GET_REF_VSEG; |
---|
| 1249 | rpc.response = 1; |
---|
| 1250 | |
---|
| 1251 | // set input arguments in RPC descriptor |
---|
| 1252 | rpc.args[0] = (uint64_t)(intptr_t)process; |
---|
| 1253 | rpc.args[1] = (uint64_t)vaddr; |
---|
| 1254 | |
---|
| 1255 | // register RPC request in remote RPC fifo (blocking function) |
---|
| 1256 | rpc_send_sync( cxy , &rpc ); |
---|
| 1257 | |
---|
| 1258 | // get output argument from rpc descriptor |
---|
| 1259 | *vseg_xp = rpc.args[2]; |
---|
[279] | 1260 | |
---|
[337] | 1261 | rpc_dmsg("\n[INFO] %s : exit / thread %x on core[%x,%d] / cycle %d\n", |
---|
| 1262 | __FUNCTION__ , CURRENT_THREAD->trdid , local_cxy, |
---|
| 1263 | CURRENT_THREAD->core->lid , hal_time_stamp() ); |
---|
[1] | 1264 | } |
---|
| 1265 | |
---|
| 1266 | ///////////////////////////////////////////// |
---|
| 1267 | void rpc_vmm_get_ref_vseg_server( xptr_t xp ) |
---|
| 1268 | { |
---|
| 1269 | process_t * process; |
---|
| 1270 | intptr_t vaddr; |
---|
| 1271 | vseg_t * vseg_ptr; |
---|
| 1272 | xptr_t vseg_xp; |
---|
| 1273 | |
---|
[337] | 1274 | rpc_dmsg("\n[INFO] %s : enter / thread %x on core[%x,%d] / cycle %d\n", |
---|
| 1275 | __FUNCTION__ , CURRENT_THREAD->trdid , local_cxy, |
---|
| 1276 | CURRENT_THREAD->core->lid , hal_time_stamp() ); |
---|
[296] | 1277 | |
---|
[1] | 1278 | // get client cluster identifier and pointer on RPC descriptor |
---|
| 1279 | cxy_t client_cxy = (cxy_t)GET_CXY( xp ); |
---|
| 1280 | rpc_desc_t * desc = (rpc_desc_t *)GET_PTR( xp ); |
---|
| 1281 | |
---|
| 1282 | // get input argument from client RPC descriptor |
---|
| 1283 | process = (process_t *)(intptr_t)hal_remote_lwd( XPTR( client_cxy , &desc->args[0] ) ); |
---|
| 1284 | vaddr = (intptr_t)hal_remote_lwd( XPTR( client_cxy , &desc->args[1] ) ); |
---|
| 1285 | |
---|
| 1286 | // call local kernel function |
---|
| 1287 | vseg_ptr = vmm_get_vseg( process , vaddr ); |
---|
| 1288 | |
---|
| 1289 | // set output argument to client RPC descriptor |
---|
[16] | 1290 | if( vseg_ptr == NULL ) vseg_xp = XPTR_NULL; |
---|
| 1291 | else vseg_xp = XPTR( local_cxy , vseg_ptr ); |
---|
[1] | 1292 | hal_remote_swd( XPTR( client_cxy , &desc->args[2] ) , (uint64_t)vseg_xp ); |
---|
[296] | 1293 | |
---|
[337] | 1294 | rpc_dmsg("\n[INFO] %s : exit / thread %x on core[%x,%d] / cycle %d\n", |
---|
| 1295 | __FUNCTION__ , CURRENT_THREAD->trdid , local_cxy, |
---|
| 1296 | CURRENT_THREAD->core->lid , hal_time_stamp() ); |
---|
[1] | 1297 | } |
---|
| 1298 | |
---|
| 1299 | |
---|
| 1300 | ///////////////////////////////////////////////////////////////////////////////////////// |
---|
[23] | 1301 | // [21] Marshaling functions attached to RPC_VMM_GET_PTE |
---|
[1] | 1302 | ///////////////////////////////////////////////////////////////////////////////////////// |
---|
| 1303 | |
---|
| 1304 | //////////////////////////////////////////// |
---|
| 1305 | void rpc_vmm_get_pte_client( cxy_t cxy, |
---|
| 1306 | process_t * process, // in |
---|
| 1307 | vpn_t vpn, // in |
---|
| 1308 | uint32_t * attr, // out |
---|
| 1309 | ppn_t * ppn, // out |
---|
| 1310 | error_t * error ) // out |
---|
| 1311 | { |
---|
[337] | 1312 | rpc_dmsg("\n[INFO] %s : enter / thread %x on core[%x,%d] / cycle %d\n", |
---|
| 1313 | __FUNCTION__ , CURRENT_THREAD->trdid , local_cxy, |
---|
| 1314 | CURRENT_THREAD->core->lid , hal_time_stamp() ); |
---|
[296] | 1315 | |
---|
[238] | 1316 | assert( (cxy != local_cxy) , __FUNCTION__ , "target cluster is not remote\n"); |
---|
[1] | 1317 | |
---|
| 1318 | // initialise RPC descriptor header |
---|
| 1319 | rpc_desc_t rpc; |
---|
| 1320 | rpc.index = RPC_VMM_GET_PTE; |
---|
| 1321 | rpc.response = 1; |
---|
| 1322 | |
---|
| 1323 | // set input arguments in RPC descriptor |
---|
| 1324 | rpc.args[0] = (uint64_t)(intptr_t)process; |
---|
| 1325 | rpc.args[1] = (uint64_t)vpn; |
---|
| 1326 | |
---|
| 1327 | // register RPC request in remote RPC fifo (blocking function) |
---|
| 1328 | rpc_send_sync( cxy , &rpc ); |
---|
| 1329 | |
---|
| 1330 | // get output argument from rpc descriptor |
---|
| 1331 | *attr = (uint32_t)rpc.args[2]; |
---|
| 1332 | *ppn = (ppn_t)rpc.args[3]; |
---|
| 1333 | *error = (error_t)rpc.args[4]; |
---|
[279] | 1334 | |
---|
[337] | 1335 | rpc_dmsg("\n[INFO] %s : exit / thread %x on core[%x,%d] / cycle %d\n", |
---|
| 1336 | __FUNCTION__ , CURRENT_THREAD->trdid , local_cxy, |
---|
| 1337 | CURRENT_THREAD->core->lid , hal_time_stamp() ); |
---|
[1] | 1338 | } |
---|
| 1339 | |
---|
| 1340 | //////////////////////////////////////// |
---|
| 1341 | void rpc_vmm_get_pte_server( xptr_t xp ) |
---|
| 1342 | { |
---|
| 1343 | process_t * process; |
---|
| 1344 | vpn_t vpn; |
---|
| 1345 | uint32_t attr; |
---|
| 1346 | ppn_t ppn; |
---|
| 1347 | error_t error; |
---|
| 1348 | |
---|
[337] | 1349 | rpc_dmsg("\n[INFO] %s : enter / thread %x on core[%x,%d] / cycle %d\n", |
---|
| 1350 | __FUNCTION__ , CURRENT_THREAD->trdid , local_cxy, |
---|
| 1351 | CURRENT_THREAD->core->lid , hal_time_stamp() ); |
---|
[296] | 1352 | |
---|
[1] | 1353 | // get client cluster identifier and pointer on RPC descriptor |
---|
| 1354 | cxy_t client_cxy = (cxy_t)GET_CXY( xp ); |
---|
| 1355 | rpc_desc_t * desc = (rpc_desc_t *)GET_PTR( xp ); |
---|
| 1356 | |
---|
| 1357 | // get input argument "process" & "vpn" from client RPC descriptor |
---|
| 1358 | process = (process_t *)(intptr_t)hal_remote_lwd( XPTR( client_cxy , &desc->args[0] ) ); |
---|
| 1359 | vpn = (vpn_t) hal_remote_lwd( XPTR( client_cxy , &desc->args[1] ) ); |
---|
| 1360 | |
---|
| 1361 | // call local kernel function |
---|
| 1362 | error = vmm_get_pte( process , vpn , &attr , &ppn ); |
---|
| 1363 | |
---|
| 1364 | // set output argument "attr" & "ppn" to client RPC descriptor |
---|
| 1365 | hal_remote_swd( XPTR( client_cxy , &desc->args[2] ) , (uint64_t)attr ); |
---|
| 1366 | hal_remote_swd( XPTR( client_cxy , &desc->args[3] ) , (uint64_t)ppn ); |
---|
| 1367 | hal_remote_swd( XPTR( client_cxy , &desc->args[4] ) , (uint64_t)error ); |
---|
[296] | 1368 | |
---|
[337] | 1369 | rpc_dmsg("\n[INFO] %s : exit / thread %x on core[%x,%d] / cycle %d\n", |
---|
| 1370 | __FUNCTION__ , CURRENT_THREAD->trdid , local_cxy, |
---|
| 1371 | CURRENT_THREAD->core->lid , hal_time_stamp() ); |
---|
[1] | 1372 | } |
---|
| 1373 | |
---|
| 1374 | ///////////////////////////////////////////////////////////////////////////////////////// |
---|
[23] | 1375 | // [22] Marshaling functions attached to RPC_KCM_ALLOC |
---|
[1] | 1376 | ///////////////////////////////////////////////////////////////////////////////////////// |
---|
| 1377 | |
---|
[23] | 1378 | ////////////////////////////////////////// |
---|
| 1379 | void rpc_kcm_alloc_client( cxy_t cxy, |
---|
| 1380 | uint32_t kmem_type, // in |
---|
| 1381 | xptr_t * buf_xp ) // out |
---|
[1] | 1382 | { |
---|
[337] | 1383 | rpc_dmsg("\n[INFO] %s : enter / thread %x on core[%x,%d] / cycle %d\n", |
---|
| 1384 | __FUNCTION__ , CURRENT_THREAD->trdid , local_cxy, |
---|
| 1385 | CURRENT_THREAD->core->lid , hal_time_stamp() ); |
---|
[296] | 1386 | |
---|
[238] | 1387 | assert( (cxy != local_cxy) , __FUNCTION__ , "target cluster is not remote\n"); |
---|
[1] | 1388 | |
---|
| 1389 | // initialise RPC descriptor header |
---|
| 1390 | rpc_desc_t rpc; |
---|
| 1391 | rpc.index = RPC_THREAD_USER_CREATE; |
---|
| 1392 | rpc.response = 1; |
---|
| 1393 | |
---|
[23] | 1394 | // set input arguments in RPC descriptor |
---|
| 1395 | rpc.args[0] = (uint64_t)kmem_type; |
---|
| 1396 | |
---|
[1] | 1397 | // register RPC request in remote RPC fifo |
---|
| 1398 | rpc_send_sync( cxy , &rpc ); |
---|
| 1399 | |
---|
| 1400 | // get output arguments from RPC descriptor |
---|
[23] | 1401 | *buf_xp = (xptr_t)rpc.args[1]; |
---|
[279] | 1402 | |
---|
[337] | 1403 | rpc_dmsg("\n[INFO] %s : exit / thread %x on core[%x,%d] / cycle %d\n", |
---|
| 1404 | __FUNCTION__ , CURRENT_THREAD->trdid , local_cxy, |
---|
| 1405 | CURRENT_THREAD->core->lid , hal_time_stamp() ); |
---|
[1] | 1406 | } |
---|
| 1407 | |
---|
[23] | 1408 | ////////////////////////////////////// |
---|
| 1409 | void rpc_kcm_alloc_server( xptr_t xp ) |
---|
[1] | 1410 | { |
---|
[337] | 1411 | rpc_dmsg("\n[INFO] %s : enter / thread %x on core[%x,%d] / cycle %d\n", |
---|
| 1412 | __FUNCTION__ , CURRENT_THREAD->trdid , local_cxy, |
---|
| 1413 | CURRENT_THREAD->core->lid , hal_time_stamp() ); |
---|
[296] | 1414 | |
---|
[1] | 1415 | // get client cluster identifier and pointer on RPC descriptor |
---|
| 1416 | cxy_t client_cxy = (cxy_t)GET_CXY( xp ); |
---|
| 1417 | rpc_desc_t * desc = (rpc_desc_t *)GET_PTR( xp ); |
---|
| 1418 | |
---|
[23] | 1419 | // get input argument "kmem_type" from client RPC descriptor |
---|
| 1420 | uint32_t kmem_type = (uint32_t)hal_remote_lwd( XPTR( client_cxy , &desc->args[0] ) ); |
---|
| 1421 | |
---|
| 1422 | // allocates memory for kcm |
---|
[1] | 1423 | kmem_req_t req; |
---|
[23] | 1424 | req.type = kmem_type; |
---|
[1] | 1425 | req.flags = AF_ZERO; |
---|
[23] | 1426 | void * buf_ptr = kmem_alloc( &req ); |
---|
[1] | 1427 | |
---|
| 1428 | // set output argument |
---|
[23] | 1429 | xptr_t buf_xp = XPTR( local_cxy , buf_ptr ); |
---|
| 1430 | hal_remote_swd( XPTR( client_cxy , &desc->args[1] ) , (uint64_t)buf_xp ); |
---|
[296] | 1431 | |
---|
[337] | 1432 | rpc_dmsg("\n[INFO] %s : exit / thread %x on core[%x,%d] / cycle %d\n", |
---|
| 1433 | __FUNCTION__ , CURRENT_THREAD->trdid , local_cxy, |
---|
| 1434 | CURRENT_THREAD->core->lid , hal_time_stamp() ); |
---|
[1] | 1435 | } |
---|
| 1436 | |
---|
| 1437 | ///////////////////////////////////////////////////////////////////////////////////////// |
---|
[23] | 1438 | // [23] Marshaling functions attached to RPC_KCM_FREE |
---|
[1] | 1439 | ///////////////////////////////////////////////////////////////////////////////////////// |
---|
| 1440 | |
---|
[23] | 1441 | ///////////////////////////////////////// |
---|
| 1442 | void rpc_kcm_free_client( cxy_t cxy, |
---|
| 1443 | void * buf, // in |
---|
| 1444 | uint32_t kmem_type ) // in |
---|
[1] | 1445 | { |
---|
[337] | 1446 | rpc_dmsg("\n[INFO] %s : enter / thread %x on core[%x,%d] / cycle %d\n", |
---|
| 1447 | __FUNCTION__ , CURRENT_THREAD->trdid , local_cxy, |
---|
| 1448 | CURRENT_THREAD->core->lid , hal_time_stamp() ); |
---|
[296] | 1449 | |
---|
[238] | 1450 | assert( (cxy != local_cxy) , __FUNCTION__ , "target cluster is not remote\n"); |
---|
[1] | 1451 | |
---|
| 1452 | // initialise RPC descriptor header |
---|
| 1453 | rpc_desc_t rpc; |
---|
| 1454 | rpc.index = RPC_THREAD_USER_CREATE; |
---|
| 1455 | rpc.response = 1; |
---|
| 1456 | |
---|
| 1457 | // set input arguments in RPC descriptor |
---|
[23] | 1458 | rpc.args[0] = (uint64_t)(intptr_t)buf; |
---|
| 1459 | rpc.args[1] = (uint64_t)kmem_type; |
---|
[1] | 1460 | |
---|
| 1461 | // register RPC request in remote RPC fifo |
---|
| 1462 | rpc_send_sync( cxy , &rpc ); |
---|
[279] | 1463 | |
---|
[337] | 1464 | rpc_dmsg("\n[INFO] %s : exit / thread %x on core[%x,%d] / cycle %d\n", |
---|
| 1465 | __FUNCTION__ , CURRENT_THREAD->trdid , local_cxy, |
---|
| 1466 | CURRENT_THREAD->core->lid , hal_time_stamp() ); |
---|
[1] | 1467 | } |
---|
| 1468 | |
---|
[23] | 1469 | ///////////////////////////////////// |
---|
| 1470 | void rpc_kcm_free_server( xptr_t xp ) |
---|
[1] | 1471 | { |
---|
[337] | 1472 | rpc_dmsg("\n[INFO] %s : enter / thread %x on core[%x,%d] / cycle %d\n", |
---|
| 1473 | __FUNCTION__ , CURRENT_THREAD->trdid , local_cxy, |
---|
| 1474 | CURRENT_THREAD->core->lid , hal_time_stamp() ); |
---|
[296] | 1475 | |
---|
[1] | 1476 | // get client cluster identifier and pointer on RPC descriptor |
---|
| 1477 | cxy_t client_cxy = (cxy_t)GET_CXY( xp ); |
---|
| 1478 | rpc_desc_t * desc = (rpc_desc_t *)GET_PTR( xp ); |
---|
| 1479 | |
---|
[23] | 1480 | // get input arguments "buf" and "kmem_type" from client RPC descriptor |
---|
| 1481 | void * buf = (void *)(intptr_t)hal_remote_lwd( XPTR( client_cxy , &desc->args[0] ) ); |
---|
| 1482 | uint32_t kmem_type = (uint32_t)hal_remote_lwd( XPTR( client_cxy , &desc->args[1] ) ); |
---|
[1] | 1483 | |
---|
| 1484 | // releases memory |
---|
| 1485 | kmem_req_t req; |
---|
[23] | 1486 | req.type = kmem_type; |
---|
| 1487 | req.ptr = buf; |
---|
| 1488 | kmem_free( &req ); |
---|
[296] | 1489 | |
---|
[337] | 1490 | rpc_dmsg("\n[INFO] %s : exit / thread %x on core[%x,%d] / cycle %d\n", |
---|
| 1491 | __FUNCTION__ , CURRENT_THREAD->trdid , local_cxy, |
---|
| 1492 | CURRENT_THREAD->core->lid , hal_time_stamp() ); |
---|
[1] | 1493 | } |
---|
| 1494 | |
---|
| 1495 | ///////////////////////////////////////////////////////////////////////////////////////// |
---|
[265] | 1496 | // [24] Marshaling functions attached to RPC_MAPPER_MOVE_BUFFER |
---|
[1] | 1497 | ///////////////////////////////////////////////////////////////////////////////////////// |
---|
| 1498 | |
---|
[265] | 1499 | /////////////////////////////////////////////////// |
---|
| 1500 | void rpc_mapper_move_buffer_client( cxy_t cxy, |
---|
| 1501 | mapper_t * mapper, // in |
---|
| 1502 | bool_t to_buffer, // in |
---|
| 1503 | bool_t is_user, // in |
---|
| 1504 | uint32_t file_offset, // in |
---|
[313] | 1505 | uint64_t buffer, // in |
---|
[265] | 1506 | uint32_t size, // in |
---|
| 1507 | error_t * error ) // out |
---|
[1] | 1508 | { |
---|
[337] | 1509 | rpc_dmsg("\n[INFO] %s : enter / thread %x on core[%x,%d] / cycle %d\n", |
---|
| 1510 | __FUNCTION__ , CURRENT_THREAD->trdid , local_cxy, |
---|
| 1511 | CURRENT_THREAD->core->lid , hal_time_stamp() ); |
---|
[296] | 1512 | |
---|
[238] | 1513 | assert( (cxy != local_cxy) , __FUNCTION__ , "target cluster is not remote\n"); |
---|
[1] | 1514 | |
---|
| 1515 | // initialise RPC descriptor header |
---|
| 1516 | rpc_desc_t rpc; |
---|
[265] | 1517 | rpc.index = RPC_MAPPER_MOVE_BUFFER; |
---|
[1] | 1518 | rpc.response = 1; |
---|
| 1519 | |
---|
| 1520 | // set input arguments in RPC descriptor |
---|
| 1521 | rpc.args[0] = (uint64_t)(intptr_t)mapper; |
---|
[23] | 1522 | rpc.args[1] = (uint64_t)to_buffer; |
---|
[265] | 1523 | rpc.args[2] = (uint64_t)is_user; |
---|
| 1524 | rpc.args[3] = (uint64_t)file_offset; |
---|
[313] | 1525 | rpc.args[4] = (uint64_t)buffer; |
---|
[265] | 1526 | rpc.args[5] = (uint64_t)size; |
---|
[1] | 1527 | |
---|
[23] | 1528 | // register RPC request in remote RPC fifo (blocking function) |
---|
[1] | 1529 | rpc_send_sync( cxy , &rpc ); |
---|
| 1530 | |
---|
[23] | 1531 | // get output values from RPC descriptor |
---|
[265] | 1532 | *error = (error_t)rpc.args[6]; |
---|
[279] | 1533 | |
---|
[337] | 1534 | rpc_dmsg("\n[INFO] %s : exit / thread %x on core[%x,%d] / cycle %d\n", |
---|
| 1535 | __FUNCTION__ , CURRENT_THREAD->trdid , local_cxy, |
---|
| 1536 | CURRENT_THREAD->core->lid , hal_time_stamp() ); |
---|
[1] | 1537 | } |
---|
| 1538 | |
---|
[265] | 1539 | /////////////////////////////////////////////// |
---|
| 1540 | void rpc_mapper_move_buffer_server( xptr_t xp ) |
---|
[1] | 1541 | { |
---|
[23] | 1542 | mapper_t * mapper; |
---|
[265] | 1543 | bool_t to_buffer; |
---|
| 1544 | bool_t is_user; |
---|
[23] | 1545 | uint32_t file_offset; |
---|
[313] | 1546 | void * user_buffer; |
---|
| 1547 | xptr_t kern_buffer; |
---|
[23] | 1548 | uint32_t size; |
---|
| 1549 | error_t error; |
---|
[1] | 1550 | |
---|
[337] | 1551 | rpc_dmsg("\n[INFO] %s : enter / thread %x on core[%x,%d] / cycle %d\n", |
---|
| 1552 | __FUNCTION__ , CURRENT_THREAD->trdid , local_cxy, |
---|
| 1553 | CURRENT_THREAD->core->lid , hal_time_stamp() ); |
---|
[296] | 1554 | |
---|
[1] | 1555 | // get client cluster identifier and pointer on RPC descriptor |
---|
| 1556 | cxy_t client_cxy = (cxy_t)GET_CXY( xp ); |
---|
[23] | 1557 | rpc_desc_t * desc = (rpc_desc_t *)GET_PTR( xp ); |
---|
[1] | 1558 | |
---|
[23] | 1559 | // get arguments from client RPC descriptor |
---|
| 1560 | mapper = (mapper_t *)(intptr_t)hal_remote_lwd( XPTR( client_cxy , &desc->args[0] ) ); |
---|
| 1561 | to_buffer = hal_remote_lwd( XPTR( client_cxy , &desc->args[1] ) ); |
---|
[265] | 1562 | is_user = hal_remote_lwd( XPTR( client_cxy , &desc->args[2] ) ); |
---|
| 1563 | file_offset = hal_remote_lwd( XPTR( client_cxy , &desc->args[3] ) ); |
---|
| 1564 | size = hal_remote_lwd( XPTR( client_cxy , &desc->args[5] ) ); |
---|
[1] | 1565 | |
---|
[23] | 1566 | // call local kernel function |
---|
[313] | 1567 | if( is_user ) |
---|
| 1568 | { |
---|
| 1569 | user_buffer = (void *)(intptr_t)hal_remote_lwd( XPTR( client_cxy , &desc->args[4] ) ); |
---|
[1] | 1570 | |
---|
[315] | 1571 | error = mapper_move_user( mapper, |
---|
| 1572 | to_buffer, |
---|
| 1573 | file_offset, |
---|
| 1574 | user_buffer, |
---|
| 1575 | size ); |
---|
[313] | 1576 | } |
---|
| 1577 | else |
---|
| 1578 | { |
---|
| 1579 | kern_buffer = (xptr_t)hal_remote_lwd( XPTR( client_cxy , &desc->args[4] ) ); |
---|
| 1580 | |
---|
[315] | 1581 | error = mapper_move_kernel( mapper, |
---|
| 1582 | to_buffer, |
---|
| 1583 | file_offset, |
---|
| 1584 | kern_buffer, |
---|
| 1585 | size ); |
---|
[313] | 1586 | } |
---|
| 1587 | |
---|
[23] | 1588 | // set output argument to client RPC descriptor |
---|
[265] | 1589 | hal_remote_swd( XPTR( client_cxy , &desc->args[6] ) , (uint64_t)error ); |
---|
[296] | 1590 | |
---|
[337] | 1591 | rpc_dmsg("\n[INFO] %s : exit / thread %x on core[%x,%d] / cycle %d\n", |
---|
| 1592 | __FUNCTION__ , CURRENT_THREAD->trdid , local_cxy, |
---|
| 1593 | CURRENT_THREAD->core->lid , hal_time_stamp() ); |
---|
[1] | 1594 | } |
---|
| 1595 | |
---|
[313] | 1596 | ///////////////////////////////////////////////////////////////////////////////////////// |
---|
| 1597 | // [25] Marshaling functions attached to RPC_MAPPER_GET_PAGE |
---|
| 1598 | ///////////////////////////////////////////////////////////////////////////////////////// |
---|
| 1599 | |
---|
| 1600 | /////////////////////////////////////////////////////// |
---|
| 1601 | void rpc_mapper_get_page_client( cxy_t cxy, |
---|
| 1602 | struct mapper_s * mapper, // in |
---|
| 1603 | uint32_t index, // in |
---|
| 1604 | page_t ** page ) // out |
---|
| 1605 | { |
---|
[337] | 1606 | rpc_dmsg("\n[INFO] %s : enter / thread %x on core[%x,%d] / cycle %d\n", |
---|
| 1607 | __FUNCTION__ , CURRENT_THREAD->trdid , local_cxy, |
---|
| 1608 | CURRENT_THREAD->core->lid , hal_time_stamp() ); |
---|
[313] | 1609 | |
---|
| 1610 | assert( (cxy != local_cxy) , __FUNCTION__ , "target cluster is not remote\n"); |
---|
| 1611 | |
---|
| 1612 | // initialise RPC descriptor header |
---|
| 1613 | rpc_desc_t rpc; |
---|
| 1614 | rpc.index = RPC_MAPPER_GET_PAGE; |
---|
| 1615 | rpc.response = 1; |
---|
| 1616 | |
---|
| 1617 | // set input arguments in RPC descriptor |
---|
| 1618 | rpc.args[0] = (uint64_t)(intptr_t)mapper; |
---|
| 1619 | rpc.args[1] = (uint64_t)index; |
---|
| 1620 | |
---|
| 1621 | // register RPC request in remote RPC fifo (blocking function) |
---|
| 1622 | rpc_send_sync( cxy , &rpc ); |
---|
| 1623 | |
---|
| 1624 | // get output values from RPC descriptor |
---|
| 1625 | *page = (page_t *)(intptr_t)rpc.args[2]; |
---|
| 1626 | |
---|
[337] | 1627 | rpc_dmsg("\n[INFO] %s : exit / thread %x on core[%x,%d] / cycle %d\n", |
---|
| 1628 | __FUNCTION__ , CURRENT_THREAD->trdid , local_cxy, |
---|
| 1629 | CURRENT_THREAD->core->lid , hal_time_stamp() ); |
---|
[313] | 1630 | } |
---|
| 1631 | |
---|
| 1632 | //////////////////////////////////////////// |
---|
| 1633 | void rpc_mapper_get_page_server( xptr_t xp ) |
---|
| 1634 | { |
---|
[337] | 1635 | rpc_dmsg("\n[INFO] %s : enter / thread %x on core[%x,%d] / cycle %d\n", |
---|
| 1636 | __FUNCTION__ , CURRENT_THREAD->trdid , local_cxy, |
---|
| 1637 | CURRENT_THREAD->core->lid , hal_time_stamp() ); |
---|
[313] | 1638 | |
---|
| 1639 | // get client cluster identifier and pointer on RPC descriptor |
---|
| 1640 | cxy_t cxy = (cxy_t)GET_CXY( xp ); |
---|
| 1641 | rpc_desc_t * desc = (rpc_desc_t *)GET_PTR( xp ); |
---|
| 1642 | |
---|
| 1643 | // get input arguments from client RPC descriptor |
---|
| 1644 | mapper_t * mapper = (mapper_t *)(intptr_t)hal_remote_lwd( XPTR( cxy , &desc->args[0] ) ); |
---|
| 1645 | uint32_t index = (uint32_t) hal_remote_lwd( XPTR( cxy , &desc->args[1] ) ); |
---|
| 1646 | |
---|
| 1647 | // call local pmem allocator |
---|
| 1648 | page_t * page = mapper_get_page( mapper , index ); |
---|
| 1649 | |
---|
| 1650 | // set output arguments into client RPC descriptor |
---|
| 1651 | hal_remote_swd( XPTR( cxy , &desc->args[1] ) , (uint64_t)(intptr_t)page ); |
---|
| 1652 | |
---|
[337] | 1653 | rpc_dmsg("\n[INFO] %s : exit / thread %x on core[%x,%d] / cycle %d\n", |
---|
| 1654 | __FUNCTION__ , CURRENT_THREAD->trdid , local_cxy, |
---|
| 1655 | CURRENT_THREAD->core->lid , hal_time_stamp() ); |
---|
[313] | 1656 | } |
---|
| 1657 | |
---|
| 1658 | |
---|
[1] | 1659 | /***************************************************************************************/ |
---|
| 1660 | /************ Generic functions supporting RPCs : client side **************************/ |
---|
| 1661 | /***************************************************************************************/ |
---|
| 1662 | |
---|
| 1663 | //////////////////////////////////////////// |
---|
| 1664 | void rpc_send_sync( cxy_t server_cxy, |
---|
| 1665 | rpc_desc_t * rpc ) |
---|
| 1666 | { |
---|
| 1667 | uint32_t cores; |
---|
| 1668 | error_t error; |
---|
| 1669 | bool_t first; |
---|
| 1670 | reg_t sr_save; |
---|
| 1671 | |
---|
[337] | 1672 | rpcg_dmsg("\n[INFO] %s : enter / client_cxy = %x / server_cxy = %x / cycle %d\n", |
---|
[296] | 1673 | __FUNCTION__ , local_cxy , server_cxy , hal_time_stamp() ); |
---|
[279] | 1674 | |
---|
[1] | 1675 | // allocate and initialise an extended pointer on the RPC descriptor |
---|
[279] | 1676 | xptr_t desc_xp = XPTR( local_cxy , rpc ); |
---|
[1] | 1677 | |
---|
[279] | 1678 | // get local pointer on rpc_fifo in remote cluster, with the |
---|
| 1679 | // assumption that rpc_fifo pddresses are identical in all clusters |
---|
[1] | 1680 | rpc_fifo_t * rf = &LOCAL_CLUSTER->rpc_fifo; |
---|
| 1681 | |
---|
| 1682 | // try to post an item in remote fifo |
---|
| 1683 | // deschedule and retry if remote fifo full |
---|
| 1684 | do |
---|
| 1685 | { |
---|
| 1686 | error = remote_fifo_put_item( XPTR( server_cxy , &rf->fifo ), |
---|
[279] | 1687 | (uint64_t )desc_xp, |
---|
[1] | 1688 | &first ); |
---|
| 1689 | if ( error ) |
---|
| 1690 | { |
---|
[279] | 1691 | printk("\n[WARNING] %s : cluster %x cannot post RPC to cluster %x\n", |
---|
[296] | 1692 | __FUNCTION__ , local_cxy , server_cxy ); |
---|
[279] | 1693 | |
---|
[296] | 1694 | if( thread_can_yield() ) sched_yield( NULL ); |
---|
[1] | 1695 | } |
---|
| 1696 | } |
---|
| 1697 | while( error ); |
---|
| 1698 | |
---|
[337] | 1699 | rpcg_dmsg("\n[INFO] %s : RPC %l registered / server_cxy = %x / cycle %d\n", |
---|
[296] | 1700 | __FUNCTION__ , desc_xp , server_cxy , hal_time_stamp() ); |
---|
[1] | 1701 | |
---|
[279] | 1702 | // send IPI to remote CP0, if this is the first RPC in remote FIFO, |
---|
| 1703 | // and there is no CPU is in kernel mode in server cluster. |
---|
[1] | 1704 | if( first ) |
---|
| 1705 | { |
---|
| 1706 | // get number of cores in kernel mode in server cluster |
---|
| 1707 | cores = hal_remote_lw( XPTR( server_cxy , &LOCAL_CLUSTER->cores_in_kernel ) ); |
---|
| 1708 | |
---|
| 1709 | if( cores == 0 ) // no core in kernel mode in server |
---|
| 1710 | { |
---|
[279] | 1711 | dev_pic_send_ipi( server_cxy , 0 ); |
---|
[1] | 1712 | |
---|
[337] | 1713 | rpcg_dmsg("\n[INFO] %s : IPI sent / client_cxy = %x / server_cxy = %x\n", |
---|
[296] | 1714 | __FUNCTION__, local_cxy , server_cxy ); |
---|
[1] | 1715 | } |
---|
| 1716 | } |
---|
| 1717 | |
---|
[279] | 1718 | // enable IRQs to allow incoming RPC and avoid deadlock |
---|
[337] | 1719 | hal_enable_irq( &sr_save ); |
---|
[1] | 1720 | |
---|
[279] | 1721 | // the server thread poll the response slot until RPC completed |
---|
| 1722 | // TODO this could be replaced by a descheduling policy... [AG] |
---|
[337] | 1723 | while( rpc->response ) asm volatile( "nop" ); |
---|
[1] | 1724 | |
---|
[279] | 1725 | // restore IRQs |
---|
[337] | 1726 | hal_restore_irq( sr_save ); |
---|
[1] | 1727 | |
---|
[337] | 1728 | rpcg_dmsg("\n[INFO] %s : completed / client_cxy = %x / server_cxy = %x / cycle %d\n", |
---|
[296] | 1729 | __FUNCTION__ , local_cxy , server_cxy , hal_time_stamp() ); |
---|
[279] | 1730 | |
---|
[1] | 1731 | } // end rpc_send_sync() |
---|
| 1732 | |
---|
| 1733 | |
---|
| 1734 | |
---|
| 1735 | /***************************************************************************************/ |
---|
| 1736 | /************ Generic functions supporting RPCs : server side **************************/ |
---|
| 1737 | /***************************************************************************************/ |
---|
| 1738 | |
---|
| 1739 | /////////////////////////////////////////// |
---|
| 1740 | void rpc_fifo_init( rpc_fifo_t * rpc_fifo ) |
---|
| 1741 | { |
---|
| 1742 | rpc_fifo->count = 0; |
---|
| 1743 | rpc_fifo->owner = 0; |
---|
| 1744 | local_fifo_init( &rpc_fifo->fifo ); |
---|
| 1745 | } |
---|
| 1746 | |
---|
[279] | 1747 | ///////////////////////////////////////////// |
---|
| 1748 | void rpc_execute_all( rpc_fifo_t * rpc_fifo ) |
---|
[1] | 1749 | { |
---|
| 1750 | xptr_t xp; // extended pointer on RPC descriptor |
---|
| 1751 | uint32_t count; // handled RPC request counter |
---|
| 1752 | thread_t * this; // pointer on this RPC thread |
---|
| 1753 | core_t * core; // pointer on core running this thread |
---|
| 1754 | rpc_desc_t * desc; // pointer on RPC descriptor |
---|
| 1755 | uint32_t index; // RPC index |
---|
| 1756 | cxy_t client_cxy; // client cluster identifier |
---|
| 1757 | error_t error; |
---|
| 1758 | |
---|
[296] | 1759 | this = CURRENT_THREAD; |
---|
| 1760 | core = this->core; |
---|
| 1761 | count = 0; |
---|
[1] | 1762 | |
---|
[337] | 1763 | rpcg_dmsg("\n[INFO] %s : enter / thread %x on core[%x,%d] / cycle %d\n", |
---|
[296] | 1764 | __FUNCTION__, this->trdid, local_cxy, core->lid , hal_time_stamp() ); |
---|
| 1765 | |
---|
[1] | 1766 | // handle up to CONFIG_RPC_PENDING_MAX requests before exit |
---|
| 1767 | do |
---|
| 1768 | { |
---|
[296] | 1769 | error = local_fifo_get_item( &rpc_fifo->fifo, (uint64_t *)&xp ); |
---|
[1] | 1770 | |
---|
| 1771 | if ( error == 0 ) // One RPC request successfully extracted from RPC_FIFO |
---|
| 1772 | { |
---|
| 1773 | // get client cluster identifier and pointer on RPC descriptor |
---|
| 1774 | client_cxy = (cxy_t)GET_CXY( xp ); |
---|
| 1775 | desc = (rpc_desc_t *)GET_PTR( xp ); |
---|
| 1776 | |
---|
[279] | 1777 | // get rpc index from RPC descriptor |
---|
[296] | 1778 | index = hal_remote_lw( XPTR( client_cxy , &desc->index ) ); |
---|
[1] | 1779 | |
---|
[337] | 1780 | rpcg_dmsg("\n[INFO] %s : thread %x on core [%x,%d] / rpc = %d\n", |
---|
| 1781 | __FUNCTION__ , this->trdid , core->lid , local_cxy , index ); |
---|
[296] | 1782 | |
---|
[1] | 1783 | // call the relevant server function |
---|
| 1784 | rpc_server[index]( xp ); |
---|
| 1785 | |
---|
| 1786 | // increment handled RPC counter |
---|
| 1787 | count++; |
---|
| 1788 | |
---|
| 1789 | // notify RPC completion as required |
---|
[337] | 1790 | hal_remote_atomic_add( XPTR( client_cxy , &desc->response ) , -1 ); |
---|
[1] | 1791 | } |
---|
| 1792 | |
---|
| 1793 | // exit loop in three cases: |
---|
| 1794 | // - fifo is empty |
---|
| 1795 | // - look has been released (because descheduling) |
---|
| 1796 | // - max number of RPCs has been reached |
---|
| 1797 | if( error || |
---|
| 1798 | (rpc_fifo->owner != this->trdid) || |
---|
| 1799 | (count > CONFIG_RPC_PENDING_MAX) ) break; |
---|
| 1800 | } |
---|
[279] | 1801 | while( 1 ); |
---|
[1] | 1802 | |
---|
| 1803 | // update RPC_FIFO global counter |
---|
| 1804 | rpc_fifo->count += count; |
---|
| 1805 | |
---|
| 1806 | } // end rpc_execute_all() |
---|
| 1807 | |
---|
| 1808 | //////////////////////////////////////////////////// |
---|
| 1809 | error_t rpc_activate_thread( rpc_fifo_t * rpc_fifo ) |
---|
| 1810 | { |
---|
| 1811 | core_t * core; |
---|
| 1812 | thread_t * thread; |
---|
| 1813 | thread_t * this; |
---|
| 1814 | scheduler_t * sched; |
---|
| 1815 | error_t error; |
---|
| 1816 | bool_t found; |
---|
| 1817 | reg_t sr_save; |
---|
| 1818 | |
---|
[279] | 1819 | |
---|
[1] | 1820 | this = CURRENT_THREAD; |
---|
| 1821 | core = this->core; |
---|
| 1822 | sched = &core->scheduler; |
---|
| 1823 | found = false; |
---|
| 1824 | |
---|
[279] | 1825 | assert( (this->trdid == rpc_fifo->owner) , __FUNCTION__ , |
---|
| 1826 | "calling thread is not RPC_FIFO owner\n" ); |
---|
[1] | 1827 | |
---|
| 1828 | // makes the calling thread not preemptable |
---|
| 1829 | // during activation / creation of the RPC thread |
---|
| 1830 | hal_disable_irq( &sr_save ); |
---|
| 1831 | |
---|
| 1832 | // search a free RPC thread (must be in THREAD_BLOCKED_IDLE state) |
---|
| 1833 | list_entry_t * iter; |
---|
| 1834 | LIST_FOREACH( &sched->k_root , iter ) |
---|
| 1835 | { |
---|
| 1836 | thread = LIST_ELEMENT( iter , thread_t , sched_list ); |
---|
[279] | 1837 | if( (thread->type == THREAD_RPC) && (thread->blocked == THREAD_BLOCKED_IDLE ) ) |
---|
[1] | 1838 | { |
---|
| 1839 | found = true; |
---|
| 1840 | break; |
---|
| 1841 | } |
---|
| 1842 | } |
---|
| 1843 | |
---|
| 1844 | if( found ) // activate this idle RPC thread |
---|
| 1845 | { |
---|
[296] | 1846 | // unblock it |
---|
[1] | 1847 | thread->blocked = 0; |
---|
[279] | 1848 | |
---|
[337] | 1849 | rpcg_dmsg("\n[INFO] %s : activate RPC thread %x on core [%x,%d] / cycle %d\n", |
---|
[296] | 1850 | __FUNCTION__ , thread , core->gid , local_cxy , hal_time_stamp() ); |
---|
[1] | 1851 | } |
---|
| 1852 | else // create a new RPC thread |
---|
| 1853 | { |
---|
[296] | 1854 | // create new thread |
---|
[1] | 1855 | error = thread_kernel_create( &thread, |
---|
| 1856 | THREAD_RPC, |
---|
| 1857 | &rpc_thread_func, |
---|
| 1858 | NULL, |
---|
| 1859 | core->lid ); |
---|
| 1860 | if( error ) |
---|
| 1861 | { |
---|
| 1862 | hal_restore_irq( sr_save ); |
---|
| 1863 | printk("\n[ERROR] in %s : no memory for new RPC thread in cluster %x\n", |
---|
| 1864 | __FUNCTION__ , local_cxy ); |
---|
| 1865 | return ENOMEM; |
---|
| 1866 | } |
---|
| 1867 | |
---|
[296] | 1868 | // unblock new thread |
---|
| 1869 | thread->blocked = 0; |
---|
[1] | 1870 | |
---|
| 1871 | // update core descriptor counter |
---|
[279] | 1872 | hal_atomic_add( &LOCAL_CLUSTER->rpc_threads , 1 ); |
---|
[296] | 1873 | |
---|
[337] | 1874 | rpcg_dmsg("\n[INFO] %s : create RPC thread %x on core [%x,%d] / cycle %d\n", |
---|
[296] | 1875 | __FUNCTION__ , thread->trdid, local_cxy, core->lid, hal_time_stamp() ); |
---|
[1] | 1876 | } |
---|
| 1877 | |
---|
| 1878 | // update owner in rpc_fifo |
---|
| 1879 | rpc_fifo->owner = thread->trdid; |
---|
| 1880 | |
---|
[296] | 1881 | // current thread switch to RPC thread |
---|
| 1882 | sched_yield( thread ); |
---|
[1] | 1883 | |
---|
| 1884 | // restore IRQs for the calling thread |
---|
| 1885 | hal_restore_irq( sr_save ); |
---|
| 1886 | |
---|
| 1887 | // return success |
---|
| 1888 | return 0; |
---|
| 1889 | |
---|
| 1890 | } // end rpc_activate_thread() |
---|
| 1891 | |
---|
| 1892 | ////////////////// |
---|
| 1893 | bool_t rpc_check() |
---|
| 1894 | { |
---|
| 1895 | thread_t * this = CURRENT_THREAD; |
---|
| 1896 | rpc_fifo_t * rpc_fifo = &LOCAL_CLUSTER->rpc_fifo; |
---|
| 1897 | error_t error; |
---|
| 1898 | |
---|
[337] | 1899 | rpcg_dmsg("\n[INFO] %s : enter / thread %x / cluster %x / cycle %d\n", |
---|
| 1900 | __FUNCTION__ , this->trdid , local_cxy , hal_time_stamp() ); |
---|
[296] | 1901 | |
---|
[5] | 1902 | // calling thread does nothing if light lock already taken or FIFO empty |
---|
[1] | 1903 | if( (rpc_fifo->owner != 0) || (local_fifo_is_empty( &rpc_fifo->fifo )) ) |
---|
| 1904 | { |
---|
[337] | 1905 | rpcg_dmsg("\n[INFO] %s : exit do nothing / thread %x / cluster %x / cycle %d\n", |
---|
| 1906 | __FUNCTION__ , this->trdid , local_cxy , hal_time_stamp() ); |
---|
[296] | 1907 | |
---|
[1] | 1908 | return false; |
---|
| 1909 | } |
---|
| 1910 | |
---|
[279] | 1911 | // try to take the light lock, and activates an RPC thread if success |
---|
[1] | 1912 | if( hal_atomic_test_set( &rpc_fifo->owner , this->trdid ) ) |
---|
| 1913 | { |
---|
| 1914 | error = rpc_activate_thread( rpc_fifo ); |
---|
| 1915 | |
---|
| 1916 | if( error ) // cannot activate an RPC_THREAD |
---|
| 1917 | { |
---|
| 1918 | rpc_fifo->owner = 0; |
---|
| 1919 | |
---|
| 1920 | printk("\n[ERROR] in %s : no memory to create a RPC thread for core %d" |
---|
| 1921 | " in cluster %x => do nothing\n", |
---|
| 1922 | __FUNCTION__ , CURRENT_CORE->lid , local_cxy ); |
---|
| 1923 | } |
---|
| 1924 | |
---|
[337] | 1925 | rpcg_dmsg("\n[INFO] %s : exit after RPC thread activation / " |
---|
| 1926 | "thread %x / cluster %x / cycle %d\n", |
---|
| 1927 | __FUNCTION__ , this->trdid , local_cxy , hal_time_stamp() ); |
---|
[296] | 1928 | |
---|
[1] | 1929 | return true; |
---|
| 1930 | } |
---|
| 1931 | else // light lock taken by another thread |
---|
| 1932 | { |
---|
[337] | 1933 | rpcg_dmsg("\n[INFO] %s : exit do nothing / thread %x / cluster %x / cycle %d\n", |
---|
| 1934 | __FUNCTION__ , this->trdid , local_cxy , hal_time_stamp() ); |
---|
[296] | 1935 | |
---|
[1] | 1936 | return false; |
---|
| 1937 | } |
---|
[5] | 1938 | } // end rpc_check() |
---|
[1] | 1939 | |
---|
| 1940 | |
---|
| 1941 | ////////////////////// |
---|
| 1942 | void rpc_thread_func() |
---|
| 1943 | { |
---|
[296] | 1944 | // makes the RPC thread not preemptable |
---|
[1] | 1945 | hal_disable_irq( NULL ); |
---|
| 1946 | |
---|
| 1947 | thread_t * this = CURRENT_THREAD; |
---|
| 1948 | rpc_fifo_t * rpc_fifo = &LOCAL_CLUSTER->rpc_fifo; |
---|
| 1949 | |
---|
[337] | 1950 | rpcg_dmsg("\n[INFO] %s : enter / thread %x on core[%x,%d] / cycle %d\n", |
---|
[296] | 1951 | __FUNCTION__, this->trdid, local_cxy, this->core->lid, hal_time_stamp() ); |
---|
[1] | 1952 | |
---|
| 1953 | // this infinite loop is not preemptable |
---|
[279] | 1954 | // the RPC thread deschedule only when the RPC_FIFO is empty |
---|
[1] | 1955 | while(1) |
---|
| 1956 | { |
---|
| 1957 | // check fifo ownership (ownership should be given by rpc_activate() |
---|
| 1958 | if( this->trdid != rpc_fifo->owner ) |
---|
| 1959 | { |
---|
[374] | 1960 | panic("thread %x on core[%x,%d] not owner of RPC_FIFO", |
---|
| 1961 | this->trdid, local_cxy, this->core->lid ); |
---|
[1] | 1962 | } |
---|
| 1963 | |
---|
| 1964 | // executes pending RPC(s) |
---|
| 1965 | rpc_execute_all( rpc_fifo ); |
---|
| 1966 | |
---|
| 1967 | // release rpc_fifo ownership (can be lost during RPC execution) |
---|
| 1968 | if( rpc_fifo->owner == this->trdid ) rpc_fifo->owner = 0; |
---|
| 1969 | |
---|
| 1970 | |
---|
[279] | 1971 | // block and deschedule or sucide |
---|
| 1972 | if( LOCAL_CLUSTER->rpc_threads >= CONFIG_RPC_THREADS_MAX ) |
---|
[1] | 1973 | { |
---|
[337] | 1974 | rpcg_dmsg("\n[INFO] %s : RPC thread %x on core[%x,%d] suicide / cycle %d\n", |
---|
[296] | 1975 | __FUNCTION__, this->trdid, local_cxy, this->core->lid, hal_time_stamp() ); |
---|
[1] | 1976 | |
---|
| 1977 | // update core descriptor counter |
---|
[279] | 1978 | hal_atomic_add( &LOCAL_CLUSTER->rpc_threads , -1 ); |
---|
[1] | 1979 | |
---|
| 1980 | // suicide |
---|
| 1981 | thread_exit(); |
---|
| 1982 | } |
---|
[279] | 1983 | else |
---|
| 1984 | { |
---|
[337] | 1985 | rpcg_dmsg("\n[INFO] %s : RPC thread %x on core[%x,%d] blocks / cycle %d\n", |
---|
[296] | 1986 | __FUNCTION__, this->trdid, local_cxy, this->core->lid, hal_time_stamp() ); |
---|
[1] | 1987 | |
---|
[296] | 1988 | thread_block( this , THREAD_BLOCKED_IDLE ); |
---|
| 1989 | sched_yield( NULL ); |
---|
[1] | 1990 | |
---|
[337] | 1991 | rpcg_dmsg("\n[INFO] %s : RPC thread %x wake up on core[%x,%d] / cycle %d\n", |
---|
[296] | 1992 | __FUNCTION__, this->trdid, local_cxy, this->core->lid, hal_time_stamp() ); |
---|
[279] | 1993 | } |
---|
| 1994 | } // end while |
---|
[1] | 1995 | } // end rpc_thread_func() |
---|
| 1996 | |
---|