]>
Commit | Line | Data |
---|---|---|
5f520819 | 1 | /* |
2eab9666 | 2 | Copyright (c) 2014-2015 Intel Corporation. All Rights Reserved. |
5f520819 KY |
3 | |
4 | Redistribution and use in source and binary forms, with or without | |
5 | modification, are permitted provided that the following conditions | |
6 | are met: | |
7 | ||
8 | * Redistributions of source code must retain the above copyright | |
9 | notice, this list of conditions and the following disclaimer. | |
10 | * Redistributions in binary form must reproduce the above copyright | |
11 | notice, this list of conditions and the following disclaimer in the | |
12 | documentation and/or other materials provided with the distribution. | |
13 | * Neither the name of Intel Corporation nor the names of its | |
14 | contributors may be used to endorse or promote products derived | |
15 | from this software without specific prior written permission. | |
16 | ||
17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
18 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
19 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | |
20 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | |
21 | HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
22 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |
23 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |
24 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |
25 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
26 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
27 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
28 | */ | |
29 | ||
30 | ||
31 | #include "offload_timer.h" | |
32 | #include "offload_target.h" | |
33 | ||
34 | #ifdef __INTEL_COMPILER | |
35 | #include <ia32intrin.h> | |
36 | #else // __INTEL_COMPILER | |
37 | #include <x86intrin.h> | |
38 | #endif // __INTEL_COMPILER | |
39 | ||
40 | ||
41 | ||
42 | int timer_enabled = 0; | |
43 | ||
44 | #ifdef TIMING_SUPPORT | |
45 | ||
46 | #if defined(LINUX) || defined(FREEBSD) | |
47 | static __thread OffloadTargetTimerData timer_data; | |
48 | #else // WINNT | |
49 | static __declspec(thread) OffloadTargetTimerData timer_data; | |
50 | #endif // defined(LINUX) || defined(FREEBSD) | |
51 | ||
52 | ||
53 | void offload_timer_start( | |
54 | OffloadTargetPhase p_type | |
55 | ) | |
56 | { | |
57 | timer_data.phases[p_type].start = _rdtsc(); | |
58 | } | |
59 | ||
60 | void offload_timer_stop( | |
61 | OffloadTargetPhase p_type | |
62 | ) | |
63 | { | |
64 | timer_data.phases[p_type].total += _rdtsc() - | |
65 | timer_data.phases[p_type].start; | |
66 | } | |
67 | ||
68 | void offload_timer_init() | |
69 | { | |
70 | memset(&timer_data, 0, sizeof(OffloadTargetTimerData)); | |
71 | } | |
72 | ||
73 | void offload_timer_fill_target_data( | |
74 | void *buf | |
75 | ) | |
76 | { | |
77 | uint64_t *data = (uint64_t*) buf; | |
78 | ||
79 | timer_data.frequency = mic_frequency; | |
80 | memcpy(data++, &(timer_data.frequency), sizeof(uint64_t)); | |
81 | ||
82 | for (int i = 0; i < c_offload_target_max_phase; i++) { | |
83 | memcpy(data++, &(timer_data.phases[i].total), sizeof(uint64_t)); | |
84 | } | |
85 | } | |
86 | ||
87 | #endif // TIMING_SUPPORT |