60 lines · cpp
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-exception6//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/__support/libc_errno.h"14#include "src/__support/macros/config.h"15 16#include "hdr/types/pid_t.h"17#include "hdr/types/struct_timespec.h"18#include <sys/syscall.h> // For syscall numbers.19 20#ifdef SYS_sched_rr_get_interval_time6421#include <linux/time_types.h> // For __kernel_timespec.22#endif23 24namespace LIBC_NAMESPACE_DECL {25 26LLVM_LIBC_FUNCTION(int, sched_rr_get_interval,27 (pid_t tid, struct timespec *tp)) {28#ifdef SYS_sched_rr_get_interval29 int ret =30 LIBC_NAMESPACE::syscall_impl<int>(SYS_sched_rr_get_interval, tid, tp);31#elif defined(SYS_sched_rr_get_interval_time64)32 // The difference between the and SYS_sched_rr_get_interval33 // SYS_sched_rr_get_interval_time64 syscalls is the data type used for the34 // time interval parameter: the latter takes a struct __kernel_timespec35 int ret;36 if (tp) {37 struct __kernel_timespec ts32;38 ret = LIBC_NAMESPACE::syscall_impl<int>(SYS_sched_rr_get_interval_time64,39 tid, &ts32);40 if (ret == 0) {41 tp->tv_sec = ts32.tv_sec;42 tp->tv_nsec = static_cast<long int>(ts32.tv_nsec);43 }44 } else45 // When tp is a nullptr, we still do the syscall to set ret and errno46 ret = LIBC_NAMESPACE::syscall_impl<int>(SYS_sched_rr_get_interval_time64,47 tid, nullptr);48#else49#error \50 "sched_rr_get_interval and sched_rr_get_interval_time64 syscalls not available."51#endif52 if (ret < 0) {53 libc_errno = -ret;54 return -1;55 }56 return 0;57}58 59} // namespace LIBC_NAMESPACE_DECL60