All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] linux-user: Implement /proc/cpuinfo for ppc cpus
@ 2026-06-10 18:06 Helge Deller
  2026-06-10 18:49 ` Richard Henderson
  0 siblings, 1 reply; 4+ messages in thread
From: Helge Deller @ 2026-06-10 18:06 UTC (permalink / raw)
  To: qemu-devel; +Cc: Helge Deller, qemu-ppc, Richard Henderson

From: Helge Deller <deller@gmx.de>

I've tried to mimic what I've seen on two debian porterboxes (ppc64 and
ppc64le), which are running via KVM/QEMU. I assume the model type of
pSeries and such doesn't make much sense for some older ppc chips, so
any better suggestions here are welcome.

v2: drop colon, add clock output, refine pvr calculation
(@Richard: I suggest to completely drop the clock for v3 ?!?!)

Signed-off-by: Helge Deller <deller@gmx.de>
Cc: qemu-ppc@nongnu.org
Cc: Richard Henderson <richard.henderson@linaro.org>
---
 linux-user/ppc/target_proc.h | 91 +++++++++++++++++++++++++++++++++++-
 1 file changed, 90 insertions(+), 1 deletion(-)

diff --git a/linux-user/ppc/target_proc.h b/linux-user/ppc/target_proc.h
index 43fe29ca72..6d78c0f543 100644
--- a/linux-user/ppc/target_proc.h
+++ b/linux-user/ppc/target_proc.h
@@ -1 +1,90 @@
-/* No target-specific /proc support */
+/*
+ * ppc specific proc functions for linux-user
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+#ifndef PPC_TARGET_PROC_H
+#define PPC_TARGET_PROC_H
+
+#include <time.h>
+
+#define PVR_VER(pvr)    (((pvr) >>  16) & 0xFFFF)      /* Version field */
+#define PVR_REV(pvr)    (((pvr) >>   0) & 0xFFFF)      /* Revison field */
+#define PVR_MAJ(pvr)    (((pvr) >>  4) & 0xF)   /* Major revision field */
+#define PVR_MIN(pvr)    (((pvr) >>  0) & 0xF)   /* Minor revision field */
+
+static int open_cpuinfo(CPUArchState *cpu_env, int fd)
+{
+    struct timespec res;
+    double freq_mhz;
+    int i, num_cpus;
+    unsigned int maj, min, pvr;
+
+    PowerPCCPUClass *pcc = POWERPC_CPU_GET_CLASS(env_cpu(cpu_env));
+    DeviceClass *dc = DEVICE_CLASS(ppc_cpu_get_family_class(pcc));
+
+    pvr = pcc->pvr;
+
+    /* Taken from Linux kernel: */
+    /* If we are a Freescale core do a simple check so
+     * we don't have to keep adding cases in the future */
+    if (PVR_VER(pvr) & 0x8000) {
+            switch (PVR_VER(pvr)) {
+            case 0x8000:	/* 7441/7450/7451, Voyager */
+            case 0x8001:	/* 7445/7455, Apollo 6 */
+            case 0x8002:	/* 7447/7457, Apollo 7 */
+            case 0x8003:	/* 7447A, Apollo 7 PM */
+            case 0x8004:	/* 7448, Apollo 8 */
+            case 0x800c:	/* 7410, Nitro */
+                    maj = ((pvr >> 8) & 0xF);
+                    min = PVR_MIN(pvr);
+                    break;
+            default:	/* e500/book-e */
+                    maj = PVR_MAJ(pvr);
+                    min = PVR_MIN(pvr);
+                    break;
+            }
+    } else {
+            switch (PVR_VER(pvr)) {
+                    case 0x1008:	/* 740P/750P ?? */
+                            maj = ((pvr >> 8) & 0xFF) - 1;
+                            min = pvr & 0xFF;
+                            break;
+                    case 0x004e: /* POWER9 bits 12-15 give chip type */
+                    case 0x0080: /* POWER10 bit 12 gives SMT8/4 */
+                            maj = (pvr >> 8) & 0x0F;
+                            min = pvr & 0xFF;
+                            break;
+                    default:
+                            maj = (pvr >> 8) & 0xFF;
+                            min = pvr & 0xFF;
+                            break;
+            }
+    }
+
+    if (clock_getres(CLOCK_REALTIME, &res) == -1) {
+        res.tv_nsec = 1;
+    }
+    freq_mhz = 1000.0 / res.tv_nsec;
+
+    num_cpus = sysconf(_SC_NPROCESSORS_ONLN);
+    for (i = 0; i < num_cpus; i++) {
+        dprintf(fd, "processor:\t: %d\n", i);
+        dprintf(fd, "cpu\t\t: %s%s\n",
+                    dc->desc,
+                    pcc->insns_flags & PPC_ALTIVEC ? ", altivec supported":"");
+        dprintf(fd, "clock\t\t: %.3fMHz\n", freq_mhz);
+        dprintf(fd, "revision\t: %d.%d (pvr %04x %04x)\n\n",
+                    maj, min, PVR_VER(pvr), PVR_REV(pvr));
+    }
+
+    dprintf(fd, "timebase\t: 512000000\n");
+    dprintf(fd, "platform\t: pSeries\n");
+    dprintf(fd, "model\t\t: IBM pSeries (QEMU user v" QEMU_VERSION ")\n");
+    dprintf(fd, "machine\t\t: CHRP IBM pSeries\n");
+
+    return 0;
+}
+#define HAVE_ARCH_PROC_CPUINFO
+
+#endif /* PPC_TARGET_PROC_H */
-- 
2.54.0



^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH v2] linux-user: Implement /proc/cpuinfo for ppc cpus
  2026-06-10 18:06 [PATCH v2] linux-user: Implement /proc/cpuinfo for ppc cpus Helge Deller
@ 2026-06-10 18:49 ` Richard Henderson
  2026-06-10 19:13   ` Helge Deller
  0 siblings, 1 reply; 4+ messages in thread
From: Richard Henderson @ 2026-06-10 18:49 UTC (permalink / raw)
  To: Helge Deller, qemu-devel; +Cc: Helge Deller, qemu-ppc

On 6/10/26 11:06, Helge Deller wrote:
> From: Helge Deller <deller@gmx.de>
> 
> I've tried to mimic what I've seen on two debian porterboxes (ppc64 and
> ppc64le), which are running via KVM/QEMU. I assume the model type of
> pSeries and such doesn't make much sense for some older ppc chips, so
> any better suggestions here are welcome.
> 
> v2: drop colon, add clock output, refine pvr calculation
> (@Richard: I suggest to completely drop the clock for v3 ?!?!)
> 
> Signed-off-by: Helge Deller <deller@gmx.de>
> Cc: qemu-ppc@nongnu.org
> Cc: Richard Henderson <richard.henderson@linaro.org>
> ---
>   linux-user/ppc/target_proc.h | 91 +++++++++++++++++++++++++++++++++++-
>   1 file changed, 90 insertions(+), 1 deletion(-)
> 
> diff --git a/linux-user/ppc/target_proc.h b/linux-user/ppc/target_proc.h
> index 43fe29ca72..6d78c0f543 100644
> --- a/linux-user/ppc/target_proc.h
> +++ b/linux-user/ppc/target_proc.h
> @@ -1 +1,90 @@
> -/* No target-specific /proc support */
> +/*
> + * ppc specific proc functions for linux-user
> + *
> + * SPDX-License-Identifier: GPL-2.0-or-later
> + */
> +#ifndef PPC_TARGET_PROC_H
> +#define PPC_TARGET_PROC_H
> +
> +#include <time.h>
> +
> +#define PVR_VER(pvr)    (((pvr) >>  16) & 0xFFFF)      /* Version field */
> +#define PVR_REV(pvr)    (((pvr) >>   0) & 0xFFFF)      /* Revison field */
> +#define PVR_MAJ(pvr)    (((pvr) >>  4) & 0xF)   /* Major revision field */
> +#define PVR_MIN(pvr)    (((pvr) >>  0) & 0xF)   /* Minor revision field */
> +
> +static int open_cpuinfo(CPUArchState *cpu_env, int fd)
> +{
> +    struct timespec res;
> +    double freq_mhz;
> +    int i, num_cpus;
> +    unsigned int maj, min, pvr;
> +
> +    PowerPCCPUClass *pcc = POWERPC_CPU_GET_CLASS(env_cpu(cpu_env));
> +    DeviceClass *dc = DEVICE_CLASS(ppc_cpu_get_family_class(pcc));
> +
> +    pvr = pcc->pvr;
> +
> +    /* Taken from Linux kernel: */
> +    /* If we are a Freescale core do a simple check so
> +     * we don't have to keep adding cases in the future */
> +    if (PVR_VER(pvr) & 0x8000) {
> +            switch (PVR_VER(pvr)) {
> +            case 0x8000:	/* 7441/7450/7451, Voyager */
> +            case 0x8001:	/* 7445/7455, Apollo 6 */
> +            case 0x8002:	/* 7447/7457, Apollo 7 */
> +            case 0x8003:	/* 7447A, Apollo 7 PM */
> +            case 0x8004:	/* 7448, Apollo 8 */
> +            case 0x800c:	/* 7410, Nitro */
> +                    maj = ((pvr >> 8) & 0xF);
> +                    min = PVR_MIN(pvr);
> +                    break;
> +            default:	/* e500/book-e */
> +                    maj = PVR_MAJ(pvr);
> +                    min = PVR_MIN(pvr);
> +                    break;
> +            }
> +    } else {
> +            switch (PVR_VER(pvr)) {
> +                    case 0x1008:	/* 740P/750P ?? */
> +                            maj = ((pvr >> 8) & 0xFF) - 1;
> +                            min = pvr & 0xFF;
> +                            break;
> +                    case 0x004e: /* POWER9 bits 12-15 give chip type */
> +                    case 0x0080: /* POWER10 bit 12 gives SMT8/4 */
> +                            maj = (pvr >> 8) & 0x0F;
> +                            min = pvr & 0xFF;
> +                            break;
> +                    default:
> +                            maj = (pvr >> 8) & 0xFF;
> +                            min = pvr & 0xFF;
> +                            break;
> +            }
> +    }

Reindent for qemu style.

> +
> +    if (clock_getres(CLOCK_REALTIME, &res) == -1) {
> +        res.tv_nsec = 1;
> +    }
> +    freq_mhz = 1000.0 / res.tv_nsec;

Seems ok.

> +        dprintf(fd, "processor:\t: %d\n", i);

Still have an extra : here.


r~


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v2] linux-user: Implement /proc/cpuinfo for ppc cpus
  2026-06-10 18:49 ` Richard Henderson
