Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/arch/riscv/include Use __volatile so the compiler doesn'...



details:   https://anonhg.NetBSD.org/src/rev/d7fa3e234f58
branches:  trunk
changeset: 371849:d7fa3e234f58
user:      simonb <simonb%NetBSD.org@localhost>
date:      Sat Oct 15 06:46:41 2022 +0000

description:
Use __volatile so the compiler doesn't optimise out successive calls
to cpu_counter().
Add a 64-bit cycle counter on _LP64.

diffstat:

 sys/arch/riscv/include/cpu_counter.h |  21 ++++++++++++++++++---
 1 files changed, 18 insertions(+), 3 deletions(-)

diffs (48 lines):

diff -r 7d4eaf977883 -r d7fa3e234f58 sys/arch/riscv/include/cpu_counter.h
--- a/sys/arch/riscv/include/cpu_counter.h      Sat Oct 15 06:41:43 2022 +0000
+++ b/sys/arch/riscv/include/cpu_counter.h      Sat Oct 15 06:46:41 2022 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: cpu_counter.h,v 1.2 2022/10/15 06:41:43 simonb Exp $   */
+/*     $NetBSD: cpu_counter.h,v 1.3 2022/10/15 06:46:41 simonb Exp $   */
 
 /*
  * Copyright (c) 2000 Soren S. Jorvang.  All rights reserved.
@@ -25,7 +25,7 @@
  * SUCH DAMAGE.
  */
 
-/* $NetBSD: cpu_counter.h,v 1.2 2022/10/15 06:41:43 simonb Exp $ */
+/* $NetBSD: cpu_counter.h,v 1.3 2022/10/15 06:46:41 simonb Exp $ */
 /*-
  * Copyright (c) 2014 The NetBSD Foundation, Inc.
  * All rights reserved.
@@ -67,13 +67,28 @@
 #ifdef _KERNEL
 
 #define        cpu_hascounter()        true
+
+#ifdef _LP64
+static __inline uint64_t
+cpu_counter(void)
+{
+       uint64_t __count;
+
+       __asm __volatile("csrr\t%0, cycle" : "=r"(__count));
+       return __count;
+}
+
+
+#else /* 32-bit */
 #define        cpu_counter()           cpu_counter32()
+#endif /* 32-bit */
 
 static __inline uint32_t
 cpu_counter32(void)
 {
        uint32_t __count;
-       __asm("csrr\t%0, cycle" : "=r"(__count));
+
+       __asm __volatile("csrr\t%0, cycle" : "=r"(__count));
        return __count;
 }
 



Home | Main Index | Thread Index | Old Index