Skip to content

Commit 8121e78

Browse files
elvinongblAlexei Starovoitov
authored andcommitted
samples/bpf: xdpsock: Add time-out for cleaning Tx
When user sets tx-pkt-count and in case where there are invalid Tx frame, the complete_tx_only_all() process polls indefinitely. So, this patch adds a time-out mechanism into the process so that the application can terminate automatically after it retries 3*polling interval duration. v1->v2: Thanks to Jesper's and Song Liu's suggestion. - clean-up git message to remove polling log - make the Tx time-out retries configurable with 1s granularity Signed-off-by: Ong Boon Leong <boon.leong.ong@intel.com> Signed-off-by: Alexei Starovoitov <ast@kernel.org> Link: https://lore.kernel.org/bpf/20211230035447.523177-7-boon.leong.ong@intel.com
1 parent fa24d0b commit 8121e78

1 file changed

Lines changed: 9 additions & 2 deletions

File tree

‎samples/bpf/xdpsock_user.c‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ static u32 irq_no;
113113
static int irqs_at_init = -1;
114114
static int opt_poll;
115115
static int opt_interval = 1;
116+
static int opt_retries = 3;
116117
static u32 opt_xdp_bind_flags = XDP_USE_NEED_WAKEUP;
117118
static u32 opt_umem_flags;
118119
static int opt_unaligned_chunks;
@@ -1028,6 +1029,7 @@ static struct option long_options[] = {
10281029
{"xdp-skb", no_argument, 0, 'S'},
10291030
{"xdp-native", no_argument, 0, 'N'},
10301031
{"interval", required_argument, 0, 'n'},
1032+
{"retries", required_argument, 0, 'O'},
10311033
{"zero-copy", no_argument, 0, 'z'},
10321034
{"copy", no_argument, 0, 'c'},
10331035
{"frame-size", required_argument, 0, 'f'},
@@ -1072,6 +1074,7 @@ static void usage(const char *prog)
10721074
" -S, --xdp-skb=n Use XDP skb-mod\n"
10731075
" -N, --xdp-native=n Enforce XDP native mode\n"
10741076
" -n, --interval=n Specify statistics update interval (default 1 sec).\n"
1077+
" -O, --retries=n Specify time-out retries (1s interval) attempt (default 3).\n"
10751078
" -z, --zero-copy Force zero-copy mode.\n"
10761079
" -c, --copy Force copy mode.\n"
10771080
" -m, --no-need-wakeup Turn off use of driver need wakeup flag.\n"
@@ -1122,7 +1125,7 @@ static void parse_command_line(int argc, char **argv)
11221125

11231126
for (;;) {
11241127
c = getopt_long(argc, argv,
1125-
"Frtli:q:pSNn:w:czf:muMd:b:C:s:P:VJ:K:G:H:T:W:U:xQaI:BR",
1128+
"Frtli:q:pSNn:w:O:czf:muMd:b:C:s:P:VJ:K:G:H:T:W:U:xQaI:BR",
11261129
long_options, &option_index);
11271130
if (c == -1)
11281131
break;
@@ -1164,6 +1167,9 @@ static void parse_command_line(int argc, char **argv)
11641167
opt_clock = CLOCK_MONOTONIC;
11651168
}
11661169
break;
1170+
case 'O':
1171+
opt_retries = atoi(optarg);
1172+
break;
11671173
case 'z':
11681174
opt_xdp_bind_flags |= XDP_ZEROCOPY;
11691175
break;
@@ -1509,7 +1515,8 @@ static void complete_tx_only_all(void)
15091515
pending = !!xsks[i]->outstanding_tx;
15101516
}
15111517
}
1512-
} while (pending);
1518+
sleep(1);
1519+
} while (pending && opt_retries-- > 0);
15131520
}
15141521

15151522
static void tx_only_all(void)

0 commit comments

Comments
 (0)