@ 2026-06-10 19:13   ` Helge Deller
  2026-06-10 21:14     ` Richard Henderson
  0 siblings, 1 reply; 4+ messages in thread
From: Helge Deller @ 2026-06-10 19:13 UTC (permalink / raw)
  To: Richard Henderson, Helge Deller, qemu-devel; +Cc: qemu-ppc

On 6/10/26 20:49, Richard Henderson wrote:
> On 6/10/26 11:06, Helge Deller wrote:
>> From: Helge Deller <deller@gmx.de>
>>
>> I've tried to mimic what I've seen on two debian porterboxes (ppc64 and
>> ppc64le), which are running via KVM/QEMU. I assume the model type of
>> pSeries and such doesn't make much sense for some older ppc chips, so
>> any better suggestions here are welcome.
>>
>> v2: drop colon, add clock output, refine pvr calculation
>> (@Richard: I suggest to completely drop the clock for v3 ?!?!)
>>
>> Signed-off-by: Helge Deller <deller@gmx.de>
>> Cc: qemu-ppc@nongnu.org
>> Cc: Richard Henderson <richard.henderson@linaro.org>
>> ---
>>   linux-user/ppc/target_proc.h | 91 +++++++++++++++++++++++++++++++++++-
>>   1 file changed, 90 insertions(+), 1 deletion(-)
>>
>> diff --git a/linux-user/ppc/target_proc.h b/linux-user/ppc/target_proc.h
>> index 43fe29ca72..6d78c0f543 100644
>> --- a/linux-user/ppc/target_proc.h
>> +++ b/linux-user/ppc/target_proc.h
>> @@ -1 +1,90 @@
>> -/* No target-specific /proc support */
>> +/*
>> + * ppc specific proc functions for linux-user
>> + *
>> + * SPDX-License-Identifier: GPL-2.0-or-later
>> + */
>> +#ifndef PPC_TARGET_PROC_H
>> +#define PPC_TARGET_PROC_H
>> +
>> +#include <time.h>
>> +
>> +#define PVR_VER(pvr)    (((pvr) >>  16) & 0xFFFF)      /* Version field */
>> +#define PVR_REV(pvr)    (((pvr) >>   0) & 0xFFFF)      /* Revison field */
>> +#define PVR_MAJ(pvr)    (((pvr) >>  4) & 0xF)   /* Major revision field */
>> +#define PVR_MIN(pvr)    (((pvr) >>  0) & 0xF)   /* Minor revision field */
>> +
>> +static int open_cpuinfo(CPUArchState *cpu_env, int fd)
>> +{
>> +    struct timespec res;
>> +    double freq_mhz;
>> +    int i, num_cpus;
>> +    unsigned int maj, min, pvr;
>> +
>> +    PowerPCCPUClass *pcc = POWERPC_CPU_GET_CLASS(env_cpu(cpu_env));
>> +    DeviceClass *dc = DEVICE_CLASS(ppc_cpu_get_family_class(pcc));
>> +
>> +    pvr = pcc->pvr;
>> +
>> +    /* Taken from Linux kernel: */
>> +    /* If we are a Freescale core do a simple check so
>> +     * we don't have to keep adding cases in the future */
>> +    if (PVR_VER(pvr) & 0x8000) {
>> +            switch (PVR_VER(pvr)) {
>> +            case 0x8000:    /* 7441/7450/7451, Voyager */
>> +            case 0x8001:    /* 7445/7455, Apollo 6 */
>> +            case 0x8002:    /* 7447/7457, Apollo 7 */
>> +            case 0x8003:    /* 7447A, Apollo 7 PM */
>> +            case 0x8004:    /* 7448, Apollo 8 */
>> +            case 0x800c:    /* 7410, Nitro */
>> +                    maj = ((pvr >> 8) & 0xF);
>> +                    min = PVR_MIN(pvr);
>> +                    break;
>> +            default:    /* e500/book-e */
>> +                    maj = PVR_MAJ(pvr);
>> +                    min = PVR_MIN(pvr);
>> +                    break;
>> +            }
>> +    } else {
>> +            switch (PVR_VER(pvr)) {
>> +                    case 0x1008:    /* 740P/750P ?? */
>> +                            maj = ((pvr >> 8) & 0xFF) - 1;
>> +                            min = pvr & 0xFF;
>> +                            break;
>> +                    case 0x004e: /* POWER9 bits 12-15 give chip type */
>> +                    case 0x0080: /* POWER10 bit 12 gives SMT8/4 */
>> +                            maj = (pvr >> 8) & 0x0F;
>> +                            min = pvr & 0xFF;
>> +                            break;
>> +                    default:
>> +                            maj = (pvr >> 8) & 0xFF;
>> +                            min = pvr & 0xFF;
>> +                            break;
>> +            }
>> +    }
> 
> Reindent for qemu style.

Sure, will do.

>> +    if (clock_getres(CLOCK_REALTIME, &res) == -1) {
>> +        res.tv_nsec = 1;
>> +    }
>> +    freq_mhz = 1000.0 / res.tv_nsec;
> 
> Seems ok.

Yes. But it will allways print 1000.000MHz, which isn't that useful either.
Shall I keep it nevertheless?
  
>> +        dprintf(fd, "processor:\t: %d\n", i);
> 
> Still have an extra : here.

Sigh :-)
Will fix.

