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