Ignore:
File:
1 edited

Legend:

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

    r445f984 r24e321c  
    341341                                }
    342342
    343                                         __STATS( if(this->print_halts) __cfaabi_bits_print_safe( STDOUT_FILENO, "PH:%d - %lld 0\n", this->unique_id, rdtscl()); )
     343                                __STATS( if(this->print_halts) __cfaabi_bits_print_safe( STDOUT_FILENO, "PH:%d - %lld 0\n", this->unique_id, rdtscl()); )
    344344                                __cfadbg_print_safe(runtime_core, "Kernel : core %p waiting on eventfd %d\n", this, this->idle);
    345345
    346                                 // __disable_interrupts_hard();
    347                                 eventfd_t val;
    348                                 eventfd_read( this->idle, &val );
    349                                 // __enable_interrupts_hard();
     346                                {
     347                                        eventfd_t val;
     348                                        ssize_t ret = read( this->idle, &val, sizeof(val) );
     349                                        if(ret < 0) {
     350                                                switch((int)errno) {
     351                                                case EAGAIN:
     352                                                #if EAGAIN != EWOULDBLOCK
     353                                                        case EWOULDBLOCK:
     354                                                #endif
     355                                                case EINTR:
     356                                                        // No need to do anything special here, just assume it's a legitimate wake-up
     357                                                        break;
     358                                                default:
     359                                                        abort( "KERNEL : internal error, read failure on idle eventfd, error(%d) %s.", (int)errno, strerror( (int)errno ) );
     360                                                }
     361                                        }
     362                                }
    350363
    351364                                        __STATS( if(this->print_halts) __cfaabi_bits_print_safe( STDOUT_FILENO, "PH:%d - %lld 1\n", this->unique_id, rdtscl()); )
     
    409422        /* paranoid */ verifyf( thrd_dst->link.next == 0p, "Expected null got %p", thrd_dst->link.next );
    410423        __builtin_prefetch( thrd_dst->context.SP );
    411 
    412         int curr = __kernel_getcpu();
    413         if(thrd_dst->last_cpu != curr) {
    414                 int64_t l = thrd_dst->last_cpu;
    415                 int64_t c = curr;
    416                 int64_t v = (l << 32) | c;
    417                 __push_stat( __tls_stats(), v, false, "Processor", this );
    418         }
    419 
    420         thrd_dst->last_cpu = curr;
    421424
    422425        __cfadbg_print_safe(runtime_core, "Kernel : core %p running thread %p (%s)\n", this, thrd_dst, thrd_dst->self_cor.name);
     
    473476                if(unlikely(thrd_dst->preempted != __NO_PREEMPTION)) {
    474477                        // The thread was preempted, reschedule it and reset the flag
    475                         schedule_thread$( thrd_dst );
     478                        schedule_thread$( thrd_dst, UNPARK_LOCAL );
    476479                        break RUNNING;
    477480                }
     
    557560// Scheduler routines
    558561// KERNEL ONLY
    559 static void __schedule_thread( thread$ * thrd ) {
     562static void __schedule_thread( thread$ * thrd, unpark_hint hint ) {
    560563        /* paranoid */ verify( ! __preemption_enabled() );
    561564        /* paranoid */ verify( ready_schedule_islocked());
     
    577580        // Dereference the thread now because once we push it, there is not guaranteed it's still valid.
    578581        struct cluster * cl = thrd->curr_cluster;
    579         __STATS(bool outside = thrd->last_proc && thrd->last_proc != kernelTLS().this_processor; )
     582        __STATS(bool outside = hint == UNPARK_LOCAL && thrd->last_proc && thrd->last_proc != kernelTLS().this_processor; )
    580583
    581584        // push the thread to the cluster ready-queue
    582         push( cl, thrd, local );
     585        push( cl, thrd, hint );
    583586
    584587        // variable thrd is no longer safe to use
     
    605608}
    606609
    607 void schedule_thread$( thread$ * thrd ) {
     610void schedule_thread$( thread$ * thrd, unpark_hint hint ) {
    608611        ready_schedule_lock();
    609                 __schedule_thread( thrd );
     612                __schedule_thread( thrd, hint );
    610613        ready_schedule_unlock();
    611614}
     
    658661}
    659662
    660 void __kernel_unpark( thread$ * thrd ) {
     663void __kernel_unpark( thread$ * thrd, unpark_hint hint ) {
    661664        /* paranoid */ verify( ! __preemption_enabled() );
    662665        /* paranoid */ verify( ready_schedule_islocked());
     
    666669        if(__must_unpark(thrd)) {
    667670                // Wake lost the race,
    668                 __schedule_thread( thrd );
     671                __schedule_thread( thrd, hint );
    669672        }
    670673
     
    673676}
    674677
    675 void unpark( thread$ * thrd ) {
     678void unpark( thread$ * thrd, unpark_hint hint ) {
    676679        if( !thrd ) return;
    677680
     
    679682                disable_interrupts();
    680683                        // Wake lost the race,
    681                         schedule_thread$( thrd );
     684                        schedule_thread$( thrd, hint );
    682685                enable_interrupts(false);
    683686        }
Note: See TracChangeset for help on using the changeset viewer.