mtk_drm_trace.c 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. /*
  2. * Copyright (C) 2015 MediaTek Inc.
  3. *
  4. * This program is free software: you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License version 2 as
  6. * published by the Free Software Foundation.
  7. *
  8. * This program is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU General Public License for more details.
  12. */
  13. #include "mtk_drm_trace.h"
  14. #include <linux/trace_events.h>
  15. #include <linux/kallsyms.h>
  16. #include <linux/kernel.h>
  17. #include "mtk_drm_ddp_comp.h"
  18. #include "mtk_drm_crtc.h"
  19. #include "mtk_drm_helper.h"
  20. #include "mtk_drm_drv.h"
  21. #ifdef DRM_MMPATH
  22. #include "mmpath.h"
  23. #endif
  24. unsigned long mtk_drm_get_tracing_mark(void)
  25. {
  26. static unsigned long addr;
  27. if (unlikely(addr == 0))
  28. addr = kallsyms_lookup_name("tracing_mark_write");
  29. return addr;
  30. }
  31. static void drm_print_trace(const char *tag, int value)
  32. {
  33. preempt_disable();
  34. event_trace_printk(mtk_drm_get_tracing_mark(), "C|%d|%s|%d\n",
  35. DRM_TRACE_ID, tag, value);
  36. preempt_enable();
  37. }
  38. void drm_trace_tag_start(const char *tag)
  39. {
  40. drm_print_trace(tag, 1);
  41. }
  42. void drm_trace_tag_end(const char *tag)
  43. {
  44. drm_print_trace(tag, 0);
  45. }
  46. void drm_trace_tag_mark(const char *tag)
  47. {
  48. preempt_disable();
  49. event_trace_printk(mtk_drm_get_tracing_mark(), "C|%d|%s|%d\n",
  50. DRM_TRACE_ID, tag, 1);
  51. event_trace_printk(mtk_drm_get_tracing_mark(), "C|%d|%s|%d\n",
  52. DRM_TRACE_ID, tag, 0);
  53. preempt_enable();
  54. }
  55. void mtk_drm_refresh_tag_start(struct mtk_ddp_comp *ddp_comp)
  56. {
  57. char tag_name[30] = {'\0'};
  58. int i, j, crtc_idx, met_mode;
  59. struct mtk_drm_crtc *mtk_crtc = ddp_comp->mtk_crtc;
  60. bool b_layer_changed = 0;
  61. struct mtk_ddp_comp *comp;
  62. struct mtk_drm_private *priv;
  63. int r;
  64. if (!mtk_crtc)
  65. return;
  66. priv = mtk_crtc->base.dev->dev_private;
  67. met_mode = mtk_drm_helper_get_opt(priv->helper_opt, MTK_DRM_OPT_MET);
  68. if (!met_mode)
  69. return;
  70. crtc_idx = drm_crtc_index(&mtk_crtc->base);
  71. if (mtk_crtc_is_dc_mode(&mtk_crtc->base)) {
  72. mtk_ddp_comp_io_cmd(ddp_comp, NULL, BACKUP_INFO_CMP,
  73. &b_layer_changed);
  74. } else {
  75. for_each_comp_in_cur_crtc_path(comp, mtk_crtc, i, j) {
  76. if (comp->id >= DDP_COMPONENT_OVL0 &&
  77. comp->id <= DDP_COMPONENT_OVL1_2L) {
  78. mtk_ddp_comp_io_cmd(comp, NULL, BACKUP_INFO_CMP,
  79. &b_layer_changed);
  80. }
  81. }
  82. }
  83. if (b_layer_changed) {
  84. r = sprintf(tag_name,
  85. crtc_idx ? "ExtDispRefresh" : "PrimDispRefresh");
  86. if (r < 0) {
  87. /* Handle sprintf() error */
  88. pr_debug("sprintf error\n");
  89. }
  90. preempt_disable();
  91. event_trace_printk(mtk_drm_get_tracing_mark(), "C|%d|%s|%d\n",
  92. DRM_TRACE_FPS_ID, tag_name, 1);
  93. preempt_enable();
  94. }
  95. }
  96. void mtk_drm_refresh_tag_end(struct mtk_ddp_comp *ddp_comp)
  97. {
  98. char tag_name[30] = {'\0'};
  99. int crtc_idx, met_mode;
  100. struct mtk_drm_crtc *mtk_crtc = ddp_comp->mtk_crtc;
  101. struct mtk_drm_private *priv;
  102. int r;
  103. if (!mtk_crtc)
  104. return;
  105. priv = mtk_crtc->base.dev->dev_private;
  106. met_mode = mtk_drm_helper_get_opt(priv->helper_opt, MTK_DRM_OPT_MET);
  107. if (!met_mode)
  108. return;
  109. crtc_idx = drm_crtc_index(&mtk_crtc->base);
  110. r = sprintf(tag_name, crtc_idx ? "ExtDispRefresh" : "PrimDispRefresh");
  111. if (r < 0) {
  112. /* Handle sprintf() error */
  113. pr_debug("sprintf error\n");
  114. }
  115. preempt_disable();
  116. event_trace_printk(mtk_drm_get_tracing_mark(), "C|%d|%s|%d\n",
  117. DRM_TRACE_FPS_ID, tag_name, 0);
  118. preempt_enable();
  119. }
  120. #ifdef DRM_MMPATH
  121. int get_HWC_gpid(struct mtk_ddp_comp *ddp_comp)
  122. {
  123. struct drm_crtc *crtc = &ddp_comp->mtk_crtc->base;
  124. struct mtk_drm_private *priv = crtc->dev->dev_private;
  125. return priv->HWC_gpid;
  126. }
  127. void MMPathTraceOVL2DSI(struct mtk_ddp_comp *ddp_comp)
  128. {
  129. char str[1300] = "";
  130. int strlen = sizeof(str), n = 0;
  131. n += scnprintf(str + n, strlen - n,
  132. "hw=DISP_OVL0, pid=%d, ", get_HWC_gpid(ddp_comp));
  133. n = MMPathTraceCrtcPlanes(&ddp_comp->mtk_crtc->base, str, strlen, n);
  134. n += scnprintf(str + n, strlen - n, "out=DISP_DSI");
  135. trace_MMPath(str);
  136. }
  137. void MMPathTraceRDMA2DSI(struct mtk_ddp_comp *ddp_comp)
  138. {
  139. char str[1300] = "";
  140. int strlen = sizeof(str), n = 0;
  141. n += scnprintf(str + n, strlen - n,
  142. "hw=DISP_RDMA0, pid=%d, ", get_HWC_gpid(ddp_comp));
  143. n = MMPathTraceRDMA(ddp_comp, str, strlen, n);
  144. n += scnprintf(str + n, strlen - n, "out=DISP_DSI");
  145. trace_MMPath(str);
  146. }
  147. void MMPathTraceOVL2WDMA(struct mtk_ddp_comp *ddp_comp)
  148. {
  149. char str[1300] = "";
  150. int strlen = sizeof(str), n = 0;
  151. if (drm_crtc_index(&ddp_comp->mtk_crtc->base) == 0)
  152. n += scnprintf(str + n, strlen - n,
  153. "hw=DISP_OVL0, pid=%d, ", get_HWC_gpid(ddp_comp));
  154. else
  155. n += scnprintf(str + n, strlen - n,
  156. "hw=DISP_OVL1, pid=%d, ", get_HWC_gpid(ddp_comp));
  157. n = MMPathTraceCrtcPlanes(&ddp_comp->mtk_crtc->base, str, strlen, n);
  158. n = MMPathTraceWDMA(ddp_comp, str, strlen, n);
  159. trace_MMPath(str);
  160. }
  161. void MMPathTraceDRM(struct mtk_ddp_comp *ddp_comp)
  162. {
  163. struct drm_crtc *crtc = &ddp_comp->mtk_crtc->base;
  164. struct mtk_drm_private *priv = crtc->dev->dev_private;
  165. if (mtk_drm_helper_get_opt(priv->helper_opt, MTK_DRM_OPT_MMPATH) == 0)
  166. return;
  167. if (ddp_comp->id == DDP_COMPONENT_RDMA0) {
  168. if (mtk_crtc_is_dc_mode(crtc) == 0)
  169. MMPathTraceOVL2DSI(ddp_comp);
  170. else
  171. MMPathTraceRDMA2DSI(ddp_comp);
  172. } else if (ddp_comp->id == DDP_COMPONENT_WDMA0)
  173. MMPathTraceOVL2WDMA(ddp_comp);
  174. }
  175. #else
  176. void MMPathTraceDRM(struct mtk_ddp_comp *ddp_comp)
  177. {
  178. }
  179. #endif