[libc-commits] [libc] [libc][Obvious] Correctly initialize the default clock frequency (PR #76582)

Joseph Huber via libc-commits libc-commits at lists.llvm.org
Fri Dec 29 11:22:25 PST 2023


https://github.com/jhuber6 created https://github.com/llvm/llvm-project/pull/76582

Summary:
The AMDGPU architecture does not use a fixed frequency for all of its
architectures. However, the newer GPUs tend to have one that's
consistent between them (Except for Vega10). This was set up but not
actually used, so the implementation was just defaulting to whatever
value the global was being set to. Fix.


>From 921b77d2122fb91b39e0de18bd276f5bf270724f Mon Sep 17 00:00:00 2001
From: Joseph Huber <huberjn at outlook.com>
Date: Fri, 29 Dec 2023 13:17:43 -0600
Subject: [PATCH] [libc][Obvious] Correctly initialize the default clock
 frequency

Summary:
The AMDGPU architecture does not use a fixed frequency for all of its
architectures. However, the newer GPUs tend to have one that's
consistent between them (Except for Vega10). This was set up but not
actually used, so the implementation was just defaulting to whatever
value the global was being set to. Fix.
---
 libc/src/time/gpu/time_utils.h | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/libc/src/time/gpu/time_utils.h b/libc/src/time/gpu/time_utils.h
index 53548181e17e25..331d0f62f739b6 100644
--- a/libc/src/time/gpu/time_utils.h
+++ b/libc/src/time/gpu/time_utils.h
@@ -25,6 +25,7 @@ namespace LIBC_NAMESPACE {
     defined(__gfx1150__) || defined(__gfx1151__)
 // These architectures use a 100 MHz fixed frequency clock.
 constexpr uint64_t clock_freq = 100000000;
+                                100000000
 #elif defined(__gfx900__) || defined(__gfx902__) || defined(__gfx904__) ||     \
     defined(__gfx906__) || defined(__gfx908__) || defined(__gfx909__) ||       \
     defined(__gfx90a__) || defined(__gfx90c__) || defined(__gfx940__)
@@ -39,7 +40,7 @@ constexpr uint64_t clock_freq = 0;
 // We provide an externally visible symbol such that the runtime can set this to
 // the correct value. If it is not set we try to default to the known values.
 extern "C" [[gnu::visibility("protected")]] uint64_t
-    [[clang::address_space(4)]] __llvm_libc_clock_freq;
+    [[clang::address_space(4)]] __llvm_libc_clock_freq = clock_freq;
 #define GPU_CLOCKS_PER_SEC static_cast<clock_t>(__llvm_libc_clock_freq)
 
 #elif defined(LIBC_TARGET_ARCH_IS_NVPTX)



More information about the libc-commits mailing list