summaryrefslogtreecommitdiffstats
path: root/src/arch/riscv/include
diff options
context:
space:
mode:
authorMichael Brown2024-09-24 15:49:32 +0200
committerMichael Brown2024-09-24 16:40:45 +0200
commit5f7c6bd95bd6089473db3ba4f033584f5de0ee8a (patch)
tree9b58e51eb17191f26cf24a7af33523ed16b9faa7 /src/arch/riscv/include
parent[crypto] Use constant-time big integer multiplication (diff)
downloadipxe-5f7c6bd95bd6089473db3ba4f033584f5de0ee8a.tar.gz
ipxe-5f7c6bd95bd6089473db3ba4f033584f5de0ee8a.tar.xz
ipxe-5f7c6bd95bd6089473db3ba4f033584f5de0ee8a.zip
[profile] Standardise return type of profile_timestamp()
All consumers of profile_timestamp() currently treat the value as an unsigned long. Only the elapsed number of ticks is ever relevant: the absolute value of the timestamp is not used. Profiling is used to measure short durations that are generally fewer than a million CPU cycles, for which an unsigned long is easily large enough. Standardise the return type of profile_timestamp() as unsigned long across all CPU architectures. This allows 32-bit architectures such as i386 and riscv32 to omit all logic associated with retrieving the upper 32 bits of the 64-bit hardware counter, which simplifies the code and allows riscv32 and riscv64 to share the same implementation. Signed-off-by: Michael Brown <mcb30@ipxe.org>
Diffstat (limited to 'src/arch/riscv/include')
-rw-r--r--src/arch/riscv/include/bits/profile.h28
1 files changed, 28 insertions, 0 deletions
diff --git a/src/arch/riscv/include/bits/profile.h b/src/arch/riscv/include/bits/profile.h
new file mode 100644
index 000000000..e9e003dab
--- /dev/null
+++ b/src/arch/riscv/include/bits/profile.h
@@ -0,0 +1,28 @@
+#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 )) unsigned long
+profile_timestamp ( void ) {
+ unsigned long cycles;
+
+ /* Read timestamp counter */
+ __asm__ __volatile__ ( "rdcycle %0" : "=r" ( cycles ) );
+ return cycles;
+}
+
+#endif /* _BITS_PROFILE_H */