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

Last change on this file since 108 was 23, checked in by alain, 7 years ago

Introduce syscalls.

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