]> git.ipfire.org Git - thirdparty/ipxe.git/commitdiff
[profile] Standardise return type of profile_timestamp()
authorMichael Brown <mcb30@ipxe.org>
Tue, 24 Sep 2024 13:49:32 +0000 (14:49 +0100)
committerMichael Brown <mcb30@ipxe.org>
Tue, 24 Sep 2024 14:40:45 +0000 (15:40 +0100)
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>
src/arch/arm32/include/bits/profile.h
src/arch/arm64/include/bits/profile.h
src/arch/i386/include/bits/profile.h
src/arch/loong64/include/bits/profile.h
src/arch/riscv/include/bits/profile.h [moved from src/arch/riscv64/include/bits/profile.h with 81% similarity]
src/arch/riscv32/include/bits/profile.h [deleted file]
src/arch/x86_64/include/bits/profile.h
src/include/ipxe/profile.h

index 2b15d16048289390d23973a5183ad2bf882d7fd2..4e4bf48a36cddc365cf9915e554437d564d7e251 100644 (file)
@@ -16,7 +16,7 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
  *
  * @ret timestamp      Timestamp
  */
-static inline __attribute__ (( always_inline )) uint64_t
+static inline __attribute__ (( always_inline )) unsigned long
 profile_timestamp ( void ) {
        uint32_t cycles;
 
index 62ffa3772580a689a71f52c274bd3071ead92846..4a5b3f7a157bd2009f0a6ecc93f96bde34045650 100644 (file)
@@ -16,7 +16,7 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
  *
  * @ret timestamp      Timestamp
  */
-static inline __attribute__ (( always_inline )) uint64_t
+static inline __attribute__ (( always_inline )) unsigned long
 profile_timestamp ( void ) {
        uint64_t cycles;
 
index e184d7b51e0711b319339345b5636ae7e87c71f0..21c216a819816e76a2700fbf7bd480fe3734c928 100644 (file)
@@ -16,12 +16,12 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
  *
  * @ret timestamp      Timestamp
  */
-static inline __attribute__ (( always_inline )) uint64_t
+static inline __attribute__ (( always_inline )) unsigned long
 profile_timestamp ( void ) {
-       uint64_t tsc;
+       uint32_t tsc;
 
        /* Read timestamp counter */
-       __asm__ __volatile__ ( "rdtsc" : "=A" ( tsc ) );
+       __asm__ __volatile__ ( "rdtsc" : "=a" ( tsc ) : : "edx" );
        return tsc;
 }
 
index 9f597ce2d92d6b6beebe1eaa4583610c38e413cd..02f8d4b7ca4ffb540356de6a797819d9755f629b 100644 (file)
@@ -16,7 +16,7 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
  *
  * @ret timestamp      Timestamp
  */
-static inline __attribute__ (( always_inline )) uint64_t
+static inline __attribute__ (( always_inline )) unsigned long
 profile_timestamp ( void ) {
        uint64_t cycles;
 
similarity index 81%
rename from src/arch/riscv64/include/bits/profile.h
rename to src/arch/riscv/include/bits/profile.h
index 2c8e29a22ecbab9c88213f4b40f0f532698d3f7e..e9e003dab5d8b409ce22f185a33f61ff4380db11 100644 (file)
@@ -16,9 +16,9 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
  *
  * @ret timestamp      Timestamp
  */
-static inline __attribute__ (( always_inline )) uint64_t
+static inline __attribute__ (( always_inline )) unsigned long
 profile_timestamp ( void ) {
-       uint64_t cycles;
+       unsigned long cycles;
 
        /* Read timestamp counter */
        __asm__ __volatile__ ( "rdcycle %0" : "=r" ( cycles ) );
diff --git a/src/arch/riscv32/include/bits/profile.h b/src/arch/riscv32/include/bits/profile.h
deleted file mode 100644 (file)
index cb96907..0000000
+++ /dev/null
@@ -1,36 +0,0 @@
-#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 */
index b7c74fbe75e231c2c058b62773bd3f87d98ed562..c85b6fe5c29a1500d5d63e3a98bedda75b5fef69 100644 (file)
@@ -16,7 +16,7 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
  *
  * @ret timestamp      Timestamp
  */
-static inline __attribute__ (( always_inline )) uint64_t
+static inline __attribute__ (( always_inline )) unsigned long
 profile_timestamp ( void ) {
        uint32_t eax;
        uint32_t edx;
index 2c69e120840243b099ca766b97f0bf3fb201a992..fd45b3cdce0c55dfe73d9545b9008ee6248fe6d4 100644 (file)
@@ -60,6 +60,8 @@ struct profiler {
 #define __profiler
 #endif
 
+unsigned long profile_timestamp ( void );
+
 extern unsigned long profile_excluded;
 
 extern void profile_update ( struct profiler *profiler, unsigned long sample );