Changeset 469 for trunk/kernel/kern


Ignore:
Timestamp:
Aug 20, 2018, 1:04:16 PM (6 years ago)
Author:
alain
Message:

1) Introduce the libsemaphore library.
2) Introduce a small libmath library, required by the "fft" application..
3) Introduce the multithreaded "fft" application.
4) Fix a bad synchronisation bug in the Copy-On-Write mechanism.

Location:
trunk/kernel/kern
Files:
4 edited

Legend:

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

    r459 r469  
    407407
    408408        // call nolock_printk to print core, function_name, and cycle
    409         nolock_printk("\n[PANIC] on core[%x,%d] in %s at cycle %d : " ,
    410         local_cxy, CURRENT_THREAD->core->lid, function_name, (uint32_t)hal_get_cycles() );
     409        nolock_printk("\n[PANIC] in %s => core[%x,%d] blocked at cycle %d : " ,
     410        function_name, local_cxy, CURRENT_THREAD->core->lid, (uint32_t)hal_get_cycles() );
    411411
    412412        // call kernel_printf on TXT0, in busy waiting to print format
  • trunk/kernel/kern/process.c

    r459 r469  
    11631163    }
    11641164
    1165 #if DEBUG_PROCESS_MAKE_FORK
     1165#if( DEBUG_PROCESS_MAKE_FORK & 1 )
    11661166cycle = (uint32_t)hal_get_cycles();
    11671167if( DEBUG_PROCESS_MAKE_FORK < cycle )
     
    12401240    "main thread must have LTID == 0\n" );
    12411241
    1242 #if( DEBUG_PROCESS_MAKE_FORK & 1 )
     1242//#if( DEBUG_PROCESS_MAKE_FORK & 1 )
     1243#if DEBUG_PROCESS_MAKE_FORK
    12431244cycle = (uint32_t)hal_get_cycles();
    12441245if( DEBUG_PROCESS_MAKE_FORK < cycle )
    1245 printk("\n[DBG] %s : thread %x in process %x created main thread %x on core[%x,%d] / cycle %d\n",
    1246 __FUNCTION__, CURRENT_THREAD->trdid, CURRENT_THREAD->process->pid,
    1247 thread, local_cxy, thread->core->lid, cycle );
     1246printk("\n[DBG] %s : thread %x in process %x created main thread %x / cycle %d\n",
     1247__FUNCTION__, CURRENT_THREAD->trdid, CURRENT_THREAD->process->pid, thread, cycle );
    12481248#endif
    12491249
     
    13421342
    13431343#if (DEBUG_PROCESS_MAKE_EXEC & 1)
     1344cycle = (uint32_t)hal_get_cycles();
    13441345if( DEBUG_PROCESS_MAKE_EXEC < cycle )
    1345 printk("\n[DBG] %s : open file <%s>\n", __FUNCTION__, path );
     1346printk("\n[DBG] %s : thread %x in process %x opened file <%s> / cycle %d\n",
     1347__FUNCTION__, thread->trdid, pid, path, cycle );
    13461348#endif
    13471349
     
    13491351    process_sigaction( pid , DELETE_ALL_THREADS );
    13501352
     1353#if (DEBUG_PROCESS_MAKE_EXEC & 1)
     1354cycle = (uint32_t)hal_get_cycles();
     1355if( DEBUG_PROCESS_MAKE_EXEC < cycle )
     1356printk("\n[DBG] %s : thread %x in process %x deleted all threads / cycle %d\n",
     1357__FUNCTION__, thread->trdid, pid, cycle );
     1358#endif
     1359
    13511360    // reset local process VMM
    13521361    vmm_destroy( process );
     
    13551364cycle = (uint32_t)hal_get_cycles();
    13561365if( DEBUG_PROCESS_MAKE_EXEC < cycle )
    1357 printk("\n[DBG] %s : thread %x in process %x / reset VMM / cycle %d\n",
     1366printk("\n[DBG] %s : thread %x in process %x reset VMM / cycle %d\n",
    13581367__FUNCTION__, thread->trdid, pid, cycle );
    13591368#endif
     
    14001409    if( error )
    14011410    {
    1402         printk("\n[ERROR] in %s : cannot reset main thread for %s\n", __FUNCTION__ , path );
     1411        printk("\n[ERROR] in %s : cannot update main thread for %s\n", __FUNCTION__ , path );
    14031412        vfs_close( file_xp , file_id );
    14041413        // FIXME restore old process VMM
  • trunk/kernel/kern/scheduler.c

    r462 r469  
    6363    list_root_init( &sched->k_root );
    6464
     65    // init spinlock
     66    spinlock_init( &sched->lock );
     67
    6568    sched->req_ack_pending = false;             // no pending request
    6669    sched->trace           = false;             // context switches trace desactivated
  • trunk/kernel/kern/thread.c

    r457 r469  
    8686    // return pointer on new thread descriptor
    8787    xptr_t base_xp = ppm_page2base( XPTR(local_cxy , page ) );
    88     return (thread_t *)GET_PTR( base_xp );
     88    return GET_PTR( base_xp );
    8989
    9090}  // end thread_alloc()
     
    419419uint32_t cycle = (uint32_t)hal_get_cycles();
    420420if( DEBUG_THREAD_USER_FORK < cycle )
    421 printk("\n[DBG] %s : thread %x enter / child_process %x / cycle %d\n",
    422 __FUNCTION__, CURRENT_THREAD, child_process->pid, cycle );
     421printk("\n[DBG] %s : thread %x in process %x enter / child_process %x / cycle %d\n",
     422__FUNCTION__, CURRENT_THREAD->trdid, CURRENT_THREAD->process->pid, child_process->pid, cycle );
    423423#endif
    424424
     
    428428    // get cluster and local pointer on parent thread descriptor
    429429    parent_cxy = GET_CXY( parent_thread_xp );
    430     parent_ptr = (thread_t *)GET_PTR( parent_thread_xp );
     430    parent_ptr = GET_PTR( parent_thread_xp );
    431431
    432432    // get relevant fields from parent thread
     
    538538        if( mapped )
    539539        {
     540            // get pointers on the page descriptor
    540541            xptr_t   page_xp  = ppm_ppn2page( ppn );
    541542            cxy_t    page_cxy = GET_CXY( page_xp );
    542             page_t * page_ptr = (page_t *)GET_PTR( page_xp );
     543            page_t * page_ptr = GET_PTR( page_xp );
     544
     545            // get extended pointers on forks and lock fields
     546            xptr_t forks_xp = XPTR( page_cxy , &page_ptr->forks );
     547            xptr_t lock_xp  = XPTR( page_cxy , &page_ptr->lock );
     548
     549            // increment the forks counter
     550            remote_spinlock_lock( lock_xp ); 
    543551            hal_remote_atomic_add( XPTR( page_cxy , &page_ptr->forks ) , 1 );
     552            remote_spinlock_unlock( lock_xp ); 
    544553
    545554#if (DEBUG_THREAD_USER_FORK & 1)
    546555cycle = (uint32_t)hal_get_cycles();
    547556if( DEBUG_THREAD_USER_FORK < cycle )
    548 printk("\n[DBG] %s : thread %x copied stack PTE to child GPT : vpn %x\n",
    549 __FUNCTION__, CURRENT_THREAD, vpn );
     557printk("\n[DBG] %s : thread %x in process %x copied one PTE to child GPT : vpn %x / forks %d\n",
     558__FUNCTION__, CURRENT_THREAD->trdid, CURRENT_THREAD->process->pid, vpn,
     559hal_remote_lw( XPTR( page_cxy , &page_ptr->forks) ) );
    550560#endif
    551561
     
    561571cycle = (uint32_t)hal_get_cycles();
    562572if( DEBUG_THREAD_USER_FORK < cycle )
    563 printk("\n[DBG] %s : thread %x exit / child_process %x / child_thread %x / cycle %d\n",
    564 __FUNCTION__, CURRENT_THREAD, child_process->pid, child_ptr, cycle );
     573printk("\n[DBG] %s : thread %x in process %x exit / child_thread %x / cycle %d\n",
     574__FUNCTION__, CURRENT_THREAD->trdid, CURRENT_THREAD->process->pid, child_ptr, cycle );
    565575#endif
    566576
     
    631641    }
    632642
    633     // update user stack in stack descriptor
     643    // update user stack in thread descriptor
    634644    thread->u_stack_base = vseg->min;
    635645    thread->u_stack_size = vseg->max - vseg->min;
     
    11721182    {
    11731183        target_process_xp  = XLIST_ELEMENT( iter , process_t , local_list );
    1174         target_process_ptr = (process_t *)GET_PTR( target_process_xp );
     1184        target_process_ptr = GET_PTR( target_process_xp );
    11751185        target_process_pid = hal_remote_lw( XPTR( target_cxy , &target_process_ptr->pid ) );
    11761186        if( target_process_pid == pid )
Note: See TracChangeset for help on using the changeset viewer.