Date: Wed, 3 Feb 2010 00:29:39 GMT From: Robert Watson <rwatson@FreeBSD.org> To: Perforce Change Reviews <perforce@freebsd.org> Subject: PERFORCE change 174201 for review Message-ID: <201002030029.o130TdN5043888@repoman.freebsd.org>
next in thread | raw e-mail | index | archive | help
http://p4web.freebsd.org/chv.cgi?CH=174201 Change 174201 by rwatson@rwatson_vimage_client on 2010/02/03 00:29:28 Allow multiple loops of a test to be run, not just iterations within a test. Add microbenchmark to compare cost of creating a shared memory object w/o a capability, and cost w/ a capability. Affected files ... .. //depot/projects/trustedbsd/capabilities/src/tools/tools/syscall_timing/syscall_timing.c#3 edit Differences ... ==== //depot/projects/trustedbsd/capabilities/src/tools/tools/syscall_timing/syscall_timing.c#3 (text+ko) ==== @@ -254,6 +254,52 @@ } void +test_shmfd(int num) +{ + int i, shmfd; + + shmfd = shm_open(SHM_ANON, O_CREAT | O_RDWR, 0600); + if (shmfd < 0) + err(-1, "test_shmfd: shm_open"); + close(shmfd); + benchmark_start(); + for (i = 0; i < num; i++) { + shmfd = shm_open(SHM_ANON, O_CREAT | O_RDWR, 0600); + if (shmfd < 0) + err(-1, "test_shmfd: shm_open"); + close(shmfd); + } + benchmark_stop(); +} + +void +test_cap_shmfd(int num) +{ + int fd, i, shmfd; + + shmfd = shm_open(SHM_ANON, O_CREAT | O_RDWR, 0600); + if (shmfd < 0) + err(-1, "test_cap_shmfd: shm_open"); + fd = cap_new(shmfd, 0); + if (fd < 0) + err(-1, "test_cap_shmfd: cap_new"); + close(fd); + close(shmfd); + benchmark_start(); + for (i = 0; i < num; i++) { + shmfd = shm_open(SHM_ANON, O_CREAT | O_RDWR, 0600); + if (shmfd < 0) + err(-1, "test_cap_shmfd: shm_open"); + fd = cap_new(shmfd, 0); + if (fd < 0) + err(-1, "test_cap_shmfd: cap_new"); + close(fd); + close(shmfd); + } + benchmark_stop(); +} + +void test_fstat_shmfd(int num) { struct stat sb; @@ -309,6 +355,8 @@ { "socketpair_dgram", test_socketpair_dgram }, { "dup", test_dup }, { "cap_new", test_cap_new }, + { "test_shmfd", test_shmfd }, + { "test_cap_shmfd", test_cap_shmfd }, { "fstat_shmfd", test_fstat_shmfd }, { "fstat_cap_shmfd", test_fstat_cap_shmfd }, }; @@ -319,7 +367,7 @@ { int i; - fprintf(stderr, "syscall_timing [iterations] [test]\n"); + fprintf(stderr, "syscall_timing [iterations] [loops] [test]\n"); for (i = 0; i < tests_count; i++) fprintf(stderr, " %s\n", tests[i].t_name); exit(-1); @@ -330,41 +378,55 @@ { struct timespec ts_res; const struct test *the_test; - int count, i; + long long ll; + char *endp; + int i, j, k; + int iterations, loops; + + if (argc < 3) + usage(); + + ll = strtoll(argv[1], &endp, 10); + if (*endp != 0 || ll < 0 || ll > 100000) + usage(); + iterations = ll; - if (argc != 3) + ll = strtoll(argv[2], &endp, 10); + if (*endp != 0 || ll < 0 || ll > 100000) usage(); - count = atoi(argv[1]); + loops = ll; assert(clock_getres(CLOCK_REALTIME, &ts_res) == 0); printf("Clock resolution: %ju.%ju\n", (uintmax_t)ts_res.tv_sec, (uintmax_t)ts_res.tv_nsec); + printf("test\tloop\ttotal\titerations\tperiteration\n"); - the_test = NULL; - for (i = 0; i < tests_count; i++) { - if (strcmp(argv[2], tests[i].t_name) == 0) - the_test = &tests[i]; - } - if (the_test == NULL) - usage(); + for (j = 3; j < argc; j++) { + the_test = NULL; + for (i = 0; i < tests_count; i++) { + if (strcmp(argv[j], tests[i].t_name) == 0) + the_test = &tests[i]; + } + if (the_test == NULL) + usage(); - the_test->t_func(count); + for (k = 0; k < loops; k++) { + the_test->t_func(iterations); + timespecsub(&ts_end, &ts_start); + printf("%s\t%d\t", the_test->t_name, k); + printf("%ju.%09ju\t%d\t", (uintmax_t)ts_end.tv_sec, + (uintmax_t)ts_end.tv_nsec, iterations); - timespecsub(&ts_end, &ts_start); - - printf("test: %s\n", argv[2]); - - printf("%ju.%09ju for %d iterations\n", (uintmax_t)ts_end.tv_sec, - (uintmax_t)ts_end.tv_nsec, count); - - /* - * Note. This assumes that each iteration takes less than - * a second, and that our total nanoseconds doesn't exceed - * the room in our arithmetic unit. Fine for system calls, - * but not for long things. - */ - ts_end.tv_sec *= 1000000000 / count; - printf("0.%09ju per/iteration\n", - (uintmax_t)(ts_end.tv_sec + ts_end.tv_nsec / count)); + /* + * Note. This assumes that each iteration takes less than + * a second, and that our total nanoseconds doesn't exceed + * the room in our arithmetic unit. Fine for system calls, + * but not for long things. + */ + ts_end.tv_sec *= 1000000000 / iterations; + printf("0.%09ju\n", (uintmax_t)(ts_end.tv_sec + + ts_end.tv_nsec / iterations)); + } + } return (0); }
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201002030029.o130TdN5043888>