Changeset ae66348 for libcfa/src


Ignore:
Timestamp:
Mar 24, 2020, 1:39:31 PM (4 years ago)
Author:
Thierry Delisle <tdelisle@…>
Branches:
ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum
Children:
c72ea7a, f100a83
Parents:
210b8b3
Message:

Threads in debug now keep track of last function to park/unpark it

Location:
libcfa/src
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • libcfa/src/bits/debug.hfa

    r210b8b3 rae66348  
    2323        #define __cfaabi_dbg_ctx_param const char caller[]
    2424        #define __cfaabi_dbg_ctx_param2 , const char caller[]
     25        #define __cfaabi_dbg_ctx_fwd caller
     26        #define __cfaabi_dbg_ctx_fwd2 , caller
    2527#else
    2628        #define __cfaabi_dbg_debug_do(...)
     
    3032        #define __cfaabi_dbg_ctx_param
    3133        #define __cfaabi_dbg_ctx_param2
     34        #define __cfaabi_dbg_ctx_fwd
     35        #define __cfaabi_dbg_ctx_fwd2
    3236#endif
    3337
  • libcfa/src/bits/locks.hfa

    r210b8b3 rae66348  
    5454
    5555                #ifdef __CFA_DEBUG__
    56                         void __cfaabi_dbg_record(__spinlock_t & this, const char prev_name[]);
     56                        void __cfaabi_dbg_record_lock(__spinlock_t & this, const char prev_name[]);
    5757                #else
    58                         #define __cfaabi_dbg_record(x, y)
     58                        #define __cfaabi_dbg_record_lock(x, y)
    5959                #endif
    6060        }
     
    6969                bool result = (this.lock == 0) && (__atomic_test_and_set( &this.lock, __ATOMIC_ACQUIRE ) == 0);
    7070                if( result ) {
    71                         __cfaabi_dbg_record( this, caller );
     71                        __cfaabi_dbg_record_lock( this, caller );
    7272                } else {
    7373                        enable_interrupts_noPoll();
     
    9999                        #endif
    100100                }
    101                 __cfaabi_dbg_record( this, caller );
     101                __cfaabi_dbg_record_lock( this, caller );
    102102        }
    103103
  • libcfa/src/concurrency/invoke.h

    r210b8b3 rae66348  
    198198                        struct $thread * prev;
    199199                } node;
    200         };
     200
     201                #ifdef __CFA_DEBUG__
     202                        // previous function to park/unpark the thread
     203                        const char * prev_park;
     204                        bool park_stale;
     205                        const char * prev_unpark;
     206                        bool unpark_stale;
     207                #endif
     208        };
     209
     210        #ifdef __CFA_DEBUG__
     211                void __cfaabi_dbg_record_thrd($thread & this, bool park, const char prev_name[]);
     212        #else
     213                #define __cfaabi_dbg_record_thrd(x, y, z)
     214        #endif
    201215
    202216        #ifdef __cforall
  • libcfa/src/concurrency/kernel.cfa

    r210b8b3 rae66348  
    343343                }
    344344
     345                __cfaabi_dbg_debug_do(
     346                        thrd_dst->park_stale = true;
     347                        thrd_dst->park_stale = false;
     348                )
     349
    345350                /* paranoid */ verify( ! kernelTLS.preemption_state.enabled );
    346351                /* paranoid */ verifyf( ((uintptr_t)thrd_dst->context.SP) < ((uintptr_t)__get_stack(thrd_dst->curr_cor)->base ) || thrd_dst->curr_cor == proc_cor, "ERROR : Destination $thread %p has been corrupted.\n StackPointer too small.\n", thrd_dst ); // add escape condition if we are setting up the processor
     
    381386
    382387                                // We may need to wake someone up here since
    383                                 unpark( this->destroyer );
     388                                unpark( this->destroyer __cfaabi_dbg_ctx2 );
    384389                                this->destroyer = 0p;
    385390                                break RUNNING;
     
    588593}
    589594
    590 void unpark( $thread * thrd ) {
     595void unpark( $thread * thrd __cfaabi_dbg_ctx_param2 ) {
    591596        if( !thrd ) return;
    592597
    593598        disable_interrupts();
    594599        static_assert(sizeof(thrd->state) == sizeof(int));
     600       
     601        // record activity
     602        __cfaabi_dbg_record_thrd( *thrd, false, caller );
     603
    595604        enum coroutine_state old_state = __atomic_exchange_n(&thrd->state, Rerun, __ATOMIC_SEQ_CST);
    596605        switch(old_state) {
     
    618627}
    619628
    620 void park( void ) {
     629void park( __cfaabi_dbg_ctx_param ) {
    621630        /* paranoid */ verify( kernelTLS.preemption_state.enabled );
    622631        disable_interrupts();
    623632        /* paranoid */ verify( ! kernelTLS.preemption_state.enabled );
    624633        /* paranoid */ verify( kernelTLS.this_thread->preempted == __NO_PREEMPTION );
     634
     635        // record activity
     636        __cfaabi_dbg_record_thrd( *kernelTLS.this_thread, true, caller );
    625637
    626638        returnToKernel();
     
    898910                // atomically release spin lock and block
    899911                unlock( lock );
    900                 park();
     912                park( __cfaabi_dbg_ctx );
    901913        }
    902914        else {
     
    917929
    918930        // make new owner
    919         unpark( thrd );
     931        unpark( thrd __cfaabi_dbg_ctx2 );
    920932}
    921933
     
    966978__cfaabi_dbg_debug_do(
    967979        extern "C" {
    968                 void __cfaabi_dbg_record(__spinlock_t & this, const char prev_name[]) {
     980                void __cfaabi_dbg_record_lock(__spinlock_t & this, const char prev_name[]) {
    969981                        this.prev_name = prev_name;
    970982                        this.prev_thrd = kernelTLS.this_thread;
     983                }
     984
     985                void __cfaabi_dbg_record_thrd($thread & this, bool park, const char prev_name[]) {
     986                        if(park) {
     987                                this.prev_park    = prev_name;
     988                                this.park_stale   = false;
     989                        }
     990                        else {
     991                                this.prev_unpark  = prev_name;
     992                                this.unpark_stale = false;
     993                        }
    971994                }
    972995        }
  • libcfa/src/concurrency/monitor.cfa

    r210b8b3 rae66348  
    119119
    120120                unlock( this->lock );
    121                 park();
     121                park( __cfaabi_dbg_ctx );
    122122
    123123                __cfaabi_dbg_print_safe( "Kernel : %10p Entered  mon %p\n", thrd, this);
     
    184184                // Release the next thread
    185185                /* paranoid */ verifyf( urgent->owner->waiting_thread == this->owner, "Expected owner to be %p, got %p (r: %i, m: %p)", kernelTLS.this_thread, this->owner, this->recursion, this );
    186                 unpark( urgent->owner->waiting_thread );
     186                unpark( urgent->owner->waiting_thread __cfaabi_dbg_ctx2 );
    187187
    188188                // Park current thread waiting
    189                 park();
     189                park( __cfaabi_dbg_ctx );
    190190
    191191                // Some one was waiting for us, enter
     
    205205
    206206                // Park current thread waiting
    207                 park();
     207                park( __cfaabi_dbg_ctx );
    208208
    209209                /* paranoid */ verifyf( kernelTLS.this_thread == this->owner, "Expected owner to be %p, got %p (r: %i, m: %p)", kernelTLS.this_thread, this->owner, this->recursion, this );
     
    247247        //We need to wake-up the thread
    248248        /* paranoid */ verifyf( !new_owner || new_owner == this->owner, "Expected owner to be %p, got %p (m: %p)", new_owner, this->owner, this );
    249         unpark( new_owner );
     249        unpark( new_owner __cfaabi_dbg_ctx2 );
    250250}
    251251
     
    460460        // Wake the threads
    461461        for(int i = 0; i < thread_count; i++) {
    462                 unpark( threads[i] );
     462                unpark( threads[i] __cfaabi_dbg_ctx2 );
    463463        }
    464464
    465465        // Everything is ready to go to sleep
    466         park();
     466        park( __cfaabi_dbg_ctx );
    467467
    468468        // We are back, restore the owners and recursions
     
    542542
    543543        // unpark the thread we signalled
    544         unpark( signallee );
     544        unpark( signallee __cfaabi_dbg_ctx2 );
    545545
    546546        //Everything is ready to go to sleep
    547         park();
     547        park( __cfaabi_dbg_ctx );
    548548
    549549
     
    646646
    647647                                // unpark the thread we signalled
    648                                 unpark( next );
     648                                unpark( next __cfaabi_dbg_ctx2 );
    649649
    650650                                //Everything is ready to go to sleep
    651                                 park();
     651                                park( __cfaabi_dbg_ctx );
    652652
    653653                                // We are back, restore the owners and recursions
     
    691691
    692692        //Everything is ready to go to sleep
    693         park();
     693        park( __cfaabi_dbg_ctx );
    694694
    695695
  • libcfa/src/concurrency/mutex.cfa

    r210b8b3 rae66348  
    4141                append( blocked_threads, kernelTLS.this_thread );
    4242                unlock( lock );
    43                 park();
     43                park( __cfaabi_dbg_ctx );
    4444        }
    4545        else {
     
    6464        this.is_locked = (this.blocked_threads != 0);
    6565        unpark(
    66                 pop_head( this.blocked_threads )
     66                pop_head( this.blocked_threads ) __cfaabi_dbg_ctx2
    6767        );
    6868        unlock( this.lock );
     
    9696                append( blocked_threads, kernelTLS.this_thread );
    9797                unlock( lock );
    98                 park();
     98                park( __cfaabi_dbg_ctx );
    9999        }
    100100}
     
    123123                owner = thrd;
    124124                recursion_count = (thrd ? 1 : 0);
    125                 unpark( thrd );
     125                unpark( thrd __cfaabi_dbg_ctx2 );
    126126        }
    127127        unlock( lock );
     
    141141        lock( lock __cfaabi_dbg_ctx2 );
    142142        unpark(
    143                 pop_head( this.blocked_threads )
     143                pop_head( this.blocked_threads ) __cfaabi_dbg_ctx2
    144144        );
    145145        unlock( lock );
     
    150150        while(this.blocked_threads) {
    151151                unpark(
    152                         pop_head( this.blocked_threads )
     152                        pop_head( this.blocked_threads ) __cfaabi_dbg_ctx2
    153153                );
    154154        }
     
    160160        append( this.blocked_threads, kernelTLS.this_thread );
    161161        unlock( this.lock );
    162         park();
     162        park( __cfaabi_dbg_ctx );
    163163}
    164164
     
    169169        unlock(l);
    170170        unlock(this.lock);
    171         park();
     171        park( __cfaabi_dbg_ctx );
    172172        lock(l);
    173173}
  • libcfa/src/concurrency/thread.hfa

    r210b8b3 rae66348  
    9292//----------
    9393// Park thread: block until corresponding call to unpark, won't block if unpark is already called
    94 void park( void );
     94void park( __cfaabi_dbg_ctx_param );
    9595
    9696//----------
    9797// Unpark a thread, if the thread is already blocked, schedule it
    9898//                  if the thread is not yet block, signal that it should rerun immediately
    99 void unpark( $thread * this );
     99void unpark( $thread * this __cfaabi_dbg_ctx_param2 );
    100100
    101101forall( dtype T | is_thread(T) )
    102 static inline void unpark( T & this ) { if(!&this) return; unpark( get_thread( this ) );}
     102static inline void unpark( T & this __cfaabi_dbg_ctx_param2 ) { if(!&this) return; unpark( get_thread( this ) __cfaabi_dbg_ctx_fwd2 );}
    103103
    104104//----------
  • libcfa/src/startup.cfa

    r210b8b3 rae66348  
    4141struct __spinlock_t;
    4242extern "C" {
    43         void __cfaabi_dbg_record(struct __spinlock_t & this, const char prev_name[]) __attribute__(( weak )) {}
     43        void __cfaabi_dbg_record_lock(struct __spinlock_t & this, const char prev_name[]) __attribute__(( weak )) {}
    4444}
    4545
Note: See TracChangeset for help on using the changeset viewer.