Annotation of Net2/tests/benchmarks/bench-4.1/gausspage.c, revision 1.1

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: 
        !            10: float  sqrt(), log(), rnd(), cos(), gauss();
        !            11: char   *valloc();
        !            12: int    rand();
        !            13: 
        !            14: main(argc, argv)
        !            15:        char *argv[];
        !            16: {
        !            17:        register int pn, i, niter, delta;
        !            18:        register char *pages;
        !            19:        float sd = 10.0;
        !            20:        int npages = 4096, pagesize, debug = 0;
        !            21:        char *name;
        !            22: 
        !            23:        name = argv[0];
        !            24:        argc--, argv++;
        !            25: again:
        !            26:        if (argc < 1) {
        !            27: usage:
        !            28:                printf(
        !            29: "usage: %s [ -d ] [ -p #pages ] [ -s standard-deviation ] iterations\n", name);
        !            30:                exit(1);
        !            31:        }
        !            32:        if (strcmp(*argv, "-s") == 0) {
        !            33:                argc--, argv++;
        !            34:                if (argc < 1)
        !            35:                        goto usage;
        !            36:                sscanf(*argv, "%f", &sd);
        !            37:                if (sd <= 0) {
        !            38:                        printf("%s: Bad standard deviation.\n", *argv);
        !            39:                        exit(2);
        !            40:                }
        !            41:                argc--, argv++;
        !            42:                goto again;
        !            43:        }
        !            44:        if (strcmp(*argv, "-p") == 0) {
        !            45:                argc--, argv++;
        !            46:                if (argc < 1)
        !            47:                        goto usage;
        !            48:                npages = atoi(*argv);
        !            49:                if (npages <= 0) {
        !            50:                        printf("%s: Bad page count.\n", *argv);
        !            51:                        exit(2);
        !            52:                }
        !            53:                argc--, argv++;
        !            54:                goto again;
        !            55:        }
        !            56:        if (strcmp(*argv, "-d") == 0) {
        !            57:                argc--, argv++;
        !            58:                debug++;
        !            59:                goto again;
        !            60:        }
        !            61:        niter = atoi(*argv);
        !            62:        pagesize = getpagesize();
        !            63:        pages = valloc(npages*pagesize);
        !            64:        if (pages == (char *)0) {
        !            65:                printf("Can't allocate %d pages (%2.1f megabytes).\n",
        !            66:                    npages, (npages*pagesize) / (1024. * 1024.));
        !            67:                exit(3);
        !            68:        }
        !            69:        pn = 0;
        !            70:        for (i = 0; i < niter; i++) {
        !            71:                delta = gauss(sd, 0.0);
        !            72:                while (pn + delta < 0 || pn + delta > npages)
        !            73:                        delta = gauss(sd, 0.0);
        !            74:                pn += delta;
        !            75:                if (debug)
        !            76:                        printf("touch page %d\n", pn);
        !            77:                else
        !            78:                        pages[pn * pagesize] = 1;
        !            79:        }
        !            80: }
        !            81: 
        !            82: float
        !            83: gauss(sd, mean)
        !            84:        float sd, mean;
        !            85: {
        !            86:        register float qa, qb;
        !            87: 
        !            88:        qa = sqrt(log(rnd()) * -2.0);
        !            89:        qb = 3.14159 * rnd();
        !            90:        return (qa * cos(qb) * sd + mean);
        !            91: }
        !            92: 
        !            93: float
        !            94: rnd()
        !            95: {
        !            96:        static int seed = 1;
        !            97:        static int biggest = 0x7fffffff;
        !            98: 
        !            99:        return ((float)rand(seed) / (float)biggest);
        !           100: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.