public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* Workaround for wrapping loadaverage
@ 2004-11-08  0:19 Patrick Mau
  2004-11-08  9:27 ` Andrew Morton
  0 siblings, 1 reply; 11+ messages in thread
From: Patrick Mau @ 2004-11-08  0:19 UTC (permalink / raw)
  To: Linux Kernel

Hallo everyone,

in a previous message archived at

http://www.ussg.iu.edu/hypermail/linux/kernel/0410.2/2950.html

I described a problem with a wrapping load average on my SMP system.
The following small userspace load simulation exactly matches the
numbers I am seeing.

We can only account for 1024 runnable processes, since we have 22 bits
precision, I would like to suggest a patch to calc_load in kernel/timer.c
that would limit the number of active tasks:


if (active_tasks > 1024 * FIXED_1)
	active_tasks = 1024 * FIXED_1;


I am aware that this is not a fix ... The wrapping happens using threaded
applications (Java/JBoss in my case). Below you'll find a small userspace
simulation.

I would really like to provide a real fix, but I really couldn't figure
out what went wrong.

Thanks for any feedback,
Patrick


/* Sample code copied from include/linux/sched.h and kernel/timer.c */

#include <stdio.h>

#define FSHIFT	11		/* 11 bit precision */
#define FIXED_1	(1 << FSHIFT)	/* 1.0 as fixed-point */

#define EXP_1	1884	/* 1/exp(5sec/1min)  */
#define EXP_5	2014	/* 1/exp(5sec/5min)  */
#define EXP_15	2037	/* 1/exp(5sec/15min) */

#define CALC_LOAD(load, exp, n) \
		load *= exp; \
		load += n*(FIXED_1-exp); \
		load >>= FSHIFT;

static unsigned long avenrun[3];

/* normal load spike and one error */
static unsigned long tasks[8] = {
	0, 1, 0, ~0, 0, 0, 0
};

static void calc_load(unsigned long tasks)
{
	tasks <<= FSHIFT;

	CALC_LOAD(avenrun[0], EXP_1, tasks);
	CALC_LOAD(avenrun[1], EXP_5, tasks);
	CALC_LOAD(avenrun[2], EXP_15, tasks);
}

int main(int argc, char **argv)
{
	int i, j;

	for (i = 0; i < 8; i++) { /* index for tasks[] */
 		/* 24 calculations per load change */

		for (j = 0; j < 24; j++) {
			calc_load(tasks[i]);

			printf("%.2f %.2f %.2f\n",
				   (float) avenrun[0] / FIXED_1, 
				   (float) avenrun[1] / FIXED_1,
				   (float) avenrun[2] / FIXED_1);
		}
	}

	return 0;
}


^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2004-11-10 23:32 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-11-08  0:19 Workaround for wrapping loadaverage Patrick Mau
2004-11-08  9:27 ` Andrew Morton
2004-11-08 10:25   ` Patrick Mau
2004-11-08 23:50     ` Andrew Morton
2004-11-09  0:43       ` Patrick Mau
2004-11-09 18:51         ` Herbert Poetzl
2004-11-09 21:49           ` Con Kolivas
2004-11-10  6:20             ` Herbert Poetzl
2004-11-10  9:57               ` Con Kolivas
2004-11-10  7:07           ` Nick Piggin
2004-11-10 23:31             ` Herbert Poetzl

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox