Changeset f32e53e


Ignore:
Timestamp:
Jul 7, 2017, 11:55:32 AM (4 years ago)
Author:
Thierry Delisle <tdelisle@…>
Branches:
aaron-thesis, arm-eh, cleanup-dtors, deferred_resn, demangler, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, resolv-new, with_gc
Children:
3f12158
Parents:
b5f9829
Message:

Converted CtxGet? from asm function to asm statement for more robustness, should fix full build

Location:
src/libcfa/concurrency
Files:
4 edited

Legend:

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

    rb5f9829 rf32e53e  
    9898        ret
    9999
    100 .text
    101         .align 2
    102 .globl  CtxGet
    103 CtxGet:
    104         movl %esp,SP_OFFSET(%eax)
    105         movl %ebp,FP_OFFSET(%eax)
    106 
    107         ret
    108 
    109100// Local Variables: //
    110101// compile-command: "make install" //
  • src/libcfa/concurrency/CtxSwitch-x86_64.S

    rb5f9829 rf32e53e  
    1 //                               -*- Mode: Asm -*- 
     1//                               -*- Mode: Asm -*-
    22//
    33// Cforall Version 1.0.0 Copyright (C) 2016 University of Waterloo
     
    1818// Free Software  Foundation; either  version 2.1 of  the License, or  (at your
    1919// option) any later version.
    20 // 
     20//
    2121// This library is distributed in the  hope that it will be useful, but WITHOUT
    2222// ANY  WARRANTY;  without even  the  implied  warranty  of MERCHANTABILITY  or
    2323// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License
    2424// for more details.
    25 // 
     25//
    2626// You should  have received a  copy of the  GNU Lesser General  Public License
    2727// along  with this library.
    28 // 
     28//
    2929
    3030// This context switch routine depends on the fact that the stack of a new
     
    9393.globl  CtxInvokeStub
    9494CtxInvokeStub:
    95         movq %rbx, %rdi 
     95        movq %rbx, %rdi
    9696        jmp *%r12
    97 
    98 .text
    99         .align 2
    100 .globl  CtxGet
    101 CtxGet:
    102         movq %rsp,SP_OFFSET(%rdi)
    103         movq %rbp,FP_OFFSET(%rdi)
    104 
    105         ret
    10697
    10798// Local Variables: //
  • src/libcfa/concurrency/invoke.h

    rb5f9829 rf32e53e  
    9999#ifndef _INVOKE_PRIVATE_H_
    100100#define _INVOKE_PRIVATE_H_
    101      
     101
    102102      struct machine_context_t {
    103103            void *SP;
     
    109109      extern void CtxInvokeStub( void );
    110110      void CtxSwitch( void * from, void * to ) asm ("CtxSwitch");
    111       void CtxGet( void * this ) asm ("CtxGet");
     111
     112      #if   defined( __x86_64__ )
     113      #define CtxGet( ctx ) __asm__ ( \
     114                  "movq %%rsp,%0\n"   \
     115                  "movq %%rbp,%1\n"   \
     116            : "=rm" (ctx.SP), "=rm" (ctx.FP) )
     117      #elif defined( __i386__ )
     118      #define CtxGet( ctx ) __asm__ ( \
     119                  "movl %%esp,%0\n"   \
     120                  "movl %%ebp,%1\n"   \
     121            : "=rm" (ctx.SP), "=rm" (ctx.FP) )
     122      #endif
    112123
    113124#endif //_INVOKE_PRIVATE_H_
  • src/libcfa/concurrency/kernel.c

    rb5f9829 rf32e53e  
    7272// Main thread construction
    7373struct current_stack_info_t {
    74         machine_context_t ctx; 
     74        machine_context_t ctx;
    7575        unsigned int size;              // size of stack
    7676        void *base;                             // base of stack
     
    8282
    8383void ?{}( current_stack_info_t * this ) {
    84         CtxGet( &this->ctx );
     84        CtxGet( this->ctx );
    8585        this->base = this->ctx.FP;
    8686        this->storage = this->ctx.SP;
     
    106106
    107107void ?{}( coroutine_desc * this, current_stack_info_t * info) {
    108         (&this->stack){ info }; 
     108        (&this->stack){ info };
    109109        this->name = "Main Thread";
    110110        this->errno_ = 0;
     
    184184
    185185void ^?{}(cluster * this) {
    186        
     186
    187187}
    188188
     
    203203
    204204                thread_desc * readyThread = NULL;
    205                 for( unsigned int spin_count = 0; ! this->is_terminated; spin_count++ ) 
     205                for( unsigned int spin_count = 0; ! this->is_terminated; spin_count++ )
    206206                {
    207207                        readyThread = nextThread( this->cltr );
     
    229229}
    230230
    231 // runThread runs a thread by context switching 
    232 // from the processor coroutine to the target thread 
     231// runThread runs a thread by context switching
     232// from the processor coroutine to the target thread
    233233void runThread(processor * this, thread_desc * dst) {
    234234        coroutine_desc * proc_cor = get_coroutine(this->runner);
    235235        coroutine_desc * thrd_cor = get_coroutine(dst);
    236        
     236
    237237        //Reset the terminating actions here
    238238        this->finish.action_code = No_Action;
     
    246246}
    247247
    248 // Once a thread has finished running, some of 
     248// Once a thread has finished running, some of
    249249// its final actions must be executed from the kernel
    250250void finishRunning(processor * this) {
     
    256256        }
    257257        else if( this->finish.action_code == Release_Schedule ) {
    258                 unlock( this->finish.lock );           
     258                unlock( this->finish.lock );
    259259                ScheduleThread( this->finish.thrd );
    260260        }
     
    291291        // SKULLDUGGERY: We want to create a context for the processor coroutine
    292292        // which is needed for the 2-step context switch. However, there is no reason
    293         // to waste the perfectly valid stack create by pthread. 
     293        // to waste the perfectly valid stack create by pthread.
    294294        current_stack_info_t info;
    295295        machine_context_t ctx;
     
    306306        LIB_DEBUG_PRINT_SAFE("Kernel : core %p created (%p, %p)\n", proc, proc->runner, &ctx);
    307307
    308         // SKULLDUGGERY: Since the coroutine doesn't have its own stack, we can't 
    309         // resume it to start it like it normally would, it will just context switch 
    310         // back to here. Instead directly call the main since we already are on the 
     308        // SKULLDUGGERY: Since the coroutine doesn't have its own stack, we can't
     309        // resume it to start it like it normally would, it will just context switch
     310        // back to here. Instead directly call the main since we already are on the
    311311        // appropriate stack.
    312312        proc_cor_storage.__cor.state = Active;
     
    315315
    316316        // Main routine of the core returned, the core is now fully terminated
    317         LIB_DEBUG_PRINT_SAFE("Kernel : core %p main ended (%p)\n", proc, proc->runner); 
     317        LIB_DEBUG_PRINT_SAFE("Kernel : core %p main ended (%p)\n", proc, proc->runner);
    318318
    319319        return NULL;
     
    322322void start(processor * this) {
    323323        LIB_DEBUG_PRINT_SAFE("Kernel : Starting core %p\n", this);
    324        
     324
    325325        pthread_create( &this->kernel_thread, NULL, CtxInvokeProcessor, (void*)this );
    326326
    327         LIB_DEBUG_PRINT_SAFE("Kernel : core %p started\n", this);       
     327        LIB_DEBUG_PRINT_SAFE("Kernel : core %p started\n", this);
    328328}
    329329
     
    334334
    335335        verifyf( thrd->next == NULL, "Expected null got %p", thrd->next );
    336        
     336
    337337        lock( &systemProcessor->proc.cltr->lock );
    338338        append( &systemProcessor->proc.cltr->ready_queue, thrd );
     
    392392// Kernel boot procedures
    393393void kernel_startup(void) {
    394         LIB_DEBUG_PRINT_SAFE("Kernel : Starting\n");   
     394        LIB_DEBUG_PRINT_SAFE("Kernel : Starting\n");
    395395
    396396        // Start by initializing the main thread
    397         // SKULLDUGGERY: the mainThread steals the process main thread 
     397        // SKULLDUGGERY: the mainThread steals the process main thread
    398398        // which will then be scheduled by the systemProcessor normally
    399399        mainThread = (thread_desc *)&mainThread_storage;
     
    417417        systemProcessor{ systemCluster, (processorCtx_t *)&systemProcessorCtx_storage };
    418418
    419         // Add the main thread to the ready queue 
     419        // Add the main thread to the ready queue
    420420        // once resume is called on systemProcessor->runner the mainThread needs to be scheduled like any normal thread
    421421        ScheduleThread(mainThread);
     
    428428        // SKULLDUGGERY: Force a context switch to the system processor to set the main thread's context to the current UNIX
    429429        // context. Hence, the main thread does not begin through CtxInvokeThread, like all other threads. The trick here is that
    430         // mainThread is on the ready queue when this call is made. 
     430        // mainThread is on the ready queue when this call is made.
    431431        resume( systemProcessor->proc.runner );
    432432
     
    457457        ^(mainThread){};
    458458
    459         LIB_DEBUG_PRINT_SAFE("Kernel : Shutdown complete\n");   
     459        LIB_DEBUG_PRINT_SAFE("Kernel : Shutdown complete\n");
    460460}
    461461
     
    473473                kernel_abort_called = true;
    474474                unlock( &kernel_abort_lock );
    475         } 
     475        }
    476476        else {
    477477                unlock( &kernel_abort_lock );
    478                
     478
    479479                sigset_t mask;
    480480                sigemptyset( &mask );
     
    482482                sigaddset( &mask, SIGUSR1 );                    // block SIGUSR1 signals
    483483                sigsuspend( &mask );                            // block the processor to prevent further damage during abort
    484                 _exit( EXIT_FAILURE );                          // if processor unblocks before it is killed, terminate it             
     484                _exit( EXIT_FAILURE );                          // if processor unblocks before it is killed, terminate it
    485485        }
    486486
     
    497497                len = snprintf( abort_text, abort_text_size, " in coroutine %.256s (%p).\n", this_coroutine()->name, this_coroutine() );
    498498                __lib_debug_write( STDERR_FILENO, abort_text, len );
    499         } 
     499        }
    500500        else {
    501501                __lib_debug_write( STDERR_FILENO, ".\n", 2 );
     
    590590                }
    591591                head->next = NULL;
    592         }       
     592        }
    593593        return head;
    594594}
     
    609609                this->top = top->next;
    610610                top->next = NULL;
    611         }       
     611        }
    612612        return top;
    613613}
Note: See TracChangeset for help on using the changeset viewer.