[Workflow] Roll back some settings since they caused more issues
[llvm-project.git] / libc / src / sched / linux / sched_rr_get_interval.cpp
blobc50dc711620b1d192fea42b48f940c8e18224345
1 //===-- Implementation of sched_rr_get_interval ---------------------------===//
2 //
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
6 //
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.
19 #endif
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
31 int ret;
32 if (tp) {
33 struct __kernel_timespec ts32;
34 ret = __llvm_libc::syscall_impl<int>(SYS_sched_rr_get_interval_time64, tid,
35 &ts32);
36 if (ret == 0) {
37 tp->tv_sec = ts32.tv_sec;
38 tp->tv_nsec = ts32.tv_nsec;
40 } else
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,
43 nullptr);
44 #else
45 #error \
46 "sched_rr_get_interval and sched_rr_get_interval_time64 syscalls not available."
47 #endif
48 if (ret < 0) {
49 libc_errno = -ret;
50 return -1;
52 return 0;
55 } // namespace __llvm_libc