The accuracy improves for longer durations to the

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: here none of the data is initially cached, we can flush the cache of any useful data before performing the actual measurement. The following procedure does this for a system with caches of no more than 512KB: code/perf/time p.c 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 /* Number of bytes in the largest cache to be cleared */ #define CBYTES (1<<19) #define CINTS (CBYTES/sizeof(int)) /* A large array to bring into cache */ static int dummy[CINTS]; volatile int sink; /* Evict the existing blocks from the data caches */ void clear_cache() { int i; int sum = 0; for (i = 0; i < CINTS; i++) dummy[i] = 3; for (i = 0; i < CINTS; i++) sum += dummy[i]; sink = sum; } code/perf/time p.c This procedure simply performs a computation over a very large array dummy, effectively evicting everything else from the cache. The code has several peculiar features to avoid common pitfalls. It both stores values into dummy and reads them back so that it will be cached regardless of the cache allocati...
View Full Document

Ask a homework question - tutors are online