[RFC][PATCH 4/4] sched: Add debugfs/sched/deadline_bw file to show current bandwidths

From: Steven Rostedt
Date: Mon Feb 01 2016 - 15:32:49 EST


From: "Steven Rostedt (Red Hat)" <rostedt@xxxxxxxxxxx>

Add a /sys/kernel/debug/sched directory and place a deadline_bw file there
that shows the current bandwidths of the CPUs for SCHED_DEADLINE tasks.

# cat /sys/kernel/debug/sched/deadline_bw
CPU[0]:
bw: 996147
total_bw: 0
CPU[1]:
bw: 996147
total_bw: 0
CPU[2]:
bw: 996147
total_bw: 0
CPU[3]:
bw: 996147
total_bw: 0
CPU[4]:
bw: 996147
total_bw: 0
CPU[5]:
bw: 996147
total_bw: 0
CPU[6]:
bw: 996147
total_bw: 0
CPU[7]:
bw: 996147
total_bw: 0

Signed-off-by: Steven Rostedt <rostedt@xxxxxxxxxxx>
---
kernel/sched/debug.c | 100 +++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 100 insertions(+)

diff --git a/kernel/sched/debug.c b/kernel/sched/debug.c
index 68838495624f..a6ce364ba9b9 100644
--- a/kernel/sched/debug.c
+++ b/kernel/sched/debug.c
@@ -1070,3 +1070,103 @@ void proc_sched_set_task(struct task_struct *p)
memset(&p->se.statistics, 0, sizeof(p->se.statistics));
#endif
}
+
+#ifdef CONFIG_DEBUG_FS
+
+
+static void *dl_next(struct seq_file *m, void *v, loff_t *pos)
+{
+ long cpu = (long)v;
+
+ /* to keep from returning zero, v is always cpu + 1 */
+ cpu--;
+ cpu = cpumask_next(cpu, cpu_possible_mask);
+
+ (*pos)++;
+
+ if (cpu >= num_possible_cpus())
+ cpu = 0;
+ else
+ cpu++;
+
+ return (void *)cpu;
+}
+
+static void *dl_start(struct seq_file *m, loff_t *pos)
+{
+ long cpu = 1;
+ loff_t l = 0;
+
+ for (; cpu && l < *pos; cpu = (long)dl_next(m, (void *)cpu, &l))
+ ;
+ return (void *)cpu;
+}
+
+static void dl_stop(struct seq_file *m, void *p)
+{
+}
+
+static int dl_show(struct seq_file *m, void *v)
+{
+ struct rq *rq;
+ long cpu = (long)v;
+ struct dl_bw *dl_bw;
+
+ if (!cpu)
+ return 0;
+
+ /* to keep from returning zero, v is always cpu + 1 */
+ cpu--;
+ rq = cpu_rq(cpu);
+ raw_spin_lock_irq(&rq->lock);
+#ifdef CONFIG_SMP
+ dl_bw = &rq->rd->dl_bw;
+#else
+ dl_bw = &rq->dl.dl_bw;
+#endif
+ seq_printf(m, "CPU[%ld]:\n", cpu);
+ seq_printf(m, " bw: %lld\n", dl_bw->bw);
+ seq_printf(m, " total_bw: %lld\n", dl_bw->total_bw);
+ raw_spin_unlock_irq(&rq->lock);
+
+ return 0;
+}
+
+static const struct seq_operations deadline_bw_seq_ops = {
+ .start = dl_start,
+ .next = dl_next,
+ .stop = dl_stop,
+ .show = dl_show,
+};
+
+static int deadline_bw_open(struct inode *inode, struct file *file)
+{
+ int ret;
+
+ ret = seq_open(file, &deadline_bw_seq_ops);
+ return ret;
+}
+
+static const struct file_operations deadline_bw_fops = {
+ .open = deadline_bw_open,
+ .read = seq_read,
+ .llseek = no_llseek,
+};
+
+static struct dentry *sched_debugfs;
+
+static __init int sched_init_debugfs(void)
+{
+ sched_debugfs = debugfs_create_dir("sched", NULL);
+
+ if (WARN_ON(!sched_debugfs)) {
+ return 0;
+ }
+
+ debugfs_create_file("deadline_bw", 0444, sched_debugfs, NULL,
+ &deadline_bw_fops);
+ return 0;
+}
+fs_initcall(sched_init_debugfs);
+
+#endif /*CONFIG_DEBUG_FS */
--
2.6.4