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 1BC00606A322 for ; Thu, 3 Dec 2026 18:01:47 +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=PZKFQsFi Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 6CCD440DFD; Thu, 3 Dec 2026 19:01:01 +0100 (CET) Received: from mail-pf1-f175.google.com (mail-pf1-f175.google.com [209.85.210.175]) by mails.dpdk.org (Postfix) with ESMTPS id 198EB40A6D for ; Thu, 3 Dec 2026 19:00:59 +0100 (CET) Received: by mail-pf1-f175.google.com with SMTP id d2e1a72fcca58-8b6b22be970so50276b3a.1 for ; Thu, 03 Dec 2026 10:00:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20260707.gappssmtp.com; s=20260707; t=1796320857; x=1796925657; 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=PZKFQsFiJOdLpITgmBHg80/0GaLWB+Z9f7ItYJFzwBQWuKKvQ47f/DX9zkSv8T7ZdC b971Yz8w4MNcr/my3Onx7IZBE6bSToknq6eHfsqhkJm8rkdFqFe3NXBBH0SoN4v9Mpk9 uNwygpUHMxZ7pfUicIJmycraH3K5CS4ixKQ60RFwgH18zNoBZ4aorHQ70b6PaCRVKd3d c0KHyiCG8E7dQWkNlPaEfGigQI5JKBjdBiuxGohI+Dej735IUlmNotGX6gQFBzGcAyo9 6nZb4FLgVMfUzq8RfpInscYpzbIkKQQEzQx+H4BjpPf93Qq9V5KyKF+nnCr29aEReawC l/qg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796320857; x=1796925657; 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=y0aBIxcay+MKOsCXimE94d56ZpUQyfhFp/yeQTW02Z6BKZ17HzHnsadxWMgo7O/0Ed eQm1KgsGmyRFqFo35Dxn6ohTppJiAyagYcIcrXQY5rcVf9Q4wQdkqul/Eq+s4+WxLNdP zaGQjWicG28mfP730bc3DL5eNqF6BkOON00bnqepH2T/NyUDL//AqIiidZNzL7GYurG0 D1YjNLLHhir7Q9ubw0Ro3QTO9US+48GxPZd4dehk3U6cy3m1hqND66vWVGkKgLUP+qCX UJihsiLQT2Ow9OT743VTewOYOWr+W/2nPg40adBBTwlxIjZbj0eueiEFIhLfDWl6FqAk dX4w== X-Gm-Message-State: APuU4Z+DStaLLvJh8OLzGALpuhWo8JmrsAgCpwk8MCNsCXu5X6p+JKTG dyIj+dtFTpfAtcV6L3/On5BikCWHBFI71dZO5C92HXhb7yjQjqoznt2PLRF1b2fkd9ny82xYAxz Y+Gpq X-Gm-Gg: AZFdTZeWpQcFIRVANGoIPkt0NpYNe/EXtLt6pnOahmez+N2z7lO4/yvaXcclH7gsuLz SLYMtSTSnM8+O/LVJ44adQtwWBSzY9hyNIDCUFBy0r6rvj46bdH5M34OBiXUKc9dj+gOQqxVosT uX/mFicT/UXqfLqKLaMUSRY7HxL7znX9Bk2LN5fJQnJwvK15FOwYkpMOmry3e+39O1WsHTR6OMA 27YTOo/K4LeK3Sk9yyxWEkyt0Jr7Mf0yTAtT4+KhxlinCXxJa3xPQktJsoyFqw4lk6TradOQCm+ LraELR1ISCqyjNpHSqhI11fSy+a2b/L5ya7PdfdcQbRC7hEWV+lWNig3KLYMHs6CsTtPjO+1nVh /8SmEs5XbYsjD/5EX6MuDnfLLt8fDL9uBRUPXN2dJ/Wkh/yR2bHQgwnlmu8/Q+jntMxyuqjBAgf os6jJku2cNEXLkNhGGR2f4aI/A1CtxBPXdoQoiJBwIpBjFyhcYKfEmsXco7/ypGfJQNYESbNDqD L5iXqaZlvYAwPSDadFPRFNJqRi1fIhCdcHQGcj9pAPnfncHf7vwBhL7fm3j3PUfY56vSe7mDS++ RwwTeSP+gCjhSRXAXk52Y/B1uD6pORbdHB0RqH7ZLcnOWLJGwgh6SZpqkPSh4vw8vhIY X-Received: by 2002:a17:90b:4ec4:b0:3b3:bf8f:9ccb with SMTP id 98e67ed59e1d1-3b41c8ffa94mr40290617a91.18.1796320857384; Thu, 03 Dec 2026 10:00:57 -0800 (PST) Received: from phoenix.lan (204-195-112-43.wavecable.com. [204.195.112.43]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-3b5c7649efbsm5329952a91.3.2026.12.03.10.00.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Dec 2026 10:00:57 -0800 (PST) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger , Reshma Pattan Subject: [PATCH v3 6/6] test/pcapng: compare timestamps in one clock domain Date: Thu, 3 Dec 2026 09:59:48 -0800 Message-ID: <20261203180050.73444-7-stephen@networkplumber.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20261203180050.73444-1-stephen@networkplumber.org> References: <20261201224258.1962108-1-stephen@networkplumber.org> <20261203180050.73444-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