Ignore:
Timestamp:
Feb 20, 2020, 4:15:51 PM (6 years ago)
Author:
Thierry Delisle <tdelisle@…>
Branches:
ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum
Children:
6a490b2
Parents:
dca5802 (diff), 2cbfe92 (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' into relaxed_ready

Location:
libcfa/src/concurrency
Files:
11 edited

Legend:

Unmodified
Added
Removed
  • libcfa/src/concurrency/CtxSwitch-x86_64.S

    rdca5802 rb7d6a36  
    8787CtxInvokeStub:
    8888        movq %rbx, %rdi
    89         jmp *%r12
     89        movq %r12, %rsi
     90        jmp *%r13
    9091        .size  CtxInvokeStub, .-CtxInvokeStub
    9192
  • libcfa/src/concurrency/alarm.cfa

    rdca5802 rb7d6a36  
    1010// Created On       : Fri Jun 2 11:31:25 2017
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Tue Dec  3 22:47:24 2019
    13 // Update Count     : 68
     12// Last Modified On : Sun Jan  5 08:41:36 2020
     13// Update Count     : 69
    1414//
    1515
     
    3939
    4040void __kernel_set_timer( Duration alarm ) {
    41         verifyf(alarm >= 1`us || alarm == 0, "Setting timer to < 1us (%jins)", alarm.tv);
     41        verifyf(alarm >= 1`us || alarm == 0, "Setting timer to < 1us (%jins)", alarm`ns);
    4242        setitimer( ITIMER_REAL, &(itimerval){ alarm }, 0p );
    4343}
  • libcfa/src/concurrency/coroutine.cfa

    rdca5802 rb7d6a36  
    1010// Created On       : Mon Nov 28 12:27:26 2016
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Thu Dec  5 14:37:29 2019
    13 // Update Count     : 15
     12// Last Modified On : Tue Feb  4 12:29:25 2020
     13// Update Count     : 16
    1414//
    1515
     
    8989}
    9090
    91 void ?{}( coroutine_desc & this, const char * name, void * storage, size_t storageSize ) with( this ) {
     91void ?{}( coroutine_desc & this, const char name[], void * storage, size_t storageSize ) with( this ) {
    9292        (this.context){0p, 0p};
    9393        (this.stack){storage, storageSize};
     
    187187// is not inline (We can't inline Cforall in C)
    188188extern "C" {
    189         void __suspend_internal(void) {
    190                 suspend();
    191         }
    192 
    193         void __leave_coroutine( coroutine_desc * src ) {
     189        void __leave_coroutine( struct coroutine_desc * src ) {
    194190                coroutine_desc * starter = src->cancellation != 0 ? src->last : src->starter;
    195191
     
    207203                CoroutineCtxSwitch( src, starter );
    208204        }
     205
     206        struct coroutine_desc * __finish_coroutine(void) {
     207                struct coroutine_desc * cor = kernelTLS.this_thread->curr_cor;
     208
     209                if(cor->state == Primed) {
     210                        suspend();
     211                }
     212
     213                cor->state = Active;
     214
     215                return cor;
     216        }
    209217}
    210218
  • libcfa/src/concurrency/coroutine.hfa

    rdca5802 rb7d6a36  
    1010// Created On       : Mon Nov 28 12:27:26 2016
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Tue Dec  3 22:47:58 2019
    13 // Update Count     : 10
     12// Last Modified On : Tue Feb  4 12:29:26 2020
     13// Update Count     : 11
    1414//
    1515
     
    3535// void ^?{}( coStack_t & this );
    3636
    37 void ?{}( coroutine_desc & this, const char * name, void * storage, size_t storageSize );
     37void ?{}( coroutine_desc & this, const char name[], void * storage, size_t storageSize );
    3838void ^?{}( coroutine_desc & this );
    3939
     
    4141static inline void ?{}( coroutine_desc & this, size_t stackSize)                     { this{ "Anonymous Coroutine", 0p, stackSize }; }
    4242static inline void ?{}( coroutine_desc & this, void * storage, size_t storageSize )  { this{ "Anonymous Coroutine", storage, storageSize }; }
    43 static inline void ?{}( coroutine_desc & this, const char * name)                    { this{ name, 0p, 0 }; }
    44 static inline void ?{}( coroutine_desc & this, const char * name, size_t stackSize ) { this{ name, 0p, stackSize }; }
     43static inline void ?{}( coroutine_desc & this, const char name[])                    { this{ name, 0p, 0 }; }
     44static inline void ?{}( coroutine_desc & this, const char name[], size_t stackSize ) { this{ name, 0p, stackSize }; }
    4545
    4646//-----------------------------------------------------------------------------
     
    6161// Start coroutine routines
    6262extern "C" {
    63       forall(dtype T | is_coroutine(T))
    64       void CtxInvokeCoroutine(T * this);
     63        void CtxInvokeCoroutine(void (*main)(void *), void * this);
    6564
    66       forall(dtype T | is_coroutine(T))
    67       void CtxStart(T * this, void ( *invoke)(T *));
     65        forall(dtype T)
     66        void CtxStart(void (*main)(T &), struct coroutine_desc * cor, T & this, void (*invoke)(void (*main)(void *), void *));
    6867
    6968        extern void _CtxCoroutine_Unwind(struct _Unwind_Exception * storage, struct coroutine_desc *) __attribute__ ((__noreturn__));
     
    129128
    130129        if( unlikely(dst->context.SP == 0p) ) {
     130                TL_GET( this_thread )->curr_cor = dst;
    131131                __stack_prepare(&dst->stack, 65000);
    132                 CtxStart(&cor, CtxInvokeCoroutine);
     132                CtxStart(main, dst, cor, CtxInvokeCoroutine);
     133                TL_GET( this_thread )->curr_cor = src;
    133134        }
    134135
  • libcfa/src/concurrency/invoke.c

    rdca5802 rb7d6a36  
    2929// Called from the kernel when starting a coroutine or task so must switch back to user mode.
    3030
    31 extern void __suspend_internal(void);
    32 extern void __leave_coroutine( struct coroutine_desc * );
    33 extern void __finish_creation( struct thread_desc * );
    34 extern void __leave_thread_monitor( struct thread_desc * this );
     31extern void __leave_coroutine ( struct coroutine_desc * );
     32extern struct coroutine_desc * __finish_coroutine(void);
     33extern void __leave_thread_monitor();
    3534extern void disable_interrupts() OPTIONAL_THREAD;
    3635extern void enable_interrupts( __cfaabi_dbg_ctx_param );
     
    3837void CtxInvokeCoroutine(
    3938        void (*main)(void *),
    40         struct coroutine_desc *(*get_coroutine)(void *),
    4139        void *this
    4240) {
    43         struct coroutine_desc* cor = get_coroutine( this );
     41        // Finish setting up the coroutine by setting its state
     42        struct coroutine_desc * cor = __finish_coroutine();
    4443
    45         if(cor->state == Primed) {
    46                 __suspend_internal();
    47         }
    48 
    49         cor->state = Active;
    50 
     44        // Call the main of the coroutine
    5145        main( this );
    5246
     
    8377
    8478void CtxInvokeThread(
    85         void (*dtor)(void *),
    8679        void (*main)(void *),
    87         struct thread_desc *(*get_thread)(void *),
    8880        void *this
    8981) {
    90         // Fetch the thread handle from the user defined thread structure
    91         struct thread_desc* thrd = get_thread( this );
    92 
    93         // First suspend, once the thread arrives here,
    94         // the function pointer to main can be invalidated without risk
    95         __finish_creation( thrd );
    96 
    9782        // Officially start the thread by enabling preemption
    9883        enable_interrupts( __cfaabi_dbg_ctx );
     
    10893        // The order of these 4 operations is very important
    10994        //Final suspend, should never return
    110         __leave_thread_monitor( thrd );
     95        __leave_thread_monitor();
    11196        __cabi_abort( "Resumed dead thread" );
    11297}
    11398
    114 
    11599void CtxStart(
    116100        void (*main)(void *),
    117         struct coroutine_desc *(*get_coroutine)(void *),
     101        struct coroutine_desc * cor,
    118102        void *this,
    119103        void (*invoke)(void *)
    120104) {
    121         struct coroutine_desc * cor = get_coroutine( this );
    122105        struct __stack_t * stack = cor->stack.storage;
    123106
     
    138121
    139122        fs->dummyReturn = NULL;
    140         fs->argument[0] = this;     // argument to invoke
     123        fs->argument[0] = main;     // argument to invoke
     124        fs->argument[1] = this;     // argument to invoke
    141125        fs->rturn = invoke;
    142126
     
    156140        fs->dummyReturn = NULL;
    157141        fs->rturn = CtxInvokeStub;
    158         fs->fixedRegisters[0] = this;
    159         fs->fixedRegisters[1] = invoke;
     142        fs->fixedRegisters[0] = main;
     143        fs->fixedRegisters[1] = this;
     144        fs->fixedRegisters[2] = invoke;
    160145
    161146#elif defined( __ARM_ARCH )
    162 
     147#error ARM needs to be upgrade to use to parameters like X86/X64 (A.K.A. : I broke this and do not know how to fix it)
    163148        struct FakeStack {
    164149                float fpRegs[16];                       // floating point registers
  • libcfa/src/concurrency/kernel.cfa

    rdca5802 rb7d6a36  
    1010// Created On       : Tue Jan 17 12:27:26 2017
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Thu Dec  5 16:25:52 2019
    13 // Update Count     : 52
     12// Last Modified On : Tue Feb  4 13:03:15 2020
     13// Update Count     : 58
    1414//
    1515
     
    210210
    211211static void start(processor * this);
    212 void ?{}(processor & this, const char * name, cluster & cltr) with( this ) {
     212void ?{}(processor & this, const char name[], cluster & cltr) with( this ) {
    213213        this.name = name;
    214214        this.cltr = &cltr;
     
    240240}
    241241
    242 void ?{}(cluster & this, const char * name, Duration preemption_rate) with( this ) {
     242void ?{}(cluster & this, const char name[], Duration preemption_rate) with( this ) {
    243243        this.name = name;
    244244        this.preemption_rate = preemption_rate;
     
    454454}
    455455
    456 static void Abort( int ret, const char * func ) {
     456static void Abort( int ret, const char func[] ) {
    457457        if ( ret ) {                                                                            // pthread routines return errno values
    458458                abort( "%s : internal error, error(%d) %s.", func, ret, strerror( ret ) );
     
    503503        verify( ! kernelTLS.preemption_state.enabled );
    504504
     505        kernelTLS.this_thread->curr_cor = dst;
    505506        __stack_prepare( &dst->stack, 65000 );
    506         CtxStart(&this->runner, CtxInvokeCoroutine);
     507        CtxStart(main, dst, this->runner, CtxInvokeCoroutine);
    507508
    508509        verify( ! kernelTLS.preemption_state.enabled );
     
    518519        CtxSwitch( &src->context, &dst->context );
    519520        // when CtxSwitch returns we are back in the src coroutine
     521
     522        mainThread->curr_cor = &mainThread->self_cor;
    520523
    521524        // set state of new coroutine to active
     
    864867                sigemptyset( &mask );
    865868                sigaddset( &mask, SIGALRM );            // block SIGALRM signals
    866                 sigsuspend( &mask );                    // block the processor to prevent further damage during abort
    867                 _exit( EXIT_FAILURE );                  // if processor unblocks before it is killed, terminate it
     869                sigaddset( &mask, SIGUSR1 );            // block SIGALRM signals
     870                sigsuspend( &mask );                            // block the processor to prevent further damage during abort
     871                _exit( EXIT_FAILURE );                          // if processor unblocks before it is killed, terminate it
    868872        }
    869873        else {
     
    986990__cfaabi_dbg_debug_do(
    987991        extern "C" {
    988                 void __cfaabi_dbg_record(__spinlock_t & this, const char * prev_name) {
     992                void __cfaabi_dbg_record(__spinlock_t & this, const char prev_name[]) {
    989993                        this.prev_name = prev_name;
    990994                        this.prev_thrd = kernelTLS.this_thread;
  • libcfa/src/concurrency/kernel.hfa

    rdca5802 rb7d6a36  
    1010// Created On       : Tue Jan 17 12:27:26 2017
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Wed Dec  4 07:54:51 2019
    13 // Update Count     : 18
     12// Last Modified On : Tue Feb  4 12:29:26 2020
     13// Update Count     : 22
    1414//
    1515
     
    151151};
    152152
    153 void  ?{}(processor & this, const char * name, struct cluster & cltr);
     153void  ?{}(processor & this, const char name[], struct cluster & cltr);
    154154void ^?{}(processor & this);
    155155
    156156static inline void  ?{}(processor & this)                    { this{ "Anonymous Processor", *mainCluster}; }
    157157static inline void  ?{}(processor & this, struct cluster & cltr)    { this{ "Anonymous Processor", cltr}; }
    158 static inline void  ?{}(processor & this, const char * name) { this{name, *mainCluster }; }
     158static inline void  ?{}(processor & this, const char name[]) { this{name, *mainCluster }; }
    159159
    160160static inline [processor *&, processor *& ] __get( processor & this ) {
     
    344344extern Duration default_preemption();
    345345
    346 void ?{} (cluster & this, const char * name, Duration preemption_rate);
     346void ?{} (cluster & this, const char name[], Duration preemption_rate);
    347347void ^?{}(cluster & this);
    348348
    349349static inline void ?{} (cluster & this)                           { this{"Anonymous Cluster", default_preemption()}; }
    350350static inline void ?{} (cluster & this, Duration preemption_rate) { this{"Anonymous Cluster", preemption_rate}; }
    351 static inline void ?{} (cluster & this, const char * name)        { this{name, default_preemption()}; }
     351static inline void ?{} (cluster & this, const char name[])        { this{name, default_preemption()}; }
    352352
    353353static inline [cluster *&, cluster *& ] __get( cluster & this ) {
  • libcfa/src/concurrency/kernel_private.hfa

    rdca5802 rb7d6a36  
    8888// Threads
    8989extern "C" {
    90       forall(dtype T | is_thread(T))
    91       void CtxInvokeThread(T * this);
     90      void CtxInvokeThread(void (*main)(void *), void * this);
    9291}
    9392
  • libcfa/src/concurrency/monitor.cfa

    rdca5802 rb7d6a36  
    243243        // last routine called by a thread.
    244244        // Should never return
    245         void __leave_thread_monitor( thread_desc * thrd ) {
     245        void __leave_thread_monitor() {
     246                thread_desc * thrd = TL_GET( this_thread );
    246247                monitor_desc * this = &thrd->self_mon;
    247248
  • libcfa/src/concurrency/thread.cfa

    rdca5802 rb7d6a36  
    5959void ?{}( scoped(T)& this ) with( this ) {
    6060        handle{};
    61         __thrd_start(handle);
     61        __thrd_start(handle, main);
    6262}
    6363
     
    6565void ?{}( scoped(T)& this, P params ) with( this ) {
    6666        handle{ params };
    67         __thrd_start(handle);
     67        __thrd_start(handle, main);
    6868}
    6969
     
    7676// Starting and stopping threads
    7777forall( dtype T | is_thread(T) )
    78 void __thrd_start( T& this ) {
     78void __thrd_start( T & this, void (*main_p)(T &) ) {
    7979        thread_desc * this_thrd = get_thread(this);
    80         thread_desc * curr_thrd = TL_GET( this_thread );
    8180
    8281        disable_interrupts();
    83         CtxStart(&this, CtxInvokeThread);
     82        CtxStart(main_p, get_coroutine(this), this, CtxInvokeThread);
     83
    8484        this_thrd->context.[SP, FP] = this_thrd->self_cor.context.[SP, FP];
    8585        verify( this_thrd->context.SP );
    86         CtxSwitch( &curr_thrd->context, &this_thrd->context );
    8786
    8887        ScheduleThread(this_thrd);
    8988        enable_interrupts( __cfaabi_dbg_ctx );
    90 }
    91 
    92 extern "C" {
    93         // KERNEL ONLY
    94         void __finish_creation(thread_desc * this) {
    95                 // set new coroutine that the processor is executing
    96                 // and context switch to it
    97                 verify( kernelTLS.this_thread != this );
    98                 verify( kernelTLS.this_thread->context.SP );
    99                 CtxSwitch( &this->context, &kernelTLS.this_thread->context );
    100         }
    10189}
    10290
  • libcfa/src/concurrency/thread.hfa

    rdca5802 rb7d6a36  
    5454
    5555forall( dtype T | is_thread(T) )
    56 void __thrd_start( T & this );
     56void __thrd_start( T & this, void (*)(T &) );
    5757
    5858//-----------------------------------------------------------------------------
Note: See TracChangeset for help on using the changeset viewer.