* gcc.dg/20150120-1.c (dg-final): Cleanup original tree dump.
[official-gcc.git] / liboffloadmic / runtime / offload_timer_target.cpp
blob8dc4bbcc81dd06e1e1f63ce549e2319d57e807c6
1 /*
2 Copyright (c) 2014 Intel Corporation. All Rights Reserved.
4 Redistribution and use in source and binary forms, with or without
5 modification, are permitted provided that the following conditions
6 are met:
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.
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.
31 #include "offload_timer.h"
32 #include "offload_target.h"
34 #ifdef __INTEL_COMPILER
35 #include <ia32intrin.h>
36 #else // __INTEL_COMPILER
37 #include <x86intrin.h>
38 #endif // __INTEL_COMPILER
42 int timer_enabled = 0;
44 #ifdef TIMING_SUPPORT
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)
53 void offload_timer_start(
54 OffloadTargetPhase p_type
57 timer_data.phases[p_type].start = _rdtsc();
60 void offload_timer_stop(
61 OffloadTargetPhase p_type
64 timer_data.phases[p_type].total += _rdtsc() -
65 timer_data.phases[p_type].start;
68 void offload_timer_init()
70 memset(&timer_data, 0, sizeof(OffloadTargetTimerData));
73 void offload_timer_fill_target_data(
74 void *buf
77 uint64_t *data = (uint64_t*) buf;
79 timer_data.frequency = mic_frequency;
80 memcpy(data++, &(timer_data.frequency), sizeof(uint64_t));
82 for (int i = 0; i < c_offload_target_max_phase; i++) {
83 memcpy(data++, &(timer_data.phases[i].total), sizeof(uint64_t));
87 #endif // TIMING_SUPPORT