Netdev List
 help / color / mirror / Atom feed
From: Willem de Bruijn <willemdebruijn.kernel@gmail.com>
To: Jason Xing <kerneljasonxing@gmail.com>,
	 Willem de Bruijn <willemdebruijn.kernel@gmail.com>
Cc: davem@davemloft.net,  edumazet@google.com,  kuba@kernel.org,
	 pabeni@redhat.com,  dsahern@kernel.org,  willemb@google.com,
	 ast@kernel.org,  daniel@iogearbox.net,  andrii@kernel.org,
	 martin.lau@linux.dev,  eddyz87@gmail.com,  song@kernel.org,
	 yonghong.song@linux.dev,  john.fastabend@gmail.com,
	 kpsingh@kernel.org,  sdf@fomichev.me,  haoluo@google.com,
	 jolsa@kernel.org,  bpf@vger.kernel.org,  netdev@vger.kernel.org,
	 Jason Xing <kernelxing@tencent.com>
Subject: Re: [PATCH net-next v2 04/12] net-timestamp: add static key to control the whole bpf extension
Date: Mon, 21 Oct 2024 10:49:45 -0400	[thread overview]
Message-ID: <67166a0997028_42f03294e7@willemb.c.googlers.com.notmuch> (raw)
In-Reply-To: <CAL+tcoD5TiaRZgW10tt8jc9srQTbaszs_o2z=Yf-bzO0Kp-vLA@mail.gmail.com>

Jason Xing wrote:
> On Mon, Oct 21, 2024 at 5:52 AM Willem de Bruijn
> <willemdebruijn.kernel@gmail.com> wrote:
> >
> > Jason Xing wrote:
> > > From: Jason Xing <kernelxing@tencent.com>
> > >
> > > Willem suggested that we use a static key to control. The advantage
> > > is that we will not affect the existing applications at all if we
> > > don't load BPF program.
> > >
> > > In this patch, except the static key, I also add one logic that is
> > > used to test if the socket has enabled its tsflags in order to
> > > support bpf logic to allow both cases to happen at the same time.
> > > Or else, the skb carring related timestamp flag doesn't know which
> > > way of printing is desirable.
> > >
> > > One thing important is this patch allows print from both applications
> > > and bpf program at the same time. Now we have three kinds of print:
> > > 1) only BPF program prints
> > > 2) only application program prints
> > > 3) both can print without side effect
> > >
> > > Signed-off-by: Jason Xing <kernelxing@tencent.com>
> >
> > Getting back to this thread. It is long, instead of responding to
> > multiple messages, let me combine them in a single response.
> 
> Thank you so much!
> 
> >
> >
> > * On future extensions:
> >
> > +1 that the UDP case, and datagrams more broadly, must have a clear
> > development path, before we can merge TCP.
> >
> > Similarly, hardware timestamps need not be supported from the start,
> > but must clearly be supportable.
> 
> Agreed. Using the standalone sk_tsflags_bpf and tskey_bpf and removing
> the TCP bpf test logic(say, BPF_SOCK_OPS_TX_TIMESTAMPING_OPT_CB_FLAG)
> could work well for both protos. Let me give it a try first.

Great, thanks.

> >
> >
> > * On queueing packets to userspace:
> >
> > > > the current behavior is to just queue to the sk_error_queue as long
> > > > as there is "SOF_TIMESTAMPING_TX_*" set in the skb's tx_flags and it
> > > > is regardless of the sk_tsflags. "
> >
> > > Totally correct. SOF_TIMESTAMPING_SOFTWARE is a report flag while
> > > SOF_TIMESTAMPING_TX_* are generation flags. Without former, users can
> > > read the skb from the errqueue but are not able to parse the
> > > timestamps
> 
> Above is what I tried to explain how the application timestamping
> feature works, not what I tried to implement for the BPF extension.
> 
> >
> > Before queuing a packet to userspace on the error queue, the relevant
> > reporting flag is always tested. sock_recv_timestamp has:
> >
> >         /*
> >          * generate control messages if
> >          * - receive time stamping in software requested
> >          * - software time stamp available and wanted
> >          * - hardware time stamps available and wanted
> >          */
> >         if (sock_flag(sk, SOCK_RCVTSTAMP) ||
> >             (tsflags & SOF_TIMESTAMPING_RX_SOFTWARE) ||
> >             (kt && tsflags & SOF_TIMESTAMPING_SOFTWARE) ||
> >             (hwtstamps->hwtstamp &&
> >              (tsflags & SOF_TIMESTAMPING_RAW_HARDWARE)))
> >                 __sock_recv_timestamp(msg, sk, skb);
> >
> > Otherwise applications could get error messages queued, and
> > epoll/poll/select would unexpectedly behave differently.
> 
> Right. And I have no intention to use the SOF_TIMESTAMPING_SOFTWARE
> flag for BPF.

Can you elaborate on this? This sounds like it would go against the
intent to have the two versions of the API (application and BPF) be
equivalent.
 
> >
> > > SOF_TIMESTAMPING_SOFTWARE is only used in traditional SO_TIMESTAMPING
> > > features including cmsg mode. But it will not be used in bpf mode.
> >
> > For simplicity, the two uses of the API are best kept identical. If
> > there is a technical reason why BPF has to diverge from established
> > behavior, this needs to be explicitly called out in the commit
> > message.
> >
> > Also, if you want to extend the API for BPF in the future, good to
> > call this out now and ideally extensions will apply to both, to
> > maintain a uniform API.
> 
> As you said, I also agree on "two uses of the API are best kept identical".
> 
> >
> >
> > * On extra measurement points, at sendmsg or tcp_write_xmit:
> >
> > The first is interesting. For application timestamping, this was
> > never needed, as the application can just call clock_gettime before
> > sendmsg.
> 
> Yes, we could add it after we finish the current series. I'm going to
> write it down on my todo list.
> 
> >
> > In general, additional measurement points are not only useful if the
> > interval between is not constant. So far, we have seen no need for
> > any additional points.
> 
> Taking a snapshot of tcp_write_xmit() could be useful especially when
> the skb is not transmitted due to nagle algorithm.
> 
> >
> >
> > * On skb state:
> >
> > > > For now, is there thing we can explore to share in the skb_shared_info?
> >
> > skb_shinfo space is at a premium. I don't think we can justify two
> > extra fields just for this use case.
> >
> > > My initial thought is just to reuse these fields in skb. It can work
> > > without interfering one another.
> >
> > I'm skeptical that two methods can work at the same time. If they are
> > started at different times, their sk_tskey will be different, for one.
> 
> Right, sk_tskey is the only special one that I will take care of.
> Others like tx_flags or txstamp_ack from struct tcp_skb_cb can be
> reused.
> 
> >
> > There may be workarounds. Maybe BPF can store its state in some BPF
> > specific field, indeed. Or perhaps it can store per-sk shadow state
> > that resolves the conflict. For instance, the offset between sk_tskey
> > and bpf_tskey.
> 
> Things could get complicated in the future if we want to unified the
> final tskey value for all the cases. Since 1) the value of
> shinfo->tskey depends on skb seq and len, 2) the final tskey output is
> the diff between sk_tskey and shinfo->tskey, can I add a bpf_tskey in
> struct sock and related output logic for bpf without caring if it's
> the same as sk_tskey.

I think we can add fields to struct sock without too much concern.
Adding fields to sk_buff or skb_shared_info would be more difficult.

> That said, the outputs from two methods differ. Do you think it is
> acceptable? It could be simpler and easier if we keep them identical.

Since we can only have one skb_shared_info.tskey, if both user and bpf
request OPT_ID, starting at different times, then we will have two
bases against which to compute the difference. Having two fields in
struct sock should suffice.

  reply	other threads:[~2024-10-21 14:49 UTC|newest]

