[708ae38] | 1 | //
|
---|
| 2 | // Cforall Version 1.0.0 Copyright (C) 2022 University of Waterloo
|
---|
| 3 | //
|
---|
| 4 | // The contents of this file are covered under the licence agreement in the
|
---|
| 5 | // file "LICENCE" distributed with Cforall.
|
---|
| 6 | //
|
---|
| 7 | // cluster.hfa -- file that includes helpers for subsystem that need cluster wide support
|
---|
| 8 | //
|
---|
| 9 | // Author : Thierry Delisle
|
---|
| 10 | // Created On : Tue Mar 15 16:40:12 2022
|
---|
| 11 | // Last Modified By :
|
---|
| 12 | // Last Modified On :
|
---|
| 13 | // Update Count :
|
---|
| 14 | //
|
---|
| 15 |
|
---|
| 16 | #include "kernel/private.hfa"
|
---|
| 17 |
|
---|
| 18 | //-----------------------------------------------------------------------
|
---|
| 19 | // Calc moving average based on existing average, before and current time.
|
---|
| 20 | static inline unsigned long long moving_average(unsigned long long currtsc, unsigned long long instsc, unsigned long long old_avg) {
|
---|
| 21 | /* paranoid */ verifyf( currtsc < 45000000000000000, "Suspiciously large current time: %'llu (%llx)\n", currtsc, currtsc );
|
---|
| 22 | /* paranoid */ verifyf( instsc < 45000000000000000, "Suspiciously large insert time: %'llu (%llx)\n", instsc, instsc );
|
---|
| 23 | /* paranoid */ verifyf( old_avg < 15000000000000, "Suspiciously large previous average: %'llu (%llx)\n", old_avg, old_avg );
|
---|
| 24 |
|
---|
| 25 | const unsigned long long new_val = currtsc > instsc ? currtsc - instsc : 0;
|
---|
| 26 | const unsigned long long total_weight = 16;
|
---|
| 27 | const unsigned long long new_weight = 4;
|
---|
| 28 | const unsigned long long old_weight = total_weight - new_weight;
|
---|
| 29 | const unsigned long long ret = ((new_weight * new_val) + (old_weight * old_avg)) / total_weight;
|
---|
| 30 | return ret;
|
---|
| 31 | }
|
---|
| 32 |
|
---|
| 33 | //-----------------------------------------------------------------------
|
---|
| 34 | // Calc age a timestamp should be before needing help.
|
---|
| 35 | forall(Data_t * | { unsigned long long ts(Data_t & this); })
|
---|
| 36 | static inline unsigned long long calc_cutoff(
|
---|
| 37 | const unsigned long long ctsc,
|
---|
| 38 | const processor * proc,
|
---|
| 39 | size_t count,
|
---|
| 40 | Data_t * data,
|
---|
| 41 | __timestamp_t * tscs,
|
---|
| 42 | const unsigned shard_factor
|
---|
| 43 | ) {
|
---|
| 44 | unsigned start = proc->rdq.id;
|
---|
| 45 | unsigned long long max = 0;
|
---|
| 46 | for(i; shard_factor) {
|
---|
| 47 | unsigned long long ptsc = ts(data[start + i]);
|
---|
| 48 | if(ptsc != -1ull) {
|
---|
| 49 | /* paranoid */ verify( start + i < count );
|
---|
| 50 | unsigned long long tsc = moving_average(ctsc, ptsc, tscs[start + i].ma);
|
---|
| 51 | if(tsc > max) max = tsc;
|
---|
| 52 | }
|
---|
| 53 | }
|
---|
| 54 | return (max + 2 * max) / 2;
|
---|
| 55 | }
|
---|
| 56 |
|
---|
| 57 | static inline unsigned cache_id(struct cluster * cltr, unsigned idx) with (cltr->sched) {
|
---|
| 58 | // Figure out the current cpu and make sure it is valid
|
---|
| 59 | const int cpu = __kernel_getcpu();
|
---|
| 60 | /* paranoid */ verify(cpu >= 0);
|
---|
| 61 | /* paranoid */ verify(cpu < cpu_info.hthrd_count);
|
---|
| 62 | unsigned this_cache = cpu_info.llc_map[cpu].cache;
|
---|
| 63 |
|
---|
| 64 | // Super important: don't write the same value over and over again
|
---|
| 65 | // We want to maximise our chances that his particular values stays in cache
|
---|
| 66 | if(caches[idx].id != this_cache)
|
---|
| 67 | __atomic_store_n(&caches[idx].id, this_cache, __ATOMIC_RELAXED);
|
---|
| 68 |
|
---|
| 69 | return this_cache;
|
---|
| 70 | }
|
---|
| 71 |
|
---|
| 72 | static struct {
|
---|
| 73 | const unsigned readyq;
|
---|
| 74 | } __shard_factor = { 2 };
|
---|
| 75 |
|
---|
| 76 | // Local Variables: //
|
---|
| 77 | // mode: c //
|
---|
| 78 | // tab-width: 4 //
|
---|
| 79 | // End: //
|
---|