[1] | 1 | /* |
---|
| 2 | * cluster.h - Cluster-Manager definition |
---|
| 3 | * |
---|
| 4 | * authors Ghassan Almaless (2008,2009,2010,2011,2012) |
---|
| 5 | * Mohamed Lamine Karaoui (2015) |
---|
| 6 | * Alain Greiner (2016) |
---|
| 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 | |
---|
| 49 | struct core_s; |
---|
| 50 | struct process_s; |
---|
| 51 | struct device_s; |
---|
| 52 | |
---|
| 53 | |
---|
| 54 | /******************************************************************************************* |
---|
| 55 | * This structure defines the process manager, that is part of the cluster manager. |
---|
| 56 | * For any process P, the process descriptor is replicated in all clusters containing |
---|
| 57 | * at least one thread of process P, but only the "reference" cluster descriptor contains |
---|
| 58 | * the reference (complete) structures such as the GPT, the VSL, or the FDT. |
---|
| 59 | * The "owner" cluster is in charge to allocate a lpid (local process index), |
---|
| 60 | * for all process owned by a cluster K, and to register the "reference" cluster for |
---|
| 61 | * all process owned by K. |
---|
| 62 | * |
---|
| 63 | * Warning : the "owner" cluster, and the "reference" cluster can be different clusters. |
---|
| 64 | * |
---|
| 65 | * The process manager of a cluster K maintains three structures: |
---|
| 66 | * 1) The pref_tbl[] is an array indexed by lpid, for all processes owned by cluster K. |
---|
| 67 | * Each entry contains an extended pointer on the reference process descriptor. |
---|
| 68 | * 2) The local_root is the root of the local list of process descriptors in cluster K. |
---|
| 69 | * A process descriptor P is present in K, as soon as P has a thread in cluster K. |
---|
| 70 | * 3) The copies_root[] array is indexed by lpid. Each entry contains the root of |
---|
| 71 | * the xlist of copies for a given process owned by cluster K. |
---|
| 72 | ******************************************************************************************/ |
---|
| 73 | |
---|
| 74 | typedef 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 | |
---|
| 80 | list_entry_t local_root; /*! root of list of process in cluster */ |
---|
| 81 | spinlock_t local_lock; /*! lock protecting access to local list */ |
---|
| 82 | uint32_t local_nr; /*! number of process in cluster */ |
---|
| 83 | |
---|
| 84 | xlist_entry_t copies_root[CONFIG_MAX_PROCESS_PER_CLUSTER]; /*! roots of lists */ |
---|
| 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 | } |
---|
| 88 | pmgr_t; |
---|
| 89 | |
---|
| 90 | /******************************************************************************************* |
---|
| 91 | * This structure defines a cluster manager. |
---|
| 92 | * It contains both global platform informations, and cluster specific ressources |
---|
| 93 | * managed by the local kernel instance. |
---|
| 94 | ******************************************************************************************/ |
---|
| 95 | |
---|
| 96 | typedef struct cluster_s |
---|
| 97 | { |
---|
| 98 | spinlock_t kcm_lock; /*! local, protect creation of KCM allocators */ |
---|
| 99 | |
---|
| 100 | // global parameters |
---|
| 101 | |
---|
| 102 | uint32_t paddr_width; /*! numer of bits in physical address */ |
---|
| 103 | uint32_t x_width; /*! number of bits to code x_size (can be 0) */ |
---|
| 104 | uint32_t y_width; /*! number of bits to code y_size (can be 0) */ |
---|
| 105 | uint32_t x_size; /*! number of clusters in a row (can be 1) */ |
---|
| 106 | uint32_t y_size; /*! number of clusters in a column (can be 1) */ |
---|
| 107 | cxy_t io_cxy; /*! io cluster identifier */ |
---|
| 108 | uint32_t dqdt_root_level; /*! index of root node in dqdt_tbl[] */ |
---|
| 109 | |
---|
| 110 | // local parameters |
---|
| 111 | |
---|
| 112 | uint32_t cores_nr; /*! number of cores in cluster */ |
---|
| 113 | uint32_t cores_in_kernel; /*! number of cores currently in kernel mode */ |
---|
| 114 | |
---|
[5] | 115 | core_t core_tbl[CONFIG_MAX_LOCAL_CORES]; /*! embedded cores */ |
---|
[1] | 116 | |
---|
| 117 | ppm_t ppm; /*! embedded kernel page manager */ |
---|
| 118 | khm_t khm; /*! embedded kernel heap manager */ |
---|
| 119 | kcm_t kcm; /*! embedded kernel cache manager (for KCMs) */ |
---|
| 120 | |
---|
| 121 | kcm_t * kcm_tbl[KMEM_TYPES_NR]; /*! pointers on allocated KCMs */ |
---|
| 122 | |
---|
| 123 | uint32_t ram_size; /*! physical memory size */ |
---|
| 124 | uint32_t ram_base; /*! physical memory base (local address) */ |
---|
| 125 | |
---|
| 126 | rpc_fifo_t rpc_fifo; /*! cluster RPC fifo (shared) */ |
---|
| 127 | list_entry_t devlist; /*! root of list of devices in cluster */ |
---|
| 128 | struct device_s * icu; /*! pointer on local XCU device */ |
---|
| 129 | |
---|
| 130 | int32_t pages_var; /*! pages number increment from last update */ |
---|
| 131 | int32_t threads_var; /*! threads number increment from last update */ |
---|
| 132 | |
---|
| 133 | dqdt_node_t dqdt_tbl[CONFIG_MAX_DQDT_DEPTH]; /*! embedded DQDT nodes */ |
---|
| 134 | |
---|
| 135 | pmgr_t pmgr; /*! embedded process manager */ |
---|
| 136 | |
---|
| 137 | char name[CONFIG_SYSFS_NAME_LEN]; |
---|
[14] | 138 | |
---|
| 139 | // sysfs_entry_t node; |
---|
[1] | 140 | } |
---|
| 141 | cluster_t; |
---|
| 142 | |
---|
| 143 | /****************************************************************************************** |
---|
| 144 | * This global variable is allocated in the kernel_init.c file. |
---|
| 145 | * There is one cluster_manager per cluster, with the same local address, |
---|
[5] | 146 | * but different content, in all clusters containing a kernel instance. |
---|
[1] | 147 | *****************************************************************************************/ |
---|
| 148 | |
---|
| 149 | extern cluster_t cluster_manager; |
---|
| 150 | |
---|
| 151 | /****************************************************************************************** |
---|
| 152 | * This macro returns a local pointer on the local cluster manager. |
---|
| 153 | *****************************************************************************************/ |
---|
| 154 | |
---|
| 155 | #define LOCAL_CLUSTER (&cluster_manager) |
---|
| 156 | |
---|
| 157 | /****************************************************************************************** |
---|
| 158 | * This generic function initialises the local cluster manager from informations found |
---|
| 159 | * in the local boot-info structure. It initializes the following local resources: |
---|
| 160 | * - the global platform parameters, |
---|
| 161 | * - the specific cluster parameters, |
---|
| 162 | * - the lock protecting KCM creation, |
---|
| 163 | * - the local DQDT nodes, |
---|
| 164 | * - the PPM, KHM, and KCM allocators, |
---|
| 165 | * - the local core descriptors, |
---|
| 166 | * - the local RPC FIFO, |
---|
| 167 | * - the process manager. |
---|
| 168 | * It does NOT initialise the local device descriptors. |
---|
| 169 | ****************************************************************************************** |
---|
| 170 | * @ info : pointer on the local boot_info_t structure build by the bootloader. |
---|
| 171 | *****************************************************************************************/ |
---|
| 172 | error_t cluster_init( boot_info_t * info ); |
---|
| 173 | |
---|
| 174 | /****************************************************************************************** |
---|
| 175 | * This function cheks the validity of a cluster identifier. TODO useful ??? [AG] |
---|
| 176 | ****************************************************************************************** |
---|
| 177 | * @ cxy : cluster identifier to be checked. |
---|
| 178 | * @ returns true if the identified cluster does not exist. |
---|
| 179 | *****************************************************************************************/ |
---|
| 180 | bool_t cluster_is_undefined( cxy_t cxy ); |
---|
| 181 | |
---|
| 182 | /****************************************************************************************** |
---|
| 183 | * This function register sysfs information in cluster TODO ??? [AG] |
---|
| 184 | *****************************************************************************************/ |
---|
| 185 | void cluster_sysfs_register(); |
---|
| 186 | |
---|
| 187 | |
---|
| 188 | /*****************************************************************************************/ |
---|
| 189 | /*************** Process Management Operations ***************************************/ |
---|
| 190 | /*****************************************************************************************/ |
---|
| 191 | |
---|
| 192 | /****************************************************************************************** |
---|
| 193 | * This function returns an extended pointer on the reference process descriptor |
---|
| 194 | * from the process PID. It can be called by any thread running in any cluster, |
---|
| 195 | * as it uses a RPC to the owner cluster if the current cluster is not the owner. |
---|
| 196 | ****************************************************************************************** |
---|
| 197 | * @ pid : process identifier. |
---|
| 198 | * @ return extended pointer on the reference process descriptor. |
---|
| 199 | *****************************************************************************************/ |
---|
| 200 | xptr_t cluster_get_reference_process_from_pid( pid_t pid ); |
---|
| 201 | |
---|
| 202 | /****************************************************************************************** |
---|
| 203 | * This function allocates a new PID in local cluster, that becomes the process owner. |
---|
| 204 | * It register the process descriptor extended pointer in the local processs manager |
---|
| 205 | * pref_tbl[] array. This function is called by the rpc_process_alloc_pid() function for |
---|
| 206 | * remote registration, or by the process_init_create() function for local registration. |
---|
| 207 | ****************************************************************************************** |
---|
| 208 | * @ process : [in] extended pointer on the process descriptor. |
---|
| 209 | * @ pid : [out] allocated PID. |
---|
| 210 | * @ return 0 if success / return EAGAIN if no PID slot available |
---|
| 211 | *****************************************************************************************/ |
---|
| 212 | error_t cluster_pid_alloc( xptr_t process_xp, |
---|
| 213 | pid_t * pid ); |
---|
| 214 | |
---|
| 215 | /****************************************************************************************** |
---|
| 216 | * This function removes a PID from the local process manager pref_tbl[] array. |
---|
| 217 | * It checks that removed process is owned by the local cluster and the lpid is legal. |
---|
| 218 | * No memory is released by this function. |
---|
| 219 | ****************************************************************************************** |
---|
| 220 | * @ pid : allocated PID. |
---|
| 221 | *****************************************************************************************/ |
---|
| 222 | void cluster_pid_release( pid_t pid ); |
---|
| 223 | |
---|
| 224 | /****************************************************************************************** |
---|
| 225 | * This function returns a pointer on the local process descriptor from the PID. |
---|
| 226 | * It uses the RPC |
---|
| 227 | * to create a local process descriptor copy if it does not exist yet. |
---|
| 228 | ****************************************************************************************** |
---|
| 229 | * @ pid : searched process identifier. |
---|
| 230 | * @ returns process descriptor pointer if found / returns NULL if not found. |
---|
| 231 | *****************************************************************************************/ |
---|
| 232 | struct process_s * cluster_get_local_process_from_pid( pid_t pid ); |
---|
| 233 | |
---|
| 234 | /****************************************************************************************** |
---|
| 235 | * This function registers a local process descriptor in the process manager local_list. |
---|
| 236 | ****************************************************************************************** |
---|
| 237 | * @ process : pointer on local process descriptor. |
---|
| 238 | *****************************************************************************************/ |
---|
| 239 | void cluster_process_local_link( struct process_s * process ); |
---|
| 240 | |
---|
| 241 | /****************************************************************************************** |
---|
| 242 | * This function removes a local process descriptor from the process manager local_list. |
---|
| 243 | ****************************************************************************************** |
---|
| 244 | * @ process : pointer on local process descriptor. |
---|
| 245 | *****************************************************************************************/ |
---|
| 246 | void cluster_process_local_unlink( struct process_s * process ); |
---|
| 247 | |
---|
| 248 | /****************************************************************************************** |
---|
| 249 | * This function registers a local process descriptor in the owner process manager |
---|
| 250 | * copies_list, that can be in a remote cluster. |
---|
| 251 | ****************************************************************************************** |
---|
| 252 | * @ process : pointer on local process descriptor. |
---|
| 253 | *****************************************************************************************/ |
---|
| 254 | void cluster_process_copies_link( struct process_s * process ); |
---|
| 255 | |
---|
| 256 | /****************************************************************************************** |
---|
| 257 | * This function removes a local process descriptor from the owner process manager |
---|
| 258 | * copies_list, that can be in a remote cluster. |
---|
| 259 | ****************************************************************************************** |
---|
| 260 | * @ process : pointer on local process descriptor. |
---|
| 261 | *****************************************************************************************/ |
---|
| 262 | void cluster_process_copies_unlink( struct process_s * process ); |
---|
| 263 | |
---|
| 264 | |
---|
| 265 | |
---|
| 266 | /*****************************************************************************************/ |
---|
| 267 | /*************** Cores Management Operations *****************************************/ |
---|
| 268 | /*****************************************************************************************/ |
---|
| 269 | |
---|
| 270 | /****************************************************************************************** |
---|
| 271 | * This function increments the "cores_in_kernel" variable in cluster descriptor. |
---|
| 272 | *****************************************************************************************/ |
---|
| 273 | void cluster_core_kernel_enter(); |
---|
| 274 | |
---|
| 275 | /****************************************************************************************** |
---|
| 276 | * This function decrements the "cores_in_kernel" variable in cluster descriptor. |
---|
| 277 | *****************************************************************************************/ |
---|
| 278 | void cluster_core_kernel_exit(); |
---|
| 279 | |
---|
| 280 | /****************************************************************************************** |
---|
| 281 | * This function returns the core local index that has the lowest usage in local cluster. |
---|
| 282 | *****************************************************************************************/ |
---|
| 283 | lid_t cluster_select_local_core(); |
---|
| 284 | |
---|
| 285 | #endif /* _CLUSTER_H_ */ |
---|