Skip to contentSkip to conversation

linux-user: Implement /proc/cpuinfo for ppc cpus

PATCH Superseded Helge Deller 4 participants 4 messages Jun 9 – Jun 13

v1 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 linux-user: Implement /proc/cpuinfo for ppc cpus

From: Helge Deller <[email protected]>

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.

---
 linux-user/ppc/target_proc.h | 38 +++++++++++++++++++++++++++++++++++-
 1 file changed, 37 insertions(+), 1 deletion(-)
linux-user/ppc/target_proc.h +37 -1
index 43fe29ca72..fa965c0e69 100644
@@ -1 +1,37 @@
-/* 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
+
+static int open_cpuinfo(CPUArchState *cpu_env, int fd)
+{
+    int i, num_cpus;
+
+    PowerPCCPUClass *pcc = POWERPC_CPU_GET_CLASS(env_cpu(cpu_env));
+    DeviceClass *dc = DEVICE_CLASS(ppc_cpu_get_family_class(pcc));
+
+    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: 3425.000000MHz\n");
+        dprintf(fd, "revision\t: %d.%d (pvr %04x %04x)\n\n",
+                    (pcc->pvr >> 8) & 0x0f, pcc->pvr & 0x0f,
+                    pcc->pvr >> 16, pcc->pvr & 0xffff);
+    }
+
+    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 */
Signature · 1 line
2.54.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 7 lines · Helge Deller

From: Helge Deller <[email protected]>

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.

Quoted 6 lines
---
 linux-user/ppc/target_proc.h | 38 +++++++++++++++++++++++++++++++++++-
 1 file changed, 37 insertions(+), 1 deletion(-)

Looks good to me.

Regards,
Pierrick

#2 lore raw
In reply to Helge Deller
Quoted 28 lines · Helge Deller

From: Helge Deller <[email protected]>

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.

---
  linux-user/ppc/target_proc.h | 38 +++++++++++++++++++++++++++++++++++-
  1 file changed, 37 insertions(+), 1 deletion(-)
linux-user/ppc/target_proc.h +9 -1
index 43fe29ca72..fa965c0e69 100644
@@ -1 +1,37 @@
-/* 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
+
+static int open_cpuinfo(CPUArchState *cpu_env, int fd)

linux-user/ppc/target_proc.h line 19

Quoted 10 lines
linux-user/ppc/target_proc.h +10 -0
+{
+    int i, num_cpus;
+
+    PowerPCCPUClass *pcc = POWERPC_CPU_GET_CLASS(env_cpu(cpu_env));
+    DeviceClass *dc = DEVICE_CLASS(ppc_cpu_get_family_class(pcc));
+
+    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",

There are extra ':' here. Should be

processor :
cpu :

not

processor: :
cpu: :

linux-user/ppc/target_proc.h line 22

Quoted 3 lines
linux-user/ppc/target_proc.h +3 -0
+                    dc->desc,
+                    pcc->insns_flags & PPC_ALTIVEC ? ", altivec supported":"");
+        dprintf(fd, "clock\t\t: 3425.000000MHz\n");

Why hardcoded? Is the clock not accessible to user-only?

linux-user/ppc/target_proc.h line 25

Quoted 3 lines
linux-user/ppc/target_proc.h +3 -0
+        dprintf(fd, "revision\t: %d.%d (pvr %04x %04x)\n\n",
+                    (pcc->pvr >> 8) & 0x0f, pcc->pvr & 0x0f,
+                    pcc->pvr >> 16, pcc->pvr & 0xffff);

There's quite a bit of decode of pvr for maj.min in the kernel.

r~

Tested-by on v1 1/1
#3 lore raw
In reply to Helge Deller

Built and tested qemu-ppc64le on ppc64le host

Test environment:
- Host: ppc64le Linux (POWER10)
- QEMU version: v11.0.50 (v11.0.0-1849-g193963218a-dirty) - upstream qemu with patch applied
- Target: ppc64le-linux-user

Manual tests performed:
- Verified /proc/cpuinfo is readable by PPC binaries under qemu-user
- Verified qemu-ppc64le -cpu POWER10 /bin/cat /proc/cpuinfo returns the expected PPC-specific cpuinfo output
- Tested POWER8, POWER9, and POWER10 CPU models
- Confirmed different PVR values for different CPU types
- Verified all required fields present (processor, cpu, clock, revision, timebase, platform, model, machine)
- CPU count correctly reported (48 online CPUs)
- Tested with both custom test program and system binaries (/bin/cat)

Test Logs:
1. POWER9 CPU model test:

$ qemu-ppc64le -cpu POWER9 /tmp/test-cpuinfo | head -10
=== /proc/cpuinfo via qemu-user ===
processor:	: 0
cpu:		: POWER9, altivec supported
clock		: 3425.000000MHz
revision	: 2.2 (pvr 004e 1202)

processor: : 1
cpu: : POWER9, altivec supported
clock : 3425.000000MHz
revision : 2.2 (pvr 004e 1202)

2. POWER10 CPU model test:

$ qemu-ppc64le -cpu POWER10 /tmp/test-cpuinfo | head -10
=== /proc/cpuinfo via qemu-user ===
processor:	: 0
cpu:		: POWER10, altivec supported
clock		: 3425.000000MHz
revision	: 2.0 (pvr 0080 0200)

processor: : 1
cpu: : POWER10, altivec supported
clock : 3425.000000MHz
revision : 2.0 (pvr 0080 0200)

3. System binary test:

$ qemu-ppc64le -cpu POWER9 /bin/cat /proc/cpuinfo | tail -5
timebase	: 512000000
platform	: pSeries
model		: IBM pSeries (QEMU user v11.0.50)
machine		: CHRP IBM pSeries

Qemu Unit tests:

make check: 118/118 tests PASSED
Ok:                118
Fail:              0

All tests passed. The patch correctly implements /proc/cpuinfo for PPC user-mode emulation without breaking existing functionality. Output format is consistent and provides accurate CPU information.

Thanks,
Misbah Anjum N