xt_profiling.h 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  1. /*
  2. * Customer ID=11656; Build=0x5f626; Copyright (c) 2005-2012 by Tensilica Inc. ALL RIGHTS RESERVED.
  3. * These coded instructions, statements, and computer programs are the
  4. * copyrighted works and confidential proprietary information of Tensilica Inc.
  5. * They may not be modified, copied, reproduced, distributed, or disclosed to
  6. * third parties in any manner, medium, or form, in whole or in part, without
  7. * the prior written consent of Tensilica Inc.
  8. */
  9. #ifndef __XT_PROFILER_H__
  10. #define __XT_PROFILER_H__
  11. #include <xtensa/config/core.h>
  12. #if XCHAL_NUM_PERF_COUNTERS
  13. /* Performance monitor counters constants */
  14. #include <xtensa/xt_perf_consts.h>
  15. #endif /* XCHAL_NUM_PERF_COUNTERS */
  16. #ifdef __cplusplus
  17. extern "C" {
  18. #endif
  19. /* This file defines an interface that allows a program being profiled
  20. to control when and how it is profiled, whether it is running under
  21. the instruction set simulator or under the hardware profiler.
  22. Both ISS and HWP implement this interface, although in different
  23. ways. Both also do the right thing if you don't call any of these
  24. functions.
  25. */
  26. /*
  27. xt_profile_init
  28. ISS: a no op.
  29. HWP: Initialize the profiler. Ordinarily, this function is called
  30. automatically via the .init section. If your environment does not
  31. support the .init section, you will need to call this function
  32. by hand.
  33. */
  34. extern void xt_profile_init(void);
  35. /*
  36. xt_profile_add_memory
  37. ISS: a no op.
  38. HWP:
  39. Makes "buf_size" bytes at "buf" available to the hardware profiler.
  40. This buffer should be initialized to zeros prior to this call.
  41. The hardware profiler has already estimated the amount of memory it needs,
  42. but under certain circumstances may still run out of memory. If so, you can
  43. provide more memory with this routine.
  44. */
  45. extern void xt_profile_add_memory(void * buf, unsigned int buf_size);
  46. /* xt_profile_enable
  47. Turn on the profiler. Ordinarily, profiling is on by default.
  48. If you turn off profiling using xt_profile_disable, You can turn
  49. it on again via this function.
  50. */
  51. extern void xt_profile_enable(void);
  52. /* xt_profile_disable
  53. Turn off the profiler. If you don't want to profile a portion of your code,
  54. use this function and then xt_profile_enable when you want to start again.
  55. */
  56. extern void xt_profile_disable(void);
  57. /* xt_profile_save_and_reset
  58. Save and reset the profiler's data.
  59. If there were errors, either during profiling or while attempting to
  60. write the data, no data will be written and this function will
  61. return non-zero.
  62. */
  63. extern int xt_profile_save_and_reset(void);
  64. /* xt_profile_get_frequency
  65. ISS: always returns 1.
  66. HWP:
  67. Returns the number of cycles between samples for timer based profiler.
  68. In performance counters based profiler always returns 1.
  69. */
  70. extern unsigned int xt_profile_get_frequency(void);
  71. /* xt_profile_set_frequency
  72. ISS: a no op.
  73. HWP:
  74. Set the number of cycles between samples for timer based profiler.
  75. Ignored in performance counters based profiler.
  76. sample frequency is the number of cycles to wait between samples. It should
  77. be a multiple of 1024.
  78. If you set the sample frequency to a different value than was passed in xt_profile_init,
  79. then the labels in the output will reflect the later frequency, even though some samples may
  80. have been taken at the earlier frequency. Typically this does not make a significant difference
  81. in the results if this function is called early enough.
  82. */
  83. extern void xt_profile_set_frequency(unsigned int sample_frequency);
  84. /* xt_profile_num_errors
  85. ISS: always returns 0
  86. HWP:
  87. Returns the number of errors that occured while taking samples. Typically these
  88. are out of memory errors and you need to pass a bigger buffer to
  89. xt_profile_add_memory
  90. */
  91. extern int xt_profile_num_errors(void);
  92. #if XCHAL_NUM_PERF_COUNTERS
  93. /* xt_profile_randomize
  94. ISS: not available
  95. HWP: Available in performance monitor based profiler.
  96. Turns on or off sampling period randomization mode. Period randomization
  97. helps to avoid aliasing problems when code being profiled is highly periodic.
  98. Profiler maintains same average sampling period but individual sampling
  99. steps may vary.
  100. Period randomization is turned off by default.
  101. <value> - non zero turns randomization on,
  102. zero turns randomization off.
  103. */
  104. extern void xt_profile_randomization(int value);
  105. /* xt_profile_config_clear
  106. ISS: not available
  107. HWP: Available in performance monitor based profiler.
  108. Stops profiling if it was enabled and clears performance counters
  109. parameters. Accumulated profile data stays in memory and will be
  110. saved when xt_profile_save_and_reset is called or at program exit.
  111. Number of configured performance counters is zero after this
  112. function call.
  113. */
  114. extern void xt_profile_config_clear(void);
  115. /* xt_profile_config_num
  116. ISS: not available
  117. HWP: Available in performance monitor based profiler.
  118. Returns number of free performance counters.
  119. */
  120. extern int xt_profile_config_num(void);
  121. /* xt_profile_config_counter error codes
  122. */
  123. #define XTPROF_ERR_OUT_OF_MEM -1
  124. #define XTPROF_ERR_INVALID_ARGS -2
  125. #define XTPROF_ERR_NOT_ENOUGH_COUNTERS -3
  126. #define XTPROF_ERR_DEFUNCT -4
  127. /* xt_profile_config_counter
  128. ISS: not available
  129. HWP: Available in performance monitor based profiler.
  130. Allocating and initializing one or more performance counter for sampling.
  131. Even though event may require multiple performance counters allocated the
  132. profile data for event is merged and dumped into single gmon file.
  133. This function disables profiling if it was enabled.
  134. Returns 0 on success, non zero if failed:
  135. XTPROF_ERR_OUT_OF_MEM - memory allocation failed;
  136. XTPROF_ERR_INVALID_ARGS - invalid function parameters;
  137. XTPROF_ERR_NOT_ENOUGH_COUNTERS - not enough free performance counters available;
  138. XTPROF_ERR_DEFUNCT - profiling is disabled because of previous errors
  139. (xt_profile_num_errors() is non zero)
  140. <selector> - events group, one of XTPERF_CNT constants defined in xt_perf_consts.h
  141. <mask> - events mask for selected group. Mask bit fields for each
  142. selector defined with XTPERF_MASK prefix in xt_perf_consts.h
  143. <trace_level> - specifies interrupt levels at which to take samples;
  144. if trace_level is greater or equal to zero samples are
  145. taken only at interrupt levels below or equal to
  146. trace_level; if trace_level is negative samples are taken
  147. only at (-trace_level) interrupt level or higher.
  148. <period> - sampling period; 1 - record every event, 2 - record every
  149. other event and so on;
  150. Please note - there is overhead associated with events recording,
  151. high frequency events may produce incorrect profile when period
  152. is too small.
  153. */
  154. extern int xt_profile_config_counter ( unsigned int selector,
  155. unsigned int mask,
  156. int trace_level,
  157. unsigned int period);
  158. #endif /* XCHAL_NUM_PERF_COUNTERS */
  159. #ifdef __cplusplus
  160. }
  161. #endif
  162. #endif /* __XT_PROFILER_H__ */