linux-user: Fix /proc/cpuinfo output for sparc and hppa
PATCH v3 1/1 linux-user: Fix /proc/cpuinfo output for sparc and hppa
The sparc and hppa 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.
---
v3:
- add trailing newline at end of /proc/cpuinfo file (needed by procps)
v2:
- drop m68k part (based on feedback from Laurent Vivier <[email protected]>)
- change commit message
linux-user/syscall.c +18 -6
@@ -8310,7 +8310,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,"processor\t: %d\n" , i); +dprintf (fd,"type\t\t: sun4u\n\n" ); + }return 0 ; }#endif
@@ -8318,11 +8324,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,"processor\t: %d\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\n" ); + }return 0 ; }#endif
Quoted 56 lines · Helge Deller
The sparc and hppa architectures provide an own output for the emulated
/proc/cpuinfofile.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=1024653Avoid such issues by adding a "processor:" line for each of the online CPUs.
Signed-off-by Helge Deller <[email protected]>---
v3:
- add trailing newline at end of/proc/cpuinfofile (needed by procps)v2:
- drop m68k part (based on feedback from Laurent Vivier <[email protected]>)
- change commit messagelinux-user/syscall.c +11
-6@@ -8310,7 +8310,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,"processor\t: %d\n" , i); +dprintf (fd,"type\t\t: sun4u\n\n" ); + }return 0 ; }#endif @@ -8318,11 +8324,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++) {
linux-user/syscall.c static int open_cpuinfo(CPUArchState *cpu_env, int fd) · line 8340
Quoted 10 lines
linux-user/syscall.c +7
-0+dprintf (fd,"processor\t: %d\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\n"); + }return 0 ; }#endif
I'd rather have common code in a single open_cpuinfo() and a per-arch dprintf_cpuinfo():
static void dprintf_cpuinfo(CPUArchState *cpu_env, int fd,
unsigned cpuid)
{
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");
}
static int open_cpuinfo(CPUArchState *cpu_env, int fd)
{
int i, num_cpus; num_cpus = sysconf(_SC_NPROCESSORS_ONLN);
for (i = 0; i < num_cpus; i++) {
dprintf(fd, "processor\t: %d\n", i);
dprintf_cpuinfo(cpu_env, fd, i);
dprintf(fd, "\n");
}
return 0;}
Anyhow,
Le 28/12/2022 à 22:09, Helge Deller a écrit :
Quoted 30 lines
The sparc and hppa architectures provide an own output for the emulated
/proc/cpuinfofile.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=1024653Avoid such issues by adding a "processor:" line for each of the online CPUs.
Signed-off-by Helge Deller <[email protected]>---
v3:
- add trailing newline at end of/proc/cpuinfofile (needed by procps)v2:
- drop m68k part (based on feedback from Laurent Vivier <[email protected]>)
- change commit messagelinux-user/syscall.c +0
-0@@ -8310,7 +8310,13 @@ static int open_net_route(CPUArchState *cpu_env, int fd)#if defined(TARGET_SPARC )
linux-user/syscall.c static int open_net_route(CPUArchState *cpu_env, int fd) · line 8319
Quoted 10 lines
linux-user/syscall.c +7
-1static 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,"processor\t: %d\n" , i); +dprintf (fd,"type\t\t: sun4u\n\n" ); + }
I'm sorry, kernel on real hardware doesn't use the "processor:" entry on sparc. See show_cpuinfo() in arch/sparc/kernel/cpu.c.
In this case, fix the userspace application, as it would not work on the real hardware too.
Quoted 16 lines
linux-user/syscall.c +4
-5return 0; }#endif @@ -8318,11 +8324,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++) {
linux-user/syscall.c static int open_cpuinfo(CPUArchState *cpu_env, int fd) · line 8340
Quoted 10 lines
linux-user/syscall.c +7
-0+dprintf (fd,"processor\t: %d\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\n"); + }return 0 ; }#endif
It's good for hppa. Please, send a v4 with only hppa.
Thanks,
Laurent
PATCH v4 1/1 linux-user: Fix /proc/cpuinfo output for hppa
The hppa architectures provides 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.
---
v4:
- Drop sparc changes
v3:
- add trailing newline at end of /proc/cpuinfo file (needed by procps)
v2:
- drop m68k part (based on feedback from Laurent Vivier <[email protected]>)
- change commit message
linux-user/syscall.c +11 -5
@@ -8318,11 +8318,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,"processor\t: %d\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\n" ); + }return 0 ; }#endif
Re: [PATCH v4] linux-user: Fix /proc/cpuinfo output for hppa
Quoted 10 lines · Helge Deller
The hppa architectures provides an own output for the emulated
/proc/cpuinfofile.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
Quoted 6 lines
Avoid such issues by adding a "processor:" line for each of the online CPUs.
Signed-off-by Helge Deller<[email protected]>Reviewed-by Philippe Mathieu-Daudé<[email protected]>---
r~
Re: [PATCH v4] linux-user: Fix /proc/cpuinfo output for hppa
In reply to Helge DellerLe 27/01/2023 à 21:10, Helge Deller a écrit :
Quoted 45 lines
The hppa architectures provides an own output for the emulated
/proc/cpuinfofile.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=1024653Avoid such issues by adding a "processor:" line for each of the online CPUs.
Signed-off-by Helge Deller <[email protected]>Reviewed-by Philippe Mathieu-Daudé <[email protected]>---
v4:
- Drop sparc changesv3:
- add trailing newline at end of/proc/cpuinfofile (needed by procps)v2:
- drop m68k part (based on feedback from Laurent Vivier <[email protected]>)
- change commit messagelinux-user/syscall.c +4
-5@@ -8318,11 +8318,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++) {
linux-user/syscall.c static int open_cpuinfo(CPUArchState *cpu_env, int fd) · line 8334
Quoted 10 lines
linux-user/syscall.c +7
-0+dprintf (fd,"processor\t: %d\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\n"); + }return 0 ; }#endif
Laurent Vivier
AppliedRe: [PATCH v4] linux-user: Fix /proc/cpuinfo output for hppa
In reply to Helge DellerLe 27/01/2023 à 21:10, Helge Deller a écrit :
Quoted 45 lines
The hppa architectures provides an own output for the emulated
/proc/cpuinfofile.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=1024653Avoid such issues by adding a "processor:" line for each of the online CPUs.
Signed-off-by Helge Deller <[email protected]>Reviewed-by Philippe Mathieu-Daudé <[email protected]>---
v4:
- Drop sparc changesv3:
- add trailing newline at end of/proc/cpuinfofile (needed by procps)v2:
- drop m68k part (based on feedback from Laurent Vivier <[email protected]>)
- change commit messagelinux-user/syscall.c +4
-5@@ -8318,11 +8318,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++) {
linux-user/syscall.c static int open_cpuinfo(CPUArchState *cpu_env, int fd) · line 8334
Quoted 10 lines
linux-user/syscall.c +7
-0+dprintf (fd,"processor\t: %d\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\n"); + }return 0 ; }#endif
Applied to my linux-user-for-8.0 branch.
Thanks,
Laurent