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 __llvm_libc
{
23 LLVM_LIBC_FUNCTION(int, sched_rr_get_interval
,
24 (pid_t tid
, struct timespec
*tp
)) {
25 #ifdef SYS_sched_rr_get_interval
26 int ret
= __llvm_libc::syscall_impl
<int>(SYS_sched_rr_get_interval
, tid
, tp
);
27 #elif defined(SYS_sched_rr_get_interval_time64)
28 // The difference between the and SYS_sched_rr_get_interval
29 // SYS_sched_rr_get_interval_time64 syscalls is the data type used for the
30 // time interval parameter: the latter takes a struct __kernel_timespec
33 struct __kernel_timespec ts32
;
34 ret
= __llvm_libc::syscall_impl
<int>(SYS_sched_rr_get_interval_time64
, tid
,
37 tp
->tv_sec
= ts32
.tv_sec
;
38 tp
->tv_nsec
= ts32
.tv_nsec
;
41 // When tp is a nullptr, we still do the syscall to set ret and errno
42 ret
= __llvm_libc::syscall_impl
<int>(SYS_sched_rr_get_interval_time64
, tid
,
46 "sched_rr_get_interval and sched_rr_get_interval_time64 syscalls not available."
55 } // namespace __llvm_libc