• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 //===----------------------------------------------------------------------===//
8 
9 #include "src/sched/sched_rr_get_interval.h"
10 
11 #include "src/__support/OSUtil/syscall.h" // For internal syscall function.
12 #include "src/__support/common.h"
13 #include "src/errno/libc_errno.h"
14 
15 #include <sys/syscall.h> // For syscall numbers.
16 
17 #ifdef SYS_sched_rr_get_interval_time64
18 #include <linux/time_types.h> // For __kernel_timespec.
19 #endif
20 
21 namespace LIBC_NAMESPACE {
22 
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 =
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
32   int ret;
33   if (tp) {
34     struct __kernel_timespec ts32;
35     ret = LIBC_NAMESPACE::syscall_impl<int>(SYS_sched_rr_get_interval_time64,
36                                             tid, &ts32);
37     if (ret == 0) {
38       tp->tv_sec = ts32.tv_sec;
39       tp->tv_nsec = ts32.tv_nsec;
40     }
41   } else
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,
44                                             tid, nullptr);
45 #else
46 #error                                                                         \
47     "sched_rr_get_interval and sched_rr_get_interval_time64 syscalls not available."
48 #endif
49   if (ret < 0) {
50     libc_errno = -ret;
51     return -1;
52   }
53   return 0;
54 }
55 
56 } // namespace LIBC_NAMESPACE
57