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 ED9AD425FC for ; Wed, 20 Sep 2023 21:55:36 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id B29D540A7A; Wed, 20 Sep 2023 21:55:36 +0200 (CEST) Received: from mail-lj1-f172.google.com (mail-lj1-f172.google.com [209.85.208.172]) by mails.dpdk.org (Postfix) with ESMTP id AA9E1402BA for ; Wed, 20 Sep 2023 21:55:35 +0200 (CEST) Received: by mail-lj1-f172.google.com with SMTP id 38308e7fff4ca-2c124adf469so3428191fa.0 for ; Wed, 20 Sep 2023 12:55:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1695239735; x=1695844535; darn=dpdk.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=HilJNPZIR8ZiSH032gllhB4RPmeoJOjt48DiCrZ9hBQ=; b=R48500YAE6mE/4+aqZu7iXKS0amvd69sZBMy+Jgt4YIeUfjW5Ky0SxgXlQwKDwGRVy jFRmYvTGX6jAOKWrtH1or3qt43yU94L8b45buARNLn/W8gUia2vKFKb+QWAOLzlER6AJ y6yRzSzria+I02m/e5xFGbGvREvXzzJXRTYRiDDAREjxng/U+WlxGENbgzReJc79ZQFf yOlcNNgSx1++Qms3IBx6Mb0vH/4036V4I1DmrbJi7UY8T+jfhcTcM+sEpQz0icIDA6cp eFineeCuzDL/Fs8ooRPPjEURcEr/kwXXQ0RtMl0YwKuLoCc2gWQIdHvWiVL6IOXxlSBJ 62ag== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695239735; x=1695844535; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=HilJNPZIR8ZiSH032gllhB4RPmeoJOjt48DiCrZ9hBQ=; b=EFk5dtFLbF0KtAnKGO4yuqo9fxy1LJ5xKEecNuhZjRd32b6kZ7t3ur8MXjKuPjTcUv UkYgADDcgq1XnhiTzWi4m6RZZAB31sr/pD368zhzpOaz1TQXiqi24ilf73d+MuNCtpz0 paV3DhU8xGqGa8fTzjV+mKdE40uiA4RmAQp0wdhVquRLjBNFoYcTlbPA5kG3dyXDekgd 8cWDTr2JTTIe3Z+d/Hhuln7az+ngBBUT5LVWWvASmSlqbexY9T5cRWXvLb0uFt8bAOX7 H/DyvNX+sIedpE0PCu7BKxSCGn2IFvMMlhQtu8JmxXci58YgT0N+HI5xQSyjk+LDmUht GtDQ== X-Gm-Message-State: AOJu0YwAdg7nSiLHDS9oRJrWplq+2Yjof9WAK2FCwHZmnljK8EwDj+h0 j/FEvIFdOk5ppeNzKx1vQWGACQnUIY/sr0fhoUpgofkPtVc= X-Google-Smtp-Source: AGHT+IHXHSYf2i4haM9iweZsVAbo4Gn9fOn7lBztG+TafB67S99fGJIRXjVA1rCzQoKzMB1JkI30QhljAxouQlnd94s= X-Received: by 2002:a2e:301a:0:b0:2bc:bcc6:d4ad with SMTP id w26-20020a2e301a000000b002bcbcc6d4admr3021972ljw.21.1695239734752; Wed, 20 Sep 2023 12:55:34 -0700 (PDT) MIME-Version: 1.0 References: <20230919110009.29e90615@hermes.local> In-Reply-To: From: Isaac Boukris Date: Wed, 20 Sep 2023 22:55:21 +0300 Message-ID: Subject: Re: dumpcap: timestamp is years ahead when in pcapng format To: Stephen Hemminger Cc: users@dpdk.org Content-Type: multipart/mixed; boundary="00000000000033511c0605cfc229" X-BeenThere: users@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK usage discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: users-bounces@dpdk.org --00000000000033511c0605cfc229 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable I found a way to get a better resolution; at init we set 'pcapng_time.tsc_hz=3Drte_get_tsc_hz()/NSEC_PER_SEC' this way we keep the number of cycles in a nano-second, then at run time we just need to divide delta by this number (with no need to multiply by NSEC_PER_SEC). The problem is I guess, that on slow systems we'll end up with tsc_hz=3D0? Perhaps we'd need to drop to ms resolution in such a case. With the attach patch I get: 2023-09-20 10:22:13.579219 IP Rocky8 > A: ICMP echo request, id 13, seq 63, length 64 2023-09-20 10:22:13.580582 IP A > Rocky8: ICMP echo reply, id 13, seq 63, length 64 3 2023-09-20 10:22:14.745176 IP Rocky8 > A: ICMP echo request, id 13, seq 64, length 64 2023-09-20 10:22:14.746206 IP ... On Wed, Sep 20, 2023 at 9:53=E2=80=AFPM Isaac Boukris = wrote: > > I figured the first packet bug, fixed with: > - if (!pcapng_time.tsc_hz) > + if (!pcapng_time.tsc_hz) { > pcapng_init(); > + return pcapng_time.ns; > + } > > However I noticed a caveat with my proposed fix as it seem we only get > a time resolution of one sec: > > 2023-09-20 09:40:20.727638 IP Rocky8 > A: ICMP echo request, id 11, > seq 81, length 64 > 2023-09-20 09:40:20.727638 IP A > Rocky8: ICMP echo reply, id 11, seq > 81, length 64 > 2023-09-20 09:40:21.727638 IP ... > > On Wed, Sep 20, 2023 at 8:59=E2=80=AFPM Isaac Boukris wrote: > > > > On Tue, Sep 19, 2023 at 9:00=E2=80=AFPM Stephen Hemminger > > wrote: > > > > > > On Tue, 19 Sep 2023 19:35:55 +0300 > > > Isaac Boukris wrote: > > > > > > > Looking with git log, i found the original line was: > > > > return pcapng_time.ns + (delta * NSEC_PER_SEC) / rte_get_tsc_hz(); > > > > > > > > Testing that does show a wrapping issue, e.g. (it stays around 08:0= 5). > > > > > > > > 2023-09-19 08:05:24.372037 IP _gateway.domain > Rocky8.38358: 31975 > > > > NXDomain 0/0/0 (46) 10 > > > > 2023-09-19 08:05:21.577497 ARP, Request who-has _gateway tell Rocky= 8, > > > > length 46 > > > > 2023-09-19 08:05:21.577599 ARP, Reply _gateway is-at 00:50:56:f8:92= :76 > > > > (oui Unknown), length 46 13 > > > > 2023-09-19 08:05:22.833897 IP 192.168.202.1.50886 > > > > > 239.255.255.250.ssdp: UDP, length 174 > > > > > > > > However with my change it looks fine and always increments. I dropp= ed > > > > all the parenthesis: > > > > return pcapng_time.ns + delta / pcapng_time.tsc_hz * NSEC_PER_SEC; > > > > > > The issue is that timestamping is in the fast path and that 64 bit di= vide is slow. > > > Looking at other alternatives. > > > > Then perhaps we can keep the division optimization and just get rid of > > the overflow check, relying on the change to multiply by NSEC_PER_SEC > > after the division. > > > > With the below change only the first packet is from 2257 while all > > subsequent packets are fine. But if I keep the overflow check and only > > change to multiply after the division, then all packets are shown from > > 2257. > > > > [admin@Rocky8 dpdk]$ git diff lib/pcapng/rte_pcapng.c > > diff --git a/lib/pcapng/rte_pcapng.c b/lib/pcapng/rte_pcapng.c > > index 80d08e1..fa545cd 100644 > > --- a/lib/pcapng/rte_pcapng.c > > +++ b/lib/pcapng/rte_pcapng.c > > @@ -79,7 +79,7 @@ static uint64_t pcapng_tsc_to_ns(uint64_t cycles) > > * Currently all TSCs operate below 5GHz. > > */ > > delta =3D cycles - pcapng_time.cycles; > > - if (unlikely(delta >=3D pcapng_time.tsc_hz)) { > > + if (0 && unlikely(delta >=3D pcapng_time.tsc_hz)) { > > if (likely(delta < pcapng_time.tsc_hz * 2)) { > > delta -=3D pcapng_time.tsc_hz; > > pcapng_time.cycles +=3D pcapng_time.tsc_hz; > > @@ -92,8 +92,9 @@ static uint64_t pcapng_tsc_to_ns(uint64_t cycles) > > } > > } > > > > - return pcapng_time.ns + rte_reciprocal_divide_u64(delta * NSEC_= PER_SEC, > > - > > &pcapng_time.tsc_hz_inverse); > > + return pcapng_time.ns + rte_reciprocal_divide_u64(delta, > > + > > &pcapng_time.tsc_hz_inverse) * NSEC_PER_SEC; > > } --00000000000033511c0605cfc229 Content-Type: application/octet-stream; name="rework_tsc_to_ns.patch" Content-Disposition: attachment; filename="rework_tsc_to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NlY3MgKiBwY2FwbmdfdGltZS50c2NfaHo7DQotICAg ICAgICAgICAgICAgICAgICAgICBwY2FwbmdfdGltZS5jeWNsZXMgKz0gc2VjcyAqIHBjYXBuZ190 aW1lLnRzY19oejsNCi0gICAgICAgICAgICAgICAgICAgICAgIHBjYXBuZ190aW1lLm5zICs9IHNl Y3MgKiBOU0VDX1BFUl9TRUM7DQotICAgICAgICAgICAgICAgfQ0KLSAgICAgICB9DQoNCi0gICAg ICAgcmV0dXJuIHBjYXBuZ190aW1lLm5zICsgcnRlX3JlY2lwcm9jYWxfZGl2aWRlX3U2NChkZWx0 YSAqIE5TRUNfUEVSX1NFQywNCisgICAgICAgcmV0dXJuIHBjYXBuZ190aW1lLm5zICsgcnRlX3Jl Y2lwcm9jYWxfZGl2aWRlX3U2NChkZWx0YSwNCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAg ICAgICAgICAgICAgICAgICAgICAgICAgICAgICAmcGNhcG5nX3RpbWUudHNjX2h6X2ludmVyc2Up Ow0KIH0NCg0KLS0NCjIuMzkuMw== --00000000000033511c0605cfc229--