Thread overview: 73+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-10-12  4:06 [PATCH net-next v2 00/12] net-timestamp: bpf extension to equip applications transparently Jason Xing
2024-10-12  4:06 ` [PATCH net-next v2 01/12] net-timestamp: introduce socket tsflag requestors Jason Xing
2024-10-15  1:30   ` Willem de Bruijn
2024-10-15  1:50     ` Jason Xing
2024-10-12  4:06 ` [PATCH net-next v2 02/12] net-timestamp: open gate for bpf_setsockopt Jason Xing
2024-10-15  1:34   ` Willem de Bruijn
2024-10-15  2:05     ` Jason Xing
2024-10-15 21:32   ` Martin KaFai Lau
2024-10-15 21:55     ` Willem de Bruijn
2024-10-22 13:22       ` Jason Xing
2024-10-23  0:06         ` Willem de Bruijn
2024-10-23  3:49           ` Jason Xing
2024-10-16  0:45     ` Jason Xing
2024-10-15 23:54   ` Martin KaFai Lau
2024-10-16  0:49     ` Jason Xing
2024-10-12  4:06 ` [PATCH net-next v2 03/12] net-timestamp: reorganize in skb_tstamp_tx_output() Jason Xing
2024-10-12  4:06 ` [PATCH net-next v2 04/12] net-timestamp: add static key to control the whole bpf extension Jason Xing
2024-10-15  1:36   ` Willem de Bruijn
2024-10-15  2:25     ` Jason Xing
2024-10-16  0:09   ` Martin KaFai Lau
2024-10-16  1:04     ` Jason Xing
2024-10-16  1:32       ` Jason Xing
2024-10-16  6:13         ` Martin KaFai Lau
2024-10-16  6:30           ` Jason Xing
2024-10-16  7:01             ` Martin KaFai Lau
2024-10-16  7:54               ` Jason Xing
2024-10-16  8:31                 ` Martin KaFai Lau
2024-10-16 10:36                   ` Jason Xing
2024-10-17  0:48                     ` Martin KaFai Lau
2024-10-17  2:28                       ` Jason Xing
2024-10-17 20:43                         ` Martin KaFai Lau
2024-10-18  2:52                           ` Jason Xing
2024-10-18  3:05                             ` Jason Xing
2024-10-16  6:31       ` Martin KaFai Lau
2024-10-16  6:45         ` Jason Xing
2024-10-16 13:13           ` Willem de Bruijn
2024-10-16 13:22             ` Jason Xing
2024-10-20 21:51   ` Willem de Bruijn
2024-10-21  3:21     ` Jason Xing
2024-10-21 14:49       ` Willem de Bruijn [this message]
2024-10-21 15:05         ` Jason Xing
2024-10-22  0:53     ` Martin KaFai Lau
2024-10-22  2:30       ` Jason Xing
2024-10-23  0:17       ` Willem de Bruijn
2024-10-23  2:31         ` Willem de Bruijn
2024-10-12  4:06 ` [PATCH net-next v2 05/12] net-timestamp: add bpf infrastructure to allow exposing timestamp later Jason Xing
2024-10-12  4:06 ` [PATCH net-next v2 06/12] net-timestamp: introduce TS_SCHED_OPT_CB to generate dev xmit timestamp Jason Xing
2024-10-16  1:01   ` Martin KaFai Lau
2024-10-16  1:24     ` Jason Xing
2024-10-16  5:35       ` Martin KaFai Lau
2024-10-16  6:08         ` Jason Xing
2024-10-12  4:06 ` [PATCH net-next v2 07/12] net-timestamp: introduce TS_SW_OPT_CB to generate driver timestamp Jason Xing
2024-10-12  4:06 ` [PATCH net-next v2 08/12] net-timestamp: introduce TS_ACK_OPT_CB to generate tcp acked timestamp Jason Xing
2024-10-12  4:06 ` [PATCH net-next v2 09/12] net-timestamp: add tx OPT_ID_TCP support for bpf case Jason Xing
2024-10-15  1:38   ` Willem de Bruijn
2024-10-15  2:25     ` Jason Xing
2024-10-15  2:38       ` Willem de Bruijn
2024-10-15  2:59         ` Jason Xing
2024-10-15  8:40   ` kernel test robot
2024-10-15  9:36     ` Jason Xing
2024-10-12  4:06 ` [PATCH net-next v2 10/12] net-timestamp: make bpf for tx timestamp work Jason Xing
2024-10-12  4:06 ` [PATCH net-next v2 11/12] net-timestamp: add bpf framework for rx timestamps Jason Xing
2024-10-15  1:44   ` Willem de Bruijn
2024-10-15  2:18     ` Jason Xing
2024-10-12  4:06 ` [PATCH net-next v2 12/12] net-timestamp: add bpf support for rx software/hardware timestamp Jason Xing
2024-10-12 17:48 ` [PATCH net-next v2 00/12] net-timestamp: bpf extension to equip applications transparently Willem de Bruijn
2024-10-13  3:28   ` Jason Xing
2024-10-13  3:43     ` Jason Xing
2024-10-13  6:05       ` Jason Xing
2024-10-15  1:28     ` Willem de Bruijn
2024-10-15  2:52       ` Jason Xing
2024-10-15  2:59         ` Willem de Bruijn
2024-10-15  3:02           ` Jason Xing

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=67166a0997028_42f03294e7@willemb.c.googlers.com.notmuch \
    --to=willemdebruijn.kernel@gmail.com \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=davem@davemloft.net \
    --cc=dsahern@kernel.org \
    --cc=eddyz87@gmail.com \
    --cc=edumazet@google.com \
    --cc=haoluo@google.com \
    --cc=john.fastabend@gmail.com \
    --cc=jolsa@kernel.org \
    --cc=kerneljasonxing@gmail.com \
    --cc=kernelxing@tencent.com \
    --cc=kpsingh@kernel.org \
    --cc=kuba@kernel.org \
    --cc=martin.lau@linux.dev \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=sdf@fomichev.me \
    --cc=song@kernel.org \
    --cc=willemb@google.com \
    --cc=yonghong.song@linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox