Message ID | ZMkPRJ3subSuW+Rg@p100 (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | linux-user: Emulate /proc/cpuinfo on aarch64 and arm | expand |
On Tue, 1 Aug 2023 at 14:57, Helge Deller <deller@gmx.de> wrote: > > Add emulation for /proc/cpuinfo for arm architecture. > The output below mimics output as seen on debian porterboxes. > +#if defined(TARGET_AARCH64) || defined(TARGET_ARM) > +static int open_cpuinfo(CPUArchState *cpu_env, int fd) > +{ > + int i, num_cpus; > + const int is64 = TARGET_ABI_BITS == 64; > + > + num_cpus = sysconf(_SC_NPROCESSORS_ONLN); > + for (i = 0; i < num_cpus; i++) { > + dprintf(fd, "processor\t: %d\n", i); > + if (!is64) { > + dprintf(fd, "model name\t: ARMv7 Processor rev 2 (v7l)\n"); > + } > + dprintf(fd, "BogoMIPS\t: %d.00\n", is64 ? 100 : 50); > + dprintf(fd, "Features\t: %s\n", > + is64 ? "fp asimd evtstrm cpuid" > + : "half thumb fastmult vfp edsp thumbee vfpv3 " \ > + "tls idiva idivt vfpd32 lpae"); > + dprintf(fd, "CPU implementer\t: 0x%d\n", is64 ? 50 : 56); > + dprintf(fd, "CPU architecture: %d\n", is64 ? 8 : 7); > + dprintf(fd, "CPU variant\t: 0x%d\n", is64 ? 0 : 2); > + dprintf(fd, "CPU part\t: 0x%d\n", is64 ? 0 : 584); > + dprintf(fd, "CPU revision\t: %d\n\n", is64 ? 1 : 2); If you want to do this you should hook it up to what the CPU being emulated actually is and what features it has. (Compare how we set the hwcaps.) > + } > + return 0; > +} thanks -- PMM
On 8/1/23 16:22, Peter Maydell wrote: > On Tue, 1 Aug 2023 at 14:57, Helge Deller <deller@gmx.de> wrote: >> >> Add emulation for /proc/cpuinfo for arm architecture. >> The output below mimics output as seen on debian porterboxes. > > >> +#if defined(TARGET_AARCH64) || defined(TARGET_ARM) >> +static int open_cpuinfo(CPUArchState *cpu_env, int fd) >> +{ >> + int i, num_cpus; >> + const int is64 = TARGET_ABI_BITS == 64; >> + >> + num_cpus = sysconf(_SC_NPROCESSORS_ONLN); >> + for (i = 0; i < num_cpus; i++) { >> + dprintf(fd, "processor\t: %d\n", i); >> + if (!is64) { >> + dprintf(fd, "model name\t: ARMv7 Processor rev 2 (v7l)\n"); >> + } >> + dprintf(fd, "BogoMIPS\t: %d.00\n", is64 ? 100 : 50); >> + dprintf(fd, "Features\t: %s\n", >> + is64 ? "fp asimd evtstrm cpuid" >> + : "half thumb fastmult vfp edsp thumbee vfpv3 " \ >> + "tls idiva idivt vfpd32 lpae"); >> + dprintf(fd, "CPU implementer\t: 0x%d\n", is64 ? 50 : 56); >> + dprintf(fd, "CPU architecture: %d\n", is64 ? 8 : 7); >> + dprintf(fd, "CPU variant\t: 0x%d\n", is64 ? 0 : 2); >> + dprintf(fd, "CPU part\t: 0x%d\n", is64 ? 0 : 584); >> + dprintf(fd, "CPU revision\t: %d\n\n", is64 ? 1 : 2); > > If you want to do this you should hook it up to what the > CPU being emulated actually is and what features it has. > (Compare how we set the hwcaps.) Nice! I didn't know about those elf hwcaps... I'll respin. Thanks, Helge
On Tue, 1 Aug 2023 at 15:41, Helge Deller <deller@gmx.de> wrote: > > On 8/1/23 16:22, Peter Maydell wrote: > > On Tue, 1 Aug 2023 at 14:57, Helge Deller <deller@gmx.de> wrote: > >> > >> Add emulation for /proc/cpuinfo for arm architecture. > >> The output below mimics output as seen on debian porterboxes. > > > > > >> +#if defined(TARGET_AARCH64) || defined(TARGET_ARM) > >> +static int open_cpuinfo(CPUArchState *cpu_env, int fd) > >> +{ > >> + int i, num_cpus; > >> + const int is64 = TARGET_ABI_BITS == 64; > >> + > >> + num_cpus = sysconf(_SC_NPROCESSORS_ONLN); > >> + for (i = 0; i < num_cpus; i++) { > >> + dprintf(fd, "processor\t: %d\n", i); > >> + if (!is64) { > >> + dprintf(fd, "model name\t: ARMv7 Processor rev 2 (v7l)\n"); > >> + } > >> + dprintf(fd, "BogoMIPS\t: %d.00\n", is64 ? 100 : 50); > >> + dprintf(fd, "Features\t: %s\n", > >> + is64 ? "fp asimd evtstrm cpuid" > >> + : "half thumb fastmult vfp edsp thumbee vfpv3 " \ > >> + "tls idiva idivt vfpd32 lpae"); > >> + dprintf(fd, "CPU implementer\t: 0x%d\n", is64 ? 50 : 56); > >> + dprintf(fd, "CPU architecture: %d\n", is64 ? 8 : 7); > >> + dprintf(fd, "CPU variant\t: 0x%d\n", is64 ? 0 : 2); > >> + dprintf(fd, "CPU part\t: 0x%d\n", is64 ? 0 : 584); > >> + dprintf(fd, "CPU revision\t: %d\n\n", is64 ? 1 : 2); > > > > If you want to do this you should hook it up to what the > > CPU being emulated actually is and what features it has. > > (Compare how we set the hwcaps.) > > Nice! > I didn't know about those elf hwcaps... In an ideal world guest code should only look at the hwcaps (which are the ABI-stable interface the kernel provides), not at what's in /proc/cpuinfo. But of course if you're a shell script then cpuinfo is a lot easier to deal with... thanks -- PMM
diff --git a/linux-user/syscall.c b/linux-user/syscall.c index dc8266c073..917c388073 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -8287,7 +8287,8 @@ void target_exception_dump(CPUArchState *env, const char *fmt, int code) #if HOST_BIG_ENDIAN != TARGET_BIG_ENDIAN || \ defined(TARGET_SPARC) || defined(TARGET_M68K) || defined(TARGET_HPPA) || \ - defined(TARGET_RISCV) || defined(TARGET_S390X) + defined(TARGET_RISCV) || defined(TARGET_S390X) || defined(TARGET_ARM) || \ + defined(TARGET_AARCH64) static int is_proc(const char *filename, const char *entry) { return strcmp(filename, entry) == 0; @@ -8503,6 +8504,33 @@ static int open_hardware(CPUArchState *cpu_env, int fd) } #endif +#if defined(TARGET_AARCH64) || defined(TARGET_ARM) +static int open_cpuinfo(CPUArchState *cpu_env, int fd) +{ + int i, num_cpus; + const int is64 = TARGET_ABI_BITS == 64; + + num_cpus = sysconf(_SC_NPROCESSORS_ONLN); + for (i = 0; i < num_cpus; i++) { + dprintf(fd, "processor\t: %d\n", i); + if (!is64) { + dprintf(fd, "model name\t: ARMv7 Processor rev 2 (v7l)\n"); + } + dprintf(fd, "BogoMIPS\t: %d.00\n", is64 ? 100 : 50); + dprintf(fd, "Features\t: %s\n", + is64 ? "fp asimd evtstrm cpuid" + : "half thumb fastmult vfp edsp thumbee vfpv3 " \ + "tls idiva idivt vfpd32 lpae"); + dprintf(fd, "CPU implementer\t: 0x%d\n", is64 ? 50 : 56); + dprintf(fd, "CPU architecture: %d\n", is64 ? 8 : 7); + dprintf(fd, "CPU variant\t: 0x%d\n", is64 ? 0 : 2); + dprintf(fd, "CPU part\t: 0x%d\n", is64 ? 0 : 584); + dprintf(fd, "CPU revision\t: %d\n\n", is64 ? 1 : 2); + } + return 0; +} +#endif + int do_guest_openat(CPUArchState *cpu_env, int dirfd, const char *pathname, int flags, mode_t mode, bool safe) { @@ -8522,7 +8550,8 @@ int do_guest_openat(CPUArchState *cpu_env, int dirfd, const char *pathname, { "/proc/net/route", open_net_route, is_proc }, #endif #if defined(TARGET_SPARC) || defined(TARGET_HPPA) || \ - defined(TARGET_RISCV) || defined(TARGET_S390X) + defined(TARGET_RISCV) || defined(TARGET_S390X) || \ + defined(TARGET_ARM) || defined(TARGET_AARCH64) { "/proc/cpuinfo", open_cpuinfo, is_proc }, #endif #if defined(TARGET_M68K)
Add emulation for /proc/cpuinfo for arm architecture. The output below mimics output as seen on debian porterboxes. aarch64 output example: processor : 0 BogoMIPS : 100.00 Features : fp asimd evtstrm cpuid CPU implementer : 0x50 CPU architecture: 8 CPU variant : 0x0 CPU part : 0x0 CPU revision : 1 arm output example: processor : 0 model name : ARMv7 Processor rev 2 (v7l) BogoMIPS : 50.00 Features : half thumb fastmult vfp edsp thumbee vfpv3 tls idiva idivt vfpd32 lpae CPU implementer : 0x56 CPU architecture: 7 CPU variant : 0x2 CPU part : 0x584 CPU revision : 2 Signed-off-by: Helge Deller <deller@gmx.de>