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