Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1) // SPDX-License-Identifier: GPL-2.0+
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3)  * debugfs file to track time spent in suspend
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5)  * Copyright (c) 2011, Google, Inc.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8) #include <linux/debugfs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9) #include <linux/err.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <linux/seq_file.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <linux/suspend.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <linux/time.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include "timekeeping_internal.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #define NUM_BINS 32
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) static unsigned int sleep_time_bin[NUM_BINS] = {0};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) static int tk_debug_sleep_time_show(struct seq_file *s, void *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) 	unsigned int bin;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) 	seq_puts(s, "      time (secs)        count\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) 	seq_puts(s, "------------------------------\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) 	for (bin = 0; bin < 32; bin++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) 		if (sleep_time_bin[bin] == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) 		seq_printf(s, "%10u - %-10u %4u\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) 			bin ? 1 << (bin - 1) : 0, 1 << bin,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) 				sleep_time_bin[bin]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) DEFINE_SHOW_ATTRIBUTE(tk_debug_sleep_time);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) static int __init tk_debug_sleep_time_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) 	debugfs_create_file("sleep_time", 0444, NULL, NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) 			    &tk_debug_sleep_time_fops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) late_initcall(tk_debug_sleep_time_init);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) void tk_debug_account_sleep_time(const struct timespec64 *t)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) 	/* Cap bin index so we don't overflow the array */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) 	int bin = min(fls(t->tv_sec), NUM_BINS-1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) 	sleep_time_bin[bin]++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) 	pm_deferred_pr_dbg("Timekeeping suspended for %lld.%03lu seconds\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) 			   (s64)t->tv_sec, t->tv_nsec / NSEC_PER_MSEC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55)