From nobody Thu Apr 2 19:15:32 2026 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BD5CB3A1C9 for ; Wed, 11 Feb 2026 17:30:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770831054; cv=none; b=gQMPiR9gHUDZpr4ppVwQ+psIzxHpHZpZRevsNt0H/KmDKZdtYTVGTQFYyQmkHbsKXlt/DVmhF7N9IybK/jcGH5/Q5+0fdPiNABRdcllpfvQ75gkMzY3L3P8RvayKE4yp2V8hpBaWGDg/3iR9q6d5xGKN/Nx5mM5wgosRYP7eLOM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770831054; c=relaxed/simple; bh=G/Fs1jo+I9DUOp3q7ItK2rL9da8TP1cJemCnwWQl2tc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=N3tVDxfZPEk+7Sf7W2LxoFq79OLcUO3PCwKQKw3dYGCBby/rENTM00mPtAEz7QJv5Q1cVud5yreY2zGwvlcLNcXHuRCsQVIl8XpQIw2NyAMwFY96nrYvrwTEdlsIqbxl3J2zR9GRIWLLPQRpda+CeuLJVRnAJrRABfib1AKVT9w= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=SdZMaVtp; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=k6LTFLm3; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="SdZMaVtp"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="k6LTFLm3" From: Nam Cao DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1770831051; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=r/8y0dAsi1KhYQOwI9LZZG8LjkoOsEKw49Zlrv+dlAg=; b=SdZMaVtpDXnlEmf2pEmfwTyNcS8A9Qiqs5CvVQO5Ve9E/z1NFbyHRpPF69btIw3HMZuMuz Ors8Gsuj4kctnAXXSgAj1daq2F0OUZwEQHzd+tKjXrP72zUWUHJqMdA9/7M1vx0zhQdafx 74OaIVPnrIgxKMuTn/iUsFFQHPDKkBy4ufbhyVr3HwB8h+A0wA5iqURQVAffd3O1A6Atvs oNY2TC64pR5zFjFq0ZnoKzKVU9Y5WvbRuDLxqukC3jv85WN5UFqBIqiiy7nYxGvtKdR1Er WZ38UfnJ1kwuWaqHfiegaqEdVZqWl3RRYG4qwY7ZmafQzecKyOXOyhB16yaEuQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1770831051; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=r/8y0dAsi1KhYQOwI9LZZG8LjkoOsEKw49Zlrv+dlAg=; b=k6LTFLm3s31j4+B5eetbSfi6TJuNhE43D3HIdciKWDDFdd3YzCd25qygSntBdy8nxc/iVj VAKUMRhPWZDhUxCQ== To: Paul Walmsley , Palmer Dabbelt , Albert Ou , Alexandre Ghiti , Andrew Jones , =?UTF-8?q?Cl=C3=A9ment=20L=C3=A9ger?= , linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org Cc: Nam Cao Subject: [PATCH 3/5] riscv: Reuse measure_cycles() in check_vector_unaligned_access() Date: Wed, 11 Feb 2026 18:30:33 +0100 Message-ID: In-Reply-To: References: 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" check_vector_unaligned_access() duplicates the logic in measure_cycles(). Reuse measure_cycles() and deduplicate. Signed-off-by: Nam Cao --- arch/riscv/kernel/unaligned_access_speed.c | 54 ++++------------------ 1 file changed, 8 insertions(+), 46 deletions(-) diff --git a/arch/riscv/kernel/unaligned_access_speed.c b/arch/riscv/kernel= /unaligned_access_speed.c index b964a666a973..c0d39c4b2150 100644 --- a/arch/riscv/kernel/unaligned_access_speed.c +++ b/arch/riscv/kernel/unaligned_access_speed.c @@ -16,7 +16,6 @@ =20 #include "copy-unaligned.h" =20 -#define MISALIGNED_ACCESS_JIFFIES_LG2 1 #define MISALIGNED_ACCESS_NS 8000000 #define MISALIGNED_BUFFER_SIZE 0x4000 #define MISALIGNED_BUFFER_ORDER get_order(MISALIGNED_BUFFER_SIZE) @@ -30,9 +29,9 @@ static long unaligned_vector_speed_param =3D RISCV_HWPROB= E_MISALIGNED_VECTOR_UNKNO =20 static cpumask_t fast_misaligned_access; =20 -#ifdef CONFIG_RISCV_PROBE_UNALIGNED_ACCESS -static u64 measure_cycles(void (*func)(void *dst, const void *src, size_t = len), - void *dst, void *src, size_t len) +static u64 __maybe_unused +measure_cycles(void (*func)(void *dst, const void *src, size_t len), + void *dst, void *src, size_t len) { u64 start_cycles, end_cycles, cycles =3D -1ULL; u64 start_ns; @@ -64,6 +63,7 @@ static u64 measure_cycles(void (*func)(void *dst, const v= oid *src, size_t len), return cycles; } =20 +#ifdef CONFIG_RISCV_PROBE_UNALIGNED_ACCESS static int check_unaligned_access(void *param) { int cpu =3D smp_processor_id(); @@ -270,11 +270,9 @@ static int riscv_offline_cpu(unsigned int cpu) static void check_vector_unaligned_access(struct work_struct *work __alway= s_unused) { int cpu =3D smp_processor_id(); - u64 start_cycles, end_cycles; u64 word_cycles; u64 byte_cycles; int ratio; - unsigned long start_jiffies, now; struct page *page; void *dst; void *src; @@ -294,50 +292,14 @@ static void check_vector_unaligned_access(struct work= _struct *work __always_unus /* Unalign src as well, but differently (off by 1 + 2 =3D 3). */ src =3D dst + (MISALIGNED_BUFFER_SIZE / 2); src +=3D 2; - word_cycles =3D -1ULL; =20 - /* Do a warmup. */ kernel_vector_begin(); - __riscv_copy_vec_words_unaligned(dst, src, MISALIGNED_COPY_SIZE); - - start_jiffies =3D jiffies; - while ((now =3D jiffies) =3D=3D start_jiffies) - cpu_relax(); - - /* - * For a fixed amount of time, repeatedly try the function, and take - * the best time in cycles as the measurement. - */ - while (time_before(jiffies, now + (1 << MISALIGNED_ACCESS_JIFFIES_LG2))) { - start_cycles =3D get_cycles64(); - /* Ensure the CSR read can't reorder WRT to the copy. */ - mb(); - __riscv_copy_vec_words_unaligned(dst, src, MISALIGNED_COPY_SIZE); - /* Ensure the copy ends before the end time is snapped. */ - mb(); - end_cycles =3D get_cycles64(); - if ((end_cycles - start_cycles) < word_cycles) - word_cycles =3D end_cycles - start_cycles; - } - - byte_cycles =3D -1ULL; - __riscv_copy_vec_bytes_unaligned(dst, src, MISALIGNED_COPY_SIZE); - start_jiffies =3D jiffies; - while ((now =3D jiffies) =3D=3D start_jiffies) - cpu_relax(); =20 - while (time_before(jiffies, now + (1 << MISALIGNED_ACCESS_JIFFIES_LG2))) { - start_cycles =3D get_cycles64(); - /* Ensure the CSR read can't reorder WRT to the copy. */ - mb(); - __riscv_copy_vec_bytes_unaligned(dst, src, MISALIGNED_COPY_SIZE); - /* Ensure the copy ends before the end time is snapped. */ - mb(); - end_cycles =3D get_cycles64(); - if ((end_cycles - start_cycles) < byte_cycles) - byte_cycles =3D end_cycles - start_cycles; - } + word_cycles =3D measure_cycles(__riscv_copy_vec_words_unaligned, + dst, src, MISALIGNED_COPY_SIZE); =20 + byte_cycles =3D measure_cycles(__riscv_copy_vec_bytes_unaligned, + dst, src, MISALIGNED_COPY_SIZE); kernel_vector_end(); =20 /* Don't divide by zero. */ --=20 2.47.3