source: trunk/kernel/kern/rpc.h

Last change on this file was 657, checked in by alain, 4 years ago

Introduce remote_buf.c/.h & socket.c/.h files.
Update dev_nic.c/.h files.

File size: 20.4 KB
RevLine 
[1]1/*
2 * rpc.h - RPC (Remote Procedure Call) operations definition.
3 *
[657]4 * Author  Alain Greiner (2016,2017,2018,2019,2020)
[1]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
[14]27#include <kernel_config.h>
[457]28#include <hal_kernel_types.h>
[1]29#include <hal_atomic.h>
30#include <bits.h>
[407]31#include <vseg.h>
[1]32#include <remote_fifo.h>
33
34/**** Forward declarations ****/
35
36struct process_s;
[313]37struct page_s;
[1]38struct vseg_s;
39struct exec_info_s;
40struct pthread_attr_s;
41struct remote_sem_s;
[612]42struct user_dir_s;
[1]43struct fragment_s;
44struct vfs_inode_s;
45struct vfs_dentry_s;
[23]46struct vfs_file_s;
[1]47struct thread_s;
48struct mapper_s;
49
[436]50
[1]51/**********************************************************************************/
52/**************  structures for Remote Procedure Calls ****************************/
53/**********************************************************************************/
54
55/***********************************************************************************
56 * This enum defines all RPC indexes.
[611]57 * It must be consistent with the rpc_server[] arrays defined in in the rpc.c file.
[1]58 **********************************************************************************/
59
60typedef enum
61{
[640]62    RPC_UNDEFINED_0               = 0,   //
63    RPC_UNDEFINED_1               = 1,   //
64    RPC_UNDEFINED_2               = 2,   //     
[601]65    RPC_PROCESS_MAKE_FORK         = 3,
[612]66    RPC_USER_DIR_CREATE           = 4,
67    RPC_USER_DIR_DESTROY          = 5,
[601]68    RPC_THREAD_USER_CREATE        = 6,
69    RPC_THREAD_KERNEL_CREATE      = 7,
[657]70    RPC_UNDEFINED_8               = 8,
[619]71    RPC_PROCESS_SIGACTION         = 9,
[1]72
[657]73    RPC_UNDEFINED_10              = 10,   //
74    RPC_UNDEFINED_11              = 11,   //
75    RPC_UNDEFINED_12              = 12,   //
76    RPC_UNDEFINED_13              = 13,   //
77    RPC_UNDEFINED_14              = 14,   //
78    RPC_VMM_RESIZE_VSEG           = 15,
79    RPC_VMM_REMOVE_VSEG           = 16,
80    RPC_VMM_CREATE_VSEG           = 17,
81    RPC_VMM_SET_COW               = 18,
82    RPC_UNDEFINED_19              = 19,   //
[1]83
[657]84    RPC_MAX_INDEX                 = 20,
[1]85}
86rpc_index_t;
87
88/***********************************************************************************
89 * This defines the prototype of the rpc_server functions,
90 * defined by the rpc_server[] array in the rpc.c file.
91 **********************************************************************************/
92
93typedef  void (rpc_server_t) ( xptr_t xp );
94
95/***********************************************************************************
[619]96 *  This structure defines the RPC descriptor (100 bytes on a 32bits core)
[1]97 **********************************************************************************/
98
99typedef struct rpc_desc_s
100{
[619]101        rpc_index_t         index;       /*! index of requested RPC service      ( 4) */
102        uint32_t          * rsp;         /*! local pointer ond responses counter ( 4) */
103    struct thread_s   * thread;      /*! local pointer on client thread      ( 4) */
104    uint32_t            lid;         /*! index of core running client thread ( 4) */ 
105    bool_t              blocking;    /*! simple RPC mode when true           ( 4) */
106    uint64_t            args[10];    /*! input/output arguments buffer       (80) */
[1]107} 
108rpc_desc_t;
109
110/**********************************************************************************/
111/******* Generic functions supporting RPCs : client side **************************/
112/**********************************************************************************/
113
114/***********************************************************************************
[409]115 * This function is executed by the client thread in the client cluster.
116 * It puts one RPC descriptor defined by the <desc> argument in the remote fifo
117 * defined by the <cxy> argument.  It sends an IPI to the server if fifo is empty.
118 * The RPC descriptor must be allocated in the caller's stack, and initialised by
119 * the caller. It exit with a Panic message if remote fifo is still full after
120 * (CONFIG_RPC_PUT_MAX_ITERATIONS) retries.
[641]121 * - When the RPC <blocking> field is true, this function blocks and deschedule
122 *   the client thread. It returns only when the server completes the RPC and
123 *   unblocks the client thread.
[416]124 * - When the <blocking> field is false, this function returns as soon as the RPC
[641]125 *   has been registered in the FIFO, and the client thread must block itself when
126 *   all RPCS have been registered in all target clusters.
[1]127 ***********************************************************************************
128 * @ cxy   : server cluster identifier
129 * @ desc  : local pointer on RPC descriptor in client cluster
130 **********************************************************************************/
[409]131void rpc_send( cxy_t        cxy,   
[416]132               rpc_desc_t * desc );
[1]133
134
135
136/**********************************************************************************/
137/******* Generic functions supporting RPCs : server side **************************/
138/**********************************************************************************/
139
140/***********************************************************************************
[583]141 * This function contains the infinite loop executed by a RPC server thread,
142 * to handle pending RPCs registered in the RPC fifo attached to a given core.
143 * In each iteration in this loop, it try to handle one RPC request:
144 * - it tries to take the RPC FIFO ownership,
145 * - it consumes one request when the FIFO is not empty,
146 * - it releases the FIFO ownership,
147 * - it execute the requested service,
148 * - it unblock and send an IPI to the client thread,
149 * - it suicides if the number of RPC threads for this core is to large,
150 * - it block on IDLE and deschedule otherwise. 
[1]151 **********************************************************************************/
[619]152void rpc_server_func( void );
[1]153
154/***********************************************************************************
155 * This function is executed in case of illegal RPC index.
156 **********************************************************************************/
[503]157void __attribute__((noinline)) rpc_undefined( xptr_t xp __attribute__ ((unused)) );
[1]158
[23]159
160
[1]161/**********************************************************************************/
162/******* Marshalling functions attached to the various RPCs ***********************/
163/**********************************************************************************/
164
165/***********************************************************************************
[640]166 * [0] undefined
[1]167 **********************************************************************************/
[632]168
[1]169/***********************************************************************************
[640]170 * [1] undefined
[409]171 **********************************************************************************/
[632]172
[409]173/***********************************************************************************
[640]174 * [2] undefined
[1]175 **********************************************************************************/
[632]176
[1]177/***********************************************************************************
[409]178 * [3] The RPC_PROCESS_MAKE_FORK creates a "child" process descriptor, and the
[408]179 * associated "child" thread descriptor in a target remote cluster that can be
180 * any cluster.  The child process is initialized from informations found in the
181 * "parent" process descriptor (that must be the parent reference cluster),
182 * and from the "parent" thread descriptor that can be in any cluster.
[1]183 ***********************************************************************************
[408]184 * @ cxy              : server cluster identifier.
185 * @ ref_process_xp   : [in]  extended pointer on reference parent process.
186 * @ parent_thread_xp : [in]  extended pointer on parent thread.
187 * @ child_pid        : [out] child process identifier.
188 * @ child_thread_ptr : [out] local pointer on child thread.
189 * @ error            : [out]  error status (0 if success).
[1]190 **********************************************************************************/
[408]191void rpc_process_make_fork_client( cxy_t              cxy,
192                                   xptr_t             ref_process_xp,
193                                   xptr_t             parent_thread_xp,
194                                   pid_t            * child_pid,
195                                   struct thread_s ** child_thread_ptr,
196                                   error_t          * error );
[1]197
[408]198void rpc_process_make_fork_server( xptr_t xp );
[1]199
200/***********************************************************************************
[612]201 * [4] The RPC_USER_DIR_CREATE allows a client thread to create an user_dir_t
202 * structure and the associated array of dirents in a remote cluster containing
[614]203 * the target directory <inode>. It creates an ANON vseg in the user reference
204 * process VMM identified by the <ref_xp>. This reference cluster cluster can be
205 * different from both the client and server clusters.
206 * It is called by the sys_opendir() function.
[612]207 ***********************************************************************************
208 * @ cxy        : server cluster identifier.
209 * @ inode      : [in]   local pointer on inode in server cluster.
[614]210 * @ ref_xp     : [in]   extended pointer on user reference process descriptor.
[612]211 * @ dir        : [out]  local pointer on created user_dir structure.
[1]212 **********************************************************************************/
[612]213void rpc_user_dir_create_client( cxy_t                 cxy,
214                                 struct vfs_inode_s  * inode,
[614]215                                 xptr_t                ref_xp,
[612]216                                 struct user_dir_s  ** dir );
[1]217
[612]218void rpc_user_dir_create_server( xptr_t xp );
219
[1]220/***********************************************************************************
[612]221 * [5] The RPC_USER_DIR_DESTROY allows a client thread to delete an user_dir_t
222 * structure and the associated array of dirents in a remote cluster containing
223 * the target directory inode. It is called by the sys_closedir() function.
224 ***********************************************************************************
225 * @ cxy        : server cluster identifier.
226 * @ dir        : [in]  local pointer on created user_dir structure.
[614]227 * @ ref_xp     : [in]   extended pointer on user reference process descriptor.
[409]228 **********************************************************************************/
[612]229void rpc_user_dir_destroy_client( cxy_t               cxy,
[614]230                                  struct user_dir_s * dir,
231                                  xptr_t              ref_xp );
[409]232
[612]233void rpc_user_dir_destroy_server( xptr_t xp );
234
[409]235/***********************************************************************************
236 * [6] The RPC_THREAD_USER_CREATE creates an user thread in the server cluster,
[23]237 * as specified by the arguments. It returns an extended pointer on the new
238 * thread descriptor in server cluster, and an error code.
239 * It is called by the sys_thread_create() system call.
[1]240 ***********************************************************************************
241 * @ cxy       : server cluster identifier.
[407]242 * @ attr      : [in]  local pointer on pthread_attr_t in client cluster.
243 * @ thread_xp : [out] buffer for thread extended pointer.
[1]244 * @ error     : [out] error status (0 if success).
245 **********************************************************************************/
246void rpc_thread_user_create_client( cxy_t                   cxy,
[23]247                                    pid_t                   pid,
248                                    void                  * start_func,
249                                    void                  * start_arg,
[407]250                                    pthread_attr_t        * attr,
[1]251                                    xptr_t                * thread_xp,
252                                    error_t               * error );
253
254void rpc_thread_user_create_server( xptr_t xp );
255
256/***********************************************************************************
[409]257 * [7] The RPC_THREAD_KERNEL_CREATE creates a kernel thread in the server cluster,
[1]258 * as specified by the type, func and args arguments. It returns the local pointer
259 * on the thread descriptor in server cluster and an error code.
[23]260 * It is used by the dev_init() function to create the device server thread.
[1]261 ***********************************************************************************
262 * @ cxy       : server cluster identifier.
263 * @ type      : [in]  type of kernel thread.
264 * @ func      : [in]  local pointer on thread function.
265 * @ args      : [in]  local pointer on function arguments.
266 * @ thread_xp : [out] pointer on buffer for thread extended pointer.
267 * @ error     : [out] error status (0 if success).
268 **********************************************************************************/
269void rpc_thread_kernel_create_client( cxy_t     cxy,
270                                      uint32_t  type,
271                                      void    * func,
272                                      void    * args,
273                                      xptr_t  * thread_xp,
274                                      error_t * error );
275
276void rpc_thread_kernel_create_server( xptr_t xp );
277
[23]278/***********************************************************************************
[657]279 * [8] undefined
[23]280 **********************************************************************************/
281
[409]282/***********************************************************************************
[623]283 * [9] The RPC_PROCESS_SIGACTION allows a client thread to request a remote cluster
284 * to execute a given sigaction, defined by the <action_type> for a given process,
[657]285 * identified by the <pid> argument.  When this RPC is used in parallel mode,
286 * the rpc_process_sigaction_client() function is not used.
[409]287 ***********************************************************************************
[436]288 * @ cxy     : server cluster identifier.
[619]289 * @ pid     : [in] target process identifier.
290 * @ action  : [in] sigaction index.
[409]291 **********************************************************************************/
[619]292void rpc_process_sigaction_client( cxy_t     cxy,
293                                   pid_t     pid,
294                                   uint32_t  action );
[409]295                             
296void rpc_process_sigaction_server( xptr_t xp );
297
[1]298/***********************************************************************************
[657]299 * [10] undefined
[1]300 **********************************************************************************/
301
302/***********************************************************************************
[657]303 * [11] undefined
[1]304 **********************************************************************************/
305
306/***********************************************************************************
[657]307 * [12] undefined                                                       
[1]308 **********************************************************************************/
309
310/***********************************************************************************
[657]311 * [13] undefined                                       
[1]312 **********************************************************************************/
313
[23]314/***********************************************************************************
[657]315 * [14] undefined
[433]316 **********************************************************************************/
317
318/***********************************************************************************
[657]319 * [15] The RPC_VMM_RESIZE_VSEG allows a client thread to request a remote cluster
[641]320 * to resize a vseg identified by the <base> argument in a process descriptor
321 * identified by the <pid> argument, as defined by the <new_base> and <new_size>
322 * arguments. Both the VSL and the GPT are updated in the remote cluster.
[611]323 ***********************************************************************************
[313]324 * @ cxy         : server cluster identifier.
[641]325 * @ pid         : [in] process identifier.
326 * @ base        : [in] vseg base.
327 * @ new_base    : [in] new vseg base.
[640]328 * @ new_size    : [in] new vseg size.
[313]329 **********************************************************************************/
[640]330void rpc_vmm_resize_vseg_client( cxy_t              cxy,
[641]331                                 pid_t              pid,
332                                 intptr_t           base,
[640]333                                 intptr_t           new_base,
334                                 intptr_t           new_size );
[601]335 
[640]336void rpc_vmm_resize_vseg_server( xptr_t xp );
337
[601]338/***********************************************************************************
[657]339 * [16] The RPC_VMM_REMOVE_VSEG allows a client thread  to request a remote cluster
[641]340 * to delete a vseg identified by the <vaddr> argument in a process descriptor
341 * identified by the <pid> argument.
342 * Both the VSL and the GPT are updated in the remote cluster.
[611]343 ***********************************************************************************
[641]344 * @ cxy       : server cluster identifier.
345 * @ pid       : [in] process identifier.
346 * @ base      : [in] vseg base.
[601]347 **********************************************************************************/
[641]348void rpc_vmm_remove_vseg_client( cxy_t      cxy,
349                                 pid_t      pid,
350                                 intptr_t   base );
[611]351 
[640]352void rpc_vmm_remove_vseg_server( xptr_t xp );
[1]353
[407]354/***********************************************************************************
[657]355 * [17] The RPC_VMM_CREATE_VSEG allows a client thread to request the remote
[407]356 * reference cluster of a given process to allocate and register in the reference
357 * process VMM a new vseg descriptor.
358 * On the server side, this RPC uses the vmm_create_vseg() function, and returns
359 * to the client the local pointer on the created vseg descriptor.
360 ***********************************************************************************
361 * @ cxy         : server cluster identifier.
362 * @ process     : [in]  local pointer on process descriptor in server.
363 * @ type        : [in]  vseg type.
364 * @ base        : [in]  base address (unused for dynamically allocated vsegs).
365 * @ size        : [in]  number of bytes.
366 * @ file_offset : [in]  offset in file (for CODE, DATA, FILE types).
367 * @ file_size   : [in]  can be smaller than size for DATA type.
368 * @ mapper_xp   : [in]  extended pointer on mapper (for CODE, DATA, FILE types).
369 * @ vseg_cxy    : [in]  target cluster for mapping (if not data type).
370 * @ vseg        : [out] local pointer on vseg descriptor / NULL if failure.
371 **********************************************************************************/
372void rpc_vmm_create_vseg_client( cxy_t              cxy,
373                                 struct process_s * process,
374                                 vseg_type_t        type,
375                                 intptr_t           base,
376                                 uint32_t           size,
377                                 uint32_t           file_offset,
378                                 uint32_t           file_size,
379                                 xptr_t             mapper_xp,
380                                 cxy_t              vseg_cxy,
381                                 struct vseg_s   ** vseg );
382
383void rpc_vmm_create_vseg_server( xptr_t xp );
384
385/***********************************************************************************
[657]386 * [18] The RPC_VMM_SET_COW allows a client thread to request the remote reference
[408]387 * cluster to set the COW flag and reset the WRITABLE flag of all GPT entries for
388 * the DATA, MMAP and REMOTE vsegs of process identified by the <process> argument.
389
390 * of a remote scheduler, identified by the <lid> argument.
391 ***********************************************************************************
392 * @ cxy         : server cluster identifier.
393 * @ process     : [in]  local pointer on reference process descriptor.
394 **********************************************************************************/
395void rpc_vmm_set_cow_client( cxy_t              cxy,
396                             struct process_s * process );
397
398void rpc_vmm_set_cow_server( xptr_t xp );
399
[428]400/***********************************************************************************
[657]401 * [19] undefined
[428]402 **********************************************************************************/
[635]403
[428]404
[1]405#endif
Note: See TracBrowser for help on using the repository browser.