brintos

brintos / llvm-project-archived public Read only

0
0
Text · 990 B · 0dd1284 Raw
31 lines · cpp
1//===-- Implementation of timespec_get for gpu ----------------------------===//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/time/timespec_get.h"10#include "hdr/time_macros.h"11#include "src/__support/common.h"12#include "src/__support/macros/config.h"13#include "src/__support/time/gpu/time_utils.h"14 15namespace LIBC_NAMESPACE_DECL {16 17LLVM_LIBC_FUNCTION(int, timespec_get, (struct timespec * ts, int base)) {18  if (base != TIME_MONOTONIC || !ts)19    return 0;20 21  uint64_t ns_per_tick = TICKS_PER_SEC / GPU_CLOCKS_PER_SEC;22  uint64_t ticks = gpu::fixed_frequency_clock();23 24  ts->tv_nsec = (ticks * ns_per_tick) % TICKS_PER_SEC;25  ts->tv_sec = (ticks * ns_per_tick) / TICKS_PER_SEC;26 27  return base;28}29 30} // namespace LIBC_NAMESPACE_DECL31