ged_profile_dvfs.c 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  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 <linux/slab.h>
  14. #include <linux/sched.h>
  15. #include "ged_base.h"
  16. #include "ged_log.h"
  17. #include "ged_profile_dvfs.h"
  18. static GED_LOG_BUF_HANDLE ghLogBuf = 0;
  19. static struct mutex gsMutex;
  20. static GED_BOOL gbAllowRecord = GED_FALSE;
  21. GED_ERROR ged_profile_dvfs_init(void)
  22. {
  23. mutex_init(&gsMutex);
  24. #if 0
  25. ghLogBuf = ged_log_buf_alloc(320, 64 * 320, GED_LOG_BUF_TYPE_QUEUEBUFFER_AUTO_INCREASE, NULL, "profile_dvfs");
  26. #endif
  27. return GED_OK;
  28. }
  29. GED_ERROR ged_profile_dvfs_enable(void)
  30. {
  31. GED_ERROR ret;
  32. mutex_lock(&gsMutex);
  33. if (0 == ghLogBuf)
  34. {
  35. ghLogBuf = ged_log_buf_alloc(320, 64 * 320, GED_LOG_BUF_TYPE_QUEUEBUFFER_AUTO_INCREASE, NULL, "profile_dvfs");
  36. }
  37. ret = ghLogBuf ? GED_OK : GED_ERROR_FAIL;
  38. mutex_unlock(&gsMutex);
  39. return ret;
  40. }
  41. void ged_profile_dvfs_disable(void)
  42. {
  43. mutex_lock(&gsMutex);
  44. if (0 != ghLogBuf)
  45. {
  46. ged_log_buf_free(ghLogBuf);
  47. ghLogBuf = 0;
  48. }
  49. mutex_unlock(&gsMutex);
  50. }
  51. void ged_profile_dvfs_start(void)
  52. {
  53. gbAllowRecord = GED_TRUE;
  54. }
  55. void ged_profile_dvfs_stop(void)
  56. {
  57. gbAllowRecord = GED_FALSE;
  58. }
  59. void ged_profile_dvfs_ignore_lines(int i32LineCount)
  60. {
  61. mutex_lock(&gsMutex);
  62. if (ghLogBuf)
  63. {
  64. ged_log_buf_ignore_lines(ghLogBuf, i32LineCount);
  65. }
  66. mutex_unlock(&gsMutex);
  67. }
  68. void ged_profile_dvfs_exit(void)
  69. {
  70. ged_profile_dvfs_disable();
  71. }
  72. void ged_profile_dvfs_record_freq_volt(unsigned int ui32Frequency, unsigned int ui32Voltage)
  73. {
  74. mutex_lock(&gsMutex);
  75. if (ghLogBuf && gbAllowRecord)
  76. {
  77. /* copy & modify from ./kernel/printk.c */
  78. unsigned long long t;
  79. unsigned long nanosec_rem;
  80. t = ged_get_time();
  81. nanosec_rem = do_div(t, 1000000000) / 1000;
  82. ged_log_buf_print(ghLogBuf, "%5lu.%06lu,freq_volt,%u,%u", (unsigned long) t, nanosec_rem, ui32Frequency, ui32Voltage);
  83. }
  84. mutex_unlock(&gsMutex);
  85. }
  86. void ged_profile_dvfs_record_temp(int i32Temp)
  87. {
  88. mutex_lock(&gsMutex);
  89. if (ghLogBuf && gbAllowRecord)
  90. {
  91. /* copy & modify from ./kernel/printk.c */
  92. unsigned long long t;
  93. unsigned long nanosec_rem;
  94. t = ged_get_time();
  95. nanosec_rem = do_div(t, 1000000000) / 1000;
  96. ged_log_buf_print(ghLogBuf, "%5lu.%06lu,temp,%d", (unsigned long) t, nanosec_rem, i32Temp);
  97. }
  98. mutex_unlock(&gsMutex);
  99. }
  100. void ged_profile_dvfs_record_thermal_limit(unsigned int ui32FreqLimit)
  101. {
  102. mutex_lock(&gsMutex);
  103. if (ghLogBuf && gbAllowRecord)
  104. {
  105. /* copy & modify from ./kernel/printk.c */
  106. unsigned long long t;
  107. unsigned long nanosec_rem;
  108. t = ged_get_time();
  109. nanosec_rem = do_div(t, 1000000000) / 1000;
  110. ged_log_buf_print(ghLogBuf, "%5lu.%06lu,thermal_limit,%u", (unsigned long) t, nanosec_rem, ui32FreqLimit);
  111. }
  112. mutex_unlock(&gsMutex);
  113. }
  114. void ged_profile_dvfs_record_gpu_loading(unsigned int ui32GpuLoading)
  115. {
  116. mutex_lock(&gsMutex);
  117. if (ghLogBuf && gbAllowRecord)
  118. {
  119. /* copy & modify from ./kernel/printk.c */
  120. unsigned long long t;
  121. unsigned long nanosec_rem;
  122. t = ged_get_time();
  123. nanosec_rem = do_div(t, 1000000000) / 1000;
  124. ged_log_buf_print(ghLogBuf, "%5lu.%06lu,gpu_load,%u", (unsigned long) t, nanosec_rem, ui32GpuLoading);
  125. }
  126. mutex_unlock(&gsMutex);
  127. }
  128. void ged_profile_dvfs_record_clock_on(void)
  129. {
  130. mutex_lock(&gsMutex);
  131. if (ghLogBuf && gbAllowRecord)
  132. {
  133. /* copy & modify from ./kernel/printk.c */
  134. unsigned long long t;
  135. unsigned long nanosec_rem;
  136. t = ged_get_time();
  137. nanosec_rem = do_div(t, 1000000000) / 1000;
  138. ged_log_buf_print(ghLogBuf, "%5lu.%06lu,gpu_clock,1", (unsigned long) t, nanosec_rem);
  139. }
  140. mutex_unlock(&gsMutex);
  141. }
  142. void ged_profile_dvfs_record_clock_off(void)
  143. {
  144. mutex_lock(&gsMutex);
  145. if (ghLogBuf && gbAllowRecord)
  146. {
  147. /* copy & modify from ./kernel/printk.c */
  148. unsigned long long t;
  149. unsigned long nanosec_rem;
  150. t = ged_get_time();
  151. nanosec_rem = do_div(t, 1000000000) / 1000;
  152. ged_log_buf_print(ghLogBuf, "%5lu.%06lu,gpu_clock,0", (unsigned long) t, nanosec_rem);
  153. }
  154. mutex_unlock(&gsMutex);
  155. }
  156. void ged_profile_dvfs_record_SW_vsync(unsigned long ulTimeStamp, long lPhase, unsigned long ul3DFenceDoneTime)
  157. {
  158. mutex_lock(&gsMutex);
  159. if (ghLogBuf && gbAllowRecord)
  160. {
  161. /* copy & modify from ./kernel/printk.c */
  162. unsigned long long t;
  163. unsigned long nanosec_rem;
  164. t = ged_get_time();
  165. nanosec_rem = do_div(t, 1000000000) / 1000;
  166. ged_log_buf_print(ghLogBuf, "%5lu.%06lu,SW_vsync,%lu,%ld,%lu", (unsigned long) t, nanosec_rem, ulTimeStamp, lPhase, ul3DFenceDoneTime);
  167. }
  168. mutex_unlock(&gsMutex);
  169. }
  170. void ged_profile_dvfs_record_policy(
  171. long lFreq, unsigned int ui32GpuLoading, long lPreT1, unsigned long ulPreFreq, long t0, unsigned long ulCurFreq, long t1, long lPhase)
  172. {
  173. mutex_lock(&gsMutex);
  174. if (ghLogBuf && gbAllowRecord)
  175. {
  176. /* copy & modify from ./kernel/printk.c */
  177. unsigned long long t;
  178. unsigned long nanosec_rem;
  179. t = ged_get_time();
  180. nanosec_rem = do_div(t, 1000000000) / 1000;
  181. ged_log_buf_print(ghLogBuf, "%5lu.%06lu,Freq=%ld,Load=%u,PreT1=%ld,PreF=%lu,t0=%ld,CurF=%lu,t1=%ld,phase=%ld", (unsigned long) t, nanosec_rem, lFreq, ui32GpuLoading, lPreT1, ulPreFreq, t0, ulCurFreq, t1, lPhase);
  182. }
  183. mutex_unlock(&gsMutex);
  184. }