From mboxrd@z Thu Jan 1 00:00:00 1970 From: John Fastabend Subject: [bpf-next PATCH v2 4/7] bpf: sockmap sample, report bytes/sec Date: Wed, 10 Jan 2018 10:39:53 -0800 Message-ID: <20180110183953.5930.25900.stgit@john-Precision-Tower-5810> References: <20180110183600.5930.68261.stgit@john-Precision-Tower-5810> Mime-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Cc: netdev@vger.kernel.org To: borkmann@iogearbox.net, john.fastabend@gmail.com, ast@kernel.org Return-path: Received: from mail-pg0-f65.google.com ([74.125.83.65]:36536 "EHLO mail-pg0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753084AbeAJSkG (ORCPT ); Wed, 10 Jan 2018 13:40:06 -0500 Received: by mail-pg0-f65.google.com with SMTP id j2so10341419pgv.3 for ; Wed, 10 Jan 2018 10:40:05 -0800 (PST) In-Reply-To: <20180110183600.5930.68261.stgit@john-Precision-Tower-5810> Sender: netdev-owner@vger.kernel.org List-ID: Report bytes/sec sent as well as total bytes. Useful to get rough idea how different configurations and usage patterns perform with sockmap. Signed-off-by: John Fastabend --- samples/sockmap/sockmap_user.c | 37 ++++++++++++++++++++++++++++++++----- 1 file changed, 32 insertions(+), 5 deletions(-) diff --git a/samples/sockmap/sockmap_user.c b/samples/sockmap/sockmap_user.c index 48fa09a..812fc7e 100644 --- a/samples/sockmap/sockmap_user.c +++ b/samples/sockmap/sockmap_user.c @@ -24,6 +24,7 @@ #include #include #include +#include #include #include @@ -191,14 +192,16 @@ static int sockmap_init_sockets(void) struct msg_stats { size_t bytes_sent; size_t bytes_recvd; + struct timespec start; + struct timespec end; }; static int msg_loop(int fd, int iov_count, int iov_length, int cnt, struct msg_stats *s, bool tx) { struct msghdr msg = {0}; + int err, i, flags = MSG_NOSIGNAL; struct iovec *iov; - int i, flags = MSG_NOSIGNAL; iov = calloc(iov_count, sizeof(struct iovec)); if (!iov) @@ -220,6 +223,7 @@ static int msg_loop(int fd, int iov_count, int iov_length, int cnt, msg.msg_iovlen = iov_count; if (tx) { + clock_gettime(CLOCK_MONOTONIC, &s->start); for (i = 0; i < cnt; i++) { int sent = sendmsg(fd, &msg, flags); @@ -229,6 +233,7 @@ static int msg_loop(int fd, int iov_count, int iov_length, int cnt, } s->bytes_sent += sent; } + clock_gettime(CLOCK_MONOTONIC, &s->end); } else { int slct, recv, max_fd = fd; struct timeval timeout; @@ -236,6 +241,9 @@ static int msg_loop(int fd, int iov_count, int iov_length, int cnt, fd_set w; total_bytes = (float)iov_count * (float)iov_length * (float)cnt; + err = clock_gettime(CLOCK_MONOTONIC, &s->start); + if (err < 0) + perror("recv start time: "); while (s->bytes_recvd < total_bytes) { timeout.tv_sec = 1; timeout.tv_usec = 0; @@ -247,15 +255,18 @@ static int msg_loop(int fd, int iov_count, int iov_length, int cnt, slct = select(max_fd + 1, &w, NULL, NULL, &timeout); if (slct == -1) { perror("select()"); + clock_gettime(CLOCK_MONOTONIC, &s->end); return slct; } else if (!slct) { fprintf(stderr, "unexpected timeout\n"); + clock_gettime(CLOCK_MONOTONIC, &s->end); return slct; } recv = recvmsg(fd, &msg, flags); if (recv < 0) { if (errno != EWOULDBLOCK) { + clock_gettime(CLOCK_MONOTONIC, &s->end); perror("recv failed()\n"); return errno; } @@ -263,6 +274,7 @@ static int msg_loop(int fd, int iov_count, int iov_length, int cnt, s->bytes_recvd += recv; } + clock_gettime(CLOCK_MONOTONIC, &s->end); } for (i = 0; i < iov_count; i++) @@ -271,11 +283,14 @@ static int msg_loop(int fd, int iov_count, int iov_length, int cnt, return 0; } +static float giga = 1000000000; + static int sendmsg_test(int iov_count, int iov_buf, int cnt, int verbose) { int txpid, rxpid, err = 0; struct msg_stats s = {0}; int status; + float sent_Bps = 0, recvd_Bps = 0; errno = 0; @@ -286,10 +301,16 @@ static int sendmsg_test(int iov_count, int iov_buf, int cnt, int verbose) fprintf(stderr, "msg_loop_rx: iov_count %i iov_buf %i cnt %i err %i\n", iov_count, iov_buf, cnt, err); - fprintf(stdout, "rx_sendmsg: TX_bytes %zu RX_bytes %zu\n", - s.bytes_sent, s.bytes_recvd); shutdown(p2, SHUT_RDWR); shutdown(p1, SHUT_RDWR); + if (s.end.tv_sec - s.start.tv_sec) { + sent_Bps = s.bytes_sent / (s.end.tv_sec - s.start.tv_sec); + recvd_Bps = s.bytes_recvd / (s.end.tv_sec - s.start.tv_sec); + } + fprintf(stdout, + "rx_sendmsg: TX: %zuB %fB/s %fGB/s RX: %zuB %fB/s %fGB/s\n", + s.bytes_sent, sent_Bps, sent_Bps/giga, + s.bytes_recvd, recvd_Bps, recvd_Bps/giga); exit(1); } else if (rxpid == -1) { perror("msg_loop_rx: "); @@ -303,9 +324,15 @@ static int sendmsg_test(int iov_count, int iov_buf, int cnt, int verbose) fprintf(stderr, "msg_loop_tx: iov_count %i iov_buf %i cnt %i err %i\n", iov_count, iov_buf, cnt, err); - fprintf(stdout, "tx_sendmsg: TX_bytes %zu RX_bytes %zu\n", - s.bytes_sent, s.bytes_recvd); shutdown(c1, SHUT_RDWR); + if (s.end.tv_sec - s.start.tv_sec) { + sent_Bps = s.bytes_sent / (s.end.tv_sec - s.start.tv_sec); + recvd_Bps = s.bytes_recvd / (s.end.tv_sec - s.start.tv_sec); + } + fprintf(stdout, + "tx_sendmsg: TX: %zuB %fB/s %f GB/s RX: %zuB %fB/s %fGB/s\n", + s.bytes_sent, sent_Bps, sent_Bps/giga, + s.bytes_recvd, recvd_Bps, recvd_Bps/giga); exit(1); } else if (txpid == -1) { perror("msg_loop_tx: ");