Commit 2d02494f authored by Thomas Gleixner's avatar Thomas Gleixner

sched, timers: cleanup avenrun users

avenrun is an rough estimate so we don't have to worry about
consistency of the three avenrun values. Remove the xtime lock
dependency and provide a function to scale the values. Cleanup the
users.

[ Impact: cleanup ]
Signed-off-by: default avatarThomas Gleixner <tglx@linutronix.de>
Acked-by: default avatarPeter Zijlstra <peterz@infradead.org>
parent dce48a84
...@@ -12,20 +12,14 @@ ...@@ -12,20 +12,14 @@
static int loadavg_proc_show(struct seq_file *m, void *v) static int loadavg_proc_show(struct seq_file *m, void *v)
{ {
int a, b, c; unsigned long avnrun[3];
unsigned long seq;
do { get_avenrun(avnrun, FIXED_1/200, 0);
seq = read_seqbegin(&xtime_lock);
a = avenrun[0] + (FIXED_1/200);
b = avenrun[1] + (FIXED_1/200);
c = avenrun[2] + (FIXED_1/200);
} while (read_seqretry(&xtime_lock, seq));
seq_printf(m, "%d.%02d %d.%02d %d.%02d %ld/%d %d\n", seq_printf(m, "%lu.%02lu %lu.%02lu %lu.%02lu %ld/%d %d\n",
LOAD_INT(a), LOAD_FRAC(a), LOAD_INT(avnrun[0]), LOAD_FRAC(avnrun[0]),
LOAD_INT(b), LOAD_FRAC(b), LOAD_INT(avnrun[1]), LOAD_FRAC(avnrun[1]),
LOAD_INT(c), LOAD_FRAC(c), LOAD_INT(avnrun[2]), LOAD_FRAC(avnrun[2]),
nr_running(), nr_threads, nr_running(), nr_threads,
task_active_pid_ns(current)->last_pid); task_active_pid_ns(current)->last_pid);
return 0; return 0;
......
...@@ -116,6 +116,7 @@ struct fs_struct; ...@@ -116,6 +116,7 @@ struct fs_struct;
* 11 bit fractions. * 11 bit fractions.
*/ */
extern unsigned long avenrun[]; /* Load averages */ extern unsigned long avenrun[]; /* Load averages */
extern void get_avenrun(unsigned long *loads, unsigned long offset, int shift);
#define FSHIFT 11 /* nr of bits of precision */ #define FSHIFT 11 /* nr of bits of precision */
#define FIXED_1 (1<<FSHIFT) /* 1.0 as fixed-point */ #define FIXED_1 (1<<FSHIFT) /* 1.0 as fixed-point */
......
...@@ -2868,6 +2868,21 @@ static unsigned long calc_load_update; ...@@ -2868,6 +2868,21 @@ static unsigned long calc_load_update;
unsigned long avenrun[3]; unsigned long avenrun[3];
EXPORT_SYMBOL(avenrun); EXPORT_SYMBOL(avenrun);
/**
* get_avenrun - get the load average array
* @loads: pointer to dest load array
* @offset: offset to add
* @shift: shift count to shift the result left
*
* These values are estimates at best, so no need for locking.
*/
void get_avenrun(unsigned long *loads, unsigned long offset, int shift)
{
loads[0] = (avenrun[0] + offset) << shift;
loads[1] = (avenrun[1] + offset) << shift;
loads[2] = (avenrun[2] + offset) << shift;
}
static unsigned long static unsigned long
calc_load(unsigned long load, unsigned long exp, unsigned long active) calc_load(unsigned long load, unsigned long exp, unsigned long active)
{ {
......
...@@ -1356,37 +1356,17 @@ int do_sysinfo(struct sysinfo *info) ...@@ -1356,37 +1356,17 @@ int do_sysinfo(struct sysinfo *info)
{ {
unsigned long mem_total, sav_total; unsigned long mem_total, sav_total;
unsigned int mem_unit, bitcount; unsigned int mem_unit, bitcount;
unsigned long seq;
memset(info, 0, sizeof(struct sysinfo));
do {
struct timespec tp; struct timespec tp;
seq = read_seqbegin(&xtime_lock);
/* memset(info, 0, sizeof(struct sysinfo));
* This is annoying. The below is the same thing
* posix_get_clock_monotonic() does, but it wants to
* take the lock which we want to cover the loads stuff
* too.
*/
getnstimeofday(&tp); ktime_get_ts(&tp);
tp.tv_sec += wall_to_monotonic.tv_sec;
tp.tv_nsec += wall_to_monotonic.tv_nsec;
monotonic_to_bootbased(&tp); monotonic_to_bootbased(&tp);
if (tp.tv_nsec - NSEC_PER_SEC >= 0) {
tp.tv_nsec = tp.tv_nsec - NSEC_PER_SEC;
tp.tv_sec++;
}
info->uptime = tp.tv_sec + (tp.tv_nsec ? 1 : 0); info->uptime = tp.tv_sec + (tp.tv_nsec ? 1 : 0);
info->loads[0] = avenrun[0] << (SI_LOAD_SHIFT - FSHIFT); get_avenrun(info->loads, 0, SI_LOAD_SHIFT - FSHIFT);
info->loads[1] = avenrun[1] << (SI_LOAD_SHIFT - FSHIFT);
info->loads[2] = avenrun[2] << (SI_LOAD_SHIFT - FSHIFT);
info->procs = nr_threads; info->procs = nr_threads;
} while (read_seqretry(&xtime_lock, seq));
si_meminfo(info); si_meminfo(info);
si_swapinfo(info); si_swapinfo(info);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment