Commit 8121e789 authored by Ong Boon Leong's avatar Ong Boon Leong Committed by Alexei Starovoitov

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: default avatarOng Boon Leong <boon.leong.ong@intel.com>
Signed-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
Link: https://lore.kernel.org/bpf/20211230035447.523177-7-boon.leong.ong@intel.com
parent fa24d0b1
...@@ -113,6 +113,7 @@ static u32 irq_no; ...@@ -113,6 +113,7 @@ static u32 irq_no;
static int irqs_at_init = -1; static int irqs_at_init = -1;
static int opt_poll; static int opt_poll;
static int opt_interval = 1; static int opt_interval = 1;
static int opt_retries = 3;
static u32 opt_xdp_bind_flags = XDP_USE_NEED_WAKEUP; static u32 opt_xdp_bind_flags = XDP_USE_NEED_WAKEUP;
static u32 opt_umem_flags; static u32 opt_umem_flags;
static int opt_unaligned_chunks; static int opt_unaligned_chunks;
...@@ -1028,6 +1029,7 @@ static struct option long_options[] = { ...@@ -1028,6 +1029,7 @@ static struct option long_options[] = {
{"xdp-skb", no_argument, 0, 'S'}, {"xdp-skb", no_argument, 0, 'S'},
{"xdp-native", no_argument, 0, 'N'}, {"xdp-native", no_argument, 0, 'N'},
{"interval", required_argument, 0, 'n'}, {"interval", required_argument, 0, 'n'},
{"retries", required_argument, 0, 'O'},
{"zero-copy", no_argument, 0, 'z'}, {"zero-copy", no_argument, 0, 'z'},
{"copy", no_argument, 0, 'c'}, {"copy", no_argument, 0, 'c'},
{"frame-size", required_argument, 0, 'f'}, {"frame-size", required_argument, 0, 'f'},
...@@ -1072,6 +1074,7 @@ static void usage(const char *prog) ...@@ -1072,6 +1074,7 @@ static void usage(const char *prog)
" -S, --xdp-skb=n Use XDP skb-mod\n" " -S, --xdp-skb=n Use XDP skb-mod\n"
" -N, --xdp-native=n Enforce XDP native mode\n" " -N, --xdp-native=n Enforce XDP native mode\n"
" -n, --interval=n Specify statistics update interval (default 1 sec).\n" " -n, --interval=n Specify statistics update interval (default 1 sec).\n"
" -O, --retries=n Specify time-out retries (1s interval) attempt (default 3).\n"
" -z, --zero-copy Force zero-copy mode.\n" " -z, --zero-copy Force zero-copy mode.\n"
" -c, --copy Force copy mode.\n" " -c, --copy Force copy mode.\n"
" -m, --no-need-wakeup Turn off use of driver need wakeup flag.\n" " -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) ...@@ -1122,7 +1125,7 @@ static void parse_command_line(int argc, char **argv)
for (;;) { for (;;) {
c = getopt_long(argc, argv, c = getopt_long(argc, argv,
"Frtli:q:pSNn:w:czf:muMd:b:C:s:P:VJ:K:G:H:T:W:U:xQaI:BR", "Frtli:q:pSNn:w:O:czf:muMd:b:C:s:P:VJ:K:G:H:T:W:U:xQaI:BR",
long_options, &option_index); long_options, &option_index);
if (c == -1) if (c == -1)
break; break;
...@@ -1164,6 +1167,9 @@ static void parse_command_line(int argc, char **argv) ...@@ -1164,6 +1167,9 @@ static void parse_command_line(int argc, char **argv)
opt_clock = CLOCK_MONOTONIC; opt_clock = CLOCK_MONOTONIC;
} }
break; break;
case 'O':
opt_retries = atoi(optarg);
break;
case 'z': case 'z':
opt_xdp_bind_flags |= XDP_ZEROCOPY; opt_xdp_bind_flags |= XDP_ZEROCOPY;
break; break;
...@@ -1509,7 +1515,8 @@ static void complete_tx_only_all(void) ...@@ -1509,7 +1515,8 @@ static void complete_tx_only_all(void)
pending = !!xsks[i]->outstanding_tx; pending = !!xsks[i]->outstanding_tx;
} }
} }
} while (pending); sleep(1);
} while (pending && opt_retries-- > 0);
} }
static void tx_only_all(void) static void tx_only_all(void)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment