Skip to contentSkip to conversation

RISC-V: Show CPU ID and Hart ID separately in /proc/cpuinfo

PATCH Superseded Anup Patel 4 participants 8 messages Sep 12, 2018 – Oct 1, 2018 RISC-V

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Anup Patel

author
#0 lore raw

PATCH 1/1 RISC-V: Show CPU ID and Hart ID separately in /proc/cpuinfo

Currently, /proc/cpuinfo show logical CPU ID as Hart ID which is in-correct. This patch shows CPU ID and Hart ID separately in /proc/cpuinfo using cpuid_to_hardid_map().

With this patch, contents of /proc/cpuinfo looks as follows:
cpu : 0
hart : 1
isa : rv64imafdcsu
mmu : sv48

cpu : 1
hart : 0
isa : rv64imafdcsu
mmu : sv48

cpu : 2
hart : 3
isa : rv64imafdcsu
mmu : sv48

cpu : 3
hart : 2
isa : rv64imafdcsu
mmu : sv48

---
 arch/riscv/kernel/cpu.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
arch/riscv/kernel/cpu.c +2 -1
index f0f0ec2737b7..7c1342e242e6 100644
@@ -87,7 +87,8 @@ static int c_show(struct seq_file *m, void *v)
 						   NULL);
 	const char *compat, *isa, *mmu;
 
-	seq_printf(m, "hart\t: %lu\n", cpu_id);
+	seq_printf(m, "cpu\t: %lu\n", cpu_id);
+	seq_printf(m, "hart\t: %lu\n", cpuid_to_hardid_map(cpu_id));
 	if (!of_property_read_string(node, "riscv,isa", &isa)
 	    && isa[0] == 'r'
 	    && isa[1] == 'v')
Signature · 1 line
2.17.1
#1 lore raw
Quoted 36 lines · Anup Patel

Currently, /proc/cpuinfo show logical CPU ID as Hart ID which is in-correct. This patch shows CPU ID and Hart ID separately in /proc/cpuinfo using cpuid_to_hardid_map().

With this patch, contents of /proc/cpuinfo looks as follows:
cpu : 0
hart : 1
isa : rv64imafdcsu
mmu : sv48

cpu : 1
hart : 0
isa : rv64imafdcsu
mmu : sv48

cpu : 2
hart : 3
isa : rv64imafdcsu
mmu : sv48

cpu : 3
hart : 2
isa : rv64imafdcsu
mmu : sv48

---
  arch/riscv/kernel/cpu.c | 3 ++-
  1 file changed, 2 insertions(+), 1 deletion(-)
arch/riscv/kernel/cpu.c +0 -0
index f0f0ec2737b7..7c1342e242e6 100644

arch/riscv/kernel/cpu.c static int c_show(struct seq_file *m, void *v) · line 94

Quoted 9 lines
arch/riscv/kernel/cpu.c +2 -1
@@ -87,7 +87,8 @@ static int c_show(struct seq_file *m, void *v)
  						   NULL);
  	const char *compat, *isa, *mmu;
 
-	seq_printf(m, "hart\t: %lu\n", cpu_id);
+	seq_printf(m, "cpu\t: %lu\n", cpu_id);
+	seq_printf(m, "hart\t: %lu\n", cpuid_to_hardid_map(cpu_id));
  	if (!of_property_read_string(node, "riscv,isa", &isa)
  	    && isa[0] == 'r'
  	    && isa[1] == 'v')

The extra hart information will not be parsed by lscpu which will make the cpu information inconsistent between lscpu & /proc/cpuinfo.

Should we patch lscpu as well to show correct hart id as well ?

Regards,
Atish

author
#2 lore raw
Quoted 51 lines · Atish Patra
Quoted 36 lines · Anup Patel

Currently, /proc/cpuinfo show logical CPU ID as Hart ID which is in-correct. This patch shows CPU ID and Hart ID separately in /proc/cpuinfo using cpuid_to_hardid_map().

With this patch, contents of /proc/cpuinfo looks as follows:
cpu : 0
hart : 1
isa : rv64imafdcsu
mmu : sv48

