From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 703B8606A322 for ; Wed, 2 Dec 2026 17:51:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=networkplumber-org.20260707.gappssmtp.com header.i=@networkplumber-org.20260707.gappssmtp.com header.a=rsa-sha256 header.s=20260707 header.b=tcS3czXR Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 27979406B8; Wed, 2 Dec 2026 18:50:39 +0100 (CET) Received: from mail-pj1-f48.google.com (mail-pj1-f48.google.com [209.85.216.48]) by mails.dpdk.org (Postfix) with ESMTPS id 3985640664 for ; Wed, 2 Dec 2026 18:50:36 +0100 (CET) Received: by mail-pj1-f48.google.com with SMTP id 98e67ed59e1d1-3b53db3d0a5so2591608a91.0 for ; Wed, 02 Dec 2026 09:50:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20260707.gappssmtp.com; s=20260707; t=1796233835; x=1796838635; darn=dpdk.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=bg5gdun//LTcFrUYPJnGEjLAQhUVtGFVi0+hL7HzO9U=; b=tcS3czXRLSSPJRPlwWnCbimhITHXvCBT44A0r+zB+Kj/Lo/LakGsCmJzyibrcDC0B1 jo12YQDM8ddE5d7DEcGgOcDSbWwQpQnp/5A8CFPjt/aJzyqkfVmuVLjq7rUEFfecZNGZ qNbA7Z7N5rkWXbUvHEemUX8ltNS/5XGvgJm8VHroiNUAQTBJadDUQkbIlL2NgJ4OLKF/ FShLDrDExxWOtEtqnJskH3/7EpQMUaKqsXbtrkdxVZsj0SyzE/00BSkz90JlPwTe7XCO Mp+HYQAC+GSwUqN7cCBvmaHb/yTjZ9bfBvsnl6YeOLbzZRZJyW9g6J5w6MgfhIy5Ywn9 YGHA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796233835; x=1796838635; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=bg5gdun//LTcFrUYPJnGEjLAQhUVtGFVi0+hL7HzO9U=; b=mJqwjbF6yxSlWoYfTYanHmO0kRe5CXcHpmHJ0dy7Tf9s1jQUBq9AGlbeOzpI2/M2wy wQKU7EkzCZi8xk4EiSZCJp+dBONUCApAqCvy4nqkvJEPb/LaLIgNlknrLOrDgzOOPb9F /+LGofB9WJOMM1j0i/Mc51QBYSwz3nI0DIhJQbYFC+DyZuuzWKGe+3o8X3DuF9ms74sX UknC8FqFHf/8BOJebSBQwHJ+mAaXmAead2mKf+T1rg5vMOenIl9C2Eqy/mATIQ50RiT4 5b5RXqqWEdJnYl7KYa0s3d00u/y2CYOmjbAq2H0JuhQppgccV+A+d1egcMX9BN8uBZVN EIEw== X-Gm-Message-State: APuU4Z/+TRoLKTN33NNMAZ5bznb/IL3MDjUqSIQw9KsxTWnyuW6fmAmi +g5iUaDcsuwpf4MT5nfSN4Cvrf9tZuvZg6ODG7knkeWfpvj4TOZymv0NBOdLDFmUyh499noECT/ 0abqo X-Gm-Gg: AZFdTZdG5zw5FgUCQASo8/ulmuhrlq7jTvzjSKU9pCW/paSBQAUY4WjnJjwipcjERsT kLbdLtSuJWzfNat6LTnzGX7+UPIMGC0KGWd0EWN7gUm+Myli3nW3khMpA2Sq2qMxoapYpnem/oB SCObftMv1AZFD1czZ4gz5IvdM+HItIxMLGuJGOQHuR5ZluyHIZ8MRYziwA5RjKLWSitasZJr0Bg mQAyGq11z1pbPJMtBRrZTJU6X/9LSyEtjqJb98X8WpOK3ynR5ftEsDDuvxbWcl+WqsBXZNCvYud QGZSscP54b/W+fnOSyA+/JNXMLGPHRiypI75IzVfsZwORust56lEKBcXANwjRKr9xn5ZRR6NoAj ixNE/a82Q8DhNlCnMSfWGApVUf/969YcvaeLoamjpBBHXMCUqVWK+UreibqsHQV5999rGf17hPx 1CaCuoCjhr17vSueZa0VGSupb1f4k/g+HZDdstQ+Gt92chn/9gU2GW+OJZhCPdTOX6aJ5X+iP/n z28k4BwV8PyZ0hwZLIZSdG1rLpdg20nA+r7SqO5eDVu4s4NFWRae8yH+fPQ58F8nsqD2VdBnfTI 1fso6DTTbwf+eXr+N7f55u768KuxfUYHWGZT8iAb6JxXEw8KVBKmo3UCo9JOYtD3qhht X-Received: by 2002:a17:90b:2c84:b0:3b3:c3b9:7de6 with SMTP id 98e67ed59e1d1-3b41c8fe20emr39218600a91.13.1796233834546; Wed, 02 Dec 2026 09:50:34 -0800 (PST) Received: from phoenix.lan (204-195-112-43.wavecable.com. [204.195.112.43]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-3b5c784e74esm211314a91.6.2026.12.02.09.50.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Dec 2026 09:50:34 -0800 (PST) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger Subject: [PATCH v2 6/7] test/pcapng: compare timestamps in one clock domain Date: Wed, 2 Dec 2026 09:49:44 -0800 Message-ID: <20261202175028.4071813-7-stephen@networkplumber.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20261202175028.4071813-1-stephen@networkplumber.org> References: <20261201224258.1962108-1-stephen@networkplumber.org> <20261202175028.4071813-1-stephen@networkplumber.org> X-Archived-By: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Archive: List-Post: List-Help: List-Subscribe: , X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=4.0.1 X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 The pcapng test bounded the packet timestamps it read back using clock_gettime(CLOCK_REALTIME) sampled around the capture, but the timestamps in the file come from the TSC converted with the reference point EAL records at init. Comparing the two measures the drift between the calibrated TSC rate and NTP's slewing of the wall clock, which grows with process uptime. Packets were reported a few tens of microseconds before the start of the window. Bound the window with rte_tsc_to_ns() so both sides of the comparison come from the same reference point. What matters for analysis is the time between packets rather than the absolute offset, so also check that the timestamps never go backwards. A reference point that moved during the capture would show up as a negative delta, which no test covered before. Signed-off-by: Stephen Hemminger --- app/test/test_pcapng.c | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/app/test/test_pcapng.c b/app/test/test_pcapng.c index 7e19aa4096..0cf5d469e5 100644 --- a/app/test/test_pcapng.c +++ b/app/test/test_pcapng.c @@ -350,6 +350,7 @@ struct pkt_print_ctx { unsigned int count; uint64_t start_ns; uint64_t end_ns; + uint64_t prev_ns; }; static void @@ -398,6 +399,19 @@ parse_pcap_packet(u_char *user, const struct pcap_pkthdr *h, goto error; } + /* + * Packets are stamped from the TSC and written in order, so the + * time between them must never go backwards. A reference point + * that moved mid-capture, for example by following a wall clock + * step, would show up here as a negative delta. + */ + if (ns < ctx->prev_ns) { + printf("Timestamp went backwards by %"PRIu64" ns\n", + ctx->prev_ns - ns); + goto error; + } + ctx->prev_ns = ns; + if (!rte_is_broadcast_ether_addr(&eh->dst_addr)) { printf("Destination is not broadcast\n"); goto error; @@ -441,8 +455,16 @@ valid_pcapng_file(const char *file_name, uint64_t started, unsigned int expected struct pkt_print_ctx ctx = { }; int ret; + /* + * Packet timestamps come from the TSC converted with the reference + * point EAL took at init. Comparing them against CLOCK_REALTIME + * read now would measure the drift between the calibrated TSC rate + * and NTP's slewing of the wall clock, so bound the window using + * the same conversion the library uses. + */ ctx.start_ns = started; - ctx.end_ns = current_timestamp() + NS_PER_S; + ctx.end_ns = rte_tsc_to_ns(rte_get_tsc_cycles()) + NS_PER_S; + ctx.prev_ns = started; ctx.pcap = pcap_open_offline_with_tstamp_precision(file_name, PCAP_TSTAMP_PRECISION_NANO, @@ -474,7 +496,7 @@ test_add_interface(void) char file_name[PATH_MAX] = "/tmp/pcapng_test_XXXXXX.pcapng"; static rte_pcapng_t *pcapng; int ret, tmp_fd; - uint64_t now = current_timestamp(); + uint64_t now = rte_tsc_to_ns(rte_get_tsc_cycles()); tmp_fd = mkstemps(file_name, strlen(".pcapng")); if (tmp_fd == -1) { @@ -535,7 +557,7 @@ test_write_packets(void) char file_name[PATH_MAX] = "/tmp/pcapng_test_XXXXXX.pcapng"; rte_pcapng_t *pcapng = NULL; int ret, tmp_fd, count; - uint64_t now = current_timestamp(); + uint64_t now = rte_tsc_to_ns(rte_get_tsc_cycles()); tmp_fd = mkstemps(file_name, strlen(".pcapng")); if (tmp_fd == -1) { @@ -625,7 +647,7 @@ test_write_before_open(void) /* Small delay so the capture start is measurably after the copies */ rte_delay_us_block(100); - now = current_timestamp(); + now = rte_tsc_to_ns(rte_get_tsc_cycles()); tmp_fd = mkstemps(file_name, strlen(".pcapng")); if (tmp_fd == -1) { -- 2.53.0