From nobody Thu Apr 2 19:15:27 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 8B66C34B191 for ; Wed, 11 Feb 2026 17:30:53 +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=PsQ896k36U4lJnEPhPLT1XP2Q0A4ePX9baaUKgM3MUpvnxCk5pp5oLZcTEdu6F0tGMIeBNG/sT7sOid5CscjGEmoCpl80iZXs3PkyKAJkIuI2NCKS7wNuGQDVxR1uSoF4Ka9GY3DH1+GBEEMrINSSMO+BGng0Ptb7R1nk0dNR0c= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770831054; c=relaxed/simple; bh=rzp3geWVTuAiQkMDh8BWYAc8nUKCBuWa4beXGqDAPWg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=g7PlP6Qg0SUF4YnBS0Ar8S2TTZwBFZujs/mzE1NVKwq+zKqtlHXIjkXsO2l/EUqAhpGTVQyUEm9y2mQT3BtWzKXd0Pm4a5KFfZtOtNpdyAJvjzG3y8C7Nu/xFu3eDdpgtb/IvvhH39DRxgWqXeKwuOPaNsmktu9cO5NwT/7grc0= 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=ecMZkWzY; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=y4ZGecbN; 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="ecMZkWzY"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="y4ZGecbN" From: Nam Cao DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1770831052; 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=X323MOQmcQUTpJgkN+84fsCKXqW3v74pQvlv4aLvRT8=; b=ecMZkWzYoWPY0RS09/lD57t2gt1Vy4HclF6l0WnT/kggt+60Q3rvJcwouC4luYCE4DsOJn PPnkFvHEqYgqi9Lzc0dv3yZ9H0+IwavqU7yTdJvnsCGxomKl53g4+7MfH+tNgrl/MIiTfe QigFZquT1bAHATGHCHUNQRABZpuXd1ThcNtT0Tpj6k2M2WVwECM1Am2H1NwqqClIXlCnUW oWNGocAvLG3ARFsmrHS1n//dWfBR0EYXyzwQU9FxHe1GBflIBJNNdLXttvtUolb5HPavoA hVFGHjYHl2XkjfceBytUPfvvUDdDdET797Ngpm+psquBBp6fTPH6SHFkKY7dfQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1770831052; 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=X323MOQmcQUTpJgkN+84fsCKXqW3v74pQvlv4aLvRT8=; b=y4ZGecbN4iScLAhdZBOG4jR47B8CfxQJ9bLUZRwGay9YA1BpQebFfqplN9wR3ViIQwxiDR IhfCBNiFhyHNfcCg== 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 5/5] riscv: Reuse compare_unaligned_access() in check_vector_unaligned_access() Date: Wed, 11 Feb 2026 18:30:35 +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 compare_unaligned_access(). Use compare_unaligned_access() and deduplicate. Signed-off-by: Nam Cao --- arch/riscv/kernel/unaligned_access_speed.c | 55 +++++++--------------- 1 file changed, 16 insertions(+), 39 deletions(-) diff --git a/arch/riscv/kernel/unaligned_access_speed.c b/arch/riscv/kernel= /unaligned_access_speed.c index b3ed74b71d3e..8a9f261dc10b 100644 --- a/arch/riscv/kernel/unaligned_access_speed.c +++ b/arch/riscv/kernel/unaligned_access_speed.c @@ -72,7 +72,7 @@ measure_cycles(void (*func)(void *dst, const void *src, s= ize_t len), static int __maybe_unused compare_unaligned_access(void (*word_copy)(void *dst, const void *src, siz= e_t len), void (*byte_copy)(void *dst, const void *src, size_t len), - void *buf) + void *buf, const char *type) { int cpu =3D smp_processor_id(); u64 word_cycles; @@ -92,8 +92,8 @@ compare_unaligned_access(void (*word_copy)(void *dst, con= st void *src, size_t le =20 /* Don't divide by zero. */ if (!word_cycles || !byte_cycles) { - pr_warn("cpu%d: rdtime lacks granularity needed to measure unaligned acc= ess speed\n", - cpu); + pr_warn("cpu%d: rdtime lacks granularity needed to measure %s unaligned = access speed\n", + cpu, type); =20 return -1; } @@ -101,8 +101,9 @@ compare_unaligned_access(void (*word_copy)(void *dst, c= onst void *src, size_t le fast =3D word_cycles < byte_cycles; =20 ratio =3D div_u64((byte_cycles * 100), word_cycles); - pr_info("cpu%d: Ratio of byte access time to unaligned word access is %d.= %02d, unaligned accesses are %s\n", + pr_info("cpu%d: %s unaligned word access speed is %d.%02dx byte access sp= eed (%s)\n", cpu, + type, ratio / 100, ratio % 100, fast ? "fast" : "slow"); @@ -121,7 +122,8 @@ static int check_unaligned_access(struct page *page) return 0; =20 ret =3D compare_unaligned_access(__riscv_copy_words_unaligned, - __riscv_copy_bytes_unaligned, buf); + __riscv_copy_bytes_unaligned, + buf, "scalar"); if (ret < 0) return 0; =20 @@ -291,13 +293,8 @@ 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 word_cycles; - u64 byte_cycles; - int ratio; struct page *page; - void *dst; - void *src; - long speed =3D RISCV_HWPROBE_MISALIGNED_VECTOR_SLOW; + int ret; =20 if (per_cpu(vector_misaligned_access, cpu) !=3D RISCV_HWPROBE_MISALIGNED_= VECTOR_UNKNOWN) return; @@ -308,40 +305,20 @@ static void check_vector_unaligned_access(struct work= _struct *work __always_unus return; } =20 - /* Make an unaligned destination buffer. */ - dst =3D (void *)((unsigned long)page_address(page) | 0x1); - /* Unalign src as well, but differently (off by 1 + 2 =3D 3). */ - src =3D dst + (MISALIGNED_BUFFER_SIZE / 2); - src +=3D 2; - kernel_vector_begin(); =20 - word_cycles =3D measure_cycles(__riscv_copy_vec_words_unaligned, - dst, src, MISALIGNED_COPY_SIZE); - - byte_cycles =3D measure_cycles(__riscv_copy_vec_bytes_unaligned, - dst, src, MISALIGNED_COPY_SIZE); + ret =3D compare_unaligned_access(__riscv_copy_vec_words_unaligned, + __riscv_copy_vec_bytes_unaligned, + page_address(page), "vector"); kernel_vector_end(); =20 - /* Don't divide by zero. */ - if (!word_cycles || !byte_cycles) { - pr_warn("cpu%d: rdtime lacks granularity needed to measure unaligned vec= tor access speed\n", - cpu); - + if (ret < 0) goto free; - } =20 - if (word_cycles < byte_cycles) - speed =3D RISCV_HWPROBE_MISALIGNED_VECTOR_FAST; - - ratio =3D div_u64((byte_cycles * 100), word_cycles); - pr_info("cpu%d: Ratio of vector byte access time to vector unaligned word= access is %d.%02d, unaligned accesses are %s\n", - cpu, - ratio / 100, - ratio % 100, - (speed =3D=3D RISCV_HWPROBE_MISALIGNED_VECTOR_FAST) ? "fast" : "slow"); - - per_cpu(vector_misaligned_access, cpu) =3D speed; + if (ret) + per_cpu(vector_misaligned_access, cpu) =3D RISCV_HWPROBE_MISALIGNED_VECT= OR_FAST; + else + per_cpu(vector_misaligned_access, cpu) =3D RISCV_HWPROBE_MISALIGNED_VECT= OR_SLOW; =20 free: __free_pages(page, MISALIGNED_BUFFER_ORDER); --=20 2.47.3