All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] qemu/timer: Don't use RDTSC on i486
@ 2023-11-25 12:23 Petr Cvek
  2023-11-26 12:37 ` Samuel Tardieu
                   ` (2 more replies)
  0 siblings, 3 replies; 11+ messages in thread
From: Petr Cvek @ 2023-11-25 12:23 UTC (permalink / raw)
  To: qemu-devel; +Cc: pbonzini, marcel.apfelbaum, mst

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 <petrcvekcz@gmail.com>
---
 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



^ permalink raw reply related	[flat|nested] 11+ messages in thread

* Re: [PATCH] qemu/timer: Don't use RDTSC on i486
  2023-11-25 12:23 [PATCH] qemu/timer: Don't use RDTSC on i486 Petr Cvek
@ 2023-11-26 12:37 ` Samuel Tardieu
  2023-11-26 12:59   ` Petr Cvek
  2023-11-26 15:56 ` Paolo Bonzini
  2023-11-27  9:49 ` Peter Maydell
  2 siblings, 1 reply; 11+ messages in thread
From: Samuel Tardieu @ 2023-11-26 12:37 UTC (permalink / raw)
  To: Petr Cvek; +Cc: pbonzini, marcel.apfelbaum, mst, qemu-devel


Petr Cvek <petrcvekcz@gmail.com> writes:

> 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
-- 
Samuel Tardieu
Télécom Paris - Institut Polytechnique de Paris


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH] qemu/timer: Don't use RDTSC on i486
  2023-11-26 12:37 ` Samuel Tardieu
@ 2023-11-26 12:59   ` Petr Cvek
  2023-11-26 13:03     ` Samuel Tardieu
  0 siblings, 1 reply; 11+ messages in thread
From: Petr Cvek @ 2023-11-26 12:59 UTC (permalink / raw)
  To: Samuel Tardieu; +Cc: pbonzini, marcel.apfelbaum, mst, qemu-devel

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):
> 
> Petr Cvek <petrcvekcz@gmail.com> writes:
> 
>> 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


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH] qemu/timer: Don't use RDTSC on i486
  2023-11-26 12:59   ` Petr Cvek
@ 2023-11-26 13:03     ` Samuel Tardieu
  2023-11-26 22:49       ` Petr Cvek
  0 siblings, 1 reply; 11+ messages in thread
From: Samuel Tardieu @ 2023-11-26 13:03 UTC (permalink / raw)
  To: Petr Cvek; +Cc: pbonzini, marcel.apfelbaum, mst, qemu-devel


Petr Cvek <petrcvekcz@gmail.com> writes:

> 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.

> 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
-- 
Samuel Tardieu
Télécom Paris - Institut Polytechnique de Paris


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH] qemu/timer: Don't use RDTSC on i486
  2023-11-25 12:23 [PATCH] qemu/timer: Don't use RDTSC on i486 Petr Cvek
  2023-11-26 12:37 ` Samuel Tardieu
@ 2023-11-26 15:56 ` Paolo Bonzini
  2023-11-26 22:52   ` Petr Cvek
  2023-11-28 15:52   ` Richard Henderson
  2023-11-27  9:49 ` Peter Maydell
  2 siblings, 2 replies; 11+ messages in thread
From: Paolo Bonzini @ 2023-11-26 15:56 UTC (permalink / raw)
  To: Petr Cvek; +Cc: qemu-devel, Marcel Apfelbaum, S. Tsirkin, Michael

[-- Attachment #1: Type: text/plain, Size: 935 bytes --]

Il sab 25 nov 2023, 13:23 Petr Cvek <petrcvekcz@gmail.com> 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?

Paolo


> Signed-off-by: Petr Cvek <petrcvekcz@gmail.com>
> ---
>  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
>
>

[-- Attachment #2: Type: text/html, Size: 1674 bytes --]

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH] qemu/timer: Don't use RDTSC on i486
  2023-11-26 13:03     ` Samuel Tardieu
@ 2023-11-26 22:49       ` Petr Cvek
  0 siblings, 0 replies; 11+ messages in thread
From: Petr Cvek @ 2023-11-26 22:49 UTC (permalink / raw)
  To: Samuel Tardieu; +Cc: pbonzini, marcel.apfelbaum, mst, qemu-devel

Dne 26. 11. 23 v 14:03 Samuel Tardieu napsal(a):
> 
> Petr Cvek <petrcvekcz@gmail.com> writes:
> 
>> 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.

> 
>> 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


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH] qemu/timer: Don't use RDTSC on i486
  2023-11-26 15:56 ` Paolo Bonzini
