Ignore:
Timestamp:
May 16, 2018, 4:15:22 PM (4 years ago)
Author:
alain
Message:

Fix few bugs whike debugging the sort multi-thread application.

File:
1 edited

Legend:

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

    r440 r443  
    142142        cluster_t    * local_cluster = LOCAL_CLUSTER;
    143143
     144#if DEBUG_THREAD_USER_INIT
     145uint32_t cycle = (uint32_t)hal_get_cycles();
     146if( DEBUG_THREAD_USER_INIT < cycle )
     147printk("\n[DBG] %s : thread %x enter to init thread %x in process %x / cycle %d\n",
     148__FUNCTION__, CURRENT_THREAD, thread, process->pid , cycle );
     149#endif
     150
    144151    // register new thread in process descriptor, and get a TRDID
    145152    error = process_register_thread( process, thread , &trdid );
     
    196203        thread->signature = THREAD_SIGNATURE;
    197204
    198     // FIXME call hal_thread_init() function to initialise the save_sr field
     205    // FIXME define and call an architecture specific hal_thread_init()
     206    // function to initialise the save_sr field
    199207    thread->save_sr = 0xFF13;
    200208
     
    204212        // update DQDT
    205213    dqdt_update_threads( 1 );
     214
     215#if DEBUG_THREAD_USER_INIT
     216cycle = (uint32_t)hal_get_cycles();
     217if( DEBUG_THREAD_USER_INIT < cycle )
     218printk("\n[DBG] %s : thread %x exit  after init of thread %x in process %x / cycle %d\n",
     219__FUNCTION__, CURRENT_THREAD, thread, process->pid , cycle );
     220#endif
    206221
    207222        return 0;
     
    227242uint32_t cycle = (uint32_t)hal_get_cycles();
    228243if( DEBUG_THREAD_USER_CREATE < cycle )
    229 printk("\n[DBG] %s : thread %x enter / process %x / cycle %d\n",
    230 __FUNCTION__, CURRENT_THREAD, pid , cycle );
     244printk("\n[DBG] %s : thread %x enter for process %x in cluster %x / cycle %d\n",
     245__FUNCTION__, CURRENT_THREAD, pid , local_cxy , cycle );
    231246#endif
    232247
     
    240255        return ENOMEM;
    241256    }
     257
     258#if( DEBUG_THREAD_USER_CREATE & 1)
     259if( DEBUG_THREAD_USER_CREATE < cycle )
     260printk("\n[DBG] %s : process descriptor = %x for process %x in cluster %x\n",
     261__FUNCTION__, process , pid , local_cxy );
     262#endif
    242263
    243264    // select a target core in local cluster
     
    256277        core_lid = cluster_select_local_core();
    257278    }
     279
     280#if( DEBUG_THREAD_USER_CREATE & 1)
     281if( DEBUG_THREAD_USER_CREATE < cycle )
     282printk("\n[DBG] %s : core[%x,%d] selected\n",
     283__FUNCTION__, local_cxy , core_lid );
     284#endif
    258285
    259286    // allocate a stack from local VMM
     
    282309        return ENOMEM;
    283310    }
     311
     312#if( DEBUG_THREAD_USER_CREATE & 1)
     313if( DEBUG_THREAD_USER_CREATE < cycle )
     314printk("\n[DBG] %s : thread descriptor %x allocated\n",
     315__FUNCTION__, thread );
     316#endif
    284317
    285318    // initialize thread descriptor
     
    300333    }
    301334
     335#if( DEBUG_THREAD_USER_CREATE & 1)
     336if( DEBUG_THREAD_USER_CREATE < cycle )
     337printk("\n[DBG] %s : thread descriptor %x initialised / trdid = %x\n",
     338__FUNCTION__, thread , thread->trdid );
     339#endif
     340
    302341    // set DETACHED flag if required
    303342    if( attr->attributes & PT_ATTR_DETACH )
     
    327366cycle = (uint32_t)hal_get_cycles();
    328367if( DEBUG_THREAD_USER_CREATE < cycle )
    329 printk("\n[DBG] %s : thread %x exit / process %x / new_thread %x / core %d / cycle %d\n",
    330 __FUNCTION__, CURRENT_THREAD, pid, thread, core_lid, cycle );
     368printk("\n[DBG] %s : thread %x exit / new_thread %x in process %x / core %d / cycle %d\n",
     369__FUNCTION__, CURRENT_THREAD, thread->trdid , pid , core_lid, cycle );
    331370#endif
    332371
     
    602641// has been released, using a cache of mmap requests. [AG]
    603642///////////////////////////////////////////////////////////////////////////////////////
    604 void thread_destroy( thread_t * thread )
     643bool_t thread_destroy( thread_t * thread )
    605644{
    606645    reg_t        save_sr;
     646    bool_t       last_thread;
    607647
    608648    process_t  * process    = thread->process;
     
    616656#endif
    617657
    618     assert( (thread->local_locks == 0) , __FUNCTION__ , "all local locks not released" );
    619 
    620     assert( (thread->remote_locks == 0) , __FUNCTION__ , "all remote locks not released" );
     658    assert( (thread->local_locks == 0) , __FUNCTION__ ,
     659    "local lock not released for thread %x in process %x", thread->trdid, process->pid );
     660
     661    assert( (thread->remote_locks == 0) , __FUNCTION__ ,
     662    "remote lock not released for thread %x in process %x", thread->trdid, process->pid );
    621663
    622664    // update intrumentation values
     
    637679
    638680    // remove thread from process th_tbl[]
    639     process_remove_thread( thread );
     681    last_thread = process_remove_thread( thread );
    640682       
    641683    // update DQDT
     
    654696__FUNCTION__, CURRENT_THREAD, thread, process->pid, cycle );
    655697#endif
     698
     699    return last_thread;
    656700
    657701}   // end thread_destroy()
     
    10921136        hal_enable_irq( NULL );
    10931137
    1094         if( CONFIG_THREAD_IDLE_MODE_SLEEP ) // force core to low-power mode
     1138        // force core to low-power mode (optional)
     1139        if( CONFIG_THREAD_IDLE_MODE_SLEEP )
    10951140        {
    10961141
     
    11131158
    11141159        }
    1115         else                                // search a runable thread
    1116         {
    1117             sched_yield( "IDLE" );
    1118         }
     1160
     1161        // search a runable thread
     1162        sched_yield( "IDLE" );
    11191163    }
    11201164}  // end thread_idle()
Note: See TracChangeset for help on using the changeset viewer.