timekeeping_debug.c 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /*
  2. * debugfs file to track time spent in suspend
  3. *
  4. * Copyright (c) 2011, Google, Inc.
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful, but WITHOUT
  12. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  14. * more details.
  15. */
  16. #include <linux/debugfs.h>
  17. #include <linux/err.h>
  18. #include <linux/init.h>
  19. #include <linux/kernel.h>
  20. #include <linux/seq_file.h>
  21. #include <linux/time.h>
  22. #include "timekeeping_internal.h"
  23. #define NUM_BINS 32
  24. static unsigned int sleep_time_bin[NUM_BINS] = {0};
  25. static int tk_debug_show_sleep_time(struct seq_file *s, void *data)
  26. {
  27. unsigned int bin;
  28. seq_puts(s, " time (secs) count\n");
  29. seq_puts(s, "------------------------------\n");
  30. for (bin = 0; bin < 32; bin++) {
  31. if (sleep_time_bin[bin] == 0)
  32. continue;
  33. seq_printf(s, "%10u - %-10u %4u\n",
  34. bin ? 1 << (bin - 1) : 0, 1 << bin,
  35. sleep_time_bin[bin]);
  36. }
  37. return 0;
  38. }
  39. static int tk_debug_sleep_time_open(struct inode *inode, struct file *file)
  40. {
  41. return single_open(file, tk_debug_show_sleep_time, NULL);
  42. }
  43. static const struct file_operations tk_debug_sleep_time_fops = {
  44. .open = tk_debug_sleep_time_open,
  45. .read = seq_read,
  46. .llseek = seq_lseek,
  47. .release = single_release,
  48. };
  49. static int __init tk_debug_sleep_time_init(void)
  50. {
  51. struct dentry *d;
  52. d = debugfs_create_file("sleep_time", 0444, NULL, NULL,
  53. &tk_debug_sleep_time_fops);
  54. if (!d) {
  55. pr_err("Failed to create sleep_time debug file\n");
  56. return -ENOMEM;
  57. }
  58. return 0;
  59. }
  60. late_initcall(tk_debug_sleep_time_init);
  61. void tk_debug_account_sleep_time(struct timespec64 *t)
  62. {
  63. /* Cap bin index so we don't overflow the array */
  64. int bin = min(fls(t->tv_sec), NUM_BINS-1);
  65. sleep_time_bin[bin]++;
  66. }