LoongArch: Refactor the Features output in show_cpuinfo()
PATCH 1/1 LoongArch: Refactor the Features output in show_cpuinfo()
1. Adds an hwcap_str[] mapping table, using KERNEL_HWCAP(x) (i.e., const_ilog2(HWCAP_LOONGARCH_x)) to map HWCAP bits to corresponding strings;
2. In show_cpuinfo(), iterates through hwcap_str in a loop, checks the bitmap of elf_hwcap, and prints the corresponding feature names;
3. Maintains the original output semantics (still printing the same feature names) to facilitate adding new CPU features in the future.
--- arch/loongarch/kernel/proc.c | 60 ++++++++++++++++-------------------- 1 file changed, 26 insertions(+), 34 deletions(-)
arch/loongarch/kernel/proc.c +26 -34
@@ -12,9 +12,32 @@#include <asm/idle.h> #include <asm/processor.h> #include <asm/time.h> +#include <asm/cpufeature.h> + +#define KERNEL_HWCAP (x) const_ilog2(HWCAP_LOONGARCH_ ## x) +static const char *const hwcap_str[] = { + [KERNEL_HWCAP (CPUCFG )] ="cpucfg" , + [KERNEL_HWCAP (LAM )] ="lam" , + [KERNEL_HWCAP (LAM_BH )] ="lam_bh" , + [KERNEL_HWCAP (UAL )] ="ual" , + [KERNEL_HWCAP (FPU )] ="fpu" , + [KERNEL_HWCAP (LSX )] ="lsx" , + [KERNEL_HWCAP (LASX )] ="lasx" , + [KERNEL_HWCAP (CRC32 )] ="crc32" , + [KERNEL_HWCAP (COMPLEX )] ="complex" , + [KERNEL_HWCAP (CRYPTO )] ="crypto" , + [KERNEL_HWCAP (LVZ )] ="lvz" , + [KERNEL_HWCAP (LBT_X86 )] ="lbt_x86" , + [KERNEL_HWCAP (LBT_ARM )] ="lbt_arm" , + [KERNEL_HWCAP (LBT_MIPS )] ="lbt_mips" , + [KERNEL_HWCAP (PTW )] ="ptw" , + [KERNEL_HWCAP (LSPW )] ="lspw" , + [KERNEL_HWCAP (SCQ )] ="scq" , +};static int show_cpuinfo (struct seq_file *m,void *v) { +unsigned int i;unsigned long n = (unsigned long ) v -1 ;unsigned int isa = cpu_data[n].isa_level;unsigned int prid = cpu_data[n].processor_id;
@@ -60,40 +83,9 @@ static int show_cpuinfo(struct seq_file *m, void *v)seq_puts (m,"\n" );seq_puts (m,"Features\t\t:" ); -if (cpu_has_cpucfg) -seq_puts (m," cpucfg" ); -if (cpu_has_lam) -seq_puts (m," lam" ); -if (cpu_has_lam_bh) -seq_puts (m," lam_bh" ); -if (cpu_has_scq) -seq_puts (m," scq" ); -if (cpu_has_ual) -seq_puts (m," ual" ); -if (cpu_has_fpu) -seq_puts (m," fpu" ); -if (cpu_has_lsx) -seq_puts (m," lsx" ); -if (cpu_has_lasx) -seq_puts (m," lasx" ); -if (cpu_has_crc32) -seq_puts (m," crc32" ); -if (cpu_has_complex) -seq_puts (m," complex" ); -if (cpu_has_crypto) -seq_puts (m," crypto" ); -if (cpu_has_ptw) -seq_puts (m," ptw" ); -if (cpu_has_lspw) -seq_puts (m," lspw" ); -if (cpu_has_lvz) -seq_puts (m," lvz" ); -if (cpu_has_lbt_x86) -seq_puts (m," lbt_x86" ); -if (cpu_has_lbt_arm) -seq_puts (m," lbt_arm" ); -if (cpu_has_lbt_mips) -seq_puts (m," lbt_mips" ); +for (i =0 ; i <ARRAY_SIZE (hwcap_str); i++) +if (elf_hwcap & (1 << i)) +seq_printf (m," %s" , hwcap_str[i]);seq_puts (m,"\n" );seq_printf (m,"Hardware Watchpoint\t: %s" ,str_yes_no (cpu_has_watch));
Signature · 1 line
2.20.1
Huacai Chen
maintainerhttps://lore.kernel.org/loongarch/[email protected]/
https://lore.kernel.org/loongarch/[email protected]/T/#u
What make you modify here again and again?
Is this function ugly?
Is this function has bugs?
Or for some other reasons?
Huacai
Quoted 100 lines · Qiang Ma
1. Adds an hwcap_str[] mapping table, using
KERNEL_HWCAP(x)(i.e.,const_ilog2(HWCAP_LOONGARCH_x)) to map HWCAP bits to corresponding strings;
2. Inshow_cpuinfo(), iterates throughhwcap_strin a loop, checks the bitmap ofelf_hwcap, and prints the corresponding feature names;
3. Maintains the original output semantics (still printing the same feature names) to facilitate adding new CPU features in the future.Signed-off-by Qiang Ma <[email protected]>--- arch/loongarch/kernel/proc.c | 60 ++++++++++++++++-------------------- 1 file changed, 26 insertions(+), 34 deletions(-)arch/loongarch/kernel/proc.c +26
-35@@ -12,9 +12,32 @@#include <asm/idle.h> #include <asm/processor.h> #include <asm/time.h> +#include <asm/cpufeature.h> + +#define KERNEL_HWCAP (x) const_ilog2(HWCAP_LOONGARCH_ ## x) +static const char *const hwcap_str[] = { + [KERNEL_HWCAP (CPUCFG )] ="cpucfg" , + [KERNEL_HWCAP (LAM )] ="lam" , + [KERNEL_HWCAP (LAM_BH )] ="lam_bh" , + [KERNEL_HWCAP (UAL )] ="ual" , + [KERNEL_HWCAP (FPU )] ="fpu" , + [KERNEL_HWCAP (LSX )] ="lsx" , + [KERNEL_HWCAP (LASX )] ="lasx" , + [KERNEL_HWCAP (CRC32 )] ="crc32" , + [KERNEL_HWCAP (COMPLEX )] ="complex" , + [KERNEL_HWCAP (CRYPTO )] ="crypto" , + [KERNEL_HWCAP (LVZ )] ="lvz" , + [KERNEL_HWCAP (LBT_X86 )] ="lbt_x86" , + [KERNEL_HWCAP (LBT_ARM )] ="lbt_arm" , + [KERNEL_HWCAP (LBT_MIPS )] ="lbt_mips" , + [KERNEL_HWCAP (PTW )] ="ptw" , + [KERNEL_HWCAP (LSPW )] ="lspw" , + [KERNEL_HWCAP (SCQ )] ="scq" , +};static int show_cpuinfo (struct seq_file *m,void *v) { +unsigned int i;unsigned long n = (unsigned long ) v -1 ;unsigned int isa = cpu_data[n].isa_level;unsigned int prid = cpu_data[n].processor_id;@@ -60,40 +83,9 @@ static int show_cpuinfo(struct seq_file *m, void *v)seq_puts (m,"\n" );seq_puts (m,"Features\t\t:" ); -if (cpu_has_cpucfg) -seq_puts (m," cpucfg" ); -if (cpu_has_lam) -seq_puts (m," lam" ); -if (cpu_has_lam_bh) -seq_puts (m," lam_bh" ); -if (cpu_has_scq) -seq_puts (m," scq" ); -if (cpu_has_ual) -seq_puts (m," ual" ); -if (cpu_has_fpu) -seq_puts (m," fpu" ); -if (cpu_has_lsx) -seq_puts (m," lsx" ); -if (cpu_has_lasx) -seq_puts (m," lasx" ); -if (cpu_has_crc32) -seq_puts (m," crc32" ); -if (cpu_has_complex) -seq_puts (m," complex" ); -if (cpu_has_crypto) -seq_puts (m," crypto" ); -if (cpu_has_ptw) -seq_puts (m," ptw" ); -if (cpu_has_lspw) -seq_puts (m," lspw" ); -if (cpu_has_lvz) -seq_puts (m," lvz" ); -if (cpu_has_lbt_x86) -seq_puts (m," lbt_x86" ); -if (cpu_has_lbt_arm) -seq_puts (m," lbt_arm" ); -if (cpu_has_lbt_mips) -seq_puts (m," lbt_mips" ); +for (i =0 ; i <ARRAY_SIZE (hwcap_str); i++) +if (elf_hwcap & (1 << i)) +seq_printf (m," %s" , hwcap_str[i]);seq_puts (m,"\n" );seq_printf (m,"Hardware Watchpoint\t: %s" ,str_yes_no (cpu_has_watch)); --2.20.1
Quoted 4 lines · Huacai Chen
https://lore.kernel.org/loongarch/[email protected]/
https://lore.kernel.org/loongarch/[email protected]/T/#uWhat make you modify here again and again?
Sorry, I didn't notice that the relevant patch had already been submitted.
Quoted 2 lines
Is this function ugly?
Is this function has bugs?
No
Quoted 1 line
Or for some other reasons?
I noticed that with the addition of new features to the LoongArch architecture,
new features can be conveniently added without constantly needing to add if statements, keeping the code concise.
Quoted 104 lines
Huacai
Quoted 99 lines · Qiang Ma
1. Adds an hwcap_str[] mapping table, using
KERNEL_HWCAP(x)(i.e.,const_ilog2(HWCAP_LOONGARCH_x)) to map HWCAP bits to corresponding strings;
2. Inshow_cpuinfo(), iterates throughhwcap_strin a loop, checks the bitmap ofelf_hwcap, and prints the corresponding feature names;
3. Maintains the original output semantics (still printing the same feature names) to facilitate adding new CPU features in the future.Signed-off-by Qiang Ma <[email protected]>--- arch/loongarch/kernel/proc.c | 60 ++++++++++++++++-------------------- 1 file changed, 26 insertions(+), 34 deletions(-)arch/loongarch/kernel/proc.c +26
-35@@ -12,9 +12,32 @@#include <asm/idle.h> #include <asm/processor.h> #include <asm/time.h> +#include <asm/cpufeature.h> + +#define KERNEL_HWCAP (x) const_ilog2(HWCAP_LOONGARCH_ ## x) +static const char *const hwcap_str[] = { + [KERNEL_HWCAP (CPUCFG )] ="cpucfg" , + [KERNEL_HWCAP (LAM )] ="lam" , + [KERNEL_HWCAP (LAM_BH )] ="lam_bh" , + [KERNEL_HWCAP (UAL )] ="ual" , + [KERNEL_HWCAP (FPU )] ="fpu" , + [KERNEL_HWCAP (LSX )] ="lsx" , + [KERNEL_HWCAP (LASX )] ="lasx" , + [KERNEL_HWCAP (CRC32 )] ="crc32" , + [KERNEL_HWCAP (COMPLEX )] ="complex" , + [KERNEL_HWCAP (CRYPTO )] ="crypto" , + [KERNEL_HWCAP (LVZ )] ="lvz" , + [KERNEL_HWCAP (LBT_X86 )] ="lbt_x86" , + [KERNEL_HWCAP (LBT_ARM )] ="lbt_arm" , + [KERNEL_HWCAP (LBT_MIPS )] ="lbt_mips" , + [KERNEL_HWCAP (PTW )] ="ptw" , + [KERNEL_HWCAP (LSPW )] ="lspw" , + [KERNEL_HWCAP (SCQ )] ="scq" , +};static int show_cpuinfo (struct seq_file *m,void *v) { +unsigned int i;unsigned long n = (unsigned long ) v -1 ;unsigned int isa = cpu_data[n].isa_level;unsigned int prid = cpu_data[n].processor_id;@@ -60,40 +83,9 @@ static int show_cpuinfo(struct seq_file *m, void *v)seq_puts (m,"\n" );seq_puts (m,"Features\t\t:" ); -if (cpu_has_cpucfg) -seq_puts (m," cpucfg" ); -if (cpu_has_lam) -seq_puts (m," lam" ); -if (cpu_has_lam_bh) -seq_puts (m," lam_bh" ); -if (cpu_has_scq) -seq_puts (m," scq" ); -if (cpu_has_ual) -seq_puts (m," ual" ); -if (cpu_has_fpu) -seq_puts (m," fpu" ); -if (cpu_has_lsx) -seq_puts (m," lsx" ); -if (cpu_has_lasx) -seq_puts (m," lasx" ); -if (cpu_has_crc32) -seq_puts (m," crc32" ); -if (cpu_has_complex) -seq_puts (m," complex" ); -if (cpu_has_crypto) -seq_puts (m," crypto" ); -if (cpu_has_ptw) -seq_puts (m," ptw" ); -if (cpu_has_lspw) -seq_puts (m," lspw" ); -if (cpu_has_lvz) -seq_puts (m," lvz" ); -if (cpu_has_lbt_x86) -seq_puts (m," lbt_x86" ); -if (cpu_has_lbt_arm) -seq_puts (m," lbt_arm" ); -if (cpu_has_lbt_mips) -seq_puts (m," lbt_mips" ); +for (i =0 ; i <ARRAY_SIZE (hwcap_str); i++) +if (elf_hwcap & (1 << i)) +seq_printf (m," %s" , hwcap_str[i]);seq_puts (m,"\n" );seq_printf (m,"Hardware Watchpoint\t: %s" ,str_yes_no (cpu_has_watch)); --2.20.1
Huacai Chen
maintainerQuoted 10 lines · Qiang Ma
Quoted 4 lines · Huacai Chen
https://lore.kernel.org/loongarch/[email protected]/
https://lore.kernel.org/loongarch/[email protected]/T/#uWhat make you modify here again and again?
Sorry, I didn't notice that the relevant patch had already been submitted.
Quoted 2 lines
Is this function ugly?
Is this function has bugs?
Quoted 8 lines
No
Quoted 1 line
Or for some other reasons?
I noticed that with the addition of new features to the LoongArch architecture,
new features can be conveniently added without constantly needing to add if statements, keeping the code concise.
cpuinfo are not always the same as hwcaps, stop please.
Huacai
Quoted 105 lines
Quoted 105 lines
Huacai
Quoted 99 lines · Qiang Ma
1. Adds an hwcap_str[] mapping table, using
KERNEL_HWCAP(x)(i.e.,const_ilog2(HWCAP_LOONGARCH_x)) to map HWCAP bits to corresponding strings;
2. Inshow_cpuinfo(), iterates throughhwcap_strin a loop, checks the bitmap ofelf_hwcap, and prints the corresponding feature names;
3. Maintains the original output semantics (still printing the same feature names) to facilitate adding new CPU features in the future.Signed-off-by Qiang Ma <[email protected]>--- arch/loongarch/kernel/proc.c | 60 ++++++++++++++++-------------------- 1 file changed, 26 insertions(+), 34 deletions(-)arch/loongarch/kernel/proc.c +26
-35@@ -12,9 +12,32 @@#include <asm/idle.h> #include <asm/processor.h> #include <asm/time.h> +#include <asm/cpufeature.h> + +#define KERNEL_HWCAP (x) const_ilog2(HWCAP_LOONGARCH_ ## x) +static const char *const hwcap_str[] = { + [KERNEL_HWCAP (CPUCFG )] ="cpucfg" , + [KERNEL_HWCAP (LAM )] ="lam" , + [KERNEL_HWCAP (LAM_BH )] ="lam_bh" , + [KERNEL_HWCAP (UAL )] ="ual" , + [KERNEL_HWCAP (FPU )] ="fpu" , + [KERNEL_HWCAP (LSX )] ="lsx" , + [KERNEL_HWCAP (LASX )] ="lasx" , + [KERNEL_HWCAP (CRC32 )] ="crc32" , + [KERNEL_HWCAP (COMPLEX )] ="complex" , + [KERNEL_HWCAP (CRYPTO )] ="crypto" , + [KERNEL_HWCAP (LVZ )] ="lvz" , + [KERNEL_HWCAP (LBT_X86 )] ="lbt_x86" , + [KERNEL_HWCAP (LBT_ARM )] ="lbt_arm" , + [KERNEL_HWCAP (LBT_MIPS )] ="lbt_mips" , + [KERNEL_HWCAP (PTW )] ="ptw" , + [KERNEL_HWCAP (LSPW )] ="lspw" , + [KERNEL_HWCAP (SCQ )] ="scq" , +};static int show_cpuinfo (struct seq_file *m,void *v) { +unsigned int i;unsigned long n = (unsigned long ) v -1 ;unsigned int isa = cpu_data[n].isa_level;unsigned int prid = cpu_data[n].processor_id;@@ -60,40 +83,9 @@ static int show_cpuinfo(struct seq_file *m, void *v)seq_puts (m,"\n" );seq_puts (m,"Features\t\t:" ); -if (cpu_has_cpucfg) -seq_puts (m," cpucfg" ); -if (cpu_has_lam) -seq_puts (m," lam" ); -if (cpu_has_lam_bh) -seq_puts (m," lam_bh" ); -if (cpu_has_scq) -seq_puts (m," scq" ); -if (cpu_has_ual) -seq_puts (m," ual" ); -if (cpu_has_fpu) -seq_puts (m," fpu" ); -if (cpu_has_lsx) -seq_puts (m," lsx" ); -if (cpu_has_lasx) -seq_puts (m," lasx" ); -if (cpu_has_crc32) -seq_puts (m," crc32" ); -if (cpu_has_complex) -seq_puts (m," complex" ); -if (cpu_has_crypto) -seq_puts (m," crypto" ); -if (cpu_has_ptw) -seq_puts (m," ptw" ); -if (cpu_has_lspw) -seq_puts (m," lspw" ); -if (cpu_has_lvz) -seq_puts (m," lvz" ); -if (cpu_has_lbt_x86) -seq_puts (m," lbt_x86" ); -if (cpu_has_lbt_arm) -seq_puts (m," lbt_arm" ); -if (cpu_has_lbt_mips) -seq_puts (m," lbt_mips" ); +for (i =0 ; i <ARRAY_SIZE (hwcap_str); i++) +if (elf_hwcap & (1 << i)) +seq_printf (m," %s" , hwcap_str[i]);seq_puts (m,"\n" );seq_printf (m,"Hardware Watchpoint\t: %s" ,str_yes_no (cpu_has_watch)); --2.20.1