Re: [PATCH bpf-next] bpf: Allow setting SO_TIMESTAMPING* with bpf_setsockopt()

From: Martin KaFai Lau
Date: Wed Jan 17 2024 - 02:34:05 EST


On 1/16/24 7:17 AM, Willem de Bruijn wrote:
Jörn-Thorben Hinz wrote:
A BPF application, e.g., a TCP congestion control, might benefit from or
even require precise (=hardware) packet timestamps. These timestamps are
already available through __sk_buff.hwtstamp and
bpf_sock_ops.skb_hwtstamp, but could not be requested: BPF programs were
not allowed to set SO_TIMESTAMPING* on sockets.

This patch only uses the SOF_TIMESTAMPING_RX_HARDWARE in the selftest. How about others? e.g. the SOF_TIMESTAMPING_TX_* that will affect the sk->sk_error_queue which seems not good. If rx tstamp is useful, tx tstamp should be useful also?


Enable BPF programs to actively request the generation of timestamps
from a stream socket. The also required ioctl(SIOCSHWTSTAMP) on the
network device must still be done separately, in user space.

hmm... so both ioctl(SIOCSHWTSTAMP) of the netdevice and the SOF_TIMESTAMPING_RX_HARDWARE of the sk must be done?

I likely miss something. When skb is created in the driver rx path, the sk is not known yet though. How the SOF_TIMESTAMPING_RX_HARDWARE of the sk affects the skb_shinfo(skb)->hwtstamps?