From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-il1-x12a.google.com (mail-il1-x12a.google.com [IPv6:2607:f8b0:4864:20::12a]) by mail.toke.dk (Postfix) with ESMTPS id 73AE99BC383 for ; Thu, 10 Nov 2022 19:52:44 +0100 (CET) Authentication-Results: mail.toke.dk; dkim=pass (2048-bit key; unprotected) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20210112 header.b=I5wpQl2t Received: by mail-il1-x12a.google.com with SMTP id l6so1472389ilq.3 for ; Thu, 10 Nov 2022 10:52:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=MaS3U08LyNcGzLT7FX/+u25NsWbC+DcNzQ0FjjWVgB0=; b=I5wpQl2tuZWPGvUBhZKA7beKI9wskjEFEbyN80pJwRF6hSd+jpfMWkVZwyMmb/kQHi s2DQ9Fj0QtkqfQmvh/4Um1q8D/YgC4D5HYhnr50TZKUCcplDzg/k9MVqKJGW4XzZdnaa hsSh5P6vwL58w1lygMaAwGaK08kXx97SCbXPvj7IMo+cpBgyjaD6Utj+seDrHzfBcw5S Th+AJwKuZ2y8GzAgkBCSV+SIiIpY5o6Zxb1IDEMpmKc1WvW5d035/8VvOF4erj8/jVt9 hNP7WLjCU1S2DVajU/i9ytGGZkxTEn+PXKbHzrUc//Y61fkiRLsKFevAPBNf2mgrTd5e N6MA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=MaS3U08LyNcGzLT7FX/+u25NsWbC+DcNzQ0FjjWVgB0=; b=VyEvqpiOvtrtukSsroACpmmx0lM/VVcFWEUXY0sSG50B5vTUJCh8HejI9WaT+cws8d CbTHjzEQ6Jm7u5FOjurksQIQUPk8zE3ajp6hjHarKYS/TelxJuAh0pJVZa8LULcOLJHy 4PHH0+s4gJXlgaSQG8VHnQDK8Fb3wvEEMQEnmKM+qdeU6uG7/cYbHWOjEXlMCdSDzO1A P6CdFdODe2nQMMbTB2k5Dyg/xmI36rZToc7jTyvPGXLnr/f9dhcyQ/pbKxkd4RHqPfiy Fb7YxsypJGEYVe45zYziIcHmhSJksFeyIT4515VtruGyxFwywM92nHz/Wi2BNGBdxQWI +Vdg== X-Gm-Message-State: ACrzQf01Z9wXw0JljtLxS59DD7QuztURcWnspmrr8JOTAXMhCfc+W3Dg CXYdlZ4qOjxA0SVDEvelVli0PzXdbVHDfGSz40ogLQ== X-Google-Smtp-Source: AMsMyM4l7V/phVfcs1QUfEuMPnt2QNGEdDusWFMhxKynKEl5lGw+WcBSLbT/S3+gTzTYM+6PDiGs/ffDdMCuFF6jD2s= X-Received: by 2002:a92:4b01:0:b0:300:d5f1:c1b0 with SMTP id m1-20020a924b01000000b00300d5f1c1b0mr3198330ilg.133.1668106362288; Thu, 10 Nov 2022 10:52:42 -0800 (PST) MIME-Version: 1.0 References: <20221104032532.1615099-1-sdf@google.com> <20221104032532.1615099-5-sdf@google.com> <636c4514917fa_13c168208d0@john.notmuch> <636c555942433_13ef3820861@john.notmuch> <636d37629d5c4_145693208e6@john.notmuch> In-Reply-To: <636d37629d5c4_145693208e6@john.notmuch> From: Stanislav Fomichev Date: Thu, 10 Nov 2022 10:52:31 -0800 Message-ID: To: John Fastabend Content-Type: text/plain; charset="UTF-8" Message-ID-Hash: 3652OXCEUAJDLMI37U64WD7I3DRBI76H X-Message-ID-Hash: 3652OXCEUAJDLMI37U64WD7I3DRBI76H X-MailFrom: sdf@google.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: bpf@vger.kernel.org, ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org, martin.lau@linux.dev, song@kernel.org, yhs@fb.com, kpsingh@kernel.org, haoluo@google.com, jolsa@kernel.org, David Ahern , Jakub Kicinski , Willem de Bruijn , Jesper Dangaard Brouer , Anatoly Burakov , Alexander Lobakin , Magnus Karlsson , Maryam Tahhan , xdp-hints@xdp-project.net, netdev@vger.kernel.org X-Mailman-Version: 3.3.6 Precedence: list Subject: [xdp-hints] Re: [RFC bpf-next v2 04/14] veth: Support rx timestamp metadata for xdp List-Id: XDP hardware hints design discussion Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: On Thu, Nov 10, 2022 at 9:39 AM John Fastabend wrote: > > Stanislav Fomichev wrote: > > On Wed, Nov 9, 2022 at 5:35 PM John Fastabend wrote: > > > > > > Stanislav Fomichev wrote: > > > > On Wed, Nov 9, 2022 at 4:26 PM John Fastabend wrote: > > > > > > > > > > Stanislav Fomichev wrote: > > > > > > xskxceiver conveniently setups up veth pairs so it seems logical > > > > > > to use veth as an example for some of the metadata handling. > > > > > > > > > > > > We timestamp skb right when we "receive" it, store its > > > > > > pointer in new veth_xdp_buff wrapper and generate BPF bytecode to > > > > > > reach it from the BPF program. > > > > > > > > > > > > This largely follows the idea of "store some queue context in > > > > > > the xdp_buff/xdp_frame so the metadata can be reached out > > > > > > from the BPF program". > > > > > > > > > > > > > > > > [...] > > > > > > > > > > > orig_data = xdp->data; > > > > > > orig_data_end = xdp->data_end; > > > > > > + vxbuf.skb = skb; > > > > > > > > > > > > act = bpf_prog_run_xdp(xdp_prog, xdp); > > > > > > > > > > > > @@ -942,6 +946,7 @@ static int veth_xdp_rcv(struct veth_rq *rq, int budget, > > > > > > struct sk_buff *skb = ptr; > > > > > > > > > > > > stats->xdp_bytes += skb->len; > > > > > > + __net_timestamp(skb); > > > > > > > > > > Just getting to reviewing in depth a bit more. But we hit veth with lots of > > > > > packets in some configurations I don't think we want to add a __net_timestamp > > > > > here when vast majority of use cases will have no need for timestamp on veth > > > > > device. I didn't do a benchmark but its not free. > > > > > > > > > > If there is a real use case for timestamping on veth we could do it through > > > > > a XDP program directly? Basically fallback for devices without hw timestamps. > > > > > Anyways I need the helper to support hardware without time stamping. > > > > > > > > > > Not sure if this was just part of the RFC to explore BPF programs or not. > > > > > > > > Initially I've done it mostly so I can have selftests on top of veth > > > > driver, but I'd still prefer to keep it to have working tests. > > > > > > I can't think of a use for it though so its just extra cycles. There > > > is a helper to read the ktime. > > > > As I mentioned in another reply, I wanted something SW-only to test > > this whole metadata story. > > Yeah I see the value there. Also because this is in the veth_xdp_rcv > path we don't actually attach XDP programs to veths except for in > CI anyways. I assume though if someone actually does use this in > prod having an extra _net_timestamp there would be extra unwanted > cycles. > > > The idea was: > > - veth rx sets skb->tstamp (otherwise it's 0 at this point) > > - veth kfunc to access rx_timestamp returns skb->tstamp > > - xsk bpf program verifies that the metadata is non-zero > > - the above shows end-to-end functionality with a software driver > > Yep 100% agree very handy for testing just not sure we can add code > to hotpath just for testing. > > > > > > > Any way I can make it configurable? Is there some ethtool "enable tx > > > > timestamping" option I can reuse? > > > > > > There is a -T option for timestamping in ethtool. There are also the > > > socket controls for it. So you could spin up a socket and use it. > > > But that is a bit broken as well I think it would be better if the > > > timestamp came from the receiving physical nic? > > > > > > I have some mlx nics here and a k8s cluster with lots of veth > > > devices so I could think a bit more. I'm just not sure why I would > > > want the veth to timestamp things off hand? > > > > -T is for dumping only it seems? > > > > I'm probably using skb->tstamp in an unconventional manner here :-/ > > Do you know if enabling timestamping on the socket, as you suggest, > > will get me some non-zero skb_hwtstamps with xsk? > > I need something to show how the kfunc can return this data and how > > can this data land in xdp prog / af_xdp chunk.. > > Take a look at ./Documentation/networking/timestamping.rst the 3.1 > section is maybe relevant. But then you end up implementing a bunch > of random ioctls for no reason other than testing. Maybe worth doing > though for this not sure. Hmm, there is a call to skb_tx_timestamp in veth_xmit that I missed. Let me see if I can make it insert skb->tstamp by turning on one of the timestamping options you mentioned.. > Using virtio driver might be actual useful and give you a test device. > Early XDP days I used it for testing a lot. Would require qemu to > setup though.