| 33 | } |
| 34 | |
| 35 | candidate_t LHD::rank(const request_t* req) { |
| 36 | uint64_t victim = -1; |
| 37 | rank_t victimRank = std::numeric_limits<rank_t>::max(); |
| 38 | |
| 39 | // Sample few candidates early in the trace so that we converge |
| 40 | // quickly to a reasonable policy. |
| 41 | // |
| 42 | // This is a hack to let us have shorter warmup so we can evaluate |
| 43 | // a longer fraction of the trace; doesn't belong in a real |
| 44 | // system. |
| 45 | uint32_t candidates = (numReconfigurations > 50) ? ASSOCIATIVITY : 8; |
| 46 | |
| 47 | for (uint32_t i = 0; i < candidates; i++) { |
| 48 | auto idx = next_rand() % tags.size(); |
| 49 | auto& tag = tags[idx]; |
| 50 | rank_t rank = getHitDensity(tag); |
| 51 | |
| 52 | if (rank < victimRank) { |
| 53 | victim = idx; |
| 54 | victimRank = rank; |
| 55 | } |
| 56 | } |
| 57 | |
| 58 | for (uint32_t i = 0; i < ADMISSIONS; i++) { |
| 59 | auto itr = indices.find(recentlyAdmitted[i]); |
| 60 | if (itr == indices.end()) { |
| 61 | continue; |
| 62 | } |
| 63 | |
| 64 | auto idx = itr->second; |
| 65 | auto& tag = tags[idx]; |
| 66 | assert(tag.id == recentlyAdmitted[i]); |
| 67 | rank_t rank = getHitDensity(tag); |
| 68 | |
| 69 | if (rank < victimRank) { |
| 70 | victim = idx; |
| 71 | victimRank = rank; |
| 72 | } |
| 73 | } |
| 74 | |
| 75 | assert(victim != (uint64_t)-1); |
| 76 | |
| 77 | ewmaVictimHitDensity = |
| 78 | EWMA_DECAY * ewmaVictimHitDensity + (1 - EWMA_DECAY) * victimRank; |
| 79 | |
| 80 | return tags[victim].id; |
| 81 | } |
| 82 | |
| 83 | void LHD::update(candidate_t id, const request_t* req) { |
| 84 | auto itr = indices.find(id); |