Helge

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v2] linux-user: Implement /proc/cpuinfo for ppc cpus
  2026-06-10 19:13   ` Helge Deller
@ 2026-06-10 21:14     ` Richard Henderson
  0 siblings, 0 replies; 4+ messages in thread
From: Richard Henderson @ 2026-06-10 21:14 UTC (permalink / raw)
  To: Helge Deller, Helge Deller, qemu-devel; +Cc: qemu-ppc

On 6/10/26 12:13, Helge Deller wrote:
>>> +    if (clock_getres(CLOCK_REALTIME, &res) == -1) {
>>> +        res.tv_nsec = 1;
>>> +    }
>>> +    freq_mhz = 1000.0 / res.tv_nsec;
>>
>> Seems ok.
> 
> Yes. But it will allways print 1000.000MHz, which isn't that useful either.
> Shall I keep it nevertheless?

Well, depends on the host, I suppose.  Perhaps we can get away with omitting it, though I 
suppose it all depends on why you're implementing /proc/cpuinfo in the first place.

I'll note that unlike "clock", "timebase" *is* used by glibc, but only if we don't 
implement the __kernel_get_tbfreq vdso call.  For linux-user, cpu_ppc_load_tbl() uses 
cpu_get_host_ticks().  Ideally we'd report the host_ticks frequency for timebase, but we 
don't have a function for that.

Perhaps we should switch cpu_ppc_load_tbl() to get_clock(), and then report timebase = 
1GHz.  That would certainly make the vdso implementation simple.


r~


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-06-10 21:15 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-06-10 18:06 [PATCH v2] linux-user: Implement /proc/cpuinfo for ppc cpus Helge Deller
2026-06-10 18:49 ` Richard Henderson
2026-06-10 19:13   ` Helge Deller
2026-06-10 21:14     ` Richard Henderson

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.