cpu : 1
hart : 0
isa : rv64imafdcsu
mmu : sv48

cpu : 2
hart : 3
isa : rv64imafdcsu
mmu : sv48

cpu : 3
hart : 2
isa : rv64imafdcsu
mmu : sv48

---
  arch/riscv/kernel/cpu.c | 3 ++-
  1 file changed, 2 insertions(+), 1 deletion(-)
arch/riscv/kernel/cpu.c +0 -0
index f0f0ec2737b7..7c1342e242e6 100644

arch/riscv/kernel/cpu.c static int c_show(struct seq_file *m, void *v) · line 94

Quoted 9 lines
arch/riscv/kernel/cpu.c +2 -1
@@ -87,7 +87,8 @@ static int c_show(struct seq_file *m, void *v)
                                                 NULL);
      const char *compat, *isa, *mmu;
 
-     seq_printf(m, "hart\t: %lu\n", cpu_id);
+     seq_printf(m, "cpu\t: %lu\n", cpu_id);
+     seq_printf(m, "hart\t: %lu\n", cpuid_to_hardid_map(cpu_id));
      if (!of_property_read_string(node, "riscv,isa", &isa)
          && isa[0] == 'r'
          && isa[1] == 'v')

The extra hart information will not be parsed by lscpu which will make the cpu information inconsistent between lscpu & /proc/cpuinfo.

Quoted 1 line

Should we patch lscpu as well to show correct hart id as well ?

Yes, we should certainly patch lscpu to parse CPU ID and HART ID differently.

Regards,
Anup

#3 lore raw
In reply to Atish Patra
Quoted 4 lines · Atish Patra

The extra hart information will not be parsed by lscpu which will make the cpu information inconsistent between lscpu & /proc/cpuinfo.

Should we patch lscpu as well to show correct hart id as well ?

It would be good to follow whatever prescedent other architectures with different logical vs physical cpuids have set.

author
#4 lore raw
Quoted 9 lines · Christoph Hellwig
Quoted 4 lines · Atish Patra

The extra hart information will not be parsed by lscpu which will make the cpu information inconsistent between lscpu & /proc/cpuinfo.

Should we patch lscpu as well to show correct hart id as well ?

It would be good to follow whatever prescedent other architectures with different logical vs physical cpuids have set.

Most architectures (x86, ARM, ARM64), display logical CPU id as "processor" attribute. I think we should use same name for logical CPU id.

Other attributes in /proc/cpuinfo are very different accros architectures. For e.g. x86 shows physical CPU id as "core id"

I will revise this patch to use "processor" attribute name for logical CPU id.

Regards,
Anup

#5 lore raw
In reply to Anup Patel
Quoted 35 lines · anup at brainfault.org

Currently, /proc/cpuinfo show logical CPU ID as Hart ID which is in-correct. This patch shows CPU ID and Hart ID separately in /proc/cpuinfo using cpuid_to_hardid_map().

With this patch, contents of /proc/cpuinfo looks as follows:
cpu : 0
hart : 1
isa : rv64imafdcsu
mmu : sv48

cpu : 1
hart : 0
isa : rv64imafdcsu
mmu : sv48

cpu : 2
hart : 3
isa : rv64imafdcsu
mmu : sv48

cpu : 3
hart : 2
isa : rv64imafdcsu
mmu : sv48

---
 arch/riscv/kernel/cpu.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
arch/riscv/kernel/cpu.c +0 -0
index f0f0ec2737b7..7c1342e242e6 100644

arch/riscv/kernel/cpu.c static int c_show(struct seq_file *m, void *v) · line 94

Quoted 9 lines
arch/riscv/kernel/cpu.c +2 -1
@@ -87,7 +87,8 @@ static int c_show(struct seq_file *m, void *v)
 						   NULL);
 	const char *compat, *isa, *mmu;
 
-	seq_printf(m, "hart\t: %lu\n", cpu_id);
+	seq_printf(m, "cpu\t: %lu\n", cpu_id);
+	seq_printf(m, "hart\t: %lu\n", cpuid_to_hardid_map(cpu_id));
 	if (!of_property_read_string(node, "riscv,isa", &isa)
 	    && isa[0] == 'r'
 	    && isa[1] == 'v')

