Changeset d8548e2


Ignore:
Timestamp:
Feb 23, 2018, 11:37:54 AM (4 years ago)
Author:
Thierry Delisle <tdelisle@…>
Branches:
aaron-thesis, arm-eh, cleanup-dtors, deferred_resn, demangler, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, resolv-new, with_gc
Children:
566b74f
Parents:
d2887f7
Message:

Fixed preemption and changed default_preemption to use cfa_time_t

Location:
src
Files:
11 edited

Legend:

Unmodified
Added
Removed
  • src/benchmark/bench.h

    rd2887f7 rd8548e2  
    1010#if defined(__cforall)
    1111}
     12#include <bits/cfatime.h>
    1213#endif
     14
    1315
    1416static inline unsigned long long int Time() {
     
    4547        ( EndTime - StartTime ) / n;
    4648
    47 unsigned int default_preemption() {
     49__cfa_time_t default_preemption() {
    4850        return 0;
    4951}
  • src/libcfa/Makefile.am

    rd2887f7 rd8548e2  
    101101        gmp                             \
    102102        bits/align.h            \
     103        bits/cfatime.h          \
    103104        bits/containers.h               \
    104105        bits/defs.h             \
  • src/libcfa/Makefile.in

    rd2887f7 rd8548e2  
    264264        concurrency/thread concurrency/kernel concurrency/monitor \
    265265        ${shell find stdhdr -type f -printf "%p "} math gmp \
    266         bits/align.h bits/containers.h bits/defs.h bits/debug.h \
    267         bits/locks.h concurrency/invoke.h
     266        bits/align.h bits/cfatime.h bits/containers.h bits/defs.h \
     267        bits/debug.h bits/locks.h concurrency/invoke.h
    268268HEADERS = $(nobase_cfa_include_HEADERS)
    269269am__tagged_files = $(HEADERS) $(SOURCES) $(TAGS_FILES) $(LISP)
     
    437437        gmp                             \
    438438        bits/align.h            \
     439        bits/cfatime.h          \
    439440        bits/containers.h               \
    440441        bits/defs.h             \
  • src/libcfa/bits/cfatime.h

    rd2887f7 rd8548e2  
    4848// ctors
    4949static inline void ?{}( __cfa_time_t & this ) { this.val = 0; }
     50static inline void ?{}( __cfa_time_t & this, const __cfa_time_t & rhs ) { this.val = rhs.val; }
    5051static inline void ?{}( __cfa_time_t & this, zero_t zero ) { this.val = 0; }
    5152
     
    9293static inline __cfa_time_t from_us ( uint64_t val ) { __cfa_time_t ret; ret.val = val *         1_000ul; return ret; }
    9394static inline __cfa_time_t from_ns ( uint64_t val ) { __cfa_time_t ret; ret.val = val *             1ul; return ret; }
     95
     96static inline uint64_t to_s  ( __cfa_time_t t ) { return t.val / 1_000_000_000ul; }
     97static inline uint64_t to_ms ( __cfa_time_t t ) { return t.val /     1_000_000ul; }
     98static inline uint64_t to_us ( __cfa_time_t t ) { return t.val /         1_000ul; }
     99static inline uint64_t to_ns ( __cfa_time_t t ) { return t.val /             1ul; }
  • src/libcfa/concurrency/coroutine.c

    rd2887f7 rd8548e2  
    9999// Wrapper for co
    100100void CoroutineCtxSwitch(coroutine_desc* src, coroutine_desc* dst) {
    101         verify( preemption.enabled || this_processor->do_terminate );
     101        verify( preemption_state.enabled || this_processor->do_terminate );
    102102        disable_interrupts();
    103103
     
    117117
    118118        enable_interrupts( __cfaabi_dbg_ctx );
    119         verify( preemption.enabled || this_processor->do_terminate );
     119        verify( preemption_state.enabled || this_processor->do_terminate );
    120120} //ctxSwitchDirect
    121121
  • src/libcfa/concurrency/kernel

    rd2887f7 rd8548e2  
    1919
    2020#include "invoke.h"
     21#include "bits/cfatime.h"
    2122
    2223extern "C" {
     
    4849
    4950        // Preemption rate on this cluster
    50         unsigned long long int preemption;
     51        __cfa_time_t preemption_rate;
    5152};
     53
     54extern __cfa_time_t default_preemption();
    5255
    5356void ?{} (cluster & this);
  • src/libcfa/concurrency/kernel.c

    rd2887f7 rd8548e2  
    6060// volatile thread_local unsigned short disable_preempt_count = 1;
    6161
    62 volatile thread_local __cfa_kernel_preemption_data_t preemption = { false, false, 1 };
     62volatile thread_local __cfa_kernel_preemption_state_t preemption_state = { false, false, 1 };
    6363
    6464//-----------------------------------------------------------------------------
     
    180180        ready_queue_lock{};
    181181
    182         preemption = default_preemption();
     182        preemption_rate = default_preemption();
    183183}
    184184
     
    209209                        if(readyThread)
    210210                        {
    211                                 verify( !preemption.enabled );
     211                                verify( !preemption_state.enabled );
    212212
    213213                                runThread(this, readyThread);
    214214
    215                                 verify( !preemption.enabled );
     215                                verify( !preemption_state.enabled );
    216216
    217217                                //Some actions need to be taken from the kernel
     
    262262void finishRunning(processor * this) with( this->finish ) {
    263263        if( action_code == Release ) {
    264                 verify( !preemption.enabled );
     264                verify( !preemption_state.enabled );
    265265                unlock( *lock );
    266266        }
     
    269269        }
    270270        else if( action_code == Release_Schedule ) {
    271                 verify( !preemption.enabled );
     271                verify( !preemption_state.enabled );
    272272                unlock( *lock );
    273273                ScheduleThread( thrd );
    274274        }
    275275        else if( action_code == Release_Multi ) {
    276                 verify( !preemption.enabled );
     276                verify( !preemption_state.enabled );
    277277                for(int i = 0; i < lock_count; i++) {
    278278                        unlock( *locks[i] );
     
    306306        this_coroutine = NULL;
    307307        this_thread = NULL;
    308         preemption.enabled = false;
    309         preemption.disable_count = 1;
     308        preemption_state.enabled = false;
     309        preemption_state.disable_count = 1;
    310310        // SKULLDUGGERY: We want to create a context for the processor coroutine
    311311        // which is needed for the 2-step context switch. However, there is no reason
     
    351351        coroutine_desc * dst = get_coroutine(*this->runner);
    352352
    353         verify( !preemption.enabled );
     353        verify( !preemption_state.enabled );
    354354
    355355        create_stack(&dst->stack, dst->stack.size);
    356356        CtxStart(this->runner, CtxInvokeCoroutine);
    357357
    358         verify( !preemption.enabled );
     358        verify( !preemption_state.enabled );
    359359
    360360        dst->last = src;
     
    382382        src->state = Active;
    383383
    384         verify( !preemption.enabled );
     384        verify( !preemption_state.enabled );
    385385}
    386386
     
    392392        verify( thrd->self_cor.state != Halted );
    393393
    394         verify( !preemption.enabled );
     394        verify( !preemption_state.enabled );
    395395
    396396        verifyf( thrd->next == NULL, "Expected null got %p", thrd->next );
     
    402402        }
    403403
    404         verify( !preemption.enabled );
     404        verify( !preemption_state.enabled );
    405405}
    406406
    407407thread_desc * nextThread(cluster * this) with( *this ) {
    408         verify( !preemption.enabled );
     408        verify( !preemption_state.enabled );
    409409        lock( ready_queue_lock __cfaabi_dbg_ctx2 );
    410410        thread_desc * head = pop_head( ready_queue );
    411411        unlock( ready_queue_lock );
    412         verify( !preemption.enabled );
     412        verify( !preemption_state.enabled );
    413413        return head;
    414414}
     
    416416void BlockInternal() {
    417417        disable_interrupts();
    418         verify( !preemption.enabled );
     418        verify( !preemption_state.enabled );
    419419        returnToKernel();
    420         verify( !preemption.enabled );
     420        verify( !preemption_state.enabled );
    421421        enable_interrupts( __cfaabi_dbg_ctx );
    422422}
     
    427427        this_processor->finish.lock        = lock;
    428428
    429         verify( !preemption.enabled );
     429        verify( !preemption_state.enabled );
    430430        returnToKernel();
    431         verify( !preemption.enabled );
     431        verify( !preemption_state.enabled );
    432432
    433433        enable_interrupts( __cfaabi_dbg_ctx );
     
    439439        this_processor->finish.thrd        = thrd;
    440440
    441         verify( !preemption.enabled );
     441        verify( !preemption_state.enabled );
    442442        returnToKernel();
    443         verify( !preemption.enabled );
     443        verify( !preemption_state.enabled );
    444444
    445445        enable_interrupts( __cfaabi_dbg_ctx );
     
    453453        this_processor->finish.thrd        = thrd;
    454454
    455         verify( !preemption.enabled );
     455        verify( !preemption_state.enabled );
    456456        returnToKernel();
    457         verify( !preemption.enabled );
     457        verify( !preemption_state.enabled );
    458458
    459459        enable_interrupts( __cfaabi_dbg_ctx );
     
    466466        this_processor->finish.lock_count  = count;
    467467
    468         verify( !preemption.enabled );
     468        verify( !preemption_state.enabled );
    469469        returnToKernel();
    470         verify( !preemption.enabled );
     470        verify( !preemption_state.enabled );
    471471
    472472        enable_interrupts( __cfaabi_dbg_ctx );
     
    481481        this_processor->finish.thrd_count  = thrd_count;
    482482
    483         verify( !preemption.enabled );
     483        verify( !preemption_state.enabled );
    484484        returnToKernel();
    485         verify( !preemption.enabled );
     485        verify( !preemption_state.enabled );
    486486
    487487        enable_interrupts( __cfaabi_dbg_ctx );
     
    489489
    490490void LeaveThread(__spinlock_t * lock, thread_desc * thrd) {
    491         verify( !preemption.enabled );
     491        verify( !preemption_state.enabled );
    492492        this_processor->finish.action_code = thrd ? Release_Schedule : Release;
    493493        this_processor->finish.lock        = lock;
     
    503503// Kernel boot procedures
    504504void kernel_startup(void) {
    505         verify( !preemption.enabled );
     505        verify( !preemption_state.enabled );
    506506        __cfaabi_dbg_print_safe("Kernel : Starting\n");
    507507
     
    548548        __cfaabi_dbg_print_safe("Kernel : Started\n--------------------------------------------------\n\n");
    549549
    550         verify( !preemption.enabled );
     550        verify( !preemption_state.enabled );
    551551        enable_interrupts( __cfaabi_dbg_ctx );
    552         verify( preemption.enabled );
     552        verify( preemption_state.enabled );
    553553}
    554554
     
    556556        __cfaabi_dbg_print_safe("\n--------------------------------------------------\nKernel : Shutting down\n");
    557557
    558         verify( preemption.enabled );
     558        verify( preemption_state.enabled );
    559559        disable_interrupts();
    560         verify( !preemption.enabled );
     560        verify( !preemption_state.enabled );
    561561
    562562        // SKULLDUGGERY: Notify the mainProcessor it needs to terminates.
  • src/libcfa/concurrency/kernel_private.h

    rd2887f7 rd8548e2  
    7878// extern volatile thread_local unsigned short disable_preempt_count;
    7979
    80 struct __cfa_kernel_preemption_data_t {
     80struct __cfa_kernel_preemption_state_t {
    8181        bool enabled;
    8282        bool in_progress;
     
    8484};
    8585
    86 extern volatile thread_local __cfa_kernel_preemption_data_t preemption;
     86extern volatile thread_local __cfa_kernel_preemption_state_t preemption_state;
    8787
    8888//-----------------------------------------------------------------------------
  • src/libcfa/concurrency/preemption.c

    rd2887f7 rd8548e2  
    2323}
    2424
     25#include "bits/cfatime.h"
    2526#include "bits/signal.h"
    2627
    27 //TODO move to defaults
    28 #define __CFA_DEFAULT_PREEMPTION__ 10000
    29 
    30 //TODO move to defaults
    31 __attribute__((weak)) unsigned int default_preemption() {
     28#if !defined(__CFA_DEFAULT_PREEMPTION__)
     29#define __CFA_DEFAULT_PREEMPTION__ 10`cfa_ms
     30#endif
     31
     32__cfa_time_t default_preemption() __attribute__((weak)) {
    3233        return __CFA_DEFAULT_PREEMPTION__;
    3334}
     
    149150        // Disable interrupts by incrementing the counter
    150151        void disable_interrupts() {
    151                 preemption.enabled = false;
    152                 __attribute__((unused)) unsigned short new_val = preemption.disable_count + 1;
    153                 preemption.disable_count = new_val;
     152                preemption_state.enabled = false;
     153                __attribute__((unused)) unsigned short new_val = preemption_state.disable_count + 1;
     154                preemption_state.disable_count = new_val;
    154155                verify( new_val < 65_000u );              // If this triggers someone is disabling interrupts without enabling them
    155156        }
     
    161162                thread_desc * thrd = this_thread;         // Cache the thread now since interrupts can start happening after the atomic add
    162163
    163                 unsigned short prev = preemption.disable_count;
    164                 preemption.disable_count -= 1;
     164                unsigned short prev = preemption_state.disable_count;
     165                preemption_state.disable_count -= 1;
    165166                verify( prev != 0u );                     // If this triggers someone is enabled already enabled interruptsverify( prev != 0u );
    166167
    167168                // Check if we need to prempt the thread because an interrupt was missed
    168169                if( prev == 1 ) {
    169                         preemption.enabled = true;
     170                        preemption_state.enabled = true;
    170171                        if( proc->pending_preemption ) {
    171172                                proc->pending_preemption = false;
     
    181182        // Don't execute any pending CtxSwitch even if counter reaches 0
    182183        void enable_interrupts_noPoll() {
    183                 unsigned short prev = preemption.disable_count;
    184                 preemption.disable_count -= 1;
     184                unsigned short prev = preemption_state.disable_count;
     185                preemption_state.disable_count -= 1;
    185186                verifyf( prev != 0u, "Incremented from %u\n", prev );                     // If this triggers someone is enabled already enabled interrupts
    186187                if( prev == 1 ) {
    187                         preemption.enabled = true;
     188                        preemption_state.enabled = true;
    188189                }
    189190        }
     
    235236// If false : preemption is unsafe and marked as pending
    236237static inline bool preemption_ready() {
    237         bool ready = preemption.enabled && !preemption.in_progress; // Check if preemption is safe
     238        bool ready = preemption_state.enabled && !preemption_state.in_progress; // Check if preemption is safe
    238239        this_processor->pending_preemption = !ready;                        // Adjust the pending flag accordingly
    239240        return ready;
     
    250251
    251252        // Start with preemption disabled until ready
    252         preemption.enabled = false;
    253         preemption.disable_count = 1;
     253        preemption_state.enabled = false;
     254        preemption_state.disable_count = 1;
    254255
    255256        // Initialize the event kernel
     
    294295        this.proc->preemption_alarm = &this.alarm;
    295296
    296         update_preemption( this.proc, from_us(this.proc->cltr->preemption) );
     297        update_preemption( this.proc, this.proc->cltr->preemption_rate );
    297298}
    298299
     
    330331        __cfaabi_dbg_print_buffer_decl( " KERNEL: preempting core %p (%p).\n", this_processor, this_thread);
    331332
    332         preemption.in_progress = true;                      // Sync flag : prevent recursive calls to the signal handler
     333        preemption_state.in_progress = true;                      // Sync flag : prevent recursive calls to the signal handler
    333334        signal_unblock( SIGUSR1 );                          // We are about to CtxSwitch out of the signal handler, let other handlers in
    334         preemption.in_progress = false;                     // Clear the in progress flag
     335        preemption_state.in_progress = false;                     // Clear the in progress flag
    335336
    336337        // Preemption can occur here
  • src/libcfa/concurrency/preemption.h

    rd2887f7 rd8548e2  
    1919#include "kernel_private.h"
    2020
    21 __attribute__((weak)) unsigned int default_preemption();
    2221void kernel_start_preemption();
    2322void kernel_stop_preemption();
  • src/libcfa/concurrency/thread.c

    rd2887f7 rd8548e2  
    9898
    9999void yield( void ) {
    100         verify( preemption.enabled );
     100        verify( preemption_state.enabled );
    101101        BlockInternal( this_thread );
    102         verify( preemption.enabled );
     102        verify( preemption_state.enabled );
    103103}
    104104
Note: See TracChangeset for help on using the changeset viewer.