From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id C054FA0555 for ; Thu, 9 Jun 2022 13:37:29 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id BB0C440220; Thu, 9 Jun 2022 13:37:29 +0200 (CEST) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by mails.dpdk.org (Postfix) with ESMTP id C2ECB40220 for ; Thu, 9 Jun 2022 13:37:27 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1654774646; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=wvBAVSHuxEHknUX8J2ZehUxoLaiualiGYEmRZDrowpw=; b=fpeRPiIRFH/5iRonh47eUiDbQZd66mKzxlHdXRRlRZv0M6u0rPOfDn9MDiJGY6WpIZFoJx c/CJ7wcu4JWPLwsFMM87Q0g8i6JE4pQwKfi3jXf3BDEsErk1JG1x4l7A42ahVQ6f50kzHo 8LYgYAGKnGS6O+l5wuuL26AhEBkG8q8= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-563-OFcU5QgVPWmWMev_Echw0A-1; Thu, 09 Jun 2022 07:37:25 -0400 X-MC-Unique: OFcU5QgVPWmWMev_Echw0A-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id E2F15811E75; Thu, 9 Jun 2022 11:37:24 +0000 (UTC) Received: from rh.redhat.com (unknown [10.39.195.82]) by smtp.corp.redhat.com (Postfix) with ESMTP id 144D018EA4; Thu, 9 Jun 2022 11:37:23 +0000 (UTC) From: Kevin Traynor To: Quentin Armitage Cc: Stephen Hemminger , dpdk stable Subject: patch 'pcapng: fix timestamp wrapping in output files' has been queued to stable release 21.11.2 Date: Thu, 9 Jun 2022 12:35:58 +0100 Message-Id: <20220609113701.386938-11-ktraynor@redhat.com> In-Reply-To: <20220609113701.386938-1-ktraynor@redhat.com> References: <20220609113701.386938-1-ktraynor@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=ktraynor@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII"; x-default=true X-BeenThere: stable@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: patches for DPDK stable branches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: stable-bounces@dpdk.org Hi, FYI, your patch has been queued to stable release 21.11.2 Note it hasn't been pushed to http://dpdk.org/browse/dpdk-stable yet. It will be pushed if I get no objections before 06/13/22. So please shout if anyone has objections. Also note that after the patch there's a diff of the upstream commit vs the patch applied to the branch. This will indicate if there was any rebasing needed to apply to the stable branch. If there were code changes for rebasing (ie: not only metadata diffs), please double check that the rebase was correctly done. Queued patches are on a temporary branch at: https://github.com/kevintraynor/dpdk-stable This queued commit can be viewed at: https://github.com/kevintraynor/dpdk-stable/commit/3a9e4cdb3f8cf9b98b22ef0d51a22dcf6519cdb8 Thanks. Kevin --- >From 3a9e4cdb3f8cf9b98b22ef0d51a22dcf6519cdb8 Mon Sep 17 00:00:00 2001 From: Quentin Armitage Date: Tue, 17 May 2022 11:01:15 +0100 Subject: [PATCH] pcapng: fix timestamp wrapping in output files [ upstream commit c882eb544842d94ce06af12b87bb7a4c572b20fb ] In pcap_tsc_to_ns(), delta * NSEC_PER_SEC will overflow approx 8 seconds after pcap_init is called when using a TSC with a frequency of 2.5GHz. To avoid the overflow, update the saved time and TSC value once delta >= tsc_hz. Fixes: 8d23ce8f5ee ("pcapng: add new library for writing pcapng files") Signed-off-by: Quentin Armitage Acked-by: Stephen Hemminger --- lib/pcapng/rte_pcapng.c | 45 +++++++++++++++++++++++++++++++++++++---- 1 file changed, 41 insertions(+), 4 deletions(-) diff --git a/lib/pcapng/rte_pcapng.c b/lib/pcapng/rte_pcapng.c index 9db058fe42..0caf3d31f8 100644 --- a/lib/pcapng/rte_pcapng.c +++ b/lib/pcapng/rte_pcapng.c @@ -21,4 +21,5 @@ #include #include +#include #include @@ -36,10 +37,13 @@ struct rte_pcapng { /* For converting TSC cycles to PCAPNG ns format */ -struct pcapng_time { +static struct pcapng_time { uint64_t ns; uint64_t cycles; + uint64_t tsc_hz; + struct rte_reciprocal_u64 tsc_hz_inverse; } pcapng_time; -RTE_INIT(pcapng_init) +static inline void +pcapng_init(void) { struct timespec ts; @@ -47,5 +51,9 @@ RTE_INIT(pcapng_init) pcapng_time.cycles = rte_get_tsc_cycles(); clock_gettime(CLOCK_REALTIME, &ts); + pcapng_time.cycles = (pcapng_time.cycles + rte_get_tsc_cycles()) / 2; pcapng_time.ns = rte_timespec_to_ns(&ts); + + pcapng_time.tsc_hz = rte_get_tsc_hz(); + pcapng_time.tsc_hz_inverse = rte_reciprocal_value_u64(pcapng_time.tsc_hz); } @@ -53,8 +61,37 @@ RTE_INIT(pcapng_init) static uint64_t pcapng_tsc_to_ns(uint64_t cycles) { - uint64_t delta; + uint64_t delta, secs; + if (!pcapng_time.tsc_hz) + pcapng_init(); + + /* In essence the calculation is: + * delta = (cycles - pcapng_time.cycles) * NSEC_PRE_SEC / rte_get_tsc_hz() + * but this overflows within 4 to 8 seconds depending on TSC frequency. + * Instead, if delta >= pcapng_time.tsc_hz: + * Increase pcapng_time.ns and pcapng_time.cycles by the number of + * whole seconds in delta and reduce delta accordingly. + * delta will therefore always lie in the interval [0, pcapng_time.tsc_hz), + * which will not overflow when multiplied by NSEC_PER_SEC provided the + * TSC frequency < approx 18.4GHz. + * + * Currently all TSCs operate below 5GHz. + */ delta = cycles - pcapng_time.cycles; - return pcapng_time.ns + (delta * NSEC_PER_SEC) / rte_get_tsc_hz(); + if (unlikely(delta >= pcapng_time.tsc_hz)) { + if (likely(delta < pcapng_time.tsc_hz * 2)) { + delta -= pcapng_time.tsc_hz; + pcapng_time.cycles += pcapng_time.tsc_hz; + pcapng_time.ns += NSEC_PER_SEC; + } else { + secs = rte_reciprocal_divide_u64(delta, &pcapng_time.tsc_hz_inverse); + delta -= secs * pcapng_time.tsc_hz; + pcapng_time.cycles += secs * pcapng_time.tsc_hz; + pcapng_time.ns += secs * NSEC_PER_SEC; + } + } + + return pcapng_time.ns + rte_reciprocal_divide_u64(delta * NSEC_PER_SEC, + &pcapng_time.tsc_hz_inverse); } -- 2.34.3 --- Diff of the applied patch vs upstream commit (please double-check if non-empty: --- --- - 2022-06-09 12:34:30.035182769 +0100 +++ 0011-pcapng-fix-timestamp-wrapping-in-output-files.patch 2022-06-09 12:34:29.618980424 +0100 @@ -1 +1 @@ -From c882eb544842d94ce06af12b87bb7a4c572b20fb Mon Sep 17 00:00:00 2001 +From 3a9e4cdb3f8cf9b98b22ef0d51a22dcf6519cdb8 Mon Sep 17 00:00:00 2001 @@ -5,0 +6,2 @@ +[ upstream commit c882eb544842d94ce06af12b87bb7a4c572b20fb ] + @@ -14 +15,0 @@ -Cc: stable@dpdk.org @@ -23 +24 @@ -index 90b2f5bc69..06ad712bd1 100644 +index 9db058fe42..0caf3d31f8 100644 @@ -26 +27 @@ -@@ -20,4 +20,5 @@ +@@ -21,4 +21,5 @@ @@ -32 +33 @@ -@@ -35,10 +36,13 @@ struct rte_pcapng { +@@ -36,10 +37,13 @@ struct rte_pcapng { @@ -48 +49 @@ -@@ -46,5 +50,9 @@ RTE_INIT(pcapng_init) +@@ -47,5 +51,9 @@ RTE_INIT(pcapng_init) @@ -58 +59 @@ -@@ -52,8 +60,37 @@ RTE_INIT(pcapng_init) +@@ -53,8 +61,37 @@ RTE_INIT(pcapng_init)