Skip to content

Commit 5dcddd2

Browse files
committed
LoongArch: Allow specify SIMD width via kernel parameters
For power saving or debugging purpose, we usually want to limit the SIMD (LSX/LASX) usage on a rich feature platform. So allow specify SIMD width via kernel parameters "simd=". Allowed values of "simd=" are any integers, and recommended values are: 0: Disable all SIMD features; 128: Enable at most 128bit SIMD features; 256: Enable at most 256bit SIMD features; -1(default): Enable as many as possible SIMD features automatically. Signed-off-by: Huacai Chen <chenhuacai@loongson.cn>
1 parent 98662be commit 5dcddd2

File tree

1 file changed

+44
-2
lines changed

1 file changed

+44
-2
lines changed

arch/loongarch/kernel/cpu-probe.c

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,48 @@ static inline void cpu_set_fpu_fcsr_mask(struct cpuinfo_loongarch *c)
5252
c->fpu_mask = ~(fcsr0 ^ fcsr1) & ~mask;
5353
}
5454

55+
/* simd = -1/0/128/256 */
56+
static unsigned int simd = -1U;
57+
58+
static int __init cpu_setup_simd(char *str)
59+
{
60+
get_option(&str, &simd);
61+
pr_info("Set SIMD width = %u\n", simd);
62+
63+
return 0;
64+
}
65+
66+
early_param("simd", cpu_setup_simd);
67+
68+
static int __init cpu_final_simd(void)
69+
{
70+
struct cpuinfo_loongarch *c = &cpu_data[0];
71+
72+
if (simd < 128) {
73+
c->options &= ~LOONGARCH_CPU_LSX;
74+
elf_hwcap &= ~HWCAP_LOONGARCH_LSX;
75+
}
76+
77+
if (simd < 256) {
78+
c->options &= ~LOONGARCH_CPU_LASX;
79+
elf_hwcap &= ~HWCAP_LOONGARCH_LASX;
80+
}
81+
82+
simd = 0;
83+
84+
if (c->options & LOONGARCH_CPU_LSX)
85+
simd = 128;
86+
87+
if (c->options & LOONGARCH_CPU_LASX)
88+
simd = 256;
89+
90+
pr_info("Final SIMD width = %u\n", simd);
91+
92+
return 0;
93+
}
94+
95+
arch_initcall(cpu_final_simd);
96+
5597
static inline void set_elf_platform(int cpu, const char *plat)
5698
{
5799
if (cpu == 0)
@@ -134,13 +176,13 @@ static void cpu_probe_common(struct cpuinfo_loongarch *c)
134176
elf_hwcap |= HWCAP_LOONGARCH_FPU;
135177
}
136178
#ifdef CONFIG_CPU_HAS_LSX
137-
if (config & CPUCFG2_LSX) {
179+
if ((config & CPUCFG2_LSX) && (simd >= 128)) {
138180
c->options |= LOONGARCH_CPU_LSX;
139181
elf_hwcap |= HWCAP_LOONGARCH_LSX;
140182
}
141183
#endif
142184
#ifdef CONFIG_CPU_HAS_LASX
143-
if (config & CPUCFG2_LASX) {
185+
if ((config & CPUCFG2_LASX) && (simd >= 256)) {
144186
c->options |= LOONGARCH_CPU_LASX;
145187
elf_hwcap |= HWCAP_LOONGARCH_LASX;
146188
}

0 commit comments

Comments
 (0)