PageRenderTime 69ms CodeModel.GetById 41ms RepoModel.GetById 0ms app.codeStats 0ms

/drivers/net/wireless/tiwlan1251/pform/linux/src/tiwlan_profile.c

http://github.com/CyanogenMod/cm-kernel
C | 344 lines | 204 code | 64 blank | 76 comment | 29 complexity | 5a4c587375f3b74fc7501dfff60e8c9c MD5 | raw file
Possible License(s): AGPL-1.0, GPL-2.0, LGPL-2.0
  1. /****************************************************************************
  2. **+-----------------------------------------------------------------------+**
  3. **| |**
  4. **| Copyright(c) 1998 - 2008 Texas Instruments. All rights reserved. |**
  5. **| All rights reserved. |**
  6. **| |**
  7. **| Redistribution and use in source and binary forms, with or without |**
  8. **| modification, are permitted provided that the following conditions |**
  9. **| are met: |**
  10. **| |**
  11. **| * Redistributions of source code must retain the above copyright |**
  12. **| notice, this list of conditions and the following disclaimer. |**
  13. **| * Redistributions in binary form must reproduce the above copyright |**
  14. **| notice, this list of conditions and the following disclaimer in |**
  15. **| the documentation and/or other materials provided with the |**
  16. **| distribution. |**
  17. **| * Neither the name Texas Instruments nor the names of its |**
  18. **| contributors may be used to endorse or promote products derived |**
  19. **| from this software without specific prior written permission. |**
  20. **| |**
  21. **| THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |**
  22. **| "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |**
  23. **| LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |**
  24. **| A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |**
  25. **| OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |**
  26. **| SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |**
  27. **| LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |**
  28. **| DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |**
  29. **| THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |**
  30. **| (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |**
  31. **| OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |**
  32. **| |**
  33. **+-----------------------------------------------------------------------+**
  34. ****************************************************************************/
  35. #include "esta_drv.h"
  36. static void tiwlan_profile_bus_access_start (void *os, unsigned);
  37. static void tiwlan_profile_bus_access_end (void *os, unsigned);
  38. static void tiwlan_profile_driver_entry_start (void *os, unsigned);
  39. static void tiwlan_profile_driver_entry_end (void *os, unsigned);
  40. static void tiwlan_profile_memory_alloc (void *os, unsigned);
  41. static void tiwlan_profile_memory_free (void *os, unsigned);
  42. static void tiwlan_profile_buf_alloc (void * os, unsigned);
  43. static void tiwlan_profile_timer_create (void * os, unsigned);
  44. static void tiwlan_profile_timer_destroy (void * os, unsigned);
  45. int tiwlan_profile_create (tiwlan_net_dev_t *drv)
  46. {
  47. drv->fpro [0] = NULL;
  48. drv->fpro [1] = NULL;
  49. drv->fpro [2] = NULL;
  50. drv->fpro [3] = NULL;
  51. drv->fpro [4] = tiwlan_profile_memory_alloc;
  52. drv->fpro [5] = tiwlan_profile_memory_free;
  53. drv->fpro [6] = tiwlan_profile_timer_create;
  54. drv->fpro [7] = tiwlan_profile_timer_destroy;
  55. drv->fpro [8] = tiwlan_profile_buf_alloc;
  56. drv->cpu_usage_estimator_start_time = 0;
  57. drv->cpu_usage_estimator_stop_time = 0;
  58. drv->max_heap_bytes_allocated = 0;
  59. drv->max_buf_bytes_allocated = 0;
  60. drv->cur_heap_bytes_allocated = 0;
  61. drv->max_number_of_timers = 0;
  62. drv->cur_number_of_timers = 0;
  63. return 0;
  64. }
  65. /* Call register profiler banchmark */
  66. int tiwlan_profile (tiwlan_net_dev_t *drv, unsigned bm, unsigned par)
  67. {
  68. if (drv && bm < MAX_PROFILE_BM && drv->fpro [bm])
  69. {
  70. (*drv->fpro [bm]) (drv, par);
  71. }
  72. return 0;
  73. }
  74. /* Stop CPU estimation for a driver entry and maintains the resolution of the estimator */
  75. void tiwlan_profile_bus_access_start (void * os, unsigned par)
  76. {
  77. tiwlan_net_dev_t * drv = (tiwlan_net_dev_t *) os;
  78. if (drv != NULL)
  79. {
  80. /* Save the current entry's start time */
  81. drv->bus_driver_entry_start_time = os_timeStampUs (drv);
  82. }
  83. }
  84. /* Starts CPU estimation for a bus driver entry */
  85. void tiwlan_profile_bus_access_end (void * os, unsigned par)
  86. {
  87. tiwlan_net_dev_t * drv = (tiwlan_net_dev_t *) os;
  88. unsigned current_entry_cpu_usage;
  89. if (drv != NULL)
  90. {
  91. /* Save the current entry's start time */
  92. current_entry_cpu_usage = os_timeStampUs (drv) - drv->bus_driver_entry_start_time;
  93. /* Make sure that it is not a negative value */
  94. if ((int)current_entry_cpu_usage < 0)
  95. {
  96. printk("\n\n%s: cpu usage estimation corrupted. entry_start=%u, entry_cpu_time = %d\n\n\n",
  97. __FUNCTION__, drv->bus_driver_entry_start_time, current_entry_cpu_usage);
  98. }
  99. /* Update the total time of driver CPU usage */
  100. else
  101. {
  102. drv->total_us_of_bus_access_cpu_time += current_entry_cpu_usage;
  103. }
  104. }
  105. }
  106. /* Starts CPU estimation for a driver entry */
  107. void tiwlan_profile_driver_entry_start (void * os, unsigned par)
  108. {
  109. tiwlan_net_dev_t * drv = (tiwlan_net_dev_t *) os;
  110. if (drv != NULL)
  111. {
  112. drv->driver_entry_start_time = os_timeStampUs (drv);
  113. }
  114. }
  115. /* Stop CPU estimation for a driver entry and maintains the resolution of the estimator */
  116. void tiwlan_profile_driver_entry_end (void * os, unsigned par)
  117. {
  118. tiwlan_net_dev_t * drv = (tiwlan_net_dev_t *) os;
  119. unsigned current_entry_cpu_usage, driver_entry_end_time;
  120. if (drv == NULL)
  121. return;
  122. /* Get the current entry's end time */
  123. driver_entry_end_time = os_timeStampUs (drv);
  124. /* Calculate the current entries CPU run time */
  125. current_entry_cpu_usage = driver_entry_end_time - drv->driver_entry_start_time;
  126. /* Make sure that it is not a negative value */
  127. if ((int)current_entry_cpu_usage < 0)
  128. {
  129. printk("\n\n%s: cpu usage estimation corrupted. entry_start=%u, entry_end=%u, entry_cpu_time = %d\n\n\n",
  130. __FUNCTION__, drv->driver_entry_start_time, driver_entry_end_time, current_entry_cpu_usage);
  131. }
  132. /* Update the total time of driver CPU usage */
  133. else
  134. {
  135. drv->total_us_of_cpu_time += current_entry_cpu_usage;
  136. }
  137. }
  138. void tiwlan_profile_memory_alloc (void * os, unsigned size)
  139. {
  140. tiwlan_net_dev_t * drv = (tiwlan_net_dev_t *) os;
  141. if (drv != NULL)
  142. {
  143. /* Increase current heap allocation counter */
  144. drv->cur_heap_bytes_allocated += size;
  145. /* Update maximum if execceded */
  146. if (drv->max_heap_bytes_allocated < drv->cur_heap_bytes_allocated)
  147. {
  148. drv->max_heap_bytes_allocated = drv->cur_heap_bytes_allocated;
  149. }
  150. }
  151. }
  152. void tiwlan_profile_memory_free (void * os, unsigned size)
  153. {
  154. tiwlan_net_dev_t * drv = (tiwlan_net_dev_t *) os;
  155. if (drv != NULL)
  156. {
  157. /* Decrease amount from heap allocation counter */
  158. drv->cur_heap_bytes_allocated -= size;
  159. /* Check for overflow */
  160. if ((int)drv->cur_heap_bytes_allocated < 0)
  161. {
  162. printk("\n\n%s: memory heap allocation calculation corrupted. Size=%u, Current allocation = %d\n\n\n",
  163. __FUNCTION__, size, drv->cur_heap_bytes_allocated);
  164. drv->cur_heap_bytes_allocated = 0;
  165. }
  166. }
  167. }
  168. void tiwlan_profile_buf_alloc (void * os, unsigned size)
  169. {
  170. tiwlan_net_dev_t * drv = (tiwlan_net_dev_t *) os;
  171. if (drv != NULL)
  172. {
  173. drv->max_buf_bytes_allocated += size;
  174. }
  175. }
  176. void tiwlan_profile_timer_create (void * os, unsigned par)
  177. {
  178. tiwlan_net_dev_t * drv = (tiwlan_net_dev_t *) os;
  179. if (drv)
  180. {
  181. /* Increase the current active timer counter */
  182. drv->cur_number_of_timers ++;
  183. /* Update maximum if execceded */
  184. if (drv->max_number_of_timers < drv->cur_number_of_timers)
  185. {
  186. drv->max_number_of_timers = drv->cur_number_of_timers;
  187. }
  188. }
  189. }
  190. void tiwlan_profile_timer_destroy (void * os, unsigned par)
  191. {
  192. tiwlan_net_dev_t * drv = (tiwlan_net_dev_t *) os;
  193. if (drv)
  194. {
  195. /* Decrease the current active timer counter */
  196. drv->cur_number_of_timers --;
  197. }
  198. }
  199. /*
  200. * Start CPU estimator
  201. * NOTE: this function does not run in a driver context
  202. */
  203. int tiwlan_profile_cpu_usage_estimator_start (tiwlan_net_dev_t * drv, unsigned int resolution)
  204. {
  205. /*
  206. * Reset estimation parameters - no need for spin lock since
  207. * estimator is not running
  208. */
  209. drv->total_us_of_cpu_time = 0;
  210. drv->total_us_of_bus_access_cpu_time = 0;
  211. drv->cpu_usage_estimator_start_time = os_timeStampUs (drv);
  212. drv->cpu_usage_estimator_stop_time = 0;
  213. /* Set the new resolution */
  214. drv->cpu_usage_estimator_resolution = resolution;
  215. /* Register profiler banchmarks */
  216. drv->fpro [0] = tiwlan_profile_driver_entry_start;
  217. drv->fpro [1] = tiwlan_profile_driver_entry_end;
  218. drv->fpro [2] = tiwlan_profile_bus_access_start;
  219. drv->fpro [3] = tiwlan_profile_bus_access_end;
  220. return 0;
  221. }
  222. /*
  223. * Stop CPU estimator and save the last CPU estimation
  224. * NOTE: this function does not run in a driver context
  225. */
  226. int tiwlan_profile_cpu_usage_estimator_stop (tiwlan_net_dev_t * drv)
  227. {
  228. drv->cpu_usage_estimator_stop_time = os_timeStampUs (drv);
  229. /* Unregister profiler banchmarks */
  230. drv->fpro [0] = NULL;
  231. drv->fpro [1] = NULL;
  232. drv->fpro [2] = NULL;
  233. drv->fpro [3] = NULL;
  234. return 0;
  235. }
  236. /*
  237. * Reset CPU estimation
  238. * NOTE: this function is not run in a driver context
  239. */
  240. int tiwlan_profile_cpu_usage_estimator_reset (tiwlan_net_dev_t * drv)
  241. {
  242. /* Reset accumulated driver time and the last estimation */
  243. drv->total_us_of_cpu_time = 0;
  244. drv->total_us_of_bus_access_cpu_time = 0;
  245. drv->cpu_usage_estimator_start_time = 0;
  246. drv->cpu_usage_estimator_stop_time = 0;
  247. return 0;
  248. }
  249. /* Print to the screen the latest resource usage and CPU estimation */
  250. int tiwlan_profile_report (tiwlan_net_dev_t *drv)
  251. {
  252. unsigned total_time, drv_cpu_usage = 0, bus_cpu_usage = 0;
  253. printk ("\nDriver Resource Usage");
  254. printk ("\n=====================");
  255. printk ("\nMaximum Heap Memory Allocated: %u (bytes)", drv->max_heap_bytes_allocated);
  256. printk ("\nCurrent Heap Memory Allocated: %u (bytes)", drv->cur_heap_bytes_allocated);
  257. printk ("\nBuffer Memory Allocated: %u (bytes)", drv->max_buf_bytes_allocated);
  258. printk ("\nFirmware Image Memory Allocated: %u (bytes)", (unsigned)drv->firmware_image.size);
  259. printk ("\nEEPROM Image Memory Allocated: %u (bytes)", (unsigned)drv->eeprom_image.size);
  260. printk ("\nMaximum Active Timers: %u", drv->max_number_of_timers);
  261. printk ("\nCurrent Active Timers: %u", drv->cur_number_of_timers);
  262. /* Check that the estimation has been started and stopped stopped */
  263. if (drv->cpu_usage_estimator_stop_time != 0)
  264. {
  265. total_time = drv->cpu_usage_estimator_stop_time - drv->cpu_usage_estimator_start_time;
  266. total_time /= 100;
  267. if ((int)total_time > 0)
  268. {
  269. drv_cpu_usage = drv->total_us_of_cpu_time / total_time;
  270. bus_cpu_usage = drv->total_us_of_bus_access_cpu_time / total_time;
  271. printk ("\nTotal Test Run Time: %u (usec)", total_time);
  272. printk ("\nTotal Driver Run Time: %u (usec)", drv->total_us_of_cpu_time);
  273. printk ("\nTotal Bus Access Time: %u (usec)", drv->total_us_of_bus_access_cpu_time);
  274. printk ("\nTotal CPU Usage: %u%%", drv_cpu_usage);
  275. printk ("\nBus Access CPU Usage: %u%%", bus_cpu_usage);
  276. printk ("\n");
  277. }
  278. }
  279. return 0;
  280. }