source: trunk/kernel/kern/rpc.h @ 10

Last change on this file since 10 was 5, checked in by alain, 8 years ago

Introduce the chdev_t structure in place of the device_t structure.

File size: 24.2 KB
RevLine 
[1]1/*
2 * rpc.h - RPC (Remote Procedure Call) operations definition.
3 *
4 * Authors Mohamed 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#ifndef _RPC_H_
26#define _RPC_H_
27
28#include <almos_config.h>
29#include <hal_types.h>
30#include <hal_atomic.h>
31#include <bits.h>
32#include <spinlock.h>
33#include <remote_fifo.h>
34
35/**** Forward declarations ****/
36
37struct process_s;
38struct vseg_s;
39struct exec_info_s;
40struct pthread_attr_s;
41struct remote_sem_s;
42struct fragment_s;
43struct vfs_inode_s;
44struct vfs_dentry_s;
45struct thread_s;
46struct mapper_s;
47
48/**********************************************************************************/
49/**************  structures for Remote Procedure Calls ****************************/
50/**********************************************************************************/
51
52/***********************************************************************************
53 * This enum defines all RPC indexes.
54 * It must be consistent with the rpc_server[] array defined in in the rpc.c file.
55 **********************************************************************************/
56
57typedef enum
58{
59    RPC_PMEM_GET_PAGES         = 0,
60    RPC_PROCESS_PID_ALLOC      = 1,
61    RPC_PROCESS_EXEC           = 2,
62    RPC_PROCESS_KILL           = 3,
63    RPC_THREAD_USER_CREATE     = 4,
64    RPC_THREAD_KERNEL_CREATE   = 5,
65
66    RPC_VFS_INODE_CREATE       = 10,
67    RPC_VFS_INODE_DESTROY      = 11,
68    RPC_VFS_DENTRY_CREATE      = 12,
69    RPC_VFS_DENTRY_DESTROY     = 13,
70
71    RPC_VMM_GET_REF_VSEG       = 20,
72    RPC_VMM_GET_PTE            = 21,
73    RPC_SEMAPHORE_ALLOC        = 22,
74    RPC_SEMAPHORE_FREE         = 23,
75    RPC_MAPPER_MOVE            = 24,
76
77    RPC_FATFS_GET_CLUSTER      = 30,
78
79    RPC_MAX_INDEX              = 31,
80}
81rpc_index_t;
82
83/***********************************************************************************
84 * This defines the prototype of the rpc_server functions,
85 * defined by the rpc_server[] array in the rpc.c file.
86 **********************************************************************************/
87
88typedef  void (rpc_server_t) ( xptr_t xp );
89
90/***********************************************************************************
91 *  This structure defines the RPC descriptor
92 **********************************************************************************/
93
94typedef struct rpc_desc_s
95{
96        rpc_index_t       index;       // index of requested RPC service
97        volatile uint32_t response;    // response valid when 0
98    uint64_t          args[8];     // input/output arguments buffer
99} 
100rpc_desc_t;
101
102/***********************************************************************************
103 * This structure defines the RPC fifo, containing a remote_fifo, the owner RPC
104 * thread TRDID (used as a light lock), and the intrumentation counter.
105 *
106 * Implementation note: the TRDID is a good owner identifier, because all
107 * RPC threads in a given cluster belong to the same process_zero kernel process,
108 * and RPC threads cannot have local index LTID = 0.
109 **********************************************************************************/
110
111typedef struct rpc_fifo_s
112{
113        trdid_t           owner;       // owner thread / 0 if no owner
114        uint64_t          count;       // total number of received RPCs (instrumentation)
115        remote_fifo_t     fifo;        // embedded remote fifo
116} 
117rpc_fifo_t;
118
119
120/**********************************************************************************/
121/******* Generic functions supporting RPCs : client side **************************/
122/**********************************************************************************/
123
124/***********************************************************************************
125 * This blocking function executes on the client core.
126 * It puts one RPC extended pointer in the remote fifo.
127 * It sends an IPI if fifo is empty, and waits until RPC response available.
128 * The RPC descriptor must be allocated in the caller's stack
129 * and initialised by the caller.  Exit with a Panic message if remote fifo
130 * is still full after (CONFIG_RPC_PUT_MAX_ITERATIONS) retries.
131 ***********************************************************************************
132 * @ cxy   : server cluster identifier
133 * @ desc  : local pointer on RPC descriptor in client cluster
134 **********************************************************************************/
135void rpc_send_sync( cxy_t        cxy,   
136                    rpc_desc_t * desc );
137
138
139
140/**********************************************************************************/
141/******* Generic functions supporting RPCs : server side **************************/
142/**********************************************************************************/
143
144/***********************************************************************************
145 * This function initialises the local RPC fifo and the lock protecting readers.
146 * The number of slots is defined by the CONFIG_REMOTE_FIFO_SLOTS parameter.
147 * Each slot contains an extended pointer on the RPC descriptor.
148 ***********************************************************************************
149 * @ rf     : pointer on the local RPC fifo.
150 **********************************************************************************/ 
151void rpc_fifo_init( rpc_fifo_t * rf );
152
153/***********************************************************************************
154 * This function is the entry point for RPC handling on the server side.
155 * It can be executed by any thread running (in kernel mode) on any core.
156 * It first checks the core private RPC fifo, an then the cluster shared RPC fifo.
157 * It calls the rpc_activate_thread() function to activate a dedicated RPC thread.
158 ***********************************************************************************
159 * @ returns true if at least one RPC found / false otherwise.
160 **********************************************************************************/
161bool_t rpc_check();
162
163/***********************************************************************************
164 * This function contains the loop to execute all pending RPCs on the server side.
165 * It should be called with irq disabled and after light lock acquisition.
166 ***********************************************************************************
167 * @ rpc_fifo  : pointer on the local RPC fifo
168 * @ returns 0 if success
169 **********************************************************************************/
170error_t rpc_execute_all( rpc_fifo_t * rpc_fifo );
171
172/**********************************************************************************
173 * This function is called by any thread running on any core in any cluster,
174 * that detected a non-empty RPC_FIFO and got the RPC_FIFO ownership.
175 * It activates one RPC thread, and immediately switches to the RPC thread.
176 * It gets the first free RPC thread from the core free-list, or creates a new one
177 * when the core free-list is empty.
178 ***********************************************************************************
179 * @ rpc_fifo : pointer on the non-empty RPC fifo.
180 * @ return 0 if success / return ENOMEM if error.
181 **********************************************************************************/
182error_t rpc_activate_thread( rpc_fifo_t * rpc_fifo );
183
184/***********************************************************************************
185 * This function contains the infinite loop executed by each RPC thread.
186 **********************************************************************************/
187void rpc_thread_func();
188
189/***********************************************************************************
190 * This function is executed in case of illegal RPC index.
191 **********************************************************************************/
192void __attribute__((noinline)) rpc_undefined();
193
194/**********************************************************************************/
195/******* Marshalling functions attached to the various RPCs ***********************/
196/**********************************************************************************/
197
198/***********************************************************************************
199 * The RPC_PMEM_GET_PAGES allocates one or several pages in a remote cluster,
200 * and returns the PPN of the first allocated page.
201 ***********************************************************************************
202 * @ cxy     : server cluster identifier
203 * @ order   : [in]  ln2( number of requested pages )
204 * @ error   : [out] error status (0 if success)
205 * @ ppn     : [out] first physical page number
206 **********************************************************************************/
207void rpc_pmem_get_pages_client( cxy_t      cxy,
208                                uint32_t   order,
209                                error_t  * error,
210                                uint32_t * ppn );
211
212void rpc_pmem_get_pages_server( xptr_t xp );
213
214/***********************************************************************************
215 * The RPC_PROCESS_PID_ALLOC allocates one new PID in a remote cluster, registers
216 * the new process in the remote cluster, and returns the PID, and an error code.
217 ***********************************************************************************
218 * @ cxy     : server cluster identifier.
219 * @ process : [in]  local pointer on process descriptor in client cluster.
220 * @ error   : [out] error status (0 if success).
221 * @ pid     : [out] new process identifier.
222 **********************************************************************************/
223void rpc_process_pid_alloc_client( cxy_t              cxy,
224                                   struct process_s * process,
225                                   error_t          * error,
226                                   pid_t            * pid );
227
228void rpc_process_pid_alloc_server( xptr_t xp );
229
230/***********************************************************************************
231 * The RPC_PROCESS_EXEC creates a process descriptor copy, in a remote cluster
232 * and initializes if from information found in the reference process descriptor.
233 * This remote cluster becomes the new reference cluster.
234 ***********************************************************************************
235 * @ cxy     : server cluster identifier.
236 * @ info    : [in]   pointer on local exec_info structure.
237 * @ error   : [out]  error status (0 if success).
238 **********************************************************************************/
239void rpc_process_exec_client( cxy_t                cxy,
240                              struct exec_info_s * info,
241                              error_t            * error );
242
243void rpc_process_exec_server( xptr_t xp );
244
245/***********************************************************************************
246 * The RPC_PROCESS_KILL is actually a multicast RPC sent by the reference cluster
247 * to other clusters containing a process descriptor copy, to destroy these copies.
248 ***********************************************************************************
249 * @ process  : local pointer on target process.
250 **********************************************************************************/
251void rpc_process_kill_client( struct process_s * process );
252
253void rpc_process_kill_server( xptr_t xp );
254
255/***********************************************************************************
256 * The RPC_THREAD_USER_CREATE creates an user thread in the server cluster,
257 * as specified by the pthread_attr_t argument. It returns the local pointer
258 * on the thread descriptor in server cluster, and an error code.
259 * It is called by the pthread_create system call.
260 ***********************************************************************************
261 * @ cxy       : server cluster identifier.
262 * @ attr      : [in]  pointer on pthread_attr_t in client cluster.
263 * @ thread_xp : [out] pointer on buffer for thread extended pointer.
264 * @ error     : [out] error status (0 if success).
265 **********************************************************************************/
266void rpc_thread_user_create_client( cxy_t                   cxy,
267                                    struct pthread_attr_s * attr,
268                                    xptr_t                * thread_xp,
269                                    error_t               * error );
270
271void rpc_thread_user_create_server( xptr_t xp );
272
273/***********************************************************************************
274 * The RPC_THREAD_KERNEL_CREATE creates a kernel thread in the server cluster,
275 * as specified by the type, func and args arguments. It returns the local pointer
276 * on the thread descriptor in server cluster and an error code.
277 * It is used by the dev_init() function to cretae the device server thread.
278 ***********************************************************************************
279 * @ cxy       : server cluster identifier.
280 * @ type      : [in]  type of kernel thread.
281 * @ func      : [in]  local pointer on thread function.
282 * @ args      : [in]  local pointer on function arguments.
283 * @ thread_xp : [out] pointer on buffer for thread extended pointer.
284 * @ error     : [out] error status (0 if success).
285 **********************************************************************************/
286void rpc_thread_kernel_create_client( cxy_t     cxy,
287                                      uint32_t  type,
288                                      void    * func,
289                                      void    * args,
290                                      xptr_t  * thread_xp,
291                                      error_t * error );
292
293void rpc_thread_kernel_create_server( xptr_t xp );
294
295/***********************************************************************************
296 * The RPC_VFS_INODE_CREATE creates an inode and the associated mapper in a
297 * remote cluster. The parent dentry must have been previously created.
298 * It returns an extended pointer on the created inode.
299 ***********************************************************************************
300 * @ cxy       :  server cluster identifier
301 * @ dentry_xp : [in]  extended pointer on parent dentry.
302 * @ type      : [in]  file system type.
303 * @ attr      : [in]  TODO ???
304 * @ mode      : [in]  access mode.
305 * @ uid       : [in]  user ID
306 * @ gid       : [in]  group ID
307 * @ inode_xp  : [out] buffer for extended pointer on created inode.
308 * @ error     : [out] error status (0 if success).
309 **********************************************************************************/
310void rpc_vfs_inode_create_client( cxy_t      cxy,
311                                  xptr_t     dentry_xp,
312                                  uint32_t   type,
313                                  uint32_t   attr,   
314                                  uint32_t   mode, 
315                                  uint32_t   uid,
316                                  uint32_t   gid,
317                                  xptr_t   * inode_xp,
318                                  error_t  * error );
319
320void rpc_vfs_inode_create_server( xptr_t xp );
321
322/***********************************************************************************
323 * The RPC_VFS_INODE_DESTROY releases memory allocated for an inode descriptor
324 * and for the associated mapper in a remote cluster.
325 ***********************************************************************************
326 * @ cxy       :  server cluster identifier
327 * @ inode     : [in]  local pointer on inode.
328 **********************************************************************************/
329void rpc_vfs_inode_destroy_client( cxy_t                 cxy,
330                                   struct vfs_inode_s * inode );
331
332void rpc_vfs_inode_destroy_server( xptr_t xp );
333
334/***********************************************************************************
335 * The RPC_VFS_DENTRY_CREATE creates a dentry in a remote cluster.
336 * It returns an extended pointer on the created dentry.
337 ***********************************************************************************
338 * @ cxy        :  server cluster identifier
339 * @ type       : [in]  file system type.
340 * @ name       : [in]  directory entry name.
341 * @ parent     : [in]  local pointer on parent inode.
342 * @ dentry_xp  : [out] buffer for extended pointer on created dentry.
343 * @ error      : [out] error status (0 if success).
344 **********************************************************************************/
345void rpc_vfs_dentry_create_client( cxy_t                  cxy,
346                                   uint32_t               type,
347                                   char                 * name,   
348                                   struct vfs_inode_s   * parent,
349                                   xptr_t               * dentry_xp,
350                                   error_t              * error );
351
352void rpc_vfs_dentry_create_server( xptr_t xp );
353
354/***********************************************************************************
355 * The RPC_VFS_DENTRY_DESTROY releases memory allocated for an dentry descriptor
356 * in a remote cluster.
357 ***********************************************************************************
358 * @ cxy       :  server cluster identifier
359 * @ dentry     : [in]  local pointer on dentry.
360 **********************************************************************************/
361void rpc_vfs_dentry_destroy_client( cxy_t                 cxy,
362                                    struct vfs_dentry_s * dentry );
363
364void rpc_vfs_dentry_destroy_server( xptr_t xp );
365
366
367
368
369/***********************************************************************************
370 * The RPC_VMM_GET_REF_VSEG returns an extended pointer
371 * on the vseg containing a given virtual address in a given process.
372 * The server cluster is supposed to be the reference cluster.
373 * It returns NULL if no vseg has been founded.
374 ***********************************************************************************
375 * @ cxy     : server cluster identifier.
376 * @ process : [in]   pointer on process descriptor in server cluster.
377 * @ vaddr   : [in]   virtual address to be searched.
378 * @ vseg    : [out]  address of buffer for vseg pointer in client cluster.
379 **********************************************************************************/
380void rpc_vmm_get_ref_vseg_client( cxy_t              cxy,
381                                  struct process_s * process,
382                                  intptr_t           vaddr,
383                                  xptr_t           * vseg_xp );
384
385void rpc_vmm_get_ref_vseg_server( xptr_t xp );
386
387/***********************************************************************************
388 * The RPC_VMM_GET_PTE returns in the "ppn" and "attr" arguments the PTE value
389 * for a given VPN in a given process.
390 * The server cluster is supposed to be the reference cluster, and the vseg
391 * containing the VPN must be registered in the reference VMM.
392 * It returns an error if physical memory cannot be allocated for the PTE2,
393 * or for the missing page itself.
394 ***********************************************************************************
395 * @ cxy     : server cluster identifier.
396 * @ process : [in]   pointer on process descriptor in server cluster.
397 * @ vaddr   : [in]   virtual address to be searched.
398 * @ attr    : [out]  address of buffer for attributes.
399 * @ ppn     : [out]  address of buffer for PPN.
400 * @ error   : [out]  address of buffer for error code.
401 **********************************************************************************/
402void rpc_vmm_get_pte_client( cxy_t              cxy,
403                             struct process_s * process,
404                             vpn_t              vpn,
405                             uint32_t         * attr,
406                             ppn_t            * ppn,
407                             error_t          * error );
408
409void rpc_vmm_get_pte_server( xptr_t xp );
410
411/***********************************************************************************
412 * The RPC_SEMAPHORE_ALLOC allocates memory for a semaphore in a remote cluster,
413 * and returns an extended pointer on the created semaphore.
414  It returns NULL if physical memory cannot be allocated.
415 ***********************************************************************************
416 * @ cxy     : server cluster identifier.
417 * @ sem_xp  : [out] buffer for extended pointer on semaphore.
418 **********************************************************************************/
419void rpc_semaphore_alloc_client( cxy_t    cxy,
420                                 xptr_t * sem_xp ); 
421
422void rpc_semaphore_alloc_server( xptr_t xp );
423
424/***********************************************************************************
425 * The RPC_SEMAPHORE_FREE releases memory allocated for a semaphore
426 * in a remote cluster.
427 ***********************************************************************************
428 * @ cxy     : server cluster identifier.
429 * @ sem     : [in] local pointer on semaphore.
430 **********************************************************************************/
431void rpc_semaphore_free_client( cxy_t                 cxy,
432                                struct remote_sem_s * sem );
433
434void rpc_semaphore_free_server( xptr_t xp );
435
436/***********************************************************************************
437 * The RPC_MAPPER_MOVE can be send by any thread running in a "client" cluster
438 * to the "server" cluster containing the mapper of a given file. The service is
439 * to move data between the mapper and an user buffer. This user buffer is described
440 * as a set of fragments. Each fragment is contained in one single physical page.
441 * It is defined by four parameters : size / file_offset / ppn / page_offset,
442 * defined in the mapper.h file. The client thread is in charge of building
443 * the fragments array covering the user buffer.
444 * As each fragments can be stored in a different cluster, and this fragment can
445 * be stored in two successive pages in the radix tree, each fragment is moved
446 * using one or two different hal_remote_memcpy().
447 ***********************************************************************************
448 * @ cxy      : server cluster identifier.
449 * @ inode    : [in]  local pointer on inode (in server cluster).
450 * @ read     : [in]  mapper to buffer if true / buffer to mapper if false.
451 * @ nb_frags : [in]  number of fragments in fragments array.
452 * @ frags    : [in]  local pointer on fragments array (in client cluster).
453 * @ error    : [out] local pointer on buffer for error code (in client cluster).
454 **********************************************************************************/
455void rpc_mapper_move_client( cxy_t                cxy,
456                             struct mapper_s    * mapper,
457                             bool_t               read,
458                             uint32_t             nb_frags,
459                             struct fragment_s  * frags,
460                             error_t            * error );
461
462void rpc_mapper_move_server( xptr_t xp );
463
464/***********************************************************************************
465 * The RPC_FATFS_GET_CLUSTER can be send by any thread running in a "client" cluster
466 * to scan the FAT mapper, stored in a remote "server" cluster, and get the FATFS
467 * cluster index of a given page of a given file.
468 ***********************************************************************************
469 * @ cxy      : server cluster identifier.
470 * @ mapper   : [in]  local pointer on FAT mapper.
471 * @ first    : [in]  FATFS cluster index allocated to first page of file.
472 * @ page     : [in]  page index in file.
473 * @ cluster  : [out] local pointer on buffer for found FATFS cluster index.
474 * @ error    : [out] local pointer on buffer for error code (in client cluster).
475 **********************************************************************************/
476void rpc_fatfs_get_cluster_client( cxy_t             cxy,
477                                   struct mapper_s * mapper,
478                                   uint32_t          first,
479                                   uint32_t          page,
480                                   uint32_t        * cluster,
481                                   error_t         * error );   
482
483void rpc_fatfs_get_cluster_server( xptr_t xp );
484
485#endif
Note: See TracBrowser for help on using the repository browser.