|
Lines 43-53
Link Here
|
| 43 |
private clock_t |
|
|
| 44 |
time_clear(char *buf, int bsize, int nreps) |
| 45 |
{ |
| 46 |
clock_t t = clock(); |
| 47 |
int i; |
| 48 |
|
| 49 |
for (i = 0; i < nreps; ++i) |
| 50 |
memset(buf, 0, bsize); |
| 51 |
return clock() - t; |
| 52 |
} |
| 53 |
|
|
Lines 181-243
Link Here
|
| 181 |
#undef PRINT_MAX |
170 |
#undef PRINT_MAX |
| 182 |
|
|
|
| 183 |
section(f, "Cache sizes"); |
| 184 |
|
| 185 |
/* |
| 186 |
* Determine the primary and secondary cache sizes by looking for a |
| 187 |
* non-linearity in the time required to fill blocks with memset. |
| 188 |
*/ |
| 189 |
{ |
| 190 |
#define MAX_BLOCK (1 << 20) |
| 191 |
static char buf[MAX_BLOCK]; |
| 192 |
int bsize = 1 << 10; |
| 193 |
int nreps = 1; |
| 194 |
clock_t t = 0; |
| 195 |
clock_t t_eps; |
| 196 |
|
| 197 |
/* |
| 198 |
* Increase the number of repetitions until the time is |
| 199 |
* long enough to exceed the likely uncertainty. |
| 200 |
*/ |
| 201 |
|
| 202 |
while ((t = time_clear(buf, bsize, nreps)) == 0) |
| 203 |
nreps <<= 1; |
| 204 |
t_eps = t; |
| 205 |
while ((t = time_clear(buf, bsize, nreps)) < t_eps * 10) |
| 206 |
nreps <<= 1; |
| 207 |
|
| 208 |
/* |
| 209 |
* Increase the block size until the time jumps non-linearly. |
| 210 |
*/ |
| 211 |
for (; bsize <= MAX_BLOCK;) { |
| 212 |
clock_t dt = time_clear(buf, bsize, nreps); |
| 213 |
|
| 214 |
if (dt > t + (t >> 1)) { |
| 215 |
t = dt; |
| 216 |
break; |
| 217 |
} |
| 218 |
bsize <<= 1; |
| 219 |
nreps >>= 1; |
| 220 |
if (nreps == 0) |
| 221 |
nreps = 1, t <<= 1; |
| 222 |
} |
| 223 |
define_int(f, "ARCH_CACHE1_SIZE", bsize >> 1); |
| 224 |
/* |
| 225 |
* Do the same thing a second time for the secondary cache. |
| 226 |
*/ |
| 227 |
if (nreps > 1) |
| 228 |
nreps >>= 1, t >>= 1; |
| 229 |
for (; bsize <= MAX_BLOCK;) { |
| 230 |
clock_t dt = time_clear(buf, bsize, nreps); |
| 231 |
|
| 232 |
if (dt > t * 1.25) { |
| 233 |
t = dt; |
| 234 |
break; |
| 235 |
} |
| 236 |
bsize <<= 1; |
| 237 |
nreps >>= 1; |
| 238 |
if (nreps == 0) |
| 239 |
nreps = 1, t <<= 1; |
| 240 |
} |
| 241 |
define_int(f, "ARCH_CACHE2_SIZE", bsize >> 1); |
| 242 |
} |
| 243 |
|
171 |
|
| 244 |
------ end of patches/patch-ac |
|
|
| 245 |
------ begin patches/patch-ad |