diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..f79318f --- /dev/null +++ b/LICENSE @@ -0,0 +1,22 @@ +The MIT License (MIT) + +Copyright (c) 2016 Erik Rigtorp + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. + diff --git a/Makefile b/Makefile index d3ba973..dd804e9 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ -CFLAGS = -g +CFLAGS = -g -Wall -O3 all: pipe_lat pipe_thr \ unix_lat unix_thr \ diff --git a/README.md b/README.md index 1e3d31e..5f161bc 100644 --- a/README.md +++ b/README.md @@ -20,4 +20,9 @@ The shared memory benchmark is a kind of "control". If run under a real-time OS it will give you the intra core communication latency. -This software is distributed under the MIT License. \ No newline at end of file +This software is distributed under the MIT License. + +Credits +------- + +* *desbma* for adding cross platform support for clock_gettime \ No newline at end of file diff --git a/pipe_lat.c b/pipe_lat.c index 06ac14d..e251866 100644 --- a/pipe_lat.c +++ b/pipe_lat.c @@ -2,7 +2,7 @@ Measure latency of IPC using unix domain sockets - Copyright (c) 2010 Erik Rigtorp + Copyright (c) 2016 Erik Rigtorp Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation @@ -26,21 +26,19 @@ OTHER DEALINGS IN THE SOFTWARE. */ - +#include #include #include #include #include -#include #include -#if defined(_POSIX_TIMERS) && (_POSIX_TIMERS > 0) && defined(_POSIX_MONOTONIC_CLOCK) +#if defined(_POSIX_TIMERS) && (_POSIX_TIMERS > 0) && \ + defined(_POSIX_MONOTONIC_CLOCK) #define HAS_CLOCK_GETTIME_MONOTONIC #endif - -int main(int argc, char *argv[]) -{ +int main(int argc, char *argv[]) { int ofds[2]; int ifds[2]; @@ -54,7 +52,7 @@ int main(int argc, char *argv[]) #endif if (argc != 3) { - printf ("usage: pipe_lat \n"); + printf("usage: pipe_lat \n"); return 1; } @@ -68,7 +66,7 @@ int main(int argc, char *argv[]) } printf("message size: %i octets\n", size); - printf("roundtrip count: %lli\n", count); + printf("roundtrip count: %li\n", count); if (pipe(ofds) == -1) { perror("pipe"); @@ -80,7 +78,7 @@ int main(int argc, char *argv[]) return 1; } - if (!fork()) { /* child */ + if (!fork()) { /* child */ for (i = 0; i < count; i++) { if (read(ifds[0], buf, size) != size) { @@ -118,7 +116,6 @@ int main(int argc, char *argv[]) perror("read"); return 1; } - } #ifdef HAS_CLOCK_GETTIME_MONOTONIC @@ -136,13 +133,12 @@ int main(int argc, char *argv[]) return 1; } - delta = (stop.tv_sec - start.tv_sec) * 1000000 + - (stop.tv_usec - start.tv_usec); + delta = + (stop.tv_sec - start.tv_sec) * 1000000 + (stop.tv_usec - start.tv_usec); #endif - printf("average latency: %lli us\n", delta / (count * 2)); - + printf("average latency: %li us\n", delta / (count * 2)); } return 0; diff --git a/pipe_thr.c b/pipe_thr.c index 158be89..566483b 100644 --- a/pipe_thr.c +++ b/pipe_thr.c @@ -2,7 +2,7 @@ Measure throughput of IPC using pipes - Copyright (c) 2010 Erik Rigtorp + Copyright (c) 2016 Erik Rigtorp Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation @@ -26,21 +26,19 @@ OTHER DEALINGS IN THE SOFTWARE. */ - +#include #include #include #include #include -#include #include -#if defined(_POSIX_TIMERS) && (_POSIX_TIMERS > 0) && defined(_POSIX_MONOTONIC_CLOCK) +#if defined(_POSIX_TIMERS) && (_POSIX_TIMERS > 0) && \ + defined(_POSIX_MONOTONIC_CLOCK) #define HAS_CLOCK_GETTIME_MONOTONIC #endif - -int main(int argc, char *argv[]) -{ +int main(int argc, char *argv[]) { int fds[2]; int size; @@ -53,7 +51,7 @@ int main(int argc, char *argv[]) #endif if (argc != 3) { - printf ("usage: pipe_thr \n"); + printf("usage: pipe_thr \n"); return 1; } @@ -67,7 +65,7 @@ int main(int argc, char *argv[]) } printf("message size: %i octets\n", size); - printf("message count: %lli\n", count); + printf("message count: %li\n", count); if (pipe(fds) == -1) { perror("pipe"); @@ -84,7 +82,7 @@ int main(int argc, char *argv[]) } } } else { - /* parent */ +/* parent */ #ifdef HAS_CLOCK_GETTIME_MONOTONIC if (clock_gettime(CLOCK_MONOTONIC, &start) == -1) { @@ -120,13 +118,14 @@ int main(int argc, char *argv[]) return 1; } - delta = (stop.tv_sec - start.tv_sec) * 1000000 + - (stop.tv_usec - start.tv_usec); + delta = + (stop.tv_sec - start.tv_sec) * 1000000 + (stop.tv_usec - start.tv_usec); #endif - printf("average throughput: %lli msg/s\n", (count * 1000000) / delta); - printf("average throughput: %lli Mb/s\n", (((count * 1000000) / delta) * size * 8) / 1000000); + printf("average throughput: %li msg/s\n", (count * 1000000) / delta); + printf("average throughput: %li Mb/s\n", + (((count * 1000000) / delta) * size * 8) / 1000000); } return 0; diff --git a/shm.c b/shm.c index d59cf9a..6b2d516 100644 --- a/shm.c +++ b/shm.c @@ -1,20 +1,46 @@ -/* Measure latency of IPC using shm */ +/* + Measure latency of IPC using shm + + Copyright (c) 2016 Erik Rigtorp + + Permission is hereby granted, free of charge, to any person + obtaining a copy of this software and associated documentation + files (the "Software"), to deal in the Software without + restriction, including without limitation the rights to use, + copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following + conditions: + + The above copyright notice and this permission notice shall be + included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES + OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT + HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + OTHER DEALINGS IN THE SOFTWARE. +*/ +#include #include #include -#include -#include -#include #include #include +#include +#include +#include +#include -int main(void) -{ +int main(void) { int shmid; key_t key; - struct timespec *shm; + struct timeval *shm; - struct timespec start, stop; + struct timeval start, stop; int64_t delta; @@ -42,7 +68,7 @@ int main(void) /* * Now we attach the segment to our data space. */ - if ((shm = shmat(shmid, NULL, 0)) == (struct timespec*) -1) { + if ((shm = shmat(shmid, NULL, 0)) == (struct timeval *)-1) { perror("shmat"); return 1; } @@ -66,18 +92,19 @@ int main(void) /* * Now we attach the segment to our data space. */ - if ((shm = shmat(shmid, NULL, 0)) == (struct timespec *) -1) { + if ((shm = shmat(shmid, NULL, 0)) == (struct timeval *)-1) { perror("shmat"); return 1; } while (1) { - while ((shm->tv_sec == start.tv_sec) && (shm->tv_nsec == start.tv_nsec)) {} + while ((shm->tv_sec == start.tv_sec) && (shm->tv_usec == start.tv_usec)) { + } gettimeofday(&stop, NULL); start = *shm; - delta = ((stop.tv_sec - start.tv_sec) * (int64_t) 1000000000 + - stop.tv_nsec - start.tv_nsec); + delta = ((stop.tv_sec - start.tv_sec) * 1000000 + stop.tv_usec - + start.tv_usec); if (delta > max) max = delta; @@ -88,7 +115,7 @@ int main(void) count++; if (!(count % 100)) { - printf("%lli %lli %lli\n", max, min, sum / count); + printf("%li %li %li\n", max, min, sum / count); } } } diff --git a/tcp_lat.c b/tcp_lat.c index 0d7ab91..7d674a6 100644 --- a/tcp_lat.c +++ b/tcp_lat.c @@ -2,7 +2,7 @@ Measure latency of IPC using tcp sockets - Copyright (c) 2010 Erik Rigtorp + Copyright (c) 2016 Erik Rigtorp Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation @@ -26,23 +26,21 @@ OTHER DEALINGS IN THE SOFTWARE. */ - +#include +#include #include #include -#include #include +#include #include -#include -#include #include -#if defined(_POSIX_TIMERS) && (_POSIX_TIMERS > 0) && defined(_POSIX_MONOTONIC_CLOCK) +#if defined(_POSIX_TIMERS) && (_POSIX_TIMERS > 0) && \ + defined(_POSIX_MONOTONIC_CLOCK) #define HAS_CLOCK_GETTIME_MONOTONIC #endif - -int main(int argc, char *argv[]) -{ +int main(int argc, char *argv[]) { int size; char *buf; int64_t count, i, delta; @@ -64,7 +62,7 @@ int main(int argc, char *argv[]) int sockfd, new_fd; if (argc != 3) { - printf ("usage: tcp_lat \n"); + printf("usage: tcp_lat \n"); return 1; } @@ -78,20 +76,21 @@ int main(int argc, char *argv[]) } memset(&hints, 0, sizeof hints); - hints.ai_family = AF_UNSPEC; // use IPv4 or IPv6, whichever + hints.ai_family = AF_UNSPEC; // use IPv4 or IPv6, whichever hints.ai_socktype = SOCK_STREAM; - hints.ai_flags = AI_PASSIVE; // fill in my IP for me + hints.ai_flags = AI_PASSIVE; // fill in my IP for me if ((ret = getaddrinfo("127.0.0.1", "3491", &hints, &res)) != 0) { fprintf(stderr, "getaddrinfo: %s\n", gai_strerror(ret)); return 1; } printf("message size: %i octets\n", size); - printf("roundtrip count: %lli\n", count); + printf("roundtrip count: %li\n", count); - if (!fork()) { /* child */ + if (!fork()) { /* child */ - if ((sockfd = socket(res->ai_family, res->ai_socktype, res->ai_protocol)) == -1) { + if ((sockfd = socket(res->ai_family, res->ai_socktype, res->ai_protocol)) == + -1) { perror("socket"); return 1; } @@ -113,14 +112,15 @@ int main(int argc, char *argv[]) addr_size = sizeof their_addr; - if ((new_fd = accept(sockfd, (struct sockaddr *)&their_addr, &addr_size)) == -1) { + if ((new_fd = accept(sockfd, (struct sockaddr *)&their_addr, &addr_size)) == + -1) { perror("accept"); return 1; } for (i = 0; i < count; i++) { - for (sofar = 0; sofar < size; ) { + for (sofar = 0; sofar < size;) { len = read(new_fd, buf, size - sofar); if (len == -1) { perror("read"); @@ -138,7 +138,8 @@ int main(int argc, char *argv[]) sleep(1); - if ((sockfd = socket(res->ai_family, res->ai_socktype, res->ai_protocol)) == -1) { + if ((sockfd = socket(res->ai_family, res->ai_socktype, res->ai_protocol)) == + -1) { perror("socket"); return 1; } @@ -167,7 +168,7 @@ int main(int argc, char *argv[]) return 1; } - for (sofar = 0; sofar < size; ) { + for (sofar = 0; sofar < size;) { len = read(sockfd, buf, size - sofar); if (len == -1) { perror("read"); @@ -175,7 +176,6 @@ int main(int argc, char *argv[]) } sofar += len; } - } #ifdef HAS_CLOCK_GETTIME_MONOTONIC @@ -193,13 +193,12 @@ int main(int argc, char *argv[]) return 1; } - delta = (stop.tv_sec - start.tv_sec) * 1000000 + - (stop.tv_usec - start.tv_usec); + delta = + (stop.tv_sec - start.tv_sec) * 1000000 + (stop.tv_usec - start.tv_usec); #endif - printf("average latency: %lli us\n", delta / (count * 2)); - + printf("average latency: %li us\n", delta / (count * 2)); } return 0; diff --git a/tcp_local_lat.c b/tcp_local_lat.c index 0e36d09..c9cb950 100644 --- a/tcp_local_lat.c +++ b/tcp_local_lat.c @@ -2,7 +2,7 @@ Measure latency of IPC using tcp sockets - Copyright (c) 2010 Erik Rigtorp + Copyright (c) 2016 Erik Rigtorp Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation @@ -26,18 +26,17 @@ OTHER DEALINGS IN THE SOFTWARE. */ - +#include +#include #include #include -#include #include +#include +#include #include -#include -#include - +#include -int main(int argc, char *argv[]) -{ +int main(int argc, char *argv[]) { int size; char *buf; int64_t count, i; @@ -54,7 +53,8 @@ int main(int argc, char *argv[]) int sockfd, new_fd; if (argc != 5) { - printf ("usage: tcp_local_lat \n"); + printf("usage: tcp_local_lat " + "\n"); return 1; } @@ -68,18 +68,19 @@ int main(int argc, char *argv[]) } printf("message size: %i octets\n", size); - printf("roundtrip count: %lli\n", count); + printf("roundtrip count: %li\n", count); memset(&hints, 0, sizeof hints); - hints.ai_family = AF_UNSPEC; // use IPv4 or IPv6, whichever + hints.ai_family = AF_UNSPEC; // use IPv4 or IPv6, whichever hints.ai_socktype = SOCK_STREAM; - hints.ai_flags = AI_PASSIVE; // fill in my IP for me + hints.ai_flags = AI_PASSIVE; // fill in my IP for me if ((ret = getaddrinfo(argv[1], argv[2], &hints, &res)) != 0) { fprintf(stderr, "getaddrinfo: %s\n", gai_strerror(ret)); return 1; } - if ((sockfd = socket(res->ai_family, res->ai_socktype, res->ai_protocol)) == -1) { + if ((sockfd = socket(res->ai_family, res->ai_socktype, res->ai_protocol)) == + -1) { perror("socket"); return 1; } @@ -101,14 +102,15 @@ int main(int argc, char *argv[]) addr_size = sizeof their_addr; - if ((new_fd = accept(sockfd, (struct sockaddr *)&their_addr, &addr_size)) == -1) { + if ((new_fd = accept(sockfd, (struct sockaddr *)&their_addr, &addr_size)) == + -1) { perror("accept"); return 1; } for (i = 0; i < count; i++) { - for (sofar = 0; sofar < size; ) { + for (sofar = 0; sofar < size;) { len = read(new_fd, buf, size - sofar); if (len == -1) { perror("read"); diff --git a/tcp_remote_lat.c b/tcp_remote_lat.c index bb59108..bc860fe 100644 --- a/tcp_remote_lat.c +++ b/tcp_remote_lat.c @@ -2,7 +2,7 @@ Measure latency of IPC using tcp sockets - Copyright (c) 2010 Erik Rigtorp + Copyright (c) 2016 Erik Rigtorp Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation @@ -26,18 +26,17 @@ OTHER DEALINGS IN THE SOFTWARE. */ - +#include +#include #include #include -#include #include +#include +#include #include -#include -#include +#include - -int main(int argc, char *argv[]) -{ +int main(int argc, char *argv[]) { int size; char *buf; int64_t count, i, delta; @@ -52,7 +51,8 @@ int main(int argc, char *argv[]) int sockfd; if (argc != 6) { - printf ("usage: tcp_lat \n"); + printf("usage: tcp_lat " + "\n"); return 1; } @@ -66,18 +66,19 @@ int main(int argc, char *argv[]) } printf("message size: %i octets\n", size); - printf("roundtrip count: %lli\n", count); + printf("roundtrip count: %li\n", count); memset(&hints, 0, sizeof hints); - hints.ai_family = AF_UNSPEC; // use IPv4 or IPv6, whichever + hints.ai_family = AF_UNSPEC; // use IPv4 or IPv6, whichever hints.ai_socktype = SOCK_STREAM; - hints.ai_flags = AI_PASSIVE; // fill in my IP for me + hints.ai_flags = AI_PASSIVE; // fill in my IP for me if ((ret = getaddrinfo(argv[1], NULL, &hints, &res)) != 0) { fprintf(stderr, "getaddrinfo: %s\n", gai_strerror(ret)); return 1; } - if ((sockfd = socket(res->ai_family, res->ai_socktype, res->ai_protocol)) == -1) { + if ((sockfd = socket(res->ai_family, res->ai_socktype, res->ai_protocol)) == + -1) { perror("socket"); return 1; } @@ -97,7 +98,7 @@ int main(int argc, char *argv[]) return 1; } - gettimeofday(&start); + gettimeofday(&start, NULL); for (i = 0; i < count; i++) { @@ -106,7 +107,7 @@ int main(int argc, char *argv[]) return 1; } - for (sofar = 0; sofar < size; ) { + for (sofar = 0; sofar < size;) { len = read(sockfd, buf, size - sofar); if (len == -1) { perror("read"); @@ -114,15 +115,14 @@ int main(int argc, char *argv[]) } sofar += len; } - } - gettimeofday(&stop); + gettimeofday(&stop, NULL); + + delta = + ((stop.tv_sec - start.tv_sec) * 1000000 + stop.tv_usec - start.tv_usec); - delta = ((stop.tv_sec - start.tv_sec) * (int64_t) 1e6 + - stop.tv_usec - start.tv_usec); - - printf("average latency: %lli us\n", delta / (count * 2)); + printf("average latency: %li us\n", delta / (count * 2)); return 0; } diff --git a/tcp_thr.c b/tcp_thr.c index 8506f53..8be3282 100644 --- a/tcp_thr.c +++ b/tcp_thr.c @@ -2,7 +2,7 @@ Measure throughput of IPC using tcp sockets - Copyright (c) 2010 Erik Rigtorp + Copyright (c) 2016 Erik Rigtorp Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation @@ -26,25 +26,22 @@ OTHER DEALINGS IN THE SOFTWARE. */ - +#include +#include +#include #include #include -#include #include +#include #include -#include -#include -#include #include -#if defined(_POSIX_TIMERS) && (_POSIX_TIMERS > 0) && defined(_POSIX_MONOTONIC_CLOCK) +#if defined(_POSIX_TIMERS) && (_POSIX_TIMERS > 0) && \ + defined(_POSIX_MONOTONIC_CLOCK) #define HAS_CLOCK_GETTIME_MONOTONIC #endif - - -int main(int argc, char *argv[]) -{ +int main(int argc, char *argv[]) { int size; char *buf; int64_t count, i, delta; @@ -66,7 +63,7 @@ int main(int argc, char *argv[]) int sockfd, new_fd; if (argc != 3) { - printf ("usage: tcp_thr \n"); + printf("usage: tcp_thr \n"); return 1; } @@ -80,21 +77,22 @@ int main(int argc, char *argv[]) } memset(&hints, 0, sizeof hints); - hints.ai_family = AF_UNSPEC; // use IPv4 or IPv6, whichever + hints.ai_family = AF_UNSPEC; // use IPv4 or IPv6, whichever hints.ai_socktype = SOCK_STREAM; - hints.ai_flags = AI_PASSIVE; // fill in my IP for me + hints.ai_flags = AI_PASSIVE; // fill in my IP for me if ((ret = getaddrinfo("127.0.0.1", "3491", &hints, &res)) != 0) { fprintf(stderr, "getaddrinfo: %s\n", gai_strerror(ret)); return 1; } printf("message size: %i octets\n", size); - printf("message count: %lli\n", count); + printf("message count: %li\n", count); if (!fork()) { /* child */ - if ((sockfd = socket(res->ai_family, res->ai_socktype, res->ai_protocol)) == -1) { + if ((sockfd = socket(res->ai_family, res->ai_socktype, res->ai_protocol)) == + -1) { perror("socket"); return 1; } @@ -116,7 +114,8 @@ int main(int argc, char *argv[]) addr_size = sizeof their_addr; - if ((new_fd = accept(sockfd, (struct sockaddr *)&their_addr, &addr_size)) == -1) { + if ((new_fd = accept(sockfd, (struct sockaddr *)&their_addr, &addr_size)) == + -1) { perror("accept"); return 1; } @@ -124,7 +123,7 @@ int main(int argc, char *argv[]) for (sofar = 0; sofar < (count * size);) { len = read(new_fd, buf, size); if (len == -1) { - perror("read"); + perror("read"); return 1; } sofar += len; @@ -134,7 +133,8 @@ int main(int argc, char *argv[]) sleep(1); - if ((sockfd = socket(res->ai_family, res->ai_socktype, res->ai_protocol)) == -1) { + if ((sockfd = socket(res->ai_family, res->ai_socktype, res->ai_protocol)) == + -1) { perror("socket"); return 1; } @@ -183,13 +183,14 @@ int main(int argc, char *argv[]) return 1; } - delta = (stop.tv_sec - start.tv_sec) * 1000000 + - (stop.tv_usec - start.tv_usec); + delta = + (stop.tv_sec - start.tv_sec) * 1000000 + (stop.tv_usec - start.tv_usec); #endif - printf("average throughput: %lli msg/s\n", (count * 1000000) / delta); - printf("average throughput: %lli Mb/s\n", (((count * 1000000) / delta) * size * 8) / 1000000); + printf("average throughput: %li msg/s\n", (count * 1000000) / delta); + printf("average throughput: %li Mb/s\n", + (((count * 1000000) / delta) * size * 8) / 1000000); } return 0; diff --git a/unix_lat.c b/unix_lat.c index 6c64474..f0bcbbc 100644 --- a/unix_lat.c +++ b/unix_lat.c @@ -2,7 +2,7 @@ Measure latency of IPC using unix domain sockets - Copyright (c) 2010 Erik Rigtorp + Copyright (c) 2016 Erik Rigtorp Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation @@ -26,21 +26,19 @@ OTHER DEALINGS IN THE SOFTWARE. */ - +#include #include #include #include #include -#include #include -#if defined(_POSIX_TIMERS) && (_POSIX_TIMERS > 0) && defined(_POSIX_MONOTONIC_CLOCK) +#if defined(_POSIX_TIMERS) && (_POSIX_TIMERS > 0) && \ + defined(_POSIX_MONOTONIC_CLOCK) #define HAS_CLOCK_GETTIME_MONOTONIC #endif - -int main(int argc, char *argv[]) -{ +int main(int argc, char *argv[]) { int sv[2]; /* the pair of socket descriptors */ int size; char *buf; @@ -52,7 +50,7 @@ int main(int argc, char *argv[]) #endif if (argc != 3) { - printf ("usage: unix_lat \n"); + printf("usage: unix_lat \n"); return 1; } @@ -66,14 +64,14 @@ int main(int argc, char *argv[]) } printf("message size: %i octets\n", size); - printf("roundtrip count: %lli\n", count); + printf("roundtrip count: %li\n", count); if (socketpair(AF_UNIX, SOCK_STREAM, 0, sv) == -1) { perror("socketpair"); return 1; } - if (!fork()) { /* child */ + if (!fork()) { /* child */ for (i = 0; i < count; i++) { if (read(sv[1], buf, size) != size) { @@ -111,7 +109,6 @@ int main(int argc, char *argv[]) perror("read"); return 1; } - } #ifdef HAS_CLOCK_GETTIME_MONOTONIC @@ -129,13 +126,12 @@ int main(int argc, char *argv[]) return 1; } - delta = (stop.tv_sec - start.tv_sec) * 1000000 + - (stop.tv_usec - start.tv_usec); + delta = + (stop.tv_sec - start.tv_sec) * 1000000 + (stop.tv_usec - start.tv_usec); #endif - printf("average latency: %lli us\n", delta / (count * 2)); - + printf("average latency: %li us\n", delta / (count * 2)); } return 0; diff --git a/unix_thr.c b/unix_thr.c index 85e69fd..00f0a00 100644 --- a/unix_thr.c +++ b/unix_thr.c @@ -2,7 +2,7 @@ Measure throughput of IPC using unix domain sockets. - Copyright (c) 2010 Erik Rigtorp + Copyright (c) 2016 Erik Rigtorp Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation @@ -26,21 +26,19 @@ OTHER DEALINGS IN THE SOFTWARE. */ - +#include #include #include #include #include -#include #include -#if defined(_POSIX_TIMERS) && (_POSIX_TIMERS > 0) && defined(_POSIX_MONOTONIC_CLOCK) +#if defined(_POSIX_TIMERS) && (_POSIX_TIMERS > 0) && \ + defined(_POSIX_MONOTONIC_CLOCK) #define HAS_CLOCK_GETTIME_MONOTONIC #endif - -int main(int argc, char *argv[]) -{ +int main(int argc, char *argv[]) { int fds[2]; /* the pair of socket descriptors */ int size; char *buf; @@ -52,7 +50,7 @@ int main(int argc, char *argv[]) #endif if (argc != 3) { - printf ("usage: unix_thr \n"); + printf("usage: unix_thr \n"); return 1; } @@ -66,7 +64,7 @@ int main(int argc, char *argv[]) } printf("message size: %i octets\n", size); - printf("message count: %lli\n", count); + printf("message count: %li\n", count); if (socketpair(AF_UNIX, SOCK_STREAM, 0, fds) == -1) { perror("socketpair"); @@ -83,7 +81,7 @@ int main(int argc, char *argv[]) } } } else { - /* parent */ +/* parent */ #ifdef HAS_CLOCK_GETTIME_MONOTONIC if (clock_gettime(CLOCK_MONOTONIC, &start) == -1) { @@ -119,13 +117,14 @@ int main(int argc, char *argv[]) return 1; } - delta = (stop.tv_sec - start.tv_sec) * 1000000 + - (stop.tv_usec - start.tv_usec); + delta = + (stop.tv_sec - start.tv_sec) * 1000000 + (stop.tv_usec - start.tv_usec); #endif - printf("average throughput: %lli msg/s\n", (count * 1000000) / delta); - printf("average throughput: %lli Mb/s\n", (((count * 1000000) / delta) * size * 8) / 1000000); + printf("average throughput: %li msg/s\n", (count * 1000000) / delta); + printf("average throughput: %li Mb/s\n", + (((count * 1000000) / delta) * size * 8) / 1000000); } return 0;