Skip to content

Revert "[libc][NFC] adjust time related implementations" #91657

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 9, 2024

Conversation

SchrodingerZhu
Copy link
Contributor

Reverts #91485. It breaks GPU and fuchisa.

@llvmbot llvmbot added the libc label May 9, 2024
@llvmbot
Copy link
Member

llvmbot commented May 9, 2024

@llvm/pr-subscribers-libc

Author: Schrodinger ZHU Yifan (SchrodingerZhu)

Changes

Reverts llvm/llvm-project#91485. It breaks GPU and fuchisa.


Patch is 22.11 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/91657.diff

24 Files Affected:

  • (modified) libc/hdr/CMakeLists.txt (-9)
  • (removed) libc/hdr/time_macros.h (-22)
  • (modified) libc/hdr/types/CMakeLists.txt (-45)
  • (removed) libc/hdr/types/clock_t.h (-22)
  • (removed) libc/hdr/types/clockid_t.h (-22)
  • (removed) libc/hdr/types/struct_timeval.h (-21)
  • (removed) libc/hdr/types/suseconds_t.h (-22)
  • (removed) libc/hdr/types/time_t.h (-22)
  • (modified) libc/src/__support/CMakeLists.txt (-2)
  • (removed) libc/src/__support/time/CMakeLists.txt (-19)
  • (removed) libc/src/__support/time/clock_gettime.h (-23)
  • (removed) libc/src/__support/time/linux/CMakeLists.txt (-14)
  • (removed) libc/src/__support/time/units.h (-38)
  • (modified) libc/src/time/clock.h (+1-1)
  • (modified) libc/src/time/clock_gettime.h (+2-3)
  • (modified) libc/src/time/gettimeofday.h (+1-1)
  • (modified) libc/src/time/linux/CMakeLists.txt (+14-16)
  • (modified) libc/src/time/linux/clock.cpp (+11-9)
  • (renamed) libc/src/time/linux/clockGetTimeImpl.h (+17-8)
  • (modified) libc/src/time/linux/clock_gettime.cpp (+7-2)
  • (modified) libc/src/time/linux/gettimeofday.cpp (+7-7)
  • (modified) libc/src/time/linux/time.cpp (+8-4)
  • (modified) libc/src/time/nanosleep.h (+2-2)
  • (modified) libc/src/time/time_func.h (+1-1)
diff --git a/libc/hdr/CMakeLists.txt b/libc/hdr/CMakeLists.txt
index 7549342514304..179b05e6ee966 100644
--- a/libc/hdr/CMakeLists.txt
+++ b/libc/hdr/CMakeLists.txt
@@ -68,13 +68,4 @@ add_proxy_header_library(
     libc.include.llvm-libc-macros.sys_epoll_macros
 )
 
-add_proxy_header_library(
-  time_macros
-  HDRS
-    time_macros.h
-  FULL_BUILD_DEPENDS
-    libc.include.time
-    libc.include.llvm-libc-macros.time_macros
-)
-
 add_subdirectory(types)
diff --git a/libc/hdr/time_macros.h b/libc/hdr/time_macros.h
deleted file mode 100644
index dc36fe66f7a80..0000000000000
--- a/libc/hdr/time_macros.h
+++ /dev/null
@@ -1,22 +0,0 @@
-//===-- Definition of macros from time.h ----------------------------------===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===----------------------------------------------------------------------===//
-
-#ifndef LLVM_LIBC_HDR_TIME_MACROS_H
-#define LLVM_LIBC_HDR_TIME_MACROS_H
-
-#ifdef LIBC_FULL_BUILD
-
-#include "include/llvm-libc-macros/time-macros.h"
-
-#else // Overlay mode
-
-#include <time.h>
-
-#endif // LLVM_LIBC_FULL_BUILD
-
-#endif // LLVM_LIBC_HDR_TIME_MACROS_H
diff --git a/libc/hdr/types/CMakeLists.txt b/libc/hdr/types/CMakeLists.txt
index 3a1bb2f3c340f..46a66ec590202 100644
--- a/libc/hdr/types/CMakeLists.txt
+++ b/libc/hdr/types/CMakeLists.txt
@@ -63,48 +63,3 @@ add_proxy_header_library(
     libc.include.llvm-libc-types.fexcept_t
     libc.include.fenv
 )
