offload_timer.h 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  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. #ifndef OFFLOAD_TIMER_H_INCLUDED
  27. #define OFFLOAD_TIMER_H_INCLUDED
  28. #include <stdio.h>
  29. #include <stdarg.h>
  30. #include <stdint.h>
  31. #include "liboffload_error_codes.h"
  32. DLL_LOCAL extern int timer_enabled;
  33. #ifdef TIMING_SUPPORT
  34. struct OffloadTargetTimerData {
  35. uint64_t frequency;
  36. struct {
  37. uint64_t start;
  38. uint64_t total;
  39. } phases[c_offload_target_max_phase];
  40. };
  41. struct OffloadHostTimerData {
  42. // source file name and line number
  43. const char* file;
  44. int line;
  45. // host timer data
  46. struct {
  47. uint64_t start;
  48. uint64_t total;
  49. } phases[c_offload_host_max_phase];
  50. uint64_t sent_bytes;
  51. uint64_t received_bytes;
  52. int card_number;
  53. int offload_number;
  54. // target timer data
  55. OffloadTargetTimerData target;
  56. // next element
  57. OffloadHostTimerData *next;
  58. };
  59. #if HOST_LIBRARY
  60. DLL_LOCAL extern int offload_report_level;
  61. DLL_LOCAL extern int offload_report_enabled;
  62. #define OFFLOAD_REPORT_1 1
  63. #define OFFLOAD_REPORT_2 2
  64. #define OFFLOAD_REPORT_3 3
  65. #define OFFLOAD_REPORT_ON 1
  66. #define OFFLOAD_REPORT_OFF 0
  67. #define OFFLOAD_TIMER_DATALEN() \
  68. ((timer_enabled || (offload_report_level && offload_report_enabled)) ? \
  69. ((1 + c_offload_target_max_phase) * sizeof(uint64_t)) : 0)
  70. #define OFFLOAD_TIMER_START(timer_data, pnode) \
  71. if (timer_enabled || \
  72. (offload_report_level && offload_report_enabled)) { \
  73. offload_timer_start(timer_data, pnode); \
  74. }
  75. #define OFFLOAD_TIMER_STOP(timer_data, pnode) \
  76. if (timer_enabled || \
  77. (offload_report_level && offload_report_enabled)) { \
  78. offload_timer_stop(timer_data, pnode); \
  79. }
  80. #define OFFLOAD_TIMER_INIT(file, line) \
  81. offload_timer_init(file, line);
  82. #define OFFLOAD_TIMER_TARGET_DATA(timer_data, data) \
  83. if (timer_enabled || \
  84. (offload_report_level && offload_report_enabled)) { \
  85. offload_timer_fill_target_data(timer_data, data); \
  86. }
  87. #define OFFLOAD_TIMER_HOST_SDATA(timer_data, data) \
  88. if (offload_report_level && offload_report_enabled) { \
  89. offload_timer_fill_host_sdata(timer_data, data); \
  90. }
  91. #define OFFLOAD_TIMER_HOST_RDATA(timer_data, data) \
  92. if (offload_report_level && offload_report_enabled) { \
  93. offload_timer_fill_host_rdata(timer_data, data); \
  94. }
  95. #define OFFLOAD_TIMER_HOST_MIC_NUM(timer_data, data) \
  96. if (offload_report_level && offload_report_enabled) { \
  97. offload_timer_fill_host_mic_num(timer_data, data); \
  98. }
  99. extern DLL_LOCAL void offload_timer_start(OffloadHostTimerData *,
  100. OffloadHostPhase t_node);
  101. extern DLL_LOCAL void offload_timer_stop(OffloadHostTimerData *,
  102. OffloadHostPhase t_node);
  103. extern DLL_LOCAL OffloadHostTimerData * offload_timer_init(const char *file, int line);
  104. extern DLL_LOCAL void offload_timer_fill_target_data(OffloadHostTimerData *,
  105. void *data);
  106. extern DLL_LOCAL void offload_timer_fill_host_sdata(OffloadHostTimerData *,
  107. uint64_t sent_bytes);
  108. extern DLL_LOCAL void offload_timer_fill_host_rdata(OffloadHostTimerData *,
  109. uint64_t sent_bytes);
  110. extern DLL_LOCAL void offload_timer_fill_host_mic_num(OffloadHostTimerData *,
  111. int card_number);
  112. // Utility structure for starting/stopping timer
  113. struct OffloadTimer {
  114. OffloadTimer(OffloadHostTimerData *data, OffloadHostPhase phase) :
  115. m_data(data),
  116. m_phase(phase)
  117. {
  118. OFFLOAD_TIMER_START(m_data, m_phase);
  119. }
  120. ~OffloadTimer()
  121. {
  122. OFFLOAD_TIMER_STOP(m_data, m_phase);
  123. }
  124. private:
  125. OffloadHostTimerData* m_data;
  126. OffloadHostPhase m_phase;
  127. };
  128. #else
  129. #define OFFLOAD_TIMER_DATALEN() \
  130. ((timer_enabled) ? \
  131. ((1 + c_offload_target_max_phase) * sizeof(uint64_t)) : 0)
  132. #define OFFLOAD_TIMER_START(pnode) \
  133. if (timer_enabled) offload_timer_start(pnode);
  134. #define OFFLOAD_TIMER_STOP(pnode) \
  135. if (timer_enabled) offload_timer_stop(pnode);
  136. #define OFFLOAD_TIMER_INIT() \
  137. if (timer_enabled) offload_timer_init();
  138. #define OFFLOAD_TIMER_TARGET_DATA(data) \
  139. if (timer_enabled) offload_timer_fill_target_data(data);
  140. extern DLL_LOCAL void offload_timer_start(OffloadTargetPhase t_node);
  141. extern DLL_LOCAL void offload_timer_stop(OffloadTargetPhase t_node);
  142. extern DLL_LOCAL void offload_timer_init(void);
  143. extern DLL_LOCAL void offload_timer_fill_target_data(void *data);
  144. #endif // HOST_LIBRARY
  145. #else // TIMING_SUPPORT
  146. #define OFFLOAD_TIMER_START(...)
  147. #define OFFLOAD_TIMER_STOP(...)
  148. #define OFFLOAD_TIMER_INIT(...)
  149. #define OFFLOAD_TIMER_TARGET_DATA(...)
  150. #define OFFLOAD_TIMER_DATALEN(...) (0)
  151. #endif // TIMING_SUPPORT
  152. #endif // OFFLOAD_TIMER_H_INCLUDED