From patchwork Mon Aug 26 23:00:31 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: William Tu X-Patchwork-Id: 1153498 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=openvswitch.org (client-ip=140.211.169.12; helo=mail.linuxfoundation.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="L0tP+nSI"; dkim-atps=neutral Received: from mail.linuxfoundation.org (mail.linuxfoundation.org [140.211.169.12]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 46HSDK0f3gz9s00 for ; Tue, 27 Aug 2019 09:01:20 +1000 (AEST) Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id 3FE59EA7; Mon, 26 Aug 2019 23:01:18 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@mail.linuxfoundation.org Received: from smtp1.linuxfoundation.org (smtp1.linux-foundation.org [172.17.192.35]) by mail.linuxfoundation.org (Postfix) with ESMTPS id F0921EA2 for ; Mon, 26 Aug 2019 23:01:16 +0000 (UTC) X-Greylist: whitelisted by SQLgrey-1.7.6 Received: from mail-pf1-f194.google.com (mail-pf1-f194.google.com [209.85.210.194]) by smtp1.linuxfoundation.org (Postfix) with ESMTPS id ABD9189B for ; Mon, 26 Aug 2019 23:01:16 +0000 (UTC) Received: by mail-pf1-f194.google.com with SMTP id w2so12772313pfi.3 for ; Mon, 26 Aug 2019 16:01:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id; bh=SaegBALqjX8jZfsMPUYiaRxWiHFGMmt/frSoI1OVXWM=; b=L0tP+nSIQqYqgGepQioPpP0/7RmKYW68b+HcY//JB2K8QC+UgSOo6uVTtwDXd//z4W KMN+newton0pjXkWKmRkE0LqyqWet11uzP/o+zivAJ5glc4tOXJ+LhMwAHbSiPGqtEPx AlMXAzirWZYclDD6iVXAJLZaK3FIa59xzrTC/M6w4NQjwwsRqbRZvp+kWIcluz9nZ2vw NMBDfaIDxZL8gceaMn9oGh/G69oOtEezjlGw+Rju0Z1KVyUuayqoF92XdpLjP5bL83o2 sMvRiN4OEhxk+WQRejZiZ+HsAnDSzLFJxXObRgkNqtvjYZCjDOE1WsyP1lGdwj6mlX6Q JEXA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id; bh=SaegBALqjX8jZfsMPUYiaRxWiHFGMmt/frSoI1OVXWM=; b=F/b6OafPGZ4m13wGX0897ubWgkW71ZJQZE+6T7jeLxREL/baVh7JjgY08YT8OTzB9a fIbpAVs2s4/nuVVFQ/cX9/HvqY2r2gLTAwEPSXBt89fUDSt08cHAJ/PfjUDperarAHom U+olh4Ya6yTJA7VhYyitZqS+ze2rZFYcsZROraOSrly+8Lhy8cFcIJipLHSZT6T14Yxl Wrf3cCQszCbjR+gzci0KNSv8gauarOeBgtCKxHn5Z086V2qRRAcdZn9LN6ssg5ScuPyw nc0X1Lt1qSc/2GedLxYW8WIMoxcAL21lrZx32+sgipVB7Kfy+eSbXPPFZXEjsi+x2bDZ M0UA== X-Gm-Message-State: APjAAAWUtr6NglHQ46qt6+Vh4aMvP7CFaj7jbUIv64gDiu9EvGJXuiKZ F9Psm5XNYNsQtxr/uL7ReunMFIiu5v8= X-Google-Smtp-Source: APXvYqzD9Wctc8FPPoMP3onOqB9GP0rRXEh7qjJbFueTxBW8G8Ehj+6vwxUiQdop2DdYo6cim89ZMQ== X-Received: by 2002:aa7:9907:: with SMTP id z7mr22019303pff.13.1566860475993; Mon, 26 Aug 2019 16:01:15 -0700 (PDT) Received: from sc9-mailhost3.vmware.com ([66.170.99.95]) by smtp.gmail.com with ESMTPSA id b24sm12453398pgw.66.2019.08.26.16.01.15 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 26 Aug 2019 16:01:15 -0700 (PDT) From: William Tu To: dev@openvswitch.org Date: Mon, 26 Aug 2019 16:00:31 -0700 Message-Id: <1566860431-12795-1-git-send-email-u9012063@gmail.com> X-Mailer: git-send-email 2.7.4 X-Spam-Status: No, score=-1.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_ENVFROM_END_DIGIT,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE autolearn=no version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on smtp1.linux-foundation.org Subject: [ovs-dev] [PATCH 1/2] ovs-thread: Make struct spin lock cache aligned. X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: ovs-dev-bounces@openvswitch.org Errors-To: ovs-dev-bounces@openvswitch.org Make the spin lock struct 64-byte aligned to avoid false sharing issue. Signed-off-by: William Tu --- include/openvswitch/thread.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/openvswitch/thread.h b/include/openvswitch/thread.h index acc822904847..5053cb3091c3 100644 --- a/include/openvswitch/thread.h +++ b/include/openvswitch/thread.h @@ -34,7 +34,7 @@ struct OVS_LOCKABLE ovs_mutex { }; #ifdef HAVE_PTHREAD_SPIN_LOCK -struct OVS_LOCKABLE ovs_spin { +OVS_ALIGNED_STRUCT(64, OVS_LOCKABLE ovs_spin) { pthread_spinlock_t lock; const char *where; /* NULL if and only if uninitialized. */ }; From patchwork Mon Aug 26 23:02:25 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: William Tu X-Patchwork-Id: 1153499 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=openvswitch.org (client-ip=140.211.169.12; helo=mail.linuxfoundation.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="aJGiCMBL"; dkim-atps=neutral Received: from mail.linuxfoundation.org (mail.linuxfoundation.org [140.211.169.12]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 46HSGb53bPz9s00 for ; Tue, 27 Aug 2019 09:03:19 +1000 (AEST) Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id 4E949150A; Mon, 26 Aug 2019 23:03:17 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@mail.linuxfoundation.org Received: from smtp1.linuxfoundation.org (smtp1.linux-foundation.org [172.17.192.35]) by mail.linuxfoundation.org (Postfix) with ESMTPS id D85D61451 for ; Mon, 26 Aug 2019 23:03:15 +0000 (UTC) X-Greylist: whitelisted by SQLgrey-1.7.6 Received: from mail-pl1-f195.google.com (mail-pl1-f195.google.com [209.85.214.195]) by smtp1.linuxfoundation.org (Postfix) with ESMTPS id 7D1F088E for ; Mon, 26 Aug 2019 23:03:15 +0000 (UTC) Received: by mail-pl1-f195.google.com with SMTP id h3so10753528pls.7 for ; Mon, 26 Aug 2019 16:03:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id; bh=I3uvgqBRNq2/Rj1qlrSbZ15Ry1UroawZ0NQW7sT0YPk=; b=aJGiCMBLhJJ6PKdeeL3sEfNNgO5K2PesTvSCWMw9/kxOv8YN16BEPO5+ZcbQGxw6Am LxCYpnIjYxZ+bJ9hR/C3tFWtFYdwChfElSVeB4O52VArXo+gNI/4TXCDU6cRgXs6TdI+ ZdFCLwUdkUNF8OcgTp5EtkgkNhcXzFcqYsGIEBFnX3KVJF7erMG1Q4gtLFkecMM2jgxb wJVYBkC0SnE1MYo8gVa2H0JWYcVseiFlZn6ccozPcJ5VSqatCzVWCaESlEmxGDpxdieg fuMhBa++ehTxKrDoPkTsk1o/PQ0/l7IavtIThQ0zHvlgGXhMcJgeYw14iJodbybcC0Yi SmRA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id; bh=I3uvgqBRNq2/Rj1qlrSbZ15Ry1UroawZ0NQW7sT0YPk=; b=YKkIjw60Z1YEPkdBWpi3DsiFIEzNgKSxCIic7x0+DZdfiDrrxAU5ZupQ/HPP0NhLTK +vehs3VI9eNougkceXrUOHUEa37lAF2H0Gl5Gepb1VVwbCl+L+h4uUyKBzk9QsEEzZC2 DCMWd2+V3Dkm1ThVRdtSrIxYDVK3AYaAxh6mdhhiElMRKZf5copWCYPHaHIVIkM+U6Sc nBmwmQSbbx0lxzxS0hZSxU4y7CU06AUgWyFGFOrKuBuHjrjnFp8vrXxeLeb1lIwYQiUH IaAbRrJiDxbe2TfEeikw6+03i1wqhKeRxG+f6TwRToZBzh2a8x+8xymlz89QlBvLglU5 FbsQ== X-Gm-Message-State: APjAAAWmU6C1M1Css8eL+hqn34cqr/Sl0XCzKBISbOpHhJ9JtSo6Psd7 G10uh2MLfiEuuzeFE5szPleMczBH X-Google-Smtp-Source: APXvYqwQudI3GgmhQ5HlnblGG5vBYWJDdTrwSWTr+g2Owy7fUHGXojcOU4IhWL3+Uq8lXs8rkGpYMg== X-Received: by 2002:a17:902:ac85:: with SMTP id h5mr7956446plr.162.1566860594794; Mon, 26 Aug 2019 16:03:14 -0700 (PDT) Received: from sc9-mailhost3.vmware.com ([66.170.99.95]) by smtp.gmail.com with ESMTPSA id f12sm13276683pgo.85.2019.08.26.16.03.14 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 26 Aug 2019 16:03:14 -0700 (PDT) From: William Tu To: dev@openvswitch.org Date: Mon, 26 Aug 2019 16:02:25 -0700 Message-Id: <1566860545-12866-1-git-send-email-u9012063@gmail.com> X-Mailer: git-send-email 2.7.4 X-Spam-Status: No, score=-1.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_ENVFROM_END_DIGIT,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE autolearn=no version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on smtp1.linux-foundation.org Subject: [ovs-dev] [PATCH 2/2] netdev-afxdp: Add need_wakeup supprt. X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: ovs-dev-bounces@openvswitch.org Errors-To: ovs-dev-bounces@openvswitch.org The patch adds support for using need_wakeup flag in AF_XDP rings. When this flag is used, it means that OVS has to explicitly wake up the kernel RX, using poll() syscall and wake up TX, using sendto() syscall. This feature improves the performance by avoiding unnecessary syscalls, so keeping more CPU time in userspace to process packets. On Intel Xeon E5-2620 v3 2.4GHz system, performance of physical port to physical port improves from 6.1Mpps to 7.3Mpps. Suggested-by: Eelco Chaudron Signed-off-by: William Tu --- acinclude.m4 | 5 +++++ lib/netdev-afxdp.c | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+) diff --git a/acinclude.m4 b/acinclude.m4 index 116ffcf9096d..8821b821ec3c 100644 --- a/acinclude.m4 +++ b/acinclude.m4 @@ -276,6 +276,11 @@ AC_DEFUN([OVS_CHECK_LINUX_AF_XDP], [ [Define to 1 if AF_XDP support is available and enabled.]) LIBBPF_LDADD=" -lbpf -lelf" AC_SUBST([LIBBPF_LDADD]) + + AC_CHECK_DECL([xsk_ring_prod__needs_wakeup], [ + AC_DEFINE([HAVE_XDP_NEED_WAKEUP], [1], + [XDP need wakeup support detected in xsk.h.]) + ], [], [#include ]) fi AM_CONDITIONAL([HAVE_AF_XDP], test "$AF_XDP_ENABLE" = true) ]) diff --git a/lib/netdev-afxdp.c b/lib/netdev-afxdp.c index e5b058d08a09..d14d100e8fa3 100644 --- a/lib/netdev-afxdp.c +++ b/lib/netdev-afxdp.c @@ -26,6 +26,7 @@ #include #include #include +#include #include #include #include @@ -117,6 +118,48 @@ struct xsk_socket_info { atomic_uint64_t tx_dropped; }; +#ifdef HAVE_XDP_NEED_WAKEUP +static inline void +xsk_rx_need_wakeup(struct xsk_umem_info *umem, + struct netdev *netdev, int fd) { + struct pollfd pfd; + int ret; + + if (xsk_ring_prod__needs_wakeup(&umem->fq)) { + pfd.fd = fd; + pfd.events = POLLIN; + + ret = poll(&pfd, 1, 1000); + if (OVS_UNLIKELY(ret == 0)) { + VLOG_WARN_RL(&rl, "%s: poll rx fd timeout.", + netdev_get_name(netdev)); + } else if (OVS_UNLIKELY(ret < 0)) { + VLOG_WARN_RL(&rl, "%s: error polling rx fd: %s.", + netdev_get_name(netdev), + ovs_strerror(ret)); + } + } +} + +static inline bool +xsk_tx_need_wakeup(struct xsk_socket_info *xsk_info) +{ + return xsk_ring_prod__needs_wakeup(&xsk_info->tx); +} +#else +static inline void +xsk_rx_need_wakeup(struct xsk_umem_info *umem OVS_UNUSED, + struct netdev *netdev OVS_UNUSED, int fd OVS_UNUSED) { + /* Nothing. */ +} + +static inline bool +xsk_tx_need_wakeup(struct xsk_socket_info *xsk_info OVS_UNUSED) +{ + return true; +} +#endif /* HAVE_XDP_NEED_WAKEUP */ + static void netdev_afxdp_cleanup_unused_pool(struct unused_pool *pool) { @@ -257,6 +300,10 @@ xsk_configure_socket(struct xsk_umem_info *umem, uint32_t ifindex, cfg.xdp_flags = XDP_FLAGS_UPDATE_IF_NOEXIST | XDP_FLAGS_SKB_MODE; } +#ifdef HAVE_XDP_NEED_WAKEUP + cfg.bind_flags |= XDP_USE_NEED_WAKEUP; +#endif + if (if_indextoname(ifindex, devname) == NULL) { VLOG_ERR("ifindex %d to devname failed (%s)", ifindex, ovs_strerror(errno)); @@ -660,6 +707,7 @@ netdev_afxdp_rxq_recv(struct netdev_rxq *rxq_, struct dp_packet_batch *batch, rcvd = xsk_ring_cons__peek(&xsk_info->rx, BATCH_SIZE, &idx_rx); if (!rcvd) { + xsk_rx_need_wakeup(umem, netdev, rx->fd); return EAGAIN; } @@ -709,6 +757,9 @@ kick_tx(struct xsk_socket_info *xsk_info, int xdpmode) int ret, retries; static const int KERNEL_TX_BATCH_SIZE = 16; + if (!xsk_tx_need_wakeup(xsk_info)) { + return 0; + } /* In SKB_MODE packet transmission is synchronous, and the kernel xmits * only TX_BATCH_SIZE(16) packets for a single sendmsg syscall. * So, we have to kick the kernel (n_packets / 16) times to be sure that