]> git.ipfire.org Git - thirdparty/squid.git/blob - lib/profiler/get_tick.h
Docs: Copyright updates for 2018 (#114)
[thirdparty/squid.git] / lib / profiler / get_tick.h
1 /*
2 * Copyright (C) 1996-2018 The Squid Software Foundation and contributors
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
9 #ifndef _PROFILER_GET_TICK_H_
10 #define _PROFILER_GET_TICK_H_
11
12 #if USE_XPROF_STATS
13
14 /*
15 * Ensure that any changes here are synchronised with SQUID_CHECK_FUNCTIONAL_CPU_PROFILER
16 */
17
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
28 asm volatile ("rdtsc":"=A" (regs));
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 */
41 asm volatile ("rdtsc" : "=a" (lo), "=d" (hi));
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
51 asm volatile ("rpcc %0" : "=r" (regs));
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 */
72 // #error for configure tests to prevent library construction
73 #error This CPU is unsupported. No profiling available here.
74 #endif
75
76 #endif /* USE_XPROF_STATS */
77 #endif /* _PROFILING_H_ */
78