Skip to contentSkip to conversation

linux-user: Enhance /proc/cpuinfo output for sparc, hppa and m68k

PATCH Superseded Helge Deller 2 participants 3 messages Dec 13, 2022

v1 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 linux-user: Enhance /proc/cpuinfo output for sparc, hppa and m68k

The sparc, hppa and m68k architectures provide an own output for the emulated /proc/cpuinfo file.

Some userspace applications count (even if that's not the recommended way) the number of lines which start with "processor:" and assume that this number then reflects the number of online CPUs. Since those 3 architectures don't provide any such line, applications may assume "0" CPUs. One such issue can be seen in debian bug report:
https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=1024653

Avoid such issues by adding a "processor:" line for each of the online CPUs.

linux-user/syscall.c +19 -6
index 9e2c0a18fc..d58e9b8d10 100644
@@ -8299,7 +8299,13 @@ static int open_net_route(CPUArchState *cpu_env, int fd)
 #if defined(TARGET_SPARC)
 static int open_cpuinfo(CPUArchState *cpu_env, int fd)
 {
-    dprintf(fd, "type\t\t: sun4u\n");
+    int i, num_cpus;
+
+    num_cpus = sysconf(_SC_NPROCESSORS_ONLN);
+    for (i = 0; i < num_cpus; i++) {
+        dprintf(fd, "%sprocessor\t: %d\n", (i > 0) ? "\n":"", i);
+        dprintf(fd, "type\t\t: sun4u\n");
+    }
     return 0;
 }
 #endif
@@ -8307,11 +8313,17 @@ static int open_cpuinfo(CPUArchState *cpu_env, int fd)
 #if defined(TARGET_HPPA)
 static int open_cpuinfo(CPUArchState *cpu_env, int fd)
 {
-    dprintf(fd, "cpu family\t: PA-RISC 1.1e\n");
-    dprintf(fd, "cpu\t\t: PA7300LC (PCX-L2)\n");
-    dprintf(fd, "capabilities\t: os32\n");
-    dprintf(fd, "model\t\t: 9000/778/B160L\n");
-    dprintf(fd, "model name\t: Merlin L2 160 QEMU (9000/778/B160L)\n");
+    int i, num_cpus;
+
+    num_cpus = sysconf(_SC_NPROCESSORS_ONLN);
+    for (i = 0; i < num_cpus; i++) {
+        dprintf(fd, "%sprocessor\t: %d\n", (i > 0) ? "\n":"", i);
+        dprintf(fd, "cpu family\t: PA-RISC 1.1e\n");
+        dprintf(fd, "cpu\t\t: PA7300LC (PCX-L2)\n");
+        dprintf(fd, "capabilities\t: os32\n");
+        dprintf(fd, "model\t\t: 9000/778/B160L - "
+                    "Merlin L2 160 QEMU (9000/778/B160L)\n");
+    }
     return 0;
 }
 #endif
@@ -8319,6 +8331,7 @@ static int open_cpuinfo(CPUArchState *cpu_env, int fd)
 #if defined(TARGET_M68K)
 static int open_hardware(CPUArchState *cpu_env, int fd)
 {
+    dprintf(fd, "processor\t: 0\n");
     dprintf(fd, "Model:\t\tqemu-m68k\n");
     return 0;
 }
#1 lore raw

Le 13/12/2022 à 17:10, Helge Deller a écrit :

Quoted 9 lines

The sparc, hppa and m68k architectures provide an own output for the emulated /proc/cpuinfo file.

Some userspace applications count (even if that's not the recommended way) the number of lines which start with "processor:" and assume that this number then reflects the number of online CPUs. Since those 3 architectures don't provide any such line, applications may assume "0" CPUs. One such issue can be seen in debian bug report:
https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=1024653

Why don't they use something like system("getconf _NPROCESSORS_CONF") ?

Quoted 10 lines

Avoid such issues by adding a "processor:" line for each of the online CPUs.

linux-user/syscall.c +0 -0
index 9e2c0a18fc..d58e9b8d10 100644

...

linux-user/syscall.c static int open_cpuinfo(CPUArchState *cpu_env, int fd) · line 8337

Quoted 8 lines
linux-user/syscall.c +1 -0
@@ -8319,6 +8331,7 @@ static int open_cpuinfo(CPUArchState *cpu_env, int fd)
  #if defined(TARGET_M68K)
  static int open_hardware(CPUArchState *cpu_env, int fd)
  {
+    dprintf(fd, "processor\t: 0\n");
      dprintf(fd, "Model:\t\tqemu-m68k\n");
      return 0;
  }

This is /proc/hardware, not /proc/cpuinfo.

root@debian10-vm1:~# cat /proc/hardware
Model:		Macintosh Quadra 800
System Memory:	1025024K
root@debian10-vm1:~# cat /proc/cpuinfo
CPU:		68040
MMU:		68040
FPU:		68040
Clocking:	1529.8MHz
BogoMips:	1019.90
Calibration:	5099520 loops

And on m68k, no one expects to have a "processor" line.

Thanks,
Laurent

#2 lore raw
Quoted 4 lines · Laurent Vivier

Le 13/12/2022 à 17:10, Helge Deller a écrit :

Quoted 3 lines

The sparc, hppa and m68k architectures provide an own output for the emulated /proc/cpuinfo file.

Quoted 8 lines
Quoted 6 lines

Some userspace applications count (even if that's not the recommended way) the number of lines which start with "processor:" and assume that this number then reflects the number of online CPUs. Since those 3 architectures don't provide any such line, applications may assume "0" CPUs.  One such issue can be seen in debian bug report:
https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=1024653

Why don't they use something like system("getconf _NPROCESSORS_CONF") ?

Yes, something like that.
Any return value other than 0 would have been sufficient at least. But sadly that's not the only program which does it that way. Just search the internet and you'll find tons of such posts to use "processor:" from /proc/cpuinfo.

Quoted 10 lines
Quoted 9 lines

Avoid such issues by adding a "processor:" line for each of the online CPUs.

linux-user/syscall.c +0 -0
index 9e2c0a18fc..d58e9b8d10 100644

...

Quoted 10 lines

linux-user/syscall.c static int open_cpuinfo(CPUArchState *cpu_env, int fd) · line 8337

Quoted 8 lines
linux-user/syscall.c +1 -0
@@ -8319,6 +8331,7 @@ static int open_cpuinfo(CPUArchState *cpu_env, int fd)
   #if defined(TARGET_M68K)
   static int open_hardware(CPUArchState *cpu_env, int fd)
   {
+    dprintf(fd, "processor\t: 0\n");
       dprintf(fd, "Model:\t\tqemu-m68k\n");
       return 0;
   }

This is /proc/hardware, not /proc/cpuinfo.

Oops... you are right!
I'll drop this hunk.

Thanks!
Helge

Quoted 16 lines
root@debian10-vm1:~# cat /proc/hardware
Model:        Macintosh Quadra 800
System Memory:    1025024K
root@debian10-vm1:~# cat /proc/cpuinfo
CPU:        68040
MMU:        68040
FPU:        68040
Clocking:    1529.8MHz
BogoMips:    1019.90
Calibration:    5099520 loops

And on m68k, no one expects to have a "processor" line.

Thanks,
Laurent