Ignore:
Timestamp:
Jan 13, 2021, 12:36:17 AM (4 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/core.c

    r669 r683  
    33 *
    44 * Author  Ghassan Almaless (2008,2009,2010,2011,2012)
    5  *         Alain Greiner (2016,2017,2018)
     5 *         Alain Greiner    (2016,2017,2018,2019,2020)
    66 *
    77 * Copyright (c) UPMC Sorbonne Universites
     
    4747        core->ticks_nr          = 0;
    4848        core->usage             = 0;
    49         core->spurious_irqs     = 0;
    5049        core->fpu_owner         = NULL;
    5150        core->rand_last         = hal_time_stamp() & 0xFFF;
     
    5554
    5655    // initialise the alarms lock
    57     busylock_init( &core->alarms_lock , LOCK_CORE_ALARMS );
     56    remote_busylock_init( XPTR( local_cxy , &core->alarms_lock ) , LOCK_CORE_ALARMS );
    5857
    5958    // initialise the alarms list
     
    6160}
    6261
    63 ///////////////////////////////////////
    64 void core_check_alarms( core_t * core )
     62////////////////////////////////////////////////////////////////////////////////////
     63// This static function checks the alarms registered in the core, and calls the
     64// relevant alarm handler for all alarms whose time is elapded.
     65// It does not take the lock protecting the alarm list, because it access only
     66// the first alarm in the list, and all modifications in he list are done
     67// the low level access functions called by the handler(s).
     68////////////////////////////////////////////////////////////////////////////////////
     69static void core_check_alarms( core_t * core )
    6570{
    6671    alarm_handler_t * handler;
     
    7277    if( list_is_empty( root ) ) return;
    7378
    74     // get pointer on first alarm when list non empty
    75     alarm_t * alarm = LIST_FIRST( root , alarm_t , list );
    76 
    77     // get first alarm date
    78     cycle_t alarm_date = alarm->date;
    79 
    80     // get current date
    81     cycle_t current_date = hal_get_cycles();
    82 
    83     if( current_date >= alarm_date )
     79    while( 1 )
    8480    {
    85         // get pointer on registered alarm handler
    86         handler = (alarm_handler_t *)alarm->func_ptr;
    87 
    88         // call alarm handler
    89         handler( alarm->args_xp );
     81        // get pointer on first alarm
     82        alarm_t * alarm = LIST_FIRST( root , alarm_t , list );
     83
     84        // get first alarm date
     85        cycle_t alarm_date = alarm->date;
     86
     87        // get current date
     88        cycle_t current_date = hal_get_cycles();
     89
     90        // call handler if delay elapsed, and retry
     91        if( current_date >= alarm_date )
     92        {
     93            // get pointer on registered alarm handler
     94            handler = (alarm_handler_t *)alarm->func_ptr;
     95
     96            // call alarm handler
     97            handler( alarm->args_xp );
     98        }
     99        else   // exit loop when first alarm delay not elapsed
     100        {
     101            break;
     102        }
    90103    }
    91104}   // end core_check_alarms()
     
    127140                    uint32_t * tm_us )
    128141{
    129         *tm_s  = (core->ticks_nr*CONFIG_SCHED_TICK_MS_PERIOD)/1000;
    130         *tm_us = (core->ticks_nr*CONFIG_SCHED_TICK_MS_PERIOD*1000)%1000000;
     142    // get number of cycles
     143    uint64_t cycles = core->cycles;
     144
     145    // get number of cycles per second
     146    uint32_t cycles_per_second = LOCAL_CLUSTER->sys_clk;
     147
     148    *tm_s  = cycles / cycles_per_second;
     149    *tm_us = (cycles * 1000000) % cycles_per_second;
    131150}
    132151
     
    139158        ticks = core->ticks_nr++;
    140159
     160    // handle alarms
     161    core_check_alarms( core );
     162
    141163        // handle scheduler
    142164        if( (ticks % CONFIG_SCHED_TICKS_PER_QUANTUM) == 0 ) sched_yield( "TICK");
    143 
    144     // handle alarms
    145     core_check_alarms( core );
    146165}
    147166
Note: See TracChangeset for help on using the changeset viewer.