perf_os_patch_threadx.c 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. /****************************************************************************
  2. * Copyright 2022 Gorgon Meducer (Email:embedded_zhuoran@hotmail.com) *
  3. * *
  4. * Licensed under the Apache License, Version 2.0 (the "License"); *
  5. * you may not use this file except in compliance with the License. *
  6. * You may obtain a copy of the License at *
  7. * *
  8. * http://www.apache.org/licenses/LICENSE-2.0 *
  9. * *
  10. * Unless required by applicable law or agreed to in writing, software *
  11. * distributed under the License is distributed on an "AS IS" BASIS, *
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
  13. * See the License for the specific language governing permissions and *
  14. * limitations under the License. *
  15. * *
  16. ****************************************************************************/
  17. /*============================ INCLUDES ======================================*/
  18. #include "tx_api.h"
  19. #include "tx_thread.h"
  20. #include "perf_counter.h"
  21. #include "cmsis_compiler.h"
  22. /*============================ MACROS ========================================*/
  23. #undef __WRAP_FUNC
  24. #undef WRAP_FUNC
  25. #if defined(__IS_COMPILER_ARM_COMPILER__) && __IS_COMPILER_ARM_COMPILER__
  26. # define __WRAP_FUNC(__NAME) $Sub$$##__NAME
  27. # define __ORIG_FUNC(__NAME) $Super$$##__NAME
  28. #elif (defined(__IS_COMPILER_LLVM__) && __IS_COMPILER_LLVM__) \
  29. || (defined(__IS_COMPILER_GCC__) && __IS_COMPILER_GCC__)
  30. # define __WRAP_FUNC(__NAME) __wrap_##__NAME
  31. # define __ORIG_FUNC(__NAME) __real_##__NAME
  32. #endif
  33. #define WRAP_FUNC(__NAME) __WRAP_FUNC(__NAME)
  34. #define ORIG_FUNC(__NAME) __ORIG_FUNC(__NAME)
  35. #if defined(TX_ENABLE_EXECUTION_CHANGE_NOTIFY) && defined(TX_EXECUTION_PROFILE_ENABLE)
  36. #error In order to use perf_counter:ThreadX-Patch, please define \
  37. TX_ENABLE_EXECUTION_CHANGE_NOTIFY or TX_EXECUTION_PROFILE_ENABLE \
  38. in the project configuration, according to the version of thread.\
  39. If you don't want to use this patch, please un-select it in RTE\
  40. or remove this patch from the compilation.
  41. #endif
  42. /*============================ TYPES =========================================*/
  43. struct __task_cycle_info_t {
  44. task_cycle_info_t tInfo;
  45. int64_t lLastTimeStamp;
  46. task_cycle_info_agent_t tList;
  47. uint32_t wMagicWord;
  48. } ;
  49. /*============================ GLOBAL VARIABLES ==============================*/
  50. /*============================ LOCAL VARIABLES ===============================*/
  51. /*============================ PROTOTYPES ====================================*/
  52. extern void __on_context_switch_in(uint32_t *pwStack);
  53. extern void __on_context_switch_out(uint32_t *pwStack);
  54. /*============================ IMPLEMENTATION ================================*/
  55. #if defined(TX_EXECUTION_PROFILE_ENABLE)
  56. void WRAP_FUNC(_tx_execution_thread_enter)(void)
  57. #else
  58. void _tx_execution_thread_enter (void)
  59. #endif
  60. {
  61. TX_THREAD * ptThread = NULL;
  62. TX_THREAD_GET_CURRENT(ptThread);
  63. __on_context_switch_in(ptThread->tx_thread_stack_start);
  64. #if defined(TX_EXECUTION_PROFILE_ENABLE)
  65. extern void ORIG_FUNC(_tx_execution_thread_enter)(void);
  66. ORIG_FUNC(_tx_execution_thread_enter)();
  67. #endif
  68. }
  69. #if defined(TX_EXECUTION_PROFILE_ENABLE)
  70. void WRAP_FUNC(_tx_execution_thread_exit)(void)
  71. #else
  72. void _tx_execution_thread_exit(void)
  73. #endif
  74. {
  75. TX_THREAD * ptThread = NULL;
  76. TX_THREAD_GET_CURRENT(ptThread);
  77. if (NULL != ptThread) {
  78. __on_context_switch_out(ptThread->tx_thread_stack_start);
  79. }
  80. #if defined(TX_EXECUTION_PROFILE_ENABLE)
  81. extern void ORIG_FUNC(_tx_execution_thread_exit)(void);
  82. ORIG_FUNC(_tx_execution_thread_exit)();
  83. #endif
  84. }
  85. #if !defined(TX_EXECUTION_PROFILE_ENABLE)
  86. void _tx_execution_isr_exit(void)
  87. {
  88. }
  89. void _tx_execution_isr_enter(void)
  90. {
  91. }
  92. #endif
  93. task_cycle_info_t * get_rtos_task_cycle_info(void)
  94. {
  95. TX_THREAD * ptThread = NULL;
  96. TX_THREAD_GET_CURRENT(ptThread);
  97. return &(((struct __task_cycle_info_t *)ptThread->tx_thread_stack_start)->tInfo);
  98. }