Ignore:
Timestamp:
Jun 19, 2020, 11:22:32 AM (4 years ago)
Author:
Thierry Delisle <tdelisle@…>
Branches:
ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum
Children:
64a7146
Parents:
37ba662
Message:

Added BIAS option to ready_queue
Added yield test for LibFibre?
Fixed some alignments and minor optimizations

Location:
libcfa/src/concurrency
Files:
2 edited

Legend:

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

    r37ba662 r04b5cef  
    342342                                /* paranoid */ verifyf( readyThread->state == Ready || readyThread->preempted != __NO_PREEMPTION, "state : %d, preempted %d\n", readyThread->state, readyThread->preempted);
    343343                                /* paranoid */ verifyf( readyThread->link.next == 0p, "Expected null got %p", readyThread->link.next );
     344                                __builtin_prefetch( readyThread->context.SP );
    344345
    345346                                // We found a thread run it
  • libcfa/src/concurrency/ready_queue.cfa

    r37ba662 r04b5cef  
    2424#include "math.hfa"
    2525
     26#include <unistd.h>
     27
    2628static const size_t cache_line_size = 64;
    2729
     
    3133        #define __CFA_MAX_PROCESSORS__ 1024
    3234#endif
     35
     36#define BIAS 64
    3337
    3438// returns the maximum number of processors the RWLock support
     
    568572        do {
    569573                // Pick the index of a lane
    570                 i = __tls_rand() % lanes.count;
     574                #if defined(BIAS)
     575                        unsigned r = __tls_rand();
     576                        unsigned rlow  = r % BIAS;
     577                        unsigned rhigh = r / BIAS;
     578                        if(0 != (rlow % BIAS) && kernelTLS.this_processor) {
     579                                // (BIAS - 1) out of BIAS chances
     580                                // Use perferred queues
     581                                i = (kernelTLS.this_processor->id * 4) + (rhigh % 4);
     582                        }
     583                        else {
     584                                // 1 out of BIAS chances
     585                                // Use all queues
     586                                i = rhigh;
     587                        }
     588                #else
     589                        i = __tls_rand();
     590                #endif
     591
     592                i %= __atomic_load_n( &lanes.count, __ATOMIC_RELAXED );
    571593
    572594                #if !defined(__CFA_NO_STATISTICS__)
     
    666688        while( query(snzi) ) {
    667689                // Pick two lists at random
    668                 int i = __tls_rand() % __atomic_load_n( &lanes.count, __ATOMIC_RELAXED );
    669                 int j = __tls_rand() % __atomic_load_n( &lanes.count, __ATOMIC_RELAXED );
     690                #if defined(BIAS)
     691                        unsigned i = __tls_rand();
     692                        unsigned j = __tls_rand();
     693
     694                        if(0 == (i % BIAS)) {
     695                                i = i / BIAS;
     696                        }
     697                        else {
     698                                i = ((kernelTLS.this_processor->id * 4) + ((i / BIAS) % 4));
     699                                j = ((kernelTLS.this_processor->id * 4) + ((j / BIAS) % 4));
     700                        }
     701                #else
     702                        unsigned i = __tls_rand();
     703                        unsigned j = __tls_rand();
     704                #endif
     705
     706                i %= __atomic_load_n( &lanes.count, __ATOMIC_RELAXED );
     707                j %= __atomic_load_n( &lanes.count, __ATOMIC_RELAXED );
    670708
    671709                // try popping from the 2 picked lists
Note: See TracChangeset for help on using the changeset viewer.