|
|
1.1 ! root 1: /* ! 2: * Random page access with ! 3: * a gaussian distribution. ! 4: * ! 5: * Allocate a large (zero fill on demand) address ! 6: * space and fault the pages in a random gaussian ! 7: * order. ! 8: */ ! 9: #include <math.h> ! 10: ! 11: float rnd(), gauss(); ! 12: char *valloc(); ! 13: int rand(); ! 14: ! 15: main(argc, argv) ! 16: char *argv[]; ! 17: { ! 18: register int pn, i, niter, delta; ! 19: register char *pages; ! 20: float sd = 10.0; ! 21: int npages = 4096, pagesize, debug = 0; ! 22: char *name; ! 23: ! 24: name = argv[0]; ! 25: argc--, argv++; ! 26: again: ! 27: if (argc < 1) { ! 28: usage: ! 29: printf( ! 30: "usage: %s [ -d ] [ -k #Kb ] [ -s standard-deviation ] iterations\n", name); ! 31: exit(1); ! 32: } ! 33: if (strcmp(*argv, "-s") == 0) { ! 34: argc--, argv++; ! 35: if (argc < 1) ! 36: goto usage; ! 37: sscanf(*argv, "%f", &sd); ! 38: if (sd <= 0) { ! 39: printf("%s: Bad standard deviation.\n", *argv); ! 40: exit(2); ! 41: } ! 42: argc--, argv++; ! 43: goto again; ! 44: } ! 45: if (strcmp(*argv, "-k") == 0) { ! 46: argc--, argv++; ! 47: if (argc < 1) ! 48: goto usage; ! 49: npages = atoi(*argv); ! 50: if (npages <= 0) { ! 51: printf("%s: Bad virtual memory size.\n", *argv); ! 52: exit(2); ! 53: } ! 54: argc--, argv++; ! 55: goto again; ! 56: } ! 57: if (strcmp(*argv, "-d") == 0) { ! 58: argc--, argv++; ! 59: debug++; ! 60: goto again; ! 61: } ! 62: niter = atoi(*argv); ! 63: pagesize = getpagesize(); ! 64: npages /= pagesize / 1024; ! 65: pages = valloc(npages, pagesize); ! 66: if (pages == (char *)0) { ! 67: printf("Can't allocate %d pages (%2.1f megabytes).\n", ! 68: npages, (npages*pagesize) / (1024. * 1024.)); ! 69: exit(3); ! 70: } ! 71: if (pagesize != 1024) ! 72: printf("Pagesize %dKb\n", pagesize / 1024); ! 73: pn = 0; ! 74: for (i = 0; i < niter; i++) { ! 75: delta = gauss(sd, 0.0); ! 76: while (pn + delta < 0 || pn + delta > npages) ! 77: delta = gauss(sd, 0.0); ! 78: pn += delta; ! 79: if (debug) ! 80: printf("touch page %d\n", pn); ! 81: else ! 82: pages[pn * pagesize] = 1; ! 83: } ! 84: } ! 85: ! 86: float ! 87: gauss(sd, mean) ! 88: float sd, mean; ! 89: { ! 90: register float qa, qb; ! 91: ! 92: qa = sqrt(log(rnd()) * -2.0); ! 93: qb = 3.14159 * rnd(); ! 94: return (qa * cos(qb) * sd + mean); ! 95: } ! 96: ! 97: float ! 98: rnd() ! 99: { ! 100: static int seed = 1; ! 101: static int biggest = 0x7fffffff; ! 102: ! 103: return ((float)rand(seed) / (float)biggest); ! 104: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.