Changeset 6a9b12b


Ignore:
Timestamp:
Apr 14, 2021, 4:28:55 PM (3 years ago)
Author:
Thierry Delisle <tdelisle@…>
Branches:
ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast-unique-expr, pthread-emulation, qualifiedEnum
Children:
fc59b580
Parents:
a7504db
Message:

Incremental change towards having the cluster keep a list of active processors.

Location:
libcfa/src/concurrency
Files:
4 edited

Legend:

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

    ra7504db r6a9b12b  
    113113static void __wake_one(cluster * cltr);
    114114
    115 static void push  (__cluster_idles & idles, processor & proc);
    116 static void remove(__cluster_idles & idles, processor & proc);
    117 static [unsigned idle, unsigned total, * processor] query( & __cluster_idles idles );
     115static void mark_idle (__cluster_proc_list & idles, processor & proc);
     116static void mark_awake(__cluster_proc_list & idles, processor & proc);
     117static [unsigned idle, unsigned total, * processor] query_idles( & __cluster_proc_list idles );
    118118
    119119extern void __cfa_io_start( processor * );
     
    189189
    190190                                // Push self to idle stack
    191                                 push(this->cltr->idles, * this);
     191                                mark_idle(this->cltr->procs, * this);
    192192
    193193                                // Confirm the ready-queue is empty
     
    195195                                if( readyThread ) {
    196196                                        // A thread was found, cancel the halt
    197                                         remove(this->cltr->idles, * this);
     197                                        mark_awake(this->cltr->procs, * this);
    198198
    199199                                        #if !defined(__CFA_NO_STATISTICS__)
     
    225225
    226226                                // We were woken up, remove self from idle
    227                                 remove(this->cltr->idles, * this);
     227                                mark_awake(this->cltr->procs, * this);
    228228
    229229                                // DON'T just proceed, start looking again
     
    617617        unsigned idle;
    618618        unsigned total;
    619         [idle, total, p] = query(this->idles);
     619        [idle, total, p] = query_idles(this->procs);
    620620
    621621        // If no one is sleeping, we are done
     
    654654}
    655655
    656 static void push  (__cluster_idles & this, processor & proc) {
     656static void mark_idle(__cluster_proc_list & this, processor & proc) {
    657657        /* paranoid */ verify( ! __preemption_enabled() );
    658658        lock( this );
     
    660660                /* paranoid */ verify( this.idle <= this.total );
    661661
    662                 insert_first(this.list, proc);
     662                insert_first(this.idles, proc);
    663663        unlock( this );
    664664        /* paranoid */ verify( ! __preemption_enabled() );
    665665}
    666666
    667 static void remove(__cluster_idles & this, processor & proc) {
     667static void mark_awake(__cluster_proc_list & this, processor & proc) {
    668668        /* paranoid */ verify( ! __preemption_enabled() );
    669669        lock( this );
     
    676676}
    677677
    678 static [unsigned idle, unsigned total, * processor] query( & __cluster_idles this ) {
     678static [unsigned idle, unsigned total, * processor] query_idles( & __cluster_proc_list this ) {
     679        /* paranoid */ verify( ! __preemption_enabled() );
     680        /* paranoid */ verify( ready_schedule_islocked() );
     681
    679682        for() {
    680683                uint64_t l = __atomic_load_n(&this.lock, __ATOMIC_SEQ_CST);
     
    682685                unsigned idle    = this.idle;
    683686                unsigned total   = this.total;
    684                 processor * proc = &this.list`first;
     687                processor * proc = &this.idles`first;
    685688                // Compiler fence is unnecessary, but gcc-8 and older incorrectly reorder code without it
    686689                asm volatile("": : :"memory");
     
    688691                return [idle, total, proc];
    689692        }
     693
     694        /* paranoid */ verify( ready_schedule_islocked() );
     695        /* paranoid */ verify( ! __preemption_enabled() );
    690696}
    691697
  • libcfa/src/concurrency/kernel.hfa

    ra7504db r6a9b12b  
    180180
    181181// Idle Sleep
    182 struct __cluster_idles {
     182struct __cluster_proc_list {
    183183        // Spin lock protecting the queue
    184184        volatile uint64_t lock;
     
    191191
    192192        // List of idle processors
    193         dlist(processor, processor) list;
     193        dlist(processor, processor) idles;
    194194};
    195195
     
    207207
    208208        // List of idle processors
    209         __cluster_idles idles;
     209        __cluster_proc_list procs;
    210210
    211211        // List of threads
  • libcfa/src/concurrency/kernel/startup.cfa

    ra7504db r6a9b12b  
    491491        // Register and Lock the RWlock so no-one pushes/pops while we are changing the queue
    492492        uint_fast32_t last_size = ready_mutate_register((__processor_id_t*)&this);
    493                 int target = this.cltr->idles.total += 1u;
     493                int target = this.cltr->procs.total += 1u;
    494494
    495495                // Adjust the ready queue size
     
    506506        // Lock the RWlock so no-one pushes/pops while we are changing the queue
    507507        uint_fast32_t last_size = ready_mutate_lock();
    508                 int target = this.cltr->idles.total -= 1u;
     508                int target = this.cltr->procs.total -= 1u;
    509509
    510510                // Adjust the ready queue size
     
    555555//-----------------------------------------------------------------------------
    556556// Cluster
    557 static void ?{}(__cluster_idles & this) {
     557static void ?{}(__cluster_proc_list & this) {
    558558        this.lock  = 0;
    559559        this.idle  = 0;
    560560        this.total = 0;
    561         (this.list){};
    562561}
    563562
  • libcfa/src/concurrency/kernel_private.hfa

    ra7504db r6a9b12b  
    247247//-----------------------------------------------------------------------
    248248// Cluster idle lock/unlock
    249 static inline void lock(__cluster_idles & this) {
     249static inline void lock(__cluster_proc_list & this) {
    250250        /* paranoid */ verify( ! __preemption_enabled() );
    251251
     
    268268}
    269269
    270 static inline void unlock(__cluster_idles & this) {
     270static inline void unlock(__cluster_proc_list & this) {
    271271        /* paranoid */ verify( ! __preemption_enabled() );
    272272
Note: See TracChangeset for help on using the changeset viewer.