Linux Audio

Check our new training course

Loading...
v4.6
 
 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/time.h>
23
24#include "timekeeping_internal.h"
25
26static unsigned int sleep_time_bin[32] = {0};
 
 
 
 
 
27
28static int tk_debug_show_sleep_time(struct seq_file *s, void *data)
29{
30	unsigned int bin;
31	seq_puts(s, "      time (secs)        count\n");
32	seq_puts(s, "------------------------------\n");
33	for (bin = 0; bin < 32; bin++) {
34		if (sleep_time_bin[bin] == 0)
35			continue;
36		seq_printf(s, "%10u - %-10u %4u\n",
37			bin ? 1 << (bin - 1) : 0, 1 << bin,
38				sleep_time_bin[bin]);
39	}
40	return 0;
41}
42
43static int tk_debug_sleep_time_open(struct inode *inode, struct file *file)
44{
45	return single_open(file, tk_debug_show_sleep_time, NULL);
46}
47
48static const struct file_operations tk_debug_sleep_time_fops = {
49	.open		= tk_debug_sleep_time_open,
50	.read		= seq_read,
51	.llseek		= seq_lseek,
52	.release	= single_release,
53};
54
55static int __init tk_debug_sleep_time_init(void)
56{
57	struct dentry *d;
58
59	d = debugfs_create_file("sleep_time", 0444, NULL, NULL,
60		&tk_debug_sleep_time_fops);
61	if (!d) {
62		pr_err("Failed to create sleep_time debug file\n");
63		return -ENOMEM;
64	}
65
66	return 0;
67}
68late_initcall(tk_debug_sleep_time_init);
69
70void tk_debug_account_sleep_time(struct timespec64 *t)
71{
72	sleep_time_bin[fls(t->tv_sec)]++;
 
 
 
 
 
73}
74
v6.13.7
 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
20/* Incremented every time mg_floor is updated */
21DEFINE_PER_CPU(unsigned long, timekeeping_mg_floor_swaps);
22
23static unsigned int sleep_time_bin[NUM_BINS] = {0};
24
25static int tk_debug_sleep_time_show(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}
39DEFINE_SHOW_ATTRIBUTE(tk_debug_sleep_time);
 
 
 
 
 
 
 
 
 
 
 
40
41static int __init tk_debug_sleep_time_init(void)
42{
43	debugfs_create_file("sleep_time", 0444, NULL, NULL,
44			    &tk_debug_sleep_time_fops);
 
 
 
 
 
 
 
45	return 0;
46}
47late_initcall(tk_debug_sleep_time_init);
48
49void tk_debug_account_sleep_time(const struct timespec64 *t)
50{
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]++;
55	pm_deferred_pr_dbg("Timekeeping suspended for %lld.%03lu seconds\n",
56			   (s64)t->tv_sec, t->tv_nsec / NSEC_PER_MSEC);
57}
58
59unsigned 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}