Ignore:
Timestamp:
Nov 6, 2020, 4:48:52 PM (5 years ago)
Author:
m3zulfiq <m3zulfiq@…>
Branches:
ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast-unique-expr, pthread-emulation, qualifiedEnum
Children:
75baaa3
Parents:
55acc3a (diff), 836c9925 (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

    r55acc3a r139775e  
    3535        extern "Cforall" {
    3636                extern __attribute__((aligned(128))) thread_local struct KernelThreadData {
    37                         struct $thread    * volatile this_thread;
    38                         struct processor  * volatile this_processor;
    39                         struct __stats_t  * volatile this_stats;
     37                        struct $thread          * volatile this_thread;
     38                        struct processor        * volatile this_processor;
     39                        struct __processor_id_t * volatile this_proc_id;
     40                        struct __stats_t        * volatile this_stats;
    4041
    4142                        struct {
     
    5455                                uint64_t bck_seed;
    5556                        } ready_rng;
    56                 } kernelTLS __attribute__ ((tls_model ( "initial-exec" )));
     57                } __cfaabi_tls __attribute__ ((tls_model ( "initial-exec" )));
    5758
     59                extern bool __preemption_enabled();
    5860
     61                static inline KernelThreadData & kernelTLS( void ) {
     62                        /* paranoid */ verify( ! __preemption_enabled() );
     63                        return __cfaabi_tls;
     64                }
     65
     66                extern uintptr_t __cfatls_get( unsigned long int member );
     67                // #define publicTLS_get( member ) ((typeof(__cfaabi_tls.member))__cfatls_get( __builtin_offsetof(KernelThreadData, member) ))
     68                #define publicTLS_get( member ) (__cfaabi_tls.member)
     69                // extern forall(otype T) T __cfatls_get( T * member, T value );
     70                // #define publicTLS_set( member, value ) __cfatls_set( (typeof(member)*)__builtin_offsetof(KernelThreadData, member), value );
    5971
    6072                static inline uint64_t __tls_rand() {
    6173                        #if defined(__SIZEOF_INT128__)
    62                                 return __lehmer64( kernelTLS.rand_seed );
     74                                return __lehmer64( kernelTLS().rand_seed );
    6375                        #else
    64                                 return __xorshift64( kernelTLS.rand_seed );
     76                                return __xorshift64( kernelTLS().rand_seed );
    6577                        #endif
    6678                }
     
    7486                static inline unsigned __tls_rand_fwd() {
    7587
    76                         kernelTLS.ready_rng.fwd_seed = (A * kernelTLS.ready_rng.fwd_seed + C) & (M - 1);
    77                         return kernelTLS.ready_rng.fwd_seed >> D;
     88                        kernelTLS().ready_rng.fwd_seed = (A * kernelTLS().ready_rng.fwd_seed + C) & (M - 1);
     89                        return kernelTLS().ready_rng.fwd_seed >> D;
    7890                }
    7991
    8092                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);
     93                        unsigned int r = kernelTLS().ready_rng.bck_seed >> D;
     94                        kernelTLS().ready_rng.bck_seed = AI * (kernelTLS().ready_rng.bck_seed - C) & (M - 1);
    8395                        return r;
    8496                }
     
    91103
    92104                static inline void __tls_rand_advance_bck(void) {
    93                         kernelTLS.ready_rng.bck_seed = kernelTLS.ready_rng.fwd_seed;
     105                        kernelTLS().ready_rng.bck_seed = kernelTLS().ready_rng.fwd_seed;
    94106                }
    95107        }
    96108
    97         #if 0 // def __ARM_ARCH
    98                 // function prototypes are only really used by these macros on ARM
    99                 void disable_global_interrupts();
    100                 void enable_global_interrupts();
    101109
    102                 #define TL_GET( member ) ( { __typeof__( kernelTLS.member ) target; \
    103                         disable_global_interrupts(); \
    104                         target = kernelTLS.member; \
    105                         enable_global_interrupts(); \
    106                         target; } )
    107                 #define TL_SET( member, value ) disable_global_interrupts(); \
    108                         kernelTLS.member = value; \
    109                         enable_global_interrupts();
    110         #else
    111                 #define TL_GET( member ) kernelTLS.member
    112                 #define TL_SET( member, value ) kernelTLS.member = value;
    113         #endif
    114110
    115111        extern void disable_interrupts();
     
    120116                extern void park( void );
    121117                extern void unpark( struct $thread * this );
    122                 static inline struct $thread * active_thread () { return TL_GET( this_thread ); }
     118                static inline struct $thread * active_thread () {
     119                        struct $thread * t = publicTLS_get( this_thread );
     120                        /* paranoid */ verify( t );
     121                        return t;
     122                }
    123123
    124124                extern bool force_yield( enum __Preemption_Reason );
     
    139139                #if !defined(__CFA_NO_STATISTICS__)
    140140                        static inline struct __stats_t * __tls_stats() {
    141                                 /* paranoid */ verify( ! kernelTLS.preemption_state.enabled );
    142                                 /* paranoid */ verify( kernelTLS.this_stats );
    143                                 return kernelTLS.this_stats;
     141                                /* paranoid */ verify( ! __preemption_enabled() );
     142                                /* paranoid */ verify( kernelTLS().this_stats );
     143                                return kernelTLS().this_stats;
    144144                        }
    145145
  • libcfa/src/concurrency/kernel/startup.cfa

    r55acc3a r139775e  
    118118//-----------------------------------------------------------------------------
    119119// Global state
    120 thread_local struct KernelThreadData kernelTLS __attribute__ ((tls_model ( "initial-exec" ))) @= {
     120thread_local struct KernelThreadData __cfaabi_tls __attribute__ ((tls_model ( "initial-exec" ))) @= {
    121121        NULL,                                                                                           // cannot use 0p
     122        NULL,
    122123        NULL,
    123124        NULL,
     
    155156// Kernel boot procedures
    156157static void __kernel_startup(void) {
    157         verify( ! kernelTLS.preemption_state.enabled );
     158        /* paranoid */ verify( ! __preemption_enabled() );
    158159        __cfadbg_print_safe(runtime_core, "Kernel : Starting\n");
    159160
     
    211212
    212213        //initialize the global state variables
    213         kernelTLS.this_processor = mainProcessor;
    214         kernelTLS.this_thread    = mainThread;
     214        __cfaabi_tls.this_processor = mainProcessor;
     215        __cfaabi_tls.this_proc_id   = (__processor_id_t*)mainProcessor;
     216        __cfaabi_tls.this_thread    = mainThread;
    215217
    216218        #if !defined( __CFA_NO_STATISTICS__ )
    217                 kernelTLS.this_stats = (__stats_t *)& storage_mainProcStats;
    218                 __init_stats( kernelTLS.this_stats );
     219                __cfaabi_tls.this_stats = (__stats_t *)& storage_mainProcStats;
     220                __init_stats( __cfaabi_tls.this_stats );
    219221        #endif
    220222
     
    227229        // Add the main thread to the ready queue
    228230        // once resume is called on mainProcessor->runner the mainThread needs to be scheduled like any normal thread
    229         __schedule_thread((__processor_id_t *)mainProcessor, mainThread);
     231        __schedule_thread(mainThread);
    230232
    231233        // SKULLDUGGERY: Force a context switch to the main processor to set the main thread's context to the current UNIX
    232234        // context. Hence, the main thread does not begin through __cfactx_invoke_thread, like all other threads. The trick here is that
    233235        // mainThread is on the ready queue when this call is made.
    234         __kernel_first_resume( kernelTLS.this_processor );
     236        __kernel_first_resume( __cfaabi_tls.this_processor );
    235237
    236238
     
    249251        __cfadbg_print_safe(runtime_core, "Kernel : Started\n--------------------------------------------------\n\n");
    250252
    251         verify( ! kernelTLS.preemption_state.enabled );
     253        /* paranoid */ verify( ! __preemption_enabled() );
    252254        enable_interrupts( __cfaabi_dbg_ctx );
    253         verify( TL_GET( preemption_state.enabled ) );
     255        /* paranoid */ verify( __preemption_enabled() );
     256
    254257}
    255258
     
    260263        mainCluster->io.ctxs = 0p;
    261264
    262         /* paranoid */ verify( TL_GET( preemption_state.enabled ) );
     265        /* paranoid */ verify( __preemption_enabled() );
    263266        disable_interrupts();
    264         /* paranoid */ verify( ! kernelTLS.preemption_state.enabled );
     267        /* paranoid */ verify( ! __preemption_enabled() );
    265268
    266269        __cfadbg_print_safe(runtime_core, "\n--------------------------------------------------\nKernel : Shutting down\n");
     
    270273        // which is currently here
    271274        __atomic_store_n(&mainProcessor->do_terminate, true, __ATOMIC_RELEASE);
    272         __kernel_last_resume( kernelTLS.this_processor );
     275        __kernel_last_resume( __cfaabi_tls.this_processor );
    273276        mainThread->self_cor.state = Halted;
    274277
     
    319322                __stats_t local_stats;
    320323                __init_stats( &local_stats );
    321                 kernelTLS.this_stats = &local_stats;
     324                __cfaabi_tls.this_stats = &local_stats;
    322325        #endif
    323326
    324327        processor * proc = (processor *) arg;
    325         kernelTLS.this_processor = proc;
    326         kernelTLS.this_thread    = 0p;
    327         kernelTLS.preemption_state.[enabled, disable_count] = [false, 1];
     328        __cfaabi_tls.this_processor = proc;
     329        __cfaabi_tls.this_proc_id   = (__processor_id_t*)proc;
     330        __cfaabi_tls.this_thread    = 0p;
     331        __cfaabi_tls.preemption_state.[enabled, disable_count] = [false, 1];
    328332        // SKULLDUGGERY: We want to create a context for the processor coroutine
    329333        // which is needed for the 2-step context switch. However, there is no reason
     
    337341
    338342        //Set global state
    339         kernelTLS.this_thread = 0p;
     343        __cfaabi_tls.this_thread = 0p;
    340344
    341345        //We now have a proper context from which to schedule threads
     
    367371        $coroutine * dst = get_coroutine(this->runner);
    368372
    369         verify( ! kernelTLS.preemption_state.enabled );
    370 
    371         kernelTLS.this_thread->curr_cor = dst;
     373        /* paranoid */ verify( ! __preemption_enabled() );
     374
     375        __cfaabi_tls.this_thread->curr_cor = dst;
    372376        __stack_prepare( &dst->stack, 65000 );
    373377        __cfactx_start(main, dst, this->runner, __cfactx_invoke_coroutine);
    374378
    375         verify( ! kernelTLS.preemption_state.enabled );
     379        /* paranoid */ verify( ! __preemption_enabled() );
    376380
    377381        dst->last = &src->self_cor;
     
    391395        /* paranoid */ verify(src->state == Active);
    392396
    393         verify( ! kernelTLS.preemption_state.enabled );
     397        /* paranoid */ verify( ! __preemption_enabled() );
    394398}
    395399
     
    399403        $coroutine * dst = get_coroutine(this->runner);
    400404
    401         verify( ! kernelTLS.preemption_state.enabled );
    402         verify( dst->starter == src );
    403         verify( dst->context.SP );
     405        /* paranoid */ verify( ! __preemption_enabled() );
     406        /* paranoid */ verify( dst->starter == src );
     407        /* paranoid */ verify( dst->context.SP );
    404408
    405409        // SKULLDUGGERY in debug the processors check that the
     
    543547
    544548                P( terminated );
    545                 verify( kernelTLS.this_processor != &this);
     549                /* paranoid */ verify( active_processor() != &this);
    546550        }
    547551
     
    693697#if defined(__CFA_WITH_VERIFY__)
    694698static bool verify_fwd_bck_rng(void) {
    695         kernelTLS.ready_rng.fwd_seed = 25214903917_l64u * (rdtscl() ^ (uintptr_t)&verify_fwd_bck_rng);
     699        __cfaabi_tls.ready_rng.fwd_seed = 25214903917_l64u * (rdtscl() ^ (uintptr_t)&verify_fwd_bck_rng);
    696700
    697701        unsigned values[10];
Note: See TracChangeset for help on using the changeset viewer.