xt_perfmon.h 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. /*
  2. * Customer ID=11656; Build=0x5f626; Copyright (c) 2012 by Tensilica Inc. ALL RIGHTS RESERVED.
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a copy
  5. * of this software and associated documentation files (the "Software"), to deal
  6. * in the Software without restriction, including without limitation the rights
  7. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. * copies of the Software, and to permit persons to whom the Software is
  9. * furnished to do so, subject to the following conditions:
  10. *
  11. * The above copyright notice and this permission notice shall be included in
  12. * all copies or substantial portions of the Software.
  13. *
  14. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  19. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  20. * THE SOFTWARE.
  21. */
  22. #ifndef __XT_PERFMON_H__
  23. #define __XT_PERFMON_H__
  24. #include <xtensa/config/core.h>
  25. #include <xtensa/xt_perf_consts.h>
  26. #ifdef __cplusplus
  27. extern "C" {
  28. #endif
  29. typedef int counter_id_t;
  30. /* xt_perf_init
  31. Initialize the performance monitor library. Ordinarily, this
  32. function is called automatically via the .init section. If your
  33. environment does not support the .init section, you will need to
  34. call this function from your code.
  35. */
  36. extern void xt_perf_init(void);
  37. /* xt_perf_enable
  38. Turn on the performance monitor. Ordinarily, counting is off by
  39. default. If you turn off performance monitor using xt_perf_disable or
  40. by call to a function that disables performance monitor, you can turn
  41. it on again via this function.
  42. */
  43. extern void xt_perf_enable(void);
  44. /* xt_perf_disable
  45. Turn off the performance monitor. If you want to suspend counting
  46. events for a portion of your code, use this function and then call
  47. xt_perf_enable when you want to start again.
  48. */
  49. extern void xt_perf_disable(void);
  50. /* xt_perf_clear
  51. Disable performance monitor and clear all initialized hardware counters.
  52. All counter ids are invalid after call to this function and all hardware
  53. counters available for initialization.
  54. */
  55. extern void xt_perf_clear (void);
  56. /* xt_perf_counters_num
  57. Returns number of free hardware performance counters. After call to xt_perf_clear
  58. all counters are free and available for initialization. With each successful
  59. xt_perf_init_counter/xt_perf_init_event call this number is decreasing until
  60. no free counters available.
  61. */
  62. extern int xt_perf_counters_num (void);
  63. /* xt_perf_init_counter32
  64. Setup 32 bit performance counter. This function disables performance monitor
  65. if it was enabled.
  66. Returns zero based counter id on success or negative value if failed.
  67. This function may fail if there is insufficient number of free hardware
  68. counters or function arguments are invalid.
  69. The counter id returned on success can be used with xt_perf_reset_counter
  70. and xt_perf_counter32 functions.
  71. <selector> - events group, one of XTPERF_CNT constants defined in
  72. xt_perf_consts.h;
  73. <mask> - events mask for selected group. Mask bit fields for each
  74. selector defined with XTPERF_MASK prefix in xt_perf_consts.h;
  75. <trace_level> - specifies interrupt levels at which to count events;
  76. if trace_level is greater or equal to zero events are
  77. counted only at interrupt levels below or equal to
  78. trace_level; if trace_level is negative events are
  79. counted only at (-trace_level) interrupt level or higher.
  80. */
  81. extern counter_id_t xt_perf_init_counter32 ( unsigned int selector,
  82. unsigned int mask,
  83. int trace_level);
  84. /* xt_perf_init_counter64
  85. Setup 64 bit performance counter. Library emulates 64 bit counters by handling
  86. profiling interrupt and recording overflows of 32 bit hardware counters.
  87. This function disables performance monitor if it was enabled.
  88. Returns zero based counter id on success or negative value if failed.
  89. This function may fail if there is insufficient number of free hardware
  90. counters or function arguments are invalid.
  91. The counter id returned on success can be used with xt_perf_reset_counter
  92. and xt_perf_counter64 functions.
  93. <selector> - events group, one of XTPERF_CNT constants defined in
  94. xt_perf_consts.h;
  95. <mask> - events mask for selected group. Mask bit fields for each
  96. selector defined with XTPERF_MASK prefix in xt_perf_consts.h;
  97. <trace_level> - specifies interrupt levels at which to count events;
  98. if trace_level is greater or equal to zero events are
  99. counted only at interrupt levels below or equal to
  100. trace_level; if trace_level is negative events are
  101. counted only at (-trace_level) interrupt level or higher.
  102. */
  103. extern counter_id_t xt_perf_init_counter64 ( unsigned int selector,
  104. unsigned int mask,
  105. int trace_level);
  106. /* xt_perf_reset_counter
  107. Reset counter value to 0.
  108. Returns zero on success or non zero if failed.
  109. */
  110. extern int xt_perf_reset_counter (counter_id_t counter_id);
  111. /* xt_perf_counter32
  112. Read 32 bit counter value.
  113. Returns zero if counter id is not valid.
  114. */
  115. extern unsigned int xt_perf_counter32 (counter_id_t counter_id);
  116. /* xt_perf_counter64
  117. Read 64 bit counter value.
  118. Counter must be initialized using xt_perf_init_counter64 function.
  119. Returns zero if counter id is not valid.
  120. */
  121. extern unsigned long long xt_perf_counter64 (counter_id_t counter_id);
  122. /* xt_perf_overflow32
  123. Read overflow flag of 32 bit counter. This flag is dropped when
  124. counter initialized or reset. Once counter overflows and wraps
  125. around the flag is set and stays set until counter reset.
  126. Returns negative value if counter id is invalid, zero if counter
  127. not overflowed, positive if in overflowed state.
  128. */
  129. extern int xt_perf_overflow32 (counter_id_t counter_id);
  130. #ifdef __cplusplus
  131. }
  132. #endif
  133. #endif /* __XT_PERFMON_H__ */