1 // SPDX-License-Identifier: GPL-2.0+
3 * debugfs file to track time spent in suspend
5 * Copyright (c) 2011, Google, Inc.
8 #include <linux/debugfs.h>
10 #include <linux/init.h>
11 #include <linux/kernel.h>
12 #include <linux/seq_file.h>
13 #include <linux/suspend.h>
14 #include <linux/time.h>
16 #include "timekeeping_internal.h"
20 static unsigned int sleep_time_bin
[NUM_BINS
] = {0};
22 static int tk_debug_sleep_time_show(struct seq_file
*s
, void *data
)
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)
30 seq_printf(s
, "%10u - %-10u %4u\n",
31 bin
? 1 << (bin
- 1) : 0, 1 << bin
,
36 DEFINE_SHOW_ATTRIBUTE(tk_debug_sleep_time
);
38 static int __init
tk_debug_sleep_time_init(void)
42 d
= debugfs_create_file("sleep_time", 0444, NULL
, NULL
,
43 &tk_debug_sleep_time_fops
);
45 pr_err("Failed to create sleep_time debug file\n");
51 late_initcall(tk_debug_sleep_time_init
);
53 void tk_debug_account_sleep_time(const struct timespec64
*t
)
55 /* Cap bin index so we don't overflow the array */
56 int bin
= min(fls(t
->tv_sec
), NUM_BINS
-1);
58 sleep_time_bin
[bin
]++;
59 pm_deferred_pr_dbg("Timekeeping suspended for %lld.%03lu seconds\n",
60 (s64
)t
->tv_sec
, t
->tv_nsec
/ NSEC_PER_MSEC
);