Ignore:
Timestamp:
Dec 5, 2017, 4:20:07 PM (7 years ago)
Author:
alain
Message:

Fix several bugs in the fork() syscall.

File:
1 edited

Legend:

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

    r407 r408  
    120120    uint32_t   lid;           // core running the server thread local index
    121121    xptr_t     lock_xp;       // extended pointer on lock protecting the chdev queue
    122     uint32_t   modified;      // non zero if the server thread state was modified
     122    uint32_t   different;     // non zero if server thread core != client thread core
    123123    uint32_t   save_sr;       // for critical section
    124124
     
    152152    lid = hal_remote_lw( XPTR( chdev_cxy , &core_ptr->lid ) );
    153153
    154     // enter critical section
     154    // compute server core != thread core
     155    different = (lid != this->core->lid) || (local_cxy != chdev_cxy);
     156
     157    // enter critical section to make atomic :
     158    // (1) client blocking
     159    // (2) client registration in server queue
     160    // (3) IPI to force server scheduling
     161    // (4) descheduling
     162    // ... in this order
    155163    hal_disable_irq( &save_sr );
     164
     165    // block current thread
     166    thread_block( CURRENT_THREAD , THREAD_BLOCKED_IO );
    156167
    157168    // register client thread in waiting queue
     
    160171    remote_spinlock_unlock( lock_xp );
    161172
    162     // unblock server thread
    163     modified = thread_unblock( XPTR( chdev_cxy , server_ptr ), THREAD_BLOCKED_DEV_QUEUE );
    164 
    165     // send IPI to core running the server thread
    166     if( modified ) dev_pic_send_ipi( chdev_cxy , lid );
     173    // send IPI to core running the server thread if required
     174    if( different ) dev_pic_send_ipi( chdev_cxy , lid );
    167175   
    168     // block client thread
    169     assert( thread_can_yield( this ) , __FUNCTION__ , "illegal sched_yield\n" );
    170 
    171176chdev_dmsg("\n[DBG] %s : core[%x,%d] (thread %s) deschedules / cycle %d\n",
    172177__FUNCTION__, local_cxy, this->core->lid, thread_type_str(this->type) , hal_time_stamp() );
    173178
    174     thread_block( CURRENT_THREAD , THREAD_BLOCKED_IO );
    175     sched_yield();
     179    // deschedule
     180    assert( thread_can_yield( this ) , __FUNCTION__ , "illegal sched_yield\n" );
     181    sched_yield("blocked on I/O");
    176182
    177183chdev_dmsg("\n[DBG] %s : core[%x,%d] (thread %s) resumes / cycle %d\n",
     
    217223__FUNCTION__ , server , hal_time_stamp() );
    218224
    219             // block and deschedule
    220             thread_block( server , THREAD_BLOCKED_DEV_QUEUE );
    221             sched_yield();
     225            // deschedule
     226            sched_yield("I/O queue empty");
    222227
    223228chdev_dmsg("\n[DBG] %s : thread %x resume /cycle %d\n",
Note: See TracChangeset for help on using the changeset viewer.