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

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

Fix several bugs in VFS.

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