os161-1.99
 All Data Structures
tlbfaulter.c
00001 /* 
00002  * tlbfaulter.c
00003  *
00004  *      This program creates an array larger than the TLB footprint,
00005  *      but hopefully smaller than memory.
00006  *      It first touches each page of the array once, which should cause
00007  *      each page to be loaded into memory.
00008  *      Then it touches the pages sequentially in a tight loop - the
00009  *      goal is to force the TLB to be filled quickly, so that TLB
00010  *      replacements will be necessary.
00011  *
00012  *      If this generates "out of memory" errors, you will need
00013  *      to increase the memory size of the machine (in sys161.conf)
00014  *      to run this test.
00015  */
00016 
00017 #include <stdio.h>
00018 #include <stdlib.h>
00019 
00020 /* 
00021  * set these to match the page size of the 
00022  * machine and the number of entries in the TLB
00023  */
00024 #define PageSize  4096
00025 #define TLBSize     64
00026 
00027 /* an array a bit larger than the size of the TLB footprint */
00028 #define ArraySize ((TLBSize+5)*PageSize)
00029 char tlbtest[ArraySize];
00030 
00031 int
00032 main()
00033 {
00034         int i,j;
00035 
00036         printf("Starting the tlbfaulter program\n");
00037 
00038         /* load up the array */
00039         for (i=0; i<ArraySize; i++) {
00040           tlbtest[i]= 'a';
00041         }
00042         
00043         printf("tlbfaulter: array initialization completed\n");
00044         
00045         /* touch one array entry on each page, sequentially, 5 times */
00046         for(j=0; j<5; j++) {
00047           for (i=0; i<ArraySize; i+=PageSize) {
00048             tlbtest[i] += 1;
00049           }
00050         }
00051         
00052         printf("tlbfaulter: array updates completed\n");
00053 
00054         /* check the array values we updated */
00055         for (i=0; i<ArraySize; i+=PageSize) {
00056           if (tlbtest[i] != ('a'+5)) {
00057             printf("Test failed! Unexpected value at array position %d\n", i);
00058             return(1);
00059           }
00060         }
00061 
00062         printf("SUCCESS\n");
00063         
00064         return 0;
00065 }
00066 
 All Data Structures