Received: by 2002:a05:7412:da14:b0:e2:908c:2ebd with SMTP id fe20csp1073076rdb; Sat, 7 Oct 2023 10:30:00 -0700 (PDT) X-Google-Smtp-Source: AGHT+IG95g2IBOlzOgtTLJ4BEXI4JvM/36aZx4wk/BZE/MLuOA6lMzHkpBICLXm+05zD+JH7DOj3 X-Received: by 2002:a9d:4d0a:0:b0:6bd:93e:460b with SMTP id n10-20020a9d4d0a000000b006bd093e460bmr11010884otf.19.1696699799682; Sat, 07 Oct 2023 10:29:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696699799; cv=none; d=google.com; s=arc-20160816; b=J6wINx32I41LBBdFo9EJPxOkGzKuhL6wYM/pnaxxVfJeL5QgizWRMy83bTb89vAKlD uGC66Mo08BKNmBTdp7I9p/p+S297n/YuU02EpvEx+2hYIBlL7cqfctzeew6X+H4xDNUP FNeFKjpayFhsL1zXVRX7Xz5EMub7UfSDX/k3/gFWa9nSbXbMS5lRE+ebK/pcMKPY7U7C IFu9RFnAHAZOtkWpnCXQSnucKqhwqEe9EYpGoBFC7hIQHzme/+GcILZtUcXCTEdyhtCd eL5uBsTxL2k6NGlb4m2bgWwRpw18K3bzOKga38czx0Q02tttqnDMqwfxwrWZqAOm5OhF oSrQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature:dkim-filter; bh=5DO3cwyjm45lldzqqqt/G4CbroCf+y81oRQuOx0JahY=; fh=wIHqZpOIuzcidDZ82yQbOZuyHJty7uvaWDEh/efoVzA=; b=K2/jWJ0UaHvMU4HTMJZvn32G7sr4LoyIO+YSlhwUU2vvte0DwgQKo/D1SY2dnoo+0+ ZAZIimaDx0C+ciUDOilNfep6hjUzstSToPzCGU+XR1AwLfiXIsMLzoA0gbC2vCtQPlFm lwMwhHW4Hp53ZbNDR/OYFDtA8GE2tASMEWEdrVp3Beka9gTVZTDIPylafQvGIj/Ju58N ZQez+qa68eV46Jfl489bNz00vwscT3D09cTHmAbc6bqIq7wwLbvzuewJX9B3amSaZ1df SoV21cvKFx+ettITSJK0KpG8/b0rv5gf1MQj7OUPOoELXlJv2AmUH3nexYIz73eNs352 ZY8A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@salutedevices.com header.s=mail header.b=KO7EYCjA; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=salutedevices.com Return-Path: Received: from morse.vger.email (morse.vger.email. [2620:137:e000::3:1]) by mx.google.com with ESMTPS id n125-20020a632783000000b00573e7fd674esi6313836pgn.661.2023.10.07.10.29.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 07 Oct 2023 10:29:59 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) client-ip=2620:137:e000::3:1; Authentication-Results: mx.google.com; dkim=pass header.i=@salutedevices.com header.s=mail header.b=KO7EYCjA; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=salutedevices.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by morse.vger.email (Postfix) with ESMTP id 8A14880BEDC7; Sat, 7 Oct 2023 10:29:52 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344250AbjJGR3Y (ORCPT + 99 others); Sat, 7 Oct 2023 13:29:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34550 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344132AbjJGR2y (ORCPT ); Sat, 7 Oct 2023 13:28:54 -0400 Received: from mx1.sberdevices.ru (mx2.sberdevices.ru [45.89.224.132]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D391DBD; Sat, 7 Oct 2023 10:28:52 -0700 (PDT) Received: from p-infra-ksmg-sc-msk02 (localhost [127.0.0.1]) by mx1.sberdevices.ru (Postfix) with ESMTP id EB99B12000F; Sat, 7 Oct 2023 20:28:48 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.sberdevices.ru EB99B12000F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=salutedevices.com; s=mail; t=1696699728; bh=5DO3cwyjm45lldzqqqt/G4CbroCf+y81oRQuOx0JahY=; h=From:To:Subject:Date:Message-ID:MIME-Version:Content-Type:From; b=KO7EYCjAntFOPZQa45efePnZSTw1OROlTWydN2C4PKBgzQaNoutuDy9V+555/arsu 7MRU6ocSo8FzpL5o/UpsyJYvyWA7RkHBEtCOWcmYlOs1FfWEe54OByVb57H51pAMjE mS6e3yi5K8u4M9Wok58uxyJdr/HSFSCaCdMM34wlyyIWYaQIc4ZrRJ4kDs7MaDLryh iTo971QTS92R3eOZ4jOmb9157GoS7NjT3xoqDE9drS73JA8or1tRl4b51wzkriJ0zz iTkmg/pAlA8cBT8Iv7JYUEIxlzN3SqxNKS0CyW+5y3LGZ5XHpp+2JPwKuaiQL8prHd qLBkPSmZexSsw== Received: from p-i-exch-sc-m01.sberdevices.ru (p-i-exch-sc-m01.sberdevices.ru [172.16.192.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.sberdevices.ru (Postfix) with ESMTPS; Sat, 7 Oct 2023 20:28:48 +0300 (MSK) Received: from localhost.localdomain (100.64.160.123) by p-i-exch-sc-m01.sberdevices.ru (172.16.192.107) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.30; Sat, 7 Oct 2023 20:28:48 +0300 From: Arseniy Krasnov To: Stefan Hajnoczi , Stefano Garzarella , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , "Michael S. Tsirkin" , Jason Wang , Bobby Eshleman CC: , , , , , , Subject: [PATCH net-next v3 11/12] test/vsock: MSG_ZEROCOPY support for vsock_perf Date: Sat, 7 Oct 2023 20:21:38 +0300 Message-ID: <20231007172139.1338644-12-avkrasnov@salutedevices.com> X-Mailer: git-send-email 2.35.0 In-Reply-To: <20231007172139.1338644-1-avkrasnov@salutedevices.com> References: <20231007172139.1338644-1-avkrasnov@salutedevices.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-Originating-IP: [100.64.160.123] X-ClientProxiedBy: p-i-exch-sc-m01.sberdevices.ru (172.16.192.107) To p-i-exch-sc-m01.sberdevices.ru (172.16.192.107) X-KSMG-Rule-ID: 10 X-KSMG-Message-Action: clean X-KSMG-AntiSpam-Lua-Profiles: 180453 [Oct 07 2023] X-KSMG-AntiSpam-Version: 6.0.0.2 X-KSMG-AntiSpam-Envelope-From: avkrasnov@salutedevices.com X-KSMG-AntiSpam-Rate: 0 X-KSMG-AntiSpam-Status: not_detected X-KSMG-AntiSpam-Method: none X-KSMG-AntiSpam-Auth: dkim=none X-KSMG-AntiSpam-Info: LuaCore: 535 535 da804c0ea8918f802fc60e7a20ba49783d957ba2, {Tracking_from_domain_doesnt_match_to}, salutedevices.com:7.1.1;100.64.160.123:7.1.2;d41d8cd98f00b204e9800998ecf8427e.com:7.1.1;127.0.0.199:7.1.2;p-i-exch-sc-m01.sberdevices.ru:5.0.1,7.1.1, FromAlignment: s, ApMailHostAddress: 100.64.160.123 X-MS-Exchange-Organization-SCL: -1 X-KSMG-AntiSpam-Interceptor-Info: scan successful X-KSMG-AntiPhishing: Clean X-KSMG-LinksScanning: Clean X-KSMG-AntiVirus: Kaspersky Secure Mail Gateway, version 2.0.1.6960, bases: 2023/10/07 16:48:00 #22085983 X-KSMG-AntiVirus-Status: Clean, skipped X-Spam-Status: No, score=2.7 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, RCVD_IN_SBL_CSS,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on morse.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (morse.vger.email [0.0.0.0]); Sat, 07 Oct 2023 10:29:52 -0700 (PDT) X-Spam-Level: ** To use this option pass '--zerocopy' parameter: ./vsock_perf --zerocopy --sender ... With this option MSG_ZEROCOPY flag will be passed to the 'send()' call. Signed-off-by: Arseniy Krasnov --- Changelog: v1 -> v2: * Move 'SOL_VSOCK' and 'VSOCK_RECVERR' from 'util.c' to 'util.h'. v2 -> v3: * Use 'msg_zerocopy_common.h' for MSG_ZEROCOPY related things. * Rename '--zc' option to '--zerocopy'. * Add detail in help that zerocopy mode is for sender mode only. tools/testing/vsock/vsock_perf.c | 80 ++++++++++++++++++++++++++++---- 1 file changed, 71 insertions(+), 9 deletions(-) diff --git a/tools/testing/vsock/vsock_perf.c b/tools/testing/vsock/vsock_perf.c index a72520338f84..4e8578f815e0 100644 --- a/tools/testing/vsock/vsock_perf.c +++ b/tools/testing/vsock/vsock_perf.c @@ -18,6 +18,9 @@ #include #include #include +#include + +#include "msg_zerocopy_common.h" #define DEFAULT_BUF_SIZE_BYTES (128 * 1024) #define DEFAULT_TO_SEND_BYTES (64 * 1024) @@ -31,6 +34,7 @@ static unsigned int port = DEFAULT_PORT; static unsigned long buf_size_bytes = DEFAULT_BUF_SIZE_BYTES; static unsigned long vsock_buf_bytes = DEFAULT_VSOCK_BUF_BYTES; +static bool zerocopy; static void error(const char *s) { @@ -252,10 +256,15 @@ static void run_sender(int peer_cid, unsigned long to_send_bytes) time_t tx_begin_ns; time_t tx_total_ns; size_t total_send; + time_t time_in_send; void *data; int fd; - printf("Run as sender\n"); + if (zerocopy) + printf("Run as sender MSG_ZEROCOPY\n"); + else + printf("Run as sender\n"); + printf("Connect to %i:%u\n", peer_cid, port); printf("Send %lu bytes\n", to_send_bytes); printf("TX buffer %lu bytes\n", buf_size_bytes); @@ -265,38 +274,82 @@ static void run_sender(int peer_cid, unsigned long to_send_bytes) if (fd < 0) exit(EXIT_FAILURE); - data = malloc(buf_size_bytes); + if (zerocopy) { + enable_so_zerocopy(fd); - if (!data) { - fprintf(stderr, "'malloc()' failed\n"); - exit(EXIT_FAILURE); + data = mmap(NULL, buf_size_bytes, PROT_READ | PROT_WRITE, + MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); + if (data == MAP_FAILED) { + perror("mmap"); + exit(EXIT_FAILURE); + } + } else { + data = malloc(buf_size_bytes); + + if (!data) { + fprintf(stderr, "'malloc()' failed\n"); + exit(EXIT_FAILURE); + } } memset(data, 0, buf_size_bytes); total_send = 0; + time_in_send = 0; tx_begin_ns = current_nsec(); while (total_send < to_send_bytes) { ssize_t sent; + size_t rest_bytes; + time_t before; - sent = write(fd, data, buf_size_bytes); + rest_bytes = to_send_bytes - total_send; + + before = current_nsec(); + sent = send(fd, data, (rest_bytes > buf_size_bytes) ? + buf_size_bytes : rest_bytes, + zerocopy ? MSG_ZEROCOPY : 0); + time_in_send += (current_nsec() - before); if (sent <= 0) error("write"); total_send += sent; + + if (zerocopy) { + struct pollfd fds = { 0 }; + + fds.fd = fd; + + if (poll(&fds, 1, -1) < 0) { + perror("poll"); + exit(EXIT_FAILURE); + } + + if (!(fds.revents & POLLERR)) { + fprintf(stderr, "POLLERR expected\n"); + exit(EXIT_FAILURE); + } + + vsock_recv_completion(fd, NULL); + } } tx_total_ns = current_nsec() - tx_begin_ns; printf("total bytes sent: %zu\n", total_send); printf("tx performance: %f Gbits/s\n", - get_gbps(total_send * 8, tx_total_ns)); - printf("total time in 'write()': %f sec\n", + get_gbps(total_send * 8, time_in_send)); + printf("total time in tx loop: %f sec\n", (float)tx_total_ns / NSEC_PER_SEC); + printf("time in 'send()': %f sec\n", + (float)time_in_send / NSEC_PER_SEC); close(fd); - free(data); + + if (zerocopy) + munmap(data, buf_size_bytes); + else + free(data); } static const char optstring[] = ""; @@ -336,6 +389,11 @@ static const struct option longopts[] = { .has_arg = required_argument, .val = 'R', }, + { + .name = "zerocopy", + .has_arg = no_argument, + .val = 'Z', + }, {}, }; @@ -351,6 +409,7 @@ static void usage(void) " --help This message\n" " --sender Sender mode (receiver default)\n" " of the receiver to connect to\n" + " --zerocopy Enable zerocopy (for sender mode only)\n" " --port Port (default %d)\n" " --bytes KMG Bytes to send (default %d)\n" " --buf-size KMG Data buffer size (default %d). In sender mode\n" @@ -413,6 +472,9 @@ int main(int argc, char **argv) case 'H': /* Help. */ usage(); break; + case 'Z': /* Zerocopy. */ + zerocopy = true; + break; default: usage(); } -- 2.25.1