From patchwork Mon Jul 12 17:15:29 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Ivanov X-Patchwork-Id: 1504148 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=openvswitch.org (client-ip=2605:bc80:3010::137; helo=smtp4.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Received: from smtp4.osuosl.org (smtp4.osuosl.org [IPv6:2605:bc80:3010::137]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4GNr500SS3z9sRf for ; Tue, 13 Jul 2021 03:15:46 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by smtp4.osuosl.org (Postfix) with ESMTP id 9D980404E4; Mon, 12 Jul 2021 17:15:43 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp4.osuosl.org ([127.0.0.1]) by localhost (smtp4.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id PlyY0UDxh7sC; Mon, 12 Jul 2021 17:15:42 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by smtp4.osuosl.org (Postfix) with ESMTPS id 940EE403DD; Mon, 12 Jul 2021 17:15:41 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id 504D2C001A; Mon, 12 Jul 2021 17:15:41 +0000 (UTC) X-Original-To: ovs-dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from smtp2.osuosl.org (smtp2.osuosl.org [IPv6:2605:bc80:3010::133]) by lists.linuxfoundation.org (Postfix) with ESMTP id 0FA6DC000E for ; Mon, 12 Jul 2021 17:15:40 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp2.osuosl.org (Postfix) with ESMTP id F2BD04015B for ; Mon, 12 Jul 2021 17:15:39 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp2.osuosl.org ([127.0.0.1]) by localhost (smtp2.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 46iNGDyBQXgY for ; Mon, 12 Jul 2021 17:15:38 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.8.0 Received: from www.kot-begemot.co.uk (ivanoab7.miniserver.com [37.128.132.42]) by smtp2.osuosl.org (Postfix) with ESMTPS id ACF36400E9 for ; Mon, 12 Jul 2021 17:15:38 +0000 (UTC) Received: from tun252.jain.kot-begemot.co.uk ([192.168.18.6] helo=jain.kot-begemot.co.uk) by www.kot-begemot.co.uk with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1m2zWq-00034p-AB for ovs-dev@openvswitch.org; Mon, 12 Jul 2021 17:15:36 +0000 Received: from jain.kot-begemot.co.uk ([192.168.3.3]) by jain.kot-begemot.co.uk with esmtp (Exim 4.92) (envelope-from ) id 1m2zWn-0002zx-EB; Mon, 12 Jul 2021 18:15:35 +0100 From: anton.ivanov@cambridgegreys.com To: ovs-dev@openvswitch.org Date: Mon, 12 Jul 2021 18:15:29 +0100 Message-Id: <20210712171529.11161-2-anton.ivanov@cambridgegreys.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20210712171529.11161-1-anton.ivanov@cambridgegreys.com> References: <20210712171529.11161-1-anton.ivanov@cambridgegreys.com> MIME-Version: 1.0 X-Clacks-Overhead: GNU Terry Pratchett Cc: Anton Ivanov Subject: [ovs-dev] [PATCH v2 2/2] Minimize the number of time calls in time_poll() X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: ovs-dev-bounces@openvswitch.org Sender: "dev" From: Anton Ivanov time_poll() makes an excessive number of time_msec() calls which incur a performance penalty. 1. Avoid time_msec() call for timeout calculation when time_poll() is asked to skip poll() 2. Reuse the time_msec() result from deadline calculation for last_wakeup and timeout calculation. Signed-off-by: Anton Ivanov --- lib/timeval.c | 36 +++++++++++++++++++++--------------- 1 file changed, 21 insertions(+), 15 deletions(-) diff --git a/lib/timeval.c b/lib/timeval.c index c6ac87376..64ab22e05 100644 --- a/lib/timeval.c +++ b/lib/timeval.c @@ -287,7 +287,7 @@ time_poll(struct pollfd *pollfds, int n_pollfds, HANDLE *handles OVS_UNUSED, long long int timeout_when, int *elapsed) { long long int *last_wakeup = last_wakeup_get(); - long long int start; + long long int start, now; bool quiescent; int retval = 0; @@ -297,28 +297,31 @@ time_poll(struct pollfd *pollfds, int n_pollfds, HANDLE *handles OVS_UNUSED, if (*last_wakeup && !thread_is_pmd()) { log_poll_interval(*last_wakeup); } - start = time_msec(); + now = start = time_msec(); timeout_when = MIN(timeout_when, deadline); quiescent = ovsrcu_is_quiescent(); for (;;) { - long long int now = time_msec(); int time_left; - if (now >= timeout_when) { + if (n_pollfds == 0) { time_left = 0; - } else if ((unsigned long long int) timeout_when - now > INT_MAX) { - time_left = INT_MAX; } else { - time_left = timeout_when - now; - } - - if (!quiescent) { - if (!time_left) { - ovsrcu_quiesce(); + if (now >= timeout_when) { + time_left = 0; + } else if ((unsigned long long int) timeout_when - now > INT_MAX) { + time_left = INT_MAX; } else { - ovsrcu_quiesce_start(); + time_left = timeout_when - now; + } + + if (!quiescent) { + if (!time_left) { + ovsrcu_quiesce(); + } else { + ovsrcu_quiesce_start(); + } } } @@ -329,6 +332,8 @@ time_poll(struct pollfd *pollfds, int n_pollfds, HANDLE *handles OVS_UNUSED, */ if (n_pollfds != 0) { retval = poll(pollfds, n_pollfds, time_left); + } else { + retval = 0; } if (retval < 0) { retval = -errno; @@ -355,7 +360,8 @@ time_poll(struct pollfd *pollfds, int n_pollfds, HANDLE *handles OVS_UNUSED, ovsrcu_quiesce_end(); } - if (deadline <= time_msec()) { + now = time_msec(); + if (deadline <= now) { #ifndef _WIN32 fatal_signal_handler(SIGALRM); #else @@ -372,7 +378,7 @@ time_poll(struct pollfd *pollfds, int n_pollfds, HANDLE *handles OVS_UNUSED, break; } } - *last_wakeup = time_msec(); + *last_wakeup = now; refresh_rusage(); *elapsed = *last_wakeup - start; return retval;