@samitouri / QOSamiQemu / commits / ec9abae783

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

Mimic the entries for /proc/cpuinfo to what can be seen on two debian porterboxes (ppc64 and ppc64le), which are running via KVM/QEMU. The "timebase" value in /proc/cpuinfo is used by glibc on power, but only if the __kernel_get_tbfreq vdso call isn't implemented. So switch cpu_ppc_load_tbl() for linux-user to get_clock(), as suggested by Richard, and report timebase = 1GHz in /proc/cpuinfo, which will make the vdso implementation simple too. v4: change timebase to 1GHz and use get_clock() v3: drop another colon, indenting fixes v2: drop colon, add clock output, refine pvr calculation Reviewed-by: Richard Henderson <richard.henderson@linaro.org> Signed-off-by: Helge Deller <deller@gmx.de>

Helge Deller committed Jun 11, 2026 at 23:26 UTC ec9abae78386f44a6f55ed3fe1ad792bab64a806
2 files changed +91 -2
linux-user/ppc/cpu_loop.c
+1 -1
@@ -26,7 +26,7 @@
26
27 static inline uint64_t cpu_ppc_get_tb(CPUPPCState *env)
28 {
29 - return cpu_get_host_ticks();
29 + return get_clock();
30 }
31
32 uint64_t cpu_ppc_load_tbl(CPUPPCState *env)
linux-user/ppc/target_proc.h
+90 -1
@@ -1 +1,90 @@
1 -/* No target-specific /proc support */
1 +/*
2 + * ppc specific proc functions for linux-user
3 + *
4 + * SPDX-License-Identifier: GPL-2.0-or-later
5 + */
6 +#ifndef PPC_TARGET_PROC_H
7 +#define PPC_TARGET_PROC_H
8 +
9 +#include <time.h>
10 +
11 +#define PVR_VER(pvr) (((pvr) >> 16) & 0xFFFF) /* Version field */
12 +#define PVR_REV(pvr) (((pvr) >> 0) & 0xFFFF) /* Revison field */
13 +#define PVR_MAJ(pvr) (((pvr) >> 4) & 0xF) /* Major revision field */
14 +#define PVR_MIN(pvr) (((pvr) >> 0) & 0xF) /* Minor revision field */
15 +
16 +static int open_cpuinfo(CPUArchState *cpu_env, int fd)
17 +{
18 + struct timespec res;
19 + double freq_mhz;
20 + int i, num_cpus;
21 + unsigned int maj, min, pvr;
22 +
23 + PowerPCCPUClass *pcc = POWERPC_CPU_GET_CLASS(env_cpu(cpu_env));
24 + DeviceClass *dc = DEVICE_CLASS(ppc_cpu_get_family_class(pcc));
25 +
26 + pvr = pcc->pvr;
27 +
28 + /* Taken from Linux kernel: */
29 + /* If we are a Freescale core do a simple check so
30 + * we don't have to keep adding cases in the future */
31 + if (PVR_VER(pvr) & 0x8000) {
32 + switch (PVR_VER(pvr)) {
33 + case 0x8000: /* 7441/7450/7451, Voyager */
34 + case 0x8001: /* 7445/7455, Apollo 6 */
35 + case 0x8002: /* 7447/7457, Apollo 7 */
36 + case 0x8003: /* 7447A, Apollo 7 PM */
37 + case 0x8004: /* 7448, Apollo 8 */
38 + case 0x800c: /* 7410, Nitro */
39 + maj = ((pvr >> 8) & 0xF);
40 + min = PVR_MIN(pvr);
41 + break;
42 + default: /* e500/book-e */
43 + maj = PVR_MAJ(pvr);
44 + min = PVR_MIN(pvr);
45 + break;
46 + }
47 + } else {
48 + switch (PVR_VER(pvr)) {
49 + case 0x1008: /* 740P/750P ?? */
50 + maj = ((pvr >> 8) & 0xFF) - 1;
51 + min = pvr & 0xFF;
52 + break;
53 + case 0x004e: /* POWER9 bits 12-15 give chip type */
54 + case 0x0080: /* POWER10 bit 12 gives SMT8/4 */
55 + maj = (pvr >> 8) & 0x0F;
56 + min = pvr & 0xFF;
57 + break;
58 + default:
59 + maj = (pvr >> 8) & 0xFF;
60 + min = pvr & 0xFF;
61 + break;
62 + }
63 + }
64 +
65 + if (clock_getres(CLOCK_REALTIME, &res) == -1) {
66 + res.tv_nsec = 1;
67 + }
68 + freq_mhz = 1000.0 / res.tv_nsec;
69 +
70 + num_cpus = sysconf(_SC_NPROCESSORS_ONLN);
71 + for (i = 0; i < num_cpus; i++) {
72 + dprintf(fd, "processor\t: %d\n", i);
73 + dprintf(fd, "cpu\t\t: %s%s\n",
74 + dc->desc,
75 + pcc->insns_flags & PPC_ALTIVEC ? ", altivec supported":"");
76 + dprintf(fd, "clock\t\t: %.3fMHz\n", freq_mhz);
77 + dprintf(fd, "revision\t: %d.%d (pvr %04x %04x)\n\n",
78 + maj, min, PVR_VER(pvr), PVR_REV(pvr));
79 + }
80 +
81 + dprintf(fd, "timebase\t: 1000000000\n");
82 + dprintf(fd, "platform\t: pSeries\n");
83 + dprintf(fd, "model\t\t: IBM pSeries (QEMU user v" QEMU_VERSION ")\n");
84 + dprintf(fd, "machine\t\t: CHRP IBM pSeries\n");
85 +
86 + return 0;
87 +}
88 +#define HAVE_ARCH_PROC_CPUINFO
89 +
90 +#endif /* PPC_TARGET_PROC_H */