[libc-commits] [libc] [libc] Implement timer_getoverrun in time (PR #234839)
Aman Maurya via libc-commits
libc-commits at lists.llvm.org
Fri Oct 23 01:01:39 PDT 2026
https://github.com/amanmaurya92 updated https://github.com/llvm/llvm-project/pull/234839
>From b7ae1fd7c65fb320f74e1d93abd5bcbb9c764a26 Mon Sep 17 00:00:00 2001
From: amanmaurya92 <amanmaurya9209 at gmail.com>
Date: Thu, 22 Oct 2026 23:43:52 +0530
Subject: [PATCH 1/2] [libc] Implement timer_getoverrun in time (#234067)
---
libc/config/linux/aarch64/entrypoints.txt | 1 +
libc/config/linux/riscv/entrypoints.txt | 1 +
libc/config/linux/x86_64/entrypoints.txt | 1 +
libc/include/time.yaml | 6 +++
.../linux/syscall_wrappers/CMakeLists.txt | 13 +++++++
.../linux/syscall_wrappers/timer_getoverrun.h | 38 +++++++++++++++++++
libc/src/time/CMakeLists.txt | 7 ++++
libc/src/time/linux/CMakeLists.txt | 15 ++++++++
libc/src/time/linux/timer_getoverrun.cpp | 31 +++++++++++++++
libc/src/time/timer_getoverrun.h | 26 +++++++++++++
libc/test/src/time/CMakeLists.txt | 1 +
libc/test/src/time/timer_test.cpp | 17 +++++++++
12 files changed, 157 insertions(+)
create mode 100644 libc/src/__support/OSUtil/linux/syscall_wrappers/timer_getoverrun.h
create mode 100644 libc/src/time/linux/timer_getoverrun.cpp
create mode 100644 libc/src/time/timer_getoverrun.h
diff --git a/libc/config/linux/aarch64/entrypoints.txt b/libc/config/linux/aarch64/entrypoints.txt
index be4d80db3afb37..8ed4aa5036503b 100644
--- a/libc/config/linux/aarch64/entrypoints.txt
+++ b/libc/config/linux/aarch64/entrypoints.txt
@@ -1448,6 +1448,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 20e33295bfb206..6b2283823b50ac 100644
--- a/libc/config/linux/riscv/entrypoints.txt
+++ b/libc/config/linux/riscv/entrypoints.txt
@@ -1638,6 +1638,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 7d7c3ad1e1768d..194c54d7b09dee 100644
--- a/libc/config/linux/x86_64/entrypoints.txt
+++ b/libc/config/linux/x86_64/entrypoints.txt
@@ -1664,6 +1664,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..b61bb14a499319
--- /dev/null
+++ b/libc/src/__support/OSUtil/linux/syscall_wrappers/timer_getoverrun.h
@@ -0,0 +1,38 @@
+//===----------------------------------------------------------------------===//
+//
+// 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) {
+#ifdef SYS_timer_getoverrun
+ return syscall_checked<int>(SYS_timer_getoverrun, timerid);
+#else
+#error "SYS_timer_getoverrun syscall not available."
+#endif
+}
+
+} // 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));
+}
>From 27d0145292c82371f26a91c52b249d83a1301b5b Mon Sep 17 00:00:00 2001
From: amanmaurya92 <amanmaurya9209 at gmail.com>
Date: Fri, 23 Oct 2026 13:31:12 +0530
Subject: [PATCH 2/2] [libc] Simplify timer_getoverrun syscall wrapper
---
.../OSUtil/linux/syscall_wrappers/timer_getoverrun.h | 4 ----
1 file changed, 4 deletions(-)
diff --git a/libc/src/__support/OSUtil/linux/syscall_wrappers/timer_getoverrun.h b/libc/src/__support/OSUtil/linux/syscall_wrappers/timer_getoverrun.h
index b61bb14a499319..c94313675980e6 100644
--- a/libc/src/__support/OSUtil/linux/syscall_wrappers/timer_getoverrun.h
+++ b/libc/src/__support/OSUtil/linux/syscall_wrappers/timer_getoverrun.h
@@ -25,11 +25,7 @@ namespace LIBC_NAMESPACE_DECL {
namespace linux_syscalls {
LIBC_INLINE ErrorOr<int> timer_getoverrun(timer_t timerid) {
-#ifdef SYS_timer_getoverrun
return syscall_checked<int>(SYS_timer_getoverrun, timerid);
-#else
-#error "SYS_timer_getoverrun syscall not available."
-#endif
}
} // namespace linux_syscalls
More information about the libc-commits
mailing list