Skip to content

Commit 32e8ba6

Browse files
committed
use geometrical mean for cache time
Signed-off-by: Pavel Boldin <boldin.pavel@gmail.com>
1 parent ebdfa35 commit 32e8ba6

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

meltdown.c

+13-1
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,18 @@ int usage(void)
147147
return 1;
148148
}
149149

150+
static int mysqrt(long val)
151+
{
152+
int root = val / 2, prevroot = 0, i = 0;
153+
154+
while (prevroot != root && i < 100) {
155+
prevroot = root;
156+
root = (val / root + root) / 2;
157+
}
158+
159+
return root;
160+
}
161+
150162
#define ESTIMATE_CYCLES 1000000
151163
static void
152164
set_cache_hit_threshold(void)
@@ -172,7 +184,7 @@ set_cache_hit_threshold(void)
172184
cached /= ESTIMATE_CYCLES;
173185
uncached /= ESTIMATE_CYCLES;
174186

175-
CACHE_HIT_THRESHOLD = (cached + uncached) / 2;
187+
CACHE_HIT_THRESHOLD = mysqrt(cached * uncached);
176188

177189
printf("cached = %ld, uncached = %ld, threshold %d\n",
178190
cached, uncached, CACHE_HIT_THRESHOLD);

0 commit comments

Comments
 (0)