Changeset b227f68 for src/libcfa


Ignore:
Timestamp:
Jun 29, 2017, 11:59:09 AM (7 years ago)
Author:
Thierry Delisle <tdelisle@…>
Branches:
ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
Children:
b751c8e
Parents:
7bbba76
Message:

Commented some debug messages.
Monitors now yield when spinning.
Debug mode saves more information about previous locks and interrupts

Location:
src/libcfa/concurrency
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • src/libcfa/concurrency/alarm.c

    r7bbba76 rb227f68  
    3838        clock_gettime( CLOCK_REALTIME, &curr );
    3939        __cfa_time_t curr_time = ((__cfa_time_t)curr.tv_sec * TIMEGRAN) + curr.tv_nsec;
    40         LIB_DEBUG_PRINT_BUFFER_DECL( STDERR_FILENO, "Kernel : current time is %lu\n", curr_time );
     40        // LIB_DEBUG_PRINT_BUFFER_DECL( STDERR_FILENO, "Kernel : current time is %lu\n", curr_time );
    4141        return curr_time;
    4242}
    4343
    4444void __kernel_set_timer( __cfa_time_t alarm ) {
    45         LIB_DEBUG_PRINT_BUFFER_DECL( STDERR_FILENO, "Kernel : set timer to %lu\n", (__cfa_time_t)alarm );
     45        // LIB_DEBUG_PRINT_BUFFER_DECL( STDERR_FILENO, "Kernel : set timer to %lu\n", (__cfa_time_t)alarm );
    4646        itimerval val;
    4747        val.it_value.tv_sec = alarm / TIMEGRAN;                 // seconds
  • src/libcfa/concurrency/invoke.h

    r7bbba76 rb227f68  
    3232            volatile int lock;
    3333            #ifdef __CFA_DEBUG__
    34                   const char * prev;
     34                  const char * prev_name;
     35                  void* prev_thrd;
    3536            #endif
    3637      };
     
    101102#ifndef _INVOKE_PRIVATE_H_
    102103#define _INVOKE_PRIVATE_H_
    103      
     104
    104105      struct machine_context_t {
    105106            void *SP;
  • src/libcfa/concurrency/kernel

    r7bbba76 rb227f68  
    2828//-----------------------------------------------------------------------------
    2929// Locks
    30 bool try_lock( spinlock * DEBUG_CTX_PARAM2 );
    31 void lock    ( spinlock * DEBUG_CTX_PARAM2 );
    32 void unlock  ( spinlock * );
     30bool try_lock  ( spinlock * DEBUG_CTX_PARAM2 );
     31void lock      ( spinlock * DEBUG_CTX_PARAM2 );
     32void lock_yield( spinlock * DEBUG_CTX_PARAM2 );
     33void unlock    ( spinlock * );
    3334
    3435struct signal_once {
  • src/libcfa/concurrency/kernel.c

    r7bbba76 rb227f68  
    605605
    606606bool try_lock( spinlock * this DEBUG_CTX_PARAM2 ) {
    607         bool ret = this->lock == 0 && __sync_lock_test_and_set_4( &this->lock, 1 ) == 0;
    608         LIB_DEBUG_DO( this->prev = caller; )
    609         return ret;
     607        return this->lock == 0 && __sync_lock_test_and_set_4( &this->lock, 1 ) == 0;
    610608}
    611609
    612610void lock( spinlock * this DEBUG_CTX_PARAM2 ) {
    613611        for ( unsigned int i = 1;; i += 1 ) {
    614                 if ( this->lock == 0 && __sync_lock_test_and_set_4( &this->lock, 1 ) == 0 ) break;
    615         }
    616         LIB_DEBUG_DO( this->prev = caller; )
    617 }
     612                if ( this->lock == 0 && __sync_lock_test_and_set_4( &this->lock, 1 ) == 0 ) { break; }
     613        }
     614        LIB_DEBUG_DO(
     615                this->prev_name = caller;
     616                this->prev_thrd = this_thread;
     617        )
     618}
     619
     620void lock_yield( spinlock * this DEBUG_CTX_PARAM2 ) {
     621        for ( unsigned int i = 1;; i += 1 ) {
     622                if ( this->lock == 0 && __sync_lock_test_and_set_4( &this->lock, 1 ) == 0 ) { break; }
     623                yield();
     624        }
     625        LIB_DEBUG_DO(
     626                this->prev_name = caller;
     627                this->prev_thrd = this_thread;
     628        )
     629}
     630
    618631
    619632void unlock( spinlock * this ) {
  • src/libcfa/concurrency/monitor.c

    r7bbba76 rb227f68  
    4545extern "C" {
    4646        void __enter_monitor_desc( monitor_desc * this ) {
    47                 lock( &this->lock DEBUG_CTX2 );
     47                lock_yield( &this->lock DEBUG_CTX2 );
    4848                thread_desc * thrd = this_thread;
    4949
     
    7676        //      TODO
    7777        void __leave_monitor_desc( monitor_desc * this ) {
    78                 lock( &this->lock DEBUG_CTX2 );
     78                lock_yield( &this->lock DEBUG_CTX2 );
    7979
    8080                // LIB_DEBUG_PRINT_SAFE("%p Leaving %p (o: %p, r: %i). ", this_thread, this, this->owner, this->recursion);
     
    104104        void __leave_thread_monitor( thread_desc * thrd ) {
    105105                monitor_desc * this = &thrd->mon;
    106                 lock( &this->lock DEBUG_CTX2 );
     106                lock_yield( &this->lock DEBUG_CTX2 );
    107107
    108108                disable_interrupts();
     
    188188// Internal scheduling
    189189void wait( condition * this, uintptr_t user_info = 0 ) {
    190         LIB_DEBUG_PRINT_SAFE("Waiting\n");
     190        // LIB_DEBUG_PRINT_SAFE("Waiting\n");
    191191
    192192        brand_condition( this );
     
    201201        spinlock *   locks     [ count ];               //We need to pass-in an array of locks to BlockInternal
    202202
    203         LIB_DEBUG_PRINT_SAFE("count %i\n", count);
     203        // LIB_DEBUG_PRINT_SAFE("count %i\n", count);
    204204
    205205        __condition_node_t waiter = { (thread_desc*)this_thread, count, user_info };
     
    208208        for(int i = 0; i < count; i++) {
    209209                (&criteria[i]){ this->monitors[i], &waiter };
    210                 LIB_DEBUG_PRINT_SAFE( "Criterion %p\n", &criteria[i] );
     210                // LIB_DEBUG_PRINT_SAFE( "Criterion %p\n", &criteria[i] );
    211211        }
    212212
     
    230230        }
    231231
    232         LIB_DEBUG_PRINT_SAFE("Will unblock: ");
     232        // LIB_DEBUG_PRINT_SAFE("Will unblock: ");
    233233        for(int i = 0; i < thread_count; i++) {
    234                 LIB_DEBUG_PRINT_SAFE("%p ", threads[i]);
    235         }
    236         LIB_DEBUG_PRINT_SAFE("\n");
     234                // LIB_DEBUG_PRINT_SAFE("%p ", threads[i]);
     235        }
     236        // LIB_DEBUG_PRINT_SAFE("\n");
    237237
    238238        // Everything is ready to go to sleep
     
    251251bool signal( condition * this ) {
    252252        if( is_empty( this ) ) {
    253                 LIB_DEBUG_PRINT_SAFE("Nothing to signal\n");
     253                // LIB_DEBUG_PRINT_SAFE("Nothing to signal\n");
    254254                return false;
    255255        }
     
    277277        //Lock all the monitors
    278278        lock_all( this->monitors, NULL, count );
    279         LIB_DEBUG_PRINT_SAFE("Signalling");
     279        // LIB_DEBUG_PRINT_SAFE("Signalling");
    280280
    281281        //Pop the head of the waiting queue
     
    285285        for(int i = 0; i < count; i++) {
    286286                __condition_criterion_t * crit = &node->criteria[i];
    287                 LIB_DEBUG_PRINT_SAFE(" %p", crit->target);
     287                // LIB_DEBUG_PRINT_SAFE(" %p", crit->target);
    288288                assert( !crit->ready );
    289289                push( &crit->target->signal_stack, crit );
    290290        }
    291291
    292         LIB_DEBUG_PRINT_SAFE("\n");
     292        // LIB_DEBUG_PRINT_SAFE("\n");
    293293
    294294        //Release
     
    320320        for(int i = 0; i < count; i++) {
    321321                (&criteria[i]){ this->monitors[i], &waiter };
    322                 LIB_DEBUG_PRINT_SAFE( "Criterion %p\n", &criteria[i] );
     322                // LIB_DEBUG_PRINT_SAFE( "Criterion %p\n", &criteria[i] );
    323323                push( &criteria[i].target->signal_stack, &criteria[i] );
    324324        }
     
    422422static inline void lock_all( spinlock ** locks, unsigned short count ) {
    423423        for( int i = 0; i < count; i++ ) {
    424                 lock( locks[i] DEBUG_CTX2 );
     424                lock_yield( locks[i] DEBUG_CTX2 );
    425425        }
    426426}
     
    429429        for( int i = 0; i < count; i++ ) {
    430430                spinlock * l = &source[i]->lock;
    431                 lock( l DEBUG_CTX2 );
     431                lock_yield( l DEBUG_CTX2 );
    432432                if(locks) locks[i] = l;
    433433        }
     
    472472        for(    int i = 0; i < count; i++ ) {
    473473
    474                 LIB_DEBUG_PRINT_SAFE( "Checking %p for %p\n", &criteria[i], target );
     474                // LIB_DEBUG_PRINT_SAFE( "Checking %p for %p\n", &criteria[i], target );
    475475                if( &criteria[i] == target ) {
    476476                        criteria[i].ready = true;
    477                         LIB_DEBUG_PRINT_SAFE( "True\n" );
     477                        // LIB_DEBUG_PRINT_SAFE( "True\n" );
    478478                }
    479479
     
    481481        }
    482482
    483         LIB_DEBUG_PRINT_SAFE( "Runing %i\n", ready2run );
     483        // LIB_DEBUG_PRINT_SAFE( "Runing %i\n", ready2run );
    484484        return ready2run ? node->waiting_thread : NULL;
    485485}
     
    488488        thread_desc * thrd = this_thread;
    489489        if( !this->monitors ) {
    490                 LIB_DEBUG_PRINT_SAFE("Branding\n");
     490                // LIB_DEBUG_PRINT_SAFE("Branding\n");
    491491                assertf( thrd->current_monitors != NULL, "No current monitor to brand condition", thrd->current_monitors );
    492492                this->monitor_count = thrd->current_monitor_count;
  • src/libcfa/concurrency/preemption.c

    r7bbba76 rb227f68  
    158158//=============================================================================================
    159159
     160LIB_DEBUG_DO( static thread_local void * last_interrupt = 0; )
     161
    160162extern "C" {
    161163        void disable_interrupts() {
     
    187189
    188190static inline void signal_unblock( int sig ) {
    189         LIB_DEBUG_PRINT_BUFFER_DECL( STDERR_FILENO, "Processor : %p unblocking sig %i\n", this_processor, sig );
     191        // LIB_DEBUG_PRINT_BUFFER_DECL( STDERR_FILENO, "Processor : %p unblocking sig %i\n", this_processor, sig );
     192
     193        // LIB_DEBUG_DO(
     194        //      sigset_t waiting;
     195        //      sigemptyset(&waiting);
     196        //      sigpending(&waiting);
     197        //      verify( !sigismember(&waiting, sig) );
     198        // )
    190199
    191200        sigset_t mask;
     
    217226
    218227void sigHandler_ctxSwitch( __CFA_SIGPARMS__ ) {
    219         LIB_DEBUG_PRINT_BUFFER_DECL( STDERR_FILENO, "Ctx Switch IRH %p running %p @ %p\n", this_processor, this_thread, (void *)(cxt->uc_mcontext.gregs[REG_RIP]) );
     228        LIB_DEBUG_PRINT_BUFFER_DECL( STDERR_FILENO, "CtxSw IRH %10p running %10p @ %10p\n", this_processor, this_thread, (void *)(cxt->uc_mcontext.gregs[REG_RIP]) );
     229        LIB_DEBUG_DO( last_interrupt = (void *)(cxt->uc_mcontext.gregs[REG_RIP]); )
    220230
    221231        if( preemption_ready() ) {
    222                 LIB_DEBUG_PRINT_BUFFER_LOCAL( STDERR_FILENO, "Ctx Switch IRH : Blocking thread %p on %p\n", this_thread, this_processor );
     232                // LIB_DEBUG_PRINT_BUFFER_LOCAL( STDERR_FILENO, "Ctx Switch IRH : Blocking thread %p on %p\n", this_thread, this_processor );
    223233                signal_unblock( SIGUSR1 );
    224234                BlockInternal( (thread_desc*)this_thread );
    225                 LIB_DEBUG_PRINT_BUFFER_LOCAL( STDERR_FILENO, "Ctx Switch IRH : Back\n\n");
     235                // LIB_DEBUG_PRINT_BUFFER_LOCAL( STDERR_FILENO, "Ctx Switch IRH : Back\n\n");
    226236        }
    227237        else {
    228                 LIB_DEBUG_PRINT_BUFFER_LOCAL( STDERR_FILENO, "Ctx Switch IRH : Defering\n" );
     238                // LIB_DEBUG_PRINT_BUFFER_LOCAL( STDERR_FILENO, "Ctx Switch IRH : Defering\n" );
    229239                defer_ctxSwitch();
    230240                signal_unblock( SIGUSR1 );
     
    233243
    234244void sigHandler_alarm( __CFA_SIGPARMS__ ) {
    235         LIB_DEBUG_PRINT_BUFFER_DECL( STDERR_FILENO, "\nAlarm IRH %p running %p @ %p\n", this_processor, this_thread, (void *)(cxt->uc_mcontext.gregs[REG_RIP]) );
    236 
    237         // if( ((intptr_t)cxt->uc_mcontext.gregs[REG_RIP]) > 0xFFFFFF ) __debug_break();
     245        LIB_DEBUG_PRINT_BUFFER_DECL( STDERR_FILENO, "\nAlarm IRH %10p running %10p @ %10p\n", this_processor, this_thread, (void *)(cxt->uc_mcontext.gregs[REG_RIP]) );
     246        LIB_DEBUG_DO( last_interrupt = (void *)(cxt->uc_mcontext.gregs[REG_RIP]); )
    238247
    239248        if( try_lock( &systemProcessor->alarm_lock DEBUG_CTX2 ) ) {
     
    248257
    249258        if( preemption_ready() && this_processor->pending_preemption ) {
    250                 LIB_DEBUG_PRINT_BUFFER_LOCAL( STDERR_FILENO, "Alarm IRH : Blocking thread %p on %p\n", this_thread, this_processor );
     259                // LIB_DEBUG_PRINT_BUFFER_LOCAL( STDERR_FILENO, "Alarm IRH : Blocking thread %p on %p\n", this_thread, this_processor );
    251260                this_processor->pending_preemption = false;
    252261                BlockInternal( (thread_desc*)this_thread );
    253                 LIB_DEBUG_PRINT_BUFFER_LOCAL( STDERR_FILENO, "Alarm Switch IRH : Back\n\n");
     262                // LIB_DEBUG_PRINT_BUFFER_LOCAL( STDERR_FILENO, "Alarm Switch IRH : Back\n\n");
    254263        }
    255264}
Note: See TracChangeset for help on using the changeset viewer.