8 #include <sys/resource.h>
9 #include <sys/socket.h>
12 #define PAGE_SIZE 4096
13 #define PAGE_MASK (PAGE_SIZE - 1)
16 main(int ac
, char **av
)
28 char *msg
= "datarate";
31 fprintf(stderr
, "%s blocksize[k,m] [pipe_writer_pri] [msg]\n", av
[0]);
34 bytes
= strtol(av
[1], &ptr
, 0);
35 if (*ptr
== 'k' || *ptr
== 'K') {
37 } else if (*ptr
== 'm' || *ptr
== 'M') {
40 fprintf(stderr
, "Illegal numerical suffix: %s\n", ptr
);
44 fprintf(stderr
, "I can't handle %d sized buffers\n", bytes
);
48 ppri
= strtol(av
[2], NULL
, 0);
52 buf
= mmap(NULL
, bytes
* 2 + PAGE_SIZE
, PROT_READ
|PROT_WRITE
, MAP_SHARED
|MAP_ANON
, -1, 0);
53 if (buf
== MAP_FAILED
) {
54 perror("mmap/buffer");
58 bzero(buf
, bytes
* 2 + PAGE_SIZE
);
60 printf("tests one-way socketpair\n");
61 if (socketpair(AF_LOCAL
, SOCK_STREAM
, PF_UNSPEC
, fds
)) {
73 buf
+= (bytes
+ PAGE_MASK
) & ~PAGE_MASK
;
76 n
= read(fds
[1], buf
+ i
, bytes
- i
);
90 if (setpriority(PRIO_PROCESS
, getpid(), ppri
) < 0) {
91 perror("setpriority");
98 * Figure out how many loops it takes for 1 second's worth.
102 if (write(fds
[0], buf
, bytes
) != bytes
) {
106 if ((j
& 31) == 0 && stop_timing(0, NULL
))
110 usleep(1000000 / 10);
113 for (j
= loops
; j
; --j
) {
114 if (write(fds
[0], buf
, bytes
) != bytes
) {
120 while(wait(NULL
) >= 0)
122 stop_timing(loops
, "full duplex socketpair / %dK bufs:", bytes
/ 1024);
123 printf("%s: blkSize %d %5.2f MBytes/sec\n",
126 (double)loops
* bytes
* 1000000.0 /
127 (1024.0 * 1024.0 * get_timing()));