tlbfaulter.c 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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. #include <stdio.h>
  17. #include <stdlib.h>
  18. /*
  19. * set these to match the page size of the
  20. * machine and the number of entries in the TLB
  21. */
  22. #define PageSize 4096
  23. #define TLBSize 64
  24. /* an array a bit larger than the size of the TLB footprint */
  25. #define ArraySize ((TLBSize+5)*PageSize)
  26. char tlbtest[ArraySize];
  27. int
  28. main()
  29. {
  30. int i,j;
  31. printf("Starting the tlbfaulter program\n");
  32. /* load up the array */
  33. for (i=0; i<ArraySize; i++) {
  34. tlbtest[i]= 'a';
  35. }
  36. printf("tlbfaulter: array initialization completed\n");
  37. /* touch one array entry on each page, sequentially, 5 times */
  38. for(j=0; j<5; j++) {
  39. for (i=0; i<ArraySize; i+=PageSize) {
  40. tlbtest[i] += 1;
  41. }
  42. }
  43. printf("tlbfaulter: array updates completed\n");
  44. /* check the array values we updated */
  45. for (i=0; i<ArraySize; i+=PageSize) {
  46. if (tlbtest[i] != ('a'+5)) {
  47. printf("Test failed! Unexpected value at array position %d\n", i);
  48. return(1);
  49. }
  50. }
  51. printf("SUCCESS\n");
  52. return 0;
  53. }