Ignore:
Timestamp:
Jan 13, 2021, 12:36:17 AM (3 years ago)
Author:
alain
Message:

All modifications required to support the <tcp_chat> application
including error recovery in case of packet loss.A

File:
1 edited

Legend:

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

    r669 r683  
    3131
    3232////////////////////////////////////////////////////////////////////////////////////////////
    33 // This static function registers the alarm identified ny the <new_alarm> argument
     33// This static function registers the alarm identified by the <alarm> & <cxy> arguments
    3434// in the list of alarms rooted in the core identified by the <core> argument.
    3535// When the existing list of alarms is not empty, it scan the list to insert the new
    3636// alarm in the right place to respect the absolute dates ordering.
    3737////////////////////////////////////////////////////////////////////////////////////////////
    38 // @ new_alarm  : local pointer on the new alarm.
    39 // @ core       : local pointer on the target core.
     38// @ cxy    : cluster containing both the new alarm and the core.
     39// @ alarm  : local pointer on the alarm.
     40// @ core   : local pointer on the core.
    4041////////////////////////////////////////////////////////////////////////////////////////////
    41 static void alarm_register( alarm_t * new_alarm,
     42static void alarm_register( cxy_t     cxy,
     43                            alarm_t * alarm,
    4244                            core_t  * core )
    4345{
    44     list_entry_t * current;          // pointer on current list_entry in existing list
    45     list_entry_t * previous;         // pointer on previous list_entry in existing list
    46     alarm_t      * current_alarm;    // pointer on current alarm in existing list
    47     cycle_t        current_date;     // date of current alarm in existing list
    48 
    49     bool_t         done = false;
    50 
    51     // get pointers on root of alarms and lock
     46    // get alarm date
     47    cycle_t new_date = hal_remote_l64( XPTR( cxy , &alarm->date ) );
     48
     49    // build local pointer on root of alarms list
    5250    list_entry_t * root = &core->alarms_root;
    53     busylock_t   * lock = &core->alarms_lock;
    54 
    55     // get pointer on new_alarm list_entry
    56     list_entry_t * new_entry = &new_alarm->list;
    57 
    58     // get new_alarm date
    59     cycle_t        new_date = new_alarm->date;
    60 
    61     // take the lock
    62     busylock_acquire( lock );
     51
     52    // build local pointer on new alarm list_entry
     53    list_entry_t * new  = &alarm->list;
    6354
    6455    // insert new alarm to respect dates order
    65     if( list_is_empty( root ) )                     // list empty
     56    if( list_remote_is_empty( cxy , &core->alarms_root ) )  // list empty
    6657    {
    67         list_add_first( root , new_entry );
     58        list_remote_add_first( cxy , root , new );
    6859    }
    69     else                                            // list non empty
     60    else                                                   // list non empty
    7061    {
    71         for( current = root->next ;
    72              (current != root) && (done == false) ;
    73              current = current->next )
     62        list_entry_t * iter;        // local pointer on current list_entry in existing list
     63        alarm_t      * iter_alarm;  // local pointer on current alarm in existing list
     64        cycle_t        iter_date;   // date of current alarm in existing list
     65        bool_t         done = false;
     66
     67        for( iter = hal_remote_lpt( XPTR( cxy , &root->next ) ) ;
     68             (iter != root) && (done == false) ;
     69             iter = hal_remote_lpt( XPTR( cxy , &iter->next ) ) )
    7470        {
    75             // get pointer on previous entry in existing list
    76             previous = current->pred;
    77 
    78             // get pointer on current alarm
    79             current_alarm = LIST_ELEMENT( current , alarm_t , list );
     71            // get local pointer on pred and next for iter
     72            list_entry_t * prev = hal_remote_lpt( XPTR( cxy , &iter->pred ) );
     73
     74            // get local pointer on current alarm
     75            iter_alarm = LIST_ELEMENT( iter , alarm_t , list );
    8076
    8177            // get date for current alarm
    82             current_date  = current_alarm->date;
    83 
    84             if( current_date > new_date )  // insert new alarm just before current
     78            iter_date = hal_remote_l64( XPTR( cxy , &iter_alarm->date ) );
     79
     80            // insert new alarm just before current when required
     81            if( iter_date > new_date ) 
    8582            {
    86                 new_entry->next = current;
    87                 new_entry->pred = previous;
    88 
    89                 current->pred  = new_entry;
    90                 previous->next = new_entry;
     83                hal_remote_spt( XPTR( cxy , &new->next ) , iter );
     84                hal_remote_spt( XPTR( cxy , &new->pred ) , prev );
     85
     86                hal_remote_spt( XPTR( cxy , &iter->pred ) , new );
     87                hal_remote_spt( XPTR( cxy , &prev->next ) , new );
    9188               
    9289                done = true;
     
    9693        if( done == false ) // new_date is larger than all registered dates
    9794        {
    98             list_add_last( root , new_entry );
     95            list_remote_add_last( cxy, root , new );
    9996        }
    10097    }
    101 
     98}  // end alarm_register()
     99           
     100
     101///////////////////////////////////
     102void alarm_init( alarm_t *  alarm )
     103{
     104    alarm->linked   = false;
     105    list_entry_init( &alarm->list );
     106}
     107
     108///////////////////////////////////////
     109void alarm_start( xptr_t     thread_xp,
     110                  cycle_t    date,
     111                  void     * func_ptr,
     112                  xptr_t     args_xp )
     113{
     114    // get cluster and local pointer on target thread
     115    thread_t * tgt_ptr = GET_PTR( thread_xp );
     116    cxy_t      tgt_cxy = GET_CXY( thread_xp );
     117
     118// check alarm state
     119assert( __FUNCTION__ , (hal_remote_l32( XPTR(tgt_cxy,&tgt_ptr->alarm.linked)) == false ),
     120"alarm already started");
     121
     122    // get local pointer on core running target thread
     123    core_t * core = hal_remote_lpt( XPTR( tgt_cxy , &tgt_ptr->core ) );
     124
     125    // build extended pointer on lock protecting alarms list
     126    xptr_t lock_xp = XPTR( tgt_cxy , &core->alarms_lock );
     127 
     128    // initialize alarm descriptor
     129    hal_remote_s64( XPTR( tgt_cxy , &tgt_ptr->alarm.date     ) , date );
     130    hal_remote_spt( XPTR( tgt_cxy , &tgt_ptr->alarm.func_ptr ) , func_ptr );
     131    hal_remote_s64( XPTR( tgt_cxy , &tgt_ptr->alarm.args_xp  ) , args_xp );
     132    hal_remote_s32( XPTR( tgt_cxy , &tgt_ptr->alarm.linked   ) , true );
     133
     134    // take the lock
     135    remote_busylock_acquire( lock_xp );
     136
     137    // register alarm in core list
     138    alarm_register( tgt_cxy , &tgt_ptr->alarm , core );
     139
     140    //release the lock
     141    remote_busylock_release( lock_xp );
     142
     143}  // end alarm_start()
     144
     145
     146/////////////////////////////////////
     147void alarm_stop( xptr_t   thread_xp )
     148{
     149    // get cluster and local pointer on target thread
     150    thread_t * tgt_ptr = GET_PTR( thread_xp );
     151    cxy_t      tgt_cxy = GET_CXY( thread_xp );
     152
     153    // get local pointer on core running target thread
     154    core_t * core = hal_remote_lpt( XPTR( tgt_cxy , &tgt_ptr->core ) );
     155
     156    // build extended pointer on lock protecting alarms list
     157    xptr_t lock_xp = XPTR( tgt_cxy , &core->alarms_lock );
     158 
     159    // take the lock
     160    remote_busylock_acquire( lock_xp );
     161
     162    // unlink the alarm from the list rooted in core
     163    list_remote_unlink( tgt_cxy , &tgt_ptr->alarm.list );
     164
     165    // update alarm state
     166    hal_remote_s32( XPTR( tgt_cxy , &tgt_ptr->alarm.linked ) , false );
     167
     168    //release the lock
     169    remote_busylock_release( lock_xp );
     170
     171}  // end alarm_stop()
     172
     173
     174//////////////////////////////////////
     175void alarm_update( xptr_t   thread_xp,
     176                   cycle_t  new_date )
     177{
     178    // get cluster and local pointer on target thread
     179    thread_t * tgt_ptr = GET_PTR( thread_xp );
     180    cxy_t      tgt_cxy = GET_CXY( thread_xp );
     181
     182    // get local pointer on core running target thread
     183    core_t * core = hal_remote_lpt( XPTR( tgt_cxy , &tgt_ptr->core ) );
     184
     185    // build extended pointer on lock protecting alarms list
     186    xptr_t lock_xp = XPTR( tgt_cxy , &core->alarms_lock );
     187 
     188    // take the lock
     189    remote_busylock_acquire( lock_xp );
     190
     191    // unlink the alarm from the core list
     192    list_remote_unlink( tgt_cxy , &tgt_ptr->alarm.list );
     193
     194    // update the alarm date and state
     195    hal_remote_s64( XPTR( tgt_cxy , &tgt_ptr->alarm.date   ) , new_date );
     196    hal_remote_s32( XPTR( tgt_cxy , &tgt_ptr->alarm.linked ) , true );
     197
     198    // register alarm in core list
     199    alarm_register( tgt_cxy , &tgt_ptr->alarm , core );
     200   
    102201    // release the lock
    103     busylock_release( lock );
    104 
    105 }  // end alarm_register()
    106 
    107 //////////////////////////////////////
    108 void alarm_start( cycle_t    date,
    109                   void     * func_ptr,
    110                   xptr_t     args_xp,
    111                   thread_t * thread )
    112 {
    113     // get pointer on alarm
    114     alarm_t * alarm = &thread->alarm;
    115 
    116     // initialize alarm descriptor
    117     alarm->date     = date;
    118     alarm->func_ptr = func_ptr;
    119     alarm->args_xp = args_xp;
    120    
    121     // register alarm in core list
    122     alarm_register( alarm , thread->core );
    123 
    124 }  // end alarm_start()
    125 
    126 /////////////////////////////////////
    127 void alarm_update( thread_t * thread,
    128                    cycle_t    new_date )
    129 {
    130     // get pointer on alarm
    131     alarm_t * alarm = &thread->alarm;
    132 
    133     // get pointer on core
    134     core_t   * core = thread->core;
    135 
    136     // get pointer on lock protecting the alarms list
    137     busylock_t   * lock = &core->alarms_lock;
    138 
    139     // unlink the alarm from the core list
    140     busylock_acquire( lock );
    141     list_unlink( &alarm->list );
    142     busylock_release( lock );
    143 
    144     // update the alarm date
    145     alarm->date = new_date;
    146 
    147     // register alarm in core list
    148     alarm_register( alarm , core );
    149    
     202    remote_busylock_release( lock_xp );
     203
    150204}  // end alarm_update()
    151205
    152 ////////////////////////////////////
    153 void alarm_stop( thread_t * thread )
    154 {
    155     // get pointer on alarm
    156     alarm_t * alarm = &thread->alarm;
    157 
    158     // get pointer on core
    159     core_t * core = thread->core;
    160 
    161     // get pointer on lock protecting the alarms list
    162     busylock_t * lock = &core->alarms_lock;
    163 
    164     // unlink the alarm from the list rooted in core
    165     busylock_acquire( lock );
    166     list_unlink( &alarm->list );
    167     busylock_release( lock );
    168 
    169 }  // end alarm_stop()
    170 
     206
Note: See TracChangeset for help on using the changeset viewer.