Ignore:
Timestamp:
Nov 7, 2017, 3:08:12 PM (6 years ago)
Author:
alain
Message:

First implementation of fork/exec.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/kernel/libk/remote_fifo.c

    r296 r407  
    3939    uint32_t  slot;
    4040
     41    fifo->owner     = 0;
    4142        fifo->wr_id     = 0;
    4243        fifo->rd_id     = 0;
     
    4748}
    4849
    49 //////////////////////////////////////////////
    50 error_t remote_fifo_put_item( xptr_t     fifo,
    51                               uint64_t   item,
    52                               bool_t   * first )
     50/////////////////////////////////////////////////
     51error_t remote_fifo_put_item( xptr_t     fifo_xp,
     52                              uint64_t   item )
    5353{
    5454    uint32_t        wr_id;
     
    5656    uint32_t        ptw;
    5757    uint32_t        watchdog;
    58     reg_t           save_sr;
    5958    uint32_t        nslots;
    6059
    6160    // get remote cluster identifier and pointer on FIFO
    62     cxy_t           cxy = (cxy_t)GET_CXY( fifo );
    63     remote_fifo_t * ptr = (remote_fifo_t *)GET_PTR( fifo );
     61    cxy_t           fifo_cxy = (cxy_t)GET_CXY( fifo_xp );
     62    remote_fifo_t * fifo_ptr = (remote_fifo_t *)GET_PTR( fifo_xp );
    6463
    6564    // initialise watchdog for contention detection
    6665    watchdog = 0;
    6766
    68     // no descheduling during put access
    69         hal_disable_irq( &save_sr );
    70        
    71     // get write slot index and atomic increment
    72         wr_id = hal_remote_atomic_add( XPTR( cxy , &ptr->wr_id ) , 1 );
     67    // get write slot index with atomic increment
     68        wr_id = hal_remote_atomic_add( XPTR( fifo_cxy , &fifo_ptr->wr_id ) , 1 );
    7369
    74     // check fifo state
     70    // wait until allocated slot is empty in remote FIFO
     71    // max retry = CONFIG_REMOTE_FIFO_MAX_ITERATIONS 
     72    // return error if watchdog is reached
    7573    while( 1 )
    7674    {
    7775        // return error if contention detected by watchdog
    78         if( watchdog > CONFIG_REMOTE_FIFO_MAX_ITERATIONS )
    79         {
    80             // restore scheduling
    81                 hal_restore_irq( save_sr );
    82 
    83             // return error
    84             return EBUSY;
    85         }
     76        if( watchdog > CONFIG_REMOTE_FIFO_MAX_ITERATIONS )  return EBUSY;
    8677
    8778        // read remote rd_id value
    88         rd_id = hal_remote_lw( XPTR( cxy , &ptr->rd_id ) );
     79        rd_id = hal_remote_lw( XPTR( fifo_cxy , &fifo_ptr->rd_id ) );
    8980
    9081        // compute number of full slots
     
    9283        else                 nslots = (0xFFFFFFFF - rd_id) + wr_id;
    9384
    94         // exit if fifo not full
     85        // exit waiting loop as soon as fifo not full
    9586        if ( nslots < CONFIG_REMOTE_FIFO_SLOTS )  break;
    9687       
    97         // restore interrupts
    98             hal_restore_irq( save_sr );
    99 
    100         // deschedule without blocking
    101         if( thread_can_yield() ) sched_yield( NULL );
    102 
    103         // disable interrupts
    104             hal_disable_irq( &save_sr );
     88        // retry later if fifo full:
     89        // - deschedule without blocking if possible
     90        // - wait ~1000 cycles otherwise
     91        if( thread_can_yield() ) sched_yield();
     92        else                     hal_fixed_delay( 1000 );
    10593
    10694        // increment watchdog
     
    112100
    113101    // copy item to fifo
    114         hal_remote_swd( XPTR( cxy , &ptr->data[ptw] ), item );
    115 
     102        hal_remote_swd( XPTR( fifo_cxy , &fifo_ptr->data[ptw] ), item );
    116103        hal_fence();
    117104
    118105    // set the slot valid flag
    119         hal_remote_sw( XPTR( cxy , &ptr->valid[ptw] ) , 1 );
     106        hal_remote_sw( XPTR( fifo_cxy , &fifo_ptr->valid[ptw] ) , 1 );
    120107        hal_fence();
    121 
    122     // return the first RPC flag
    123     *first = ( wr_id == rd_id );
    124    
    125     // restore scheduling
    126         hal_restore_irq( save_sr );
    127108
    128109    return 0;
Note: See TracChangeset for help on using the changeset viewer.