linux-user: Fix /proc/cpuinfo output for sparc and hppa
PATCH v2 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.
---
v2:
- drop m68k part (based on feedback from Laurent Vivier <[email protected]>)
- change commit message
linux-user/syscall.c +18 -6
@@ -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
Quoted 26 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]>---
v2:
- drop m68k part (based on feedback from Laurent Vivier <[email protected]>)
- change commit messagelinux-user/syscall.c +0
-0
linux-user/syscall.c static int open_net_route(CPUArchState *cpu_env, int fd) · line 8306
Quoted 9 lines
linux-user/syscall.c +5
-1@@ -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);
it turned out, that the procps tools expect the /proc/cpuinfo file to have a trailing \n at the end of the file.
So, I'll respin this patch and send a v3 version to replace this conditional \n-output.
Same applies for the hppa arch.....
Quoted 9 lines
linux-user/syscall.c +2
-0+ 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) {
linux-user/syscall.c static int open_cpuinfo(CPUArchState *cpu_env, int fd) · line 8320
Quoted 10 lines
linux-user/syscall.c +5
-5-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);
^^ here.
Helge
Quoted 9 lines
linux-user/syscall.c +6
-0+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