We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent ebdfa35 commit 32e8ba6Copy full SHA for 32e8ba6
meltdown.c
@@ -147,6 +147,18 @@ int usage(void)
147
return 1;
148
}
149
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
162
#define ESTIMATE_CYCLES 1000000
163
static void
164
set_cache_hit_threshold(void)
@@ -172,7 +184,7 @@ set_cache_hit_threshold(void)
172
184
cached /= ESTIMATE_CYCLES;
173
185
uncached /= ESTIMATE_CYCLES;
174
186
175
- CACHE_HIT_THRESHOLD = (cached + uncached) / 2;
187
+ CACHE_HIT_THRESHOLD = mysqrt(cached * uncached);
176
188
177
189
printf("cached = %ld, uncached = %ld, threshold %d\n",
178
190
cached, uncached, CACHE_HIT_THRESHOLD);
0 commit comments