From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mail.toke.dk (Postfix) with ESMTPS id 6E79C9FF11E for ; Tue, 18 Apr 2023 16:01:39 +0200 (CEST) Authentication-Results: mail.toke.dk; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=dJKEPDOu DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1681826498; 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=5fONgD5ZI0CkRixaJ2Z/vCiQZM4I6ehW6VIFsC+eLAk=; b=dJKEPDOujrwfs0BgevLOc6NBVZ8w5tK6QDwdv8UtUK5XkVlVREKKBYZ+LPdl2YJ0/ClvWj 1/Zsypsk25OkB+B8VGqpl8SPbwppNMKbVO/7aS/Aqf/3suOjgCAZ/FRWcg8gLRRl0qDMjX S7tZu7udG6Sdz6dStlTz0DKHj9MKD2M= Received: from mail-ed1-f71.google.com (mail-ed1-f71.google.com [209.85.208.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-192-2ZfH5v32OMKEv4DFDI4onA-1; Tue, 18 Apr 2023 10:01:34 -0400 X-MC-Unique: 2ZfH5v32OMKEv4DFDI4onA-1 Received: by mail-ed1-f71.google.com with SMTP id g1-20020a50d5c1000000b00506955403b5so4768132edj.23 for ; Tue, 18 Apr 2023 07:01:34 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681826493; x=1684418493; h=content-transfer-encoding:in-reply-to:references:to :content-language:subject:cc:user-agent:mime-version:date:message-id :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=5fONgD5ZI0CkRixaJ2Z/vCiQZM4I6ehW6VIFsC+eLAk=; b=jabio5Im+q63BkHoppF8uerSaOFrFp3nnylMYsBVEYUcaMFzPKJbxQFz6x/UMxqROi 3QoZTXmfMfYJFK/j/iJj7KXF9zaSG/xncDIxyHAJQ8GIAw6APHkYAps9gbP/v041onTg G4kV9QFP9LtMC8Vmu/mZbivKPrX12FIb5XWLJ9lKm8/xH67K4Eftj3MjWLGful2iyYe3 xerpyMoSD/3OSV+hHYGs39h2g+z3fN0nlE9YfMCN1W7ORciUhUKLKOfbPMT6ViEgGd7a ywj7VBITv/9CzLq+hSj6XfNgXZmDWc2ckcdh7vGFbmbPGRgK3p2IUfeuCuZxCGaITFlQ xV/w== X-Gm-Message-State: AAQBX9fo1wEHw7gYLSOHqkRmi8GM5LxWhOe3VITqclGmkuq8MlE4PFd8 uJsSmqyPvXPK9/5wBsP8JeJEXNrtcIu7KRwsVCvuWtA14xZ9FvYOg+Uk0LdHgiCX4EX9SmBSnFa FmyvvjjHKlnDaluDNukYB X-Received: by 2002:a17:907:d689:b0:953:1a7c:51b7 with SMTP id wf9-20020a170907d68900b009531a7c51b7mr1833381ejc.28.1681826493392; Tue, 18 Apr 2023 07:01:33 -0700 (PDT) X-Google-Smtp-Source: AKy350aemARlMVPdy8kgJgXVuHzGD4sbX/Gl6p99Go7osU8PHjd+oUCms+1rCgpAgVHjctvdD0LBVw== X-Received: by 2002:a17:907:d689:b0:953:1a7c:51b7 with SMTP id wf9-20020a170907d68900b009531a7c51b7mr1833311ejc.28.1681826492813; Tue, 18 Apr 2023 07:01:32 -0700 (PDT) Received: from [192.168.42.222] (194-45-78-10.static.kviknet.net. [194.45.78.10]) by smtp.gmail.com with ESMTPSA id qx11-20020a170906fccb00b0094f499257f7sm4053337ejb.151.2023.04.18.07.01.30 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 18 Apr 2023 07:01:31 -0700 (PDT) From: Jesper Dangaard Brouer X-Google-Original-From: Jesper Dangaard Brouer Message-ID: Date: Tue, 18 Apr 2023 16:01:30 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.8.0 To: Kurt Kanzenbach , yoong.siang.song@intel.com References: <168174338054.593471.8312147519616671551.stgit@firesoul> <168174344813.593471.4026230439937368990.stgit@firesoul> <87leiqsexd.fsf@kurt> In-Reply-To: <87leiqsexd.fsf@kurt> X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Message-ID-Hash: NZ3B63V2AVZRQSH3XOKMASUTSPHLXTD6 X-Message-ID-Hash: NZ3B63V2AVZRQSH3XOKMASUTSPHLXTD6 X-MailFrom: jbrouer@redhat.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: brouer@redhat.com, netdev@vger.kernel.org, martin.lau@kernel.org, ast@kernel.org, daniel@iogearbox.net, alexandr.lobakin@intel.com, larysa.zaremba@intel.com, xdp-hints@xdp-project.net, intel-wired-lan@lists.osuosl.org, pabeni@redhat.com, jesse.brandeburg@intel.com, kuba@kernel.org, bpf@vger.kernel.org, edumazet@google.com, john.fastabend@gmail.com, hawk@kernel.org, davem@davemloft.net, Stanislav Fomichev , =?UTF-8?Q?Toke_H=c3=b8iland-J=c3=b8rgensen?= , Pasi Vaananen X-Mailman-Version: 3.3.8 Precedence: list Subject: [xdp-hints] Re: [PATCH bpf-next V1 5/5] selftests/bpf: xdp_hw_metadata track more timestamps List-Id: XDP hardware hints design discussion Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: On 17/04/2023 17.31, Kurt Kanzenbach wrote: > On Mon Apr 17 2023, Jesper Dangaard Brouer wrote: >> To correlate the hardware RX timestamp with something, add tracking of >> two software timestamps both clock source CLOCK_TAI (see description in >> man clock_gettime(2)). >> >> XDP metadata is extended with xdp_timestamp for capturing when XDP >> received the packet. Populated with BPF helper bpf_ktime_get_tai_ns(). I >> could not find a BPF helper for getting CLOCK_REALTIME, which would have >> been preferred. In userspace when AF_XDP sees the packet another >> software timestamp is recorded via clock_gettime() also clock source >> CLOCK_TAI. >> >> Example output shortly after loading igc driver: >> >> poll: 1 (0) skip=1 fail=0 redir=2 >> xsk_ring_cons__peek: 1 >> 0x12557a8: rx_desc[1]->addr=100000000009000 addr=9100 comp_addr=9000 >> rx_hash: 0x82A96531 with RSS type:0x1 >> rx_timestamp: 1681740540304898909 (sec:1681740540.3049) >> XDP RX-time: 1681740577304958316 (sec:1681740577.3050) delta sec:37.0001 (37000059.407 usec) >> AF_XDP time: 1681740577305051315 (sec:1681740577.3051) delta sec:0.0001 (92.999 usec) >> 0x12557a8: complete idx=9 addr=9000 >> >> The first observation is that the 37 sec difference between RX HW vs XDP >> timestamps, which indicate hardware is likely clock source >> CLOCK_REALTIME, because (as of this writing) CLOCK_TAI is initialised >> with a 37 sec offset. > > Maybe I'm missing something here, but in order to compare the hardware > with software timestamps (e.g., by using bpf_ktime_get_tai_ns()) the > time sources have to be synchronized by using something like > phc2sys. That should make them comparable within reasonable range > (nanoseconds). Precisely, in this test I've not synchronized the clocks. The observation is that driver igc clock gets initialized to CLOCK_REALTIME wall-clock time, and it slowly drifts as documented in provided link[1]. [1] https://github.com/xdp-project/xdp-project/blob/master/areas/hints/xdp_hints_kfuncs02_driver_igc.org#driver-igc-clock-drift-observations [2] https://github.com/xdp-project/xdp-project/blob/master/areas/hints/xdp_hints_kfuncs02_driver_igc.org#quick-time-sync-setup I've also played with using phc2sys (in same doc[2]) to sync HW clock with SW clock. I do *seek input* if I'm using it correctly?!?. I don't have a PTP clock setup , so I manually: Use phc2sys to synchronize the system clock to the PTP hardware clock (PHC) on the network card (which driver inited to CLOCK_REALTIME wall-clock). Stop ntp clock sync and disable most CPU sleep states: sudo systemctl stop chronyd sudo tuned-adm profile latency-performance sudo hexdump --format '"%d\n"' /dev/cpu_dma_latency 2 Adjust for the 37 sec offset to TAI, such that our BPF-prog using TAI will align: sudo phc2sys -s igc1 -O -37 -R 2 -u 10 Result on igc with xdp_hw_metadata: poll: 1 (0) skip=1 fail=0 redir=6 xsk_ring_cons__peek: 1 rx_hash: 0x82A96531 with RSS type:0x1 rx_timestamp: 1681825632645744805 (sec:1681825632.6457) XDP RX-time: 1681825632645755858 (sec:1681825632.6458) delta sec:0.0000 (11.053 usec) AF_XDP time: 1681825632645769371 (sec:1681825632.6458) delta sec:0.0000 (13.513 usec) The log file from phc2sys says: phc2sys[1294263]: [86275.140] CLOCK_REALTIME rms 6 max 11 freq +13719 +/- 5 delay 1435 +/- 5 Notice the delta between HW and SW timestamps is 11.053 usec. Even-though it is small, I don't really trust it, because the phc2sys log says frequency offset mean is "+13719" nanosec. So, it is true that latency/delay between HW to XDP-SW is 11 usec? Or is this due to (in)accuracy of phc2sys sync? --Jesper