Ignore:
Timestamp:
Nov 30, 2022, 10:36:25 PM (3 years ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
ADT, ast-experimental, master
Children:
5657de9, c8238c0
Parents:
be1d00c
Message:

generalization of PRNG

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

Legend:

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

    rbe1d00c rdd46fd3  
    4646                        } preemption_state;
    4747
    48                         #if defined(__SIZEOF_INT128__)
    49                                 __uint128_t rand_seed;
    50                         #else
    51                                 uint64_t rand_seed;
    52                         #endif
     48                        PRNG_STATE_T random_state;
     49
    5350                        struct {
    5451                                uint64_t fwd_seed;
     
    5754
    5855                        struct __stats_t        * volatile this_stats;
    59 
    6056
    6157                        #ifdef __CFA_WITH_VERIFY__
     
    7672                #define publicTLS_get( member ) ((typeof(__cfaabi_tls.member))__cfatls_get( __builtin_offsetof(KernelThreadData, member) ))
    7773
    78                 static inline uint64_t __tls_rand() {
    79                         return
    80                         #if defined(__SIZEOF_INT128__)
    81                                 lehmer64( kernelTLS().rand_seed );
    82                         #else
    83                                 xorshift_13_7_17( kernelTLS().rand_seed );
    84                         #endif
     74                static inline
     75                        #ifdef __x86_64__                                                       // 64-bit architecture
     76                        uint64_t
     77                        #else                                                                           // 32-bit architecture
     78                        uint32_t
     79                        #endif // __x86_64__
     80                __tls_rand() {
     81                        return PRNG_NAME( kernelTLS().random_state );
    8582                }
    8683
  • libcfa/src/concurrency/kernel/startup.cfa

    rbe1d00c rdd46fd3  
    108108extern void __wake_proc(processor *);
    109109extern int cfa_main_returned;                                                   // from interpose.cfa
    110 PRNG_ARG_T __global_random_prime = 4_294_967_291u;
     110size_t __global_random_prime = 4_294_967_291u;
    111111bool __global_random_mask = false;
    112112
     
    135135// Global state
    136136__thread struct KernelThreadData __cfaabi_tls __attribute__ ((tls_model ( "initial-exec" ))) @= {
    137         NULL,                                                                                           // cannot use 0p
    138         NULL,
    139         false,
    140         { 1, false, false },
    141         0,
    142         { 0, 0 },
    143         NULL,
     137        .this_thread : NULL,                                                            // cannot use 0p
     138        .this_processor : NULL,
     139        .sched_lock : false,
     140        .preemption_state : { .disable_count : 1, .enabled : false, .in_progress : false },
     141        // random_state uninitialized
     142        .ready_rng : { .fwd_seed : 0, .bck_seed : 0 },
     143        .this_stats : NULL,
    144144        #ifdef __CFA_WITH_VERIFY__
    145                 false,
    146                 0,
     145                .in_sched_lock : false,
     146                .sched_id : 0,
    147147        #endif
    148148};
     
    521521        preferred = ready_queue_new_preferred();
    522522        last_proc = 0p;
    523         random_state = __global_random_mask ? __global_random_prime : __global_random_prime ^ rdtscl();
     523        PRNG_SET_SEED( random_state,  __global_random_mask ? __global_random_prime : __global_random_prime ^ rdtscl() );
    524524        #if defined( __CFA_WITH_VERIFY__ )
    525525                executing = 0p;
Note: See TracChangeset for help on using the changeset viewer.