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