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 585C4606A320 for ; Tue, 1 Dec 2026 22:43:46 +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=T2s131yy Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 0741C40696; Tue, 1 Dec 2026 23:43:09 +0100 (CET) Received: from mail-pf1-f179.google.com (mail-pf1-f179.google.com [209.85.210.179]) by mails.dpdk.org (Postfix) with ESMTPS id 3D97D40687 for ; Tue, 1 Dec 2026 23:43:08 +0100 (CET) Received: by mail-pf1-f179.google.com with SMTP id d2e1a72fcca58-8c700d6cc0bso6354180b3a.1 for ; Tue, 01 Dec 2026 14:43:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20260707.gappssmtp.com; s=20260707; t=1796164987; x=1796769787; 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=T2s131yyFkRsgJQmKEVeyvRK8u1l0PqbiXAkchv+aE0Y9lr0tuiCE/sEJwTLDeZcbX otAu93bVWAKGmy3I+GMPLcM3lh1BBN+nrUPyGtqs5EJVBhrGz/fLIDibHTY3e0A3iO8b 1a0MHYjUjHQtyM8sJxiWsr9S7qxLqdz2RqcJNrH5D1uoGOUrrroP0xN4THygcTaydocz xsuHCNNlqVunwxhYZm2keXr8H75i9PS+vYru/cMXUGSKEEDQoiFOEgxROSBQJa70yVpI dpcjiJNAJv8PqMzmtr4LT5KlPZONKF0T4NOugXupABjC7+u3mrUmrXGK5gYAUMU2UNAR /jdw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796164987; x=1796769787; 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=ZD2zUDyaISgbllXTD01Srl/5ylN4or3WeQK9xDsYts+l2wSdamVdezKw0f4VYOB2T1 JTTLe/matPUmOoe4J/XR2/fUsDshiFUgMiepJx/3mLydPTiozeCZrIsLixAJBuenCnJ8 QVsXDBLnfQgGGZKS9k16CqLibIDTXDHX+ood8XdWTVHOj17453d49bEaadP3IySely6g czz86PhBipefug4abCQUulFBAM9rQyBk+E94SGLi6BaEv0en3fP5gHC0d5DqytRTp1s/ Tj7xEwUGhuMMhFvs/xNOzjGvdhvb1MpZdrNmwNvq/+Ta6hCHdpO1WU2EUuw58Rllcy96 W+oQ== X-Gm-Message-State: APuU4Z+3wBtZ5OaT7PhbLEwzTmv39cmXHb/UIBMzgOJEClmG0shKYgtI zzkVU4do9M8753a7zoFDL9c1hD7wBhYf9eszolJN83rYYDV77pJuwHWLTX8O329tzGL3oKSWXwb Zip7GgtI= X-Gm-Gg: AZFdTZd+VrXL9x72Y/5N/n5SDHdKZrgE+Nws8N4NY0gGZTECYqQe4ZNe8vRcQtGsuJA CBpIrF2+9KUZiIJVUOyTHgVBnqRh2MyJaxPRmJUczikt3fC3Ru+1J3v1kszg6FOJpWqLQOLWgTo +PXg01oxnJm9tAJrdmteQdtxoy4MbmC9beDzHlU5mTR2SiF9BGJaoRWHvv+FQ+BbZDZXFI+nFoF ES2fKwiN6JhUFQyiY7f+c2iLkNPhULXRJ6yFoQuLMJYFzU9Kq5REdTWSFnCwbR861fF0dVzWXmg +wMvKgXpzY1h3iUqb9z/lQXO+4+ZHCTrTnldmKTk8lhRG6gfNFR3hXOFTiZVHb0SyGLV2hFbxn0 QlJpBd8EyCunEfgew6rdX8Ulau21P+j38G/0r1MDwOci45gcvkYQCuPZh+Zy3y0pKHWYAGYYgGk MnK2KfXYE7q/e7zJUnMpl+30Q3X/csfuEyGMzOuXMb/iwUYZpEAhmaav0d+X9nyLxoBs/BeceSC QDG+pgXtaLOTZVpInEww/3AkX3AeURx7V0Q8hkj0L6bLlZRvjh31R+s3x59knjg5AcJJ09cnRk3 rMa67GQrAL0mmlQYoyUbU/jOJ/2tuBLqb/vTwJk2EAMXrIZdSllIt9+X7cRuosLWtOq+AeX3e4/ l7I3cTcnhYOoejA== X-Received: by 2002:a05:6a20:7345:b0:3e2:44c8:6e65 with SMTP id adf61e73a8af0-400ad967b14mr34083933637.23.1796164986642; Tue, 01 Dec 2026 14:43:06 -0800 (PST) Received: from phoenix.lan (204-195-112-43.wavecable.com. [204.195.112.43]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-cde6cfebdbasm20739684a12.13.2026.12.01.14.43.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 01 Dec 2026 14:43:05 -0800 (PST) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger , Reshma Pattan Subject: [PATCH 6/7] test/pcapng: compare timestamps in one clock domain Date: Tue, 1 Dec 2026 14:41:39 -0800 Message-ID: <20261201224258.1962108-7-stephen@networkplumber.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20261201224258.1962108-1-stephen@networkplumber.org> References: <20261201224258.1962108-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