Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0
0002 #include <linux/fs.h>
0003 #include <linux/init.h>
0004 #include <linux/pid_namespace.h>
0005 #include <linux/proc_fs.h>
0006 #include <linux/sched.h>
0007 #include <linux/sched/loadavg.h>
0008 #include <linux/sched/stat.h>
0009 #include <linux/seq_file.h>
0010 #include <linux/seqlock.h>
0011 #include <linux/time.h>
0012 
0013 static int loadavg_proc_show(struct seq_file *m, void *v)
0014 {
0015     unsigned long avnrun[3];
0016 
0017     get_avenrun(avnrun, FIXED_1/200, 0);
0018 
0019     seq_printf(m, "%lu.%02lu %lu.%02lu %lu.%02lu %u/%d %d\n",
0020         LOAD_INT(avnrun[0]), LOAD_FRAC(avnrun[0]),
0021         LOAD_INT(avnrun[1]), LOAD_FRAC(avnrun[1]),
0022         LOAD_INT(avnrun[2]), LOAD_FRAC(avnrun[2]),
0023         nr_running(), nr_threads,
0024         idr_get_cursor(&task_active_pid_ns(current)->idr) - 1);
0025     return 0;
0026 }
0027 
0028 static int __init proc_loadavg_init(void)
0029 {
0030     proc_create_single("loadavg", 0, NULL, loadavg_proc_show);
0031     return 0;
0032 }
0033 fs_initcall(proc_loadavg_init);