[1] | 1 | /* |
---|
| 2 | * cluster.c - Cluster-Manager related operations |
---|
[19] | 3 | * |
---|
[1] | 4 | * Author Ghassan Almaless (2008,2009,2010,2011,2012) |
---|
| 5 | * Mohamed Lamine Karaoui (2015) |
---|
[635] | 6 | * Alain Greiner (2016,2017,2018,2019) |
---|
[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 | |
---|
[14] | 26 | #include <kernel_config.h> |
---|
[456] | 27 | #include <hal_kernel_types.h> |
---|
[1] | 28 | #include <hal_atomic.h> |
---|
| 29 | #include <hal_special.h> |
---|
[50] | 30 | #include <hal_ppm.h> |
---|
[564] | 31 | #include <hal_macros.h> |
---|
[407] | 32 | #include <remote_fifo.h> |
---|
[1] | 33 | #include <printk.h> |
---|
| 34 | #include <errno.h> |
---|
[564] | 35 | #include <queuelock.h> |
---|
[1] | 36 | #include <core.h> |
---|
[443] | 37 | #include <chdev.h> |
---|
[1] | 38 | #include <scheduler.h> |
---|
| 39 | #include <list.h> |
---|
| 40 | #include <cluster.h> |
---|
| 41 | #include <boot_info.h> |
---|
| 42 | #include <bits.h> |
---|
| 43 | #include <ppm.h> |
---|
| 44 | #include <thread.h> |
---|
| 45 | #include <kmem.h> |
---|
| 46 | #include <process.h> |
---|
| 47 | #include <dqdt.h> |
---|
| 48 | |
---|
[408] | 49 | ///////////////////////////////////////////////////////////////////////////////////// |
---|
[1] | 50 | // Extern global variables |
---|
[408] | 51 | ///////////////////////////////////////////////////////////////////////////////////// |
---|
[1] | 52 | |
---|
[564] | 53 | extern process_t process_zero; // allocated in kernel_init.c |
---|
| 54 | extern chdev_directory_t chdev_dir; // allocated in kernel_init.c |
---|
[1] | 55 | |
---|
[564] | 56 | |
---|
| 57 | |
---|
| 58 | /////////////////////////////////////////////////// |
---|
| 59 | void cluster_info_init( struct boot_info_s * info ) |
---|
[1] | 60 | { |
---|
[428] | 61 | boot_device_t * dev; // pointer on external peripheral |
---|
| 62 | uint32_t func; // external peripheral functionnal type |
---|
[564] | 63 | uint32_t x; |
---|
| 64 | uint32_t y; |
---|
| 65 | uint32_t i; |
---|
[1] | 66 | |
---|
| 67 | cluster_t * cluster = LOCAL_CLUSTER; |
---|
| 68 | |
---|
| 69 | // initialize cluster global parameters |
---|
[19] | 70 | cluster->paddr_width = info->paddr_width; |
---|
[1] | 71 | cluster->x_width = info->x_width; |
---|
| 72 | cluster->y_width = info->y_width; |
---|
| 73 | cluster->x_size = info->x_size; |
---|
| 74 | cluster->y_size = info->y_size; |
---|
| 75 | cluster->io_cxy = info->io_cxy; |
---|
| 76 | |
---|
[557] | 77 | // initialize the cluster_info[][] array |
---|
[564] | 78 | for (x = 0; x < CONFIG_MAX_CLUSTERS_X; x++) |
---|
| 79 | { |
---|
| 80 | for (y = 0; y < CONFIG_MAX_CLUSTERS_Y;y++) |
---|
| 81 | { |
---|
[557] | 82 | cluster->cluster_info[x][y] = info->cluster_info[x][y]; |
---|
| 83 | } |
---|
| 84 | } |
---|
[564] | 85 | |
---|
[428] | 86 | // initialize external peripherals channels |
---|
| 87 | for( i = 0 ; i < info->ext_dev_nr ; i++ ) |
---|
| 88 | { |
---|
| 89 | dev = &info->ext_dev[i]; |
---|
| 90 | func = FUNC_FROM_TYPE( dev->type ); |
---|
| 91 | if( func == DEV_FUNC_TXT ) cluster->nb_txt_channels = dev->channels; |
---|
| 92 | if( func == DEV_FUNC_NIC ) cluster->nb_nic_channels = dev->channels; |
---|
| 93 | if( func == DEV_FUNC_IOC ) cluster->nb_ioc_channels = dev->channels; |
---|
| 94 | if( func == DEV_FUNC_FBF ) cluster->nb_fbf_channels = dev->channels; |
---|
| 95 | } |
---|
| 96 | |
---|
[564] | 97 | // initialize number of cores |
---|
| 98 | cluster->cores_nr = info->cores_nr; |
---|
[1] | 99 | |
---|
[564] | 100 | } // end cluster_info_init() |
---|
| 101 | |
---|
| 102 | ///////////////////////////////////////////////////////// |
---|
| 103 | error_t cluster_manager_init( struct boot_info_s * info ) |
---|
| 104 | { |
---|
| 105 | error_t error; |
---|
| 106 | lpid_t lpid; // local process_index |
---|
| 107 | lid_t lid; // local core index |
---|
| 108 | |
---|
| 109 | cluster_t * cluster = LOCAL_CLUSTER; |
---|
| 110 | |
---|
[438] | 111 | #if DEBUG_CLUSTER_INIT |
---|
[593] | 112 | uint32_t cycle = (uint32_t)hal_get_cycles(); |
---|
| 113 | thread_t * this = CURRENT_THREAD; |
---|
[438] | 114 | if( DEBUG_CLUSTER_INIT < cycle ) |
---|
[593] | 115 | printk("\n[%s] thread[%x,%x] enters for cluster %x / cycle %d\n", |
---|
| 116 | __FUNCTION__, this->process->pid, this->trdid, local_cxy , cycle ); |
---|
[433] | 117 | #endif |
---|
[50] | 118 | |
---|
[1] | 119 | // initialises embedded PPM |
---|
[50] | 120 | error = hal_ppm_init( info ); |
---|
[1] | 121 | |
---|
[50] | 122 | if( error ) |
---|
| 123 | { |
---|
| 124 | printk("\n[ERROR] in %s : cannot initialize PPM in cluster %x\n", |
---|
| 125 | __FUNCTION__ , local_cxy ); |
---|
| 126 | return ENOMEM; |
---|
| 127 | } |
---|
| 128 | |
---|
[438] | 129 | #if( DEBUG_CLUSTER_INIT & 1 ) |
---|
[433] | 130 | cycle = (uint32_t)hal_get_cycles(); |
---|
[438] | 131 | if( DEBUG_CLUSTER_INIT < cycle ) |
---|
[593] | 132 | printk("\n[%s] PPM initialized in cluster %x / cycle %d\n", |
---|
[433] | 133 | __FUNCTION__ , local_cxy , cycle ); |
---|
| 134 | #endif |
---|
[50] | 135 | |
---|
[1] | 136 | // initialises embedded KHM |
---|
| 137 | khm_init( &cluster->khm ); |
---|
[19] | 138 | |
---|
[438] | 139 | #if( DEBUG_CLUSTER_INIT & 1 ) |
---|
[457] | 140 | cycle = (uint32_t)hal_get_cycles(); |
---|
[438] | 141 | if( DEBUG_CLUSTER_INIT < cycle ) |
---|
[593] | 142 | printk("\n[%s] KHM initialized in cluster %x at cycle %d\n", |
---|
[437] | 143 | __FUNCTION__ , local_cxy , hal_get_cycles() ); |
---|
| 144 | #endif |
---|
[50] | 145 | |
---|
[19] | 146 | // initialises embedded KCM |
---|
[635] | 147 | uint32_t i; |
---|
| 148 | for( i = 0 ; i < 6 ; i++ ) kcm_init( &cluster->kcm[i] , i+6 ); |
---|
[1] | 149 | |
---|
[438] | 150 | #if( DEBUG_CLUSTER_INIT & 1 ) |
---|
[457] | 151 | cycle = (uint32_t)hal_get_cycles(); |
---|
[438] | 152 | if( DEBUG_CLUSTER_INIT < cycle ) |
---|
[635] | 153 | printk("\n[%s] KCM[6:11] initialized in cluster %x at cycle %d\n", |
---|
[437] | 154 | __FUNCTION__ , local_cxy , hal_get_cycles() ); |
---|
| 155 | #endif |
---|
[50] | 156 | |
---|
[296] | 157 | // initialises all cores descriptors |
---|
[1] | 158 | for( lid = 0 ; lid < cluster->cores_nr; lid++ ) |
---|
| 159 | { |
---|
| 160 | core_init( &cluster->core_tbl[lid], // target core descriptor |
---|
| 161 | lid, // local core index |
---|
| 162 | info->core[lid].gid ); // gid from boot_info_t |
---|
| 163 | } |
---|
[19] | 164 | |
---|
[438] | 165 | #if( DEBUG_CLUSTER_INIT & 1 ) |
---|
[433] | 166 | cycle = (uint32_t)hal_get_cycles(); |
---|
[438] | 167 | if( DEBUG_CLUSTER_INIT < cycle ) |
---|
[593] | 168 | printk("\n[%s] cores initialized in cluster %x / cycle %d\n", |
---|
[433] | 169 | __FUNCTION__ , local_cxy , cycle ); |
---|
| 170 | #endif |
---|
[50] | 171 | |
---|
[440] | 172 | // initialises RPC FIFOs |
---|
| 173 | for( lid = 0 ; lid < cluster->cores_nr; lid++ ) |
---|
| 174 | { |
---|
[564] | 175 | remote_fifo_init( &cluster->rpc_fifo[lid] ); |
---|
[440] | 176 | cluster->rpc_threads[lid] = 0; |
---|
| 177 | } |
---|
[1] | 178 | |
---|
[438] | 179 | #if( DEBUG_CLUSTER_INIT & 1 ) |
---|
[437] | 180 | cycle = (uint32_t)hal_get_cycles(); |
---|
[438] | 181 | if( DEBUG_CLUSTER_INIT < cycle ) |
---|
[593] | 182 | printk("\n[%s] RPC fifo inialized in cluster %x at cycle %d\n", |
---|
[407] | 183 | __FUNCTION__ , local_cxy , hal_get_cycles() ); |
---|
[437] | 184 | #endif |
---|
[50] | 185 | |
---|
[1] | 186 | // initialise pref_tbl[] in process manager |
---|
[564] | 187 | queuelock_init( &cluster->pmgr.pref_lock , LOCK_CLUSTER_PREFTBL ); |
---|
[1] | 188 | cluster->pmgr.pref_nr = 0; |
---|
[19] | 189 | cluster->pmgr.pref_tbl[0] = XPTR( local_cxy , &process_zero ); |
---|
[580] | 190 | for( lpid = 0 ; lpid < CONFIG_MAX_PROCESS_PER_CLUSTER ; lpid++ ) |
---|
[1] | 191 | { |
---|
| 192 | cluster->pmgr.pref_tbl[lpid] = XPTR_NULL; |
---|
| 193 | } |
---|
| 194 | |
---|
| 195 | // initialise local_list in process manager |
---|
[23] | 196 | xlist_root_init( XPTR( local_cxy , &cluster->pmgr.local_root ) ); |
---|
[1] | 197 | cluster->pmgr.local_nr = 0; |
---|
[564] | 198 | remote_queuelock_init( XPTR( local_cxy , &cluster->pmgr.local_lock ) , |
---|
| 199 | LOCK_CLUSTER_LOCALS ); |
---|
[1] | 200 | |
---|
| 201 | // initialise copies_lists in process manager |
---|
[101] | 202 | for( lpid = 0 ; lpid < CONFIG_MAX_PROCESS_PER_CLUSTER ; lpid++ ) |
---|
[1] | 203 | { |
---|
| 204 | cluster->pmgr.copies_nr[lpid] = 0; |
---|
| 205 | xlist_root_init( XPTR( local_cxy , &cluster->pmgr.copies_root[lpid] ) ); |
---|
[564] | 206 | remote_queuelock_init( XPTR( local_cxy , &cluster->pmgr.copies_lock[lpid] ), |
---|
| 207 | LOCK_CLUSTER_COPIES ); |
---|
[19] | 208 | } |
---|
[1] | 209 | |
---|
[438] | 210 | #if DEBUG_CLUSTER_INIT |
---|
[433] | 211 | cycle = (uint32_t)hal_get_cycles(); |
---|
[438] | 212 | if( DEBUG_CLUSTER_INIT < cycle ) |
---|
[593] | 213 | printk("\n[%s] thread[%x,%x] exit for cluster %x / cycle %d\n", |
---|
| 214 | __FUNCTION__, this->process->pid, this->trdid, local_cxy, cycle ); |
---|
[433] | 215 | #endif |
---|
[50] | 216 | |
---|
[124] | 217 | hal_fence(); |
---|
[1] | 218 | |
---|
| 219 | return 0; |
---|
[564] | 220 | } // end cluster_manager_init() |
---|
[1] | 221 | |
---|
[564] | 222 | /////////////////////////////////// |
---|
[561] | 223 | cxy_t cluster_random_select( void ) |
---|
| 224 | { |
---|
| 225 | uint32_t index; |
---|
[564] | 226 | uint32_t x; |
---|
[561] | 227 | uint32_t y; |
---|
[564] | 228 | cxy_t cxy; |
---|
[561] | 229 | |
---|
[564] | 230 | uint32_t x_size = LOCAL_CLUSTER->x_size; |
---|
| 231 | uint32_t y_size = LOCAL_CLUSTER->y_size; |
---|
| 232 | |
---|
| 233 | do |
---|
| 234 | { |
---|
[561] | 235 | index = ( hal_get_cycles() + hal_get_gid() ) % (x_size * y_size); |
---|
| 236 | x = index / y_size; |
---|
| 237 | y = index % y_size; |
---|
[564] | 238 | cxy = HAL_CXY_FROM_XY( x , y ); |
---|
| 239 | } |
---|
| 240 | while ( cluster_is_active( cxy ) == false ); |
---|
[561] | 241 | |
---|
[564] | 242 | return ( cxy ); |
---|
[561] | 243 | } |
---|
| 244 | |
---|
[1] | 245 | //////////////////////////////////////// |
---|
| 246 | bool_t cluster_is_undefined( cxy_t cxy ) |
---|
| 247 | { |
---|
[564] | 248 | uint32_t x_size = LOCAL_CLUSTER->x_size; |
---|
| 249 | uint32_t y_size = LOCAL_CLUSTER->y_size; |
---|
[1] | 250 | |
---|
[564] | 251 | uint32_t x = HAL_X_FROM_CXY( cxy ); |
---|
| 252 | uint32_t y = HAL_Y_FROM_CXY( cxy ); |
---|
[1] | 253 | |
---|
[564] | 254 | if( x >= x_size ) return true; |
---|
| 255 | if( y >= y_size ) return true; |
---|
[1] | 256 | |
---|
| 257 | return false; |
---|
| 258 | } |
---|
| 259 | |
---|
[564] | 260 | ////////////////////////////////////// |
---|
| 261 | bool_t cluster_is_active ( cxy_t cxy ) |
---|
| 262 | { |
---|
| 263 | uint32_t x = HAL_X_FROM_CXY( cxy ); |
---|
| 264 | uint32_t y = HAL_Y_FROM_CXY( cxy ); |
---|
| 265 | |
---|
| 266 | return ( LOCAL_CLUSTER->cluster_info[x][y] != 0 ); |
---|
| 267 | } |
---|
| 268 | |
---|
[1] | 269 | //////////////////////////////////////////////////////////////////////////////////// |
---|
| 270 | // Cores related functions |
---|
| 271 | //////////////////////////////////////////////////////////////////////////////////// |
---|
| 272 | |
---|
[583] | 273 | /////////////////////////////////////// |
---|
[485] | 274 | lid_t cluster_select_local_core( void ) |
---|
[1] | 275 | { |
---|
[440] | 276 | uint32_t min = 1000; |
---|
| 277 | lid_t sel = 0; |
---|
| 278 | uint32_t nthreads; |
---|
| 279 | lid_t lid; |
---|
| 280 | scheduler_t * sched; |
---|
[1] | 281 | |
---|
| 282 | cluster_t * cluster = LOCAL_CLUSTER; |
---|
| 283 | |
---|
| 284 | for( lid = 0 ; lid < cluster->cores_nr ; lid++ ) |
---|
| 285 | { |
---|
[440] | 286 | sched = &cluster->core_tbl[lid].scheduler; |
---|
| 287 | nthreads = sched->u_threads_nr + sched->k_threads_nr; |
---|
| 288 | |
---|
| 289 | if( nthreads < min ) |
---|
[1] | 290 | { |
---|
[440] | 291 | min = nthreads; |
---|
[1] | 292 | sel = lid; |
---|
| 293 | } |
---|
[19] | 294 | } |
---|
[1] | 295 | return sel; |
---|
| 296 | } |
---|
| 297 | |
---|
| 298 | //////////////////////////////////////////////////////////////////////////////////// |
---|
[428] | 299 | // Process related functions |
---|
[1] | 300 | //////////////////////////////////////////////////////////////////////////////////// |
---|
| 301 | |
---|
[433] | 302 | |
---|
| 303 | ////////////////////////////////////////////////////// |
---|
[443] | 304 | xptr_t cluster_get_process_from_pid_in_cxy( cxy_t cxy, |
---|
| 305 | pid_t pid ) |
---|
| 306 | { |
---|
| 307 | xptr_t root_xp; // xptr on root of list of processes in owner cluster |
---|
| 308 | xptr_t lock_xp; // xptr on lock protecting this list |
---|
| 309 | xptr_t iter_xp; // iterator |
---|
| 310 | xptr_t current_xp; // xptr on current process descriptor |
---|
| 311 | bool_t found; |
---|
| 312 | |
---|
| 313 | cluster_t * cluster = LOCAL_CLUSTER; |
---|
| 314 | |
---|
| 315 | // get owner cluster and lpid |
---|
| 316 | cxy_t owner_cxy = CXY_FROM_PID( pid ); |
---|
| 317 | lpid_t lpid = LPID_FROM_PID( pid ); |
---|
| 318 | |
---|
| 319 | // get lock & root of list of copies from owner cluster |
---|
| 320 | root_xp = XPTR( owner_cxy , &cluster->pmgr.copies_root[lpid] ); |
---|
| 321 | lock_xp = XPTR( owner_cxy , &cluster->pmgr.copies_lock[lpid] ); |
---|
| 322 | |
---|
| 323 | // take the lock protecting the list of processes |
---|
[564] | 324 | remote_queuelock_acquire( lock_xp ); |
---|
[443] | 325 | |
---|
| 326 | // scan list of processes |
---|
| 327 | found = false; |
---|
| 328 | XLIST_FOREACH( root_xp , iter_xp ) |
---|
| 329 | { |
---|
| 330 | current_xp = XLIST_ELEMENT( iter_xp , process_t , copies_list ); |
---|
| 331 | |
---|
| 332 | if( GET_CXY( current_xp ) == cxy ) |
---|
| 333 | { |
---|
| 334 | found = true; |
---|
| 335 | break; |
---|
| 336 | } |
---|
| 337 | } |
---|
| 338 | |
---|
| 339 | // release the lock protecting the list of processes |
---|
[564] | 340 | remote_queuelock_release( lock_xp ); |
---|
[443] | 341 | |
---|
| 342 | // return extended pointer on process descriptor in owner cluster |
---|
| 343 | if( found ) return current_xp; |
---|
| 344 | else return XPTR_NULL; |
---|
| 345 | |
---|
| 346 | } // end cluster_get_process_from_pid_in_cxy() |
---|
| 347 | |
---|
| 348 | |
---|
| 349 | ////////////////////////////////////////////////////// |
---|
[433] | 350 | xptr_t cluster_get_owner_process_from_pid( pid_t pid ) |
---|
| 351 | { |
---|
| 352 | xptr_t root_xp; // xptr on root of list of processes in owner cluster |
---|
[436] | 353 | xptr_t lock_xp; // xptr on lock protecting this list |
---|
[433] | 354 | xptr_t iter_xp; // iterator |
---|
| 355 | xptr_t current_xp; // xptr on current process descriptor |
---|
| 356 | process_t * current_ptr; // local pointer on current process |
---|
| 357 | pid_t current_pid; // current process identifier |
---|
| 358 | bool_t found; |
---|
| 359 | |
---|
| 360 | cluster_t * cluster = LOCAL_CLUSTER; |
---|
| 361 | |
---|
| 362 | // get owner cluster and lpid |
---|
| 363 | cxy_t owner_cxy = CXY_FROM_PID( pid ); |
---|
| 364 | |
---|
| 365 | // get lock & root of list of process in owner cluster |
---|
| 366 | root_xp = XPTR( owner_cxy , &cluster->pmgr.local_root ); |
---|
| 367 | lock_xp = XPTR( owner_cxy , &cluster->pmgr.local_lock ); |
---|
| 368 | |
---|
| 369 | // take the lock protecting the list of processes |
---|
[564] | 370 | remote_queuelock_acquire( lock_xp ); |
---|
[433] | 371 | |
---|
| 372 | // scan list of processes in owner cluster |
---|
| 373 | found = false; |
---|
| 374 | XLIST_FOREACH( root_xp , iter_xp ) |
---|
| 375 | { |
---|
| 376 | current_xp = XLIST_ELEMENT( iter_xp , process_t , local_list ); |
---|
| 377 | current_ptr = GET_PTR( current_xp ); |
---|
[564] | 378 | current_pid = hal_remote_l32( XPTR( owner_cxy , ¤t_ptr->pid ) ); |
---|
[433] | 379 | |
---|
| 380 | if( current_pid == pid ) |
---|
| 381 | { |
---|
| 382 | found = true; |
---|
| 383 | break; |
---|
| 384 | } |
---|
| 385 | } |
---|
| 386 | |
---|
| 387 | // release the lock protecting the list of processes |
---|
[564] | 388 | remote_queuelock_release( lock_xp ); |
---|
[433] | 389 | |
---|
| 390 | // return extended pointer on process descriptor in owner cluster |
---|
| 391 | if( found ) return current_xp; |
---|
| 392 | else return XPTR_NULL; |
---|
| 393 | |
---|
[436] | 394 | } // end cluster_get_owner_process_from_pid() |
---|
| 395 | |
---|
[443] | 396 | |
---|
[1] | 397 | ////////////////////////////////////////////////////////// |
---|
| 398 | xptr_t cluster_get_reference_process_from_pid( pid_t pid ) |
---|
[19] | 399 | { |
---|
[23] | 400 | xptr_t ref_xp; // extended pointer on reference process descriptor |
---|
[1] | 401 | |
---|
| 402 | cluster_t * cluster = LOCAL_CLUSTER; |
---|
| 403 | |
---|
| 404 | // get owner cluster and lpid |
---|
| 405 | cxy_t owner_cxy = CXY_FROM_PID( pid ); |
---|
| 406 | lpid_t lpid = LPID_FROM_PID( pid ); |
---|
| 407 | |
---|
[19] | 408 | // Check valid PID |
---|
[23] | 409 | if( lpid >= CONFIG_MAX_PROCESS_PER_CLUSTER ) return XPTR_NULL; |
---|
[1] | 410 | |
---|
| 411 | if( local_cxy == owner_cxy ) // local cluster is owner cluster |
---|
[19] | 412 | { |
---|
[23] | 413 | ref_xp = cluster->pmgr.pref_tbl[lpid]; |
---|
[1] | 414 | } |
---|
| 415 | else // use a remote_lwd to access owner cluster |
---|
| 416 | { |
---|
[564] | 417 | ref_xp = (xptr_t)hal_remote_l64( XPTR( owner_cxy , &cluster->pmgr.pref_tbl[lpid] ) ); |
---|
[1] | 418 | } |
---|
| 419 | |
---|
[23] | 420 | return ref_xp; |
---|
[1] | 421 | } |
---|
| 422 | |
---|
[416] | 423 | /////////////////////////////////////////////// |
---|
| 424 | error_t cluster_pid_alloc( process_t * process, |
---|
| 425 | pid_t * pid ) |
---|
[1] | 426 | { |
---|
| 427 | lpid_t lpid; |
---|
| 428 | bool_t found; |
---|
| 429 | |
---|
[440] | 430 | #if DEBUG_CLUSTER_PID_ALLOC |
---|
[593] | 431 | uint32_t cycle = (uint32_t)hal_get_cycles(); |
---|
| 432 | thread_t * this = CURRENT_THREAD; |
---|
[440] | 433 | if( DEBUG_CLUSTER_PID_ALLOC < cycle ) |
---|
[593] | 434 | printk("\n[%s] thread[%x,%x] enters in cluster %x / cycle %d\n", |
---|
| 435 | __FUNCTION__ , this->process->pid , this->trdid , local_cxy , cycle ); |
---|
[440] | 436 | #endif |
---|
| 437 | |
---|
[1] | 438 | pmgr_t * pm = &LOCAL_CLUSTER->pmgr; |
---|
| 439 | |
---|
[564] | 440 | // get the lock protecting pref_tbl |
---|
| 441 | queuelock_acquire( &pm->pref_lock ); |
---|
[1] | 442 | |
---|
| 443 | // search an empty slot |
---|
| 444 | found = false; |
---|
| 445 | for( lpid = 0 ; lpid < CONFIG_MAX_PROCESS_PER_CLUSTER ; lpid++ ) |
---|
| 446 | { |
---|
| 447 | if( pm->pref_tbl[lpid] == XPTR_NULL ) |
---|
| 448 | { |
---|
| 449 | found = true; |
---|
| 450 | break; |
---|
| 451 | } |
---|
| 452 | } |
---|
| 453 | |
---|
| 454 | if( found ) |
---|
| 455 | { |
---|
| 456 | // register process in pref_tbl[] |
---|
[416] | 457 | pm->pref_tbl[lpid] = XPTR( local_cxy , process ); |
---|
[1] | 458 | pm->pref_nr++; |
---|
| 459 | |
---|
| 460 | // returns pid |
---|
| 461 | *pid = PID( local_cxy , lpid ); |
---|
| 462 | |
---|
[416] | 463 | // release the processs_manager lock |
---|
[564] | 464 | queuelock_release( &pm->pref_lock ); |
---|
[416] | 465 | |
---|
| 466 | return 0; |
---|
[1] | 467 | } |
---|
| 468 | else |
---|
| 469 | { |
---|
[564] | 470 | // release the lock |
---|
| 471 | queuelock_release( &pm->pref_lock ); |
---|
[416] | 472 | |
---|
[564] | 473 | return 0xFFFFFFFF; |
---|
[19] | 474 | } |
---|
[1] | 475 | |
---|
[440] | 476 | #if DEBUG_CLUSTER_PID_ALLOC |
---|
| 477 | cycle = (uint32_t)hal_get_cycles(); |
---|
| 478 | if( DEBUG_CLUSTER_PID_ALLOC < cycle ) |
---|
[593] | 479 | printk("\n[%s] thread[%x,%x] exit in cluster %x / cycle %d\n", |
---|
| 480 | __FUNCTION__ , this->process->pid , this->trdid , local_cxy , cycle ); |
---|
[440] | 481 | #endif |
---|
| 482 | |
---|
[1] | 483 | } // end cluster_pid_alloc() |
---|
| 484 | |
---|
| 485 | ///////////////////////////////////// |
---|
| 486 | void cluster_pid_release( pid_t pid ) |
---|
| 487 | { |
---|
[440] | 488 | |
---|
| 489 | #if DEBUG_CLUSTER_PID_RELEASE |
---|
[593] | 490 | uint32_t cycle = (uint32_t)hal_get_cycles(); |
---|
| 491 | thread_t * this = CURRENT_THREAD; |
---|
| 492 | if( DEBUG_CLUSTER_PID_ALLOC < cycle ) |
---|
| 493 | printk("\n[%s] thread[%x,%x] enters in cluster %x / pid %x / cycle %d\n", |
---|
| 494 | __FUNCTION__ , this->process->pid , this->trdid , local_cxy , pid, cycle ); |
---|
[440] | 495 | #endif |
---|
| 496 | |
---|
[1] | 497 | cxy_t owner_cxy = CXY_FROM_PID( pid ); |
---|
| 498 | lpid_t lpid = LPID_FROM_PID( pid ); |
---|
| 499 | |
---|
[409] | 500 | pmgr_t * pm = &LOCAL_CLUSTER->pmgr; |
---|
| 501 | |
---|
[440] | 502 | // check lpid |
---|
[492] | 503 | assert( (lpid < CONFIG_MAX_PROCESS_PER_CLUSTER), |
---|
[440] | 504 | "illegal LPID = %d" , lpid ); |
---|
[1] | 505 | |
---|
[440] | 506 | // check owner cluster |
---|
[492] | 507 | assert( (owner_cxy == local_cxy) , |
---|
[440] | 508 | "local_cluster %x != owner_cluster %x" , local_cxy , owner_cxy ); |
---|
| 509 | |
---|
[564] | 510 | // get the lock protecting pref_tbl |
---|
| 511 | queuelock_acquire( &pm->pref_lock ); |
---|
[1] | 512 | |
---|
| 513 | // remove process from pref_tbl[] |
---|
| 514 | pm->pref_tbl[lpid] = XPTR_NULL; |
---|
| 515 | pm->pref_nr--; |
---|
| 516 | |
---|
| 517 | // release the processs_manager lock |
---|
[564] | 518 | queuelock_release( &pm->pref_lock ); |
---|
[1] | 519 | |
---|
[440] | 520 | #if DEBUG_CLUSTER_PID_RELEASE |
---|
| 521 | cycle = (uint32_t)hal_get_cycles(); |
---|
[593] | 522 | if( DEBUG_CLUSTER_PID_ALLOC < cycle ) |
---|
| 523 | printk("\n[%s] thread[%x,%x] exit in cluster %x / cycle %d\n", |
---|
| 524 | __FUNCTION__ , this->process->pid , this->trdid , local_cxy , cycle ); |
---|
[440] | 525 | #endif |
---|
| 526 | |
---|
[1] | 527 | } // end cluster_pid_release() |
---|
| 528 | |
---|
| 529 | /////////////////////////////////////////////////////////// |
---|
| 530 | process_t * cluster_get_local_process_from_pid( pid_t pid ) |
---|
| 531 | { |
---|
[23] | 532 | xptr_t process_xp; |
---|
| 533 | process_t * process_ptr; |
---|
| 534 | xptr_t root_xp; |
---|
| 535 | xptr_t iter_xp; |
---|
| 536 | bool_t found; |
---|
[19] | 537 | |
---|
[23] | 538 | found = false; |
---|
| 539 | root_xp = XPTR( local_cxy , &LOCAL_CLUSTER->pmgr.local_root ); |
---|
| 540 | |
---|
| 541 | XLIST_FOREACH( root_xp , iter_xp ) |
---|
[1] | 542 | { |
---|
[23] | 543 | process_xp = XLIST_ELEMENT( iter_xp , process_t , local_list ); |
---|
| 544 | process_ptr = (process_t *)GET_PTR( process_xp ); |
---|
| 545 | if( process_ptr->pid == pid ) |
---|
[1] | 546 | { |
---|
[23] | 547 | found = true; |
---|
[1] | 548 | break; |
---|
| 549 | } |
---|
| 550 | } |
---|
| 551 | |
---|
[23] | 552 | if (found ) return process_ptr; |
---|
| 553 | else return NULL; |
---|
| 554 | |
---|
[1] | 555 | } // end cluster_get_local_process_from_pid() |
---|
| 556 | |
---|
| 557 | ////////////////////////////////////////////////////// |
---|
| 558 | void cluster_process_local_link( process_t * process ) |
---|
| 559 | { |
---|
| 560 | pmgr_t * pm = &LOCAL_CLUSTER->pmgr; |
---|
| 561 | |
---|
[443] | 562 | // get extended pointers on local process list root & lock |
---|
| 563 | xptr_t root_xp = XPTR( local_cxy , &pm->local_root ); |
---|
| 564 | xptr_t lock_xp = XPTR( local_cxy , &pm->local_lock ); |
---|
| 565 | |
---|
[564] | 566 | // get lock protecting the local list |
---|
| 567 | remote_queuelock_acquire( lock_xp ); |
---|
[1] | 568 | |
---|
[443] | 569 | // register process in local list |
---|
| 570 | xlist_add_last( root_xp , XPTR( local_cxy , &process->local_list ) ); |
---|
[1] | 571 | pm->local_nr++; |
---|
| 572 | |
---|
[564] | 573 | // release lock protecting the local list |
---|
| 574 | remote_queuelock_release( lock_xp ); |
---|
[1] | 575 | } |
---|
| 576 | |
---|
| 577 | //////////////////////////////////////////////////////// |
---|
| 578 | void cluster_process_local_unlink( process_t * process ) |
---|
| 579 | { |
---|
| 580 | pmgr_t * pm = &LOCAL_CLUSTER->pmgr; |
---|
| 581 | |
---|
[443] | 582 | // get extended pointers on local process list lock |
---|
| 583 | xptr_t lock_xp = XPTR( local_cxy , &pm->local_lock ); |
---|
| 584 | |
---|
[564] | 585 | // get lock protecting the local list |
---|
| 586 | remote_queuelock_acquire( lock_xp ); |
---|
[1] | 587 | |
---|
[443] | 588 | // remove process from local list |
---|
[23] | 589 | xlist_unlink( XPTR( local_cxy , &process->local_list ) ); |
---|
[1] | 590 | pm->local_nr--; |
---|
| 591 | |
---|
[564] | 592 | // release lock protecting the local list |
---|
| 593 | remote_queuelock_release( lock_xp ); |
---|
[1] | 594 | } |
---|
| 595 | |
---|
| 596 | /////////////////////////////////////////////////////// |
---|
| 597 | void cluster_process_copies_link( process_t * process ) |
---|
| 598 | { |
---|
| 599 | pmgr_t * pm = &LOCAL_CLUSTER->pmgr; |
---|
| 600 | |
---|
[438] | 601 | #if DEBUG_CLUSTER_PROCESS_COPIES |
---|
[593] | 602 | uint32_t cycle = (uint32_t)hal_get_cycles(); |
---|
| 603 | thread_t * this = CURRENT_THREAD; |
---|
[438] | 604 | if( DEBUG_CLUSTER_PROCESS_COPIES < cycle ) |
---|
[593] | 605 | printk("\n[%s] thread[%x,%x] enters for process %x / cycle %d\n", |
---|
| 606 | __FUNCTION__ , this->process->pid , this->trdid , process->pid , cycle ); |
---|
[436] | 607 | #endif |
---|
| 608 | |
---|
[1] | 609 | // get owner cluster identifier CXY and process LPID |
---|
| 610 | pid_t pid = process->pid; |
---|
| 611 | cxy_t owner_cxy = CXY_FROM_PID( pid ); |
---|
| 612 | lpid_t lpid = LPID_FROM_PID( pid ); |
---|
| 613 | |
---|
| 614 | // get extended pointer on lock protecting copies_list[lpid] |
---|
[120] | 615 | xptr_t copies_lock = XPTR( owner_cxy , &pm->copies_lock[lpid] ); |
---|
[1] | 616 | |
---|
| 617 | // get extended pointer on the copies_list[lpid] root |
---|
[120] | 618 | xptr_t copies_root = XPTR( owner_cxy , &pm->copies_root[lpid] ); |
---|
[1] | 619 | |
---|
| 620 | // get extended pointer on the local copies_list entry |
---|
| 621 | xptr_t copies_entry = XPTR( local_cxy , &process->copies_list ); |
---|
| 622 | |
---|
[19] | 623 | // get lock protecting copies_list[lpid] |
---|
[564] | 624 | remote_queuelock_acquire( copies_lock ); |
---|
[1] | 625 | |
---|
[436] | 626 | // add copy to copies_list |
---|
[1] | 627 | xlist_add_first( copies_root , copies_entry ); |
---|
| 628 | hal_remote_atomic_add( XPTR( owner_cxy , &pm->copies_nr[lpid] ) , 1 ); |
---|
| 629 | |
---|
[19] | 630 | // release lock protecting copies_list[lpid] |
---|
[564] | 631 | remote_queuelock_release( copies_lock ); |
---|
[1] | 632 | |
---|
[438] | 633 | #if DEBUG_CLUSTER_PROCESS_COPIES |
---|
[436] | 634 | cycle = (uint32_t)hal_get_cycles(); |
---|
[438] | 635 | if( DEBUG_CLUSTER_PROCESS_COPIES < cycle ) |
---|
[593] | 636 | printk("\n[%s] thread[%x,%x] exit for process %x / cycle %d\n", |
---|
| 637 | __FUNCTION__ , this->process->pid , this->trdid , process->pid , cycle ); |
---|
[436] | 638 | #endif |
---|
| 639 | |
---|
| 640 | } // end cluster_process_copies_link() |
---|
| 641 | |
---|
[1] | 642 | ///////////////////////////////////////////////////////// |
---|
| 643 | void cluster_process_copies_unlink( process_t * process ) |
---|
| 644 | { |
---|
| 645 | pmgr_t * pm = &LOCAL_CLUSTER->pmgr; |
---|
| 646 | |
---|
[438] | 647 | #if DEBUG_CLUSTER_PROCESS_COPIES |
---|
[593] | 648 | uint32_t cycle = (uint32_t)hal_get_cycles(); |
---|
| 649 | thread_t * this = CURRENT_THREAD; |
---|
[438] | 650 | if( DEBUG_CLUSTER_PROCESS_COPIES < cycle ) |
---|
[593] | 651 | printk("\n[%s] thread[%x,%x] enters for process %x / cycle %d\n", |
---|
| 652 | __FUNCTION__ , this->process->pid , this->trdid , process->pid , cycle ); |
---|
[436] | 653 | #endif |
---|
| 654 | |
---|
[1] | 655 | // get owner cluster identifier CXY and process LPID |
---|
| 656 | pid_t pid = process->pid; |
---|
| 657 | cxy_t owner_cxy = CXY_FROM_PID( pid ); |
---|
| 658 | lpid_t lpid = LPID_FROM_PID( pid ); |
---|
| 659 | |
---|
| 660 | // get extended pointer on lock protecting copies_list[lpid] |
---|
[436] | 661 | xptr_t copies_lock = XPTR( owner_cxy , &pm->copies_lock[lpid] ); |
---|
[1] | 662 | |
---|
| 663 | // get extended pointer on the local copies_list entry |
---|
| 664 | xptr_t copies_entry = XPTR( local_cxy , &process->copies_list ); |
---|
| 665 | |
---|
[19] | 666 | // get lock protecting copies_list[lpid] |
---|
[564] | 667 | remote_queuelock_acquire( copies_lock ); |
---|
[1] | 668 | |
---|
[436] | 669 | // remove copy from copies_list |
---|
[1] | 670 | xlist_unlink( copies_entry ); |
---|
| 671 | hal_remote_atomic_add( XPTR( owner_cxy , &pm->copies_nr[lpid] ) , -1 ); |
---|
| 672 | |
---|
[19] | 673 | // release lock protecting copies_list[lpid] |
---|
[564] | 674 | remote_queuelock_release( copies_lock ); |
---|
[1] | 675 | |
---|
[438] | 676 | #if DEBUG_CLUSTER_PROCESS_COPIES |
---|
[436] | 677 | cycle = (uint32_t)hal_get_cycles(); |
---|
[438] | 678 | if( DEBUG_CLUSTER_PROCESS_COPIES < cycle ) |
---|
[593] | 679 | printk("\n[%s] thread[%x,%x] exit for process %x / cycle %d\n", |
---|
| 680 | __FUNCTION__ , this->process->pid , this->trdid , process->pid , cycle ); |
---|
[436] | 681 | #endif |
---|
| 682 | |
---|
| 683 | } // end cluster_process_copies_unlink() |
---|
| 684 | |
---|
[583] | 685 | //////////////////////////////////////////// |
---|
| 686 | void cluster_processes_display( cxy_t cxy, |
---|
| 687 | bool_t owned ) |
---|
[1] | 688 | { |
---|
[428] | 689 | xptr_t root_xp; |
---|
[443] | 690 | xptr_t lock_xp; |
---|
[428] | 691 | xptr_t iter_xp; |
---|
[443] | 692 | xptr_t process_xp; |
---|
[583] | 693 | process_t * process_ptr; |
---|
| 694 | cxy_t process_cxy; |
---|
| 695 | pid_t pid; |
---|
[443] | 696 | cxy_t txt0_cxy; |
---|
| 697 | chdev_t * txt0_ptr; |
---|
| 698 | xptr_t txt0_xp; |
---|
| 699 | xptr_t txt0_lock_xp; |
---|
[627] | 700 | uint32_t pref_nr; // number of owned processes in cluster cxy |
---|
[1] | 701 | |
---|
[583] | 702 | assert( (cluster_is_undefined( cxy ) == false), "illegal cluster index" ); |
---|
[443] | 703 | |
---|
| 704 | // get extended pointer on root and lock for local process list in cluster |
---|
[428] | 705 | root_xp = XPTR( cxy , &LOCAL_CLUSTER->pmgr.local_root ); |
---|
[443] | 706 | lock_xp = XPTR( cxy , &LOCAL_CLUSTER->pmgr.local_lock ); |
---|
[1] | 707 | |
---|
[627] | 708 | // get number of owned processes in cluster cxy |
---|
| 709 | pref_nr = hal_remote_l32( XPTR( cxy , &LOCAL_CLUSTER->pmgr.pref_nr ) ); |
---|
| 710 | |
---|
| 711 | // display nothing if no user process in cluster cxy |
---|
| 712 | if( (owned != false) && (pref_nr < 2) ) return; |
---|
| 713 | |
---|
[443] | 714 | // get pointers on TXT0 chdev |
---|
| 715 | txt0_xp = chdev_dir.txt_tx[0]; |
---|
| 716 | txt0_cxy = GET_CXY( txt0_xp ); |
---|
| 717 | txt0_ptr = GET_PTR( txt0_xp ); |
---|
[1] | 718 | |
---|
[443] | 719 | // get extended pointer on TXT0 lock |
---|
| 720 | txt0_lock_xp = XPTR( txt0_cxy , &txt0_ptr->wait_lock ); |
---|
| 721 | |
---|
| 722 | // get lock on local process list |
---|
[564] | 723 | remote_queuelock_acquire( lock_xp ); |
---|
[443] | 724 | |
---|
[564] | 725 | // get TXT0 lock |
---|
| 726 | remote_busylock_acquire( txt0_lock_xp ); |
---|
[443] | 727 | |
---|
| 728 | nolock_printk("\n***** processes in cluster %x / cycle %d\n", |
---|
| 729 | cxy , (uint32_t)hal_get_cycles() ); |
---|
| 730 | |
---|
| 731 | // loop on all processes in cluster cxy |
---|
[428] | 732 | XLIST_FOREACH( root_xp , iter_xp ) |
---|
| 733 | { |
---|
[583] | 734 | process_xp = XLIST_ELEMENT( iter_xp , process_t , local_list ); |
---|
| 735 | process_ptr = GET_PTR( process_xp ); |
---|
| 736 | process_cxy = GET_CXY( process_xp ); |
---|
| 737 | |
---|
| 738 | // get process PID |
---|
| 739 | pid = hal_remote_l32( XPTR( process_cxy , &process_ptr->pid ) ); |
---|
| 740 | |
---|
| 741 | if( owned ) // display only user & owned processes |
---|
| 742 | { |
---|
| 743 | if( (CXY_FROM_PID( pid ) == cxy) && (LPID_FROM_PID( pid ) != 0) ) |
---|
| 744 | { |
---|
| 745 | process_display( process_xp ); |
---|
| 746 | } |
---|
| 747 | } |
---|
| 748 | else // display all local processes |
---|
| 749 | { |
---|
| 750 | process_display( process_xp ); |
---|
| 751 | } |
---|
[428] | 752 | } |
---|
[443] | 753 | |
---|
[564] | 754 | // release TXT0 lock |
---|
| 755 | remote_busylock_release( txt0_lock_xp ); |
---|
[443] | 756 | |
---|
| 757 | // release lock on local process list |
---|
[564] | 758 | remote_queuelock_release( lock_xp ); |
---|
[443] | 759 | |
---|
[428] | 760 | } // end cluster_processes_display() |
---|
[1] | 761 | |
---|
[19] | 762 | |
---|