RE: [PATCH] sched: Folding nohz load accounting more accurate

From: Peter Zijlstra
Date: Mon Jun 18 2012 - 06:13:22 EST


On Wed, 2012-06-13 at 20:13 -0700, Doug Smythies wrote:
> ./waiter 2 900 345912 9444

So we're all simply just trying to burn a particular amount of cpu-time?

I have a little consume.c thing lying about doing something like that.
Its independent of clockspeed, but doesn't really like preemption much,
but it more or less works ;-)

---
#include <sys/time.h>
#include <unistd.h>
#include <stdio.h>

unsigned long long stamp(void)
{
struct timeval tv;

gettimeofday(&tv, NULL);

return (unsigned long long)tv.tv_sec * 1000000 + tv.tv_usec;
}

void consume(int spin, int total)
{
unsigned long long begin, now;

begin = stamp();

for (;;) {
now = stamp();
if ((long long)(now - begin) > spin) {
usleep(total - spin);
begin += total;
}
}
}

int main(int argc, char **argv)
{
int period = 100000; /* 100ms */
int frac;

if (argc < 2) {
fprintf(stderr, "%s <frac> [<period>]\n"
" frac -- [1-100] %% of time to burn\n"
" period -- [usec] period of burn/sleep cycle\n",
argv[0]);
return -1;
}

frac = atoi(argv[1]);
if (argc > 2)
period = atoi(argv[2]);

if (frac > 100)
frac = 100;

if (frac < 1)
frac = 1;

consume((period * frac) / 100, period);

return 0;
}

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/