[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 12:04:45 PST 2023


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

>From 8df14ff5256544e25ce160112c869c65aaca2370 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 | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/libc/src/time/gpu/time_utils.h b/libc/src/time/gpu/time_utils.h
index 53548181e17e25..9ad381dd24c111 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;
+
 #elif defined(__gfx900__) || defined(__gfx902__) || defined(__gfx904__) ||     \
     defined(__gfx906__) || defined(__gfx908__) || defined(__gfx909__) ||       \
     defined(__gfx90a__) || defined(__gfx90c__) || defined(__gfx940__)
@@ -36,10 +37,11 @@ constexpr uint64_t clock_freq = 25000000;
 constexpr uint64_t clock_freq = 0;
 #endif
 
-// 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.
+// 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