Changes in / [a3effcc:a6cafa8]


Ignore:
Files:
2 deleted
2 edited

Legend:

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

    ra3effcc ra6cafa8  
    579579
    580580        // Lock the RWlock so no-one pushes/pops while we are changing the queue
    581         disable_interrupts();
    582581        uint_fast32_t last_size = ready_mutate_lock();
    583582
     
    587586        // Unlock the RWlock
    588587        ready_mutate_unlock( last_size );
    589         enable_interrupts_noPoll(); // Don't poll, could be in main cluster
    590 
    591588
    592589        this.io.cnt  = num_io;
     
    604601
    605602        // Lock the RWlock so no-one pushes/pops while we are changing the queue
    606         disable_interrupts();
    607603        uint_fast32_t last_size = ready_mutate_lock();
    608604
     
    612608        // Unlock the RWlock
    613609        ready_mutate_unlock( last_size );
    614         enable_interrupts_noPoll(); // Don't poll, could be in main cluster
    615610
    616611        #if !defined(__CFA_NO_STATISTICS__)
  • libcfa/src/concurrency/ready_queue.cfa

    ra3effcc ra6cafa8  
    215215}
    216216
    217 static inline [unsigned, bool] idx_from_r(unsigned r, unsigned preferred) {
    218         unsigned i;
    219         bool local;
    220         #if defined(BIAS)
    221                 unsigned rlow  = r % BIAS;
    222                 unsigned rhigh = r / BIAS;
    223                 if((0 != rlow) && preferred >= 0) {
    224                         // (BIAS - 1) out of BIAS chances
    225                         // Use perferred queues
    226                         i = preferred + (rhigh % 4);
    227                         local = true;
    228                 }
    229                 else {
    230                         // 1 out of BIAS chances
    231                         // Use all queues
    232                         i = rhigh;
    233                         local = false;
    234                 }
    235         #else
    236                 i = r;
    237                 local = false;
    238         #endif
    239         return [i, local];
    240 }
    241 
    242217//-----------------------------------------------------------------------
    243218__attribute__((hot)) bool push(struct cluster * cltr, struct $thread * thrd) with (cltr->ready_queue) {
     
    247222        thrd->link.ts = rdtscl();
    248223
    249         __attribute__((unused)) bool local;
    250         __attribute__((unused)) int preferred;
    251         #if defined(BIAS)
    252                 preferred =
     224        #if defined(BIAS) && !defined(__CFA_NO_STATISTICS__)
     225                bool local = false;
     226                int preferred =
    253227                        //*
    254228                        kernelTLS.this_processor ? kernelTLS.this_processor->id * 4 : -1;
     
    256230                        thrd->link.preferred * 4;
    257231                        //*/
     232
     233
    258234        #endif
    259235
     
    262238        do {
    263239                // Pick the index of a lane
    264                 unsigned r = __tls_rand();
    265                 [i, local] = idx_from_r(r, preferred);
    266 
    267                 #if !defined(__CFA_NO_STATISTICS__)
    268                         if(local) {
    269                                 __tls_stats()->ready.pick.push.local++;
    270                         }
     240                #if defined(BIAS)
     241                        unsigned r = __tls_rand();
     242                        unsigned rlow  = r % BIAS;
     243                        unsigned rhigh = r / BIAS;
     244                        if((0 != rlow) && preferred >= 0) {
     245                                // (BIAS - 1) out of BIAS chances
     246                                // Use perferred queues
     247                                i = preferred + (rhigh % 4);
     248
     249                                #if !defined(__CFA_NO_STATISTICS__)
     250                                        local = true;
     251                                        __tls_stats()->ready.pick.push.local++;
     252                                #endif
     253                        }
     254                        else {
     255                                // 1 out of BIAS chances
     256                                // Use all queues
     257                                i = rhigh;
     258                                local = false;
     259                        }
     260                #else
     261                        i = __tls_rand();
    271262                #endif
    272263
     
    320311        /* paranoid */ verify( lanes.count > 0 );
    321312        unsigned count = __atomic_load_n( &lanes.count, __ATOMIC_RELAXED );
    322         int preferred;
    323313        #if defined(BIAS)
    324314                // Don't bother trying locally too much
    325315                int local_tries = 8;
    326                 preferred = kernelTLS.this_processor->id * 4;
    327         #endif
    328 
     316        #endif
    329317
    330318        // As long as the list is not empty, try finding a lane that isn't empty and pop from it
     
    335323        #endif
    336324                // Pick two lists at random
    337                 unsigned ri = __tls_rand();
    338                 unsigned rj = __tls_rand();
    339 
    340                 unsigned i, j;
    341                 __attribute__((unused)) bool locali, localj;
    342                 [i, locali] = idx_from_r(ri, preferred);
    343                 [j, localj] = idx_from_r(rj, preferred);
    344 
    345                 #if !defined(__CFA_NO_STATISTICS__)
    346                         if(locali) {
    347                                 __tls_stats()->ready.pick.pop.local++;
    348                         }
    349                         if(localj) {
    350                                 __tls_stats()->ready.pick.pop.local++;
    351                         }
     325                unsigned i,j;
     326                #if defined(BIAS)
     327                        #if !defined(__CFA_NO_STATISTICS__)
     328                                bool local = false;
     329                        #endif
     330                        uint64_t r = __tls_rand();
     331                        unsigned rlow  = r % BIAS;
     332                        uint64_t rhigh = r / BIAS;
     333                        if(local_tries && 0 != rlow) {
     334                                // (BIAS - 1) out of BIAS chances
     335                                // Use perferred queues
     336                                unsigned pid = kernelTLS.this_processor->id * 4;
     337                                i = pid + (rhigh % 4);
     338                                j = pid + ((rhigh >> 32ull) % 4);
     339
     340                                // count the tries
     341                                local_tries--;
     342
     343                                #if !defined(__CFA_NO_STATISTICS__)
     344                                        local = true;
     345                                        __tls_stats()->ready.pick.pop.local++;
     346                                #endif
     347                        }
     348                        else {
     349                                // 1 out of BIAS chances
     350                                // Use all queues
     351                                i = rhigh;
     352                                j = rhigh >> 32ull;
     353                        }
     354                #else
     355                        i = __tls_rand();
     356                        j = __tls_rand();
    352357                #endif
    353358
     
    359364                if(thrd) {
    360365                        #if defined(BIAS) && !defined(__CFA_NO_STATISTICS__)
    361                                 if( locali || localj ) __tls_stats()->ready.pick.pop.lsuccess++;
     366                                if( local ) __tls_stats()->ready.pick.pop.lsuccess++;
    362367                        #endif
    363368                        return thrd;
Note: See TracChangeset for help on using the changeset viewer.