dsp_utils.h 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. /*
  2. * Copyright (c) 2021 Alibaba Group. All rights reserved.
  3. * License-Identifier: Apache-2.0
  4. *
  5. * Licensed under the Apache License, Version 2.0 (the "License"); you may
  6. * not use this file except in compliance with the License.
  7. * You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  13. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. *
  17. */
  18. /*!
  19. * \file
  20. * \brief This section defines DSP shared strcut for CPU&DSP&APP.
  21. *
  22. * General properties:
  23. * 1. Post porcess define data and strcut, visiable for APP
  24. * 2. user define data shared bedtween DSP ans host
  25. */
  26. #ifndef DSP_UTILS_H
  27. #define DSP_UTILS_H
  28. #include <stdio.h>
  29. #include "xrp_ring_buffer.h"
  30. #define MAX_PROFILE_GROUP 16
  31. #define RING_MODE
  32. //typedef struct profiler{
  33. //
  34. // struct xrp_ring_buffer;
  35. //}profiler_t;
  36. typedef struct xrp_ring_buffer profiler;
  37. typedef struct profile_group{
  38. int status;
  39. char group_name[32];
  40. }profile_group_t;
  41. typedef struct profile_entry{
  42. char entry_name[8];
  43. uint32_t begin_cycle;
  44. uint32_t end_cycle;
  45. char reserve[12];
  46. uint32_t total_cycle;
  47. }profile_entry_t;
  48. typedef struct profile_head{
  49. profile_group_t group[MAX_PROFILE_GROUP];
  50. profile_entry_t entry[0];
  51. }profile_head_t;
  52. #ifdef DSP_PROFILE_ENBALE
  53. int dsp_profile_init(void* buf,size_t buf_size);
  54. void dsp_profile_entry_add(void*entry_ptr,size_t entry_size);
  55. void dsp_profile_entry_add_ring(void*entry_ptr,size_t entry_size);
  56. #define DSP_PROFILE_FUNC_START(cookie) ( \
  57. static profile_entry_t entry; \
  58. memcpy(entry.entry_name,___FUNCTION__,16);\
  59. entry.begin_cycle = XT_RSR_CCOUNT();\
  60. )
  61. #define DSP_PROFILE_FUNC_END(cookie) ( \
  62. entry.end_cycle = XT_RSR_CCOUNT();\
  63. xrp_rb_write(cookie,&entry,sizeof(profile_entry_t));\
  64. )
  65. #define DSP_PROFILE_CUSTOM_DECLATR(name) static profile_entry_t entry_##name ={ \
  66. .entry_name = #name \
  67. };
  68. #define DSP_PROFILE_CUSTOM_START(name) entry_##name.begin_cycle = XT_RSR_CCOUNT();
  69. #define DSP_PROFILE_CUSTOM_ID_ADD(name,id) *((int *)&entry_##name.entry_name[4])=id;
  70. #ifdef RING_MODE
  71. #define DSP_PROFILE_CUSTOM_END(name) {entry_##name.end_cycle = XT_RSR_CCOUNT();\
  72. entry_##name.total_cycle = entry_##name.end_cycle- entry_##name.begin_cycle;\
  73. dsp_profile_entry_add_ring(&entry_##name,sizeof(profile_entry_t));}
  74. #else
  75. #define DSP_PROFILE_CUSTOM_END(name) {entry_##name.end_cycle = XT_RSR_CCOUNT();\
  76. entry_##name.total_cycle = entry_##name.end_cycle- entry_##name.begin_cycle;\
  77. dsp_profile_entry_add(&entry_##name,sizeof(profile_entry_t));}
  78. #endif
  79. #else
  80. #define DSP_PROFILE_FUNC_START(cookie)
  81. #define DSP_PROFILE_FUNC_END(cookie)
  82. #define DSP_PROFILE_CUSTOM_DECLATR(name)
  83. #define DSP_PROFILE_CUSTOM_ID_ADD(name,id)
  84. #define DSP_PROFILE_CUSTOM_START(name)
  85. #define DSP_PROFILE_CUSTOM_END(name)
  86. #endif
  87. #endif /* */