]>
Commit | Line | Data |
---|---|---|
35728b82 | 1 | // SPDX-License-Identifier: GPL-2.0+ |
5c83545f CC |
2 | /* |
3 | * debugfs file to track time spent in suspend | |
4 | * | |
5 | * Copyright (c) 2011, Google, Inc. | |
5c83545f CC |
6 | */ |
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> | |
cb08e035 | 13 | #include <linux/suspend.h> |
5c83545f CC |
14 | #include <linux/time.h> |
15 | ||
64e8d20b RK |
16 | #include "timekeeping_internal.h" |
17 | ||
a4f8f666 JS |
18 | #define NUM_BINS 32 |
19 | ||
2a153857 JL |
20 | /* Incremented every time mg_floor is updated */ |
21 | DEFINE_PER_CPU(unsigned long, timekeeping_mg_floor_swaps); | |
22 | ||
a4f8f666 | 23 | static unsigned int sleep_time_bin[NUM_BINS] = {0}; |
5c83545f | 24 | |
5b20c6fd | 25 | static int tk_debug_sleep_time_show(struct seq_file *s, void *data) |
5c83545f CC |
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 | } | |
5b20c6fd | 39 | DEFINE_SHOW_ATTRIBUTE(tk_debug_sleep_time); |
5c83545f CC |
40 | |
41 | static int __init tk_debug_sleep_time_init(void) | |
42 | { | |
ae503ab0 GKH |
43 | debugfs_create_file("sleep_time", 0444, NULL, NULL, |
44 | &tk_debug_sleep_time_fops); | |
5c83545f CC |
45 | return 0; |
46 | } | |
47 | late_initcall(tk_debug_sleep_time_init); | |
48 | ||
985e6950 | 49 | void tk_debug_account_sleep_time(const struct timespec64 *t) |
5c83545f | 50 | { |
a4f8f666 JS |
51 | /* Cap bin index so we don't overflow the array */ |
52 | int bin = min(fls(t->tv_sec), NUM_BINS-1); | |
53 | ||
54 | sleep_time_bin[bin]++; | |
cb08e035 RW |
55 | pm_deferred_pr_dbg("Timekeeping suspended for %lld.%03lu seconds\n", |
56 | (s64)t->tv_sec, t->tv_nsec / NSEC_PER_MSEC); | |
5c83545f CC |
57 | } |
58 | ||
2a153857 JL |
59 | unsigned long timekeeping_get_mg_floor_swaps(void) |
60 | { | |
61 | unsigned long sum = 0; | |
62 | int cpu; | |
63 | ||
64 | for_each_possible_cpu(cpu) | |
65 | sum += data_race(per_cpu(timekeeping_mg_floor_swaps, cpu)); | |
66 | ||
67 | return sum; | |
68 | } |