Changeset d3ba775 for libcfa/src


Ignore:
Timestamp:
May 3, 2021, 5:04:05 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:
9fa538c
Parents:
eeb9f9f
Message:

More clean-up after new subqueue

Location:
libcfa/src/concurrency
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • libcfa/src/concurrency/invoke.h

    reeb9f9f rd3ba775  
    154154                struct __stack_context_t context;
    155155
     156                // Link lists fields
     157                // instrusive link field for threads
     158                struct __thread_desc_link link;
     159
    156160                // current execution status for coroutine
    157161                // Possible values are:
     
    168172                struct cluster * curr_cluster;
    169173
    170                 // Link lists fields
    171                 // instrusive link field for threads
    172                 struct __thread_desc_link link;
     174                // preferred ready-queue
     175                unsigned preferred;
    173176
    174177                // coroutine body used to store context
  • libcfa/src/concurrency/kernel/startup.cfa

    reeb9f9f rd3ba775  
    462462        link.next = 0p;
    463463        link.ts   = 0;
    464         link.preferred = -1u;
     464        preferred = -1u;
    465465        last_proc = 0p;
    466466        #if defined( __CFA_WITH_VERIFY__ )
  • libcfa/src/concurrency/ready_queue.cfa

    reeb9f9f rd3ba775  
    1717// #define __CFA_DEBUG_PRINT_READY_QUEUE__
    1818
    19 // #define USE_MPSC
    2019
    2120#define USE_RELAXED_FIFO
     
    274273                        #endif
    275274
    276                 #if defined(USE_MPSC)
    277                         // mpsc always succeeds
    278                 } while( false );
    279                 #else
    280275                        // If we can't lock it retry
    281276                } while( !__atomic_try_acquire( &lanes.data[i].lock ) );
    282                 #endif
    283277
    284278                // Actually push it
    285279                push(lanes.data[i], thrd);
    286280
    287                 #if !defined(USE_MPSC)
    288281                        // Unlock and return
    289282                        __atomic_unlock( &lanes.data[i].lock );
    290                 #endif
    291283
    292284                // Mark the current index in the tls rng instance as having an item
     
    347339                __cfadbg_print_safe(ready_queue, "Kernel : Pushing %p on cluster %p\n", thrd, cltr);
    348340
     341                // #define USE_PREFERRED
     342                #if !defined(USE_PREFERRED)
    349343                const bool external = (!kernelTLS().this_processor) || (cltr != kernelTLS().this_processor->cltr);
    350344                /* paranoid */ verify(external || kernelTLS().this_processor->rdq.id < lanes.count );
    351 
    352                 // write timestamp
    353                 #if !defined(USE_NEW_SUBQUEUE)
    354                         thrd->link.ts = rdtscl();
     345                #else
     346                        unsigned preferred = thrd->preferred;
     347                        const bool external = (!kernelTLS().this_processor) || preferred == -1u || thrd->curr_cluster != cltr;
     348                        /* paranoid */ verifyf(external || preferred < lanes.count, "Invalid preferred queue %u for %u lanes", preferred, lanes.count );
     349
     350                        unsigned r = preferred % READYQ_SHARD_FACTOR;
     351                        const unsigned start = preferred - r;
    355352                #endif
    356353
     
    367364                        }
    368365                        else {
     366                                #if !defined(USE_PREFERRED)
    369367                                processor * proc = kernelTLS().this_processor;
    370368                                unsigned r = proc->rdq.its++;
    371369                                i =  proc->rdq.id + (r % READYQ_SHARD_FACTOR);
     370                #else
     371                                        i = start + (r++ % READYQ_SHARD_FACTOR);
     372                                #endif
    372373                        }
    373 
    374 
    375                 #if defined(USE_MPSC)
    376                         // mpsc always succeeds
    377                 } while( false );
    378                 #else
    379374                        // If we can't lock it retry
    380375                } while( !__atomic_try_acquire( &lanes.data[i].lock ) );
    381                 #endif
    382376
    383377                // Actually push it
    384378                push(lanes.data[i], thrd);
    385379
    386                 #if !defined(USE_MPSC)
    387380                        // Unlock and return
    388381                        __atomic_unlock( &lanes.data[i].lock );
    389                 #endif
    390382
    391383                #if !defined(__CFA_NO_STATISTICS__)
     
    491483                lanes.tscs[w].tv = thrd->link.ts;
    492484        #endif
     485
     486        thrd->preferred = w;
    493487
    494488        // return the popped thread
     
    518512// Check that all the intrusive queues in the data structure are still consistent
    519513static void check( __ready_queue_t & q ) with (q) {
    520         #if defined(__CFA_WITH_VERIFY__) && !defined(USE_MPSC)
     514        #if defined(__CFA_WITH_VERIFY__)
    521515                {
    522516                        for( idx ; lanes.count ) {
     
    553547// fixes the list so that the pointers back to anchors aren't left dangling
    554548static inline void fix(__intrusive_lane_t & ll) {
    555         #if !defined(USE_MPSC)
    556549                        if(is_empty(ll)) {
    557550                                verify(ll.anchor.next == 0p);
    558551                                ll.prev = mock_head(ll);
    559552                        }
    560         #endif
    561553}
    562554
  • libcfa/src/concurrency/ready_subqueue.hfa

    reeb9f9f rd3ba775  
    3131
    3232        // We add a boat-load of assertions here because the anchor code is very fragile
     33        /* paranoid */ verify( offsetof( $thread, link ) == offsetof(__intrusive_lane_t, anchor) );
    3334        /* paranoid */ verify( ((uintptr_t)( mock_head(this) ) + offsetof( $thread, link )) == (uintptr_t)(&this.anchor) );
    3435        /* paranoid */ verify( &mock_head(this)->link.next == &this.anchor.next );
  • libcfa/src/concurrency/thread.cfa

    reeb9f9f rd3ba775  
    3939        link.next = 0p;
    4040        link.ts   = 0;
    41         link.preferred = -1u;
     41        preferred = -1u;
    4242        last_proc = 0p;
    4343        #if defined( __CFA_WITH_VERIFY__ )
Note: See TracChangeset for help on using the changeset viewer.