/* [<][>][^][v][top][bottom][index][help] */
DEFINITIONS
This source file includes following definitions.
- main
1 /*
2 * tlbfaulter.c
3 *
4 * This program creates an array larger than the TLB footprint,
5 * but hopefully smaller than memory.
6 * It first touches each page of the array once, which should cause
7 * each page to be loaded into memory.
8 * Then it touches the pages sequentially in a tight loop - the
9 * goal is to force the TLB to be filled quickly, so that TLB
10 * replacements will be necessary.
11 *
12 * If this generates "out of memory" errors, you will need
13 * to increase the memory size of the machine (in sys161.conf)
14 * to run this test.
15 */
16
17 #include <stdio.h>
18 #include <stdlib.h>
19
20 /*
21 * set these to match the page size of the
22 * machine and the number of entries in the TLB
23 */
24 #define PageSize 4096
25 #define TLBSize 64
26
27 /* an array a bit larger than the size of the TLB footprint */
28 #define ArraySize ((TLBSize+5)*PageSize)
29 char tlbtest[ArraySize];
30
31 int
32 main()
33 {
34 int i,j;
35
36 printf("Starting the tlbfaulter program\n");
37
38 /* load up the array */
39 for (i=0; i<ArraySize; i++) {
40 tlbtest[i]= 'a';
41 }
42
43 printf("tlbfaulter: array initialization completed\n");
44
45 /* touch one array entry on each page, sequentially, 5 times */
46 for(j=0; j<5; j++) {
47 for (i=0; i<ArraySize; i+=PageSize) {
48 tlbtest[i] += 1;
49 }
50 }
51
52 printf("tlbfaulter: array updates completed\n");
53
54 /* check the array values we updated */
55 for (i=0; i<ArraySize; i+=PageSize) {
56 if (tlbtest[i] != ('a'+5)) {
57 printf("Test failed! Unexpected value at array position %d\n", i);
58 return(1);
59 }
60 }
61
62 printf("SUCCESS\n");
63
64 return 0;
65 }
66