Ignore:
Timestamp:
Aug 20, 2020, 11:48:15 PM (4 years ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast-unique-expr, pthread-emulation, qualifiedEnum
Children:
d685cb0
Parents:
67ca73e (diff), 013b028 (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:

fix conflicts

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

Legend:

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

    r67ca73e re67a82d  
    5050                                uint64_t rand_seed;
    5151                        #endif
     52                        struct {
     53                                uint64_t fwd_seed;
     54                                uint64_t bck_seed;
     55                        } ready_rng;
    5256                } kernelTLS __attribute__ ((tls_model ( "initial-exec" )));
     57
     58
    5359
    5460                static inline uint64_t __tls_rand() {
     
    5864                                return __xorshift64( kernelTLS.rand_seed );
    5965                        #endif
     66                }
     67
     68                #define M  (1_l64u << 48_l64u)
     69                #define A  (25214903917_l64u)
     70                #define AI (18446708753438544741_l64u)
     71                #define C  (11_l64u)
     72                #define D  (16_l64u)
     73
     74                static inline unsigned __tls_rand_fwd() {
     75
     76                        kernelTLS.ready_rng.fwd_seed = (A * kernelTLS.ready_rng.fwd_seed + C) & (M - 1);
     77                        return kernelTLS.ready_rng.fwd_seed >> D;
     78                }
     79
     80                static inline unsigned __tls_rand_bck() {
     81                        unsigned int r = kernelTLS.ready_rng.bck_seed >> D;
     82                        kernelTLS.ready_rng.bck_seed = AI * (kernelTLS.ready_rng.bck_seed - C) & (M - 1);
     83                        return r;
     84                }
     85
     86                #undef M
     87                #undef A
     88                #undef AI
     89                #undef C
     90                #undef D
     91
     92                static inline void __tls_rand_advance_bck(void) {
     93                        kernelTLS.ready_rng.bck_seed = kernelTLS.ready_rng.fwd_seed;
    6094                }
    6195        }
  • libcfa/src/concurrency/kernel/startup.cfa

    r67ca73e re67a82d  
    7878static void ?{}(processorCtx_t & this, processor * proc, current_stack_info_t * info);
    7979
     80#if defined(__CFA_WITH_VERIFY__)
     81        static bool verify_fwd_bck_rng(void);
     82#endif
     83
    8084//-----------------------------------------------------------------------------
    8185// Forward Declarations for other modules
     
    8791//-----------------------------------------------------------------------------
    8892// Other Forward Declarations
    89 extern bool __wake_proc(processor *);
     93extern void __wake_proc(processor *);
    9094
    9195//-----------------------------------------------------------------------------
     
    158162        __cfa_dbg_global_clusters.list{ __get };
    159163        __cfa_dbg_global_clusters.lock{};
     164
     165        /* paranoid */ verify( verify_fwd_bck_rng() );
    160166
    161167        // Initialize the global scheduler lock
     
    475481        #endif
    476482
    477         int target = __atomic_add_fetch( &cltr->nprocessors, 1u, __ATOMIC_SEQ_CST );
     483        lock( this.cltr->idles );
     484                int target = this.cltr->idles.total += 1u;
     485        unlock( this.cltr->idles );
    478486
    479487        id = doregister((__processor_id_t*)&this);
     
    493501// Not a ctor, it just preps the destruction but should not destroy members
    494502static void deinit(processor & this) {
    495 
    496         int target = __atomic_sub_fetch( &this.cltr->nprocessors, 1u, __ATOMIC_SEQ_CST );
     503        lock( this.cltr->idles );
     504                int target = this.cltr->idles.total -= 1u;
     505        unlock( this.cltr->idles );
    497506
    498507        // Lock the RWlock so no-one pushes/pops while we are changing the queue
     
    501510                // Adjust the ready queue size
    502511                ready_queue_shrink( this.cltr, target );
    503 
    504                 // Make sure we aren't on the idle queue
    505                 unsafe_remove( this.cltr->idles, &this );
    506512
    507513        // Unlock the RWlock
     
    516522        ( this.terminated ){ 0 };
    517523        ( this.runner ){};
    518         init( this, name, _cltr );
     524
     525        disable_interrupts();
     526                init( this, name, _cltr );
     527        enable_interrupts( __cfaabi_dbg_ctx );
    519528
    520529        __cfadbg_print_safe(runtime_core, "Kernel : Starting core %p\n", &this);
     
    540549        free( this.stack );
    541550
    542         deinit( this );
     551        disable_interrupts();
     552                deinit( this );
     553        enable_interrupts( __cfaabi_dbg_ctx );
    543554}
    544555
    545556//-----------------------------------------------------------------------------
    546557// Cluster
     558static void ?{}(__cluster_idles & this) {
     559        this.lock  = 0;
     560        this.idle  = 0;
     561        this.total = 0;
     562        (this.list){};
     563}
     564
    547565void ?{}(cluster & this, const char name[], Duration preemption_rate, unsigned num_io, const io_context_params & io_params) with( this ) {
    548566        this.name = name;
    549567        this.preemption_rate = preemption_rate;
    550         this.nprocessors = 0;
    551568        ready_queue{};
    552569
     
    666683        return stack;
    667684}
     685
     686#if defined(__CFA_WITH_VERIFY__)
     687static bool verify_fwd_bck_rng(void) {
     688        kernelTLS.ready_rng.fwd_seed = 25214903917_l64u * (rdtscl() ^ (uintptr_t)&verify_fwd_bck_rng);
     689
     690        unsigned values[10];
     691        for(i; 10) {
     692                values[i] = __tls_rand_fwd();
     693        }
     694
     695        __tls_rand_advance_bck();
     696
     697        for ( i; 9 -~= 0 ) {
     698                if(values[i] != __tls_rand_bck()) {
     699                        return false;
     700                }
     701        }
     702
     703        return true;
     704}
     705#endif
Note: See TracChangeset for help on using the changeset viewer.