xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
* [Xen-devel] [PRE-4.12 PATCH] xen/arm: time: cycles_t should be an uint64_t and not unsigned long
@ 2019-06-20 17:47 Julien Grall
  2019-06-20 17:50 ` Andrew Cooper
  2019-06-20 23:56 ` Stefano Stabellini
  0 siblings, 2 replies; 4+ messages in thread
From: Julien Grall @ 2019-06-20 17:47 UTC (permalink / raw)
  To: xen-devel; +Cc: Julien Grall, sstabellini, ian.jackson, jbeulich

Since commit ca73ac8e7d "xen/arm: Add an isb() before reading CNTPCT_EL0
to prevent re-ordering", get_cycles() is now returning the number of
cycles and used in more callers.

While the counter registers is always 64-bit, get_cycles() will only
reutrn a 32-bit on Arm32 and therefore truncate the value. This will
result to weird behavior by both Xen and the Guest as the timer will not
be setup correctly.

This could be resolved by switch cycles_t from unsigned long to
unsigned int.

Signed-off-by: Julien Grall <julien.grall@arm.com>

---
    This is only targeting xen 4.11 and earlier. Xen 4.12 and later have
    a correct definition of cycles_t thanks to da3d55ae67 "console:
    avoid printing no or null time stamps".

    This will hopefully unblock osstest on staging-4.10 and
    staging-4.11. This patch should be backported up to Xen 4.8.
---
 xen/include/asm-arm/time.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/xen/include/asm-arm/time.h b/xen/include/asm-arm/time.h
index ca30406669..bd7dc86d78 100644
--- a/xen/include/asm-arm/time.h
+++ b/xen/include/asm-arm/time.h
@@ -7,7 +7,7 @@
     DT_MATCH_COMPATIBLE("arm,armv7-timer"), \
     DT_MATCH_COMPATIBLE("arm,armv8-timer")
 
-typedef unsigned long cycles_t;
+typedef uint64_t cycles_t;
 
 static inline cycles_t get_cycles (void)
 {
-- 
2.11.0


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

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

* Re: [Xen-devel] [PRE-4.12 PATCH] xen/arm: time: cycles_t should be an uint64_t and not unsigned long
  2019-06-20 17:47 [Xen-devel] [PRE-4.12 PATCH] xen/arm: time: cycles_t should be an uint64_t and not unsigned long Julien Grall
@ 2019-06-20 17:50 ` Andrew Cooper
  2019-06-21  9:20   ` Julien Grall
  2019-06-20 23:56 ` Stefano Stabellini
  1 sibling, 1 reply; 4+ messages in thread
From: Andrew Cooper @ 2019-06-20 17:50 UTC (permalink / raw)
  To: Julien Grall, xen-devel; +Cc: sstabellini, ian.jackson, jbeulich

On 20/06/2019 18:47, Julien Grall wrote:
> Since commit ca73ac8e7d "xen/arm: Add an isb() before reading CNTPCT_EL0
> to prevent re-ordering", get_cycles() is now returning the number of
> cycles and used in more callers.
>
> While the counter registers is always 64-bit, get_cycles() will only
> reutrn a 32-bit on Arm32 and therefore truncate the value. This will

"return 32 bits"

~Andrew

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

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

* Re: [Xen-devel] [PRE-4.12 PATCH] xen/arm: time: cycles_t should be an uint64_t and not unsigned long
  2019-06-20 17:47 [Xen-devel] [PRE-4.12 PATCH] xen/arm: time: cycles_t should be an uint64_t and not unsigned long Julien Grall
  2019-06-20 17:50 ` Andrew Cooper
@ 2019-06-20 23:56 ` Stefano Stabellini
  1 sibling, 0 replies; 4+ messages in thread
From: Stefano Stabellini @ 2019-06-20 23:56 UTC (permalink / raw)
  To: Julien Grall; +Cc: xen-devel, sstabellini, ian.jackson, jbeulich

On Thu, 20 Jun 2019, Julien Grall wrote:
> Since commit ca73ac8e7d "xen/arm: Add an isb() before reading CNTPCT_EL0
> to prevent re-ordering", get_cycles() is now returning the number of
> cycles and used in more callers.
> 
> While the counter registers is always 64-bit, get_cycles() will only
> reutrn a 32-bit on Arm32 and therefore truncate the value. This will
> result to weird behavior by both Xen and the Guest as the timer will not
> be setup correctly.
> 
> This could be resolved by switch cycles_t from unsigned long to
> unsigned int.
> 
> Signed-off-by: Julien Grall <julien.grall@arm.com>

Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>

I'll commit adding a reference to
da3d55ae67225798c2ad8f42af2f432f6f2b2214 in the commit message.


> ---
>     This is only targeting xen 4.11 and earlier. Xen 4.12 and later have
>     a correct definition of cycles_t thanks to da3d55ae67 "console:
>     avoid printing no or null time stamps".
> 
>     This will hopefully unblock osstest on staging-4.10 and
>     staging-4.11. This patch should be backported up to Xen 4.8.
> ---
>  xen/include/asm-arm/time.h | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/xen/include/asm-arm/time.h b/xen/include/asm-arm/time.h
> index ca30406669..bd7dc86d78 100644
> --- a/xen/include/asm-arm/time.h
> +++ b/xen/include/asm-arm/time.h
> @@ -7,7 +7,7 @@
>      DT_MATCH_COMPATIBLE("arm,armv7-timer"), \
>      DT_MATCH_COMPATIBLE("arm,armv8-timer")
>  
> -typedef unsigned long cycles_t;
> +typedef uint64_t cycles_t;
>  
>  static inline cycles_t get_cycles (void)
>  {
> -- 
> 2.11.0
> 

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

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

* Re: [Xen-devel] [PRE-4.12 PATCH] xen/arm: time: cycles_t should be an uint64_t and not unsigned long
  2019-06-20 17:50 ` Andrew Cooper
@ 2019-06-21  9:20   ` Julien Grall
  0 siblings, 0 replies; 4+ messages in thread
From: Julien Grall @ 2019-06-21  9:20 UTC (permalink / raw)
  To: Andrew Cooper, xen-devel; +Cc: sstabellini, ian.jackson, jbeulich

Hi,

On 20/06/2019 18:50, Andrew Cooper wrote:
> On 20/06/2019 18:47, Julien Grall wrote:
>> Since commit ca73ac8e7d "xen/arm: Add an isb() before reading CNTPCT_EL0
>> to prevent re-ordering", get_cycles() is now returning the number of
>> cycles and used in more callers.
>>
>> While the counter registers is always 64-bit, get_cycles() will only
>> reutrn a 32-bit on Arm32 and therefore truncate the value. This will
> 
> "return 32 bits"

Yes, sorry Stefano committed without this change.

Cheers,

-- 
Julien Grall

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

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

end of thread, other threads:[~2019-06-21  9:21 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-06-20 17:47 [Xen-devel] [PRE-4.12 PATCH] xen/arm: time: cycles_t should be an uint64_t and not unsigned long Julien Grall
2019-06-20 17:50 ` Andrew Cooper
2019-06-21  9:20   ` Julien Grall
2019-06-20 23:56 ` Stefano Stabellini

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).