-
-add_proxy_header_library(
-  time_t
-  HDRS
-    time_t.h
-  FULL_BUILD_DEPENDS
-    libc.include.llvm-libc-types.time_t
-    libc.include.time
-)
-
-add_proxy_header_library(
-  clockid_t
-  HDRS
-    clockid_t.h
-  FULL_BUILD_DEPENDS
-    libc.include.llvm-libc-types.clockid_t
-    libc.include.sys_types
-)
-
-add_proxy_header_library(
-  clock_t
-  HDRS
-    clock_t.h
-  FULL_BUILD_DEPENDS
-    libc.include.llvm-libc-types.clock_t
-    libc.include.time
-)
-
-add_proxy_header_library(
-  suseconds_t
-  HDRS
-    suseconds_t.h
-  FULL_BUILD_DEPENDS
-    libc.include.llvm-libc-types.suseconds_t
-    libc.include.sys_time
-)
-
-add_proxy_header_library(
-  struct_timeval
-  HDRS
-    struct_timeval.h
-  FULL_BUILD_DEPENDS
-    libc.include.llvm-libc-types.struct_timeval
-    libc.include.sys_time
-)
diff --git a/libc/hdr/types/clock_t.h b/libc/hdr/types/clock_t.h
deleted file mode 100644
index b0b658e96c3db..0000000000000
--- a/libc/hdr/types/clock_t.h
+++ /dev/null
@@ -1,22 +0,0 @@
-//===-- Proxy for clock_t -------------------------------------------------===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===----------------------------------------------------------------------===//
-
-#ifndef LLVM_LIBC_HDR_TYPES_CLOCK_T_H
-#define LLVM_LIBC_HDR_TYPES_CLOCK_T_H
-
-#ifdef LIBC_FULL_BUILD
-
-#include "include/llvm-libc-types/clock_t.h"
-
-#else // Overlay mode
-
-#include <sys/types.h>
-
-#endif // LLVM_LIBC_FULL_BUILD
-
-#endif // LLVM_LIBC_HDR_TYPES_CLOCK_T_H
diff --git a/libc/hdr/types/clockid_t.h b/libc/hdr/types/clockid_t.h
deleted file mode 100644
index 333342072a2ff..0000000000000
--- a/libc/hdr/types/clockid_t.h
+++ /dev/null
@@ -1,22 +0,0 @@
-//===-- Proxy for clockid_t -----------------------------------------------===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===----------------------------------------------------------------------===//
-
-#ifndef LLVM_LIBC_HDR_TYPES_CLOCKID_T_H
-#define LLVM_LIBC_HDR_TYPES_CLOCKID_T_H
-
-#ifdef LIBC_FULL_BUILD
-
-#include "include/llvm-libc-types/clockid_t.h"
-
-#else // Overlay mode
-
-#include <sys/types.h>
-
-#endif // LLVM_LIBC_FULL_BUILD
-
-#endif // LLVM_LIBC_HDR_TYPES_CLOCKID_T_H
diff --git a/libc/hdr/types/struct_timeval.h b/libc/hdr/types/struct_timeval.h
deleted file mode 100644
index 8fc321a52d711..0000000000000
--- a/libc/hdr/types/struct_timeval.h
+++ /dev/null
@@ -1,21 +0,0 @@
-//===-- Proxy for struct timeval  ----------------------------------------===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===----------------------------------------------------------------------===//
-#ifndef LLVM_LIBC_HDR_TYPES_STRUCT_TIMEVAL_H
-#define LLVM_LIBC_HDR_TYPES_STRUCT_TIMEVAL_H
-
-#ifdef LIBC_FULL_BUILD
-
-#include "include/llvm-libc-types/struct_timeval.h"
-
-#else
-
-#include <sys/time.h>
-
-#endif // LIBC_FULL_BUILD
-
-#endif // LLVM_LIBC_HDR_TYPES_STRUCT_TIMEVAL_H
diff --git a/libc/hdr/types/suseconds_t.h b/libc/hdr/types/suseconds_t.h
deleted file mode 100644
index 72e54a965f750..0000000000000
--- a/libc/hdr/types/suseconds_t.h
+++ /dev/null
@@ -1,22 +0,0 @@
-//===-- Proxy for suseconds_t ---------------------------------------------===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===----------------------------------------------------------------------===//
-
-#ifndef LLVM_LIBC_HDR_TIMES_SUSECONDS_T_H
-#define LLVM_LIBC_HDR_TIMES_SUSECONDS_T_H
-
-#ifdef LIBC_FULL_BUILD
-
-#include "include/llvm-libc-types/suseconds_t.h"
-
-#else // Overlay mode
-
-#include <sys/types.h>
-
-#endif // LLVM_LIBC_FULL_BUILD
-
-#endif // #ifndef LLVM_LIBC_HDR_TIMES_SUSECONDS_T_H
diff --git a/libc/hdr/types/time_t.h b/libc/hdr/types/time_t.h
deleted file mode 100644
index fc9a1506a2cda..0000000000000
--- a/libc/hdr/types/time_t.h
+++ /dev/null
@@ -1,22 +0,0 @@
-//===-- Proxy for time_t --------------------------------------------------===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===----------------------------------------------------------------------===//
-
-#ifndef LLVM_LIBC_HDR_TYPES_TIME_T_H
-#define LLVM_LIBC_HDR_TYPES_TIME_T_H
-
-#ifdef LIBC_FULL_BUILD
-
-#include "include/llvm-libc-types/time_t.h"
-
-#else // Overlay mode
-
-#include <time.h>
-
-#endif // LLVM_LIBC_FULL_BUILD
-
-#endif // LLVM_LIBC_HDR_TYPES_TIME_T_H
diff --git a/libc/src/__support/CMakeLists.txt b/libc/src/__support/CMakeLists.txt
index 32d693ec6a268..dcae55e050bf1 100644
--- a/libc/src/__support/CMakeLists.txt
+++ b/libc/src/__support/CMakeLists.txt
@@ -281,5 +281,3 @@ add_subdirectory(File)
 add_subdirectory(HashTable)
 
 add_subdirectory(fixed_point)
