cmdq_prof.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. #include "cmdq_prof.h"
  2. #include "cmdq_core.h"
  3. /* expect no EMI latency, GCE spends 80 ns per 4 cycle*/
  4. #define CMDQ_HW_EXEC_NS(hw_cycle) (hw_cycle * (80 / 4))
  5. typedef enum CMDQ_OP_STATISTIC_ENUM {
  6. CMDQ_STA_READ = 0,
  7. CMDQ_STA_MOVE,
  8. CMDQ_STA_WRI,
  9. CMDQ_STA_WRI_WITH_MASK,
  10. CMDQ_STA_POLL,
  11. CMDQ_STA_JUMP,
  12. CMDQ_STA_WFE, /* wait for event */
  13. CMDQ_STA_SYNC, /* sync op and no wait for event */
  14. CMDQ_STA_EOC,
  15. CMDQ_STA_MAX_COUNT, /* always keep at the end */
  16. } CMDQ_OP_STATISTIC_ENUM;
  17. const char *cmdq_prof_get_statistic_id_name(const CMDQ_OP_STATISTIC_ENUM statisticId)
  18. {
  19. const char *IDName = "UNKNOWN";
  20. #undef DECLARE_CMDQ_INSTR_CYCLE
  21. #define DECLARE_CMDQ_INSTR_CYCLE(id, hw_op, cycle, name) { if (id == statisticId) {IDName = #name; break; } }
  22. do {
  23. #include "cmdq_instr_cycle.h"
  24. } while (0);
  25. #undef DECLARE_CMDQ_INSTR_CYCLE
  26. return IDName;
  27. }
  28. uint32_t cmdq_prof_get_statistic_id(const uint32_t *pCmd)
  29. {
  30. const uint32_t argB = pCmd[0];
  31. const uint32_t argA = pCmd[1];
  32. const uint32_t op = argA >> 24;
  33. uint32_t addr;
  34. uint32_t maskEn = 0;
  35. switch (op) {
  36. case CMDQ_CODE_WRITE:
  37. /* check address */
  38. if (argA & (1 << 23)) {
  39. /* address is GPR */
  40. return CMDQ_STA_WRI;
  41. }
  42. addr = cmdq_core_subsys_to_reg_addr(argA);
  43. maskEn = (addr & 0x1);
  44. if (maskEn)
  45. return CMDQ_STA_WRI_WITH_MASK;
  46. else
  47. return CMDQ_STA_WRI;
  48. case CMDQ_CODE_WFE:
  49. /* check waiting flag */
  50. if ((argB >> 15) & 0x1)
  51. return CMDQ_STA_WFE;
  52. else
  53. return CMDQ_STA_SYNC;
  54. case CMDQ_CODE_READ:
  55. return CMDQ_STA_READ;
  56. case CMDQ_CODE_MOVE:
  57. return CMDQ_STA_MOVE;
  58. case CMDQ_CODE_POLL:
  59. return CMDQ_STA_POLL;
  60. case CMDQ_CODE_JUMP:
  61. return CMDQ_STA_JUMP;
  62. case CMDQ_CODE_EOC:
  63. return CMDQ_STA_EOC;
  64. default:
  65. CMDQ_ERR("unknown op, argA: 0x%08x\n", argA);
  66. return 0;
  67. }
  68. CMDQ_ERR("unknown op, argA: 0x%08x\n", argA);
  69. return 0;
  70. }
  71. uint32_t cmdq_prof_calculate_HW_cycle(const CMDQ_OP_STATISTIC_ENUM statisticId,
  72. const uint32_t count)
  73. {
  74. uint32_t hwCycle = -1;
  75. #undef DECLARE_CMDQ_INSTR_CYCLE
  76. #define DECLARE_CMDQ_INSTR_CYCLE(id, hw_op, cycle, name) { if (id == statisticId) {hwCycle = (count * cycle); break; } }
  77. do {
  78. #include "cmdq_instr_cycle.h"
  79. } while (0);
  80. #undef DECLARE_CMDQ_INSTR_CYCLE
  81. if (-1 == hwCycle) {
  82. /* Error message dump */
  83. CMDQ_ERR("unknown statisticId: %d\n", statisticId);
  84. }
  85. return hwCycle;
  86. }
  87. int32_t cmdq_prof_estimate_command_exe_time(const uint32_t *pCmd, uint32_t commandSize)
  88. {
  89. uint32_t statistic[CMDQ_STA_MAX_COUNT] = { 0 };
  90. int i;
  91. uint32_t statisticId = 0;
  92. uint32_t cycle = 0;
  93. uint32_t totalCycle = 0;
  94. uint32_t totalNS = 0;
  95. if (NULL == pCmd)
  96. return -EFAULT;
  97. /* gather statistic */
  98. for (i = 0; i < commandSize; i += CMDQ_INST_SIZE, pCmd += 2) {
  99. statisticId = cmdq_prof_get_statistic_id(pCmd);
  100. statistic[statisticId] += 1;
  101. }
  102. CMDQ_LOG("NAME, COUNT, least HW exec cycle\n");
  103. /* calculate execution time */
  104. for (i = 0; i < CMDQ_STA_MAX_COUNT; i++) {
  105. cycle = cmdq_prof_calculate_HW_cycle(i, statistic[i]);
  106. totalCycle += cycle;
  107. CMDQ_LOG("%d:%11s, %d, %3d\n",
  108. i, cmdq_prof_get_statistic_id_name(i), statistic[i], cycle);
  109. }
  110. totalNS = CMDQ_HW_EXEC_NS(totalCycle);
  111. CMDQ_LOG("=====================================\n");
  112. CMDQ_LOG("estimated least HW exec time(ns): %6d\n", totalNS);
  113. CMDQ_LOG("***each HW cycle spends time(ns): %6d\n", CMDQ_HW_EXEC_NS(1));
  114. CMDQ_LOG
  115. ("***Real exec time will be longer when POLL/WAIT instr cannot pass their condition immediately.\n");
  116. return totalNS;
  117. }