qemu/timer: Don't use RDTSC on i486
PATCH 1/1 qemu/timer: Don't use RDTSC on i486
GCC defines __i386__ for i386 and i486, which both lack RDTSC instruction. The i386 seems to be impossible to distinguish, but i486 can be identified by checking for undefined __i486__.
--- include/qemu/timer.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
include/qemu/timer.h +1 -1
@@ -872,7 +872,7 @@ static inline int64_t cpu_get_host_ticks(void) return retval; } -#elif defined(__i386__) +#elif defined(__i386__) && !defined(__i486__)static inline int64_t cpu_get_host_ticks (void ) {
Signature · 1 line
2.43.0
Quoted 3 lines · Petr Cvek
GCC defines
__i386__for i386 and i486, which both lack RDTSC instruction. The i386 seems to be impossible to distinguish, but i486 can be identified by checking for undefined__i486__.
Couldn't you check for an undefined __tune_i386__, which would be set by both GCC and LLVM when using -march=i386.
Sam
Signature · 2 lines
Samuel Tardieu Télécom Paris - Institut Polytechnique de Paris
Actually I was thinking about mentioning it in the commit message also, but I wasn't able to find any specification for that (if all compilers use it).
Other problem is the __tune_i386__ is also set when -mtune=i386 (but with -march=i686).
But if the general idea of changing the code for 486 is OK it can be added also.
Petr
Dne 26. 11. 23 v 13:37 Samuel Tardieu napsal(a):
Quoted 10 lines
Quoted 3 lines · Petr Cvek
GCC defines
__i386__for i386 and i486, which both lack RDTSC instruction. The i386 seems to be impossible to distinguish, but i486 can be identified by checking for undefined__i486__.Couldn't you check for an undefined
__tune_i386__, which would be set by both GCC and LLVM when using -march=i386.Sam
Quoted 2 lines · Petr Cvek
Actually I was thinking about mentioning it in the commit message also, but I wasn't able to find any specification for that (if all compilers use it).
Note that this change would be safe: at worst, some compilers don't use __tune_i386__ and the situation would be the same as today without the patch.
Quoted 1 line
Other problem is the
__tune_i386__is also set when -mtune=i386 (but with -march=i686).
Indeed, this is the case for GCC (not clang).
Sam
Signature · 2 lines
Samuel Tardieu Télécom Paris - Institut Polytechnique de Paris
Dne 26. 11. 23 v 14:03 Samuel Tardieu napsal(a):
Quoted 7 lines
Quoted 2 lines · Petr Cvek
Actually I was thinking about mentioning it in the commit message also, but I wasn't able to find any specification for that (if all compilers use it).
Note that this change would be safe: at worst, some compilers don't use
__tune_i386__and the situation would be the same as today without the patch.
Good remark. You're right.
Quoted 6 lines
Quoted 2 lines
Other problem is the
__tune_i386__is also set when -mtune=i386 (but with -march=i686).Indeed, this is the case for GCC (not clang).
Sam
Il sab 25 nov 2023, 13:23 Petr Cvek <[email protected]> ha scritto:
Quoted 4 lines
GCC defines
__i386__for i386 and i486, which both lack RDTSC instruction. The i386 seems to be impossible to distinguish, but i486 can be identified by checking for undefined__i486__.
As far as I know QEMU cannot be run on i486 anyway since TCG assumes the presence of CPUID. Have you actually tried?
Paolo
Quoted 22 lines
Signed-off-by Petr Cvek <[email protected]>--- include/qemu/timer.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)include/qemu/timer.h +1
-2@@ -872,7 +872,7 @@ static inline int64_t cpu_get_host_ticks(void) return retval; } -#elif defined(__i386__) +#elif defined(__i386__) && !defined(__i486__)static inline int64_t cpu_get_host_ticks (void ) { --2.43.0
Dne 26. 11. 23 v 16:56 Paolo Bonzini napsal(a):
Quoted 11 lines
Il sab 25 nov 2023, 13:23 Petr Cvek <[email protected] <mailto:[email protected]>> ha scritto:
GCC defines
__i386__for i386 and i486, which both lack RDTSC instruction. The i386 seems to be impossible to distinguish, but i486 can be identified by checking for undefined__i486__.As far as I know QEMU cannot be run on i486 anyway since TCG assumes the presence of CPUID. Have you actually tried?
Yes I tried running x86_64 mesa3d glxgears on amd 5x86. It worked with about 5 fps :). Latest 486 CPUs supports CPUID btw.
Quoted 24 lines
Paolo
Signed-off-by: Petr Cvek <[email protected] <mailto:[email protected]>> --- include/qemu/timer.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/qemu/timer.h b/include/qemu/timer.h index 9a366e551f..7baa5d1d41 100644 --- a/include/qemu/timer.h +++ b/include/qemu/timer.h @@ -872,7 +872,7 @@ static inline int64_t cpu_get_host_ticks(void) return retval; } -#elif defined(__i386__) +#elif defined(__i386__) && !defined(__i486__) static inline int64_t cpu_get_host_ticks(void) { -- 2.43.0
Quoted 10 lines · Paolo Bonzini
Il sab 25 nov 2023, 13:23 Petr Cvek <[email protected] <mailto:[email protected]>> ha scritto:
GCC defines
__i386__for i386 and i486, which both lack RDTSC instruction. The i386 seems to be impossible to distinguish, but i486 can be identified by checking for undefined__i486__.As far as I know QEMU cannot be run on i486 anyway since TCG assumes the presence of CPUID. Have you actually tried?
TCG does not assume CPUID.
We might have problems without cmpxchg8b, but if so that's in accel/tcg/ not tcg/.
r~
I can agree that binary compiled for i486 doesn't contain cmpxchg8b and works OK with exception of setjmp bug I described in another thread [1]. glxgears which doesn't use signals works without problem. 64bit atomic operations seems to be emulated in util/atomic64.c.
However I've found out the compilation for i386 seems to fail during configure due to the lack of i386 atomic instructions in my GCC 13.2.0 version. If this is normal behavior, I guess __tune_i386__ check doesn't make sense to add.
[1] [BUG] accel/tcg: cpu_exec_longjmp_cleanup: assertion failed: (cpu == current_cpu)
Petr
Dne 28. 11. 23 v 16:52 Richard Henderson napsal(a):
Quoted 18 lines · Paolo Bonzini
Quoted 10 lines
Il sab 25 nov 2023, 13:23 Petr Cvek <[email protected] <mailto:[email protected]>> ha scritto:
GCC defines
__i386__for i386 and i486, which both lack RDTSC instruction. The i386 seems to be impossible to distinguish, but i486 can be identified by checking for undefined__i486__.As far as I know QEMU cannot be run on i486 anyway since TCG assumes the presence of CPUID. Have you actually tried?
TCG does not assume CPUID.
We might have problems without cmpxchg8b, but if so that's in accel/tcg/ not tcg/.
r~
Quoted 3 lines · Petr Cvek
I can agree that binary compiled for i486 doesn't contain cmpxchg8b and works OK with exception of setjmp bug I described in another thread [1]. glxgears which doesn't use signals works without problem. 64bit atomic operations seems to be emulated in
util/atomic64.c.However I've found out the compilation for i386 seems to fail during configure due to the lack of i386 atomic instructions in my GCC 13.2.0 version. If this is normal behavior, I guess
__tune_i386__check doesn't make sense to add.
Correct, we cannot operate at all without the i486 atomic insns.
r~
Quoted 6 lines · Petr Cvek
GCC defines
__i386__for i386 and i486, which both lack RDTSC instruction. The i386 seems to be impossible to distinguish, but i486 can be identified by checking for undefined__i486__.Signed-off-by Petr Cvek <[email protected]>
Last time this came up (over a decade ago!) we dropped the idea because we couldn't find a consistent way of identifying the no-RDTSC CPUs:
https://patchwork.ozlabs.org/project/qemu-devel/patch/[email protected]/
We have already deprecated 32-bit x86 host support for system emulation mode, incidentally.
thanks
-- PMM