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

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

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

File size: 20.4 KB
Line 
1/*
2 * rpc.h - RPC (Remote Procedure Call) operations definition.
3 *
4 * Author  Alain Greiner (2016,2017,2018,2019,2020)
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_kernel_types.h>
29#include <hal_atomic.h>
30#include <bits.h>
31#include <vseg.h>
32#include <remote_fifo.h>
33
34/**** Forward declarations ****/
35
36struct process_s;
37struct page_s;
38struct vseg_s;
39struct exec_info_s;
40struct pthread_attr_s;
41struct remote_sem_s;
42struct user_dir_s;
43struct fragment_s;
44struct vfs_inode_s;
45struct vfs_dentry_s;
46struct vfs_file_s;
47struct thread_s;
48struct mapper_s;
49
50
51/**********************************************************************************/
52/**************  structures for Remote Procedure Calls ****************************/
53/**********************************************************************************/
54
55/***********************************************************************************
56 * This enum defines all RPC indexes.
57 * It must be consistent with the rpc_server[] arrays defined in in the rpc.c file.
58 **********************************************************************************/
59
60typedef enum
61{
62    RPC_UNDEFINED_0               = 0,   //
63    RPC_UNDEFINED_1               = 1,   //
64    RPC_UNDEFINED_2               = 2,   //     
65    RPC_PROCESS_MAKE_FORK         = 3,
66    RPC_USER_DIR_CREATE           = 4,
67    RPC_USER_DIR_DESTROY          = 5,
68    RPC_THREAD_USER_CREATE        = 6,
69    RPC_THREAD_KERNEL_CREATE      = 7,
70    RPC_UNDEFINED_8               = 8,
71    RPC_PROCESS_SIGACTION         = 9,
72
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,   //
83
84    RPC_MAX_INDEX                 = 20,
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/***********************************************************************************
96 *  This structure defines the RPC descriptor (100 bytes on a 32bits core)
97 **********************************************************************************/
98
99typedef struct rpc_desc_s
100{
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) */
107} 
108rpc_desc_t;
109
110/**********************************************************************************/
111/******* Generic functions supporting RPCs : client side **************************/
112/**********************************************************************************/
113
114/***********************************************************************************
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.
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.
124 * - When the <blocking> field is false, this function returns as soon as the RPC
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.
127 ***********************************************************************************
128 * @ cxy   : server cluster identifier
129 * @ desc  : local pointer on RPC descriptor in client cluster
130 **********************************************************************************/
131void rpc_send( cxy_t        cxy,   
132               rpc_desc_t * desc );
133
134
135
136/**********************************************************************************/
137/******* Generic functions supporting RPCs : server side **************************/
138/**********************************************************************************/
139
140/***********************************************************************************
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. 
151 **********************************************************************************/
152void rpc_server_func( void );
153
154/***********************************************************************************
155 * This function is executed in case of illegal RPC index.
156 **********************************************************************************/
157void __attribute__((noinline)) rpc_undefined( xptr_t xp __attribute__ ((unused)) );
158
159
160
161/**********************************************************************************/
162/******* Marshalling functions attached to the various RPCs ***********************/
163/**********************************************************************************/
164
165/***********************************************************************************
166 * [0] undefined
167 **********************************************************************************/
168
169/***********************************************************************************
170 * [1] undefined
171 **********************************************************************************/
172
173/***********************************************************************************
174 * [2] undefined
175 **********************************************************************************/
176
177/***********************************************************************************
178 * [3] The RPC_PROCESS_MAKE_FORK creates a "child" process descriptor, and the
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.
183 ***********************************************************************************
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).
190 **********************************************************************************/
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 );
197
198void rpc_process_make_fork_server( xptr_t xp );
199
200/***********************************************************************************
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
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.
207 ***********************************************************************************
208 * @ cxy        : server cluster identifier.
209 * @ inode      : [in]   local pointer on inode in server cluster.
210 * @ ref_xp     : [in]   extended pointer on user reference process descriptor.
211 * @ dir        : [out]  local pointer on created user_dir structure.
212 **********************************************************************************/
213void rpc_user_dir_create_client( cxy_t                 cxy,
214                                 struct vfs_inode_s  * inode,
215                                 xptr_t                ref_xp,
216                                 struct user_dir_s  ** dir );
217
218void rpc_user_dir_create_server( xptr_t xp );
219
220/***********************************************************************************
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.
227 * @ ref_xp     : [in]   extended pointer on user reference process descriptor.
228 **********************************************************************************/
229void rpc_user_dir_destroy_client( cxy_t               cxy,
230                                  struct user_dir_s * dir,
231                                  xptr_t              ref_xp );
232
233void rpc_user_dir_destroy_server( xptr_t xp );
234
235/***********************************************************************************
236 * [6] The RPC_THREAD_USER_CREATE creates an user thread in the server cluster,
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.
240 ***********************************************************************************
241 * @ cxy       : server cluster identifier.
242 * @ attr      : [in]  local pointer on pthread_attr_t in client cluster.
243 * @ thread_xp : [out] buffer for thread extended pointer.
244 * @ error     : [out] error status (0 if success).
245 **********************************************************************************/
246void rpc_thread_user_create_client( cxy_t                   cxy,
247                                    pid_t                   pid,
248                                    void                  * start_func,
249                                    void                  * start_arg,
250                                    pthread_attr_t        * attr,
251                                    xptr_t                * thread_xp,
252                                    error_t               * error );
253
254void rpc_thread_user_create_server( xptr_t xp );
255
256/***********************************************************************************
257 * [7] The RPC_THREAD_KERNEL_CREATE creates a kernel thread in the server cluster,
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.
260 * It is used by the dev_init() function to create the device server thread.
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
278/***********************************************************************************
279 * [8] undefined
280 **********************************************************************************/
281
282/***********************************************************************************
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,
285 * identified by the <pid> argument.  When this RPC is used in parallel mode,
286 * the rpc_process_sigaction_client() function is not used.
287 ***********************************************************************************
288 * @ cxy     : server cluster identifier.
289 * @ pid     : [in] target process identifier.
290 * @ action  : [in] sigaction index.
291 **********************************************************************************/
292void rpc_process_sigaction_client( cxy_t     cxy,
293                                   pid_t     pid,
294                                   uint32_t  action );
295                             
296void rpc_process_sigaction_server( xptr_t xp );
297
298/***********************************************************************************
299 * [10] undefined
300 **********************************************************************************/
301
302/***********************************************************************************
303 * [11] undefined
304 **********************************************************************************/
305
306/***********************************************************************************
307 * [12] undefined                                                       
308 **********************************************************************************/
309
310/***********************************************************************************
311 * [13] undefined                                       
312 **********************************************************************************/
313
314/***********************************************************************************
315 * [14] undefined
316 **********************************************************************************/
317
318/***********************************************************************************
319 * [15] The RPC_VMM_RESIZE_VSEG allows a client thread to request a remote cluster
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.
323 ***********************************************************************************
324 * @ cxy         : server cluster identifier.
325 * @ pid         : [in] process identifier.
326 * @ base        : [in] vseg base.
327 * @ new_base    : [in] new vseg base.
328 * @ new_size    : [in] new vseg size.
329 **********************************************************************************/
330void rpc_vmm_resize_vseg_client( cxy_t              cxy,
331                                 pid_t              pid,
332                                 intptr_t           base,
333                                 intptr_t           new_base,
334                                 intptr_t           new_size );
335 
336void rpc_vmm_resize_vseg_server( xptr_t xp );
337
338/***********************************************************************************
339 * [16] The RPC_VMM_REMOVE_VSEG allows a client thread  to request a remote cluster
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.
343 ***********************************************************************************
344 * @ cxy       : server cluster identifier.
345 * @ pid       : [in] process identifier.
346 * @ base      : [in] vseg base.
347 **********************************************************************************/
348void rpc_vmm_remove_vseg_client( cxy_t      cxy,
349                                 pid_t      pid,
350                                 intptr_t   base );
351 
352void rpc_vmm_remove_vseg_server( xptr_t xp );
353
354/***********************************************************************************
355 * [17] The RPC_VMM_CREATE_VSEG allows a client thread to request the remote
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/***********************************************************************************
386 * [18] The RPC_VMM_SET_COW allows a client thread to request the remote reference
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
400/***********************************************************************************
401 * [19] undefined
402 **********************************************************************************/
403
404
405#endif
Note: See TracBrowser for help on using the repository browser.