Changeset 2c88368 for src


Ignore:
Timestamp:
May 22, 2018, 4:46:29 PM (7 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

Location:
src/libcfa
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • src/libcfa/bits/containers.h

    ra8706fc r2c88368  
    220220        }
    221221
    222         #define _next .0
    223         #define _prev .1
     222        #define next 0
     223        #define prev 1
    224224        forall(dtype T | sized(T))
    225225        static inline void push_front( __dllist(T) & this, T & node ) with( this ) {
     226                verify(__get);
    226227                if ( head ) {
    227                         __get( node )_next = head;
    228                         __get( node )_prev = __get( *head )_prev;
     228                        __get( node ).next = head;
     229                        __get( node ).prev = __get( *head ).prev;
    229230                        // inserted node must be consistent before it is seen
    230231                        // prevent code movement across barrier
    231232                        asm( "" : : : "memory" );
    232                         __get( *head )_prev = &node;
    233                         T & prev = *__get( node )_prev;
    234                         __get( prev )_next = &node;
     233                        __get( *head ).prev = &node;
     234                        T & _prev = *__get( node ).prev;
     235                        __get( _prev ).next = &node;
    235236                }
    236237                else {
    237                         __get( node )_next = &node;
    238                         __get( node )_prev = &node;
     238                        __get( node ).next = &node;
     239                        __get( node ).prev = &node;
    239240                }
    240241
     
    246247        forall(dtype T | sized(T))
    247248        static inline void remove( __dllist(T) & this, T & node ) with( this ) {
     249                verify(__get);
    248250                if ( &node == head ) {
    249                         if ( __get( *head )_next == head ) {
     251                        if ( __get( *head ).next == head ) {
    250252                                head = NULL;
    251253                        }
    252254                        else {
    253                                 head = __get( *head )_next;
     255                                head = __get( *head ).next;
    254256                        }
    255257                }
    256                 __get( *__get( node )_next )_prev = __get( node )_prev;
    257                 __get( *__get( node )_prev )_next = __get( node )_next;
    258                 __get( node )_next = NULL;
    259                 __get( node )_prev = NULL;
    260         }
    261         #undef _next
    262         #undef _prev
     258                __get( *__get( node ).next ).prev = __get( node ).prev;
     259                __get( *__get( node ).prev ).next = __get( node ).next;
     260                __get( node ).next = NULL;
     261                __get( node ).prev = NULL;
     262        }
     263        #undef next
     264        #undef prev
    263265#endif
    264266
  • src/libcfa/concurrency/alarm.c

    ra8706fc r2c88368  
    3737
    3838void __kernel_set_timer( Duration alarm ) {
     39        verifyf(alarm >= 1`us || alarm == 0, "Setting timer to < 1us (%luns)", alarm.tv);
    3940        setitimer( ITIMER_REAL, &(itimerval){ alarm }, NULL );
    4041}
     
    6869}
    6970
    70 __cfaabi_dbg_debug_do( bool validate( alarm_list_t * this ) {
     71#if !defined(NDEBUG) && (defined(__CFA_DEBUG__) || defined(__CFA_VERIFY__))
     72bool validate( alarm_list_t * this ) {
    7173        alarm_node_t ** it = &this->head;
    7274        while( (*it) ) {
     
    7577
    7678        return it == this->tail;
    77 })
     79}
     80#endif
    7881
    7982static inline void insert_at( alarm_list_t * this, alarm_node_t * n, __alarm_it_t p ) {
  • src/libcfa/concurrency/kernel

    ra8706fc r2c88368  
    145145        __dllist_t(struct processor) idles;
    146146
     147        // List of processors
     148        __spinlock_t thread_list_lock;
     149        __dllist_t(struct thread_desc) threads;
     150
    147151        // Link lists fields
    148152        struct {
  • src/libcfa/concurrency/kernel.c

    ra8706fc r2c88368  
    4949thread_desc * mainThread;
    5050
    51 struct { __dllist_t(thread_desc) list; __spinlock_t lock; } global_threads ;
    5251struct { __dllist_t(cluster    ) list; __spinlock_t lock; } global_clusters;
    5352
    5453//-----------------------------------------------------------------------------
    5554// Global state
    56 
    57 // volatile thread_local bool preemption_in_progress = 0;
    58 // volatile thread_local bool preemption_enabled = false;
    59 // volatile thread_local unsigned short disable_preempt_count = 1;
    60 
    6155thread_local struct KernelThreadData kernelTLS = {
    6256        NULL,
     
    123117        node.next = NULL;
    124118        node.prev = NULL;
    125         doregister(this);
     119        doregister(curr_cluster, this);
    126120
    127121        monitors{ &self_mon_p, 1, (fptr_t)0 };
     
    172166        procs{ __get };
    173167        idles{ __get };
     168        threads{ __get };
    174169
    175170        doregister(this);
     
    523518        __cfaabi_dbg_print_safe("Kernel : Starting\n");
    524519
    525         global_threads. list{ __get };
    526         global_threads. lock{};
    527520        global_clusters.list{ __get };
    528521        global_clusters.lock{};
     
    624617        ^(mainThread){};
    625618
     619        ^(global_clusters.list){};
     620        ^(global_clusters.lock){};
     621
    626622        __cfaabi_dbg_print_safe("Kernel : Shutdown complete\n");
    627623}
     
    697693        else {
    698694                int len = snprintf( abort_text, abort_text_size, "Error occurred outside of any thread.\n" );
     695                __cfaabi_dbg_bits_write( abort_text, len );
    699696        }
    700697}
     
    760757//-----------------------------------------------------------------------------
    761758// Global Queues
    762 void doregister( thread_desc & thrd ) {
    763         // lock      ( global_thread.lock );
    764         // push_front( global_thread.list, thrd );
    765         // unlock    ( global_thread.lock );
    766 }
    767 
    768 void unregister( thread_desc & thrd ) {
    769         // lock  ( global_thread.lock );
    770         // remove( global_thread.list, thrd );
    771         // unlock( global_thread.lock );
    772 }
    773 
    774759void doregister( cluster     & cltr ) {
    775         // lock      ( global_cluster.lock );
    776         // push_front( global_cluster.list, cltr );
    777         // unlock    ( global_cluster.lock );
     760        lock      ( global_clusters.lock __cfaabi_dbg_ctx2);
     761        push_front( global_clusters.list, cltr );
     762        unlock    ( global_clusters.lock );
    778763}
    779764
    780765void unregister( cluster     & cltr ) {
    781         // lock  ( global_cluster.lock );
    782         // remove( global_cluster.list, cltr );
    783         // unlock( global_cluster.lock );
    784 }
    785 
     766        lock  ( global_clusters.lock __cfaabi_dbg_ctx2);
     767        remove( global_clusters.list, cltr );
     768        unlock( global_clusters.lock );
     769}
     770
     771void doregister( cluster * cltr, thread_desc & thrd ) {
     772        lock      (cltr->thread_list_lock __cfaabi_dbg_ctx2);
     773        push_front(cltr->threads, thrd);
     774        unlock    (cltr->thread_list_lock);
     775}
     776
     777void unregister( cluster * cltr, thread_desc & thrd ) {
     778        lock  (cltr->thread_list_lock __cfaabi_dbg_ctx2);
     779        remove(cltr->threads, thrd );
     780        unlock(cltr->thread_list_lock);
     781}
    786782
    787783void doregister( cluster * cltr, processor * proc ) {
    788         // lock      (cltr->proc_list_lock __cfaabi_dbg_ctx2);
    789         // push_front(cltr->procs, *proc);
    790         // unlock    (cltr->proc_list_lock);
     784        lock      (cltr->proc_list_lock __cfaabi_dbg_ctx2);
     785        push_front(cltr->procs, *proc);
     786        unlock    (cltr->proc_list_lock);
    791787}
    792788
    793789void unregister( cluster * cltr, processor * proc ) {
    794         // lock  (cltr->proc_list_lock __cfaabi_dbg_ctx2);
    795         // remove(cltr->procs, *proc );
    796         // unlock(cltr->proc_list_lock);
     790        lock  (cltr->proc_list_lock __cfaabi_dbg_ctx2);
     791        remove(cltr->procs, *proc );
     792        unlock(cltr->proc_list_lock);
    797793}
    798794
  • src/libcfa/concurrency/kernel_private.h

    ra8706fc r2c88368  
    101101
    102102
    103 void doregister( struct thread_desc & thrd );
    104 void unregister( struct thread_desc & thrd );
     103void doregister( struct cluster & cltr );
     104void unregister( struct cluster & cltr );
    105105
    106 void doregister( struct cluster     & cltr );
    107 void unregister( struct cluster     & cltr );
     106void doregister( struct cluster * cltr, struct thread_desc & thrd );
     107void unregister( struct cluster * cltr, struct thread_desc & thrd );
    108108
    109109void doregister( struct cluster * cltr, struct processor * proc );
  • 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
  • src/libcfa/concurrency/thread.c

    ra8706fc r2c88368  
    4242        node.next = NULL;
    4343        node.prev = NULL;
    44         doregister(this);
     44        doregister(curr_cluster, this);
    4545
    4646        monitors{ &self_mon_p, 1, (fptr_t)0 };
     
    4848
    4949void ^?{}(thread_desc& this) with( this ) {
    50         unregister(this);
     50        unregister(curr_cluster, this);
    5151        ^self_cor{};
    5252}
  • src/libcfa/time

    ra8706fc r2c88368  
    1 // 
     1//
    22// Cforall Version 1.0.0 Copyright (C) 2018 University of Waterloo
    33//
    44// The contents of this file are covered under the licence agreement in the
    55// file "LICENCE" distributed with Cforall.
    6 // 
    7 // time -- 
    8 // 
     6//
     7// time --
     8//
    99// Author           : Peter A. Buhr
    1010// Created On       : Wed Mar 14 23:18:57 2018
     
    1212// Last Modified On : Sat Apr 14 17:48:23 2018
    1313// Update Count     : 636
    14 // 
     14//
    1515
    1616#pragma once
     
    9191static inline int64_t ?`w( Duration dur ) { return dur.tv / (7LL * 24LL * 60LL * 60LL * TIMEGRAN); }
    9292
     93static inline Duration max( Duration lhs, Duration rhs ) { return  (lhs.tv < rhs.tv) ? rhs : lhs;}
     94static inline Duration min( Duration lhs, Duration rhs ) { return !(rhs.tv < lhs.tv) ? lhs : rhs;}
     95
    9396
    9497//######################### C timeval #########################
Note: See TracChangeset for help on using the changeset viewer.