BPF List
 help / color / mirror / Atom feed
From: Martin KaFai Lau <martin.lau@linux.dev>
To: Stanislav Fomichev <sdf@google.com>
Cc: ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org,
	song@kernel.org, yhs@fb.com, john.fastabend@gmail.com,
	kpsingh@kernel.org, haoluo@google.com, jolsa@kernel.org,
	Jesper Dangaard Brouer <jbrouer@redhat.com>,
	bpf@vger.kernel.org
Subject: Re: [PATCH bpf-next] selftests/bpf: Properly enable hwtstamp in xdp_hw_metadata
Date: Wed, 25 Jan 2023 17:12:08 -0800	[thread overview]
Message-ID: <c2c7f7c7-4c36-c4de-332a-22531a53b7b6@linux.dev> (raw)
In-Reply-To: <20230125223205.3933482-1-sdf@google.com>

On 1/25/23 2:32 PM, Stanislav Fomichev wrote:
> The existing timestamping_enable() is a no-op because it applies
> to the socket-related path that we are not verifying here
> anymore. (but still leaving the code around hoping we can
> have xdp->skb path verified here as well)
> 
>    poll: 1 (0)
>    xsk_ring_cons__peek: 1
>    0xf64788: rx_desc[0]->addr=100000000008000 addr=8100 comp_addr=8000
>    rx_hash: 3697961069
>    rx_timestamp:  1674657672142214773 (sec:1674657672.1422)
>    XDP RX-time:   1674657709561774876 (sec:1674657709.5618) delta sec:37.4196
>    AF_XDP time:   1674657709561871034 (sec:1674657709.5619) delta
> sec:0.0001 (96.158 usec)
>    0xf64788: complete idx=8 addr=8000
> 
> Also, maybe something to archive here, see [0] for Jesper's note
> about NIC vs host clock delta.
> 
> 0: https://lore.kernel.org/bpf/f3a116dc-1b14-3432-ad20-a36179ef0608@redhat.com/
> 
> Fixes: 297a3f124155 ("selftests/bpf: Simple program to dump XDP RX metadata")
> Reported-by: Jesper Dangaard Brouer <jbrouer@redhat.com>
> Tested-by: Jesper Dangaard Brouer <jbrouer@redhat.com>
> Signed-off-by: Stanislav Fomichev <sdf@google.com>
> ---
>   tools/testing/selftests/bpf/xdp_hw_metadata.c | 28 ++++++++++++++++++-
>   1 file changed, 27 insertions(+), 1 deletion(-)
> 
> diff --git a/tools/testing/selftests/bpf/xdp_hw_metadata.c b/tools/testing/selftests/bpf/xdp_hw_metadata.c
> index 0008f0f239e8..dc899c53db5e 100644
> --- a/tools/testing/selftests/bpf/xdp_hw_metadata.c
> +++ b/tools/testing/selftests/bpf/xdp_hw_metadata.c
> @@ -24,6 +24,7 @@
>   #include <linux/net_tstamp.h>
>   #include <linux/udp.h>
>   #include <linux/sockios.h>
> +#include <linux/net_tstamp.h>
>   #include <sys/mman.h>
>   #include <net/if.h>
>   #include <poll.h>
> @@ -278,13 +279,36 @@ static int rxq_num(const char *ifname)
>   
>   	ret = ioctl(fd, SIOCETHTOOL, &ifr);
>   	if (ret < 0)
> -		error(-1, errno, "socket");
> +		error(-1, errno, "ioctl(SIOCETHTOOL)");
>   
>   	close(fd);
>   
>   	return ch.rx_count + ch.combined_count;
>   }
>   
> +static void hwtstamp_enable(const char *ifname)
> +{
> +	struct hwtstamp_config cfg = {
> +		.rx_filter = HWTSTAMP_FILTER_ALL,
> +	};
> +
> +	struct ifreq ifr = {
> +		.ifr_data = (void *)&cfg,
> +	};
> +	strcpy(ifr.ifr_name, ifname);
> +	int fd, ret;
> +
> +	fd = socket(AF_UNIX, SOCK_DGRAM, 0);
> +	if (fd < 0)
> +		error(-1, errno, "socket");
> +
> +	ret = ioctl(fd, SIOCSHWTSTAMP, &ifr);
> +	if (ret < 0)
> +		error(-1, errno, "ioctl(SIOCSHWTSTAMP)");
> +
> +	close(fd);
> +}
> +
>   static void cleanup(void)
>   {
>   	LIBBPF_OPTS(bpf_xdp_attach_opts, opts);
> @@ -341,6 +365,8 @@ int main(int argc, char *argv[])
>   
>   	printf("rxq: %d\n", rxq);
>   
> +	hwtstamp_enable(ifname);

Will it to restore to the earlier setting when the process exits?


  reply	other threads:[~2023-01-26  1:12 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-01-25 22:32 [PATCH bpf-next] selftests/bpf: Properly enable hwtstamp in xdp_hw_metadata Stanislav Fomichev
2023-01-26  1:12 ` Martin KaFai Lau [this message]
2023-01-26 17:31   ` Stanislav Fomichev
2023-01-27  9:34 ` Jesper Dangaard Brouer

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=c2c7f7c7-4c36-c4de-332a-22531a53b7b6@linux.dev \
    --to=martin.lau@linux.dev \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=haoluo@google.com \
    --cc=jbrouer@redhat.com \
    --cc=john.fastabend@gmail.com \
    --cc=jolsa@kernel.org \
    --cc=kpsingh@kernel.org \
    --cc=sdf@google.com \
    --cc=song@kernel.org \
    --cc=yhs@fb.com \
    /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