From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pf1-f174.google.com (mail-pf1-f174.google.com [209.85.210.174]) (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 9C751282F15 for ; Thu, 2 Jul 2026 03:52:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.174 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782964364; cv=none; b=CLDInovpgw0UlOqE9B02m6s5Sbp32rLbFUPQttmAJicCU9NaBB/SJGFiNp8hXVFjbgZqv2GLymZYrHyDProuRt4bvMoxs26tY3DpOzIhbKs3DSknwsJTCI4kwDZweh/irvgDTy/xzCMTO5I82Q0MilQxLETS9eMteRtcy7/f9U8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782964364; c=relaxed/simple; bh=7ZcPijjc1RgbgAx4Q7izzYD4hi46U+2wPXK+U0WesyM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=VT2zB2YIPzNZ5tY13kEqbVJxI7kzC0e2fbmIPoTfPzoVOsLh+EoTQKI6B9O20JqN93kHMuTXBy5ok7loXlZzEH1zFNaS3l2DfDzUEBzd4vvuXqVsoPPhSPjNgFiK/wCjfeZfTWV0hmQqjKViMLLXxs0Fbsn5XYVQrQciYIWxF7I= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=r5nXFPWm; arc=none smtp.client-ip=209.85.210.174 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="r5nXFPWm" Received: by mail-pf1-f174.google.com with SMTP id d2e1a72fcca58-847a483e344so149538b3a.0 for ; Wed, 01 Jul 2026 20:52:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1782964363; x=1783569163; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=aTxIoT2T4MF8kQ0IhrOvAz2CYquvztawWB3Fq2L/RIo=; b=r5nXFPWmwBUBhb/SlXqZRAiAiFUOhYUC4m4Y0XTfonHmeAN5vX5vsCO9zcNbe4Y07u BGfzFDAkoAeIbHMUBXS8YR6U0ySTXMA+w1blOwHGhVP4D/EgWAKJWR3OUmve/hLIEn3l OFLn6D/l2RLr+ADtfjRZvXbQJdoO4r4YhD3PqJylZdkgFfcHIQjVvRGXFVs1ZLinUIFk SG/8kzaRxsLUoyIfWmD8+jMzhGEYZa/XSTlPt7WpY6aZ2UcjIEEa/AdDID1KpciPwyCh /tmU+FuZR1vkIAMCQtDruVeJ52KahC6uHcDglTBgFhoPTQBhmXbcj1RY04LiQt0AiqM5 Jo7g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1782964363; x=1783569163; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=aTxIoT2T4MF8kQ0IhrOvAz2CYquvztawWB3Fq2L/RIo=; b=lLsMNZezPBaoiy9M34bxgCK1FFzFdKbppBTOWS+UNTixb+Xec0CF7aQzXxUuORNv12 udEtGrPlxvxX8kX1iMgzEWFhyCF4zO/suboWSKYyMYD7QiPJAhvmtqV0R2ZJ16gLZtIf oxniFzlEWFV1zLgQp6x/UzYtd05N7ug5QZYJ6d4wlH4RZac7dUCvINvDAxCaxin1/BTB QFs2oRsGkK4yVtjz00CNe85PDpUHbnucStjXElibWYQBfpS+UWQKrAsfMOP8ep9wsfrP 8ZaWgzL2jsAB6xxrVhuQ/Prh4n1O/4RYWaqKDmet/+nePzJJ2R3qcvRaW+5TEPbVwsC5 0CXw== X-Forwarded-Encrypted: i=1; AHgh+RqcZAVpJXECjdl/Qv8dXB3IPgB3ZkiaQJvSYy73x6N2ydN60wwpy4d1LJ2dgMLdl8CrhHshxn/XglW43m8=@vger.kernel.org X-Gm-Message-State: AOJu0YwqHAo+wQ10ZcTOIGitQgOVbieE7E1hVK41N3dLpkbcFNYz6RER CHTKrVGRObuv06lyRoVjl+sGo8E8p2sBPNxDdQ/XYveGfPLIx5/94PeB X-Gm-Gg: AfdE7cn/VBO8fKhpvErF6dmhk/GANEc86OL+QI1AwGAa4X5+guEXZpBxqEq62aCmJ/O GvquYEdpFAea2NIvHF/7vNXXUI/0YG0s9qiuX0hrSwswS72ZZ0f7wGap768jpsSU3iu6z1wAn9d B2iMsxpQUInrQfbR1YwohP59LvTu3YOhId5XfXtp9yVvn1KiudROL8mdljZT6NvFU92a6RuwWKv AiWWUA6dRhuuCB/oLewgvgel/uni1BB5+dEGzBDyt/hZrB0cy6F98vZD95GVIRbyhY6U22Jo0bJ YAt/yq7gfoETpzjiEWQ3YOD6Mferv3NStj8uoFQWRnaEgkIuB/Qq+0WV21LtzdESe4Bsjp+2LKt seA+i7B5CZ0ZAxKmtFn/b/49LiH8kY8Q28dk7AtJSmhVITh2oeveZ0ENVaL4dGsFNqsE9T42hYf BZxpE4q1AYV/EOmem9bRq26yky750C1E9WHG954QpfUsqqlNDQ25CJWHdy/Y51gbY= X-Received: by 2002:a05:6a00:f8c:b0:847:7cf2:a8ff with SMTP id d2e1a72fcca58-847a83566aamr7305698b3a.30.1782964362566; Wed, 01 Jul 2026 20:52:42 -0700 (PDT) Received: from frank0988server (36-236-219-120.dynamic-ip.hinet.net. [36.236.219.120]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-847cb94bd7esm650121b3a.38.2026.07.01.20.52.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Jul 2026 20:52:42 -0700 (PDT) From: Chun-Cheng Chang To: Jeff Johnson Cc: linux-wireless@vger.kernel.org, linux-kernel@vger.kernel.org, Chun-Cheng Chang Subject: [PATCH v2] wifi: ath: avoid repeated divisions in DFS PRI detector Date: Thu, 2 Jul 2026 03:52:36 +0000 Message-ID: <20260702035236.392328-1-frank0988855428@gmail.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260701170424.380202-1-frank0988855428@gmail.com> References: <20260701170424.380202-1-frank0988855428@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit pde_get_multiple() is called repeatedly with the same PRI (Pulse Repetition Interval) value while validating candidate and existing PRI sequences. Cache the reciprocal value for each sequence structure and leverage reciprocal_divide() in the hot path. This keeps the existing matching logic and tolerance checks intact while replacing expensive hardware integer divisions with low-cost multiply-and-shift operations. Testing with a userspace model of the same detector logic demonstrated identical detector states and outputs across 100 verification traces. To eliminate memory allocator noise, an isolated micro-benchmark using a static object pool showed that the reciprocal variant reduces CPU cycles by approximately 3.4%. Signed-off-by: Chun-Cheng Chang --- Changes in v2: - Use a known identity for the author and Signed-off-by tags. drivers/net/wireless/ath/dfs_pri_detector.c | 14 +++++++++++--- drivers/net/wireless/ath/dfs_pri_detector.h | 3 +++ 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/drivers/net/wireless/ath/dfs_pri_detector.c b/drivers/net/wireless/ath/dfs_pri_detector.c index 388f9d1913bd..520fd1567a0b 100644 --- a/drivers/net/wireless/ath/dfs_pri_detector.c +++ b/drivers/net/wireless/ath/dfs_pri_detector.c @@ -16,6 +16,7 @@ #include #include +#include #include "ath.h" #include "dfs_pattern_detector.h" @@ -41,7 +42,9 @@ struct pulse_elem { * pde_get_multiple() - get number of multiples considering a given tolerance * Return value: factor if abs(val - factor*fraction) <= tolerance, 0 otherwise */ -static u32 pde_get_multiple(u32 val, u32 fraction, u32 tolerance) +static u32 pde_get_multiple(u32 val, u32 fraction, + struct reciprocal_value fraction_recip, + u32 tolerance) { u32 remainder; u32 factor; @@ -56,8 +59,8 @@ static u32 pde_get_multiple(u32 val, u32 fraction, u32 tolerance) /* val and fraction are within tolerance */ return 1; - factor = val / fraction; - remainder = val % fraction; + factor = reciprocal_divide(val, fraction_recip); + remainder = val - factor * fraction; if (remainder > tolerance) { /* no exact match */ if ((fraction - remainder) <= tolerance) @@ -247,6 +250,9 @@ static bool pseq_handler_create_sequences(struct pri_detector *pde, ps.last_ts = ts; ps.pri = GET_PRI_TO_USE(pde->rs->pri_min, pde->rs->pri_max, ts - p->ts); + ps.pri_recip = (struct reciprocal_value){}; + if (ps.pri) + ps.pri_recip = reciprocal_value(ps.pri); ps.dur = ps.pri * (pde->rs->ppb - 1) + 2 * pde->rs->max_pri_tolerance; @@ -261,6 +267,7 @@ static bool pseq_handler_create_sequences(struct pri_detector *pde, break; /* check if pulse match (multi)PRI */ factor = pde_get_multiple(ps.last_ts - p2->ts, ps.pri, + ps.pri_recip, pde->rs->max_pri_tolerance); if (factor > 0) { ps.count++; @@ -318,6 +325,7 @@ pseq_handler_add_to_existing_seqs(struct pri_detector *pde, u64 ts) delta_ts = ts - ps->last_ts; factor = pde_get_multiple(delta_ts, ps->pri, + ps->pri_recip, pde->rs->max_pri_tolerance); if (factor > 0) { ps->last_ts = ts; diff --git a/drivers/net/wireless/ath/dfs_pri_detector.h b/drivers/net/wireless/ath/dfs_pri_detector.h index 86339f2b4d3a..c519466cff8b 100644 --- a/drivers/net/wireless/ath/dfs_pri_detector.h +++ b/drivers/net/wireless/ath/dfs_pri_detector.h @@ -18,6 +18,7 @@ #define DFS_PRI_DETECTOR_H #include +#include extern struct ath_dfs_pool_stats global_dfs_pool_stats; @@ -25,6 +26,7 @@ extern struct ath_dfs_pool_stats global_dfs_pool_stats; * struct pri_sequence - sequence of pulses matching one PRI * @head: list_head * @pri: pulse repetition interval (PRI) in usecs + * @pri_recip: cached reciprocal value for PRI divisions * @dur: duration of sequence in usecs * @count: number of pulses in this sequence * @count_falses: number of not matching pulses in this sequence @@ -35,6 +37,7 @@ extern struct ath_dfs_pool_stats global_dfs_pool_stats; struct pri_sequence { struct list_head head; u32 pri; + struct reciprocal_value pri_recip; u32 dur; u32 count; u32 count_falses; -- 2.53.0