offload_timer_target.cpp 2.7 KB

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