@ 2023-11-26 22:52   ` Petr Cvek
  2023-11-28 15:52   ` Richard Henderson
  1 sibling, 0 replies; 11+ messages in thread
From: Petr Cvek @ 2023-11-26 22:52 UTC (permalink / raw)
  To: Paolo Bonzini; +Cc: qemu-devel, Marcel Apfelbaum, S. Tsirkin, Michael

Dne 26. 11. 23 v 16:56 Paolo Bonzini napsal(a):
> 
> 
> Il sab 25 nov 2023, 13:23 Petr Cvek <petrcvekcz@gmail.com <mailto:petrcvekcz@gmail.com>> 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.

> Paolo
> 
> 
>     Signed-off-by: Petr Cvek <petrcvekcz@gmail.com <mailto:petrcvekcz@gmail.com>>
>     ---
>      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
> 


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH] qemu/timer: Don't use RDTSC on i486
  2023-11-25 12:23 [PATCH] qemu/timer: Don't use RDTSC on i486 Petr Cvek
  2023-11-26 12:37 ` Samuel Tardieu
  2023-11-26 15:56 ` Paolo Bonzini
@ 2023-11-27  9:49 ` Peter Maydell
  2 siblings, 0 replies; 11+ messages in thread
From: Peter Maydell @ 2023-11-27  9:49 UTC (permalink / raw)
  To: Petr Cvek; +Cc: qemu-devel, pbonzini, marcel.apfelbaum, mst

On Sat, 25 Nov 2023 at 12:24, Petr Cvek <petrcvekcz@gmail.com> wrote:
>
> 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 <petrcvekcz@gmail.com>

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/1353683570-30525-1-git-send-email-peter.maydell@linaro.org/

We have already deprecated 32-bit x86 host support for
system emulation mode, incidentally.

thanks
-- PMM


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH] qemu/timer: Don't use RDTSC on i486
  2023-11-26 15:56 ` Paolo Bonzini
  2023-11-26 22:52   ` Petr Cvek
@ 2023-11-28 15:52   ` Richard Henderson
  2023-11-29 13:50     ` Petr Cvek
  1 sibling, 1 reply; 11+ messages in thread
From: Richard Henderson @ 2023-11-28 15:52 UTC (permalink / raw)
  To: Paolo Bonzini, Petr Cvek
  Cc: qemu-devel, Marcel Apfelbaum, S. Tsirkin, Michael

On 11/26/23 09:56, Paolo Bonzini wrote:
> 
> 
> Il sab 25 nov 2023, 13:23 Petr Cvek <petrcvekcz@gmail.com <mailto:petrcvekcz@gmail.com>> 
> 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~


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH] qemu/timer: Don't use RDTSC on i486
  2023-11-28 15:52   ` Richard Henderson
@ 2023-11-29 13:50     ` Petr Cvek
  2023-11-29 14:27       ` Richard Henderson
  0 siblings, 1 reply; 11+ messages in thread
From: Petr Cvek @ 2023-11-29 13:50 UTC (permalink / raw)
  To: Richard Henderson, Paolo Bonzini
  Cc: qemu-devel, Marcel Apfelbaum, S. Tsirkin, Michael

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):
> On 11/26/23 09:56, Paolo Bonzini wrote:
>>
>>
>> Il sab 25 nov 2023, 13:23 Petr Cvek <petrcvekcz@gmail.com <mailto:petrcvekcz@gmail.com>> 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~


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH] qemu/timer: Don't use RDTSC on i486
  2023-11-29 13:50     ` Petr Cvek
@ 2023-11-29 14:27       ` Richard Henderson
  0 siblings, 0 replies; 11+ messages in thread
From: Richard Henderson @ 2023-11-29 14:27 UTC (permalink / raw)
  To: Petr Cvek, Paolo Bonzini
  Cc: qemu-devel, Marcel Apfelbaum, S. Tsirkin, Michael

On 11/29/23 07:50, Petr Cvek wrote:
> 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~


^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2023-11-29 14:27 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-11-25 12:23 [PATCH] qemu/timer: Don't use RDTSC on i486 Petr Cvek
2023-11-26 12:37 ` Samuel Tardieu
2023-11-26 12:59   ` Petr Cvek
2023-11-26 13:03     ` Samuel Tardieu
2023-11-26 22:49       ` Petr Cvek
2023-11-26 15:56 ` Paolo Bonzini
2023-11-26 22:52   ` Petr Cvek
2023-11-28 15:52   ` Richard Henderson
2023-11-29 13:50     ` Petr Cvek
2023-11-29 14:27       ` Richard Henderson
2023-11-27  9:49 ` Peter Maydell

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.