qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Philippe Mathieu-Daudé" <philmd@linaro.org>
To: Helge Deller <deller@gmx.de>, Laurent Vivier <laurent@vivier.eu>,
	Richard Henderson <richard.henderson@linaro.org>,
	qemu-devel@nongnu.org
Subject: Re: [PATCH v3] linux-user: Fix /proc/cpuinfo output for sparc and hppa
Date: Thu, 29 Dec 2022 08:51:04 +0100	[thread overview]
Message-ID: <54a4141c-85ab-6d1e-7f52-a4320b0c6556@linaro.org> (raw)
In-Reply-To: <Y6ywbxuxqQ/cGPJW@p100>

On 28/12/22 22:09, Helge Deller wrote:
> 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.
> 
> Signed-off-by: Helge Deller <deller@gmx.de>
> 
> ---
> v3:
> - add trailing newline at end of /proc/cpuinfo file (needed by procps)
> 
> v2:
> - drop m68k part (based on feedback from Laurent Vivier <laurent@vivier.eu>)
> - change commit message
> 
> 
> diff --git a/linux-user/syscall.c b/linux-user/syscall.c
> index afb24fd0b9..5ec11a3683 100644
> --- a/linux-user/syscall.c
> +++ b/linux-user/syscall.c
> @@ -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

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,
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>



  reply	other threads:[~2022-12-29  7:51 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-12-28 21:09 [PATCH v3] linux-user: Fix /proc/cpuinfo output for sparc and hppa Helge Deller
2022-12-29  7:51 ` Philippe Mathieu-Daudé [this message]
2023-01-26 15:30 ` Laurent Vivier
2023-01-27 20:10   ` [PATCH v4] linux-user: Fix /proc/cpuinfo output for hppa Helge Deller
2023-01-27 22:53     ` Richard Henderson
2023-01-30  8:42     ` Laurent Vivier
2023-01-30  8:48     ` Laurent Vivier

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=54a4141c-85ab-6d1e-7f52-a4320b0c6556@linaro.org \
    --to=philmd@linaro.org \
    --cc=deller@gmx.de \
    --cc=laurent@vivier.eu \
    --cc=qemu-devel@nongnu.org \
    --cc=richard.henderson@linaro.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).