I like this, but it doesn't appear to apply. Do you mind sending something against Linus' master? Then I should be able to sort it out.

Thanks!

author
#6 lore raw
Quoted 40 lines · Palmer Dabbelt
Quoted 38 lines · anup at brainfault.org

Currently, /proc/cpuinfo show logical CPU ID as Hart ID which is in-correct. This patch shows CPU ID and Hart ID separately in /proc/cpuinfo using cpuid_to_hardid_map().

With this patch, contents of /proc/cpuinfo looks as follows:
cpu : 0
hart : 1
isa : rv64imafdcsu
mmu : sv48

cpu : 1
hart : 0
isa : rv64imafdcsu
mmu : sv48

cpu : 2
hart : 3
isa : rv64imafdcsu
mmu : sv48

cpu : 3
hart : 2
isa : rv64imafdcsu
mmu : sv48

---
 arch/riscv/kernel/cpu.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
arch/riscv/kernel/cpu.c +0 -0
index f0f0ec2737b7..7c1342e242e6 100644
@@ -87,7 +87,8 @@ static int c_show(struct seq_file *m, void *v)
                                                 NULL);
      const char *compat, *isa, *mmu;
 
Quoted 10 lines

arch/riscv/kernel/cpu.c static int c_show(struct seq_file *m, void *v) · line 94

Quoted 6 lines
arch/riscv/kernel/cpu.c +2 -1
-     seq_printf(m, "hart\t: %lu\n", cpu_id);
+     seq_printf(m, "cpu\t: %lu\n", cpu_id);
+     seq_printf(m, "hart\t: %lu\n", cpuid_to_hardid_map(cpu_id));
      if (!of_property_read_string(node, "riscv,isa", &isa)
          && isa[0] == 'r'
          && isa[1] == 'v')

I like this, but it doesn't appear to apply. Do you mind sending something against Linus' master? Then I should be able to sort it out.

This patch is requires cpuid_to_hardid_map() added by Atish's patchset so I have requested Atish to make this patch part of his v6 patchset.

Thanks,
Anup

#7 lore raw
Quoted 52 lines · anup at brainfault.org
Quoted 40 lines · Palmer Dabbelt
Quoted 38 lines · anup at brainfault.org

Currently, /proc/cpuinfo show logical CPU ID as Hart ID which is in-correct. This patch shows CPU ID and Hart ID separately in /proc/cpuinfo using cpuid_to_hardid_map().

With this patch, contents of /proc/cpuinfo looks as follows:
cpu : 0
hart : 1
isa : rv64imafdcsu
mmu : sv48

cpu : 1
hart : 0
isa : rv64imafdcsu
mmu : sv48

cpu : 2
hart : 3
isa : rv64imafdcsu
mmu : sv48

cpu : 3
hart : 2
isa : rv64imafdcsu
mmu : sv48

---
 arch/riscv/kernel/cpu.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
arch/riscv/kernel/cpu.c +0 -0
index f0f0ec2737b7..7c1342e242e6 100644
@@ -87,7 +87,8 @@ static int c_show(struct seq_file *m, void *v)
                                                 NULL);
      const char *compat, *isa, *mmu;
 
Quoted 10 lines

arch/riscv/kernel/cpu.c static int c_show(struct seq_file *m, void *v) · line 94

Quoted 6 lines
arch/riscv/kernel/cpu.c +2 -1
-     seq_printf(m, "hart\t: %lu\n", cpu_id);
+     seq_printf(m, "cpu\t: %lu\n", cpu_id);
+     seq_printf(m, "hart\t: %lu\n", cpuid_to_hardid_map(cpu_id));
      if (!of_property_read_string(node, "riscv,isa", &isa)
          && isa[0] == 'r'
          && isa[1] == 'v')

I like this, but it doesn't appear to apply. Do you mind sending something against Linus' master? Then I should be able to sort it out.

Quoted 3 lines

This patch is requires cpuid_to_hardid_map() added by Atish's patchset so I have requested Atish to make this patch part of his v6 patchset.

Thanks!