1 //===-- Implementation of sched_rr_get_interval ---------------------------===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 #include "src/sched/sched_rr_get_interval.h"
11 #include "src/__support/OSUtil/syscall.h" // For internal syscall function.
12 #include "src/__support/common.h"
13 #include "src/__support/macros/config.h"
14 #include "src/errno/libc_errno.h"
16 #include <sys/syscall.h> // For syscall numbers.
18 #ifdef SYS_sched_rr_get_interval_time64
19 #include <linux/time_types.h> // For __kernel_timespec.
22 namespace LIBC_NAMESPACE_DECL
{
24 LLVM_LIBC_FUNCTION(int, sched_rr_get_interval
,
25 (pid_t tid
, struct timespec
*tp
)) {
26 #ifdef SYS_sched_rr_get_interval
28 LIBC_NAMESPACE::syscall_impl
<int>(SYS_sched_rr_get_interval
, tid
, tp
);
29 #elif defined(SYS_sched_rr_get_interval_time64)
30 // The difference between the and SYS_sched_rr_get_interval
31 // SYS_sched_rr_get_interval_time64 syscalls is the data type used for the
32 // time interval parameter: the latter takes a struct __kernel_timespec
35 struct __kernel_timespec ts32
;
36 ret
= LIBC_NAMESPACE::syscall_impl
<int>(SYS_sched_rr_get_interval_time64
,
39 tp
->tv_sec
= ts32
.tv_sec
;
40 tp
->tv_nsec
= static_cast<long int>(ts32
.tv_nsec
);
43 // When tp is a nullptr, we still do the syscall to set ret and errno
44 ret
= LIBC_NAMESPACE::syscall_impl
<int>(SYS_sched_rr_get_interval_time64
,
48 "sched_rr_get_interval and sched_rr_get_interval_time64 syscalls not available."
57 } // namespace LIBC_NAMESPACE_DECL