@@ -95,6 +95,7 @@ static int opt_timeout = 1000;
9595static bool opt_need_wakeup = true;
9696static u32 opt_num_xsks = 1 ;
9797static u32 prog_id ;
98+ static bool opt_busy_poll ;
9899
99100struct xsk_ring_stats {
100101 unsigned long rx_npkts ;
@@ -911,6 +912,7 @@ static struct option long_options[] = {
911912 {"quiet" , no_argument , 0 , 'Q' },
912913 {"app-stats" , no_argument , 0 , 'a' },
913914 {"irq-string" , no_argument , 0 , 'I' },
915+ {"busy-poll" , no_argument , 0 , 'B' },
914916 {0 , 0 , 0 , 0 }
915917};
916918
@@ -949,6 +951,7 @@ static void usage(const char *prog)
949951 " -Q, --quiet Do not display any stats.\n"
950952 " -a, --app-stats Display application (syscall) statistics.\n"
951953 " -I, --irq-string Display driver interrupt statistics for interface associated with irq-string.\n"
954+ " -B, --busy-poll Busy poll.\n"
952955 "\n" ;
953956 fprintf (stderr , str , prog , XSK_UMEM__DEFAULT_FRAME_SIZE ,
954957 opt_batch_size , MIN_PKT_SIZE , MIN_PKT_SIZE ,
@@ -964,7 +967,7 @@ static void parse_command_line(int argc, char **argv)
964967 opterr = 0 ;
965968
966969 for (;;) {
967- c = getopt_long (argc , argv , "Frtli:q:pSNn:czf:muMd:b:C:s:P:xQaI:" ,
970+ c = getopt_long (argc , argv , "Frtli:q:pSNn:czf:muMd:b:C:s:P:xQaI:B " ,
968971 long_options , & option_index );
969972 if (c == -1 )
970973 break ;
@@ -1062,7 +1065,9 @@ static void parse_command_line(int argc, char **argv)
10621065 fprintf (stderr , "ERROR: Failed to get irqs for %s\n" , opt_irq_str );
10631066 usage (basename (argv [0 ]));
10641067 }
1065-
1068+ break ;
1069+ case 'B' :
1070+ opt_busy_poll = 1 ;
10661071 break ;
10671072 default :
10681073 usage (basename (argv [0 ]));
@@ -1131,7 +1136,7 @@ static inline void complete_tx_l2fwd(struct xsk_socket_info *xsk)
11311136 while (ret != rcvd ) {
11321137 if (ret < 0 )
11331138 exit_with_error (- ret );
1134- if (xsk_ring_prod__needs_wakeup (& umem -> fq )) {
1139+ if (opt_busy_poll || xsk_ring_prod__needs_wakeup (& umem -> fq )) {
11351140 xsk -> app_stats .fill_fail_polls ++ ;
11361141 recvfrom (xsk_socket__fd (xsk -> xsk ), NULL , 0 , MSG_DONTWAIT , NULL ,
11371142 NULL );
@@ -1178,7 +1183,7 @@ static void rx_drop(struct xsk_socket_info *xsk)
11781183
11791184 rcvd = xsk_ring_cons__peek (& xsk -> rx , opt_batch_size , & idx_rx );
11801185 if (!rcvd ) {
1181- if (xsk_ring_prod__needs_wakeup (& xsk -> umem -> fq )) {
1186+ if (opt_busy_poll || xsk_ring_prod__needs_wakeup (& xsk -> umem -> fq )) {
11821187 xsk -> app_stats .rx_empty_polls ++ ;
11831188 recvfrom (xsk_socket__fd (xsk -> xsk ), NULL , 0 , MSG_DONTWAIT , NULL , NULL );
11841189 }
@@ -1189,7 +1194,7 @@ static void rx_drop(struct xsk_socket_info *xsk)
11891194 while (ret != rcvd ) {
11901195 if (ret < 0 )
11911196 exit_with_error (- ret );
1192- if (xsk_ring_prod__needs_wakeup (& xsk -> umem -> fq )) {
1197+ if (opt_busy_poll || xsk_ring_prod__needs_wakeup (& xsk -> umem -> fq )) {
11931198 xsk -> app_stats .fill_fail_polls ++ ;
11941199 recvfrom (xsk_socket__fd (xsk -> xsk ), NULL , 0 , MSG_DONTWAIT , NULL , NULL );
11951200 }
@@ -1341,7 +1346,7 @@ static void l2fwd(struct xsk_socket_info *xsk)
13411346
13421347 rcvd = xsk_ring_cons__peek (& xsk -> rx , opt_batch_size , & idx_rx );
13431348 if (!rcvd ) {
1344- if (xsk_ring_prod__needs_wakeup (& xsk -> umem -> fq )) {
1349+ if (opt_busy_poll || xsk_ring_prod__needs_wakeup (& xsk -> umem -> fq )) {
13451350 xsk -> app_stats .rx_empty_polls ++ ;
13461351 recvfrom (xsk_socket__fd (xsk -> xsk ), NULL , 0 , MSG_DONTWAIT , NULL , NULL );
13471352 }
@@ -1354,7 +1359,7 @@ static void l2fwd(struct xsk_socket_info *xsk)
13541359 if (ret < 0 )
13551360 exit_with_error (- ret );
13561361 complete_tx_l2fwd (xsk );
1357- if (xsk_ring_prod__needs_wakeup (& xsk -> tx )) {
1362+ if (opt_busy_poll || xsk_ring_prod__needs_wakeup (& xsk -> tx )) {
13581363 xsk -> app_stats .tx_wakeup_sendtos ++ ;
13591364 kick_tx (xsk );
13601365 }
@@ -1459,6 +1464,24 @@ static void enter_xsks_into_map(struct bpf_object *obj)
14591464 }
14601465}
14611466
1467+ static void apply_setsockopt (struct xsk_socket_info * xsk )
1468+ {
1469+ int sock_opt ;
1470+
1471+ if (!opt_busy_poll )
1472+ return ;
1473+
1474+ sock_opt = 1 ;
1475+ if (setsockopt (xsk_socket__fd (xsk -> xsk ), SOL_SOCKET , SO_PREFER_BUSY_POLL ,
1476+ (void * )& sock_opt , sizeof (sock_opt )) < 0 )
1477+ exit_with_error (errno );
1478+
1479+ sock_opt = 20 ;
1480+ if (setsockopt (xsk_socket__fd (xsk -> xsk ), SOL_SOCKET , SO_BUSY_POLL ,
1481+ (void * )& sock_opt , sizeof (sock_opt )) < 0 )
1482+ exit_with_error (errno );
1483+ }
1484+
14621485int main (int argc , char * * argv )
14631486{
14641487 struct rlimit r = {RLIM_INFINITY , RLIM_INFINITY };
@@ -1500,6 +1523,9 @@ int main(int argc, char **argv)
15001523 for (i = 0 ; i < opt_num_xsks ; i ++ )
15011524 xsks [num_socks ++ ] = xsk_configure_socket (umem , rx , tx );
15021525
1526+ for (i = 0 ; i < opt_num_xsks ; i ++ )
1527+ apply_setsockopt (xsks [i ]);
1528+
15031529 if (opt_bench == BENCH_TXONLY ) {
15041530 gen_eth_hdr_data ();
15051531
0 commit comments