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/thread.c

    r669 r683  
    33 *
    44 * Author  Ghassan Almaless (2008,2009,2010,2011,2012)
    5  *         Alain Greiner (2016,2017,2018,2019,2020)
     5 *         Alain Greiner    (2016,2017,2018,2019,2020)
    66 *
    77 * Copyright (c) UPMC Sorbonne Universites
     
    6767  }
    6868}
    69 
    70 /////////////////////////////////////////////////////////////////////////////////////
    71 // This static function allocates physical memory for a thread descriptor.
    72 // It can be called by the three functions:
    73 // - thread_user_create()
    74 // - thread_user_fork()
    75 // - thread_kernel_create()
    76 /////////////////////////////////////////////////////////////////////////////////////
    77 // @ return pointer on thread descriptor if success / return NULL if failure.
    78 /////////////////////////////////////////////////////////////////////////////////////
    79 static thread_t * thread_alloc( void )
    80 {
    81         kmem_req_t     req;    // kmem request
    82 
    83         // allocates memory for thread descriptor + kernel stack
    84         req.type  = KMEM_PPM;
    85         req.order = CONFIG_THREAD_DESC_ORDER;
    86         req.flags = AF_KERNEL | AF_ZERO;
    87 
    88     return kmem_alloc( &req );
    89 
    90 }  // end thread_alloc()
    91  
    9269
    9370/////////////////////////////////////////////////////////////////////////////////////
     
    144121
    145122#if DEBUG_BUSYLOCK
    146     xlist_root_init( XPTR( local_cxy , &thread->busylocks_root ) );
     123xlist_root_init( XPTR( local_cxy , &thread->busylocks_root ) );
    147124#endif
    148125
     
    161138    list_entry_init( &thread->sched_list );
    162139
    163     // initialize the embedded alarm to unlink
     140    // initialize the embedded alarm
    164141    list_entry_init( &thread->alarm.list );
    165142
     
    187164    dqdt_increment_threads();
    188165
     166    // nitialize timer alarm
     167    alarm_init( &thread->alarm );
     168
    189169#if CONFIG_INSTRUMENTATION_PGFAULTS
    190     thread->info.false_pgfault_nr    = 0;
    191     thread->info.false_pgfault_cost  = 0;
    192     thread->info.false_pgfault_max   = 0;
    193     thread->info.local_pgfault_nr    = 0;
    194     thread->info.local_pgfault_cost  = 0;
    195     thread->info.local_pgfault_max   = 0;
    196     thread->info.global_pgfault_nr   = 0;
    197     thread->info.global_pgfault_cost = 0;
    198     thread->info.global_pgfault_max  = 0;
     170thread->info.false_pgfault_nr    = 0;
     171thread->info.false_pgfault_cost  = 0;
     172thread->info.false_pgfault_max   = 0;
     173thread->info.local_pgfault_nr    = 0;
     174thread->info.local_pgfault_cost  = 0;
     175thread->info.local_pgfault_max   = 0;
     176thread->info.global_pgfault_nr   = 0;
     177thread->info.global_pgfault_cost = 0;
     178thread->info.global_pgfault_max  = 0;
    199179#endif
    200180
     
    273253
    274254    // allocate memory for thread descriptor
    275     thread = thread_alloc();
     255    thread = kmem_alloc( CONFIG_THREAD_DESC_ORDER , AF_ZERO );
    276256
    277257    if( thread == NULL )
     
    467447
    468448    // allocate memory for child thread descriptor
    469     child_ptr = thread_alloc();
     449    child_ptr = kmem_alloc( CONFIG_THREAD_DESC_ORDER , AF_ZERO );
    470450
    471451    if( child_ptr == NULL )
     
    677657uint32_t cycle = (uint32_t)hal_get_cycles();
    678658if( DEBUG_THREAD_USER_EXEC < cycle )
    679 printk("\n[%s] thread[%x,%x] enter / cycle %d\n",
    680 __FUNCTION__, process->pid, thread->trdid, cycle );
     659printk("\n[%s] thread[%x,%x] enter / argc %d / argv %x / cycle %d\n",
     660__FUNCTION__, process->pid, thread->trdid, argc, argv, cycle );
    681661#endif
    682662
     
    727707#endif
    728708
    729     // restore CPU registers ... and jump to user code
     709    // restore CPU registers => jump to user code
    730710    hal_do_cpu_restore( thread->cpu_context );
    731711
     
    759739
    760740    // allocate memory for new thread descriptor
    761     thread = thread_alloc();
     741    thread = kmem_alloc( CONFIG_THREAD_DESC_ORDER , AF_ZERO );
    762742
    763743    if( thread == NULL )
     
    839819
    840820// check arguments
    841 assert( __FUNCTION__, (type == THREAD_IDLE) , "illegal thread type" );
    842 assert( __FUNCTION__, (core_lid < LOCAL_CLUSTER->cores_nr) , "illegal core index" );
     821assert( __FUNCTION__, (type == THREAD_IDLE),
     822"illegal thread type" );
     823
     824assert( __FUNCTION__, (core_lid < LOCAL_CLUSTER->cores_nr),
     825"illegal core index" );
    843826
    844827    // set type in thread descriptor
     
    848831    error = process_register_thread( &process_zero , thread , &trdid );
    849832
    850 assert( __FUNCTION__, (error == 0), "cannot register idle_thread in kernel process" );
     833assert( __FUNCTION__, (error == 0),
     834"cannot register idle_thread in kernel process" );
    851835
    852836    // set trdid in thread descriptor
     
    863847                         NULL );   // no user stack for a kernel thread
    864848
    865 assert( __FUNCTION__, (error == 0), "cannot initialize idle_thread" );
     849assert( __FUNCTION__, (error == 0),
     850"cannot initialize idle_thread" );
    866851
    867852    // allocate CPU context
    868853    error = hal_cpu_context_alloc( thread );
    869854
    870 assert( __FUNCTION__, (error == 0), "cannot allocate CPU context" );
     855assert( __FUNCTION__,(error == 0),
     856"cannot allocate CPU context" );
    871857
    872858    // initialize CPU context
     
    963949
    964950    // release memory for thread descriptor (including kernel stack)
    965     kmem_req_t   req;
    966     req.type  = KMEM_PPM;
    967     req.ptr   = thread;
    968     kmem_free( &req );
     951    kmem_free( thread , CONFIG_THREAD_DESC_ORDER );
    969952
    970953#if DEBUG_THREAD_DESTROY
     
    10911074}  // end thread_unblock()
    10921075
    1093 //////////////////////////////////////
     1076//////////////////////////////////////////////
    10941077void thread_delete_request( xptr_t  target_xp,
    1095                     bool_t  is_forced )
     1078                            bool_t  is_forced )
    10961079{
    10971080    reg_t       save_sr;                // for critical section
     
    14751458        thread->busylocks - 1, (uint32_t)hal_get_cycles() );
    14761459
    1477 #if DEBUG_BUSYLOCK
     1460#if DEBUG_BUSYLOCK_TYPE
    14781461
    14791462// scan list of busylocks
Note: See TracChangeset for help on using the changeset viewer.