Ignore:
Timestamp:
Nov 14, 2022, 11:52:44 AM (3 years ago)
Author:
caparson <caparson@…>
Branches:
ADT, ast-experimental, master
Children:
7d9598d8
Parents:
b77f0e1 (diff), 19a8c40 (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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • libcfa/src/concurrency/kernel.cfa

    rb77f0e1 r63be3387  
    138138extern bool __cfa_io_drain( processor * proc ) __attribute__((nonnull (1)));
    139139extern bool __cfa_io_flush( processor * ) __attribute__((nonnull (1)));
    140 extern void __cfa_io_idle( processor * ) __attribute__((nonnull (1)));
    141 
    142 #if defined(CFA_WITH_IO_URING_IDLE)
    143         extern bool __kernel_read(processor * proc, io_future_t & future, iovec &, int fd);
    144 #endif
     140
    145141
    146142extern void __disable_interrupts_hard();
     
    162158        verify(this);
    163159
    164         /* paranoid */ verify( this->idle_wctx.ftr   != 0p );
    165         /* paranoid */ verify( this->idle_wctx.rdbuf != 0p );
    166 
    167         // used for idle sleep when io_uring is present
    168         // mark it as already fulfilled so we know if there is a pending request or not
    169         this->idle_wctx.ftr->self.ptr = 1p;
    170 
    171160        __cfadbg_print_safe(runtime_core, "Kernel : core %p starting\n", this);
    172161        #if !defined(__CFA_NO_STATISTICS__)
     
    291280        /* paranoid */ verify( ! __preemption_enabled() );
    292281        /* paranoid */ verifyf( thrd_dst->state == Ready || thrd_dst->preempted != __NO_PREEMPTION, "state : %d, preempted %d\n", thrd_dst->state, thrd_dst->preempted);
    293         /* paranoid */ verifyf( thrd_dst->link.next == 0p, "Expected null got %p", thrd_dst->link.next );
     282        /* paranoid */ verifyf( thrd_dst->rdy_link.next == 0p, "Expected null got %p", thrd_dst->rdy_link.next );
    294283        __builtin_prefetch( thrd_dst->context.SP );
    295284
     
    321310                /* paranoid */ verifyf( ((uintptr_t)thrd_dst->context.SP) < ((uintptr_t)__get_stack(thrd_dst->curr_cor)->base ) || thrd_dst->curr_cor == proc_cor || thrd_dst->corctx_flag, "ERROR : Destination thread$ %p has been corrupted.\n StackPointer too small.\n", thrd_dst ); // add escape condition if we are setting up the processor
    322311                /* paranoid */ verifyf( ((uintptr_t)thrd_dst->context.SP) > ((uintptr_t)__get_stack(thrd_dst->curr_cor)->limit) || thrd_dst->curr_cor == proc_cor || thrd_dst->corctx_flag, "ERROR : Destination thread$ %p has been corrupted.\n StackPointer too large.\n", thrd_dst ); // add escape condition if we are setting up the processor
     312                /* paranoid */ verify( __atomic_exchange_n( &thrd_dst->executing, this, __ATOMIC_SEQ_CST) == 0p );
    323313                /* paranoid */ verify( 0x0D15EA5E0D15EA5Ep == thrd_dst->canary );
    324314
     
    332322
    333323                /* paranoid */ verify( 0x0D15EA5E0D15EA5Ep == thrd_dst->canary );
     324                /* paranoid */ verify( __atomic_exchange_n( &thrd_dst->executing, 0p, __ATOMIC_SEQ_CST) == this );
    334325                /* paranoid */ verifyf( ((uintptr_t)thrd_dst->context.SP) > ((uintptr_t)__get_stack(thrd_dst->curr_cor)->limit) || thrd_dst->corctx_flag, "ERROR : Destination thread$ %p has been corrupted.\n StackPointer too large.\n", thrd_dst );
    335326                /* paranoid */ verifyf( ((uintptr_t)thrd_dst->context.SP) < ((uintptr_t)__get_stack(thrd_dst->curr_cor)->base ) || thrd_dst->corctx_flag, "ERROR : Destination thread$ %p has been corrupted.\n StackPointer too small.\n", thrd_dst );
     327                /* paranoid */ verify( thrd_dst->state != Halted );
    336328                /* paranoid */ verify( thrd_dst->context.SP );
    337                 /* paranoid */ verify( thrd_dst->curr_cluster == this->cltr );
    338329                /* paranoid */ verify( kernelTLS().this_thread == thrd_dst );
    339330                /* paranoid */ verify( ! __preemption_enabled() );
     
    452443                                        "Error preempted thread marked as not currently running, state %d, preemption %d\n", thrd->state, thrd->preempted );
    453444        /* paranoid */ #endif
    454         /* paranoid */ verifyf( thrd->link.next == 0p, "Expected null got %p", thrd->link.next );
     445        /* paranoid */ verifyf( thrd->rdy_link.next == 0p, "Expected null got %p", thrd->rdy_link.next );
    455446        /* paranoid */ verify( 0x0D15EA5E0D15EA5Ep == thrd->canary );
    456447
     
    600591                /* paranoid */ verifyf( ((uintptr_t)thrd->context.SP) < ((uintptr_t)__get_stack(thrd->curr_cor)->base ), "ERROR : thread$ %p has been corrupted.\n StackPointer too small.\n", thrd );
    601592
    602                 thrd->state = Halting;
    603593                if( TICKET_RUNNING != thrd->ticket ) { abort( "Thread terminated with pending unpark" ); }
    604594                if( thrd != this->owner ) { abort( "Thread internal monitor has incorrect owner" ); }
    605595                if( this->recursion != 1) { abort( "Thread internal monitor has unbalanced recursion" ); }
     596
     597                thrd->state = Halting;
     598                thrd->ticket = TICKET_DEAD;
    606599
    607600                // Leave the thread
     
    624617                // If that is the case, abandon the preemption.
    625618                bool preempted = false;
    626                 if(thrd->link.next == 0p) {
     619                if(thrd->rdy_link.next == 0p) {
    627620                        preempted = true;
    628621                        thrd->preempted = reason;
     
    726719
    727720
    728         #if !defined(CFA_WITH_IO_URING_IDLE)
    729                 #if !defined(__CFA_NO_STATISTICS__)
    730                         if(this->print_halts) {
    731                                 __cfaabi_bits_print_safe( STDOUT_FILENO, "PH:%d - %lld 0\n", this->unique_id, rdtscl());
     721        #if !defined(__CFA_NO_STATISTICS__)
     722                if(this->print_halts) {
     723                        __cfaabi_bits_print_safe( STDOUT_FILENO, "PH:%d - %lld 0\n", this->unique_id, rdtscl());
     724                }
     725        #endif
     726
     727        __cfadbg_print_safe(runtime_core, "Kernel : core %p waiting on eventfd %d\n", this, this->idle_fd);
     728
     729        {
     730                eventfd_t val;
     731                ssize_t ret = read( this->idle_wctx.evfd, &val, sizeof(val) );
     732                if(ret < 0) {
     733                        switch((int)errno) {
     734                        case EAGAIN:
     735                        #if EAGAIN != EWOULDBLOCK
     736                                case EWOULDBLOCK:
     737                        #endif
     738                        case EINTR:
     739                                // No need to do anything special here, just assume it's a legitimate wake-up
     740                                break;
     741                        default:
     742                                abort( "KERNEL : internal error, read failure on idle eventfd, error(%d) %s.", (int)errno, strerror( (int)errno ) );
    732743                        }
    733                 #endif
    734 
    735                 __cfadbg_print_safe(runtime_core, "Kernel : core %p waiting on eventfd %d\n", this, this->idle_fd);
    736 
    737                 {
    738                         eventfd_t val;
    739                         ssize_t ret = read( this->idle_wctx.evfd, &val, sizeof(val) );
    740                         if(ret < 0) {
    741                                 switch((int)errno) {
    742                                 case EAGAIN:
    743                                 #if EAGAIN != EWOULDBLOCK
    744                                         case EWOULDBLOCK:
    745                                 #endif
    746                                 case EINTR:
    747                                         // No need to do anything special here, just assume it's a legitimate wake-up
    748                                         break;
    749                                 default:
    750                                         abort( "KERNEL : internal error, read failure on idle eventfd, error(%d) %s.", (int)errno, strerror( (int)errno ) );
    751                                 }
    752                         }
    753                 }
    754 
    755                 #if !defined(__CFA_NO_STATISTICS__)
    756                         if(this->print_halts) {
    757                                 __cfaabi_bits_print_safe( STDOUT_FILENO, "PH:%d - %lld 1\n", this->unique_id, rdtscl());
    758                         }
    759                 #endif
    760         #else
    761                 __cfa_io_idle( this );
     744                }
     745        }
     746
     747        #if !defined(__CFA_NO_STATISTICS__)
     748                if(this->print_halts) {
     749                        __cfaabi_bits_print_safe( STDOUT_FILENO, "PH:%d - %lld 1\n", this->unique_id, rdtscl());
     750                }
    762751        #endif
    763752}
     
    775764                insert_first(this.idles, proc);
    776765
     766                // update the pointer to the head wait context, which should now point to this proc.
    777767                __atomic_store_n(&this.fdw, &proc.idle_wctx, __ATOMIC_SEQ_CST);
    778768        unlock( this );
     
    791781
    792782                {
     783                        // update the pointer to the head wait context
    793784                        struct __fd_waitctx * wctx = 0;
    794785                        if(!this.idles`isEmpty) wctx = &this.idles`first.idle_wctx;
Note: See TracChangeset for help on using the changeset viewer.