Ignore:
Timestamp:
Aug 11, 2020, 4:40:15 PM (5 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:
0d070ca
Parents:
07d867b (diff), 129674b (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' into new-ast

File:
1 edited

Legend:

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

    r07d867b r22f94a4  
    1010// Created On       : Mon Jun 5 14:20:42 2017
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Thu Dec  5 16:34:05 2019
    13 // Update Count     : 43
     12// Last Modified On : Wed Jun 17 11:36:25 2020
     13// Update Count     : 46
    1414//
    1515
     
    1919#include <assert.h>
    2020
    21 extern "C" {
    2221#include <errno.h>
    2322#include <stdio.h>
     
    2524#include <unistd.h>
    2625#include <limits.h>                                                                             // PTHREAD_STACK_MIN
    27 }
    2826
    2927#include "bits/signal.hfa"
     28#include "kernel_private.hfa"
    3029
    3130#if !defined(__CFA_DEFAULT_PREEMPTION__)
     
    3938// FwdDeclarations : timeout handlers
    4039static void preempt( processor   * this );
    41 static void timeout( $thread * this );
     40static void timeout( struct __processor_id_t * id, $thread * this );
    4241
    4342// FwdDeclarations : Signal handlers
     
    9089
    9190// Tick one frame of the Discrete Event Simulation for alarms
    92 static void tick_preemption() {
     91static void tick_preemption( struct __processor_id_t * id ) {
    9392        alarm_node_t * node = 0p;                                                       // Used in the while loop but cannot be declared in the while condition
    9493        alarm_list_t * alarms = &event_kernel->alarms;          // Local copy for ease of reading
     
    108107                }
    109108                else {
    110                         timeout( node->thrd );
     109                        timeout( id, node->thrd );
    111110                }
    112111
     
    121120        // If there are still alarms pending, reset the timer
    122121        if( & (*alarms)`first ) {
    123                 __cfaabi_dbg_print_buffer_decl( " KERNEL: @%ju(%ju) resetting alarm to %ju.\n", currtime.tv, __kernel_get_time().tv, (alarms->head->alarm - currtime).tv);
     122                __cfadbg_print_buffer_decl(preemption, " KERNEL: @%ju(%ju) resetting alarm to %ju.\n", currtime.tv, __kernel_get_time().tv, (alarms->head->alarm - currtime).tv);
    124123                Duration delta = (*alarms)`first.alarm - currtime;
    125124                Duration capped = max(delta, 50`us);
     
    188187        void enable_interrupts( __cfaabi_dbg_ctx_param ) {
    189188                processor   * proc = kernelTLS.this_processor; // Cache the processor now since interrupts can start happening after the atomic store
     189                /* paranoid */ verify( proc );
    190190
    191191                with( kernelTLS.preemption_state ){
     
    268268
    269269// reserved for future use
    270 static void timeout( $thread * this ) {
    271         __unpark( this __cfaabi_dbg_ctx2 );
     270static void timeout( struct __processor_id_t * id, $thread * this ) {
     271        #if !defined( __CFA_NO_STATISTICS__ )
     272                kernelTLS.this_stats = this->curr_cluster->stats;
     273        #endif
     274        __unpark( id, this __cfaabi_dbg_ctx2 );
    272275}
    273276
     
    291294// Startup routine to activate preemption
    292295// Called from kernel_startup
    293 void kernel_start_preemption() {
     296void __kernel_alarm_startup() {
    294297        __cfaabi_dbg_print_safe( "Kernel : Starting preemption\n" );
    295298
     
    313316// Shutdown routine to deactivate preemption
    314317// Called from kernel_shutdown
    315 void kernel_stop_preemption() {
     318void __kernel_alarm_shutdown() {
    316319        __cfaabi_dbg_print_safe( "Kernel : Preemption stopping\n" );
    317320
     
    405408// Waits on SIGALRM and send SIGUSR1 to whom ever needs it
    406409static void * alarm_loop( __attribute__((unused)) void * args ) {
     410        __processor_id_t id;
     411        id.id = doregister(&id);
     412
    407413        // Block sigalrms to control when they arrive
    408414        sigset_t mask;
     
    449455                        // __cfaabi_dbg_print_safe( "Kernel : Preemption thread tick\n" );
    450456                        lock( event_kernel->lock __cfaabi_dbg_ctx2 );
    451                         tick_preemption();
     457                        tick_preemption( &id );
    452458                        unlock( event_kernel->lock );
    453459                        break;
     
    462468EXIT:
    463469        __cfaabi_dbg_print_safe( "Kernel : Preemption thread stopping\n" );
     470        unregister(&id);
    464471        return 0p;
    465472}
     
    475482        sigset_t oldset;
    476483        int ret;
    477         ret = pthread_sigmask(0, 0p, &oldset);
     484        ret = pthread_sigmask(0, ( const sigset_t * ) 0p, &oldset);  // workaround trac#208: cast should be unnecessary
    478485        if(ret != 0) { abort("ERROR sigprocmask returned %d", ret); }
    479486
Note: See TracChangeset for help on using the changeset viewer.