acme
Foundational cross-platform layer of the ca2 framework
Loading...
Searching...
No Matches
GetCPUTime.h
1// Copyright (C) 2009,2010,2011,2012 GlavSoft LLC.
2// All rights reserved.
3//
4//-------------------------------------------------------------------------
5// This file is part of the T i g h t V N C software. Please visit our Web site:
6//
7// http://www.t i g h t v n c.com/
8//
9// This program is free software; you can redistribute it and/or modify
10// it under the terms of the GNU General Public License as published by
11// the Free Software Foundation; either version 2 of the License, or
12// (at your option) any later version.
13//
14// This program is distributed in the hope that it will be useful,
15// but WITHOUT ANY WARRANTY; without even the implied warranty of
16// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17// GNU General Public License for more details.
18//
19// You should have received a copy of the GNU General Public License along
20// with this program; if not, w_rite to the Free Software Foundation, Inc.,
21// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22//-------------------------------------------------------------------------
23//
24
25//#ifndef _GETCPUTIME_H_
26//#define _GETCPUTIME_H_
27#pragma once
28
29// returns current process time of work in seconds
30::f64 getCPUTime();
31
32// returns kernel time of work in seconds
33::f64 getKernelTime();
34
35// returns current processor tick number
36inline ::u64 rdtsc() {
37 ::u32 lo, hi;
38#ifdef __GNUC__
39
40#if defined(__aarch64__)
41
42 uint64_t val;
43 asm volatile("mrs %0, cntvct_el0" : "=r"(val));
44 return val;
45
46#else
47 asm volatile ("rdtsc\n" : "=a" (lo), "=d" (hi));
48
49#endif
50
51#elif _MSC_VER
52#ifdef _M_IX86
53 __asm
54 {
55 rdtsc
56 mov DWORD PTR [lo], eax
57 mov DWORD PTR [hi], edx
58 }
59#else
60 return 0;
61#endif
62#else
63 #error "Unsupported compiler"
64#endif
65 return ((::u64)hi << 32) | lo;
66}
67
68//#endif _GETCPUTIME_H_