brintos

brintos / llvm-project-archived public Read only

0
0
Text · 732 B · e382cb5 Raw
37 lines · c
1// RUN: %clang -pthread %s -Wl,-as-needed -o %t && %run %t2//3// UNSUPPORTED: darwin, target={{.*solaris.*}}4 5#include <time.h>6#include <unistd.h>7#include <assert.h>8#include <pthread.h>9 10long cpu_ns() {11  clockid_t clk;12  struct timespec ts;13  int res = clock_getcpuclockid(getpid(), &clk);14  assert(!res);15  res = clock_gettime(clk, &ts);16  assert(!res);17  return ts.tv_nsec;18}19 20long th_cpu_ns() {21  clockid_t clk;22  struct timespec ts;23  int res = pthread_getcpuclockid(pthread_self(), &clk);24  assert(!res);25  res = clock_gettime(clk, &ts);26  assert(!res);27  return ts.tv_nsec;28}29 30int main() {31  long cpuns = cpu_ns();32  asm volatile ("" :: "r"(cpuns));33  cpuns = th_cpu_ns();34  asm volatile ("" :: "r"(cpuns));35  return 0;36}37