timer_list_aee.c 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301
  1. /*
  2. * Copyright (C) year 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.
  11. * See http://www.gnu.org/licenses/gpl-2.0.html for more details.
  12. */
  13. #include <linux/proc_fs.h>
  14. #include <linux/module.h>
  15. #include <linux/spinlock.h>
  16. #include <linux/sched.h>
  17. #include <linux/seq_file.h>
  18. #include <linux/kallsyms.h>
  19. #include <linux/nmi.h>
  20. #include <linux/uaccess.h>
  21. #ifdef CONFIG_MTK_AEE_IPANIC
  22. #include <mt-plat/mtk_ram_console.h>
  23. #endif
  24. #include "tick-internal.h"
  25. static char print_at_AEE_buffer[256];
  26. #define SEQ_printf_at_AEE(m, x...) do { \
  27. if (snprintf(print_at_AEE_buffer, sizeof(print_at_AEE_buffer), x) > 0) \
  28. aee_sram_fiq_log(print_at_AEE_buffer);\
  29. } while (0)
  30. static void print_name_offset(struct seq_file *m, void *sym,
  31. struct hrtimer *timer)
  32. {
  33. char symname[KSYM_NAME_LEN];
  34. if (lookup_symbol_name((unsigned long)sym, symname) < 0) {
  35. SEQ_printf_at_AEE(m, "<%pK>", sym);
  36. } else {
  37. SEQ_printf_at_AEE(m, "%s", symname);
  38. if (timer && !strncmp(symname, "hrtimer_wakeup",
  39. strlen("hrtimer_wakeup"))) {
  40. struct hrtimer_sleeper *t =
  41. container_of(timer, struct hrtimer_sleeper,
  42. timer);
  43. SEQ_printf_at_AEE(m, " (task: %s)", t->task->comm);
  44. }
  45. }
  46. }
  47. static void
  48. print_timer(struct seq_file *m, struct hrtimer *taddr, struct hrtimer *timer,
  49. int idx, u64 now)
  50. {
  51. #ifdef CONFIG_TIMER_STATS
  52. char tmp[TASK_COMM_LEN + 1];
  53. #endif
  54. SEQ_printf_at_AEE(m, " #%d: ", idx);
  55. print_name_offset(m, taddr, NULL);
  56. SEQ_printf_at_AEE(m, ", ");
  57. print_name_offset(m, timer->function, taddr);
  58. SEQ_printf_at_AEE(m, ", S:%02x", timer->state);
  59. #ifdef CONFIG_TIMER_STATS
  60. SEQ_printf_at_AEE(m, ", ");
  61. print_name_offset(m, timer->start_site, NULL);
  62. memcpy(tmp, timer->start_comm, TASK_COMM_LEN);
  63. tmp[TASK_COMM_LEN] = 0;
  64. SEQ_printf_at_AEE(m, ", %s/%d", tmp, timer->start_pid);
  65. #endif
  66. SEQ_printf_at_AEE(m, "\n");
  67. SEQ_printf_at_AEE(m,
  68. " # expires at %llu-%llu nsecs [in %lld to %lld nsecs]\n",
  69. (unsigned long long)ktime_to_ns(hrtimer_get_softexpires(timer)),
  70. (unsigned long long)ktime_to_ns(hrtimer_get_expires(timer)),
  71. (long long)(ktime_to_ns(hrtimer_get_softexpires(timer)) - now),
  72. (long long)(ktime_to_ns(hrtimer_get_expires(timer)) - now));
  73. }
  74. static void
  75. print_active_timers(struct seq_file *m, struct hrtimer_clock_base *base,
  76. u64 now)
  77. {
  78. struct hrtimer *timer = NULL, tmp;
  79. unsigned long next = 0, i;
  80. struct timerqueue_node *curr = NULL;
  81. unsigned long flags;
  82. next_one:
  83. i = 0;
  84. touch_nmi_watchdog();
  85. raw_spin_lock_irqsave(&base->cpu_base->lock, flags);
  86. curr = timerqueue_getnext(&base->active);
  87. /*
  88. * Crude but we have to do this O(N*N) thing, because
  89. * we have to unlock the base when printing:
  90. */
  91. while (curr && i < next) {
  92. curr = timerqueue_iterate_next(curr);
  93. i++;
  94. }
  95. if (curr) {
  96. timer = container_of(curr, struct hrtimer, node);
  97. tmp = *timer;
  98. raw_spin_unlock_irqrestore(&base->cpu_base->lock, flags);
  99. print_timer(m, timer, &tmp, i, now);
  100. next++;
  101. goto next_one;
  102. }
  103. raw_spin_unlock_irqrestore(&base->cpu_base->lock, flags);
  104. }
  105. static void
  106. print_base(struct seq_file *m, struct hrtimer_clock_base *base, u64 now)
  107. {
  108. SEQ_printf_at_AEE(m, " .base: %pK\n", base);
  109. SEQ_printf_at_AEE(m, " .index: %d\n", base->index);
  110. SEQ_printf_at_AEE(m, " .resolution: %u nsecs\n", hrtimer_resolution);
  111. SEQ_printf_at_AEE(m, " .get_time: ");
  112. print_name_offset(m, base->get_time, NULL);
  113. SEQ_printf_at_AEE(m, "\n");
  114. #ifdef CONFIG_HIGH_RES_TIMERS
  115. SEQ_printf_at_AEE(m, " .offset: %llu nsecs\n",
  116. (unsigned long long) ktime_to_ns(base->offset));
  117. #endif
  118. SEQ_printf_at_AEE(m, "active timers:\n");
  119. print_active_timers(m, base, now + ktime_to_ns(base->offset));
  120. }
  121. static void print_cpu(struct seq_file *m, int cpu, u64 now)
  122. {
  123. struct hrtimer_cpu_base *cpu_base = &per_cpu(hrtimer_bases, cpu);
  124. int i;
  125. SEQ_printf_at_AEE(m, "cpu: %d\n", cpu);
  126. for (i = 0; i < HRTIMER_MAX_CLOCK_BASES; i++) {
  127. SEQ_printf_at_AEE(m, " clock %d:\n", i);
  128. print_base(m, cpu_base->clock_base + i, now);
  129. }
  130. #define P(x) \
  131. SEQ_printf_at_AEE(m, " .%-15s: %llu\n", #x, \
  132. (unsigned long long)(cpu_base->x))
  133. #define P_ns(x) \
  134. SEQ_printf_at_AEE(m, " .%-15s: %llu nsecs\n", #x, \
  135. (unsigned long long)(ktime_to_ns(cpu_base->x)))
  136. #ifdef CONFIG_HIGH_RES_TIMERS
  137. P_ns(expires_next);
  138. P(hres_active);
  139. P(nr_events);
  140. P(nr_retries);
  141. P(nr_hangs);
  142. P(max_hang_time);
  143. #endif
  144. #undef P
  145. #undef P_ns
  146. #ifdef CONFIG_TICK_ONESHOT
  147. # define P(x) \
  148. SEQ_printf_at_AEE(m, " .%-15s: %llu\n", #x, \
  149. (unsigned long long)(ts->x))
  150. # define P_ns(x) \
  151. SEQ_printf_at_AEE(m, " .%-15s: %llu nsecs\n", #x, \
  152. (unsigned long long)(ktime_to_ns(ts->x)))
  153. {
  154. struct tick_sched *ts = tick_get_tick_sched(cpu);
  155. P(nohz_mode);
  156. P_ns(last_tick);
  157. P(tick_stopped);
  158. P(idle_jiffies);
  159. P(idle_calls);
  160. P(idle_sleeps);
  161. P_ns(idle_entrytime);
  162. P_ns(idle_waketime);
  163. P_ns(idle_exittime);
  164. P_ns(idle_sleeptime);
  165. P_ns(iowait_sleeptime);
  166. P(last_jiffies);
  167. P(next_timer);
  168. P_ns(idle_expires);
  169. SEQ_printf_at_AEE(m, "jiffies: %llu\n",
  170. (unsigned long long)jiffies);
  171. }
  172. #endif
  173. #undef P
  174. #undef P_ns
  175. SEQ_printf_at_AEE(m, "\n");
  176. }
  177. #ifdef CONFIG_GENERIC_CLOCKEVENTS
  178. static void
  179. print_tickdevice(struct seq_file *m, struct tick_device *td, int cpu)
  180. {
  181. struct clock_event_device *dev = td->evtdev;
  182. touch_nmi_watchdog();
  183. SEQ_printf_at_AEE(m, "Tick Device: mode: %d\n", td->mode);
  184. if (cpu < 0)
  185. SEQ_printf_at_AEE(m, "Broadcast device\n");
  186. else
  187. SEQ_printf_at_AEE(m, "Per CPU device: %d\n", cpu);
  188. SEQ_printf_at_AEE(m, "Clock Event Device: ");
  189. if (!dev) {
  190. SEQ_printf_at_AEE(m, "<NULL>\n");
  191. return;
  192. }
  193. SEQ_printf_at_AEE(m, "%s\n", dev->name);
  194. SEQ_printf_at_AEE(m, " max_delta_ns: %llu\n",
  195. (unsigned long long) dev->max_delta_ns);
  196. SEQ_printf_at_AEE(m, " min_delta_ns: %llu\n",
  197. (unsigned long long) dev->min_delta_ns);
  198. SEQ_printf_at_AEE(m, " mult: %u\n", dev->mult);
  199. SEQ_printf_at_AEE(m, " shift: %u\n", dev->shift);
  200. SEQ_printf_at_AEE(m, " mode: %d\n",
  201. clockevent_get_state(dev));
  202. SEQ_printf_at_AEE(m, " next_event: %lld nsecs\n",
  203. (unsigned long long) ktime_to_ns(dev->next_event));
  204. SEQ_printf_at_AEE(m, " set_next_event: ");
  205. print_name_offset(m, dev->set_next_event, NULL);
  206. SEQ_printf_at_AEE(m, "\n");
  207. if (dev->set_state_shutdown) {
  208. SEQ_printf_at_AEE(m, " shutdown: ");
  209. print_name_offset(m, dev->set_state_shutdown, NULL);
  210. SEQ_printf_at_AEE(m, "\n");
  211. }
  212. if (dev->set_state_periodic) {
  213. SEQ_printf_at_AEE(m, " periodic: ");
  214. print_name_offset(m, dev->set_state_periodic, NULL);
  215. SEQ_printf_at_AEE(m, "\n");
  216. }
  217. if (dev->set_state_oneshot) {
  218. SEQ_printf_at_AEE(m, " oneshot: ");
  219. print_name_offset(m, dev->set_state_oneshot, NULL);
  220. SEQ_printf_at_AEE(m, "\n");
  221. }
  222. if (dev->set_state_oneshot_stopped) {
  223. SEQ_printf_at_AEE(m, " oneshot stopped: ");
  224. print_name_offset(m, dev->set_state_oneshot_stopped, NULL);
  225. SEQ_printf_at_AEE(m, "\n");
  226. }
  227. if (dev->tick_resume) {
  228. SEQ_printf_at_AEE(m, " resume: ");
  229. print_name_offset(m, dev->tick_resume, NULL);
  230. SEQ_printf_at_AEE(m, "\n");
  231. }
  232. SEQ_printf_at_AEE(m, " event_handler: ");
  233. print_name_offset(m, dev->event_handler, NULL);
  234. SEQ_printf_at_AEE(m, "\n");
  235. SEQ_printf_at_AEE(m, " retries: %lu\n", dev->retries);
  236. SEQ_printf_at_AEE(m, "\n");
  237. }
  238. #endif
  239. static inline void timer_list_header(struct seq_file *m, u64 now)
  240. {
  241. SEQ_printf_at_AEE(m, "Timer List Version: v0.8\n");
  242. SEQ_printf_at_AEE(m, "HRTIMER_MAX_CLOCK_BASES: %d\n",
  243. HRTIMER_MAX_CLOCK_BASES);
  244. SEQ_printf_at_AEE(m, "now at %lld nsecs\n", (unsigned long long)now);
  245. SEQ_printf_at_AEE(m, "\n");
  246. }
  247. void timer_list_aee_dump(int exclude_cpus)
  248. {
  249. u64 now = ktime_to_ns(ktime_get());
  250. int cpu;
  251. timer_list_header(NULL, now);
  252. for_each_online_cpu(cpu)
  253. if ((exclude_cpus & (1 << cpu)) == 0)
  254. print_cpu(NULL, cpu, now);
  255. #ifdef CONFIG_GENERIC_CLOCKEVENTS
  256. for_each_online_cpu(cpu)
  257. if ((exclude_cpus & (1 << cpu)) == 0)
  258. print_tickdevice(NULL, tick_get_device(cpu), cpu);
  259. #endif
  260. }