aboutsummaryrefslogtreecommitdiffstats
path: root/src/arch/riscv32/include/bits/profile.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/arch/riscv32/include/bits/profile.h')
-rw-r--r--src/arch/riscv32/include/bits/profile.h36
1 files changed, 36 insertions, 0 deletions
diff --git a/src/arch/riscv32/include/bits/profile.h b/src/arch/riscv32/include/bits/profile.h
new file mode 100644
index 000000000..cb969077d
--- /dev/null
+++ b/src/arch/riscv32/include/bits/profile.h
@@ -0,0 +1,36 @@
+#ifndef _BITS_PROFILE_H
+#define _BITS_PROFILE_H
+
+/** @file
+ *
+ * Profiling
+ *
+ */
+
+FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
+
+#include <stdint.h>
+
+/**
+ * Get profiling timestamp
+ *
+ * @ret timestamp Timestamp
+ */
+static inline __attribute__ (( always_inline )) uint64_t
+profile_timestamp ( void ) {
+ uint32_t cycles_lo;
+ uint32_t cycles_hi;
+ uint32_t tmp;
+
+ /* Read timestamp counter */
+ __asm__ __volatile__ ( "\n1:\n\t"
+ "rdcycleh %1\n\t"
+ "rdcycle %0\n\t"
+ "rdcycleh %2\n\t"
+ "bne %1, %2, 1b\n\t"
+ : "=r" ( cycles_lo ), "=r" ( cycles_hi ),
+ "=r" ( tmp ) );
+ return ( ( ( ( uint64_t ) cycles_hi ) << 32 ) | cycles_lo );
+}
+
+#endif /* _BITS_PROFILE_H */