-
-add_subdirectory(time)
diff --git a/libc/src/__support/time/CMakeLists.txt b/libc/src/__support/time/CMakeLists.txt
deleted file mode 100644
index 36ce4f9dadb2c..0000000000000
--- a/libc/src/__support/time/CMakeLists.txt
+++ /dev/null
@@ -1,19 +0,0 @@
-if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${LIBC_TARGET_OS})
-  add_subdirectory(${LIBC_TARGET_OS})
-endif()
-
-add_object_library(
-  clock_gettime
-  ALIAS
-  DEPENDS
-    .${LIBC_TARGET_OS}.clock_gettime
-)
-
-add_header_library(
-  units
-  HDRS
-    units.h
-  DEPENDS
-    libc.src.__support.common
-    libc.hdr.types.time_t
-)
diff --git a/libc/src/__support/time/clock_gettime.h b/libc/src/__support/time/clock_gettime.h
deleted file mode 100644
index 0655ccdc0028b..0000000000000
--- a/libc/src/__support/time/clock_gettime.h
+++ /dev/null
@@ -1,23 +0,0 @@
-//===--- clock_gettime internal implementation ------------------*- C++ -*-===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===----------------------------------------------------------------------===//
-
-#ifndef LLVM_LIBC_SRC___SUPPORT_TIME_CLOCK_GETTIME_H
-#define LLVM_LIBC_SRC___SUPPORT_TIME_CLOCK_GETTIME_H
-#include "hdr/types/clockid_t.h"
-#include "hdr/types/struct_timespec.h"
-#include "src/__support/common.h"
-
-#include "src/__support/error_or.h"
-
-namespace LIBC_NAMESPACE {
-namespace internal {
-ErrorOr<int> clock_gettime(clockid_t clockid, timespec *ts);
-}
-} // namespace LIBC_NAMESPACE
-
-#endif // LLVM_LIBC_SRC___SUPPORT_TIME_CLOCK_GETTIME_H
diff --git a/libc/src/__support/time/linux/CMakeLists.txt b/libc/src/__support/time/linux/CMakeLists.txt
deleted file mode 100644
index 034fa317ff6df..0000000000000
--- a/libc/src/__support/time/linux/CMakeLists.txt
+++ /dev/null
@@ -1,14 +0,0 @@
-add_object_library(
-  clock_gettime
-  HDRS
-    ../clock_gettime.h
-  SRCS
-    clock_gettime.cpp
-  DEPENDS
-    libc.include.sys_syscall
-    libc.hdr.types.struct_timespec
-    libc.hdr.types.clockid_t
-    libc.src.__support.common
-    libc.src.__support.error_or
-    libc.src.__support.OSUtil.osutil
-)
diff --git a/libc/src/__support/time/units.h b/libc/src/__support/time/units.h
deleted file mode 100644
index f6bd19f9b1396..0000000000000
--- a/libc/src/__support/time/units.h
+++ /dev/null
@@ -1,38 +0,0 @@
-//===--- Time units conversion ----------------------------------*- C++ -*-===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===----------------------------------------------------------------------===//
-
-#ifndef LLVM_LIBC_SRC___SUPPORT_TIME_UNITS_H
-#define LLVM_LIBC_SRC___SUPPORT_TIME_UNITS_H
-
-#include "hdr/types/time_t.h"
-#include "src/__support/common.h"
-
-namespace LIBC_NAMESPACE {
-namespace time_units {
-LIBC_INLINE constexpr time_t operator""_s_ns(unsigned long long s) {
-  return s * 1'000'000'000;
-}
-LIBC_INLINE constexpr time_t operator""_s_us(unsigned long long s) {
-  return s * 1'000'000;
-}
-LIBC_INLINE constexpr time_t operator""_s_ms(unsigned long long s) {
-  return s * 1'000;
-}
-LIBC_INLINE constexpr time_t operator""_ms_ns(unsigned long long ms) {
-  return ms * 1'000'000;
-}
-LIBC_INLINE constexpr time_t operator""_ms_us(unsigned long long ms) {
-  return ms * 1'000;
-}
-LIBC_INLINE constexpr time_t operator""_us_ns(unsigned long long us) {
-  return us * 1'000;
-}
-} // namespace time_units
-} // namespace LIBC_NAMESPACE
-
-#endif // LLVM_LIBC_SRC___SUPPORT_TIME_UNITS_H
diff --git a/libc/src/time/clock.h b/libc/src/time/clock.h
index f5d14d036e138..d4af7656644a0 100644
--- a/libc/src/time/clock.h
+++ b/libc/src/time/clock.h
@@ -9,7 +9,7 @@
 #ifndef LLVM_LIBC_SRC_TIME_CLOCK_H
 #define LLVM_LIBC_SRC_TIME_CLOCK_H
 
