1 /*
2 This file is part of the BOLT-LMM linear mixed model software package
3 developed by Po-Ru Loh. Copyright (C) 2014-2019 Harvard University.
4
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19 #include <cstdlib>
20 #include <sys/time.h>
21
22 #include "Timer.hpp"
23
Timer(void)24 Timer::Timer(void) {
25 update_time();
26 }
27
update_time(void)28 double Timer::update_time(void) {
29 struct timeval tv;
30 gettimeofday(&tv, NULL);
31 prevtime = curtime;
32 curtime = tv.tv_sec + 1e-6 * tv.tv_usec;
33 return curtime - prevtime;
34 }
35
rdtsc(void)36 unsigned long long Timer::rdtsc(void) {
37 unsigned int hi, lo;
38 #ifdef __amd64__
39 __asm__ __volatile__ ("rdtsc" : "=a"(lo), "=d"(hi));
40 #elif __powerpc__
41 unsigned int tmp;
42 __asm__ ("0:"
43 "mftbu %[hi32]\n"
44 "mftb %[lo32]\n"
45 "mftbu %[tmp]\n"
46 "cmpw %[tmp],%[hi32]\n"
47 "bne 0b\n"
48 : [hi32] "=r"(hi), [lo32] "=r"(lo),
49 [tmp] "=r"(tmp));
50 #endif
51 return ((unsigned long long) lo) | (((unsigned long long) hi)<<32);
52 }
53
get_time(void)54 double Timer::get_time(void) {
55 struct timeval tv;
56 gettimeofday(&tv, NULL);
57 return tv.tv_sec + 1e-6 * tv.tv_usec;
58 }
59