1/*
2 * Copyright (c) 2007, 2008, 2009, ETH Zurich.
3 * All rights reserved.
4 *
5 * This file is distributed under the terms in the attached LICENSE file.
6 * If you do not find this file, copies can be found by writing to:
7 * ETH Zurich D-INFK, Haldeneggsteig 4, CH-8092 Zurich. Attn: Systems Group.
8 */
9
10#include "wtime.h"
11//#include <sys/time.h>
12#ifndef POSIX
13#include <barrelfish/barrelfish.h>
14#include <barrelfish_kpi/cpu.h>
15#else
16
17#include <stdint.h>
18
19static inline uint64_t rdtsc(void)
20{
21    uint32_t eax, edx;
22    __asm volatile ("rdtsc" : "=a" (eax), "=d" (edx));
23    return ((uint64_t)edx << 32) | eax;
24}
25
26#endif
27
28void wtime(double *t)
29{
30  uint64_t tsc;
31  static uint64_t sec = 0;
32//  struct timeval tv;
33//  gettimeofday(&tv, (void *)0);
34  tsc = rdtsc();
35  if (sec == 0) sec = tsc;
36  *t = (tsc - sec);
37}
38
39
40