Repository navigation
Expand file tree
/
Copy pathcooling.c
More file actions
61 lines (54 loc) · 1.9 KB
/
Copy pathcooling.c
File metadata and controls
61 lines (54 loc) · 1.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
/* SPDX-License-Identifier: MIT */
/* Copyright (c) 2026 MoatLab, Virginia Tech. */
/* cooling.c — cooling factor α (Algorithm 1).
*
* PAC update has form pac[p] ← α · pac[p] + S_p with α ∈ [0, 1]. Default
* α = 1.0 (pure accumulation, no cooling). When α < 1.0, cooling is
* triggered every cooling_trigger_samples PEBS samples (default 200000):
* the cooling coroutine walks every PAC entry and multiplies pac_value
* by α (or zeros it when α = 0).
*/
#include <stdint.h>
#include "pact.h"
#include "cooling.h"
/* Apply α decay to one PAC entry. α = 1.0 → no-op; α = 0 → reset; otherwise
* multiply. */
static inline void cool_one_entry(pac_metadata_t *meta, double alpha)
{
if (alpha == 0.0) {
meta->pac_value = 0;
} else {
meta->pac_value = (uint64_t)((double)meta->pac_value * alpha);
}
}
/* Sweep one PAC table: apply cooling to every entry, yielding every 10K
* processed to keep other coroutines responsive. */
static void cool_pac_table(pact_context_t *ctx, pac_table_t *table, double alpha, mco_coro *co)
{
uint64_t processed = 0;
khint_t k;
kh_foreach(table, k)
{
cool_one_entry(kh_val(table, k), alpha);
if (++processed % 10000 == 0) {
mco_yield(co);
}
}
ctx->workload->stats.cooling_decays += processed;
}
void cooling_coroutine(mco_coro *co)
{
pact_context_t *ctx = (pact_context_t *)mco_get_user_data(co);
uint64_t last_trigger_count = 0;
while (ctx->running) {
/* Default α = 1.0: no cooling. Skip the table walk entirely. */
if (ctx->cooling_alpha < 1.0) {
uint64_t current = ctx->sample_counts;
if (current - last_trigger_count >= ctx->cooling_trigger_samples) {
cool_pac_table(ctx, ctx->workload->pac_table, ctx->cooling_alpha, co);
last_trigger_count = current;
}
}
mco_yield(co);
}
}