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

Last change on this file since 285 was 279, checked in by alain, 7 years ago

1) Introduce independant command fields for the various devices in the thread descriptor.
2) Introduce a new dev_pic_enable_ipi() function in the generic PIC device
3) Fix two bugs identified by Maxime in the scheduler initialisation, and in the sched_select().
4) fix several bugs in the TSAR hal_kentry.S.
5) Introduce a third kgiet segment (besides kdata and kcode) in the TSAR bootloader.

File size: 29.1 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 checks the RPC fifo, try to take the light-lock and activates (or creates)
161 * an RPC thread in case of success.
162 ***********************************************************************************
163 * @ returns true if success / 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 **********************************************************************************/
173void rpc_execute_all( rpc_fifo_t * rpc_fifo );
174
175/**********************************************************************************
176 * This function is called by any thread running on any core in any cluster,
177 * that detected a non-empty RPC_FIFO and got the RPC_FIFO ownership.
178 * It activates one RPC thread, and immediately switches to the RPC thread.
179 * It gets the first free RPC thread from the core free-list, or creates a new one
180 * when the core free-list is empty.
181 ***********************************************************************************
182 * @ rpc_fifo : pointer on the non-empty RPC fifo.
183 * @ return 0 if success / return ENOMEM if error.
184 **********************************************************************************/
185error_t rpc_activate_thread( rpc_fifo_t * rpc_fifo );
186
187/***********************************************************************************
188 * This function contains the infinite loop executed by each RPC thread.
189 **********************************************************************************/
190void rpc_thread_func();
191
192/***********************************************************************************
193 * This function is executed in case of illegal RPC index.
194 **********************************************************************************/
195void __attribute__((noinline)) rpc_undefined();
196
197
198
199
200/**********************************************************************************/
201/******* Marshalling functions attached to the various RPCs ***********************/
202/**********************************************************************************/
203
204/***********************************************************************************
205 * [0] The RPC_PMEM_GET_PAGES allocates one or several pages in a remote cluster,
206 * and returns the PPN of the first allocated page.
207 ***********************************************************************************
208 * @ cxy     : server cluster identifier
209 * @ order   : [in]  ln2( number of requested pages )
210 * @ error   : [out] error status (0 if success)
211 * @ ppn     : [out] first physical page number
212 **********************************************************************************/
213void rpc_pmem_get_pages_client( cxy_t      cxy,
214                                uint32_t   order,
215                                error_t  * error,
216                                uint32_t * ppn );
217
218void rpc_pmem_get_pages_server( xptr_t xp );
219
220/***********************************************************************************
221 * [1] The RPC_PROCESS_PID_ALLOC allocates one new PID in a remote cluster, registers
222 * the new process in the remote cluster, and returns the PID, and an error code.
223 ***********************************************************************************
224 * @ cxy     : server cluster identifier.
225 * @ process : [in]  local pointer on process descriptor in client cluster.
226 * @ error   : [out] error status (0 if success).
227 * @ pid     : [out] new process identifier.
228 **********************************************************************************/
229void rpc_process_pid_alloc_client( cxy_t              cxy,
230                                   struct process_s * process,
231                                   error_t          * error,
232                                   pid_t            * pid );
233
234void rpc_process_pid_alloc_server( xptr_t xp );
235
236/***********************************************************************************
237 * [2] The RPC_PROCESS_EXEC creates a process descriptor copy, in a remote cluster
238 * and initializes if from information found in the reference process descriptor.
239 * This remote cluster becomes the new reference cluster.
240 ***********************************************************************************
241 * @ cxy     : server cluster identifier.
242 * @ info    : [in]   pointer on local exec_info structure.
243 * @ error   : [out]  error status (0 if success).
244 **********************************************************************************/
245void rpc_process_exec_client( cxy_t                cxy,
246                              struct exec_info_s * info,
247                              error_t            * error );
248
249void rpc_process_exec_server( xptr_t xp );
250
251/***********************************************************************************
252 * [3] The RPC_PROCESS_KILL is actually a multicast RPC sent by the reference cluster
253 * to other clusters containing a process descriptor copy, to destroy these copies.
254 ***********************************************************************************
255 * @ process  : local pointer on target process.
256 **********************************************************************************/
257void rpc_process_kill_client( struct process_s * process );
258
259void rpc_process_kill_server( xptr_t xp );
260
261/***********************************************************************************
262 * [4] The RPC_THREAD_USER_CREATE creates an user thread in the server cluster,
263 * as specified by the arguments. It returns an extended pointer on the new
264 * thread descriptor in server cluster, and an error code.
265 * It is called by the sys_thread_create() system call.
266 ***********************************************************************************
267 * @ cxy       : server cluster identifier.
268 * @ attr      : [in]  pointer on pthread_attr_t in client cluster.
269 * @ thread_xp : [out] pointer on buffer for thread extended pointer.
270 * @ error     : [out] error status (0 if success).
271 **********************************************************************************/
272void rpc_thread_user_create_client( cxy_t                   cxy,
273                                    pid_t                   pid,
274                                    void                  * start_func,
275                                    void                  * start_arg,
276                                    struct pthread_attr_s * attr,
277                                    xptr_t                * thread_xp,
278                                    error_t               * error );
279
280void rpc_thread_user_create_server( xptr_t xp );
281
282/***********************************************************************************
283 * [5] The RPC_THREAD_KERNEL_CREATE creates a kernel thread in the server cluster,
284 * as specified by the type, func and args arguments. It returns the local pointer
285 * on the thread descriptor in server cluster and an error code.
286 * It is used by the dev_init() function to create the device server thread.
287 ***********************************************************************************
288 * @ cxy       : server cluster identifier.
289 * @ type      : [in]  type of kernel thread.
290 * @ func      : [in]  local pointer on thread function.
291 * @ args      : [in]  local pointer on function arguments.
292 * @ thread_xp : [out] pointer on buffer for thread extended pointer.
293 * @ error     : [out] error status (0 if success).
294 **********************************************************************************/
295void rpc_thread_kernel_create_client( cxy_t     cxy,
296                                      uint32_t  type,
297                                      void    * func,
298                                      void    * args,
299                                      xptr_t  * thread_xp,
300                                      error_t * error );
301
302void rpc_thread_kernel_create_server( xptr_t xp );
303
304/***********************************************************************************
305 * [6] The RPC_SIGNAL_RISE ask a target cluster to register a given signal in
306 * all threads descriptors of a given process.
307 * It is used by the sys_kill() function.
308 ***********************************************************************************
309 * @ cxy       : server cluster identifier.
310 * @ process   : [in]  local pointer on target process descriptor in server.
311 * @ sig_id    : [in]  signal index.
312 **********************************************************************************/
313void rpc_signal_rise_client( cxy_t              cxy,
314                             struct process_s * process,
315                             uint32_t           sig_id );
316                             
317void rpc_signal_rise_server( xptr_t xp );
318
319/***********************************************************************************
320 * [10] The RPC_VFS_INODE_CREATE creates an inode and the associated mapper in a
321 * remote cluster. The parent dentry must have been previously created.
322 * It returns an extended pointer on the created inode.
323 ***********************************************************************************
324 * @ cxy        :  server cluster identifier.
325 * @ dentry_xp  : [in]  extended pointer on parent dentry.
326 * @ fs_type    : [in]  file system type.
327 * @ inode_type : [in]  file system type.
328 * @ extend     : [in]  fs_type_specific inode extension.
329 * @ attr       : [in]  inode attributes.
330 * @ rights     : [in]  access rights
331 * @ uid        : [in]  user ID
332 * @ gid        : [in]  group ID
333 * @ inode_xp   : [out] buffer for extended pointer on created inode.
334 * @ error      : [out] error status (0 if success).
335 **********************************************************************************/
336void rpc_vfs_inode_create_client( cxy_t      cxy,
337                                  xptr_t     dentry_xp,
338                                  uint32_t   fs_type,
339                                  uint32_t   inode_type,
340                                  void     * extend,
341                                  uint32_t   attr,   
342                                  uint32_t   rights, 
343                                  uint32_t   uid,
344                                  uint32_t   gid,
345                                  xptr_t   * inode_xp,
346                                  error_t  * error );
347
348void rpc_vfs_inode_create_server( xptr_t xp );
349
350/***********************************************************************************
351 * [11] The RPC_VFS_INODE_DESTROY releases memory allocated for an inode descriptor
352 * and for the associated mapper in a remote cluster.
353 ***********************************************************************************
354 * @ cxy       :  server cluster identifier
355 * @ inode     : [in]  local pointer on inode.
356 **********************************************************************************/
357void rpc_vfs_inode_destroy_client( cxy_t                 cxy,
358                                   struct vfs_inode_s * inode );
359
360void rpc_vfs_inode_destroy_server( xptr_t xp );
361
362/***********************************************************************************
363 * [12] The RPC_VFS_DENTRY_CREATE creates a dentry in a remote cluster.
364 * It returns an extended pointer on the created dentry.
365 ***********************************************************************************
366 * @ cxy        :  server cluster identifier
367 * @ type       : [in]  file system type.
368 * @ name       : [in]  directory entry name.
369 * @ parent     : [in]  local pointer on parent inode.
370 * @ dentry_xp  : [out] buffer for extended pointer on created dentry.
371 * @ error      : [out] error status (0 if success).
372 **********************************************************************************/
373void rpc_vfs_dentry_create_client( cxy_t                  cxy,
374                                   uint32_t               type,
375                                   char                 * name,   
376                                   struct vfs_inode_s   * parent,
377                                   xptr_t               * dentry_xp,
378                                   error_t              * error );
379
380void rpc_vfs_dentry_create_server( xptr_t xp );
381
382/***********************************************************************************
383 * [13] The RPC_VFS_DENTRY_DESTROY releases memory allocated for an dentry descriptor
384 * in a remote cluster.
385 ***********************************************************************************
386 * @ cxy       :  server cluster identifier
387 * @ dentry     : [in]  local pointer on dentry.
388 **********************************************************************************/
389void rpc_vfs_dentry_destroy_client( cxy_t                 cxy,
390                                    struct vfs_dentry_s * dentry );
391
392void rpc_vfs_dentry_destroy_server( xptr_t xp );
393
394/***********************************************************************************
395 * [14] The RPC_VFS_FILE_CREATE creates a file descriptor in a remote cluster.
396 * It returns an extended pointer on the created file structure.
397 ***********************************************************************************
398 * @ cxy        :  server cluster identifier
399 * @ inode      : [in]  local pointer on parent inode.
400 * @ file_attr  : [in]  new file attributes.
401 * @ file_xp    : [out] buffer for extended pointer on created file.
402 * @ error      : [out] error status (0 if success).
403 **********************************************************************************/
404void rpc_vfs_file_create_client( cxy_t                  cxy,
405                                 struct vfs_inode_s   * inode,
406                                 uint32_t               file_attr,
407                                 xptr_t               * file_xp,
408                                 error_t              * error );
409
410void rpc_vfs_file_create_server( xptr_t xp );
411
412/***********************************************************************************
413 * [15] The RPC_VFS_FILE_DESTROY releases memory allocated for a file descriptor
414 * in a remote cluster.
415 ***********************************************************************************
416 * @ cxy       :  server cluster identifier
417 * @ file       : [in]  local pointer on file.
418 **********************************************************************************/
419void rpc_vfs_file_destroy_client( cxy_t               cxy,
420                                  struct vfs_file_s * file );
421
422void rpc_vfs_file_destroy_server( xptr_t xp );
423
424/***********************************************************************************
425 * [16] The RPC_VFS_LOAD_INODE calls the vfs_inode_load() kernel function in a
426 * remote cluster containing a parent inode directory to scan the associated
427 * mapper, find a directory entry, identified by its name, and update the remote
428 * child inode.
429 ***********************************************************************************
430 * @ cxy            :  server cluster identifier
431 * @ parent_inode   : [in]  local pointer on parent inode.
432 * @ name           : [in]  local pointer on child name (in client cluster).
433 * @ child_inode_xp : [in]  extended pointer on child inode (in another cluster).
434 * @ error          : [out] error status (0 if success).
435 **********************************************************************************/
436void rpc_vfs_inode_load_client( cxy_t                cxy,
437                                struct vfs_inode_s * parent_inode,
438                                char               * name,
439                                xptr_t               child_inode_xp,
440                                error_t            * error );
441
442void rpc_vfs_inode_load_server( xptr_t xp );
443
444/***********************************************************************************
445 * [17] The RPC_VFS_MAPPER_LOAD_ALL calls the vfs_mapper_load_all() kernel function
446 * in a remote cluster containing an inode, to load all pages of the associated
447 * mapper from the file system on device.
448 ***********************************************************************************
449 * @ cxy     :  server cluster identifier
450 * @ inode   : [in]  local pointer on inode in server cluster.
451 * @ error   : [out] error status (0 if success).
452 **********************************************************************************/
453void rpc_vfs_mapper_load_all_client( cxy_t                cxy,
454                                     struct vfs_inode_s * inode,
455                                     error_t            * error );
456
457void rpc_vfs_mapper_load_all_server( xptr_t xp );
458
459/***********************************************************************************
460 * [18] The RPC_FATFS_GET_CLUSTER can be send by any thread running in a "client"
461 * cluster to scan the FAT mapper, stored in a remote "server" cluster, and get
462 * from the mapper the local pointer on a given page.
463 ***********************************************************************************
464 * @ cxy      : server cluster identifier.
465 * @ mapper   : [in]  local pointer on FAT mapper.
466 * @ first    : [in]  FATFS cluster index allocated to first page of file.
467 * @ page     : [in]  page index in file.
468 * @ cluster  : [out] local pointer on buffer for found FATFS cluster index.
469 * @ error    : [out] local pointer on buffer for error code (in client cluster).
470 **********************************************************************************/
471void rpc_fatfs_get_cluster_client( cxy_t             cxy,
472                                   struct mapper_s * mapper,
473                                   uint32_t          first,
474                                   uint32_t          page,
475                                   uint32_t        * cluster,
476                                   error_t         * error );   
477
478void rpc_fatfs_get_cluster_server( xptr_t xp );
479
480/***********************************************************************************
481 * [20] The RPC_VMM_GET_REF_VSEG returns an extended pointer
482 * on the vseg containing a given virtual address in a given process.
483 * The server cluster is supposed to be the reference cluster.
484 * It returns XPTR_NULL if no vseg has been founded.
485 ***********************************************************************************
486 * @ cxy     : server cluster identifier.
487 * @ process : [in]   pointer on process descriptor in server cluster.
488 * @ vaddr   : [in]   virtual address to be searched.
489 * @ vseg_xp : [out]  buffer for extended pointer on vseg in client cluster.
490 **********************************************************************************/
491void rpc_vmm_get_ref_vseg_client( cxy_t              cxy,
492                                  struct process_s * process,
493                                  intptr_t           vaddr,
494                                  xptr_t           * vseg_xp );
495
496void rpc_vmm_get_ref_vseg_server( xptr_t xp );
497
498/***********************************************************************************
499 * [21] The RPC_VMM_GET_PTE returns in the "ppn" and "attr" arguments the PTE value
500 * for a given VPN in a given process.
501 * The server cluster is supposed to be the reference cluster, and the vseg
502 * containing the VPN must be registered in the reference VMM.
503 * It returns an error if physical memory cannot be allocated for the PTE2,
504 * or for the missing page itself.
505 ***********************************************************************************
506 * @ cxy     : server cluster identifier.
507 * @ process : [in]   pointer on process descriptor in server cluster.
508 * @ vaddr   : [in]   virtual address to be searched.
509 * @ attr    : [out]  address of buffer for attributes.
510 * @ ppn     : [out]  address of buffer for PPN.
511 * @ error   : [out]  address of buffer for error code.
512 **********************************************************************************/
513void rpc_vmm_get_pte_client( cxy_t              cxy,
514                             struct process_s * process,
515                             vpn_t              vpn,
516                             uint32_t         * attr,
517                             ppn_t            * ppn,
518                             error_t          * error );
519
520void rpc_vmm_get_pte_server( xptr_t xp );
521
522/***********************************************************************************
523 * [22] The RPC_KCM_ALLOC allocates memory from a given KCM in a remote cluster,
524 * and returns an extended pointer on the allocated object.
525  It returns XPTR_NULL if physical memory cannot be allocated.
526 ***********************************************************************************
527 * @ cxy       : server cluster identifier.
528 * @ kmem_type : [in]  KCM object type (as defined in kmem.h).
529 * @ buf_xp    : [out] buffer for extended pointer on allocated buffer.
530 **********************************************************************************/
531void rpc_kcm_alloc_client( cxy_t      cxy,
532                           uint32_t   kmem_type,
533                           xptr_t   * buf_xp ); 
534
535void rpc_kcm_alloc_server( xptr_t xp );
536
537/***********************************************************************************
538 * [23] The RPC_KCM_FREE releases memory allocated for a KCM object of a given type,
539 * in a remote cluster.
540 ***********************************************************************************
541 * @ cxy       : server cluster identifier.
542 * @ buf       : [in] local pointer on allocated buffer.
543 * @ kmem_type : [in]  KCM object type (as defined in kmem.h).
544 **********************************************************************************/
545void rpc_kcm_free_client( cxy_t     cxy,
546                          void    * buf,
547                          uint32_t  kmem_type );
548
549void rpc_kcm_free_server( xptr_t xp );
550
551/***********************************************************************************
552 * [24] The RPC_MAPPER_MOVE_USER is called by the vfs_move() function.
553 * It allows a client thread to requires a remote mapper to move data to/from
554 * an user buffer, as specified by the arguments.
555 ***********************************************************************************
556 * @ cxy         : server cluster identifier.
557 * @ mapper      : [in]  local pointer on mapper
558 * @ to_buffer   : [in]  move data from buffer to mapper if non zero.
559 * @ is_user     : [in]  buffer in user space if non zero.
560 * @ file_offset : [in]  first byte to move in mapper
561 * @ buffer      : [in]  pointer on buffer in user space
562 * @ size        : [in]  number of bytes to move
563 * @ error       : [out] error status (0 if success).
564 **********************************************************************************/
565void rpc_mapper_move_buffer_client( cxy_t             cxy,
566                                    struct mapper_s * mapper,
567                                    bool_t            to_buffer,
568                                    bool_t            is_user,
569                                    uint32_t          file_offset,
570                                    void            * buffer,
571                                    uint32_t          size,
572                                    error_t         * error );
573
574void rpc_mapper_move_buffer_server( xptr_t xp );
575
576
577
578
579#endif
Note: See TracBrowser for help on using the repository browser.