Ignore:
Timestamp:
Oct 4, 2018, 11:47:36 PM (6 years ago)
Author:
alain
Message:

Complete restructuration of kernel locks.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/kernel/kern/cluster.c

    r562 r564  
    2929#include <hal_special.h>
    3030#include <hal_ppm.h>
     31#include <hal_macros.h>
    3132#include <remote_fifo.h>
    3233#include <printk.h>
    3334#include <errno.h>
    34 #include <spinlock.h>
     35#include <queuelock.h>
    3536#include <core.h>
    3637#include <chdev.h>
     
    4546#include <process.h>
    4647#include <dqdt.h>
    47 #include <cluster_info.h>
    4848
    4949/////////////////////////////////////////////////////////////////////////////////////
     
    5151/////////////////////////////////////////////////////////////////////////////////////
    5252
    53 extern process_t           process_zero;     // allocated in kernel_init.c file
    54 extern chdev_directory_t   chdev_dir;        // allocated in kernel_init.c file
    55 
    56 ///////////////////////////////////////////////n
    57 error_t cluster_init( struct boot_info_s * info )
    58 {
    59     error_t         error;
    60     lpid_t          lpid;     // local process_index
    61     lid_t           lid;      // local core index
    62     uint32_t        i;        // index in loop on external peripherals
     53extern process_t           process_zero;     // allocated in kernel_init.c
     54extern chdev_directory_t   chdev_dir;        // allocated in kernel_init.c
     55
     56
     57
     58///////////////////////////////////////////////////
     59void cluster_info_init( struct boot_info_s * info )
     60{
    6361    boot_device_t * dev;      // pointer on external peripheral
    6462    uint32_t        func;     // external peripheral functionnal type
     63    uint32_t        x;
     64    uint32_t        y;
     65    uint32_t        i;   
    6566
    6667        cluster_t * cluster = LOCAL_CLUSTER;
     
    7576
    7677    // initialize the cluster_info[][] array
    77     int x;
    78     int y;
    79     for (x = 0; x < CONFIG_MAX_CLUSTERS_X; x++) {
    80         for (y = 0; y < CONFIG_MAX_CLUSTERS_Y;y++) {
     78    for (x = 0; x < CONFIG_MAX_CLUSTERS_X; x++)
     79    {
     80        for (y = 0; y < CONFIG_MAX_CLUSTERS_Y;y++)
     81        {
    8182            cluster->cluster_info[x][y] = info->cluster_info[x][y];
    8283        }
    8384    }
     85
    8486    // initialize external peripherals channels
    8587    for( i = 0 ; i < info->ext_dev_nr ; i++ )
     
    9395    }
    9496
    95     // initialize cluster local parameters
    96         cluster->cores_nr        = info->cores_nr;
     97    // initialize number of cores
     98        cluster->cores_nr  = info->cores_nr;
     99
     100}  // end cluster_info_init()
     101
     102/////////////////////////////////////////////////////////
     103error_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;
    97110
    98111    // initialize the lock protecting the embedded kcm allocator
    99         spinlock_init( &cluster->kcm_lock );
     112        busylock_init( &cluster->kcm_lock , LOCK_CLUSTER_KCM );
    100113
    101114#if DEBUG_CLUSTER_INIT
    102115uint32_t cycle = (uint32_t)hal_get_cycles();
    103116if( DEBUG_CLUSTER_INIT < cycle )
    104 printk("\n[DBG] %s : thread %x enters for cluster %x / cycle %d\n",
    105 __FUNCTION__ , CURRENT_THREAD , local_cxy , cycle );
     117printk("\n[DBG] %s : thread %x in process %x enters for cluster %x / cycle %d\n",
     118__FUNCTION__, CURRENT_THREAD->trdid, CURRENT_THREAD->process->pid, local_cxy , cycle );
    106119#endif
    107120
    108121    // initialises DQDT
    109122    cluster->dqdt_root_level = dqdt_init( info->x_size,
    110                                           info->y_size,
    111                                           info->y_width ) - 1;
     123                                          info->y_size ) - 1;
     124
     125#if( DEBUG_CLUSTER_INIT & 1 )
     126cycle = (uint32_t)hal_get_cycles();
     127if( DEBUG_CLUSTER_INIT < cycle )
     128printk("\n[DBG] %s : DQDT initialized in cluster %x / cycle %d\n",
     129__FUNCTION__ , local_cxy , cycle );
     130#endif
    112131
    113132    // initialises embedded PPM
     
    166185        for( lid = 0 ; lid < cluster->cores_nr; lid++ )
    167186    {
    168             local_fifo_init( &cluster->rpc_fifo[lid] );
     187            remote_fifo_init( &cluster->rpc_fifo[lid] );
    169188        cluster->rpc_threads[lid] = 0;
    170189    }
     
    178197
    179198    // initialise pref_tbl[] in process manager
    180         spinlock_init( &cluster->pmgr.pref_lock );
     199        queuelock_init( &cluster->pmgr.pref_lock , LOCK_CLUSTER_PREFTBL );
    181200    cluster->pmgr.pref_nr = 0;
    182201    cluster->pmgr.pref_tbl[0] = XPTR( local_cxy , &process_zero );
     
    187206
    188207    // initialise local_list in process manager
    189         remote_spinlock_init( XPTR( local_cxy , &cluster->pmgr.local_lock ) );
    190208    xlist_root_init( XPTR( local_cxy , &cluster->pmgr.local_root ) );
    191209    cluster->pmgr.local_nr = 0;
     210        remote_queuelock_init( XPTR( local_cxy , &cluster->pmgr.local_lock ) ,
     211                           LOCK_CLUSTER_LOCALS );
    192212
    193213    // initialise copies_lists in process manager
    194214    for( lpid = 0 ; lpid < CONFIG_MAX_PROCESS_PER_CLUSTER ; lpid++ )
    195215    {
    196             remote_spinlock_init( XPTR( local_cxy , &cluster->pmgr.copies_lock[lpid] ) );
    197216        cluster->pmgr.copies_nr[lpid] = 0;
    198217        xlist_root_init( XPTR( local_cxy , &cluster->pmgr.copies_root[lpid] ) );
     218            remote_queuelock_init( XPTR( local_cxy , &cluster->pmgr.copies_lock[lpid] ),
     219                               LOCK_CLUSTER_COPIES );
    199220    }
    200221
     
    202223cycle = (uint32_t)hal_get_cycles();
    203224if( DEBUG_CLUSTER_INIT < cycle )
    204 printk("\n[DBG] %s , thread %x exit for cluster %x / cycle %d\n",
    205 __FUNCTION__ , CURRENT_THREAD , local_cxy , cycle );
     225printk("\n[DBG] %s : thread %x in process %x exit for cluster %x / cycle %d\n",
     226__FUNCTION__, CURRENT_THREAD->trdid, CURRENT_THREAD->process->pid , local_cxy , cycle );
    206227#endif
    207228
     
    209230
    210231        return 0;
    211 } // end cluster_init()
    212 
    213 /////////////////////////////////
     232} // end cluster_manager_init()
     233
     234///////////////////////////////////
    214235cxy_t cluster_random_select( void )
    215236{
    216     uint32_t  x_size;
    217     uint32_t  y_size;
    218     uint32_t  y_width;
    219237    uint32_t  index;
    220     uint32_t  x;
     238    uint32_t  x;   
    221239    uint32_t  y;
    222 
    223     do {
    224         x_size     = LOCAL_CLUSTER->x_size;
    225         y_size     = LOCAL_CLUSTER->y_size;
    226         y_width   = LOCAL_CLUSTER->y_width;
     240    cxy_t     cxy;
     241
     242    uint32_t  x_size    = LOCAL_CLUSTER->x_size;
     243    uint32_t  y_size    = LOCAL_CLUSTER->y_size;
     244
     245    do
     246    {
    227247        index     = ( hal_get_cycles() + hal_get_gid() ) % (x_size * y_size);
    228248        x         = index / y_size;
    229249        y         = index % y_size;
    230     } while ( cluster_info_is_active( LOCAL_CLUSTER->cluster_info[x][y] ) == 0 );
    231 
    232     return (x<<y_width) + y;
     250        cxy       = HAL_CXY_FROM_XY( x , y );
     251    }
     252    while ( cluster_is_active( cxy ) == false );
     253
     254    return ( cxy );
    233255}
    234256
     
    236258bool_t cluster_is_undefined( cxy_t cxy )
    237259{
    238     cluster_t * cluster = LOCAL_CLUSTER;
    239 
    240     uint32_t y_width = cluster->y_width;
    241 
    242     uint32_t x = cxy >> y_width;
    243     uint32_t y = cxy & ((1<<y_width)-1);
    244 
    245     if( x >= cluster->x_size ) return true;
    246     if( y >= cluster->y_size ) return true;
     260    uint32_t  x_size = LOCAL_CLUSTER->x_size;
     261    uint32_t  y_size = LOCAL_CLUSTER->y_size;
     262
     263    uint32_t  x      = HAL_X_FROM_CXY( cxy );
     264    uint32_t  y      = HAL_Y_FROM_CXY( cxy );
     265
     266    if( x >= x_size ) return true;
     267    if( y >= y_size ) return true;
    247268
    248269    return false;
     270}
     271
     272//////////////////////////////////////
     273bool_t cluster_is_active ( cxy_t cxy )
     274{
     275    uint32_t x = HAL_X_FROM_CXY( cxy );
     276    uint32_t y = HAL_Y_FROM_CXY( cxy );
     277
     278    return ( LOCAL_CLUSTER->cluster_info[x][y] != 0 );
    249279}
    250280
     
    304334
    305335    // take the lock protecting the list of processes
    306     remote_spinlock_lock( lock_xp );
     336    remote_queuelock_acquire( lock_xp );
    307337
    308338    // scan list of processes
     
    320350
    321351    // release the lock protecting the list of processes
    322     remote_spinlock_unlock( lock_xp );
     352    remote_queuelock_release( lock_xp );
    323353
    324354    // return extended pointer on process descriptor in owner cluster
     
    350380
    351381    // take the lock protecting the list of processes
    352     remote_spinlock_lock( lock_xp );
     382    remote_queuelock_acquire( lock_xp );
    353383
    354384    // scan list of processes in owner cluster
     
    358388        current_xp  = XLIST_ELEMENT( iter_xp , process_t , local_list );
    359389        current_ptr = GET_PTR( current_xp );
    360         current_pid = hal_remote_lw( XPTR( owner_cxy , &current_ptr->pid ) );
     390        current_pid = hal_remote_l32( XPTR( owner_cxy , &current_ptr->pid ) );
    361391
    362392        if( current_pid == pid )
     
    368398
    369399    // release the lock protecting the list of processes
    370     remote_spinlock_unlock( lock_xp );
     400    remote_queuelock_release( lock_xp );
    371401
    372402    // return extended pointer on process descriptor in owner cluster
     
    397427    else                              // use a remote_lwd to access owner cluster
    398428    {
    399         ref_xp = (xptr_t)hal_remote_lwd( XPTR( owner_cxy , &cluster->pmgr.pref_tbl[lpid] ) );
     429        ref_xp = (xptr_t)hal_remote_l64( XPTR( owner_cxy , &cluster->pmgr.pref_tbl[lpid] ) );
    400430    }
    401431
     
    419449    pmgr_t    * pm         = &LOCAL_CLUSTER->pmgr;
    420450
    421     // get the process manager lock
    422     spinlock_lock( &pm->pref_lock );
     451    // get the lock protecting pref_tbl
     452    queuelock_acquire( &pm->pref_lock );
    423453
    424454    // search an empty slot
     
    443473
    444474        // release the processs_manager lock
    445         spinlock_unlock( &pm->pref_lock );
     475        queuelock_release( &pm->pref_lock );
    446476
    447477        return 0;
     
    449479    else
    450480    {
    451         // release the processs_manager lock
    452         spinlock_unlock( &pm->pref_lock );
    453 
    454         return -1;
     481        // release the lock
     482        queuelock_release( &pm->pref_lock );
     483
     484        return 0xFFFFFFFF;
    455485    }
    456486
     
    488518    "local_cluster %x !=  owner_cluster %x" , local_cxy , owner_cxy );
    489519
    490     // get the process manager lock
    491     spinlock_lock( &pm->pref_lock );
     520    // get the lock protecting pref_tbl
     521    queuelock_acquire( &pm->pref_lock );
    492522
    493523    // remove process from pref_tbl[]
     
    496526
    497527    // release the processs_manager lock
    498     spinlock_unlock( &pm->pref_lock );
     528    queuelock_release( &pm->pref_lock );
    499529
    500530#if DEBUG_CLUSTER_PID_RELEASE
     
    538568void cluster_process_local_link( process_t * process )
    539569{
    540     reg_t    save_sr;
    541 
    542570    pmgr_t * pm = &LOCAL_CLUSTER->pmgr;
    543571
     
    546574    xptr_t lock_xp = XPTR( local_cxy , &pm->local_lock );
    547575
    548     // get lock protecting the process manager local list
    549     remote_spinlock_lock_busy( lock_xp , &save_sr );
     576    // get lock protecting the local list
     577    remote_queuelock_acquire( lock_xp );
    550578
    551579    // register process in local list
     
    553581    pm->local_nr++;
    554582
    555     // release lock protecting the process manager local list
    556     remote_spinlock_unlock_busy( lock_xp , save_sr );
     583    // release lock protecting the local list
     584    remote_queuelock_release( lock_xp );
    557585}
    558586
     
    560588void cluster_process_local_unlink( process_t * process )
    561589{
    562     reg_t save_sr;
    563 
    564590    pmgr_t * pm = &LOCAL_CLUSTER->pmgr;
    565591
     
    567593    xptr_t lock_xp = XPTR( local_cxy , &pm->local_lock );
    568594
    569     // get lock protecting the process manager local list
    570     remote_spinlock_lock_busy( lock_xp , &save_sr );
     595    // get lock protecting the local list
     596    remote_queuelock_acquire( lock_xp );
    571597
    572598    // remove process from local list
     
    574600    pm->local_nr--;
    575601
    576     // release lock protecting the process manager local list
    577     remote_spinlock_unlock_busy( lock_xp , save_sr );
     602    // release lock protecting the local list
     603    remote_queuelock_release( lock_xp );
    578604}
    579605
     
    581607void cluster_process_copies_link( process_t * process )
    582608{
    583     reg_t    irq_state;
    584609    pmgr_t * pm = &LOCAL_CLUSTER->pmgr;
    585610
     
    606631
    607632    // get lock protecting copies_list[lpid]
    608     remote_spinlock_lock_busy( copies_lock , &irq_state );
     633    remote_queuelock_acquire( copies_lock );
    609634
    610635    // add copy to copies_list
     
    613638
    614639    // release lock protecting copies_list[lpid]
    615     remote_spinlock_unlock_busy( copies_lock , irq_state );
     640    remote_queuelock_release( copies_lock );
    616641
    617642#if DEBUG_CLUSTER_PROCESS_COPIES
     
    627652void cluster_process_copies_unlink( process_t * process )
    628653{
    629     uint32_t irq_state;
    630654    pmgr_t * pm = &LOCAL_CLUSTER->pmgr;
    631655
     
    649673
    650674    // get lock protecting copies_list[lpid]
    651     remote_spinlock_lock_busy( copies_lock , &irq_state );
     675    remote_queuelock_acquire( copies_lock );
    652676
    653677    // remove copy from copies_list
     
    656680
    657681    // release lock protecting copies_list[lpid]
    658     remote_spinlock_unlock_busy( copies_lock , irq_state );
     682    remote_queuelock_release( copies_lock );
    659683
    660684#if DEBUG_CLUSTER_PROCESS_COPIES
     
    678702    xptr_t        txt0_xp;
    679703    xptr_t        txt0_lock_xp;
    680     reg_t         txt0_save_sr;     // save SR to take TXT0 lock in busy mode     
    681704
    682705    assert( (cluster_is_undefined( cxy ) == false),
     
    696719
    697720    // get lock on local process list
    698     remote_spinlock_lock( lock_xp );
    699 
    700     // get TXT0 lock in busy waiting mode
    701     remote_spinlock_lock_busy( txt0_lock_xp , &txt0_save_sr );
     721    remote_queuelock_acquire( lock_xp );
     722
     723    // get TXT0 lock
     724    remote_busylock_acquire( txt0_lock_xp );
    702725     
    703726    // display header
     
    712735    }
    713736
    714     // release TXT0 lock in busy waiting mode
    715     remote_spinlock_unlock_busy( txt0_lock_xp , txt0_save_sr );
     737    // release TXT0 lock
     738    remote_busylock_release( txt0_lock_xp );
    716739
    717740    // release lock on local process list
    718     remote_spinlock_unlock( lock_xp );
     741    remote_queuelock_release( lock_xp );
    719742
    720743}  // end cluster_processes_display()
Note: See TracChangeset for help on using the changeset viewer.