blob: b73e8850e58d9c5b291559f475e67c7ed47c2db3 [file] [log] [blame]
Thomas Gleixner35728b82018-10-31 19:21:09 +01001// SPDX-License-Identifier: GPL-2.0+
Colin Cross5c835452013-05-21 22:32:14 -07002/*
3 * debugfs file to track time spent in suspend
4 *
5 * Copyright (c) 2011, Google, Inc.
Colin Cross5c835452013-05-21 22:32:14 -07006 */
7
8#include <linux/debugfs.h>
9#include <linux/err.h>
10#include <linux/init.h>
11#include <linux/kernel.h>
12#include <linux/seq_file.h>
Rafael J. Wysockicb08e032017-07-23 00:03:43 +020013#include <linux/suspend.h>
Colin Cross5c835452013-05-21 22:32:14 -070014#include <linux/time.h>
15
Rashika Kheria64e8d202014-02-27 17:25:54 +053016#include "timekeeping_internal.h"
17
John Stultza4f8f662016-08-23 16:08:22 -070018#define NUM_BINS 32
19
20static unsigned int sleep_time_bin[NUM_BINS] = {0};
Colin Cross5c835452013-05-21 22:32:14 -070021
Yangtao Li5b20c6f2018-12-11 11:37:44 -050022static int tk_debug_sleep_time_show(struct seq_file *s, void *data)
Colin Cross5c835452013-05-21 22:32:14 -070023{
24 unsigned int bin;
25 seq_puts(s, " time (secs) count\n");
26 seq_puts(s, "------------------------------\n");
27 for (bin = 0; bin < 32; bin++) {
28 if (sleep_time_bin[bin] == 0)
29 continue;
30 seq_printf(s, "%10u - %-10u %4u\n",
31 bin ? 1 << (bin - 1) : 0, 1 << bin,
32 sleep_time_bin[bin]);
33 }
34 return 0;
35}
Yangtao Li5b20c6f2018-12-11 11:37:44 -050036DEFINE_SHOW_ATTRIBUTE(tk_debug_sleep_time);
Colin Cross5c835452013-05-21 22:32:14 -070037
38static int __init tk_debug_sleep_time_init(void)
39{
Greg Kroah-Hartmanae503ab2019-01-22 16:21:42 +010040 debugfs_create_file("sleep_time", 0444, NULL, NULL,
41 &tk_debug_sleep_time_fops);
Colin Cross5c835452013-05-21 22:32:14 -070042 return 0;
43}
44late_initcall(tk_debug_sleep_time_init);
45
Ondrej Mosnacek985e6952018-07-13 14:06:42 +020046void tk_debug_account_sleep_time(const struct timespec64 *t)
Colin Cross5c835452013-05-21 22:32:14 -070047{
John Stultza4f8f662016-08-23 16:08:22 -070048 /* Cap bin index so we don't overflow the array */
49 int bin = min(fls(t->tv_sec), NUM_BINS-1);
50
51 sleep_time_bin[bin]++;
Rafael J. Wysockicb08e032017-07-23 00:03:43 +020052 pm_deferred_pr_dbg("Timekeeping suspended for %lld.%03lu seconds\n",
53 (s64)t->tv_sec, t->tv_nsec / NSEC_PER_MSEC);
Colin Cross5c835452013-05-21 22:32:14 -070054}
55