LCOV - code coverage report
Current view: top level - kernel/time - timekeeping_debug.c (source / functions) Hit Total Coverage
Test: landlock.info Lines: 3 19 15.8 %
Date: 2021-04-22 12:43:58 Functions: 1 4 25.0 %

          Line data    Source code
       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             : static unsigned int sleep_time_bin[NUM_BINS] = {0};
      21             : 
      22           0 : static int tk_debug_sleep_time_show(struct seq_file *s, void *data)
      23             : {
      24           0 :         unsigned int bin;
      25           0 :         seq_puts(s, "      time (secs)        count\n");
      26           0 :         seq_puts(s, "------------------------------\n");
      27           0 :         for (bin = 0; bin < 32; bin++) {
      28           0 :                 if (sleep_time_bin[bin] == 0)
      29           0 :                         continue;
      30           0 :                 seq_printf(s, "%10u - %-10u %4u\n",
      31           0 :                         bin ? 1 << (bin - 1) : 0, 1 << bin,
      32             :                                 sleep_time_bin[bin]);
      33             :         }
      34           0 :         return 0;
      35             : }
      36           0 : DEFINE_SHOW_ATTRIBUTE(tk_debug_sleep_time);
      37             : 
      38           1 : static int __init tk_debug_sleep_time_init(void)
      39             : {
      40           1 :         debugfs_create_file("sleep_time", 0444, NULL, NULL,
      41             :                             &tk_debug_sleep_time_fops);
      42           1 :         return 0;
      43             : }
      44             : late_initcall(tk_debug_sleep_time_init);
      45             : 
      46           0 : void tk_debug_account_sleep_time(const struct timespec64 *t)
      47             : {
      48             :         /* Cap bin index so we don't overflow the array */
      49           0 :         int bin = min(fls(t->tv_sec), NUM_BINS-1);
      50             : 
      51           0 :         sleep_time_bin[bin]++;
      52           0 :         pm_deferred_pr_dbg("Timekeeping suspended for %lld.%03lu seconds\n",
      53             :                            (s64)t->tv_sec, t->tv_nsec / NSEC_PER_MSEC);
      54           0 : }
      55             : 

Generated by: LCOV version 1.14