Ignore:
Timestamp:
Jan 19, 2022, 2:36:56 PM (4 years ago)
Author:
Michael Brooks <mlbrooks@…>
Branches:
ADT, ast-experimental, enum, master, pthread-emulation, qualifiedEnum, stuck-waitfor-destruct
Children:
97c215f
Parents:
5235d49 (diff), 6a33e40 (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:software/cfa/cfa-cc

Location:
libcfa/src/concurrency/kernel
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • libcfa/src/concurrency/kernel/fwd.hfa

    r5235d49 r12c1eef  
    7777
    7878                static inline uint64_t __tls_rand() {
     79                        return
    7980                        #if defined(__SIZEOF_INT128__)
    80                                 return __lehmer64( kernelTLS().rand_seed );
     81                                lehmer64( kernelTLS().rand_seed );
    8182                        #else
    82                                 return __xorshift64( kernelTLS().rand_seed );
     83                                xorshift_13_7_17( kernelTLS().rand_seed );
    8384                        #endif
    8485                }
    8586
    86                 #define M  (1_l64u << 48_l64u)
    87                 #define A  (25214903917_l64u)
    88                 #define AI (18446708753438544741_l64u)
    89                 #define C  (11_l64u)
    90                 #define D  (16_l64u)
    91 
    9287                static inline unsigned __tls_rand_fwd() {
    93 
    94                         kernelTLS().ready_rng.fwd_seed = (A * kernelTLS().ready_rng.fwd_seed + C) & (M - 1);
    95                         return kernelTLS().ready_rng.fwd_seed >> D;
     88                        return LCGBI_fwd( kernelTLS().ready_rng.fwd_seed );
    9689                }
    9790
    9891                static inline unsigned __tls_rand_bck() {
    99                         unsigned int r = kernelTLS().ready_rng.bck_seed >> D;
    100                         kernelTLS().ready_rng.bck_seed = AI * (kernelTLS().ready_rng.bck_seed - C) & (M - 1);
    101                         return r;
    102                 }
    103 
    104                 #undef M
    105                 #undef A
    106                 #undef AI
    107                 #undef C
    108                 #undef D
     92                        return LCGBI_bck( kernelTLS().ready_rng.bck_seed );
     93                }
    10994
    11095                static inline void __tls_rand_advance_bck(void) {
     
    11297                }
    11398        }
    114 
    115 
    11699
    117100        extern void disable_interrupts();
     
    142125                        }
    143126                }
    144 
    145                 extern uint64_t thread_rand();
    146127
    147128                // Semaphore which only supports a single thread
  • libcfa/src/concurrency/kernel/startup.cfa

    r5235d49 r12c1eef  
    3434#include "kernel_private.hfa"
    3535#include "startup.hfa"          // STARTUP_PRIORITY_XXX
     36#include "limits.hfa"
    3637#include "math.hfa"
    3738
     
    101102extern void __wake_proc(processor *);
    102103extern int cfa_main_returned;                                                   // from interpose.cfa
     104extern uint32_t __global_random_seed;
    103105
    104106//-----------------------------------------------------------------------------
     
    176178
    177179
    178 
    179180//=============================================================================================
    180181// Kernel Setup logic
     
    279280        // When its coroutine terminates, it return control to the mainThread
    280281        // which is currently here
     282        /* paranoid */ verify( !__atomic_load_n(&mainProcessor->do_terminate, __ATOMIC_ACQUIRE) );
    281283        __atomic_store_n(&mainProcessor->do_terminate, true, __ATOMIC_RELEASE);
     284        __wake_proc( mainProcessor );
    282285        __kernel_last_resume( __cfaabi_tls.this_processor );
    283286        mainThread->self_cor.state = Halted;
     
    403406
    404407        __cfaabi_tls.this_thread->curr_cor = dst;
    405         __stack_prepare( &dst->stack, 65000 );
     408        __stack_prepare( &dst->stack, DEFAULT_STACK_SIZE );
    406409        __cfactx_start(main, dst, this->runner, __cfactx_invoke_coroutine);
    407410
     
    487490        preferred = ready_queue_new_preferred();
    488491        last_proc = 0p;
     492        random_state = __global_random_seed;
    489493        #if defined( __CFA_WITH_VERIFY__ )
    490494                canary = 0x0D15EA5E0D15EA5Ep;
     
    511515        this.rdq.its = 0;
    512516        this.rdq.itr = 0;
    513         this.rdq.id  = -1u;
    514         this.rdq.target = -1u;
    515         this.rdq.last = -1u;
    516         this.rdq.cutoff = 0ull;
     517        this.rdq.id  = MAX;
     518        this.rdq.target = MAX;
     519        this.rdq.last = MAX;
     520        this.rdq.cpu = 0;
     521        // this.rdq.cutoff = 0ull;
    517522        do_terminate = false;
    518523        preemption_alarm = 0p;
     
    564569extern size_t __page_size;
    565570void ^?{}(processor & this) with( this ){
    566         if( ! __atomic_load_n(&do_terminate, __ATOMIC_ACQUIRE) ) {
    567                 __cfadbg_print_safe(runtime_core, "Kernel : core %p signaling termination\n", &this);
    568 
    569                 __atomic_store_n(&do_terminate, true, __ATOMIC_RELAXED);
     571        /* paranoid */ verify( !__atomic_load_n(&do_terminate, __ATOMIC_ACQUIRE) );
     572        __cfadbg_print_safe(runtime_core, "Kernel : core %p signaling termination\n", &this);
     573
     574        __atomic_store_n(&do_terminate, true, __ATOMIC_RELAXED);
     575        __disable_interrupts_checked();
    570576                __wake_proc( &this );
    571 
    572                 wait( terminated );
    573                 /* paranoid */ verify( active_processor() != &this);
    574         }
     577        __enable_interrupts_checked();
     578
     579        wait( terminated );
     580        /* paranoid */ verify( active_processor() != &this);
    575581
    576582        __destroy_pthread( kernel_thread, this.stack, 0p );
     
    682688        [this->unique_id, last_size] = ready_mutate_register();
    683689
     690                this->rdq.cpu = __kernel_getcpu();
     691
    684692                this->cltr->procs.total += 1u;
    685693                insert_last(this->cltr->procs.actives, *this);
     
    721729        check( pthread_attr_init( &attr ), "pthread_attr_init" ); // initialize attribute
    722730
    723         size_t stacksize;
    724         // default stack size, normally defined by shell limit
    725         check( pthread_attr_getstacksize( &attr, &stacksize ), "pthread_attr_getstacksize" );
    726         assert( stacksize >= PTHREAD_STACK_MIN );
     731        size_t stacksize = DEFAULT_STACK_SIZE;
    727732
    728733        void * stack;
     
    749754        #endif
    750755
    751 
    752756        check( pthread_attr_setstack( &attr, stack, stacksize ), "pthread_attr_setstack" );
    753 
    754757        check( pthread_create( pthread, &attr, start, arg ), "pthread_create" );
    755758        return stack;
Note: See TracChangeset for help on using the changeset viewer.