]> git.ipfire.org Git - thirdparty/squid.git/blame - lib/profiler/get_tick.h
FreeBSD: fix oid definition clash.
[thirdparty/squid.git] / lib / profiler / get_tick.h
CommitLineData
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_
7typedef int64_t hrtime_t;
8#endif
9
10#if defined(__GNUC__) && ( defined(__i386) || defined(__i386__) )
11static inline hrtime_t
12get_tick(void)
13{
14 hrtime_t regs;
15
16asm 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__) )
23static inline hrtime_t
24get_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 */
29asm volatile ("rdtsc" : "=a" (lo), "=d" (hi));
30 return (hrtime_t)hi << 32 | lo;
31}
32
33#elif defined(__GNUC__) && defined(__alpha)
34static inline hrtime_t
35get_tick(void)
36{
37 hrtime_t regs;
38
39asm 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 */
44static __inline hrtime_t
45get_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_ */