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/errno/libc_errno.h"
15 #include <sys/syscall.h> // For syscall numbers.
17 #ifdef SYS_sched_rr_get_interval_time64
18 #include <linux/time_types.h> // For __kernel_timespec.
21 namespace LIBC_NAMESPACE
{
23 LLVM_LIBC_FUNCTION(int, sched_rr_get_interval
,
24 (pid_t tid
, struct timespec
*tp
)) {
25 #ifdef SYS_sched_rr_get_interval
27 LIBC_NAMESPACE::syscall_impl
<int>(SYS_sched_rr_get_interval
, tid
, tp
);
28 #elif defined(SYS_sched_rr_get_interval_time64)
29 // The difference between the and SYS_sched_rr_get_interval
30 // SYS_sched_rr_get_interval_time64 syscalls is the data type used for the
31 // time interval parameter: the latter takes a struct __kernel_timespec
34 struct __kernel_timespec ts32
;
35 ret
= LIBC_NAMESPACE::syscall_impl
<int>(SYS_sched_rr_get_interval_time64
,
38 tp
->tv_sec
= ts32
.tv_sec
;
39 tp
->tv_nsec
= ts32
.tv_nsec
;
42 // When tp is a nullptr, we still do the syscall to set ret and errno
43 ret
= LIBC_NAMESPACE::syscall_impl
<int>(SYS_sched_rr_get_interval_time64
,
47 "sched_rr_get_interval and sched_rr_get_interval_time64 syscalls not available."
56 } // namespace LIBC_NAMESPACE