Changeset 34b8cb7


Ignore:
Timestamp:
Nov 19, 2021, 11:23:17 AM (3 years ago)
Author:
Thierry Delisle <tdelisle@…>
Branches:
ADT, ast-experimental, enum, forall-pointer-decay, master, pthread-emulation, qualifiedEnum
Children:
b14ec5f
Parents:
3df86cc
Message:

Step 1 of a new scheme to simplify wake_one.

Location:
libcfa/src/concurrency
Files:
3 edited

Legend:

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

    r3df86cc r34b8cb7  
    126126static void mark_idle (__cluster_proc_list & idles, processor & proc);
    127127static void mark_awake(__cluster_proc_list & idles, processor & proc);
    128 static [unsigned idle, unsigned total, * processor] query_idles( & __cluster_proc_list idles );
    129128
    130129extern void __cfa_io_start( processor * );
     
    766765
    767766        // Check if there is a sleeping processor
    768         processor * p;
    769         unsigned idle;
    770         unsigned total;
    771         [idle, total, p] = query_idles(this->procs);
     767        int fd = __atomic_load_n(&this->procs.fd, __ATOMIC_SEQ_CST);
    772768
    773769        // If no one is sleeping, we are done
    774         if( idle == 0 ) return;
     770        if( fd == 0 ) return;
    775771
    776772        // We found a processor, wake it up
    777773        eventfd_t val;
    778774        val = 1;
    779         eventfd_write( p->idle, val );
     775        eventfd_write( fd, val );
    780776
    781777        #if !defined(__CFA_NO_STATISTICS__)
     
    813809                remove(proc);
    814810                insert_first(this.idles, proc);
     811
     812                __atomic_store_n(&this.fd, proc.idle, __ATOMIC_SEQ_CST);
    815813        unlock( this );
    816814        /* paranoid */ verify( ! __preemption_enabled() );
     
    824822                remove(proc);
    825823                insert_last(this.actives, proc);
     824
     825                __atomic_store_n(&this.fd, this.idles`first.idle, __ATOMIC_SEQ_CST);
    826826        unlock( this );
    827         /* paranoid */ verify( ! __preemption_enabled() );
    828 }
    829 
    830 static [unsigned idle, unsigned total, * processor] query_idles( & __cluster_proc_list this ) {
    831         /* paranoid */ verify( ! __preemption_enabled() );
    832         /* paranoid */ verify( ready_schedule_islocked() );
    833 
    834         for() {
    835                 uint64_t l = __atomic_load_n(&this.lock, __ATOMIC_SEQ_CST);
    836                 if( 1 == (l % 2) ) { Pause(); continue; }
    837                 unsigned idle    = this.idle;
    838                 unsigned total   = this.total;
    839                 processor * proc = &this.idles`first;
    840                 // Compiler fence is unnecessary, but gcc-8 and older incorrectly reorder code without it
    841                 asm volatile("": : :"memory");
    842                 if(l != __atomic_load_n(&this.lock, __ATOMIC_SEQ_CST)) { Pause(); continue; }
    843                 return [idle, total, proc];
    844         }
    845 
    846         /* paranoid */ verify( ready_schedule_islocked() );
    847827        /* paranoid */ verify( ! __preemption_enabled() );
    848828}
     
    906886                if(head == tail) return false;
    907887                #if OLD_MAIN
    908                 ready_schedule_lock();
    909                 ret = __cfa_io_drain( proc );
    910                 ready_schedule_unlock();
     888                        ready_schedule_lock();
     889                        ret = __cfa_io_drain( proc );
     890                        ready_schedule_unlock();
    911891                #else
    912892                        ret = __cfa_io_drain( proc );
    913         #endif
     893                #endif
    914894        #endif
    915895        return ret;
  • libcfa/src/concurrency/kernel.hfa

    r3df86cc r34b8cb7  
    195195struct __cluster_proc_list {
    196196        // Spin lock protecting the queue
    197         volatile uint64_t lock;
     197        __spinlock_t lock;
     198
     199        // FD to use to wake a processor
     200        volatile int fd;
    198201
    199202        // Total number of processors
  • libcfa/src/concurrency/kernel/startup.cfa

    r3df86cc r34b8cb7  
    584584// Cluster
    585585static void ?{}(__cluster_proc_list & this) {
    586         this.lock  = 0;
     586        this.fd    = 0;
    587587        this.idle  = 0;
    588588        this.total = 0;
Note: See TracChangeset for help on using the changeset viewer.