From patchwork Fri Jan 12 05:07:10 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Fastabend X-Patchwork-Id: 859505 X-Patchwork-Delegate: bpf@iogearbox.net Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="b+HlvvyT"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3zHrMy5rmgz9t2l for ; Fri, 12 Jan 2018 16:07:26 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754216AbeALFHY (ORCPT ); Fri, 12 Jan 2018 00:07:24 -0500 Received: from mail-pf0-f195.google.com ([209.85.192.195]:33122 "EHLO mail-pf0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750714AbeALFHX (ORCPT ); Fri, 12 Jan 2018 00:07:23 -0500 Received: by mail-pf0-f195.google.com with SMTP id y89so3609167pfk.0 for ; Thu, 11 Jan 2018 21:07:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:from:to:cc:date:message-id:in-reply-to:references :user-agent:mime-version:content-transfer-encoding; bh=BNI1koNrC9N5UFEv/QtK0GJhrk+yEGyFObxc9uyfq44=; b=b+HlvvyT5SdJR4Yvsq2C/eptCFOoyu5K47/HR8MpVjleCY0er3e1E8ww0KpJTyOad9 n3M3aro+m0/leP/ltfuNcWK0+1lGirM8wkHzQE2eEQc5WxB/VNUFt1Ed1NRkcfzOKcoW Hvlw8nrWz9EC1OqrYaZryecHGo2lRn2BbgYwwdDV0MKY0Jb/p1DMtT9sMOHNZosuJybI 4rBaCvNcw2RF45FVqlxsc/9mlcOAMUKu5p8UJzNFssXpF0qAL+1CAKILoVDh3axiD3O8 YQyWnA/1sKKTLqae1R4jD2HY57e0cRVghkF/ewA01BJpizEIYiKfG4BVQF/VeGR/lQ2v 99bQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:from:to:cc:date:message-id:in-reply-to :references:user-agent:mime-version:content-transfer-encoding; bh=BNI1koNrC9N5UFEv/QtK0GJhrk+yEGyFObxc9uyfq44=; b=oFscWIQTf5WET7V7d8TX9YhAhJJxtD8Qkqw0V5x/W147DWLukCjBIu5gjK5WF3UkoZ +azmzXpDJ6yaIGCY4lgTNZeaWONaM2rsojgeoWBoIx5d1Ts+KoOEaHFCYLm6Vv/rP7Gw BrpU5J7OeUoI4wR98MBHpTxUHZsIzG97Grb88hN5cPaDDG+85QKmKgRydqzLD5RJwtTo 2BwFrOTd3Cb2SqzntNqPBsycApVqHHcckJlayoIguDUR39j/fbq0RY1pCaPqBHRVQzmQ MJQvAS1ZIgtX3PYlyHR9RubcxRtD4qbQwdYHHIfXFppLDU06feJ3IRq3C1SNUvP6vVPV pm4g== X-Gm-Message-State: AKGB3mIi8GI8+7Dn3y7jKI5EfmqKS0GkPx4gygwea2iFBuwHf+rKtsby LzZx1UkL+B+UovqlHuniYZRWJQ== X-Google-Smtp-Source: ACJfBouG+tGBdY1L0LNyuWEiL9YidiQooI4ob0ftu9zMvVApMwgGYYybhOmWxkFTZv0CiigK7m5UXQ== X-Received: by 10.84.246.131 with SMTP id m3mr24333535pll.50.1515733643049; Thu, 11 Jan 2018 21:07:23 -0800 (PST) Received: from [127.0.1.1] ([75.106.27.153]) by smtp.gmail.com with ESMTPSA id 15sm16077254pfi.97.2018.01.11.21.07.16 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 11 Jan 2018 21:07:22 -0800 (PST) Subject: [bpf-next PATCH v3 4/7] bpf: sockmap sample, report bytes/sec From: John Fastabend To: borkmann@iogearbox.net, john.fastabend@gmail.com, ast@kernel.org, kafai@fb.com Cc: netdev@vger.kernel.org Date: Thu, 11 Jan 2018 21:07:10 -0800 Message-ID: <20180112050710.5823.76043.stgit@john-Precision-Tower-5810> In-Reply-To: <20180112050243.5823.85987.stgit@john-Precision-Tower-5810> References: <20180112050243.5823.85987.stgit@john-Precision-Tower-5810> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org 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 Acked-by: Martin KaFai Lau --- 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 bbe9587..442fc00 100644 --- a/samples/sockmap/sockmap_user.c +++ b/samples/sockmap/sockmap_user.c @@ -24,6 +24,7 @@ #include #include #include +#include #include #include @@ -189,14 +190,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) @@ -218,6 +221,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); @@ -228,6 +232,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; @@ -235,6 +240,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; @@ -246,15 +254,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); goto out_errno; } else if (!slct) { fprintf(stderr, "unexpected timeout\n"); + clock_gettime(CLOCK_MONOTONIC, &s->end); goto out_errno; } recv = recvmsg(fd, &msg, flags); if (recv < 0) { if (errno != EWOULDBLOCK) { + clock_gettime(CLOCK_MONOTONIC, &s->end); perror("recv failed()\n"); goto out_errno; } @@ -262,6 +273,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++) @@ -273,11 +285,14 @@ static int msg_loop(int fd, int iov_count, int iov_length, int cnt, return errno; } +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; @@ -288,10 +303,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: "); @@ -305,9 +326,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: ");