Ignore:
File:
1 edited

Legend:

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

    r0fb3ee5 ra2a4566  
    303303                        lanes.help[idx].dst = 0;
    304304                        lanes.help[idx].tri = 0;
     305                }
     306
     307                caches = alloc( cpu_info.llc_count );
     308                for( idx; (size_t)cpu_info.llc_count ) {
     309                        (caches[idx]){};
    305310                }
    306311        #else
     
    399404                /* paranoid */ verify(cpu < cpu_info.hthrd_count);
    400405                unsigned this_cache = cpu_info.llc_map[cpu].cache;
    401 
    402                 // Super important: don't write the same value over and over again
    403                 // We want to maximise our chances that his particular values stays in cache
    404                 if(lanes.caches[this / READYQ_SHARD_FACTOR].id != this_cache)
    405                         __atomic_store_n(&lanes.caches[this / READYQ_SHARD_FACTOR].id, this_cache, __ATOMIC_RELAXED);
     406                __atomic_store_n(&lanes.caches[this / READYQ_SHARD_FACTOR].id, this_cache, __ATOMIC_RELAXED);
    406407
    407408                const unsigned long long ctsc = rdtscl();
     
    505506        }
    506507
     508        static inline int pop_getcpu(processor * proc, __ready_queue_caches_t * caches) {
     509                const int prv = proc->rdq.cpu;
     510                const int cpu = __kernel_getcpu();
     511                if( prv != proc->rdq.cpu ) {
     512                        unsigned pidx = cpu_info.llc_map[prv].cache;
     513                        /* paranoid */ verify(pidx < cpu_info.llc_count);
     514
     515                        unsigned nidx = cpu_info.llc_map[cpu].cache;
     516                        /* paranoid */ verify(pidx < cpu_info.llc_count);
     517
     518                        depart(caches[pidx]);
     519                        arrive(caches[nidx]);
     520
     521                        __STATS( /* cpu migs++ */ )
     522                }
     523                return proc->rdq.cpu = cpu;
     524        }
     525
    507526        // Pop from the ready queue from a given cluster
    508527        __attribute__((hot)) thread$ * pop_fast(struct cluster * cltr) with (cltr->ready_queue) {
     
    511530
    512531                processor * const proc = kernelTLS().this_processor;
    513                 const int cpu = __kernel_getcpu();
     532                const int cpu = pop_getcpu( proc, caches );
     533                // const int cpu = __kernel_getcpu();
    514534                /* paranoid */ verify(cpu >= 0);
    515535                /* paranoid */ verify(cpu < cpu_info.hthrd_count);
     
    528548                        unsigned long long max = 0;
    529549                        for(i; READYQ_SHARD_FACTOR) {
    530                                 unsigned long long tsc = moving_average(ctsc, ts(lanes.data[start + i]), lanes.tscs[start + i].ma);
     550                                unsigned long long tsc = moving_average(ctsc - ts(lanes.data[start + i]), lanes.tscs[start + i].ma);
    531551                                if(tsc > max) max = tsc;
    532552                        }
     
    549569                        unsigned long long max = 0;
    550570                        for(i; READYQ_SHARD_FACTOR) {
    551                                 unsigned long long tsc = moving_average(ctsc, ts(lanes.data[start + i]), lanes.tscs[start + i].ma);
     571                                unsigned long long tsc = moving_average(ctsc - ts(lanes.data[start + i]), lanes.tscs[start + i].ma);
    552572                                if(tsc > max) max = tsc;
    553573                        }
     
    557577                                proc->rdq.target = MAX;
    558578                                lanes.help[target / READYQ_SHARD_FACTOR].tri++;
    559                                 if(moving_average(ctsc, lanes.tscs[target].tv, lanes.tscs[target].ma) > cutoff) {
     579                                if(moving_average(ctsc - lanes.tscs[target].tv, lanes.tscs[target].ma) > cutoff) {
     580                                        __STATS( __tls_stats()->ready.pop.helped[target]++; )
    560581                                        thread$ * t = try_pop(cltr, target __STATS(, __tls_stats()->ready.pop.help));
    561582                                        proc->rdq.last = target;
     
    566587
    567588                        unsigned last = proc->rdq.last;
    568                         if(last != MAX && moving_average(ctsc, lanes.tscs[last].tv, lanes.tscs[last].ma) > cutoff) {
     589                        if(last != MAX && moving_average(ctsc - lanes.tscs[last].tv, lanes.tscs[last].ma) > cutoff) {
     590                                __STATS( __tls_stats()->ready.pop.helped[last]++; )
    569591                                thread$ * t = try_pop(cltr, last __STATS(, __tls_stats()->ready.pop.help));
    570592                                if(t) return t;
Note: See TracChangeset for help on using the changeset viewer.