diff mbox series

[kvm-unit-tests] x86: eventinj: Do a real io_delay()

Message ID 20190502184913.10138-1-nadav.amit@gmail.com (mailing list archive)
State New, archived
Headers show
Series [kvm-unit-tests] x86: eventinj: Do a real io_delay() | expand

Commit Message

Nadav Amit May 2, 2019, 6:49 p.m. UTC
From: Nadav Amit <nadav.amit@gmail.com>

There is no guarantee that a self-IPI would be delivered immediately.
io_delay() is called after self-IPI is generated but does nothing.
Instead, change io_delay() to wait for 10000 cycles, which should be
enough on any system whatsoever.

Signed-off-by: Nadav Amit <nadav.amit@gmail.com>
---
 x86/eventinj.c | 5 +++++
 1 file changed, 5 insertions(+)

Comments

Krish Sadhukhan May 3, 2019, 5:38 p.m. UTC | #1
On 5/2/19 11:49 AM, nadav.amit@gmail.com wrote:
> From: Nadav Amit <nadav.amit@gmail.com>
>
> There is no guarantee that a self-IPI would be delivered immediately.
> io_delay() is called after self-IPI is generated but does nothing.
> Instead, change io_delay() to wait for 10000 cycles, which should be
> enough on any system whatsoever.
>
> Signed-off-by: Nadav Amit <nadav.amit@gmail.com>
> ---
>   x86/eventinj.c | 5 +++++
>   1 file changed, 5 insertions(+)
>
> diff --git a/x86/eventinj.c b/x86/eventinj.c
> index 8064eb9..250537b 100644
> --- a/x86/eventinj.c
> +++ b/x86/eventinj.c
> @@ -18,6 +18,11 @@ void do_pf_tss(void);
>   
>   static inline void io_delay(void)
>   {
> +	u64 start = rdtsc();
> +
> +	do {
> +		pause();
> +	} while (rdtsc() - start < 10000);
>   }
>   
>   static void apic_self_ipi(u8 v)

Perhaps call delay() (in delay.c)  inside of io_delay() OR perhaps 
replace all instances of io_delay() with delay() ?
Nadav Amit May 3, 2019, 5:45 p.m. UTC | #2
> On May 3, 2019, at 10:38 AM, Krish Sadhukhan <krish.sadhukhan@oracle.com> wrote:
> 
> 
> On 5/2/19 11:49 AM, nadav.amit@gmail.com wrote:
>> From: Nadav Amit <nadav.amit@gmail.com>
>> 
>> There is no guarantee that a self-IPI would be delivered immediately.
>> io_delay() is called after self-IPI is generated but does nothing.
>> Instead, change io_delay() to wait for 10000 cycles, which should be
>> enough on any system whatsoever.
>> 
>> Signed-off-by: Nadav Amit <nadav.amit@gmail.com>
>> ---
>>  x86/eventinj.c | 5 +++++
>>  1 file changed, 5 insertions(+)
>> 
>> diff --git a/x86/eventinj.c b/x86/eventinj.c
>> index 8064eb9..250537b 100644
>> --- a/x86/eventinj.c
>> +++ b/x86/eventinj.c
>> @@ -18,6 +18,11 @@ void do_pf_tss(void);
>>    static inline void io_delay(void)
>>  {
>> +	u64 start = rdtsc();
>> +
>> +	do {
>> +		pause();
>> +	} while (rdtsc() - start < 10000);
>>  }
>>    static void apic_self_ipi(u8 v)
> 
> Perhaps call delay() (in delay.c) inside of io_delay() OR perhaps replace
> all instances of io_delay() with delay() ?

There is such a mess with this delay(). It times stuff based on number of
pause() invocations. There is an additional implementation in ioapic.c
(which by itself is broken, since there is no compiler barrier).

Let me see what I can do...
diff mbox series

Patch

diff --git a/x86/eventinj.c b/x86/eventinj.c
index 8064eb9..250537b 100644
--- a/x86/eventinj.c
+++ b/x86/eventinj.c
@@ -18,6 +18,11 @@  void do_pf_tss(void);
 
 static inline void io_delay(void)
 {
+	u64 start = rdtsc();
+
+	do {
+		pause();
+	} while (rdtsc() - start < 10000);
 }
 
 static void apic_self_ipi(u8 v)