From: Jesse Taube <jesse@rivosinc.com>
To: linux-riscv@lists.infradead.org
Cc: "Jonathan Corbet" <corbet@lwn.net>,
"Paul Walmsley" <paul.walmsley@sifive.com>,
"Palmer Dabbelt" <palmer@dabbelt.com>,
"Albert Ou" <aou@eecs.berkeley.edu>,
"Conor Dooley" <conor@kernel.org>,
"Rob Herring" <robh@kernel.org>,
"Krzysztof Kozlowski" <krzk+dt@kernel.org>,
"Clément Léger" <cleger@rivosinc.com>,
"Evan Green" <evan@rivosinc.com>,
"Andrew Jones" <ajones@ventanamicro.com>,
"Jesse Taube" <jesse@rivosinc.com>,
"Charlie Jenkins" <charlie@rivosinc.com>,
"Xiao Wang" <xiao.w.wang@intel.com>,
"Andy Chiu" <andy.chiu@sifive.com>,
"Eric Biggers" <ebiggers@google.com>,
"Greentime Hu" <greentime.hu@sifive.com>,
"Björn Töpel" <bjorn@rivosinc.com>,
"Heiko Stuebner" <heiko@sntech.de>,
"Costa Shulyupin" <costa.shul@redhat.com>,
"Andrew Morton" <akpm@linux-foundation.org>,
"Baoquan He" <bhe@redhat.com>,
"Anup Patel" <apatel@ventanamicro.com>,
"Zong Li" <zong.li@sifive.com>,
"Sami Tolvanen" <samitolvanen@google.com>,
"Ben Dooks" <ben.dooks@codethink.co.uk>,
"Alexandre Ghiti" <alexghiti@rivosinc.com>,
"Gustavo A. R. Silva" <gustavoars@kernel.org>,
"Erick Archer" <erick.archer@gmx.com>,
"Joel Granados" <j.granados@samsung.com>,
linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org,
devicetree@vger.kernel.org
Subject: [PATCH 1/1] RISC-V: Add parameter to unaligned access speed
Date: Mon, 5 Aug 2024 13:38:15 -0400 [thread overview]
Message-ID: <20240805173816.3722002-1-jesse@rivosinc.com> (raw)
Add a kernel parameter to the unaligned access speed. This allows
skiping of the speed tests for unaligned accesses, which often is very
slow.
Signed-off-by: Jesse Taube <jesse@rivosinc.com>
---
arch/riscv/kernel/unaligned_access_speed.c | 81 ++++++++++++++++++++++
1 file changed, 81 insertions(+)
diff --git a/arch/riscv/kernel/unaligned_access_speed.c b/arch/riscv/kernel/unaligned_access_speed.c
index 1548eb10ae4f..02f7a92a5fa0 100644
--- a/arch/riscv/kernel/unaligned_access_speed.c
+++ b/arch/riscv/kernel/unaligned_access_speed.c
@@ -400,13 +400,94 @@ static int vec_check_unaligned_access_speed_all_cpus(void *unused __always_unuse
}
#endif
+static DEFINE_PER_CPU(long, unaligned_scalar_speed_param) = RISCV_HWPROBE_MISALIGNED_UNKNOWN;
+
+static int __init set_unaligned_scalar_speed_param(char *str)
+{
+ cpumask_var_t mask;
+ int ret, cpu;
+ long speed = RISCV_HWPROBE_MISALIGNED_UNKNOWN;
+
+ if (!strncmp(str, "fast,", 5)) {
+ str += 5;
+ speed = RISCV_HWPROBE_MISALIGNED_FAST;
+ }
+
+ if (!strncmp(str, "slow,", 5)) {
+ str += 5;
+ speed = RISCV_HWPROBE_MISALIGNED_SLOW;
+ }
+ if (speed == RISCV_HWPROBE_MISALIGNED_UNKNOWN) {
+ pr_warn("Invalid unaligned access speed parameter\n");
+ return 1;
+ }
+
+ if (!zalloc_cpumask_var(&mask, GFP_KERNEL))
+ return -ENOMEM;
+
+ ret = cpulist_parse(str, mask);
+
+ for_each_cpu(cpu, mask)
+ if (per_cpu(unaligned_scalar_speed_param, cpu) == RISCV_HWPROBE_MISALIGNED_UNKNOWN)
+ per_cpu(unaligned_scalar_speed_param, cpu) = speed;
+
+ free_cpumask_var(mask);
+ return ret == 0;
+}
+__setup("unaligned_scalar_speed=", set_unaligned_scalar_speed_param);
+
+static DEFINE_PER_CPU(long, unaligned_vector_speed_param) = RISCV_HWPROBE_VECTOR_MISALIGNED_UNKNOWN;
+
+static int __init set_unaligned_vector_speed_param(char *str)
+{
+ cpumask_var_t mask;
+ int ret, cpu;
+ long speed = RISCV_HWPROBE_VECTOR_MISALIGNED_UNKNOWN;
+
+ if (!strncmp(str, "fast,", 5)) {
+ str += 5;
+ speed = RISCV_HWPROBE_VECTOR_MISALIGNED_FAST;
+ }
+
+ if (!strncmp(str, "slow,", 5)) {
+ str += 5;
+ speed = RISCV_HWPROBE_VECTOR_MISALIGNED_SLOW;
+ }
+ if (speed == RISCV_HWPROBE_VECTOR_MISALIGNED_UNKNOWN) {
+ pr_warn("Invalid unaligned access speed parameter\n");
+ return 1;
+ }
+
+ if (!zalloc_cpumask_var(&mask, GFP_KERNEL))
+ return -ENOMEM;
+
+ ret = cpulist_parse(str, mask);
+
+ for_each_cpu(cpu, mask)
+ if (per_cpu(unaligned_vector_speed_param, cpu) == RISCV_HWPROBE_VECTOR_MISALIGNED_UNKNOWN)
+ per_cpu(unaligned_vector_speed_param, cpu) = speed;
+
+ free_cpumask_var(mask);
+ return ret == 0;
+}
+__setup("unaligned_vector_speed=", set_unaligned_vector_speed_param);
+
static int check_unaligned_access_all_cpus(void)
{
+ int cpu;
bool all_cpus_emulated, all_cpus_vec_unsupported;
all_cpus_emulated = check_unaligned_access_emulated_all_cpus();
all_cpus_vec_unsupported = check_vector_unaligned_access_emulated_all_cpus();
+ for_each_online_cpu(cpu) {
+ if (per_cpu(misaligned_access_speed, cpu) == RISCV_HWPROBE_MISALIGNED_UNKNOWN)
+ per_cpu(misaligned_access_speed, cpu) = per_cpu(unaligned_scalar_speed_param, cpu);
+
+ if (per_cpu(vector_misaligned_access, cpu) == RISCV_HWPROBE_VECTOR_MISALIGNED_UNKNOWN)
+ per_cpu(vector_misaligned_access, cpu) = per_cpu(unaligned_vector_speed_param, cpu);
+ }
+
pr_info("\e[31m%s vector unaligned access\e[0m\n",
all_cpus_vec_unsupported ? "All CPUs do not support" : "At least one cpu supports");
if (!all_cpus_vec_unsupported &&
--
2.45.2
next reply other threads:[~2024-08-05 17:38 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-08-05 17:38 Jesse Taube [this message]
2024-08-05 17:38 ` [PATCH 0/1] RISC-V: kernel parameter for unaligned access speed Jesse Taube
2024-08-05 18:38 ` [PATCH 1/1] RISC-V: Add parameter to " Evan Green
2024-08-05 18:48 ` Charlie Jenkins
2024-08-05 18:56 ` Evan Green
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240805173816.3722002-1-jesse@rivosinc.com \
--to=jesse@rivosinc.com \
--cc=ajones@ventanamicro.com \
--cc=akpm@linux-foundation.org \
--cc=alexghiti@rivosinc.com \
--cc=andy.chiu@sifive.com \
--cc=aou@eecs.berkeley.edu \
--cc=apatel@ventanamicro.com \
--cc=ben.dooks@codethink.co.uk \
--cc=bhe@redhat.com \
--cc=bjorn@rivosinc.com \
--cc=charlie@rivosinc.com \
--cc=cleger@rivosinc.com \
--cc=conor@kernel.org \
--cc=corbet@lwn.net \
--cc=costa.shul@redhat.com \
--cc=devicetree@vger.kernel.org \
--cc=ebiggers@google.com \
--cc=erick.archer@gmx.com \
--cc=evan@rivosinc.com \
--cc=greentime.hu@sifive.com \
--cc=gustavoars@kernel.org \
--cc=heiko@sntech.de \
--cc=j.granados@samsung.com \
--cc=krzk+dt@kernel.org \
--cc=linux-doc@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-riscv@lists.infradead.org \
--cc=palmer@dabbelt.com \
--cc=paul.walmsley@sifive.com \
--cc=robh@kernel.org \
--cc=samitolvanen@google.com \
--cc=xiao.w.wang@intel.com \
--cc=zong.li@sifive.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox