Changeset 1757f98


Ignore:
Timestamp:
Nov 19, 2021, 3:03:54 PM (2 years ago)
Author:
Thierry Delisle <tdelisle@…>
Branches:
ADT, ast-experimental, enum, forall-pointer-decay, master, pthread-emulation, qualifiedEnum
Children:
cd4c605
Parents:
a633f6f
Message:

Refactoring idle sleep to try and help the change from idle on read to idle on io_uring_enter.

Location:
libcfa/src/concurrency
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • libcfa/src/concurrency/io/setup.cfa

    ra633f6f r1757f98  
    111111                this.ext_sq.empty = true;
    112112                (this.ext_sq.queue){};
    113                 __io_uring_setup( this, cl.io.params, proc->idle );
     113                __io_uring_setup( this, cl.io.params, proc->idle_fd );
    114114                __cfadbg_print_safe(io_core, "Kernel I/O : Created ring for io_context %u (%p)\n", this.fd, &this);
    115115        }
  • libcfa/src/concurrency/kernel.cfa

    ra633f6f r1757f98  
    124124static void __wake_one(cluster * cltr);
    125125
     126static void idle_sleep(processor * proc);
    126127static bool mark_idle (__cluster_proc_list & idles, processor & proc);
    127128static void mark_awake(__cluster_proc_list & idles, processor & proc);
     
    228229                                }
    229230
    230                                 #if !defined(__CFA_NO_STATISTICS__)
    231                                         if(this->print_halts) {
    232                                                 __cfaabi_bits_print_safe( STDOUT_FILENO, "PH:%d - %lld 0\n", this->unique_id, rdtscl());
    233                                         }
    234                                 #endif
    235 
    236                                 __cfadbg_print_safe(runtime_core, "Kernel : core %p waiting on eventfd %d\n", this, this->idle);
    237 
    238                                 {
    239                                         eventfd_t val;
    240                                         ssize_t ret = read( this->idle, &val, sizeof(val) );
    241                                         if(ret < 0) {
    242                                                 switch((int)errno) {
    243                                                 case EAGAIN:
    244                                                 #if EAGAIN != EWOULDBLOCK
    245                                                         case EWOULDBLOCK:
    246                                                 #endif
    247                                                 case EINTR:
    248                                                         // No need to do anything special here, just assume it's a legitimate wake-up
    249                                                         break;
    250                                                 default:
    251                                                         abort( "KERNEL : internal error, read failure on idle eventfd, error(%d) %s.", (int)errno, strerror( (int)errno ) );
    252                                                 }
    253                                         }
    254                                 }
    255 
    256                                 #if !defined(__CFA_NO_STATISTICS__)
    257                                         if(this->print_halts) {
    258                                                 __cfaabi_bits_print_safe( STDOUT_FILENO, "PH:%d - %lld 1\n", this->unique_id, rdtscl());
    259                                         }
    260                                 #endif
     231                                idle_sleep( this );
    261232
    262233                                // We were woken up, remove self from idle
     
    349320
    350321                                __STATS( if(this->print_halts) __cfaabi_bits_print_safe( STDOUT_FILENO, "PH:%d - %lld 0\n", this->unique_id, rdtscl()); )
    351                                 __cfadbg_print_safe(runtime_core, "Kernel : core %p waiting on eventfd %d\n", this, this->idle);
     322                                __cfadbg_print_safe(runtime_core, "Kernel : core %p waiting on eventfd %d\n", this, this->idle_fd);
    352323
    353324                                {
    354325                                        eventfd_t val;
    355                                         ssize_t ret = read( this->idle, &val, sizeof(val) );
     326                                        ssize_t ret = read( this->idle_fd, &val, sizeof(val) );
    356327                                        if(ret < 0) {
    357328                                                switch((int)errno) {
     
    798769                eventfd_t val;
    799770                val = 1;
    800                 eventfd_write( this->idle, val );
     771                eventfd_write( this->idle_fd, val );
    801772        __enable_interrupts_checked();
     773}
     774
     775static void idle_sleep(processor * this) {
     776        #if !defined(__CFA_NO_STATISTICS__)
     777                if(this->print_halts) {
     778                        __cfaabi_bits_print_safe( STDOUT_FILENO, "PH:%d - %lld 0\n", this->unique_id, rdtscl());
     779                }
     780        #endif
     781
     782        __cfadbg_print_safe(runtime_core, "Kernel : core %p waiting on eventfd %d\n", this, this->idle_fd);
     783
     784        {
     785                eventfd_t val;
     786                ssize_t ret = read( this->idle_fd, &val, sizeof(val) );
     787                if(ret < 0) {
     788                        switch((int)errno) {
     789                        case EAGAIN:
     790                        #if EAGAIN != EWOULDBLOCK
     791                                case EWOULDBLOCK:
     792                        #endif
     793                        case EINTR:
     794                                // No need to do anything special here, just assume it's a legitimate wake-up
     795                                break;
     796                        default:
     797                                abort( "KERNEL : internal error, read failure on idle eventfd, error(%d) %s.", (int)errno, strerror( (int)errno ) );
     798                        }
     799                }
     800        }
     801
     802        #if !defined(__CFA_NO_STATISTICS__)
     803                if(this->print_halts) {
     804                        __cfaabi_bits_print_safe( STDOUT_FILENO, "PH:%d - %lld 1\n", this->unique_id, rdtscl());
     805                }
     806        #endif
    802807}
    803808
     
    810815                insert_first(this.idles, proc);
    811816
    812                 __atomic_store_n(&this.fd, proc.idle, __ATOMIC_SEQ_CST);
     817                __atomic_store_n(&this.fd, proc.idle_fd, __ATOMIC_SEQ_CST);
    813818        unlock( this );
    814819        /* paranoid */ verify( ! __preemption_enabled() );
     
    827832                {
    828833                        int fd = 0;
    829                         if(!this.idles`isEmpty) fd = this.idles`first.idle;
     834                        if(!this.idles`isEmpty) fd = this.idles`first.idle_fd;
    830835                        __atomic_store_n(&this.fd, fd, __ATOMIC_SEQ_CST);
    831836                }
  • libcfa/src/concurrency/kernel.hfa

    ra633f6f r1757f98  
    100100
    101101        // Idle lock (kernel semaphore)
    102         int idle;
     102        int idle_fd;
    103103
    104104        // Termination synchronisation (user semaphore)
  • libcfa/src/concurrency/kernel/startup.cfa

    ra633f6f r1757f98  
    527527        this.local_data = 0p;
    528528
    529         this.idle = eventfd(0, 0);
    530         if (idle < 0) {
     529        this.idle_fd = eventfd(0, 0);
     530        if (idle_fd < 0) {
    531531                abort("KERNEL ERROR: PROCESSOR EVENTFD - %s\n", strerror(errno));
    532532        }
     
    542542// Not a ctor, it just preps the destruction but should not destroy members
    543543static void deinit(processor & this) {
    544         close(this.idle);
     544        close(this.idle_fd);
    545545}
    546546
Note: See TracChangeset for help on using the changeset viewer.