]>
Commit | Line | Data |
---|---|---|
f0ba1a9b | 1 | /* |
ef57eb7b | 2 | * Copyright (C) 1996-2016 The Squid Software Foundation and contributors |
f0ba1a9b AJ |
3 | * |
4 | * Squid software is distributed under GPLv2+ license and includes | |
5 | * contributions from numerous individuals and organizations. | |
6 | * Please see the COPYING and CONTRIBUTORS files for details. | |
7 | */ | |
8 | ||
25f98340 AJ |
9 | #ifndef _PROFILER_GET_TICK_H_ |
10 | #define _PROFILER_GET_TICK_H_ | |
11 | ||
25f98340 AJ |
12 | #if USE_XPROF_STATS |
13 | ||
5e44eea8 AJ |
14 | /* |
15 | * Ensure that any changes here are synchronised with SQUID_CHECK_FUNCTIONAL_CPU_PROFILER | |
16 | */ | |
17 | ||
25f98340 AJ |
18 | #if !_SQUID_SOLARIS_ |
19 | typedef int64_t hrtime_t; | |
20 | #endif | |
21 | ||
22 | #if defined(__GNUC__) && ( defined(__i386) || defined(__i386__) ) | |
23 | static inline hrtime_t | |
24 | get_tick(void) | |
25 | { | |
26 | hrtime_t regs; | |
27 | ||
f53969cc | 28 | asm volatile ("rdtsc":"=A" (regs)); |
25f98340 AJ |
29 | return regs; |
30 | /* We need return value, we rely on CC to optimise out needless subf calls */ | |
31 | /* Note that "rdtsc" is relatively slow OP and stalls the CPU pipes, so use it wisely */ | |
32 | } | |
33 | ||
34 | #elif defined(__GNUC__) && ( defined(__x86_64) || defined(__x86_64__) ) | |
35 | static inline hrtime_t | |
36 | get_tick(void) | |
37 | { | |
38 | uint32_t lo, hi; | |
39 | // Based on an example in Wikipedia | |
40 | /* We cannot use "=A", since this would use %rax on x86_64 */ | |
f53969cc | 41 | asm volatile ("rdtsc" : "=a" (lo), "=d" (hi)); |
25f98340 AJ |
42 | return (hrtime_t)hi << 32 | lo; |
43 | } | |
44 | ||
45 | #elif defined(__GNUC__) && defined(__alpha) | |
46 | static inline hrtime_t | |
47 | get_tick(void) | |
48 | { | |
49 | hrtime_t regs; | |
50 | ||
f53969cc | 51 | asm volatile ("rpcc %0" : "=r" (regs)); |
25f98340 AJ |
52 | return regs; |
53 | } | |
54 | ||
55 | #elif defined(_M_IX86) && defined(_MSC_VER) /* x86 platform on Microsoft C Compiler ONLY */ | |
56 | static __inline hrtime_t | |
57 | get_tick(void) | |
58 | { | |
59 | hrtime_t regs; | |
60 | ||
61 | __asm { | |
62 | cpuid | |
63 | rdtsc | |
64 | mov eax,DWORD PTR regs[0] | |
65 | mov edx,DWORD PTR regs[4] | |
66 | } | |
67 | return regs; | |
68 | } | |
69 | ||
70 | #else | |
71 | /* This CPU is unsupported. Short-circuit, no profiling here */ | |
5e44eea8 AJ |
72 | // #error for configure tests to prevent library construction |
73 | #error This CPU is unsupported. No profiling available here. | |
25f98340 AJ |
74 | #endif |
75 | ||
76 | #endif /* USE_XPROF_STATS */ | |
77 | #endif /* _PROFILING_H_ */ | |
f53969cc | 78 |