Linux Audio

Check our new training course

Loading...
v6.2
 1// SPDX-License-Identifier: GPL-2.0+
 2/*
 3 * debugfs file to track time spent in suspend
 4 *
 5 * Copyright (c) 2011, Google, Inc.
 
 
 
 
 
 
 
 
 
 
 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>
13#include <linux/suspend.h>
14#include <linux/time.h>
15
16#include "timekeeping_internal.h"
17
18#define NUM_BINS 32
19
20static unsigned int sleep_time_bin[NUM_BINS] = {0};
21
22static int tk_debug_sleep_time_show(struct seq_file *s, void *data)
23{
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}
36DEFINE_SHOW_ATTRIBUTE(tk_debug_sleep_time);
 
 
 
 
 
 
 
 
 
 
 
37
38static int __init tk_debug_sleep_time_init(void)
39{
40	debugfs_create_file("sleep_time", 0444, NULL, NULL,
41			    &tk_debug_sleep_time_fops);
 
 
 
 
 
 
 
42	return 0;
43}
44late_initcall(tk_debug_sleep_time_init);
45
46void tk_debug_account_sleep_time(const struct timespec64 *t)
47{
48	/* 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]++;
52	pm_deferred_pr_dbg("Timekeeping suspended for %lld.%03lu seconds\n",
53			   (s64)t->tv_sec, t->tv_nsec / NSEC_PER_MSEC);
54}
55
v4.17
 
 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
17#include <linux/debugfs.h>
18#include <linux/err.h>
19#include <linux/init.h>
20#include <linux/kernel.h>
21#include <linux/seq_file.h>
22#include <linux/suspend.h>
23#include <linux/time.h>
24
25#include "timekeeping_internal.h"
26
27#define NUM_BINS 32
28
29static unsigned int sleep_time_bin[NUM_BINS] = {0};
30
31static int tk_debug_show_sleep_time(struct seq_file *s, void *data)
32{
33	unsigned int bin;
34	seq_puts(s, "      time (secs)        count\n");
35	seq_puts(s, "------------------------------\n");
36	for (bin = 0; bin < 32; bin++) {
37		if (sleep_time_bin[bin] == 0)
38			continue;
39		seq_printf(s, "%10u - %-10u %4u\n",
40			bin ? 1 << (bin - 1) : 0, 1 << bin,
41				sleep_time_bin[bin]);
42	}
43	return 0;
44}
45
46static int tk_debug_sleep_time_open(struct inode *inode, struct file *file)
47{
48	return single_open(file, tk_debug_show_sleep_time, NULL);
49}
50
51static const struct file_operations tk_debug_sleep_time_fops = {
52	.open		= tk_debug_sleep_time_open,
53	.read		= seq_read,
54	.llseek		= seq_lseek,
55	.release	= single_release,
56};
57
58static int __init tk_debug_sleep_time_init(void)
59{
60	struct dentry *d;
61
62	d = debugfs_create_file("sleep_time", 0444, NULL, NULL,
63		&tk_debug_sleep_time_fops);
64	if (!d) {
65		pr_err("Failed to create sleep_time debug file\n");
66		return -ENOMEM;
67	}
68
69	return 0;
70}
71late_initcall(tk_debug_sleep_time_init);
72
73void tk_debug_account_sleep_time(struct timespec64 *t)
74{
75	/* Cap bin index so we don't overflow the array */
76	int bin = min(fls(t->tv_sec), NUM_BINS-1);
77
78	sleep_time_bin[bin]++;
79	pm_deferred_pr_dbg("Timekeeping suspended for %lld.%03lu seconds\n",
80			   (s64)t->tv_sec, t->tv_nsec / NSEC_PER_MSEC);
81}
82