Changeset c60e5094


Ignore:
Timestamp:
Nov 19, 2021, 11:59:55 AM (9 months ago)
Author:
Thierry Delisle <tdelisle@…>
Branches:
enum, forall-pointer-decay, master, pthread-emulation
Children:
813dfd86, cd4c605
Parents:
3e417bf (diff), a633f6f (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

Location:
libcfa/src/concurrency
Files:
4 edited

Legend:

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

    r3e417bf rc60e5094  
    126126static bool 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() );
     
    826824                remove(proc);
    827825                insert_last(this.actives, proc);
     826
     827                {
     828                        int fd = 0;
     829                        if(!this.idles`isEmpty) fd = this.idles`first.idle;
     830                        __atomic_store_n(&this.fd, fd, __ATOMIC_SEQ_CST);
     831                }
     832
    828833        unlock( this );
    829         /* paranoid */ verify( ! __preemption_enabled() );
    830 }
    831 
    832 static [unsigned idle, unsigned total, * processor] query_idles( & __cluster_proc_list this ) {
    833         /* paranoid */ verify( ! __preemption_enabled() );
    834         /* paranoid */ verify( ready_schedule_islocked() );
    835 
    836         for() {
    837                 uint64_t l = __atomic_load_n(&this.lock, __ATOMIC_SEQ_CST);
    838                 if( 1 == (l % 2) ) { Pause(); continue; }
    839                 unsigned idle    = this.idle;
    840                 unsigned total   = this.total;
    841                 processor * proc = &this.idles`first;
    842                 // Compiler fence is unnecessary, but gcc-8 and older incorrectly reorder code without it
    843                 asm volatile("": : :"memory");
    844                 if(l != __atomic_load_n(&this.lock, __ATOMIC_SEQ_CST)) { Pause(); continue; }
    845                 return [idle, total, proc];
    846         }
    847 
    848         /* paranoid */ verify( ready_schedule_islocked() );
    849834        /* paranoid */ verify( ! __preemption_enabled() );
    850835}
     
    908893                if(head == tail) return false;
    909894                #if OLD_MAIN
    910                 ready_schedule_lock();
    911                 ret = __cfa_io_drain( proc );
    912                 ready_schedule_unlock();
     895                        ready_schedule_lock();
     896                        ret = __cfa_io_drain( proc );
     897                        ready_schedule_unlock();
    913898                #else
    914899                        ret = __cfa_io_drain( proc );
    915         #endif
     900                #endif
    916901        #endif
    917902        return ret;
  • libcfa/src/concurrency/kernel.hfa

    r3e417bf rc60e5094  
    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

    r3e417bf rc60e5094  
    584584// Cluster
    585585static void ?{}(__cluster_proc_list & this) {
    586         this.lock  = 0;
     586        this.fd    = 0;
    587587        this.idle  = 0;
    588588        this.total = 0;
  • libcfa/src/concurrency/kernel_private.hfa

    r3e417bf rc60e5094  
    268268        ready_schedule_lock();
    269269
    270         // Simple counting lock, acquired, acquired by incrementing the counter
    271         // to an odd number
    272         for() {
    273                 uint64_t l = this.lock;
    274                 if(
    275                         (0 == (l % 2))
    276                         && __atomic_compare_exchange_n(&this.lock, &l, l + 1, false, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST)
    277                 ) return;
    278                 Pause();
    279         }
     270        lock( this.lock __cfaabi_dbg_ctx2 );
    280271
    281272        /* paranoid */ verify( ! __preemption_enabled() );
     
    289280        ready_schedule_lock();
    290281
    291         // Simple counting lock, acquired, acquired by incrementing the counter
    292         // to an odd number
    293         uint64_t l = this.lock;
    294         if(
    295                 (0 == (l % 2))
    296                 && __atomic_compare_exchange_n(&this.lock, &l, l + 1, false, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST)
    297         ) {
     282        if(try_lock( this.lock __cfaabi_dbg_ctx2 )) {
    298283                // success
    299284                /* paranoid */ verify( ! __preemption_enabled() );
     
    311296        /* paranoid */ verify( ! __preemption_enabled() );
    312297
    313         /* paranoid */ verify( 1 == (this.lock % 2) );
    314         // Simple couting lock, release by incrementing to an even number
    315         __atomic_fetch_add( &this.lock, 1, __ATOMIC_SEQ_CST );
     298        unlock(this.lock);
    316299
    317300        // Release the global lock, which we acquired when locking
Note: See TracChangeset for help on using the changeset viewer.