Skip to content

Commit 28d2420

Browse files
jackzxcui1989kuba-moo
authored andcommitted
net: af_packet: remove last_kactive_blk_num field
kactive_blk_num (K) is only incremented on block close. In timer callback prb_retire_rx_blk_timer_expired, except delete_blk_timer is true, last_kactive_blk_num (L) is set to match kactive_blk_num (K) in all cases. L is also set to match K in prb_open_block. The only case K not equal to L is when scheduled by tpacket_rcv and K is just incremented on block close but no new block could be opened, so that it does not call prb_open_block in prb_dispatch_next_block. This patch modifies the prb_retire_rx_blk_timer_expired function by simply removing the check for L == K. This patch just provides another checkpoint to thaw the might-be-frozen block in any case. It doesn't have any effect because __packet_lookup_frame_in_block() has the same logic and does it again without this patch when detecting the ring is frozen. The patch only advances checking the status of the ring. Suggested-by: Willem de Bruijn <[email protected]> Reviewed-by: Willem de Bruijn <[email protected]> Reviewed-by: Jason Xing <[email protected]> Link: https://lore.kernel.org/all/[email protected]/ Signed-off-by: Xin Zhao <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
1 parent e663ad6 commit 28d2420

File tree

2 files changed

+28
-38
lines changed

2 files changed

+28
-38
lines changed

net/packet/af_packet.c

Lines changed: 28 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -669,7 +669,6 @@ static void init_prb_bdqc(struct packet_sock *po,
669669
p1->knum_blocks = req_u->req3.tp_block_nr;
670670
p1->hdrlen = po->tp_hdrlen;
671671
p1->version = po->tp_version;
672-
p1->last_kactive_blk_num = 0;
673672
po->stats.stats3.tp_freeze_q_cnt = 0;
674673
if (req_u->req3.tp_retire_blk_tov)
675674
p1->retire_blk_tov = req_u->req3.tp_retire_blk_tov;
@@ -693,7 +692,6 @@ static void _prb_refresh_rx_retire_blk_timer(struct tpacket_kbdq_core *pkc)
693692
{
694693
mod_timer(&pkc->retire_blk_timer,
695694
jiffies + pkc->tov_in_jiffies);
696-
pkc->last_kactive_blk_num = pkc->kactive_blk_num;
697695
}
698696

699697
/*
@@ -750,38 +748,36 @@ static void prb_retire_rx_blk_timer_expired(struct timer_list *t)
750748
write_unlock(&pkc->blk_fill_in_prog_lock);
751749
}
752750

753-
if (pkc->last_kactive_blk_num == pkc->kactive_blk_num) {
754-
if (!frozen) {
755-
if (!BLOCK_NUM_PKTS(pbd)) {
756-
/* An empty block. Just refresh the timer. */
757-
goto refresh_timer;
758-
}
759-
prb_retire_current_block(pkc, po, TP_STATUS_BLK_TMO);
760-
if (!prb_dispatch_next_block(pkc, po))
761-
goto refresh_timer;
762-
else
763-
goto out;
751+
if (!frozen) {
752+
if (!BLOCK_NUM_PKTS(pbd)) {
753+
/* An empty block. Just refresh the timer. */
754+
goto refresh_timer;
755+
}
756+
prb_retire_current_block(pkc, po, TP_STATUS_BLK_TMO);
757+
if (!prb_dispatch_next_block(pkc, po))
758+
goto refresh_timer;
759+
else
760+
goto out;
761+
} else {
762+
/* Case 1. Queue was frozen because user-space was
763+
* lagging behind.
764+
*/
765+
if (prb_curr_blk_in_use(pbd)) {
766+
/*
767+
* Ok, user-space is still behind.
768+
* So just refresh the timer.
769+
*/
770+
goto refresh_timer;
764771
} else {
765-
/* Case 1. Queue was frozen because user-space was
766-
* lagging behind.
772+
/* Case 2. queue was frozen,user-space caught up,
773+
* now the link went idle && the timer fired.
774+
* We don't have a block to close.So we open this
775+
* block and restart the timer.
776+
* opening a block thaws the queue,restarts timer
777+
* Thawing/timer-refresh is a side effect.
767778
*/
768-
if (prb_curr_blk_in_use(pbd)) {
769-
/*
770-
* Ok, user-space is still behind.
771-
* So just refresh the timer.
772-
*/
773-
goto refresh_timer;
774-
} else {
775-
/* Case 2. queue was frozen,user-space caught up,
776-
* now the link went idle && the timer fired.
777-
* We don't have a block to close.So we open this
778-
* block and restart the timer.
779-
* opening a block thaws the queue,restarts timer
780-
* Thawing/timer-refresh is a side effect.
781-
*/
782-
prb_open_block(pkc, pbd);
783-
goto out;
784-
}
779+
prb_open_block(pkc, pbd);
780+
goto out;
785781
}
786782
}
787783

net/packet/internal.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,6 @@ struct tpacket_kbdq_core {
2424
unsigned short kactive_blk_num;
2525
unsigned short blk_sizeof_priv;
2626

27-
/* last_kactive_blk_num:
28-
* trick to see if user-space has caught up
29-
* in order to avoid refreshing timer when every single pkt arrives.
30-
*/
31-
unsigned short last_kactive_blk_num;
32-
3327
char *pkblk_start;
3428
char *pkblk_end;
3529
int kblk_size;

0 commit comments

Comments
 (0)