diff --git a/aio-sig.c b/aio-sig.c index 408aa6f372b9bdcd360d9b2cb909feae7cc79cdf..f496ca0a26be11bc8b291d5fca30a304e5b4ebd3 100644 --- a/aio-sig.c +++ b/aio-sig.c @@ -11,10 +11,9 @@ struct aiocb aiocb; atomic_int done; -void callback(int sig, siginfo_t* info, void* context) { +void callback(int sig, siginfo_t *info, void *context) { stop_watch(); - if (info->si_value.sival_int != 42) - errx(EXIT_FAILURE, "got unexpected sigval value"); + if (info->si_value.sival_int != 42) errx(EXIT_FAILURE, "got unexpected sigval value"); atomic_store(&done, 1); } @@ -29,21 +28,19 @@ void init(int fd) { sa.sa_sigaction = callback; sigemptyset(&sa.sa_mask); sa.sa_flags = SA_SIGINFO; - if (sigaction(SIGUSR1, &sa, NULL) == -1) - err(EXIT_FAILURE, "sigaction failed"); + if (sigaction(SIGUSR1, &sa, NULL) == -1) err(EXIT_FAILURE, "sigaction failed"); } -void do_write(int fd, const void* buf, size_t count) { - aiocb.aio_buf = (void*)buf; +void do_write(int fd, const void *buf, size_t count) { + aiocb.aio_buf = (void *)buf; aiocb.aio_nbytes = count; start_watch(); int res = aio_write(&aiocb); - if (res == -1) - err(EXIT_FAILURE, "aio_write failed"); + if (res == -1) err(EXIT_FAILURE, "aio_write failed"); - while(!atomic_load(&done)) {} + while (!atomic_load(&done)) { + } atomic_store(&done, 1); - } diff --git a/aio-thrd.c b/aio-thrd.c index 7e03762494143bb9db4027bbcc301249e5974c22..ef7c36508e9ae140c8a8e80fdbeab2c92f7911d4 100644 --- a/aio-thrd.c +++ b/aio-thrd.c @@ -13,8 +13,7 @@ struct aiocb aiocb; void callback(union sigval sigval) { stop_watch(); - if (sigval.sival_int != 42) - errx(EXIT_FAILURE, "got unexpected sigval value"); + if (sigval.sival_int != 42) errx(EXIT_FAILURE, "got unexpected sigval value"); atomic_store(&done, 1); } @@ -26,16 +25,16 @@ void init(int fd) { aiocb.aio_sigevent.sigev_value.sival_int = 42; } -void do_write(int fd, void* buf, size_t count) { +void do_write(int fd, void *buf, size_t count) { aiocb.aio_buf = buf; aiocb.aio_nbytes = count; start_watch(); int res = aio_write(&aiocb); - while(!atomic_load(&done)) {} + while (!atomic_load(&done)) { + } atomic_store(&done, 0); - if (res == -1) - err(EXIT_FAILURE, "aio_write failed"); + if (res == -1) err(EXIT_FAILURE, "aio_write failed"); } diff --git a/bench.c b/bench.c index 38c2828341a9a11527f080436d2841a3a1b78979..6f2c3c4822cf34913da2b7ba5641558878404ea1 100644 --- a/bench.c +++ b/bench.c @@ -8,7 +8,7 @@ #include "stopwatch.h" void init(int fd); -void do_write(int fd, const void* buf, size_t count); +void do_write(int fd, const void *buf, size_t count); const size_t warmup = 10000; const size_t iterations = 1000000; @@ -31,8 +31,7 @@ int main() { init(fd); - for (size_t i = 0; i < warmup; ++i) - do_write(fd, &write_buf, sizeof(write_buf)); + for (size_t i = 0; i < warmup; ++i) do_write(fd, &write_buf, sizeof(write_buf)); for (int64_t i = 1; i <= iterations; ++i) { do_write(fd, &write_buf, sizeof(write_buf)); diff --git a/blocking.c b/blocking.c index 513e62199fc5a44d099d6e0ede0601e5e02b2ae5..3f3cdbdb44a5baf3d0b4c27bf4c67dd812655423 100644 --- a/blocking.c +++ b/blocking.c @@ -6,11 +6,10 @@ void init(__attribute__((unused)) int fd) {} -void do_write(int fd, const void* buf, size_t count) { +void do_write(int fd, const void *buf, size_t count) { start_watch(); ssize_t res = write(fd, buf, count); stop_watch(); - if (res == -1) - err(EXIT_FAILURE, "write failed"); + if (res == -1) err(EXIT_FAILURE, "write failed"); } diff --git a/epoll.c b/epoll.c index a4ef79a398d03ec8fda17534a611abd58ea8e5f2..dd27dd8ab48a010aa7209de17ac4d20e923d9ae3 100644 --- a/epoll.c +++ b/epoll.c @@ -10,29 +10,23 @@ int nfds, epollfd; void init(int fd) { epollfd = epoll_create1(0); - if (epollfd == -1) - err(EXIT_FAILURE, "creating epoll failed"); + if (epollfd == -1) err(EXIT_FAILURE, "creating epoll failed"); ev.events = EPOLLOUT; ev.data.fd = fd; - if (epoll_ctl(epollfd, EPOLL_CTL_ADD, fd, &ev) == -1) - err(EXIT_FAILURE, "epoll_ctl failed"); - + if (epoll_ctl(epollfd, EPOLL_CTL_ADD, fd, &ev) == -1) err(EXIT_FAILURE, "epoll_ctl failed"); } -void do_write(int fd, const void* buf, size_t count) { +void do_write(int fd, const void *buf, size_t count) { start_watch(); nfds = epoll_wait(epollfd, &ev, 1, -1); size_t res = write(fd, buf, count); stop_watch(); - if (nfds == -1) - err(EXIT_FAILURE, "epoll_wait failed"); + if (nfds == -1) err(EXIT_FAILURE, "epoll_wait failed"); - if (ev.data.fd != fd) - errx(EXIT_FAILURE, "got unexpected fd from epoll"); + if (ev.data.fd != fd) errx(EXIT_FAILURE, "got unexpected fd from epoll"); - if (res == -1) - err(EXIT_FAILURE, "write failed"); + if (res == -1) err(EXIT_FAILURE, "write failed"); } diff --git a/io-uring-no-syscall.c b/io-uring-no-syscall.c index aa0cef02e0b1023a613bd64d71b68b537993d02d..01bd4cbc9145d064b947cae820712684e882969d 100644 --- a/io-uring-no-syscall.c +++ b/io-uring-no-syscall.c @@ -17,7 +17,7 @@ void init(__attribute__((unused)) int fd) { } } -void do_write(int fd, const void* buf, size_t count) { +void do_write(int fd, const void *buf, size_t count) { start_watch(); struct io_uring_sqe *sqe = io_uring_get_sqe(&ring); while (unlikely(!sqe)) { @@ -27,8 +27,9 @@ void do_write(int fd, const void* buf, size_t count) { int res = io_uring_submit(&ring); - struct io_uring_cqe* cqe; - while (io_uring_peek_cqe(&ring, &cqe) == -EAGAIN) {} + struct io_uring_cqe *cqe; + while (io_uring_peek_cqe(&ring, &cqe) == -EAGAIN) { + } stop_watch(); diff --git a/io-uring-sqpoll.c b/io-uring-sqpoll.c index 7ea1e118bf24a4b5735813965c7d227accd8601d..93865f68f478624087fd550c430e09e79aa057dd 100644 --- a/io-uring-sqpoll.c +++ b/io-uring-sqpoll.c @@ -17,7 +17,7 @@ void init(__attribute__((unused)) int fd) { } } -void do_write(int fd, const void* buf, size_t count) { +void do_write(int fd, const void *buf, size_t count) { start_watch(); struct io_uring_sqe *sqe = io_uring_get_sqe(&ring); @@ -34,7 +34,7 @@ void do_write(int fd, const void* buf, size_t count) { err(EXIT_FAILURE, "io_uring_submit_and_wait failed"); } - struct io_uring_cqe* cqe; + struct io_uring_cqe *cqe; res = io_uring_peek_cqe(&ring, &cqe); if (res < 0) { err(EXIT_FAILURE, "io_uring_peek_cqe failed"); diff --git a/io-uring.c b/io-uring.c index 51afb7df194828fba770860b2a3b2280d1b6c8b8..ea0141eb2f8a09a3e7ce45c12458227a2e66ff68 100644 --- a/io-uring.c +++ b/io-uring.c @@ -15,7 +15,7 @@ void init(__attribute__((unused)) int fd) { } } -void do_write(int fd, const void* buf, size_t count) { +void do_write(int fd, const void *buf, size_t count) { start_watch(); struct io_uring_sqe *sqe = io_uring_get_sqe(&ring); @@ -25,14 +25,11 @@ void do_write(int fd, const void* buf, size_t count) { stop_watch(); - if (res < 0) - err(EXIT_FAILURE, "io_uring_submit_and_wait failed"); + if (res < 0) err(EXIT_FAILURE, "io_uring_submit_and_wait failed"); - struct io_uring_cqe* cqe; + struct io_uring_cqe *cqe; res = io_uring_peek_cqe(&ring, &cqe); - if (res < 0) - err(EXIT_FAILURE, "io_uring_peek_cqe failed"); + if (res < 0) err(EXIT_FAILURE, "io_uring_peek_cqe failed"); - if (cqe->res < 0) - err(EXIT_FAILURE, "write request failed"); + if (cqe->res < 0) err(EXIT_FAILURE, "write request failed"); } diff --git a/stopwatch.c b/stopwatch.c index f781b7b8340a77c5b97ab36f59d53641e164a904..7ea5337663908a2cc74689fbf9064af2b3df627c 100644 --- a/stopwatch.c +++ b/stopwatch.c @@ -2,17 +2,12 @@ struct timespec start, stop; -int64_t sec_to_nanos(int64_t sec) { - return sec * 1000 * 1000 * 1000; -} +int64_t sec_to_nanos(int64_t sec) { return sec * 1000 * 1000 * 1000; } -double nanos_to_millis(int64_t nanos) { - return ((double)nanos) / (1000 * 1000); -} +double nanos_to_millis(int64_t nanos) { return ((double)nanos) / (1000 * 1000); } int64_t clock_diff_nanos() { int64_t nanos = sec_to_nanos(stop.tv_sec - start.tv_sec); nanos += (stop.tv_nsec - start.tv_nsec); return nanos; } - diff --git a/stopwatch.h b/stopwatch.h index 0743b112bc3864a44f50e658fdb137d2fced0bad..97aee422433b69be98f91582530bee7e7511509f 100644 --- a/stopwatch.h +++ b/stopwatch.h @@ -1,17 +1,13 @@ -#pragma once +#pragma once #include <stdint.h> #include <time.h> extern struct timespec start, stop; -static inline void start_watch() { - clock_gettime(CLOCK_MONOTONIC, &start); -} +static inline void start_watch() { clock_gettime(CLOCK_MONOTONIC, &start); } -static inline void stop_watch() { - clock_gettime(CLOCK_MONOTONIC, &stop); -} +static inline void stop_watch() { clock_gettime(CLOCK_MONOTONIC, &stop); } int64_t clock_diff_nanos(); double nanos_to_millis(int64_t nanos);