[libc-commits] [libc] 48c35e1 - [libc] Implement timer_getoverrun in time (#234839)

via libc-commits libc-commits at lists.llvm.org
Fri Oct 23 03:24:40 PDT 2026


Author: Aman Maurya
Date: 2026-10-23T15:54:35+05:30
New Revision: 48c35e1861f64ff4e42197aa21380b635193e21e

URL: https://github.com/llvm/llvm-project/commit/48c35e1861f64ff4e42197aa21380b635193e21e
DIFF: https://github.com/llvm/llvm-project/commit/48c35e1861f64ff4e42197aa21380b635193e21e.diff

LOG: [libc] Implement timer_getoverrun in time (#234839)

### Summary
Implement the standard POSIX function `timer_getoverrun` in `<time.h>`.

- Adds internal Linux syscall wrapper in
`libc/src/__support/OSUtil/linux/syscall_wrappers/timer_getoverrun.h`.
- Implements `timer_getoverrun` entrypoint in
`libc/src/time/linux/timer_getoverrun.cpp`.
- Declares `timer_getoverrun` in `libc/include/time.yaml`.
- Registers entrypoints for Linux (`x86_64`, `aarch64`, `riscv`).
- Adds unit test in `libc/test/src/time/timer_test.cpp`.

Implementing `timer_getoverrun` finishes the POSIX timer API in LLVM
libc.

Fixes #234067.

Added: 
    libc/src/__support/OSUtil/linux/syscall_wrappers/timer_getoverrun.h
    libc/src/time/linux/timer_getoverrun.cpp
    libc/src/time/timer_getoverrun.h

Modified: 
    libc/config/linux/aarch64/entrypoints.txt
    libc/config/linux/riscv/entrypoints.txt
    libc/config/linux/x86_64/entrypoints.txt
    libc/include/time.yaml
    libc/src/__support/OSUtil/linux/syscall_wrappers/CMakeLists.txt
    libc/src/time/CMakeLists.txt
    libc/src/time/linux/CMakeLists.txt
    libc/test/src/time/CMakeLists.txt
    libc/test/src/time/timer_test.cpp

Removed: 
    


################################################################################
diff  --git a/libc/config/linux/aarch64/entrypoints.txt b/libc/config/linux/aarch64/entrypoints.txt
index f4d7454254a532..ae4d060ad2e65c 100644
--- a/libc/config/linux/aarch64/entrypoints.txt
+++ b/libc/config/linux/aarch64/entrypoints.txt
@@ -1449,6 +1449,7 @@ if(LLVM_LIBC_FULL_BUILD)
     libc.src.time.timespec_get
     libc.src.time.timer_create
     libc.src.time.timer_delete
+    libc.src.time.timer_getoverrun
     libc.src.time.timer_gettime
     libc.src.time.timer_settime
 

diff  --git a/libc/config/linux/riscv/entrypoints.txt b/libc/config/linux/riscv/entrypoints.txt
index 5400f787471151..f8906e3adbfd30 100644
--- a/libc/config/linux/riscv/entrypoints.txt
+++ b/libc/config/linux/riscv/entrypoints.txt
@@ -1639,6 +1639,7 @@ if(LLVM_LIBC_FULL_BUILD)
     libc.src.time.timespec_get
     libc.src.time.timer_create
     libc.src.time.timer_delete
+    libc.src.time.timer_getoverrun
     libc.src.time.timer_gettime
     libc.src.time.timer_settime
 

diff  --git a/libc/config/linux/x86_64/entrypoints.txt b/libc/config/linux/x86_64/entrypoints.txt
index 570f6d994de221..5d67548617ea5b 100644
--- a/libc/config/linux/x86_64/entrypoints.txt
+++ b/libc/config/linux/x86_64/entrypoints.txt
@@ -1665,6 +1665,7 @@ if(LLVM_LIBC_FULL_BUILD)
     libc.src.time.timespec_get
     libc.src.time.timer_create
     libc.src.time.timer_delete
+    libc.src.time.timer_getoverrun
     libc.src.time.timer_gettime
     libc.src.time.timer_settime
 

diff  --git a/libc/include/time.yaml b/libc/include/time.yaml
index 837b844579d27d..d63dc20e46e587 100644
--- a/libc/include/time.yaml
+++ b/libc/include/time.yaml
@@ -185,6 +185,12 @@ functions:
     return_type: int
     arguments:
       - type: timer_t
+  - name: timer_getoverrun
+    standards:
+      - posix
+    return_type: int
+    arguments:
+      - type: timer_t
   - name: timer_gettime
     standards:
       - posix

diff  --git a/libc/src/__support/OSUtil/linux/syscall_wrappers/CMakeLists.txt b/libc/src/__support/OSUtil/linux/syscall_wrappers/CMakeLists.txt
index 67432985afe067..c7c1f4b9d204f1 100644
--- a/libc/src/__support/OSUtil/linux/syscall_wrappers/CMakeLists.txt
+++ b/libc/src/__support/OSUtil/linux/syscall_wrappers/CMakeLists.txt
@@ -1603,6 +1603,19 @@ add_header_library(
     libc.src.__support.macros.config
 )
 
+add_header_library(
+  timer_getoverrun
+  HDRS
+    timer_getoverrun.h
+  DEPENDS
+    libc.hdr.types.timer_t
+    libc.include.sys_syscall
+    libc.src.__support.OSUtil.osutil
+    libc.src.__support.common
+    libc.src.__support.error_or
+    libc.src.__support.macros.config
+)
+
 add_header_library(
   timer_gettime
   HDRS

diff  --git a/libc/src/__support/OSUtil/linux/syscall_wrappers/timer_getoverrun.h b/libc/src/__support/OSUtil/linux/syscall_wrappers/timer_getoverrun.h
new file mode 100644
index 00000000000000..c94313675980e6
--- /dev/null
+++ b/libc/src/__support/OSUtil/linux/syscall_wrappers/timer_getoverrun.h
@@ -0,0 +1,34 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+///
+/// \file
+/// Implementation header for timer_getoverrun syscall wrapper.
+///
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SRC___SUPPORT_OSUTIL_SYSCALL_WRAPPERS_TIMER_GETOVERRUN_H
+#define LLVM_LIBC_SRC___SUPPORT_OSUTIL_SYSCALL_WRAPPERS_TIMER_GETOVERRUN_H
+
+#include "hdr/types/timer_t.h"
+#include "src/__support/OSUtil/linux/syscall.h" // For syscall_checked
+#include "src/__support/common.h"
+#include "src/__support/error_or.h"
+#include "src/__support/macros/config.h"
+#include <sys/syscall.h> // For syscall numbers
+
+namespace LIBC_NAMESPACE_DECL {
+namespace linux_syscalls {
+
+LIBC_INLINE ErrorOr<int> timer_getoverrun(timer_t timerid) {
+  return syscall_checked<int>(SYS_timer_getoverrun, timerid);
+}
+
+} // namespace linux_syscalls
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC___SUPPORT_OSUTIL_SYSCALL_WRAPPERS_TIMER_GETOVERRUN_H

diff  --git a/libc/src/time/CMakeLists.txt b/libc/src/time/CMakeLists.txt
index fcf25bf7e67f1f..40402d602055d8 100644
--- a/libc/src/time/CMakeLists.txt
+++ b/libc/src/time/CMakeLists.txt
@@ -314,6 +314,13 @@ add_entrypoint_object(
     .${LIBC_TARGET_OS}.timer_delete
 )
 
+add_entrypoint_object(
+  timer_getoverrun
+  ALIAS
+  DEPENDS
+    .${LIBC_TARGET_OS}.timer_getoverrun
+)
+
 add_entrypoint_object(
   timer_gettime
   ALIAS

diff  --git a/libc/src/time/linux/CMakeLists.txt b/libc/src/time/linux/CMakeLists.txt
index a868c06d73d338..9ecd82a91be832 100644
--- a/libc/src/time/linux/CMakeLists.txt
+++ b/libc/src/time/linux/CMakeLists.txt
@@ -121,6 +121,21 @@ add_entrypoint_object(
     libc.src.errno.errno
 )
 
+add_entrypoint_object(
+  timer_getoverrun
+  SRCS
+    timer_getoverrun.cpp
+  HDRS
+    ../timer_getoverrun.h
+  DEPENDS
+    libc.hdr.types.timer_t
+    libc.src.__support.OSUtil.linux.syscall_wrappers.timer_getoverrun
+    libc.src.__support.common
+    libc.src.__support.libc_errno
+    libc.src.__support.macros.config
+    libc.src.errno.errno
+)
+
 add_entrypoint_object(
   timer_gettime
   SRCS

diff  --git a/libc/src/time/linux/timer_getoverrun.cpp b/libc/src/time/linux/timer_getoverrun.cpp
new file mode 100644
index 00000000000000..ef68a7d965d16a
--- /dev/null
+++ b/libc/src/time/linux/timer_getoverrun.cpp
@@ -0,0 +1,31 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+///
+/// \file
+/// Linux implementation of timer_getoverrun function.
+///
+//===----------------------------------------------------------------------===//
+
+#include "src/time/timer_getoverrun.h"
+#include "src/__support/OSUtil/linux/syscall_wrappers/timer_getoverrun.h"
+#include "src/__support/common.h"
+#include "src/__support/libc_errno.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+LLVM_LIBC_FUNCTION(int, timer_getoverrun, (timer_t timerid)) {
+  auto result = linux_syscalls::timer_getoverrun(timerid);
+  if (!result) {
+    libc_errno = result.error();
+    return -1;
+  }
+  return result.value();
+}
+
+} // namespace LIBC_NAMESPACE_DECL

diff  --git a/libc/src/time/timer_getoverrun.h b/libc/src/time/timer_getoverrun.h
new file mode 100644
index 00000000000000..5d48185f63b066
--- /dev/null
+++ b/libc/src/time/timer_getoverrun.h
@@ -0,0 +1,26 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+///
+/// \file
+/// Implementation header for timer_getoverrun function.
+///
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SRC_TIME_TIMER_GETOVERRUN_H
+#define LLVM_LIBC_SRC_TIME_TIMER_GETOVERRUN_H
+
+#include "hdr/types/timer_t.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+int timer_getoverrun(timer_t timerid);
+
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC_TIME_TIMER_GETOVERRUN_H

diff  --git a/libc/test/src/time/CMakeLists.txt b/libc/test/src/time/CMakeLists.txt
index e00d3768ff9358..848d19b5b36de7 100644
--- a/libc/test/src/time/CMakeLists.txt
+++ b/libc/test/src/time/CMakeLists.txt
@@ -179,6 +179,7 @@ add_libc_test(
     libc.src.time.clock_gettime
     libc.src.time.timer_create
     libc.src.time.timer_delete
+    libc.src.time.timer_getoverrun
     libc.src.time.timer_gettime
     libc.src.time.timer_settime
     libc.src.unistd.gettid

diff  --git a/libc/test/src/time/timer_test.cpp b/libc/test/src/time/timer_test.cpp
index 01e504ff1b8234..faa33f3c60eb37 100644
--- a/libc/test/src/time/timer_test.cpp
+++ b/libc/test/src/time/timer_test.cpp
@@ -21,6 +21,7 @@
 #include "src/time/clock_gettime.h"
 #include "src/time/timer_create.h"
 #include "src/time/timer_delete.h"
+#include "src/time/timer_getoverrun.h"
 #include "src/time/timer_gettime.h"
 #include "src/time/timer_settime.h"
 #include "src/unistd/gettid.h"
@@ -229,3 +230,19 @@ TEST_F(LlvmLibcTimerTest, GetTimeNullPointer) {
 
   ASSERT_THAT(LIBC_NAMESPACE::timer_delete(timerid), Succeeds(0));
 }
+
+TEST_F(LlvmLibcTimerTest, GetOverrunInvalidTimerId) {
+  ASSERT_THAT(LIBC_NAMESPACE::timer_getoverrun(reinterpret_cast<timer_t>(-1)),
+              Fails(EINVAL));
+}
+
+TEST_F(LlvmLibcTimerTest, GetOverrunInitial) {
+  timer_t timerid;
+  ASSERT_THAT(LIBC_NAMESPACE::timer_create(CLOCK_REALTIME, nullptr, &timerid),
+              Succeeds(0));
+
+  int overrun = LIBC_NAMESPACE::timer_getoverrun(timerid);
+  ASSERT_GE(overrun, 0);
+
+  ASSERT_THAT(LIBC_NAMESPACE::timer_delete(timerid), Succeeds(0));
+}


        


More information about the libc-commits mailing list