[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) |
---|
[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 | |
---|
[14] | 26 | #include <kernel_config.h> |
---|
[1] | 27 | #include <hal_types.h> |
---|
| 28 | #include <hal_atomic.h> |
---|
| 29 | #include <hal_special.h> |
---|
[50] | 30 | #include <hal_ppm.h> |
---|
[407] | 31 | #include <remote_fifo.h> |
---|
[1] | 32 | #include <printk.h> |
---|
| 33 | #include <errno.h> |
---|
| 34 | #include <spinlock.h> |
---|
| 35 | #include <core.h> |
---|
| 36 | #include <scheduler.h> |
---|
| 37 | #include <list.h> |
---|
| 38 | #include <cluster.h> |
---|
| 39 | #include <boot_info.h> |
---|
| 40 | #include <bits.h> |
---|
| 41 | #include <ppm.h> |
---|
| 42 | #include <thread.h> |
---|
| 43 | #include <kmem.h> |
---|
| 44 | #include <process.h> |
---|
| 45 | #include <dqdt.h> |
---|
| 46 | |
---|
[408] | 47 | ///////////////////////////////////////////////////////////////////////////////////// |
---|
[1] | 48 | // Extern global variables |
---|
[408] | 49 | ///////////////////////////////////////////////////////////////////////////////////// |
---|
[1] | 50 | |
---|
[23] | 51 | extern process_t process_zero; // allocated in kernel_init.c file |
---|
[1] | 52 | |
---|
| 53 | |
---|
| 54 | ///////////////////////////////////////////////// |
---|
| 55 | error_t cluster_init( struct boot_info_s * info ) |
---|
| 56 | { |
---|
[428] | 57 | error_t error; |
---|
| 58 | lpid_t lpid; // local process_index |
---|
| 59 | lid_t lid; // local core index |
---|
| 60 | uint32_t i; // index in loop on external peripherals |
---|
| 61 | boot_device_t * dev; // pointer on external peripheral |
---|
| 62 | uint32_t func; // external peripheral functionnal type |
---|
[1] | 63 | |
---|
| 64 | cluster_t * cluster = LOCAL_CLUSTER; |
---|
| 65 | |
---|
| 66 | // initialize cluster global parameters |
---|
[19] | 67 | cluster->paddr_width = info->paddr_width; |
---|
[1] | 68 | cluster->x_width = info->x_width; |
---|
| 69 | cluster->y_width = info->y_width; |
---|
| 70 | cluster->x_size = info->x_size; |
---|
| 71 | cluster->y_size = info->y_size; |
---|
| 72 | cluster->io_cxy = info->io_cxy; |
---|
| 73 | |
---|
[428] | 74 | // initialize external peripherals channels |
---|
| 75 | for( i = 0 ; i < info->ext_dev_nr ; i++ ) |
---|
| 76 | { |
---|
| 77 | dev = &info->ext_dev[i]; |
---|
| 78 | func = FUNC_FROM_TYPE( dev->type ); |
---|
| 79 | if( func == DEV_FUNC_TXT ) cluster->nb_txt_channels = dev->channels; |
---|
| 80 | if( func == DEV_FUNC_NIC ) cluster->nb_nic_channels = dev->channels; |
---|
| 81 | if( func == DEV_FUNC_IOC ) cluster->nb_ioc_channels = dev->channels; |
---|
| 82 | if( func == DEV_FUNC_FBF ) cluster->nb_fbf_channels = dev->channels; |
---|
| 83 | } |
---|
| 84 | |
---|
[1] | 85 | // initialize cluster local parameters |
---|
| 86 | cluster->cores_nr = info->cores_nr; |
---|
| 87 | |
---|
[19] | 88 | // initialize the lock protecting the embedded kcm allocator |
---|
[1] | 89 | spinlock_init( &cluster->kcm_lock ); |
---|
| 90 | |
---|
[433] | 91 | #if CONFIG_DEBUG_CLUSTER_INIT |
---|
| 92 | uint32_t cycle = (uint32_t)hal_get_cycles(); |
---|
| 93 | if( CONFIG_DEBUG_CLUSTER_INIT < cycle ) |
---|
| 94 | printk("\n[DBG] %s enters for cluster %x / cycle %d\n", |
---|
| 95 | __FUNCTION__ , local_cxy , cycle ); |
---|
| 96 | #endif |
---|
[50] | 97 | |
---|
[19] | 98 | // initialises DQDT |
---|
| 99 | cluster->dqdt_root_level = dqdt_init( info->x_size, |
---|
| 100 | info->y_size, |
---|
[1] | 101 | info->y_width ); |
---|
| 102 | cluster->threads_var = 0; |
---|
| 103 | cluster->pages_var = 0; |
---|
| 104 | |
---|
| 105 | // initialises embedded PPM |
---|
[50] | 106 | error = hal_ppm_init( info ); |
---|
[1] | 107 | |
---|
[50] | 108 | if( error ) |
---|
| 109 | { |
---|
| 110 | printk("\n[ERROR] in %s : cannot initialize PPM in cluster %x\n", |
---|
| 111 | __FUNCTION__ , local_cxy ); |
---|
| 112 | return ENOMEM; |
---|
| 113 | } |
---|
| 114 | |
---|
[433] | 115 | #if CONFIG_DEBUG_CLUSTER_INIT |
---|
| 116 | cycle = (uint32_t)hal_get_cycles(); |
---|
| 117 | if( CONFIG_DEBUG_CLUSTER_INIT < cycle ) |
---|
| 118 | cluster_dmsg("\n[DBG] %s : PPM initialized in cluster %x / cycle %d\n", |
---|
| 119 | __FUNCTION__ , local_cxy , cycle ); |
---|
| 120 | #endif |
---|
[50] | 121 | |
---|
[1] | 122 | // initialises embedded KHM |
---|
| 123 | khm_init( &cluster->khm ); |
---|
[19] | 124 | |
---|
[407] | 125 | cluster_dmsg("\n[DBG] %s : KHM initialized in cluster %x at cycle %d\n", |
---|
[101] | 126 | __FUNCTION__ , local_cxy , hal_get_cycles() ); |
---|
[50] | 127 | |
---|
[19] | 128 | // initialises embedded KCM |
---|
[5] | 129 | kcm_init( &cluster->kcm , KMEM_KCM ); |
---|
[1] | 130 | |
---|
[407] | 131 | cluster_dmsg("\n[DBG] %s : KCM initialized in cluster %x at cycle %d\n", |
---|
[101] | 132 | __FUNCTION__ , local_cxy , hal_get_cycles() ); |
---|
[50] | 133 | |
---|
[296] | 134 | // initialises all cores descriptors |
---|
[1] | 135 | for( lid = 0 ; lid < cluster->cores_nr; lid++ ) |
---|
| 136 | { |
---|
| 137 | core_init( &cluster->core_tbl[lid], // target core descriptor |
---|
| 138 | lid, // local core index |
---|
| 139 | info->core[lid].gid ); // gid from boot_info_t |
---|
| 140 | } |
---|
[19] | 141 | |
---|
[433] | 142 | #if CONFIG_DEBUG_CLUSTER_INIT |
---|
| 143 | cycle = (uint32_t)hal_get_cycles(); |
---|
| 144 | if( CONFIG_DEBUG_CLUSTER_INIT < cycle ) |
---|
| 145 | cluster_dmsg("\n[DBG] %s : cores initialized in cluster %x / cycle %d\n", |
---|
| 146 | __FUNCTION__ , local_cxy , cycle ); |
---|
| 147 | #endif |
---|
[50] | 148 | |
---|
[1] | 149 | // initialises RPC fifo |
---|
[407] | 150 | local_fifo_init( &cluster->rpc_fifo ); |
---|
[279] | 151 | cluster->rpc_threads = 0; |
---|
[1] | 152 | |
---|
[407] | 153 | cluster_dmsg("\n[DBG] %s : RPC fifo inialized in cluster %x at cycle %d\n", |
---|
| 154 | __FUNCTION__ , local_cxy , hal_get_cycles() ); |
---|
[50] | 155 | |
---|
[1] | 156 | // initialise pref_tbl[] in process manager |
---|
| 157 | spinlock_init( &cluster->pmgr.pref_lock ); |
---|
| 158 | cluster->pmgr.pref_nr = 0; |
---|
[19] | 159 | cluster->pmgr.pref_tbl[0] = XPTR( local_cxy , &process_zero ); |
---|
[1] | 160 | for( lpid = 1 ; lpid < CONFIG_MAX_PROCESS_PER_CLUSTER ; lpid++ ) |
---|
| 161 | { |
---|
| 162 | cluster->pmgr.pref_tbl[lpid] = XPTR_NULL; |
---|
| 163 | } |
---|
| 164 | |
---|
| 165 | // initialise local_list in process manager |
---|
[23] | 166 | remote_spinlock_init( XPTR( local_cxy , &cluster->pmgr.local_lock ) ); |
---|
| 167 | xlist_root_init( XPTR( local_cxy , &cluster->pmgr.local_root ) ); |
---|
[1] | 168 | cluster->pmgr.local_nr = 0; |
---|
| 169 | |
---|
| 170 | // initialise copies_lists in process manager |
---|
[101] | 171 | for( lpid = 0 ; lpid < CONFIG_MAX_PROCESS_PER_CLUSTER ; lpid++ ) |
---|
[1] | 172 | { |
---|
| 173 | remote_spinlock_init( XPTR( local_cxy , &cluster->pmgr.copies_lock[lpid] ) ); |
---|
| 174 | cluster->pmgr.copies_nr[lpid] = 0; |
---|
| 175 | xlist_root_init( XPTR( local_cxy , &cluster->pmgr.copies_root[lpid] ) ); |
---|
[19] | 176 | } |
---|
[1] | 177 | |
---|
[433] | 178 | #if CONFIG_DEBUG_CLUSTER_INIT |
---|
| 179 | cycle = (uint32_t)hal_get_cycles(); |
---|
| 180 | if( CONFIG_DEBUG_CLUSTER_INIT < cycle ) |
---|
| 181 | cluster_dmsg("\n[DBG] %s Process Manager initialized in cluster %x / cycle %d\n", |
---|
| 182 | __FUNCTION__ , local_cxy , cycle ); |
---|
| 183 | #endif |
---|
[50] | 184 | |
---|
[124] | 185 | hal_fence(); |
---|
[1] | 186 | |
---|
| 187 | return 0; |
---|
| 188 | } // end cluster_init() |
---|
| 189 | |
---|
| 190 | //////////////////////////////////////// |
---|
| 191 | bool_t cluster_is_undefined( cxy_t cxy ) |
---|
| 192 | { |
---|
| 193 | cluster_t * cluster = LOCAL_CLUSTER; |
---|
| 194 | |
---|
| 195 | uint32_t y_width = cluster->y_width; |
---|
| 196 | |
---|
| 197 | uint32_t x = cxy >> y_width; |
---|
| 198 | uint32_t y = cxy & ((1<<y_width)-1); |
---|
| 199 | |
---|
[19] | 200 | if( x >= cluster->x_size ) return true; |
---|
| 201 | if( y >= cluster->y_size ) return true; |
---|
[1] | 202 | |
---|
| 203 | return false; |
---|
| 204 | } |
---|
| 205 | |
---|
| 206 | //////////////////////////////////////////////////////////////////////////////////// |
---|
| 207 | // Cores related functions |
---|
| 208 | //////////////////////////////////////////////////////////////////////////////////// |
---|
| 209 | |
---|
| 210 | ///////////////////////////////// |
---|
| 211 | lid_t cluster_select_local_core() |
---|
| 212 | { |
---|
| 213 | uint32_t min = 100; |
---|
| 214 | lid_t sel = 0; |
---|
| 215 | lid_t lid; |
---|
| 216 | |
---|
| 217 | cluster_t * cluster = LOCAL_CLUSTER; |
---|
| 218 | |
---|
| 219 | for( lid = 0 ; lid < cluster->cores_nr ; lid++ ) |
---|
| 220 | { |
---|
| 221 | if( cluster->core_tbl[lid].usage < min ) |
---|
| 222 | { |
---|
| 223 | min = cluster->core_tbl[lid].usage; |
---|
| 224 | sel = lid; |
---|
| 225 | } |
---|
[19] | 226 | } |
---|
[1] | 227 | return sel; |
---|
| 228 | } |
---|
| 229 | |
---|
| 230 | //////////////////////////////////////////////////////////////////////////////////// |
---|
[428] | 231 | // Process related functions |
---|
[1] | 232 | //////////////////////////////////////////////////////////////////////////////////// |
---|
| 233 | |
---|
[433] | 234 | |
---|
| 235 | ////////////////////////////////////////////////////// |
---|
| 236 | xptr_t cluster_get_owner_process_from_pid( pid_t pid ) |
---|
| 237 | { |
---|
| 238 | xptr_t root_xp; // xptr on root of list of processes in owner cluster |
---|
[436] | 239 | xptr_t lock_xp; // xptr on lock protecting this list |
---|
[433] | 240 | xptr_t iter_xp; // iterator |
---|
| 241 | xptr_t current_xp; // xptr on current process descriptor |
---|
| 242 | process_t * current_ptr; // local pointer on current process |
---|
| 243 | pid_t current_pid; // current process identifier |
---|
| 244 | bool_t found; |
---|
| 245 | |
---|
| 246 | cluster_t * cluster = LOCAL_CLUSTER; |
---|
| 247 | |
---|
| 248 | // get owner cluster and lpid |
---|
| 249 | cxy_t owner_cxy = CXY_FROM_PID( pid ); |
---|
| 250 | |
---|
| 251 | // get lock & root of list of process in owner cluster |
---|
| 252 | root_xp = XPTR( owner_cxy , &cluster->pmgr.local_root ); |
---|
| 253 | lock_xp = XPTR( owner_cxy , &cluster->pmgr.local_lock ); |
---|
| 254 | |
---|
| 255 | // take the lock protecting the list of processes |
---|
| 256 | remote_spinlock_lock( lock_xp ); |
---|
| 257 | |
---|
| 258 | // scan list of processes in owner cluster |
---|
| 259 | found = false; |
---|
| 260 | XLIST_FOREACH( root_xp , iter_xp ) |
---|
| 261 | { |
---|
| 262 | current_xp = XLIST_ELEMENT( iter_xp , process_t , local_list ); |
---|
| 263 | current_ptr = GET_PTR( current_xp ); |
---|
| 264 | current_pid = hal_remote_lw( XPTR( owner_cxy , ¤t_ptr->pid ) ); |
---|
| 265 | |
---|
| 266 | if( current_pid == pid ) |
---|
| 267 | { |
---|
| 268 | found = true; |
---|
| 269 | break; |
---|
| 270 | } |
---|
| 271 | } |
---|
| 272 | |
---|
| 273 | // release the lock protecting the list of processes |
---|
| 274 | remote_spinlock_unlock( lock_xp ); |
---|
| 275 | |
---|
| 276 | // return extended pointer on process descriptor in owner cluster |
---|
| 277 | if( found ) return current_xp; |
---|
| 278 | else return XPTR_NULL; |
---|
| 279 | |
---|
[436] | 280 | } // end cluster_get_owner_process_from_pid() |
---|
| 281 | |
---|
[1] | 282 | ////////////////////////////////////////////////////////// |
---|
| 283 | xptr_t cluster_get_reference_process_from_pid( pid_t pid ) |
---|
[19] | 284 | { |
---|
[23] | 285 | xptr_t ref_xp; // extended pointer on reference process descriptor |
---|
[1] | 286 | |
---|
| 287 | cluster_t * cluster = LOCAL_CLUSTER; |
---|
| 288 | |
---|
| 289 | // get owner cluster and lpid |
---|
| 290 | cxy_t owner_cxy = CXY_FROM_PID( pid ); |
---|
| 291 | lpid_t lpid = LPID_FROM_PID( pid ); |
---|
| 292 | |
---|
[19] | 293 | // Check valid PID |
---|
[23] | 294 | if( lpid >= CONFIG_MAX_PROCESS_PER_CLUSTER ) return XPTR_NULL; |
---|
[1] | 295 | |
---|
| 296 | if( local_cxy == owner_cxy ) // local cluster is owner cluster |
---|
[19] | 297 | { |
---|
[23] | 298 | ref_xp = cluster->pmgr.pref_tbl[lpid]; |
---|
[1] | 299 | } |
---|
| 300 | else // use a remote_lwd to access owner cluster |
---|
| 301 | { |
---|
[23] | 302 | ref_xp = (xptr_t)hal_remote_lwd( XPTR( owner_cxy , &cluster->pmgr.pref_tbl[lpid] ) ); |
---|
[1] | 303 | } |
---|
| 304 | |
---|
[23] | 305 | return ref_xp; |
---|
[1] | 306 | } |
---|
| 307 | |
---|
[416] | 308 | /////////////////////////////////////////////// |
---|
| 309 | error_t cluster_pid_alloc( process_t * process, |
---|
| 310 | pid_t * pid ) |
---|
[1] | 311 | { |
---|
| 312 | lpid_t lpid; |
---|
| 313 | bool_t found; |
---|
| 314 | |
---|
| 315 | pmgr_t * pm = &LOCAL_CLUSTER->pmgr; |
---|
| 316 | |
---|
| 317 | // get the process manager lock |
---|
| 318 | spinlock_lock( &pm->pref_lock ); |
---|
| 319 | |
---|
| 320 | // search an empty slot |
---|
| 321 | found = false; |
---|
| 322 | for( lpid = 0 ; lpid < CONFIG_MAX_PROCESS_PER_CLUSTER ; lpid++ ) |
---|
| 323 | { |
---|
| 324 | if( pm->pref_tbl[lpid] == XPTR_NULL ) |
---|
| 325 | { |
---|
| 326 | found = true; |
---|
| 327 | break; |
---|
| 328 | } |
---|
| 329 | } |
---|
| 330 | |
---|
| 331 | if( found ) |
---|
| 332 | { |
---|
| 333 | // register process in pref_tbl[] |
---|
[416] | 334 | pm->pref_tbl[lpid] = XPTR( local_cxy , process ); |
---|
[1] | 335 | pm->pref_nr++; |
---|
| 336 | |
---|
| 337 | // returns pid |
---|
| 338 | *pid = PID( local_cxy , lpid ); |
---|
| 339 | |
---|
[416] | 340 | // release the processs_manager lock |
---|
| 341 | spinlock_unlock( &pm->pref_lock ); |
---|
| 342 | |
---|
| 343 | return 0; |
---|
[1] | 344 | } |
---|
| 345 | else |
---|
| 346 | { |
---|
[416] | 347 | // release the processs_manager lock |
---|
| 348 | spinlock_unlock( &pm->pref_lock ); |
---|
| 349 | |
---|
| 350 | return -1; |
---|
[19] | 351 | } |
---|
[1] | 352 | |
---|
| 353 | } // end cluster_pid_alloc() |
---|
| 354 | |
---|
| 355 | ///////////////////////////////////// |
---|
| 356 | void cluster_pid_release( pid_t pid ) |
---|
| 357 | { |
---|
| 358 | cxy_t owner_cxy = CXY_FROM_PID( pid ); |
---|
| 359 | lpid_t lpid = LPID_FROM_PID( pid ); |
---|
| 360 | |
---|
[409] | 361 | pmgr_t * pm = &LOCAL_CLUSTER->pmgr; |
---|
| 362 | |
---|
[1] | 363 | // check pid argument |
---|
[409] | 364 | assert( (lpid < CONFIG_MAX_PROCESS_PER_CLUSTER) && (owner_cxy == local_cxy) , |
---|
| 365 | __FUNCTION__ , "illegal PID" ); |
---|
[1] | 366 | |
---|
| 367 | // get the process manager lock |
---|
| 368 | spinlock_lock( &pm->pref_lock ); |
---|
| 369 | |
---|
| 370 | // remove process from pref_tbl[] |
---|
| 371 | pm->pref_tbl[lpid] = XPTR_NULL; |
---|
| 372 | pm->pref_nr--; |
---|
| 373 | |
---|
| 374 | // release the processs_manager lock |
---|
| 375 | spinlock_unlock( &pm->pref_lock ); |
---|
| 376 | |
---|
| 377 | } // end cluster_pid_release() |
---|
| 378 | |
---|
| 379 | /////////////////////////////////////////////////////////// |
---|
| 380 | process_t * cluster_get_local_process_from_pid( pid_t pid ) |
---|
| 381 | { |
---|
[23] | 382 | xptr_t process_xp; |
---|
| 383 | process_t * process_ptr; |
---|
| 384 | xptr_t root_xp; |
---|
| 385 | xptr_t iter_xp; |
---|
| 386 | bool_t found; |
---|
[19] | 387 | |
---|
[23] | 388 | found = false; |
---|
| 389 | root_xp = XPTR( local_cxy , &LOCAL_CLUSTER->pmgr.local_root ); |
---|
| 390 | |
---|
| 391 | XLIST_FOREACH( root_xp , iter_xp ) |
---|
[1] | 392 | { |
---|
[23] | 393 | process_xp = XLIST_ELEMENT( iter_xp , process_t , local_list ); |
---|
| 394 | process_ptr = (process_t *)GET_PTR( process_xp ); |
---|
| 395 | if( process_ptr->pid == pid ) |
---|
[1] | 396 | { |
---|
[23] | 397 | found = true; |
---|
[1] | 398 | break; |
---|
| 399 | } |
---|
| 400 | } |
---|
| 401 | |
---|
[23] | 402 | if (found ) return process_ptr; |
---|
| 403 | else return NULL; |
---|
| 404 | |
---|
[1] | 405 | } // end cluster_get_local_process_from_pid() |
---|
| 406 | |
---|
| 407 | ////////////////////////////////////////////////////// |
---|
| 408 | void cluster_process_local_link( process_t * process ) |
---|
| 409 | { |
---|
[407] | 410 | uint32_t irq_state; |
---|
[1] | 411 | pmgr_t * pm = &LOCAL_CLUSTER->pmgr; |
---|
| 412 | |
---|
| 413 | // get lock protecting the process manager local list |
---|
[407] | 414 | remote_spinlock_lock_busy( XPTR( local_cxy , &pm->local_lock ) , & irq_state ); |
---|
[1] | 415 | |
---|
[428] | 416 | xlist_add_last( XPTR( local_cxy , &pm->local_root ), |
---|
| 417 | XPTR( local_cxy , &process->local_list ) ); |
---|
[1] | 418 | pm->local_nr++; |
---|
| 419 | |
---|
| 420 | // release lock protecting the process manager local list |
---|
[407] | 421 | remote_spinlock_unlock_busy( XPTR( local_cxy , &pm->local_lock ) , irq_state ); |
---|
[1] | 422 | } |
---|
| 423 | |
---|
| 424 | //////////////////////////////////////////////////////// |
---|
| 425 | void cluster_process_local_unlink( process_t * process ) |
---|
| 426 | { |
---|
[407] | 427 | uint32_t irq_state; |
---|
[1] | 428 | pmgr_t * pm = &LOCAL_CLUSTER->pmgr; |
---|
| 429 | |
---|
| 430 | // get lock protecting the process manager local list |
---|
[407] | 431 | remote_spinlock_lock_busy( XPTR( local_cxy , &pm->local_lock ) , &irq_state ); |
---|
[1] | 432 | |
---|
[23] | 433 | xlist_unlink( XPTR( local_cxy , &process->local_list ) ); |
---|
[1] | 434 | pm->local_nr--; |
---|
| 435 | |
---|
| 436 | // release lock protecting the process manager local list |
---|
[407] | 437 | remote_spinlock_unlock_busy( XPTR( local_cxy , &pm->local_lock ) , irq_state ); |
---|
[1] | 438 | } |
---|
| 439 | |
---|
| 440 | /////////////////////////////////////////////////////// |
---|
| 441 | void cluster_process_copies_link( process_t * process ) |
---|
| 442 | { |
---|
[436] | 443 | reg_t irq_state; |
---|
[1] | 444 | pmgr_t * pm = &LOCAL_CLUSTER->pmgr; |
---|
| 445 | |
---|
[436] | 446 | #if CONFIG_DEBUG_CLUSTER_PROCESS_COPIES |
---|
| 447 | uint32_t cycle = (uint32_t)hal_get_cycles(); |
---|
| 448 | if( CONFIG_DEBUG_CLUSTER_PROCESS_COPIES < cycle ) |
---|
| 449 | printk("\n[DBG] %s enters / cluster %x / process %x / cycle %d\n", |
---|
| 450 | __FUNCTION__ , local_cxy , process , cycle ); |
---|
| 451 | #endif |
---|
| 452 | |
---|
[1] | 453 | // get owner cluster identifier CXY and process LPID |
---|
| 454 | pid_t pid = process->pid; |
---|
| 455 | cxy_t owner_cxy = CXY_FROM_PID( pid ); |
---|
| 456 | lpid_t lpid = LPID_FROM_PID( pid ); |
---|
| 457 | |
---|
| 458 | // get extended pointer on lock protecting copies_list[lpid] |
---|
[120] | 459 | xptr_t copies_lock = XPTR( owner_cxy , &pm->copies_lock[lpid] ); |
---|
[1] | 460 | |
---|
| 461 | // get extended pointer on the copies_list[lpid] root |
---|
[120] | 462 | xptr_t copies_root = XPTR( owner_cxy , &pm->copies_root[lpid] ); |
---|
[1] | 463 | |
---|
| 464 | // get extended pointer on the local copies_list entry |
---|
| 465 | xptr_t copies_entry = XPTR( local_cxy , &process->copies_list ); |
---|
| 466 | |
---|
[19] | 467 | // get lock protecting copies_list[lpid] |
---|
[407] | 468 | remote_spinlock_lock_busy( copies_lock , &irq_state ); |
---|
[1] | 469 | |
---|
[436] | 470 | // add copy to copies_list |
---|
[1] | 471 | xlist_add_first( copies_root , copies_entry ); |
---|
| 472 | hal_remote_atomic_add( XPTR( owner_cxy , &pm->copies_nr[lpid] ) , 1 ); |
---|
| 473 | |
---|
[19] | 474 | // release lock protecting copies_list[lpid] |
---|
[407] | 475 | remote_spinlock_unlock_busy( copies_lock , irq_state ); |
---|
[1] | 476 | |
---|
[436] | 477 | #if CONFIG_DEBUG_CLUSTER_PROCESS_COPIES |
---|
| 478 | cycle = (uint32_t)hal_get_cycles(); |
---|
| 479 | if( CONFIG_DEBUG_CLUSTER_PROCESS_COPIES < cycle ) |
---|
| 480 | printk("\n[DBG] %s exit / cluster %x / process %x / cycle %d\n", |
---|
| 481 | __FUNCTION__ , local_cxy , process , cycle ); |
---|
| 482 | #endif |
---|
| 483 | |
---|
| 484 | } // end cluster_process_copies_link() |
---|
| 485 | |
---|
[1] | 486 | ///////////////////////////////////////////////////////// |
---|
| 487 | void cluster_process_copies_unlink( process_t * process ) |
---|
| 488 | { |
---|
[407] | 489 | uint32_t irq_state; |
---|
[1] | 490 | pmgr_t * pm = &LOCAL_CLUSTER->pmgr; |
---|
| 491 | |
---|
[436] | 492 | #if CONFIG_DEBUG_CLUSTER_PROCESS_COPIES |
---|
| 493 | uint32_t cycle = (uint32_t)hal_get_cycles(); |
---|
| 494 | if( CONFIG_DEBUG_CLUSTER_PROCESS_COPIES < cycle ) |
---|
| 495 | printk("\n[DBG] %s enters / cluster %x / process %x / cycle %d\n", |
---|
| 496 | __FUNCTION__ , local_cxy , process , cycle ); |
---|
| 497 | #endif |
---|
| 498 | |
---|
[1] | 499 | // get owner cluster identifier CXY and process LPID |
---|
| 500 | pid_t pid = process->pid; |
---|
| 501 | cxy_t owner_cxy = CXY_FROM_PID( pid ); |
---|
| 502 | lpid_t lpid = LPID_FROM_PID( pid ); |
---|
| 503 | |
---|
| 504 | // get extended pointer on lock protecting copies_list[lpid] |
---|
[436] | 505 | xptr_t copies_lock = XPTR( owner_cxy , &pm->copies_lock[lpid] ); |
---|
[1] | 506 | |
---|
| 507 | // get extended pointer on the local copies_list entry |
---|
| 508 | xptr_t copies_entry = XPTR( local_cxy , &process->copies_list ); |
---|
| 509 | |
---|
[19] | 510 | // get lock protecting copies_list[lpid] |
---|
[407] | 511 | remote_spinlock_lock_busy( copies_lock , &irq_state ); |
---|
[1] | 512 | |
---|
[436] | 513 | // remove copy from copies_list |
---|
[1] | 514 | xlist_unlink( copies_entry ); |
---|
| 515 | hal_remote_atomic_add( XPTR( owner_cxy , &pm->copies_nr[lpid] ) , -1 ); |
---|
| 516 | |
---|
[19] | 517 | // release lock protecting copies_list[lpid] |
---|
[407] | 518 | remote_spinlock_unlock_busy( copies_lock , irq_state ); |
---|
[1] | 519 | |
---|
[436] | 520 | #if CONFIG_DEBUG_CLUSTER_PROCESS_COPIES |
---|
| 521 | cycle = (uint32_t)hal_get_cycles(); |
---|
| 522 | if( CONFIG_DEBUG_CLUSTER_PROCESS_COPIES < cycle ) |
---|
| 523 | printk("\n[DBG] %s exit / cluster %x / process %x / cycle %d\n", |
---|
| 524 | __FUNCTION__ , local_cxy , process , cycle ); |
---|
| 525 | #endif |
---|
| 526 | |
---|
| 527 | } // end cluster_process_copies_unlink() |
---|
| 528 | |
---|
[428] | 529 | /////////////////////////////////////////// |
---|
| 530 | void cluster_processes_display( cxy_t cxy ) |
---|
[1] | 531 | { |
---|
[428] | 532 | xptr_t root_xp; |
---|
| 533 | xptr_t iter_xp; |
---|
| 534 | xptr_t process_xp; |
---|
[1] | 535 | |
---|
[428] | 536 | // get extended pointer on root of process in cluster cxy |
---|
| 537 | root_xp = XPTR( cxy , &LOCAL_CLUSTER->pmgr.local_root ); |
---|
[1] | 538 | |
---|
[428] | 539 | // skip one line |
---|
[433] | 540 | printk("\n***** processes in cluster %x / cycle %d\n", cxy , (uint32_t)hal_get_cycles() ); |
---|
[1] | 541 | |
---|
[428] | 542 | // loop on all reference processes in cluster cxy |
---|
| 543 | XLIST_FOREACH( root_xp , iter_xp ) |
---|
| 544 | { |
---|
| 545 | process_xp = XLIST_ELEMENT( iter_xp , process_t , local_list ); |
---|
| 546 | process_display( process_xp ); |
---|
| 547 | } |
---|
| 548 | } // end cluster_processes_display() |
---|
[1] | 549 | |
---|
[19] | 550 | |
---|