diff options
author | Michael Brown <mcb30@ipxe.org> | 2024-09-24 14:49:32 +0100 |
---|---|---|
committer | Michael Brown <mcb30@ipxe.org> | 2024-09-24 15:40:45 +0100 |
commit | 5f7c6bd95bd6089473db3ba4f033584f5de0ee8a (patch) | |
tree | 9b58e51eb17191f26cf24a7af33523ed16b9faa7 /src/arch | |
parent | 3def13265d9475c861eed1a101584b761e97ae33 (diff) | |
download | ipxe-5f7c6bd95bd6089473db3ba4f033584f5de0ee8a.tar.gz |
[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')
-rw-r--r-- | src/arch/arm32/include/bits/profile.h | 2 | ||||
-rw-r--r-- | src/arch/arm64/include/bits/profile.h | 2 | ||||
-rw-r--r-- | src/arch/i386/include/bits/profile.h | 6 | ||||
-rw-r--r-- | src/arch/loong64/include/bits/profile.h | 2 | ||||
-rw-r--r-- | src/arch/riscv/include/bits/profile.h (renamed from src/arch/riscv64/include/bits/profile.h) | 4 | ||||
-rw-r--r-- | src/arch/riscv32/include/bits/profile.h | 36 | ||||
-rw-r--r-- | src/arch/x86_64/include/bits/profile.h | 2 |
7 files changed, 9 insertions, 45 deletions
diff --git a/src/arch/arm32/include/bits/profile.h b/src/arch/arm32/include/bits/profile.h index 2b15d1604..4e4bf48a3 100644 --- a/src/arch/arm32/include/bits/profile.h +++ b/src/arch/arm32/include/bits/profile.h @@ -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; diff --git a/src/arch/arm64/include/bits/profile.h b/src/arch/arm64/include/bits/profile.h index 62ffa3772..4a5b3f7a1 100644 --- a/src/arch/arm64/include/bits/profile.h +++ b/src/arch/arm64/include/bits/profile.h @@ -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; diff --git a/src/arch/i386/include/bits/profile.h b/src/arch/i386/include/bits/profile.h index e184d7b51..21c216a81 100644 --- a/src/arch/i386/include/bits/profile.h +++ b/src/arch/i386/include/bits/profile.h @@ -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; } diff --git a/src/arch/loong64/include/bits/profile.h b/src/arch/loong64/include/bits/profile.h index 9f597ce2d..02f8d4b7c 100644 --- a/src/arch/loong64/include/bits/profile.h +++ b/src/arch/loong64/include/bits/profile.h @@ -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; diff --git a/src/arch/riscv64/include/bits/profile.h b/src/arch/riscv/include/bits/profile.h index 2c8e29a22..e9e003dab 100644 --- a/src/arch/riscv64/include/bits/profile.h +++ b/src/arch/riscv/include/bits/profile.h @@ -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 index cb969077d..000000000 --- a/src/arch/riscv32/include/bits/profile.h +++ /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 */ diff --git a/src/arch/x86_64/include/bits/profile.h b/src/arch/x86_64/include/bits/profile.h index b7c74fbe7..c85b6fe5c 100644 --- a/src/arch/x86_64/include/bits/profile.h +++ b/src/arch/x86_64/include/bits/profile.h @@ -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; |