Ignore:
Timestamp:
May 22, 2018, 4:46:29 PM (6 years ago)
Author:
Rob Schluntz <rschlunt@…>
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, with_gc
Children:
59c034c6, d807ca28
Parents:
a8706fc (diff), a1a17a74 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge branch 'master' of plg.uwaterloo.ca:/u/cforall/software/cfa/cfa-cc

File:
1 edited

Legend:

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

    ra8706fc r2c88368  
    1515
    1616#include "preemption.h"
     17#include <assert.h>
    1718
    1819extern "C" {
     
    9192        //Loop throught every thing expired
    9293        while( node = get_expired( alarms, currtime ) ) {
     94                // __cfaabi_dbg_print_buffer_decl( " KERNEL: preemption tick.\n" );
    9395
    9496                // Check if this is a kernel
     
    103105                Duration period = node->period;
    104106                if( period > 0 ) {
     107                        // __cfaabi_dbg_print_buffer_local( " KERNEL: alarm period is %lu.\n", period.tv );
    105108                        node->alarm = currtime + period;    // Alarm is periodic, add currtime to it (used cached current time)
    106109                        insert( alarms, node );             // Reinsert the node for the next time it triggers
     
    112115
    113116        // If there are still alarms pending, reset the timer
    114         if( alarms->head ) { __kernel_set_timer( alarms->head->alarm - currtime ); }
     117        if( alarms->head ) {
     118                __cfaabi_dbg_print_buffer_decl( " KERNEL: @%lu(%lu) resetting alarm to %lu.\n", currtime.tv, __kernel_get_time().tv, (alarms->head->alarm - currtime).tv);
     119                Duration delta = alarms->head->alarm - currtime;
     120                Duration caped = max(delta, 50`us);
     121                // itimerval tim  = { caped };
     122                // __cfaabi_dbg_print_buffer_local( "    Values are %lu, %lu, %lu %lu.\n", delta.tv, caped.tv, tim.it_value.tv_sec, tim.it_value.tv_usec);
     123
     124                __kernel_set_timer( caped );
     125        }
    115126}
    116127
     
    335346        if( !preemption_ready() ) { return; }
    336347
    337         __cfaabi_dbg_print_buffer_decl( " KERNEL: preempting core %p (%p).\n", kernelTLS.this_processor, kernelTLS.this_thread );
     348        __cfaabi_dbg_print_buffer_decl( " KERNEL: preempting core %p (%p @ %p).\n", kernelTLS.this_processor, kernelTLS.this_thread, (void *)(cxt->uc_mcontext.CFA_REG_IP) );
    338349
    339350        // Sync flag : prevent recursive calls to the signal handler
    340351        kernelTLS.preemption_state.in_progress = true;
    341352
    342         // We are about to CtxSwitch out of the signal handler, let other handlers in
    343         signal_unblock( SIGUSR1 );
     353        // Clear sighandler mask before context switching.
     354        static_assert( sizeof( sigset_t ) == sizeof( cxt->uc_sigmask ), "Expected cxt->uc_sigmask to be of sigset_t" );
     355        if ( pthread_sigmask( SIG_SETMASK, (sigset_t *)&(cxt->uc_sigmask), NULL ) == -1 ) {
     356                abort( "internal error, sigprocmask" );
     357        }
    344358
    345359        // TODO: this should go in finish action
     
    377391                                case EAGAIN :
    378392                                case EINTR :
     393                                        {__cfaabi_dbg_print_buffer_decl( " KERNEL: Spurious wakeup %d.\n", err );}
    379394                                        continue;
    380395                        case EINVAL :
     
    424439        sigset_t oldset;
    425440        int ret;
    426         ret = sigprocmask(0, NULL, &oldset);
     441        ret = pthread_sigmask(0, NULL, &oldset);
    427442        if(ret != 0) { abort("ERROR sigprocmask returned %d", ret); }
    428443
    429444        ret = sigismember(&oldset, SIGUSR1);
    430445        if(ret <  0) { abort("ERROR sigismember returned %d", ret); }
    431 
    432446        if(ret == 1) { abort("ERROR SIGUSR1 is disabled"); }
     447
     448        ret = sigismember(&oldset, SIGALRM);
     449        if(ret <  0) { abort("ERROR sigismember returned %d", ret); }
     450        if(ret == 0) { abort("ERROR SIGALRM is enabled"); }
     451
     452        ret = sigismember(&oldset, SIGTERM);
     453        if(ret <  0) { abort("ERROR sigismember returned %d", ret); }
     454        if(ret == 1) { abort("ERROR SIGTERM is disabled"); }
    433455}
    434456
Note: See TracChangeset for help on using the changeset viewer.