From nobody Sat Feb 7 14:34:21 2026 Received: from mail-wm1-f49.google.com (mail-wm1-f49.google.com [209.85.128.49]) (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 AA7DD3093D7 for ; Fri, 6 Feb 2026 21:09:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.49 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770412190; cv=none; b=Da7jfgFm5j54mUlk2sNEfQLofIGj9RU5He9vRATFH2bZZtqcEUCLozQDpul5u6OpnK7doR887wvn4y9ZqXQE9JV5eHTpCtTOeOuOGwWRAVQUrKAi+AYYIYFDBPHOp/1afa0w9sA5awi0ChlqRu+1zAZsl2lUvTCGWRZSEcEHRz4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770412190; c=relaxed/simple; bh=uQW0hDq304V6H9OiddeiltQWnd2evSXrQFoWu7l0hxM=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=Pv/rOdL1alUgszZJZ4Qmd0uHNiqQpBzab5tqrnZxDZ684KFp83Rbzr51R/m0Xda00GDIEX2hQlaUtHcD2wLf4uhcqFYj+TkVDVoUjusAysf79eU+UGQxGqYspQbJR2ABOb5HzW3/rOnELKqNZzTYvIe2pXQ/hLHx+k+X6w4YG4o= 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=dTuy/aFr; arc=none smtp.client-ip=209.85.128.49 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="dTuy/aFr" Received: by mail-wm1-f49.google.com with SMTP id 5b1f17b1804b1-47ee76e8656so38587195e9.0 for ; Fri, 06 Feb 2026 13:09:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1770412188; x=1771016988; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=GSQFCK7yDJc10r3FKl/3EZjeALk58Amm1GWLHWektGQ=; b=dTuy/aFrLHqDCGP+Z9w8YjUiGwRdT3v4U+CivYDgX18vrBra7VmMP5OalZy9xpgjiy BsAjykmDcZ/4hQ/W4E2Ib/981S2J5UvN5Ag6FjhkNsjTpexNvlxGoSIw0nmdTcHKKvzM i0ZEPGX42Eebo7O7+cAY9U5yZiwyKG+5huS+tyXufgQzZC+IvDlKh/4AJ1uxjhNIGyT/ /i6SbFY1C48WAFiGBmWI25LTIgWBR/BQUDjv8+6WV/OQnsMjWX79y17gaIyHXMfDSuin 6B3Kj+qvVm1YIbc+aoBz/xvNypzaFsrldHF7/YAAiUAtDY1awBmFkpuqIjJjsoHQD1Dk acCQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1770412188; x=1771016988; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=GSQFCK7yDJc10r3FKl/3EZjeALk58Amm1GWLHWektGQ=; b=mlc6trrR5qmhNS105fuu5gkJjhi/xwtrpFjmk1cGc9DMrKK91FluSDKQsiwn88MYci fnlK7TOOIKON8eEB5kFEqJWU+Hl/VAyLCwPPuh5mmYd7b8cj3TNXCvz9AQSo7qnyDTKG tljl06zvArghgISmlb7L8aSH3aDXO3O2G0hBUmFIChoCI0Qr7ZB/HWqquHh8BcexMMRS 1ptD67L91jrQtD8+r426/DmZVvht+TEzOin7UI+KGVI9ZmwGRD6hza4UnYiDhl16ocbw WNsqyOpjVWzc81mUYz1qfo7JQQUDIL+4xfs7r+NK32ZbAbJIVPxM4uKKIfaX9yF41XRW +YTg== X-Forwarded-Encrypted: i=1; AJvYcCX217njLDkXXqqTlFPskrAAYkriB4x3QiauVEKEwFlFkeqLBen5WOAMTQHuRqy//MVWtgm51zHzPUjwjJc=@vger.kernel.org X-Gm-Message-State: AOJu0YwkJXv5rTIP9PYJ0WBCn6skSNDj/EKXNQBDK4lOeWv0Whg5Ubtt cZ9UF8Jmfu58OZf53KCOXg6m6I0jO5Fcl3uMs8hTgCLRoP5JLJ2r8ThL X-Gm-Gg: AZuq6aLnsJge4zS5SvCwLwUITLZgd83MOP7pMHQ4U2WTqZDBCo2RiY8lytaGr6eKEqX o8XjPtO/NfgXGFYlpjtgd9ku+omaL1DZlU9y0ouylkwronYtHCojyQVzuAcv8cfZYRLEKo7nmdl QVLt1vxF5ybieG5epIqbN/lLBetHplB3bR2cd7lPjBawca/3VYTJXWumRcBakL+/4K1SZHT1rp7 diix79Ql1zrw5vsdWfxVI8IHCKwEtz7zHbp7PBcXLxPxMSnwDHa+RUgYispUscH+7joOEo/Wcty mDfL0a5Kp9DhFC95wfXsjrZZwlKoAluUkQ1pvahOsOnvV0algDJc4AxVBYI3TaEjG+FRU4N+g7B wme/+H3jcHFzvj8XPOZb1O4uQOgFqzIjttf1aHOZPNY+IYTLEiPpfSzq/Juv0hU/94pKjmDst5T 9dqFA7WzqgGI1OGFDt10IkwTRpMunlEmxBlF/IuRtC0IyJJEhilB7uT0CZng0X8iIGSo4hfSzJ X-Received: by 2002:a05:600c:5290:b0:477:6d96:b3e5 with SMTP id 5b1f17b1804b1-4832020023cmr57675045e9.7.1770412187832; Fri, 06 Feb 2026 13:09:47 -0800 (PST) Received: from snowdrop.snailnet.com (82-69-66-36.dsl.in-addr.zen.co.uk. [82.69.66.36]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4831d0b5b31sm125177815e9.4.2026.02.06.13.09.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 06 Feb 2026 13:09:47 -0800 (PST) From: david.laight.linux@gmail.com To: Giovanni Cabiddu , Herbert Xu , "David S. Miller" , Suman Kumar Chakraborty , Vijay Sundar Selvamani , George Abraham P , qat-linux@intel.com, linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org Cc: David Laight Subject: [PATCH next] crypto: qat - replace avg_array() with a better function Date: Fri, 6 Feb 2026 21:09:40 +0000 Message-Id: <20260206210940.315817-1-david.laight.linux@gmail.com> X-Mailer: git-send-email 2.39.5 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: David Laight avg_array() is defined as a 'type independant' #define. However the algorithm is only valid for unsigned types and the implementation is only valid for u64. All the callers pass temporary kmalloc() allocated arrays of u64. Replace with a function that takes a pointer to a u64 array. Change the implementation to sum the low and high 32bits of each value separately and then compute the average. This will be massively faster as it does two divisions rather than one for each element. Also removes some very pointless __unqual_scalar_typeof(). They could be 'auto _x =3D 0 ? x + 0 : 0;' even if the types weren't fixed. Only compile tested. Signed-off-by: David Laight --- .../intel/qat/qat_common/adf_tl_debugfs.c | 38 ++++++++----------- 1 file changed, 15 insertions(+), 23 deletions(-) diff --git a/drivers/crypto/intel/qat/qat_common/adf_tl_debugfs.c b/drivers= /crypto/intel/qat/qat_common/adf_tl_debugfs.c index b81f70576683..a084437a2631 100644 --- a/drivers/crypto/intel/qat/qat_common/adf_tl_debugfs.c +++ b/drivers/crypto/intel/qat/qat_common/adf_tl_debugfs.c @@ -77,32 +77,24 @@ static int tl_collect_values_u64(struct adf_telemetry *= telemetry, * @len: Number of elements. * * This algorithm computes average of an array without running into overfl= ow. + * (Provided len is less than 2 << 31.) * * Return: average of values. */ -#define avg_array(array, len) ( \ -{ \ - typeof(&(array)[0]) _array =3D (array); \ - __unqual_scalar_typeof(_array[0]) _x =3D 0; \ - __unqual_scalar_typeof(_array[0]) _y =3D 0; \ - __unqual_scalar_typeof(_array[0]) _a, _b; \ - typeof(len) _len =3D (len); \ - size_t _i; \ - \ - for (_i =3D 0; _i < _len; _i++) { \ - _a =3D _array[_i]; \ - _b =3D do_div(_a, _len); \ - _x +=3D _a; \ - if (_y >=3D _len - _b) { \ - _x++; \ - _y -=3D _len - _b; \ - } else { \ - _y +=3D _b; \ - } \ - } \ - do_div(_y, _len); \ - (_x + _y); \ -}) +static u64 avg_array(const u64 *array, size_t len) +{ + u64 sum_hi =3D 0, sum_lo =3D 0; + size_t i; + + for (i =3D 0; i < len; i++) { + sum_hi +=3D array[i] >> 32; + sum_lo +=3D (u32)array[i]; + } + + sum_lo +=3D (u64)do_div(sum_hi, len) << 32; + + return (sum_hi << 32) + div_u64(sum_lo, len); +} =20 /* Calculation function for simple counter. */ static int tl_calc_count(struct adf_telemetry *telemetry, --=20 2.39.5