4 * $DragonFly: src/test/sysperf/pipe2.c,v 1.3 2004/04/01 01:47:44 dillon Exp $
8 #include <sys/resource.h>
10 #define LOOPS ((int)(1000000LL * 16384 / bytes / divisor))
13 main(int ac, char **av)
27 fprintf(stderr, "%s blocksize[k,m] [pipe_writer_pri]\n", av[0]);
30 bytes = strtol(av[1], &ptr, 0);
31 if (*ptr == 'k' || *ptr == 'K') {
33 } else if (*ptr == 'm' || *ptr == 'M') {
36 fprintf(stderr, "Illegal numerical suffix: %s\n", ptr);
40 fprintf(stderr, "I can't handle %d sized buffers\n", bytes);
44 ppri = strtol(av[2], NULL, 0);
47 * Tiny block sizes, try to take into account overhead.
50 divisor = 4096 / bytes;
51 else if (bytes > 1024 * 1024)
56 if ((buf = malloc(bytes)) == NULL) {
63 printf("tests one-way pipe using direct-write buffer\n");
73 while (read(fds[1], buf, bytes) > 0)
81 if (setpriority(PRIO_PROCESS, getpid(), ppri) < 0) {
82 perror("setpriority");
87 write(fds[0], buf, bytes); /* prime the caches */
89 for (j = LOOPS; j; --j) {
90 if (write(fds[0], buf, bytes) != bytes) {
96 while(wait(NULL) >= 0);
97 stop_timing(LOOPS, "full duplex pipe / %dK bufs:", bytes / 1024);
98 printf("datarate: %5.2f MBytes/sec\n",
99 (double)LOOPS * bytes * 1000000.0 /
100 (1024.0 * 1024.0 * get_timing()));