6 #include <sys/resource.h>
10 #define PAGE_MASK (PAGE_SIZE - 1)
13 main(int ac
, char **av
)
25 char *msg
= "datarate";
28 fprintf(stderr
, "%s blocksize[k,m] [pipe_writer_pri] [msg]\n", av
[0]);
31 bytes
= strtol(av
[1], &ptr
, 0);
32 if (*ptr
== 'k' || *ptr
== 'K') {
34 } else if (*ptr
== 'm' || *ptr
== 'M') {
37 fprintf(stderr
, "Illegal numerical suffix: %s\n", ptr
);
41 fprintf(stderr
, "I can't handle %d sized buffers\n", bytes
);
45 ppri
= strtol(av
[2], NULL
, 0);
49 buf
= mmap(NULL
, bytes
* 2 + PAGE_SIZE
,
50 PROT_READ
|PROT_WRITE
, MAP_SHARED
|MAP_ANON
, -1, 0);
51 if (buf
== MAP_FAILED
) {
52 perror("mmap/buffer");
56 bzero(buf
, bytes
* 2 + PAGE_SIZE
);
58 printf("tests one-way pipe using direct-write buffer\n");
71 buf
+= (bytes
+ PAGE_MASK
) & ~PAGE_MASK
;
74 n
= read(fds
[1], buf
+ i
, bytes
- i
);
88 if (setpriority(PRIO_PROCESS
, getpid(), ppri
) < 0) {
89 perror("setpriority");
96 * Figure out how many loops it takes for 1 second's worth.
100 if (write(fds
[0], buf
, bytes
) != bytes
) {
104 if ((j
& 31) == 0 && stop_timing(0, NULL
))
109 usleep(1000000 / 10);
112 for (j
= loops
; j
; --j
) {
113 if (write(fds
[0], buf
, bytes
) != bytes
) {
119 while(wait(NULL
) >= 0)
121 stop_timing(loops
, "full duplex pipe / %dK bufs:", bytes
/ 1024);
122 printf("%s: blkSize %d %5.2f MBytes/sec\n",
125 (double)loops
* bytes
* 1000000.0 /
126 (1024.0 * 1024.0 * get_timing()));