]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
selftests: Add napi threaded busy poll test in `busy_poller`
authorSamiullah Khawaja <skhawaja@google.com>
Tue, 28 Oct 2025 20:30:06 +0000 (20:30 +0000)
committerJakub Kicinski <kuba@kernel.org>
Tue, 4 Nov 2025 02:11:40 +0000 (18:11 -0800)
Add testcase to run busy poll test with threaded napi busy poll enabled.

Signed-off-by: Samiullah Khawaja <skhawaja@google.com>
Reviewed-by: Willem de Bruijn <willemb@google.com>
Acked-by: Martin Karsten <mkarsten@uwaterloo.ca>
Tested-by: Martin Karsten <mkarsten@uwaterloo.ca>
Link: https://patch.msgid.link/20251028203007.575686-3-skhawaja@google.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
tools/testing/selftests/net/busy_poll_test.sh
tools/testing/selftests/net/busy_poller.c

index 7d2d40812074fb248641a14fa336cb2ef340f896..5ec1c85c1623e58b2a00bdff741ab10300132980 100755 (executable)
@@ -27,6 +27,8 @@ NAPI_DEFER_HARD_IRQS=100
 GRO_FLUSH_TIMEOUT=50000
 SUSPEND_TIMEOUT=20000000
 
+NAPI_THREADED_MODE_BUSY_POLL=2
+
 setup_ns()
 {
        set -e
@@ -62,6 +64,9 @@ cleanup_ns()
 test_busypoll()
 {
        suspend_value=${1:-0}
+       napi_threaded_value=${2:-0}
+       prefer_busy_poll_value=${3:-$PREFER_BUSY_POLL}
+
        tmp_file=$(mktemp)
        out_file=$(mktemp)
 
@@ -73,10 +78,11 @@ test_busypoll()
                                             -b${SERVER_IP}        \
                                             -m${MAX_EVENTS}       \
                                             -u${BUSY_POLL_USECS}  \
-                                            -P${PREFER_BUSY_POLL} \
+                                            -P${prefer_busy_poll_value} \
                                             -g${BUSY_POLL_BUDGET} \
                                             -i${NSIM_SV_IFIDX}    \
                                             -s${suspend_value}    \
+                                            -t${napi_threaded_value} \
                                             -o${out_file}&
 
        wait_local_port_listen nssv ${SERVER_PORT} tcp
@@ -109,6 +115,15 @@ test_busypoll_with_suspend()
        return $?
 }
 
+test_busypoll_with_napi_threaded()
+{
+       # Only enable napi threaded poll. Set suspend timeout and prefer busy
+       # poll to 0.
+       test_busypoll 0 ${NAPI_THREADED_MODE_BUSY_POLL} 0
+
+       return $?
+}
+
 ###
 ### Code start
 ###
@@ -154,6 +169,13 @@ if [ $? -ne 0 ]; then
        exit 1
 fi
 
+test_busypoll_with_napi_threaded
+if [ $? -ne 0 ]; then
+       echo "test_busypoll_with_napi_threaded failed"
+       cleanup_ns
+       exit 1
+fi
+
 echo "$NSIM_SV_FD:$NSIM_SV_IFIDX" > $NSIM_DEV_SYS_UNLINK
 
 echo $NSIM_CL_ID > $NSIM_DEV_SYS_DEL
index 04c7ff577bb8925b4c19b208b0ddc3e41d75cd30..3a81f9c947950f02adb0044bab3bd7eff110d183 100644 (file)
@@ -65,15 +65,16 @@ static uint32_t cfg_busy_poll_usecs;
 static uint16_t cfg_busy_poll_budget;
 static uint8_t cfg_prefer_busy_poll;
 
-/* IRQ params */
+/* NAPI params */
 static uint32_t cfg_defer_hard_irqs;
 static uint64_t cfg_gro_flush_timeout;
 static uint64_t cfg_irq_suspend_timeout;
+static enum netdev_napi_threaded cfg_napi_threaded_poll = NETDEV_NAPI_THREADED_DISABLED;
 
 static void usage(const char *filepath)
 {
        error(1, 0,
-             "Usage: %s -p<port> -b<addr> -m<max_events> -u<busy_poll_usecs> -P<prefer_busy_poll> -g<busy_poll_budget> -o<outfile> -d<defer_hard_irqs> -r<gro_flush_timeout> -s<irq_suspend_timeout> -i<ifindex>",
+             "Usage: %s -p<port> -b<addr> -m<max_events> -u<busy_poll_usecs> -P<prefer_busy_poll> -g<busy_poll_budget> -o<outfile> -d<defer_hard_irqs> -r<gro_flush_timeout> -s<irq_suspend_timeout> -t<napi_threaded_poll> -i<ifindex>",
              filepath);
 }
 
@@ -86,7 +87,7 @@ static void parse_opts(int argc, char **argv)
        if (argc <= 1)
                usage(argv[0]);
 
-       while ((c = getopt(argc, argv, "p:m:b:u:P:g:o:d:r:s:i:")) != -1) {
+       while ((c = getopt(argc, argv, "p:m:b:u:P:g:o:d:r:s:i:t:")) != -1) {
                /* most options take integer values, except o and b, so reduce
                 * code duplication a bit for the common case by calling
                 * strtoull here and leave bounds checking and casting per
@@ -168,6 +169,12 @@ static void parse_opts(int argc, char **argv)
 
                        cfg_ifindex = (int)tmp;
                        break;
+               case 't':
+                       if (tmp > 2)
+                               error(1, ERANGE, "napi threaded poll value must be 0-2");
+
+                       cfg_napi_threaded_poll = (enum netdev_napi_threaded)tmp;
+                       break;
                }
        }
 
@@ -247,6 +254,9 @@ static void setup_queue(void)
        netdev_napi_set_req_set_irq_suspend_timeout(set_req,
                                                    cfg_irq_suspend_timeout);
 
+       if (cfg_napi_threaded_poll)
+               netdev_napi_set_req_set_threaded(set_req, cfg_napi_threaded_poll);
+
        if (netdev_napi_set(ys, set_req))
                error(1, 0, "can't set NAPI params: %s\n", yerr.msg);