Re: [PATCH] net: af_packet: add af_packet hrtimer mode
From: Ferenc Fejes
Date: Fri Aug 08 2025 - 07:40:02 EST
Dear Xin,
On Fri, 2025-08-08 at 12:33 +0800, Xin Zhao wrote:
> On Wed, 2025-08-06 at 15:25 +0800, Ferenc wrote:
>
> > Do you have performance numbers? It would be nice to see the test
> > environment,
> > measurements carried out and some latency/jitter numbers.
>
> Dear Ferenc,
>
> We test it on 6.1.134 rt-linux version, we set 2ms as the retire timeout, the
> following test result describe the packet details including cur_ts_us(time
> when
> the sample code handle the packet) and cur_pk_ts_us(time when the packet send)
> and delay(time unit is us, the gap between cur_ts_us and cur_pk_ts_us).
Thanks for the additional details. Out of curiosity, how do your setup looks
like? The packet received from the LIDAR device are
A) processed on the system
B) processed on the system and transmitted elsewhere
C) only transmitted elsewhere
>From the details provided so far I'm unable to understand the setup you have.
Both 2ms and 8ms looks pretty high for me. For example on a loaded system, I
have seen ~200-300us latencies with AF_PACKET software switch P95 with soma rare
outliers over 1ms. But that system might be faster than a embedded device you
have.
> Test result before change to hrtimer:
> --------num_pkts:54--------
> pack_size_:902, atx_udp_seq:86152515, cur_ts_us:[1749707679501254],
> cur_pkg_ts_us:[1749707679492443], delay:8811
> pack_size_:902, atx_udp_seq:86152516, cur_ts_us:[1749707679501260],
> cur_pkg_ts_us:[1749707679492590], delay:8670
> pack_size_:902, atx_udp_seq:86152517, cur_ts_us:[1749707679501266],
> cur_pkg_ts_us:[1749707679492737], delay:8529
> pack_size_:902, atx_udp_seq:86152518, cur_ts_us:[1749707679501274],
> cur_pkg_ts_us:[1749707679492884], delay:8391
> ...
> Test result after change to hrtimer:
> --------num_pkts:14--------
> pack_size_:902, atx_udp_seq:42679600, cur_ts_us:[1750220805104634],
> cur_pkg_ts_us:[1750220805101776], delay:2858
> pack_size_:902, atx_udp_seq:42679601, cur_ts_us:[1750220805104635],
> cur_pkg_ts_us:[1750220805101923], delay:2712
> pack_size_:902, atx_udp_seq:42679602, cur_ts_us:[1750220805104636],
> cur_pkg_ts_us:[1750220805102074], delay:2562
> pack_size_:902, atx_udp_seq:42679603, cur_ts_us:[1750220805104638],
> cur_pkg_ts_us:[1750220805102223], delay:2415
These timestamps calculated like this for example?:
sk = socket(AF_PACKET, ...)
cur_ts_us = now();
send(pkt, sk)
cur_pkg_ts_us = now()
> ...
> In our system, we care about the delay value, cpu usage and context switches.
> Use af_packet the cpu usage of the lidar process change from about 16.91% to
> 12.92%, the context switches change from about 900+ per second to 400+ per
> second. The benefits of using AF_PACKET are significant enough that we need
> to adopt it. After using hrtimer instead of timer, the impact of the delay
> has also been controlled, which is what we hoped for.
>
> Thanks
> Xin Zhao
>
Thanks,
Ferenc