]> git.ipfire.org Git - thirdparty/squid.git/blob - lib/profiler/get_tick.h
Merge form trunk
[thirdparty/squid.git] / lib / profiler / get_tick.h
1 #ifndef _PROFILER_GET_TICK_H_
2 #define _PROFILER_GET_TICK_H_
3
4 #include "config.h"
5
6 #if USE_XPROF_STATS
7
8 #if !_SQUID_SOLARIS_
9 typedef int64_t hrtime_t;
10 #endif
11
12 #if defined(__GNUC__) && ( defined(__i386) || defined(__i386__) )
13 static inline hrtime_t
14 get_tick(void)
15 {
16 hrtime_t regs;
17
18 asm volatile ("rdtsc":"=A" (regs));
19 return regs;
20 /* We need return value, we rely on CC to optimise out needless subf calls */
21 /* Note that "rdtsc" is relatively slow OP and stalls the CPU pipes, so use it wisely */
22 }
23
24 #elif defined(__GNUC__) && ( defined(__x86_64) || defined(__x86_64__) )
25 static inline hrtime_t
26 get_tick(void)
27 {
28 uint32_t lo, hi;
29 // Based on an example in Wikipedia
30 /* We cannot use "=A", since this would use %rax on x86_64 */
31 asm volatile ("rdtsc" : "=a" (lo), "=d" (hi));
32 return (hrtime_t)hi << 32 | lo;
33 }
34
35 #elif defined(__GNUC__) && defined(__alpha)
36 static inline hrtime_t
37 get_tick(void)
38 {
39 hrtime_t regs;
40
41 asm volatile ("rpcc %0" : "=r" (regs));
42 return regs;
43 }
44
45 #elif defined(_M_IX86) && defined(_MSC_VER) /* x86 platform on Microsoft C Compiler ONLY */
46 static __inline hrtime_t
47 get_tick(void)
48 {
49 hrtime_t regs;
50
51 __asm {
52 cpuid
53 rdtsc
54 mov eax,DWORD PTR regs[0]
55 mov edx,DWORD PTR regs[4]
56 }
57 return regs;
58 }
59
60 #else
61 /* This CPU is unsupported. Short-circuit, no profiling here */
62 #define get_tick() 0
63 #undef USE_XPROF_STATS
64 #define USE_XPROF_STATS 0
65 #endif
66
67 #endif /* USE_XPROF_STATS */
68 #endif /* _PROFILING_H_ */