| 118 | } |
| 119 | |
| 120 | void adjust_histogram(ReuseHistogram* hist, uint64_t total_requests, float rate) { |
| 121 | uint64_t total = hist->cold_miss_bin; |
| 122 | GHashTableIter iter; |
| 123 | gpointer key, value; |
| 124 | g_hash_table_iter_init(&iter, hist->bins); |
| 125 | while (g_hash_table_iter_next(&iter, &key, &value)) { |
| 126 | BinEntry* bin = (BinEntry*)value; |
| 127 | total += bin->frequency; |
| 128 | } |
| 129 | |
| 130 | uint64_t expected = (uint64_t)(total_requests * rate); |
| 131 | |
| 132 | if (expected > total) { |
| 133 | uint64_t diff = expected - total; |
| 134 | // Use get_min_distance to find the smallest distance bucket. |
| 135 | uint64_t min_distance = get_min_distance(hist); |
| 136 | if (min_distance != UINT64_MAX) { |
| 137 | BinEntry* bin = (BinEntry*)g_hash_table_lookup(hist->bins, &min_distance); |
| 138 | if (bin) { |
| 139 | bin->frequency += diff; |
| 140 | } |
| 141 | } |
| 142 | } |
| 143 | } |
no test coverage detected