Changeset 47ecf2b


Ignore:
Timestamp:
Jul 4, 2017, 3:39:28 PM (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:
cd17862
Parents:
8ee50281
Message:

Some cleanup before refactoring alarms

Location:
src/libcfa/concurrency
Files:
4 edited

Legend:

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

    r8ee50281 r47ecf2b  
    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/coroutine.c

    r8ee50281 r47ecf2b  
    4444// Coroutine ctors and dtors
    4545void ?{}(coStack_t* this) {
    46         this->size              = 10240;        // size of stack
     46        this->size              = 65000;        // size of stack
    4747        this->storage   = NULL; // pointer to stack
    4848        this->limit             = NULL; // stack grows towards stack limit
     
    5050        this->context   = NULL; // address of cfa_context_t
    5151        this->top               = NULL; // address of top of storage
    52         this->userStack = false;       
     52        this->userStack = false;
    5353}
    5454
     
    114114        assert( src->stack.context );
    115115        CtxSwitch( src->stack.context, dst->stack.context );
    116         // when CtxSwitch returns we are back in the src coroutine             
     116        // when CtxSwitch returns we are back in the src coroutine
    117117
    118118        // set state of new coroutine to active
     
    132132                this->size = libCeiling( storageSize, 16 );
    133133                // use malloc/memalign because "new" raises an exception for out-of-memory
    134                
     134
    135135                // assume malloc has 8 byte alignment so add 8 to allow rounding up to 16 byte alignment
    136136                LIB_DEBUG_DO( this->storage = memalign( pageSize, cxtSize + this->size + pageSize ) );
  • src/libcfa/concurrency/kernel.c

    r8ee50281 r47ecf2b  
    337337                sigaddset( &new_mask, SIGALRM );
    338338
    339                 if ( sigprocmask( SIG_BLOCK, &new_mask, &old_mask ) == -1 ) {
    340                         abortf( "internal error, sigprocmask" );
     339                if ( pthread_sigmask( SIG_BLOCK, &new_mask, &old_mask ) == -1 ) {
     340                        abortf( "internal error, pthread_sigmask" );
    341341                }
    342342
     
    348348        // Toggle back previous signal mask of system processor.
    349349        if ( is_system_proc ) {
    350                 if ( sigprocmask( SIG_SETMASK, &old_mask, NULL ) == -1 ) {
    351                         abortf( "internal error, sigprocmask" );
     350                if ( pthread_sigmask( SIG_SETMASK, &old_mask, NULL ) == -1 ) {
     351                        abortf( "internal error, pthread_sigmask" );
    352352                } // if
    353353        } // if
  • src/libcfa/concurrency/preemption.c

    r8ee50281 r47ecf2b  
    179179                if( prev == 1 && proc->pending_preemption ) {
    180180                        proc->pending_preemption = false;
    181                         LIB_DEBUG_PRINT_BUFFER_DECL( STDERR_FILENO, "Executing deferred CtxSwitch on %p\n", this_processor );
    182181                        BlockInternal( thrd );
    183                         LIB_DEBUG_PRINT_BUFFER_LOCAL( STDERR_FILENO, "Executing deferred back\n" );
    184182                }
    185183
     
    189187
    190188static inline void signal_unblock( int 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         // )
     189        LIB_DEBUG_PRINT_BUFFER_DECL( STDERR_FILENO, "Unblock %d on %p\n", sig, this_processor );
    199190
    200191        sigset_t mask;
     
    202193        sigaddset( &mask, sig );
    203194
    204         if ( sigprocmask( SIG_UNBLOCK, &mask, NULL ) == -1 ) {
    205             abortf( "internal error, sigprocmask" );
     195        if ( pthread_sigmask( SIG_UNBLOCK, &mask, NULL ) == -1 ) {
     196            abortf( "internal error, pthread_sigmask" );
    206197        } // if
    207198}
     199
     200// static inline void signal_block( int sig ) {
     201//      sigset_t mask;
     202//      sigemptyset( &mask );
     203//      sigaddset( &mask, sig );
     204
     205//      if ( pthread_sigmask( SIG_BLOCK, &mask, NULL ) == -1 ) {
     206//          abortf( "internal error, pthread_sigmask" );
     207//      } // if
     208// }
    208209
    209210static inline bool preemption_ready() {
     
    225226}
    226227
     228#ifdef __x86_64__
     229#define CFA_REG_IP REG_RIP
     230#else
     231#define CFA_REG_IP REG_EIP
     232#endif
     233
    227234void sigHandler_ctxSwitch( __CFA_SIGPARMS__ ) {
    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]); )
     235        LIB_DEBUG_DO( last_interrupt = (void *)(cxt->uc_mcontext.gregs[CFA_REG_IP]); )
     236        verify( this_processor != systemProcessor );
    230237
    231238        if( preemption_ready() ) {
    232                 // LIB_DEBUG_PRINT_BUFFER_LOCAL( STDERR_FILENO, "Ctx Switch IRH : Blocking thread %p on %p\n", this_thread, this_processor );
    233239                signal_unblock( SIGUSR1 );
    234240                BlockInternal( (thread_desc*)this_thread );
    235                 // LIB_DEBUG_PRINT_BUFFER_LOCAL( STDERR_FILENO, "Ctx Switch IRH : Back\n\n");
    236241        }
    237242        else {
    238                 // LIB_DEBUG_PRINT_BUFFER_LOCAL( STDERR_FILENO, "Ctx Switch IRH : Defering\n" );
    239243                defer_ctxSwitch();
    240                 signal_unblock( SIGUSR1 );
    241244        }
    242245}
    243246
    244247void sigHandler_alarm( __CFA_SIGPARMS__ ) {
    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]); )
     248        LIB_DEBUG_DO( last_interrupt = (void *)(cxt->uc_mcontext.gregs[CFA_REG_IP]); )
     249        verify( this_processor == systemProcessor );
    247250
    248251        if( try_lock( &systemProcessor->alarm_lock DEBUG_CTX2 ) ) {
    249252                tick_preemption();
     253                systemProcessor->pending_alarm = false;
    250254                unlock( &systemProcessor->alarm_lock );
    251255        }
     
    257261
    258262        if( preemption_ready() && this_processor->pending_preemption ) {
    259                 // LIB_DEBUG_PRINT_BUFFER_LOCAL( STDERR_FILENO, "Alarm IRH : Blocking thread %p on %p\n", this_thread, this_processor );
     263
    260264                this_processor->pending_preemption = false;
    261265                BlockInternal( (thread_desc*)this_thread );
    262                 // LIB_DEBUG_PRINT_BUFFER_LOCAL( STDERR_FILENO, "Alarm Switch IRH : Back\n\n");
    263266        }
    264267}
    265268
    266269static void preempt( processor * this ) {
    267         // LIB_DEBUG_PRINT_BUFFER_DECL( STDERR_FILENO, "Processor : signalling %p\n", this );
    268 
    269270        if( this != systemProcessor ) {
    270271                pthread_kill( this->kernel_thread, SIGUSR1 );
     
    284285        act.sa_sigaction = (void (*)(int, siginfo_t *, void *))handler;
    285286        act.sa_flags = flags;
    286 
    287         // disabled during signal handler
    288         sigemptyset( &act.sa_mask );
    289         sigaddset( &act.sa_mask, sig );
    290287
    291288        if ( sigaction( sig, &act, NULL ) == -1 ) {
Note: See TracChangeset for help on using the changeset viewer.