Ignore:
Timestamp:
Apr 10, 2019, 10:09:39 AM (5 years ago)
Author:
alain
Message:

Fix a bug in the vmm_remove_vseg() function: the physical pages
associated to an user DATA vseg were released to the kernel when
the target process descriptor was in the reference cluster.
This physical pages release should be done only when the page
forks counter value is zero.
All other modifications are cosmetic.

File:
1 edited

Legend:

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

    r619 r625  
    138138    uint32_t   server_lid;    // core running the server thread local index
    139139    xptr_t     lock_xp;       // extended pointer on lock protecting the chdev state
    140     uint32_t   save_sr;       // for critical section
    141140
    142141#if (DEBUG_SYS_READ & 1)
     
    177176uint32_t rx_cycle = (uint32_t)hal_get_cycles();
    178177if( (is_rx) && (DEBUG_CHDEV_CMD_RX < rx_cycle) )
    179 printk("\n[%s] client[%x,%x] enter for RX / server[%x,%x] / cycle %d\n",
     178printk("\n[%s] client thread[%x,%x] enter for RX / server[%x,%x] / cycle %d\n",
    180179__FUNCTION__, this->process->pid, this->trdid, server_pid, server_trdid, rx_cycle );
    181180#endif
     
    184183uint32_t tx_cycle = (uint32_t)hal_get_cycles();
    185184if( (is_rx == 0) && (DEBUG_CHDEV_CMD_TX < tx_cycle) )
    186 printk("\n[%s] client[%x,%x] enter for TX / server[%x,%x] / cycle %d\n",
     185printk("\n[%s] client thread[%x,%x] enter for TX / server[%x,%x] / cycle %d\n",
    187186__FUNCTION__, this->process->pid, this->trdid, server_pid, server_trdid, tx_cycle );
    188187#endif
     
    194193    xptr_t  root_xp    = XPTR( chdev_cxy , &chdev_ptr->wait_root );
    195194
    196     // build extended pointer on server thread blocked state
    197     xptr_t  blocked_xp = XPTR( chdev_cxy , &server_ptr->blocked );
    198 
    199195    // build extended pointer on lock protecting chdev waiting queue
    200196    lock_xp            = XPTR( chdev_cxy , &chdev_ptr->wait_lock );
    201197
    202     // TODO the hal_disable_irq() / hal_restore_irq()
    203     // in the sequence below is probably useless, as it is
    204     // already done by the busylock_acquire() / busylock_release()
    205     // => remove it [AG] october 2018
    206 
    207     // critical section for the following sequence:
     198    // The following actions execute in critical section,
     199    // because the lock_acquire / lock_release :
    208200    // (1) take the lock protecting the chdev state
    209     // (2) block the client thread
    210     // (3) unblock the server thread if required
    211     // (4) register client thread in server queue
    212     // (5) send IPI to force server scheduling
    213     // (6) release the lock protecting waiting queue
    214     // (7) deschedule
    215 
    216     // enter critical section
    217     hal_disable_irq( &save_sr );
    218 
    219     // take the lock protecting chdev queue
     201    // (2) register client thread in server queue
     202    // (3) unblock the server thread and block client thread
     203    // (4) send IPI to force server scheduling
     204    // (5) release the lock protecting waiting queue
     205
     206    // 1. take the lock protecting chdev queue
    220207    remote_busylock_acquire( lock_xp );
    221208
    222     // block current thread
    223     thread_block( XPTR( local_cxy , CURRENT_THREAD ) , THREAD_BLOCKED_IO );
    224 
    225 #if (DEBUG_CHDEV_CMD_TX & 1)
    226 if( (is_rx == 0) && (DEBUG_CHDEV_CMD_TX < tx_cycle) )
    227 printk("\n[%s] client thread[%x,%x] blocked\n",
    228 __FUNCTION__, this->process->pid, this->trdid );
    229 #endif
    230 
    231 #if (DEBUG_CHDEV_CMD_RX & 1)
    232 if( (is_rx) && (DEBUG_CHDEV_CMD_RX < rx_cycle) )
    233 printk("\n[%s] client thread[%x,%x] blocked\n",
    234 __FUNCTION__, this->process_pid, this->trdid );
    235 #endif
    236 
    237     // unblock server thread if required
    238     if( hal_remote_l32( blocked_xp ) & THREAD_BLOCKED_IDLE )
    239     thread_unblock( server_xp , THREAD_BLOCKED_IDLE );
    240 
    241 #if (DEBUG_CHDEV_CMD_TX & 1)
    242 if( (is_rx == 0) && (DEBUG_CHDEV_CMD_TX < tx_cycle) )
    243 printk("\n[%s] TX server thread[%x,%x] unblocked\n",
    244 __FUNCTION__, server_pid, server_trdid );
    245 #endif
    246 
    247 #if (DEBUG_CHDEV_CMD_RX & 1)
    248 if( (is_rx) && (DEBUG_CHDEV_CMD_RX < rx_cycle) )
    249 printk("\n[%s] RX server thread[%x,%x] unblocked\n",
    250 __FUNCTION__, server_pid, server_trdid );
    251 #endif
    252 
    253     // register client thread in waiting queue
     209    // 2. register client thread in waiting queue
    254210    xlist_add_last( root_xp , list_xp );
    255211
     
    266222#endif
    267223 
    268     // send IPI to core running the server thread when server core != client core
     224    // 3. client thread unblocks server thread and blocks itself
     225    thread_unblock( server_xp , THREAD_BLOCKED_IDLE );
     226    thread_block( XPTR( local_cxy , CURRENT_THREAD ) , THREAD_BLOCKED_IO );
     227
     228#if (DEBUG_CHDEV_CMD_TX & 1)
     229if( (is_rx == 0) && (DEBUG_CHDEV_CMD_TX < tx_cycle) )
     230printk("\n[%s] client thread[%x,%x] unblock server thread[%x,%x] and block itsef\n",
     231__FUNCTION__, this->process->pid, this->trdid, server_pid, server_trdid );
     232#endif
     233
     234#if (DEBUG_CHDEV_CMD_RX & 1)
     235if( (is_rx) && (DEBUG_CHDEV_CMD_RX < rx_cycle) )
     236printk("\n[%s] client thread[%x,%x] unblock server thread[%x,%x] and block itsef\n",
     237__FUNCTION__, this->process->pid, this->trdid, server_pid, server_trdid );
     238#endif
     239
     240    // 4. send IPI to core running the server thread when server core != client core
    269241    if( (server_lid != this->core->lid) || (local_cxy != chdev_cxy) )
    270242    {
     
    285257    }
    286258 
    287     // release lock protecting chdev queue
     259    // 5. release lock protecting chdev queue
    288260    remote_busylock_release( lock_xp );
    289261
    290262    // deschedule
    291263    sched_yield("blocked on I/O");
    292 
    293     // exit critical section
    294     hal_restore_irq( save_sr );
    295264
    296265#if DEBUG_CHDEV_CMD_RX
    297266rx_cycle = (uint32_t)hal_get_cycles();
    298267if( (is_rx) && (DEBUG_CHDEV_CMD_RX < rx_cycle) )
    299 printk("\n[%s] client_thread[%x,%x] exit for RX / cycle %d\n",
     268printk("\n[%s] client thread[%x,%x] exit for RX / cycle %d\n",
    300269__FUNCTION__, this->process->pid, this->trdid, rx_cycle );
    301270#endif
     
    304273tx_cycle = (uint32_t)hal_get_cycles();
    305274if( (is_rx == 0) && (DEBUG_CHDEV_CMD_TX < tx_cycle) )
    306 printk("\n[%s] client_thread[%x,%x] exit for TX / cycle %d\n",
     275printk("\n[%s] client thread[%x,%x] exit for TX / cycle %d\n",
    307276__FUNCTION__, this->process->pid, this->trdid, tx_cycle );
    308277#endif
     
    344313uint32_t rx_cycle = (uint32_t)hal_get_cycles();
    345314if( (chdev->is_rx) && (DEBUG_CHDEV_SERVER_RX < rx_cycle) )
    346 printk("\n[%s] DEV thread[%x,%x] check TXT_RX channel %d / cycle %d\n",
     315printk("\n[%s] server thread[%x,%x] check TXT_RX channel %d / cycle %d\n",
    347316__FUNCTION__ , server->process->pid, server->trdid, chdev->channel, rx_cycle );
    348317#endif
     
    370339rx_cycle = (uint32_t)hal_get_cycles();
    371340if( (chdev->is_rx) && (DEBUG_CHDEV_SERVER_RX < rx_cycle) )
    372 printk("\n[%s] thread[%x,%x] found RX queue empty => blocks / cycle %d\n",
     341printk("\n[%s] server thread[%x,%x] found RX queue empty => blocks / cycle %d\n",
    373342__FUNCTION__ , server->process->pid, server->trdid, rx_cycle );
    374343#endif
     
    377346tx_cycle = (uint32_t)hal_get_cycles();
    378347if( (chdev->is_rx == 0) && (DEBUG_CHDEV_SERVER_TX < tx_cycle) )
    379 printk("\n[%s] thread[%x,%x] found TX queue empty => blocks / cycle %d\n",
     348printk("\n[%s] server thread[%x,%x] found TX queue empty => blocks / cycle %d\n",
    380349__FUNCTION__ , server->process->pid, server->trdid, tx_cycle );
    381350#endif
     
    407376rx_cycle = (uint32_t)hal_get_cycles();
    408377if( (chdev->is_rx) && (DEBUG_CHDEV_SERVER_RX < rx_cycle) )
    409 printk("\n[%s] thread[%x,%x] for RX get client thread[%x,%x] / cycle %d\n",
     378printk("\n[%s] server thread[%x,%x] get command from client thread[%x,%x] / cycle %d\n",
    410379__FUNCTION__, server->process->pid, server->trdid, client_pid, client_trdid, rx_cycle );
    411380#endif
     
    414383tx_cycle = (uint32_t)hal_get_cycles();
    415384if( (chdev->is_rx == 0) && (DEBUG_CHDEV_SERVER_TX < tx_cycle) )
    416 printk("\n[%s] thread[%x,%x] for TX get client thread[%x,%x] / cycle %d\n",
     385printk("\n[%s] server thread[%x,%x] get command from client thread[%x,%x] / cycle %d\n",
    417386__FUNCTION__, server->process->pid, server->trdid, client_pid, client_trdid, tx_cycle );
    418387#endif
     
    445414rx_cycle = (uint32_t)hal_get_cycles();
    446415if( (chdev->is_rx) && (DEBUG_CHDEV_SERVER_RX < rx_cycle) )
    447 printk("\n[%s] thread[%x,%x] completes RX for client thread[%x,%x] / cycle %d\n",
     416printk("\n[%s] thread[%x,%x] completes command for client thread[%x,%x] / cycle %d\n",
    448417__FUNCTION__, server->process->pid, server->trdid, client_pid, client_trdid, rx_cycle );
    449418#endif
     
    452421tx_cycle = (uint32_t)hal_get_cycles();
    453422if( (chdev->is_rx == 0) && (DEBUG_CHDEV_SERVER_TX < tx_cycle) )
    454 printk("\n[%s] thread[%x,%x] completes TX for client thread[%x,%x] / cycle %d\n",
     423printk("\n[%s] thread[%x,%x] completes command for client thread[%x,%x] / cycle %d\n",
    455424__FUNCTION__, server->process->pid, server->trdid, client_pid, client_trdid, tX_cycle );
    456425#endif
Note: See TracChangeset for help on using the changeset viewer.