Re: [PATCH net-next v7] net: af_packet: Use hrtimer to do the retire operation
From: Willem de Bruijn
Date: Tue Aug 26 2025 - 12:10:43 EST
Xin Zhao wrote:
> On Tue, 2025-08-25 at 20:54 +0800, Willem wrote:
>
> > > I understand that the additional in_scheduled variable is meant to prevent
> > > multiple calls to hrtimer_start. However, based on the current logic
> > > implementation, the only scenario that would cancel the hrtimer is after calling
> > > prb_shutdown_retire_blk_timer. Therefore, once we have called hrtimer_start in
> > > prb_setup_retire_blk_timer, we don't need to worry about the hrtimer stopping,
> > > and we don't need to execute hrtimer_start again or check if the hrtimer is in
> > > an active state. We can simply update the timeout in the callback.
> >
> > The hrtimer is also canceled when the callback returns
> > HRTIMER_NORESTART.
>
> In prb_retire_rx_blk_timer_expired function, the only way to return HRTIMER_NORESTART
> is that the pkc->delete_blk_timer is NOT 0.
> The delete_blk_timer is only set to 1 in prb_shutdown_retire_blk_timer which is called
> by packet_set_ring.
> In my understanding, once packet_set_ring is called and prb_shutdown_retire_blk_timer
> is executed, the only way to make this af_packet work again is to call packet_set_ring
> again to execute prb_setup_retire_blk_timer. At that point, hrtimer_start will be
> called again. Therefore, I feel that there is no need to perform the check in
> _prb_refresh_rx_retire_blk_timer. Only let prb_setup_retire_blk_timer to hrtimer_start,
> is that right?
Good point.
Let's clean up the control flow a bit more to make that more clear.
For one, no need for delete_blk_timer. hrtimer_cancel will cancel the
timer if it is queued. And the callback spends the vast majority of
its time after the check. So the odds of delete_blk_timer having any
effect is minimal.
And if the callback just restarts itself unconditionally, no need for
the special refresh_timer and out labels. Or the somewhat complex
calling flow between _prb_refresh_rx_retire_blk_timer, prb_open_block
and prb_retire_rx_blk_timer_expired. They all just schedule the next
timer the fixed computed jiffies/ms from now. The only special case
is when prb_open_block is called from tpacket_rcv. That would set
the timeout further into the future than the already queued timer.
I don't think that an earlier timeout is problematic. No need to
add complexity to avoid that.