Received: from mail-pj1-f73.google.com (mail-pj1-f73.google.com [209.85.216.73]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7CB082C21C3 for ; Tue, 28 Oct 2025 20:30:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.73 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1761683415; cv=none; b=IH0AHwr3DkamA6esdNbb0tw7dNOOyj03dEvS+OBUCs/DgBj7t4YMGEKA/8u5dg3IFbBVIIxxV6i1ccCQ1HT36qexu9Sb61YskpJ/Yla6bsgI1KgDleikkgnSi6ZWP1upS+kcXu2ALxyjj5xsq050xNI3IUDXRUniP38MafvWWxc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1761683415; c=relaxed/simple; bh=P2oIOr8GX6sqSANmbPHywqeRaxch6Ps8a7GGCBre+PQ=; h=Date:Mime-Version:Message-ID:Subject:From:To:Cc:Content-Type; b=DVKjGnLVg945D/X8QG1g4vQKpJLRd2kLgn/C9/5Z2IrdNF60GDChLvZwzK2uH8a77+gfxH1qaAm3koOezqb+7rGfNNXDYxPsBN3pLJOhe8ZMLgkO1gj9Jjuajtib4rdFRBUCVDRXFI8g9uAuhenP7XNraeWzRactSHXwZnFhg8k= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--skhawaja.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=R4zagWp8; arc=none smtp.client-ip=209.85.216.73 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--skhawaja.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="R4zagWp8" Received: by mail-pj1-f73.google.com with SMTP id 98e67ed59e1d1-33d8970ae47so5905529a91.1 for ; Tue, 28 Oct 2025 13:30:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1761683409; x=1762288209; darn=vger.kernel.org; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=wSibEWFR6NL1uHIIQIW4gn6GVrzBwxcD5VH5r3nlZZk=; b=R4zagWp8+HNJ6ytVTPqW8Y9BsCAdxCSSov8nt0t5ijPf0VPquW9mQUhocZOB27f8TO dVDPhoflGN47x0EhLuvPusJY+B49BcPK1M6CSCb+YorhhzCdWfwwbxvSNuYqW5lLnzdv G5U9rvmLcSJupM5AycTSP75tERV9T8TJSmnZWzEWOT4rDFV8LP1WnDsr5tC+AmBRcULP MfChGLr7Zoo0/4yLqaK9Nc3UUK8vjxYDjQv6KPqRJCptRK0im0QrOzIFUYkUPZmzKp84 5DA0/mQSvf9LRbrrkKdO7RPutF+AjwDdebtI2hrl+1rQ6O9ER8qdqMKP5gOrVYrbP9DJ kzQA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1761683409; x=1762288209; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=wSibEWFR6NL1uHIIQIW4gn6GVrzBwxcD5VH5r3nlZZk=; b=GmYXnUGb4YF1bpNrzy394fpDLeu3PSVYmhFcz5KYbRVOZ3LMUPVlbwbtJisrkgVcaw 61LwazlDidQ0QjlygkQaXJ8zPFT7UzCm9EjdJH0VbHcJ0Pp0f7OPSFPq5/B0jKe88s6x kt+zPY7yz9C6zWn8rGwzVJdeaLPQFOYZKbjSU0VzXYP4d0EG5ZMEmIY+sAEsHxvoX9B5 nlcBaYDi4sZQhvQrdCOBJcjWeEONX2Nqcs9IaJ3jaMYp+zsKMqcVTjsTmV1UIswQIs/N +QQv/AILo6k7Aq/p5Dcj3NyM4jwh65HD8BNLw9be6AEqdJxzRY/yibp8N2bdI2xOFc/4 g5Zw== X-Forwarded-Encrypted: i=1; AJvYcCUBWYq6J5RoRmF7RvXXIIVfgy2qJJp1+c8a/8Zc8C99cTI+jH/KMhHSkZD1lvegNtFVZ7A4Cjk=@vger.kernel.org X-Gm-Message-State: AOJu0Ywj7MDE+e+3uF6xJwzkdqtFh6a+516FkI15N6zoh5Xif2msTxIP 7BZtAt6SEFLEKERk8NjRMkBugltyB6G+7HX2A14S0CK2K49cygBdmbXEU9KM9zV+ZxRmYvSdi/7 p4liw8/6FLhiUTA== X-Google-Smtp-Source: AGHT+IEHNX/YAFNQ7jWOfx5dJ8vSAG2HALCVrspOSiaHF+M5SHV8QBTJXF2XO0k4j+dDMFg6Ln0dlzcsYqMNCQ== X-Received: from pjot4.prod.google.com ([2002:a17:90a:9504:b0:33b:c327:1273]) (user=skhawaja job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90b:1c8d:b0:32e:a54a:be5d with SMTP id 98e67ed59e1d1-3403a25a759mr349080a91.2.1761683408708; Tue, 28 Oct 2025 13:30:08 -0700 (PDT) Date: Tue, 28 Oct 2025 20:30:04 +0000 Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 X-Mailer: git-send-email 2.51.1.851.g4ebd6896fd-goog Message-ID: <20251028203007.575686-1-skhawaja@google.com> Subject: [PATCH net-next v10 0/2] Add support to do threaded napi busy poll From: Samiullah Khawaja To: Jakub Kicinski , "David S . Miller " , Eric Dumazet , Paolo Abeni , almasrymina@google.com, willemb@google.com Cc: Joe Damato , mkarsten@uwaterloo.ca, netdev@vger.kernel.org, skhawaja@google.com Content-Type: text/plain; charset="UTF-8" Extend the already existing support of threaded napi poll to do continuous busy polling. This is used for doing continuous polling of napi to fetch descriptors from backing RX/TX queues for low latency applications. Allow enabling of threaded busypoll using netlink so this can be enabled on a set of dedicated napis for low latency applications. Once enabled user can fetch the PID of the kthread doing NAPI polling and set affinity, priority and scheduler for it depending on the low-latency requirements. Extend the netlink interface to allow enabling/disabling threaded busypolling at individual napi level. We use this for our AF_XDP based hard low-latency usecase with usecs level latency requirement. For our usecase we want low jitter and stable latency at P99. Following is an analysis and comparison of available (and compatible) busy poll interfaces for a low latency usecase with stable P99. This can be suitable for applications that want very low latency at the expense of cpu usage and efficiency. Already existing APIs (SO_BUSYPOLL and epoll) allow busy polling a NAPI backing a socket, but the missing piece is a mechanism to busy poll a NAPI instance in a dedicated thread while ignoring available events or packets, regardless of the userspace API. Most existing mechanisms are designed to work in a pattern where you poll until new packets or events are received, after which userspace is expected to handle them. As a result, one has to hack together a solution using a mechanism intended to receive packets or events, not to simply NAPI poll. NAPI threaded busy polling, on the other hand, provides this capability natively, independent of any userspace API. This makes it really easy to setup and manage. For analysis we use an AF_XDP based benchmarking tool `xsk_rr`. The description of the tool and how it tries to simulate the real workload is following, - It sends UDP packets between 2 machines. - The client machine sends packets at a fixed frequency. To maintain the frequency of the packet being sent, we use open-loop sampling. That is the packets are sent in a separate thread. - The server replies to the packet inline by reading the pkt from the recv ring and replies using the tx ring. - To simulate the application processing time, we use a configurable delay in usecs on the client side after a reply is received from the server. The xsk_rr tool is posted separately as an RFC for tools/testing/selftest. We use this tool with following napi polling configurations, - Interrupts only - SO_BUSYPOLL (inline in the same thread where the client receives the packet). - SO_BUSYPOLL (separate thread and separate core) - Threaded NAPI busypoll System is configured using following script in all 4 cases, ``` echo 0 | sudo tee /sys/class/net/eth0/threaded echo 0 | sudo tee /proc/sys/kernel/timer_migration echo off | sudo tee /sys/devices/system/cpu/smt/control sudo ethtool -L eth0 rx 1 tx 1 sudo ethtool -G eth0 rx 1024 echo 0 | sudo tee /proc/sys/net/core/rps_sock_flow_entries echo 0 | sudo tee /sys/class/net/eth0/queues/rx-0/rps_cpus # pin IRQs on CPU 2 IRQS="$(gawk '/eth0-(TxRx-)?1/ {match($1, /([0-9]+)/, arr); \ print arr[0]}' < /proc/interrupts)" for irq in "${IRQS}"; \ do echo 2 | sudo tee /proc/irq/$irq/smp_affinity_list; done echo -1 | sudo tee /proc/sys/kernel/sched_rt_runtime_us for i in /sys/devices/virtual/workqueue/*/cpumask; \ do echo $i; echo 1,2,3,4,5,6 > $i; done if [[ -z "$1" ]]; then echo 400 | sudo tee /proc/sys/net/core/busy_read echo 100 | sudo tee /sys/class/net/eth0/napi_defer_hard_irqs echo 15000 | sudo tee /sys/class/net/eth0/gro_flush_timeout fi sudo ethtool -C eth0 adaptive-rx off adaptive-tx off rx-usecs 0 tx-usecs 0 if [[ "$1" == "enable_threaded" ]]; then echo 0 | sudo tee /proc/sys/net/core/busy_poll echo 0 | sudo tee /proc/sys/net/core/busy_read echo 100 | sudo tee /sys/class/net/eth0/napi_defer_hard_irqs echo 15000 | sudo tee /sys/class/net/eth0/gro_flush_timeout NAPI_ID=$(ynl --family netdev --output-json --do queue-get \ --json '{"ifindex": '${IFINDEX}', "id": '0', "type": "rx"}' | jq '."napi-id"') ynl --family netdev --json '{"id": "'${NAPI_ID}'", "threaded": "busy-poll"}' NAPI_T=$(ynl --family netdev --output-json --do napi-get \ --json '{"id": "'$NAPI_ID'"}' | jq '."pid"') sudo chrt -f -p 50 $NAPI_T # pin threaded poll thread to CPU 2 sudo taskset -pc 2 $NAPI_T fi if [[ "$1" == "enable_interrupt" ]]; then echo 0 | sudo tee /proc/sys/net/core/busy_read echo 0 | sudo tee /sys/class/net/eth0/napi_defer_hard_irqs echo 15000 | sudo tee /sys/class/net/eth0/gro_flush_timeout fi ``` To enable various configurations, script can be run as following, - Interrupt Only ```