Linux 6.9-rc4
[sfrench/cifs-2.6.git] / kernel / latencytop.c
index 871734ea2f045a5ec7787c6d27d4951118c74df9..781249098cb6e729b77b81658c217097085e6eb6 100644 (file)
@@ -1,13 +1,9 @@
+// SPDX-License-Identifier: GPL-2.0-only
 /*
  * latencytop.c: Latency display infrastructure
  *
  * (C) Copyright 2008 Intel Corporation
  * Author: Arjan van de Ven <arjan@linux.intel.com>
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; version 2
- * of the License.
  */
 
 /*
@@ -59,6 +55,7 @@
 #include <linux/sched/stat.h>
 #include <linux/list.h>
 #include <linux/stacktrace.h>
+#include <linux/sysctl.h>
 
 static DEFINE_RAW_SPINLOCK(latency_lock);
 
@@ -67,6 +64,31 @@ static struct latency_record latency_record[MAXLR];
 
 int latencytop_enabled;
 
+#ifdef CONFIG_SYSCTL
+static int sysctl_latencytop(struct ctl_table *table, int write, void *buffer,
+               size_t *lenp, loff_t *ppos)
+{
+       int err;
+
+       err = proc_dointvec(table, write, buffer, lenp, ppos);
+       if (latencytop_enabled)
+               force_schedstat_enabled();
+
+       return err;
+}
+
+static struct ctl_table latencytop_sysctl[] = {
+       {
+               .procname   = "latencytop",
+               .data       = &latencytop_enabled,
+               .maxlen     = sizeof(int),
+               .mode       = 0644,
+               .proc_handler   = sysctl_latencytop,
+       },
+       {}
+};
+#endif
+
 void clear_tsk_latency_tracing(struct task_struct *p)
 {
        unsigned long flags;
@@ -90,7 +112,7 @@ static void __sched
 account_global_scheduler_latency(struct task_struct *tsk,
                                 struct latency_record *lat)
 {
-       int firstnonnull = MAXLR + 1;
+       int firstnonnull = MAXLR;
        int i;
 
        /* skip kernel threads for now */
@@ -128,7 +150,7 @@ account_global_scheduler_latency(struct task_struct *tsk,
        }
 
        i = firstnonnull;
-       if (i >= MAXLR - 1)
+       if (i >= MAXLR)
                return;
 
        /* Allocted a new one: */
@@ -259,29 +281,20 @@ static int lstats_open(struct inode *inode, struct file *filp)
        return single_open(filp, lstats_show, NULL);
 }
 
-static const struct file_operations lstats_fops = {
-       .open           = lstats_open,
-       .read           = seq_read,
-       .write          = lstats_write,
-       .llseek         = seq_lseek,
-       .release        = single_release,
+static const struct proc_ops lstats_proc_ops = {
+       .proc_open      = lstats_open,
+       .proc_read      = seq_read,
+       .proc_write     = lstats_write,
+       .proc_lseek     = seq_lseek,
+       .proc_release   = single_release,
 };
 
 static int __init init_lstats_procfs(void)
 {
-       proc_create("latency_stats", 0644, NULL, &lstats_fops);
+       proc_create("latency_stats", 0644, NULL, &lstats_proc_ops);
+#ifdef CONFIG_SYSCTL
+       register_sysctl_init("kernel", latencytop_sysctl);
+#endif
        return 0;
 }
-
-int sysctl_latencytop(struct ctl_table *table, int write,
-                       void __user *buffer, size_t *lenp, loff_t *ppos)
-{
-       int err;
-
-       err = proc_dointvec(table, write, buffer, lenp, ppos);
-       if (latencytop_enabled)
-               force_schedstat_enabled();
-
-       return err;
-}
 device_initcall(init_lstats_procfs);