-#include "hdr/types/clock_t.h"
+#include <time.h>
 
 namespace LIBC_NAMESPACE {
 
diff --git a/libc/src/time/clock_gettime.h b/libc/src/time/clock_gettime.h
index 48e81a3554291..72e2e1949feb6 100644
--- a/libc/src/time/clock_gettime.h
+++ b/libc/src/time/clock_gettime.h
@@ -9,12 +9,11 @@
 #ifndef LLVM_LIBC_SRC_TIME_CLOCK_GETTIME_H
 #define LLVM_LIBC_SRC_TIME_CLOCK_GETTIME_H
 
-#include "hdr/types/clockid_t.h"
-#include "hdr/types/struct_timespec.h"
+#include <time.h>
 
 namespace LIBC_NAMESPACE {
 
-int clock_gettime(clockid_t clockid, timespec *tp);
+int clock_gettime(clockid_t clockid, struct timespec *tp);
 
 } // namespace LIBC_NAMESPACE
 
diff --git a/libc/src/time/gettimeofday.h b/libc/src/time/gettimeofday.h
index 62ee31edcad67..880b94cee7311 100644
--- a/libc/src/time/gettimeofday.h
+++ b/libc/src/time/gettimeofday.h
@@ -9,7 +9,7 @@
 #ifndef LLVM_LIBC_SRC_TIME_GETTIMEOFDAY_H
 #define LLVM_LIBC_SRC_TIME_GETTIMEOFDAY_H
 
-#include "hdr/types/struct_timeval.h"
+#include <time.h>
 
 namespace LIBC_NAMESPACE {
 
diff --git a/libc/src/time/linux/CMakeLists.txt b/libc/src/time/linux/CMakeLists.txt
index 8a0e6b04b66e6..df79bf5986261 100644
--- a/libc/src/time/linux/CMakeLists.txt
+++ b/libc/src/time/linux/CMakeLists.txt
@@ -5,9 +5,9 @@ add_entrypoint_object(
   HDRS
     ../time_func.h
   DEPENDS
-    libc.hdr.time_macros
-    libc.hdr.types.time_t
-    libc.src.__support.time.clock_gettime
+    libc.include.time
+    libc.include.sys_syscall
+    libc.src.__support.OSUtil.osutil
     libc.src.errno.errno
 )
 
@@ -18,11 +18,10 @@ add_entrypoint_object(
   HDRS
     ../clock.h
   DEPENDS
-    libc.hdr.time_macros
-    libc.hdr.types.clock_t
-    libc.src.__support.time.units
-    libc.src.__support.time.clock_gettime
+    libc.include.time
+    libc.include.sys_syscall
     libc.src.__support.CPP.limits
+    libc.src.__support.OSUtil.osutil
     libc.src.errno.errno
 )
 
@@ -33,10 +32,10 @@ add_entrypoint_object(
   HDRS
     ../nanosleep.h
   DEPENDS
-    libc.hdr.types.struct_timespec
+    libc.include.time
     libc.include.sys_syscall
-    libc.src.__support.OSUtil.osutil
     libc.src.__support.CPP.limits
+    libc.src.__support.OSUtil.osutil
     libc.src.errno.errno
 )
 
@@ -47,9 +46,9 @@ add_entrypoint_object(
   HDRS
     ../clock_gettime.h
   DEPENDS
-    libc.hdr.types.clockid_t
-    libc.hdr.types.struct_timespec
-    libc.src.__support.time.clock_gettime
+    libc.include.time
+    libc.include.sys_syscall
+    libc.src.__support.OSUtil.osutil
     libc.src.errno.errno
 )
 
@@ -60,9 +59,8 @@ add_entrypoint_object(
   HDRS
     ../gettimeofday.h
   DEPENDS
-    libc.hdr.time_macros
-    libc.hdr.types.suseconds_t
-    libc.src.__support.time.clock_gettime
-    libc.src.__support.time.units
+    libc.include.time
+    libc.include.sys_syscall
+    libc.src.__support.OSUtil.osutil
     libc.src.errno.errno
 )
diff --git a/libc/src/time/linux/clock.cpp b/libc/src/time/linux/clock.cpp
index fc48e2792747d..1e95f0526bc9c 100644
--- a/libc/src/time/linux/clock.cpp
+++ b/libc/src/time/linux/clock.cpp
@@ -7,19 +7,21 @@
 //===----------------------------------------------------------------------===//
 
 #include "src/time/clock.h"
-#include "hdr/time_macros.h"
+
 #include "src/__support/CPP/limits.h"
+#include "src/__support/OSUtil/syscall.h" // For internal syscall function.
 #include "src/__support/common.h"
-#include "src/__support/time/clock_gettime.h"
-#include "src/__support/time/units.h"
 #include "src/errno/libc_errno.h"
+#include "src/time/linux/clockGetTimeImpl.h"
+
+#include <sys/syscall.h> // For syscall numbers.
+#include <time.h>
 
 namespace LIBC_NAMESPACE {
 
 LLVM_LIBC_FUNCTION(clock_t, clock, ()) {
-  using namespace time_units;
   struct timespec ts;
-  auto result = internal::clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &ts);
+  auto result = internal::clock_gettimeimpl(CLOCK_PROCESS_CPUTIME_ID, &ts);
   if (!result.has_value()) {
     libc_errno = result.error();
     return -1;
@@ -32,15 +34,15 @@ LLVM_LIBC_FUNCTION(clock_t, clock, ()) {
       cpp::numeric_limits<clock_t>::max() / CLOCKS_PER_SEC;
   if (ts.tv_sec > CLOCK_SECS_MAX)
     return clock_t(-1);
-  if (ts.tv_nsec / 1_s_ns > CLOCK_SECS_MAX - ts.tv_sec)
+  if (ts.tv_nsec / 1000000000 > CLOCK_SECS_MAX - ts.tv_sec)
     return clock_t(-1);
 
   // For the integer computation converting tv_nsec to clocks to work
   // correctly, we want CLOCKS_PER_SEC to be less than 1000000000.
-  static_assert(1_s_ns > CLOCKS_PER_SEC,
-                "Expected CLOCKS_PER_SEC to be less than 1'000'000'000.");
+  static_assert(1000000000 > CLOCKS_PER_SEC,
+                "Expected CLOCKS_PER_SEC to be less than 1000000000.");
   return clock_t(ts.tv_sec * CLOCKS_PER_SEC +
-                 ts.tv_nsec / (1_s_ns / CLOCKS_PER_SEC));
+                 ts.tv_nsec / (1000000000 / CLOCKS_PER_SEC));
 }
 
 } // namespace LIBC_NAMESPACE
diff --git a/libc/src/__support/time/linux/clock_gettime.cpp b/libc/src/time/linux/clockGetTimeImpl.h
similarity index 64%
rename from libc/src/__support/time/linux/clock_gettime.cpp
rename to libc/src/time/linux/clockGetTimeImpl.h
index 6a131df9ba593..8c8c9fcf845cc 100644
--- a/libc/src/__support/time/linux/clock_gettime.cpp
+++ b/libc/src/time/linux/clockGetTimeImpl.h
@@ -1,4 +1,4 @@
-//===--- clock_gettime linux implementation ---------------------*- C++ -*-===//
+//===- Linux implementation of the POSIX clock_gettime function -*- C++ -*-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -6,14 +6,23 @@
 //
 //===----------------------------------------------------------------------===//
 
-#ifndef LLVM_LIBC_SRC___SUPPORT_TIME_LINUX_CLOCK_GETTIME_H
-#define LLVM_LIBC_SRC___SUPPORT_TIME_LINUX_CLOCK_GETTIME_H
-#include "src/__support/time/clock_gettime.h"
-#include "src/__support/OSUtil/syscall.h"
-#include <sys/syscall.h>
+#ifndef LLVM_LIBC_SRC_TIME_LINUX_CLOCKGETTIMEIMPL_H
+#define LLVM_LIBC_SRC_TIME_LINUX_CLOCKGETTIMEIMPL_H
+
+#include "src/__support/OSUtil/syscall.h" // For internal syscall function.
+#include "src/__support/common.h"
+#include "src/__support/error_or.h"
+#include "src/errno/libc_errno.h"
+
+#include <stdint.h>      // For int64_t.
+#include <sys/syscall.h> // For syscall numbers.
+#include <time.h>
+
 namespace LIBC_NAMESPACE {
 namespace internal {
-ErrorOr<int> clock_gettime(clockid_t clockid, timespec *ts) {
+
+LIBC_INLINE ErrorOr<int> clock_gettimeimpl(clockid_t clockid,
+                                           struct timespec *ts) {
 #if SYS_clock_gettime
   int ret = LIBC_NAMESPACE::syscall_impl<int>(SYS_clock_gettime,
                                               static_cast<long>(clockid),
@@ -36,4 +45,4 @@ ErrorOr<int> clock_gettime(clockid_t clockid, timespec *ts) {
 } // namespace internal
 } // namespace LIBC_NAMESPACE
 
-#endif // LLVM_LIBC_SRC___SUPPORT_TIME_LINUX_CLOCK_GETTIME_H
+#endif // LLVM_LIBC_SRC_TIME_LINUX_CLOCKGETTIMEIMPL_H
diff --git a/libc/src/time/linux/clock_gettime.cpp b/libc/src/time/linux/clock_gettime.cpp
index 920363e85e06c..47e974a866c83 100644
--- a/libc/src/time/linux/clock_gettime.cpp
+++ b/libc/src/time/linux/clock_gettime.cpp
@@ -7,16 +7,21 @@
 //===----------------------------------------------------------------------===//
 
 #include "src/time/clock_gettime.h"
+
+#include "src/__support/OSUtil/syscall.h" // For internal syscall function.
 #include "src/__support/common.h"
-#include "src/__support/time/clock_gettime.h"
 #include "src/errno/libc_errno.h"
+#include "src/time/linux/clockGetTimeImpl.h"
+
+#include <sys/syscall.h> // For syscall numbers.
+#include <time.h>
 
 namespace LIBC_NAMESPACE {
 
 // TODO(michaelrj): Move this into time/linux with the other syscalls.
 LLVM_LIBC_FUNCTION(int, clock_gettime,
                    (clockid_t clockid, struct timespec *ts)) {
-  auto result = internal::clock_gettime(clockid, ts);
+  auto result = internal::clock_gettimeimpl(clockid, ts);
 
   // A negative return value indicates an error with the magnitude of the
   // value being the error code.
diff --git a/libc/src/time/linux/gettimeofday.cpp b/libc/src/time/linux/gettimeofday.cpp
index c7bcd45e01fa9..07ab4d579176e 100644
--- a/libc/src/time/linux/gettimeofday.cpp
+++ b/libc/src/time/linux/gettimeofday.cpp
@@ -7,24 +7,24 @@
 //===----------------------------------------------------------------------===//
 
 #include "src/time/gettimeofday.h"
-#include "hdr/time_macros.h"
-#include "hdr/types/suseconds_t.h"
+
+#include "src/__support/OSUtil/syscall.h" // For internal syscall function.
 #include "src/__support/common.h"
-#include "src/__support/time/clock_gettime.h"
-#include "src/__support/time/units.h"
 #include "src/errno/libc_errno.h"
+#include "src/time/linux/clockGetTimeImpl.h"
+
+#include <sys/syscall.h> // For syscall numbers.
 
 namespace LIBC_NAMESPACE {
 
 // TODO(michaelrj): Move this into time/linux with the other syscalls.
 LLVM_LIBC_FUNCTION(int, gettimeofday,
                    (struct timeval * tv, [[maybe_unused]] void *unused)) {
-  using namespace time_units;
   if (tv == nullptr)
     return 0;
 
   struct timespec ts;
-  auto result = internal::clock_gettime(CLOCK_REALTIME, &ts);
+  auto result = internal::clock_gettimeimpl(CLOCK_REALTIME, &ts);
 
   // A negative return value indicates an error with the magnitude of the
   // value being the error code.
@@ -34,7 +34,7 @@ LLVM_LIBC_FUNCTION(int, gettimeofday,
   }
 
   tv->tv_sec = ts.tv_sec;
-  tv->tv_usec =...
[truncated]

@lntue lntue merged commit 5a0e0b6 into main May 9, 2024
@lntue lntue deleted the revert-91485-libc/time branch May 9, 2024 21:28
SchrodingerZhu added a commit that referenced this pull request May 10, 2024
SchrodingerZhu added a commit that referenced this pull request May 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants