linux-user: Emulate /proc/cpuinfo on aarch64 and arm
PATCH 1/1 linux-user: Emulate /proc/cpuinfo on aarch64 and arm
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
linux-user/syscall.c +31 -2
@@ -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)
Quoted 17 lines · Helge Deller
Add emulation for
/proc/cpuinfofor arm architecture. The output below mimics output as seen on debian porterboxes.linux-user/syscall.c +12
-0+#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" ); + }
linux-user/syscall.c static int open_hardware(CPUArchState *cpu_env, int fd) · line 8528
Quoted 10 lines
linux-user/syscall.c +10
-0+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.)
linux-user/syscall.c static int open_hardware(CPUArchState *cpu_env, int fd) · line 8531
Quoted 3 lines
linux-user/syscall.c +3
-0+ } +return 0 ; +}
thanks
-- PMM
Quoted 24 lines · Peter Maydell
Quoted 23 lines · Helge Deller
Add emulation for
/proc/cpuinfofor arm architecture. The output below mimics output as seen on debian porterboxes.linux-user/syscall.c +18
-0+#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 );
Quoted 8 lines
linux-user/syscall.c static int open_hardware(CPUArchState *cpu_env, int fd) · line 8528
Quoted 4 lines
linux-user/syscall.c +4
-0+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
Quoted 35 lines · Helge Deller
Quoted 24 lines · Peter Maydell
Quoted 23 lines · Helge Deller
Add emulation for
/proc/cpuinfofor arm architecture. The output below mimics output as seen on debian porterboxes.linux-user/syscall.c +18
-0+#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 );Quoted 8 lines
linux-user/syscall.c static int open_hardware(CPUArchState *cpu_env, int fd) · line 8528
Quoted 4 lines
linux-user/syscall.c +4
-0+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.)
Quoted 2 lines
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