source: trunk/kernel/kern/cluster.h @ 424

Last change on this file since 424 was 416, checked in by alain, 7 years ago

Improve sys_exec.

File size: 14.4 KB
RevLine 
[1]1/*
2 * cluster.h - Cluster-Manager definition
[19]3 *
[1]4 * authors  Ghassan Almaless (2008,2009,2010,2011,2012)
5 *          Mohamed Lamine Karaoui (2015)
[23]6 *          Alain Greiner (2016,2017)
[1]7 *
8 * Copyright (c) UPMC Sorbonne Universites
9 *
10 * This file is part of ALMOS-MKH.
11 *
12 * ALMOS-MKH is free software; you can redistribute it and/or modify it
13 * under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; version 2.0 of the License.
15 *
16 * ALMOS-MKH is distributed in the hope that it will be useful, but
17 * WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
19 * General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with ALMOS-MKH; if not, write to the Free Software Foundation,
23 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24 */
25
26#ifndef _CLUSTER_H_
27#define _CLUSTER_H_
28
[14]29#include <kernel_config.h>
[1]30#include <hal_types.h>
31#include <bits.h>
32#include <spinlock.h>
33#include <readlock.h>
34#include <remote_barrier.h>
35#include <list.h>
36#include <xlist.h>
37#include <dqdt.h>
38#include <kmem.h>
39#include <hal_atomic.h>
40#include <ppm.h>
41#include <kcm.h>
42#include <khm.h>
43#include <rpc.h>
44#include <core.h>
45#include <process.h>
46
47/**** Forward declarations  ****/
48
49struct core_s;
50struct process_s;
51
52
53/*******************************************************************************************
54 * This structure defines the process manager, that is part of the cluster manager.
55 * For any process P, the process descriptor is replicated in all clusters containing
[19]56 * at least one thread of process P, but only the "reference" cluster descriptor contains
[23]57 * the reference (complete) GPT, VSL, and FDT structures.
58 * The "owner" cluster K is in charge to allocate a lpid (local process index),
59 * to the owned processes, and to register the "reference" cluster for these processes.
[1]60 *
[19]61 * Warning : the "owner" cluster, and the "reference" cluster can be different clusters.
[1]62 *
63 * The process manager of a cluster K maintains three structures:
[23]64 * 1) The pref_tbl[] is an array indexed by lpid. There is one entry per owned process.
[1]65 *    Each entry contains an extended pointer on the reference process descriptor.
[23]66 *
[1]67 * 2) The local_root is the root of the local list of process descriptors in cluster K.
68 *    A process descriptor P is present in K, as soon as P has a thread in cluster K.
[23]69 *
70 * 3) The copies_root[] array is indexed by lpid. There is one entry per owned process,
71 *    and each each entry contains the root of the xlist of copies for this process.
[1]72 ******************************************************************************************/
73
74typedef struct process_manager_s
75{
76        xptr_t            pref_tbl[CONFIG_MAX_PROCESS_PER_CLUSTER];  /*! reference  process   */
77        spinlock_t        pref_lock;              /*! lock protecting lpid allocation/release */
78    uint32_t          pref_nr;                /*! number of processes owned by cluster    */
79
[23]80    xlist_entry_t     local_root;             /*! root of list of process in cluster      */
81    remote_spinlock_t local_lock;             /*! lock protecting access to local list    */
[1]82    uint32_t          local_nr;               /*! number of process in cluster            */
83
[19]84    xlist_entry_t     copies_root[CONFIG_MAX_PROCESS_PER_CLUSTER];  /*! roots of lists    */
[1]85    remote_spinlock_t copies_lock[CONFIG_MAX_PROCESS_PER_CLUSTER];  /*! one lock per list */
86    uint32_t          copies_nr[CONFIG_MAX_PROCESS_PER_CLUSTER];    /*! number of copies  */
87}
88pmgr_t;
89
90/*******************************************************************************************
91 * This structure defines a cluster manager.
[19]92 * It contains both global platform information, and cluster specific resources
[279]93 * controled by the local kernel instance.
[1]94 ******************************************************************************************/
95
96typedef struct cluster_s
97{
[23]98        spinlock_t        kcm_lock;        /*! local, protect creation of KCM allocators      */
[1]99
100    // global parameters
[23]101        uint32_t          paddr_width;     /*! numer of bits in physical address              */
102    uint32_t          x_width;         /*! number of bits to code x_size  (can be 0)      */
103    uint32_t          y_width;         /*! number of bits to code y_size  (can be 0)      */
104        uint32_t          x_size;          /*! number of clusters in a row    (can be 1)      */
105        uint32_t          y_size;          /*! number of clusters in a column (can be 1)      */
106        cxy_t             io_cxy;          /*! io cluster identifier                          */
107    uint32_t          dqdt_root_level; /*! index of root node in dqdt_tbl[]               */
[1]108
109    // local parameters
[407]110        uint32_t          cores_nr;        /*! actual number of cores in cluster              */
[279]111    uint32_t          ram_size;        /*! physical memory size                           */
112    uint32_t          ram_base;        /*! physical memory base (local address)           */
113
[5]114        core_t            core_tbl[CONFIG_MAX_LOCAL_CORES];         /*! embedded cores        */
[1]115
[279]116        list_entry_t      dev_root;        /*! root of list of devices in cluster             */
117
118    // memory allocators
[23]119        ppm_t             ppm;             /*! embedded kernel page manager                   */
120        khm_t             khm;             /*! embedded kernel heap manager                   */
121        kcm_t             kcm;             /*! embedded kernel cache manager (for KCMs)       */
[1]122    kcm_t           * kcm_tbl[KMEM_TYPES_NR];         /*! pointers on allocated KCMs      */
123
[279]124    // RPC
[407]125        remote_fifo_t     rpc_fifo;        /*! RPC fifo (one per cluster)                     */
126    uint32_t          rpc_threads;     /*! current number of RPC threads in cluster       */
[1]127
[279]128    // DQDT
[23]129    int32_t           pages_var;       /*! pages number increment from last DQQT update   */
130    int32_t           threads_var;     /*! threads number increment from last DQDT update */
[1]131
[409]132        dqdt_node_t       dqdt_tbl[CONFIG_DQDT_LEVELS_NR]; /*! embedded DQDT nodes in cluster */
[1]133
[279]134    // Local process manager
[23]135    pmgr_t            pmgr;            /*! embedded process manager                       */
[188]136
137    void            * pic_extend;      /*! PIC implementation specific extension          */
[19]138}
[1]139cluster_t;
140
141/******************************************************************************************
142 * This global variable is allocated in the kernel_init.c file.
[19]143 * There is one cluster_manager per cluster, with the same local address,
144 * but different content, in all clusters containing a kernel instance.
[1]145 *****************************************************************************************/
146
147extern cluster_t cluster_manager;
148
149/******************************************************************************************
150 * This macro returns a local pointer on the local cluster manager.
151 *****************************************************************************************/
152
153#define LOCAL_CLUSTER    (&cluster_manager)
154
155/******************************************************************************************
[19]156 * This generic function initialises the local cluster manager from information found
[1]157 * in the local boot-info structure. It initializes the following local resources:
158 * - the global platform parameters,
159 * - the specific cluster parameters,
160 * - the lock protecting KCM creation,
161 * - the local DQDT nodes,
162 * - the PPM, KHM, and KCM allocators,
163 * - the local core descriptors,
164 * - the local RPC FIFO,
165 * - the process manager.
166 * It does NOT initialise the local device descriptors.
167 ******************************************************************************************
168 * @ info : pointer on the local boot_info_t structure build by the bootloader.
169 *****************************************************************************************/
[19]170error_t cluster_init( boot_info_t * info );
[1]171
172/******************************************************************************************
[407]173 * This function checks the validity of a cluster identifier.
[1]174 ******************************************************************************************
175 * @ cxy    : cluster identifier to be checked.
176 * @ returns true if the identified cluster does not exist.
177 *****************************************************************************************/
178bool_t cluster_is_undefined( cxy_t cxy );
179
180
181/*****************************************************************************************/
182/***************   Process Management Operations   ***************************************/
183/*****************************************************************************************/
184
185/******************************************************************************************
186 * This function returns an extended pointer on the reference process descriptor
[101]187 * from the process PID. This PID can be be different from the calling process PID.
[23]188 * It can be called by any thread running in any cluster,
[1]189 ******************************************************************************************
190 * @ pid  : process identifier.
[23]191 * @ return extended pointer on reference process if success / return XPTR_NULL if error.
[1]192 *****************************************************************************************/
193xptr_t cluster_get_reference_process_from_pid( pid_t pid );
194
[19]195/******************************************************************************************
[1]196 * This function allocates a new PID in local cluster, that becomes the process owner.
[19]197 * It registers the process descriptor extended pointer in the local processs manager
[408]198 * pref_tbl[] array. This function is called by the process_make_fork() function,
[416]199 * by the process_make_exec() function, and by the process_init_create() function.
[1]200 ******************************************************************************************
[416]201 * @ process    : pointer on process descriptor.
[1]202 * @ pid        : [out] allocated PID.
[416]203 * @ return 0 if success / return -1 if no PID slot available.
[1]204 *****************************************************************************************/
[416]205error_t cluster_pid_alloc( struct process_s * process,
206                           pid_t            * pid );
[1]207
[19]208/******************************************************************************************
[1]209 * This function removes a PID from the local process manager pref_tbl[] array.
210 * It checks that removed process is owned by the local cluster and the lpid is legal.
211 * No memory is released by this function.
212 ******************************************************************************************
213 * @ pid        : allocated PID.
214 *****************************************************************************************/
215void cluster_pid_release( pid_t  pid );
216
217/******************************************************************************************
218 * This function returns a pointer on the local process descriptor from the PID.
219 * It uses the RPC
220 * to create a local process descriptor copy if it does not exist yet.
221 ******************************************************************************************
222 * @ pid     : searched process identifier.
223 * @ returns process descriptor pointer if found / returns NULL if not found.
224 *****************************************************************************************/
225struct process_s * cluster_get_local_process_from_pid( pid_t pid );
226
227/******************************************************************************************
228 * This function registers a local process descriptor in the process manager local_list.
229 ******************************************************************************************
230 * @ process     : pointer on local process descriptor.
231 *****************************************************************************************/
[19]232void cluster_process_local_link( struct process_s * process );
[1]233
234/******************************************************************************************
235 * This function removes a local process descriptor from the process manager local_list.
236 ******************************************************************************************
237 * @ process     : pointer on local process descriptor.
238 *****************************************************************************************/
[19]239void cluster_process_local_unlink( struct process_s * process );
[1]240
241/******************************************************************************************
242 * This function registers a local process descriptor in the owner process manager
243 * copies_list, that can be in a remote cluster.
244 ******************************************************************************************
245 * @ process     : pointer on local process descriptor.
246 *****************************************************************************************/
[19]247void cluster_process_copies_link( struct process_s * process );
[1]248
249/******************************************************************************************
250 * This function removes a local process descriptor from the owner process manager
251 * copies_list, that can be in a remote cluster.
252 ******************************************************************************************
253 * @ process     : pointer on local process descriptor.
254 *****************************************************************************************/
[19]255void cluster_process_copies_unlink( struct process_s * process );
[1]256
257
258
259/*****************************************************************************************/
260/***************   Cores Management Operations   *****************************************/
261/*****************************************************************************************/
262
263/******************************************************************************************
264 * This function increments the "cores_in_kernel" variable in cluster descriptor.
265 *****************************************************************************************/
266void cluster_core_kernel_enter();
267
268/******************************************************************************************
269 * This function decrements the "cores_in_kernel" variable in cluster descriptor.
270 *****************************************************************************************/
271void cluster_core_kernel_exit();
272
273/******************************************************************************************
274 * This function returns the core local index that has the lowest usage in local cluster.
275 *****************************************************************************************/
276lid_t cluster_select_local_core();
277
278#endif  /* _CLUSTER_H_ */
Note: See TracBrowser for help on using the repository browser.