Ignore:
Timestamp:
Sep 27, 2021, 2:09:55 PM (4 years ago)
Author:
Thierry Delisle <tdelisle@…>
Branches:
ADT, ast-experimental, enum, forall-pointer-decay, master, pthread-emulation, qualifiedEnum
Children:
cc287800
Parents:
4e28d2e9 (diff), 056cbdb (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

    r4e28d2e9 r949339b  
    2222#include <errno.h>
    2323#include <stdio.h>
     24#include <string.h>
    2425#include <signal.h>
    2526#include <unistd.h>
     
    3132#include "kernel_private.hfa"
    3233#include "preemption.hfa"
     34#include "strstream.hfa"
     35#include "device/cpu.hfa"
    3336
    3437//Private includes
     
    231234                                __cfadbg_print_safe(runtime_core, "Kernel : core %p waiting on eventfd %d\n", this, this->idle);
    232235
    233                                 __disable_interrupts_hard();
    234                                 eventfd_t val;
    235                                 eventfd_read( this->idle, &val );
    236                                 __enable_interrupts_hard();
     236                                {
     237                                        eventfd_t val;
     238                                        ssize_t ret = read( this->idle, &val, sizeof(val) );
     239                                        if(ret < 0) {
     240                                                switch((int)errno) {
     241                                                case EAGAIN:
     242                                                #if EAGAIN != EWOULDBLOCK
     243                                                        case EWOULDBLOCK:
     244                                                #endif
     245                                                case EINTR:
     246                                                        // No need to do anything special here, just assume it's a legitimate wake-up
     247                                                        break;
     248                                                default:
     249                                                        abort( "KERNEL : internal error, read failure on idle eventfd, error(%d) %s.", (int)errno, strerror( (int)errno ) );
     250                                                }
     251                                        }
     252                                }
    237253
    238254                                #if !defined(__CFA_NO_STATISTICS__)
     
    325341                                }
    326342
    327                                         __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()); )
    328344                                __cfadbg_print_safe(runtime_core, "Kernel : core %p waiting on eventfd %d\n", this, this->idle);
    329345
    330                                 // __disable_interrupts_hard();
    331                                 eventfd_t val;
    332                                 eventfd_read( this->idle, &val );
    333                                 // __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                                }
    334363
    335364                                        __STATS( if(this->print_halts) __cfaabi_bits_print_safe( STDOUT_FILENO, "PH:%d - %lld 1\n", this->unique_id, rdtscl()); )
     
    393422        /* paranoid */ verifyf( thrd_dst->link.next == 0p, "Expected null got %p", thrd_dst->link.next );
    394423        __builtin_prefetch( thrd_dst->context.SP );
    395 
    396         int curr = __kernel_getcpu();
    397         if(thrd_dst->last_cpu != curr) {
    398                 int64_t l = thrd_dst->last_cpu;
    399                 int64_t c = curr;
    400                 int64_t v = (l << 32) | c;
    401                 __push_stat( __tls_stats(), v, false, "Processor", this );
    402         }
    403 
    404         thrd_dst->last_cpu = curr;
    405424
    406425        __cfadbg_print_safe(runtime_core, "Kernel : core %p running thread %p (%s)\n", this, thrd_dst, thrd_dst->self_cor.name);
     
    457476                if(unlikely(thrd_dst->preempted != __NO_PREEMPTION)) {
    458477                        // The thread was preempted, reschedule it and reset the flag
    459                         schedule_thread$( thrd_dst );
     478                        schedule_thread$( thrd_dst, UNPARK_LOCAL );
    460479                        break RUNNING;
    461480                }
     
    541560// Scheduler routines
    542561// KERNEL ONLY
    543 static void __schedule_thread( thread$ * thrd ) {
     562static void __schedule_thread( thread$ * thrd, unpark_hint hint ) {
    544563        /* paranoid */ verify( ! __preemption_enabled() );
    545564        /* paranoid */ verify( ready_schedule_islocked());
     
    561580        // Dereference the thread now because once we push it, there is not guaranteed it's still valid.
    562581        struct cluster * cl = thrd->curr_cluster;
    563         __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; )
    564583
    565584        // push the thread to the cluster ready-queue
    566         push( cl, thrd, local );
     585        push( cl, thrd, hint );
    567586
    568587        // variable thrd is no longer safe to use
     
    589608}
    590609
    591 void schedule_thread$( thread$ * thrd ) {
     610void schedule_thread$( thread$ * thrd, unpark_hint hint ) {
    592611        ready_schedule_lock();
    593                 __schedule_thread( thrd );
     612                __schedule_thread( thrd, hint );
    594613        ready_schedule_unlock();
    595614}
     
    642661}
    643662
    644 void __kernel_unpark( thread$ * thrd ) {
     663void __kernel_unpark( thread$ * thrd, unpark_hint hint ) {
    645664        /* paranoid */ verify( ! __preemption_enabled() );
    646665        /* paranoid */ verify( ready_schedule_islocked());
     
    650669        if(__must_unpark(thrd)) {
    651670                // Wake lost the race,
    652                 __schedule_thread( thrd );
     671                __schedule_thread( thrd, hint );
    653672        }
    654673
     
    657676}
    658677
    659 void unpark( thread$ * thrd ) {
     678void unpark( thread$ * thrd, unpark_hint hint ) {
    660679        if( !thrd ) return;
    661680
     
    663682                disable_interrupts();
    664683                        // Wake lost the race,
    665                         schedule_thread$( thrd );
     684                        schedule_thread$( thrd, hint );
    666685                enable_interrupts(false);
    667686        }
Note: See TracChangeset for help on using the changeset viewer.