Ignore:
File:
1 edited

Legend:

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

    r4dad189 r169d944  
    1010// Created On       : Mon Jun 5 14:20:42 2017
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Tue Feb  6 15:00:36 2018
    13 // Update Count     : 10
     12// Last Modified On : Thu Feb  8 16:12:58 2018
     13// Update Count     : 12
    1414//
    1515
     
    6767}
    6868
    69 enum {
    70         PREEMPT_NORMAL    = 0,
    71         PREEMPT_TERMINATE = 1,
    72 };
    73 
    7469//=============================================================================================
    7570// Kernel Preemption logic
     
    197192
    198193        if ( pthread_sigmask( SIG_UNBLOCK, &mask, NULL ) == -1 ) {
    199             abortf( "internal error, pthread_sigmask" );
     194            abort( "internal error, pthread_sigmask" );
    200195        }
    201196}
     
    208203
    209204        if ( pthread_sigmask( SIG_BLOCK, &mask, NULL ) == -1 ) {
    210             abortf( "internal error, pthread_sigmask" );
     205            abort( "internal error, pthread_sigmask" );
    211206        }
    212207}
     
    214209// kill wrapper : signal a processor
    215210static void preempt( processor * this ) {
    216         sigval_t value = { PREEMPT_NORMAL };
    217         pthread_sigqueue( this->kernel_thread, SIGUSR1, value );
    218 }
    219 
    220 // kill wrapper : signal a processor
    221 void terminate(processor * this) {
    222         this->do_terminate = true;
    223         sigval_t value = { PREEMPT_TERMINATE };
    224         pthread_sigqueue( this->kernel_thread, SIGUSR1, value );
     211        pthread_kill( this->kernel_thread, SIGUSR1 );
    225212}
    226213
     
    247234// Called from kernel_startup
    248235void kernel_start_preemption() {
    249         __cfaabi_dbg_print_safe("Kernel : Starting preemption\n");
     236        __cfaabi_dbg_print_safe( "Kernel : Starting preemption\n" );
    250237
    251238        // Start with preemption disabled until ready
     
    268255// Called from kernel_shutdown
    269256void kernel_stop_preemption() {
    270         __cfaabi_dbg_print_safe("Kernel : Preemption stopping\n");
     257        __cfaabi_dbg_print_safe( "Kernel : Preemption stopping\n" );
    271258
    272259        // Block all signals since we are already shutting down
     
    284271        // Preemption is now fully stopped
    285272
    286         __cfaabi_dbg_print_safe("Kernel : Preemption stopped\n");
     273        __cfaabi_dbg_print_safe( "Kernel : Preemption stopped\n" );
    287274}
    288275
     
    312299        __cfaabi_dbg_debug_do( last_interrupt = (void *)(cxt->uc_mcontext.CFA_REG_IP); )
    313300
    314         // SKULLDUGGERY: if a thread creates a processor and the immediately deletes it,
    315         // the interrupt that is supposed to force the kernel thread to preempt might arrive
    316         // before the kernel thread has even started running. When that happens an iterrupt
    317         // we a null 'this_processor' will be caught, just ignore it.
    318         if(!this_processor) return;
    319 
    320         choose(sfp->si_value.sival_int) {
    321                 case PREEMPT_NORMAL   : ;// Normal case, nothing to do here
    322                 case PREEMPT_TERMINATE: verify(this_processor->do_terminate);
    323                 default:
    324                         abortf( "internal error, signal value is %d", sfp->si_value.sival_int );
    325         }
    326 
    327301        // Check if it is safe to preempt here
    328302        if( !preemption_ready() ) { return; }
    329303
    330         __cfaabi_dbg_print_buffer_decl(" KERNEL: preempting core %p (%p).\n", this_processor, this_thread);
     304        __cfaabi_dbg_print_buffer_decl( " KERNEL: preempting core %p (%p).\n", this_processor, this_thread);
    331305
    332306        preemption_in_progress = true;                      // Sync flag : prevent recursive calls to the signal handler
     
    348322
    349323        if ( pthread_sigmask( SIG_BLOCK, &mask, NULL ) == -1 ) {
    350             abortf( "internal error, pthread_sigmask" );
     324            abort( "internal error, pthread_sigmask" );
    351325        }
    352326
     
    365339                                        continue;
    366340                        case EINVAL :
    367                                         abortf("Timeout was invalid.");
     341                                        abort( "Timeout was invalid." );
    368342                                default:
    369                                         abortf("Unhandled error %d", err);
     343                                        abort( "Unhandled error %d", err);
    370344                        }
    371345                }
     
    374348                assertf(sig == SIGALRM, "Kernel Internal Error, sigwait: Unexpected signal %d (%d : %d)\n", sig, info.si_code, info.si_value.sival_int);
    375349
    376                 // __cfaabi_dbg_print_safe("Kernel : Caught alarm from %d with %d\n", info.si_code, info.si_value.sival_int );
     350                // __cfaabi_dbg_print_safe( "Kernel : Caught alarm from %d with %d\n", info.si_code, info.si_value.sival_int );
    377351                // Switch on the code (a.k.a. the sender) to
    378352                switch( info.si_code )
     
    382356                case SI_TIMER:
    383357                case SI_KERNEL:
    384                         // __cfaabi_dbg_print_safe("Kernel : Preemption thread tick\n");
     358                        // __cfaabi_dbg_print_safe( "Kernel : Preemption thread tick\n" );
    385359                        lock( event_kernel->lock __cfaabi_dbg_ctx2 );
    386360                        tick_preemption();
     
    396370
    397371EXIT:
    398         __cfaabi_dbg_print_safe("Kernel : Preemption thread stopping\n");
     372        __cfaabi_dbg_print_safe( "Kernel : Preemption thread stopping\n" );
    399373        return NULL;
    400374}
Note: See TracChangeset for help on using the changeset viewer.