From: Con Kolivas <kernel@kolivas.org>
To: Ingo Molnar <mingo@elte.hu>
Cc: Mike Galbraith <efault@gmx.de>,
linux list <linux-kernel@vger.kernel.org>,
Andrew Morton <akpm@linux-foundation.org>,
ck list <ck@vds.kolivas.org>
Subject: Ten percent test
Date: Fri, 6 Apr 2007 11:03:33 +1000 [thread overview]
Message-ID: <200704061103.34489.kernel@kolivas.org> (raw)
In-Reply-To: <20070405115447.GA24138@elte.hu>
[-- Attachment #1: Type: text/plain, Size: 599 bytes --]
On Thursday 05 April 2007 21:54, Ingo Molnar wrote:
> - fiftyp.c: noticeable, but alot better than previously!
fiftyp.c seems to have been stumbled across by accident as having an effect
when Xenofon was trying to recreate Mike's 50% x 3 test case. I suggest a ten
percent version like the following would be more useful as a test for the
harmful effect discovered in fiftyp.c. (/me throws in obligatory code style
change).
Starts 15 processes that sleep ten times longer than they run. Change forks to
15 times the number of cpus you have and it should work on any size hardware.
--
-ck
[-- Attachment #2: tenp.c --]
[-- Type: text/x-csrc, Size: 3784 bytes --]
// gcc -O2 -o tenp tenp.c -lrt
// code from interbench.c
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <unistd.h>
#include <errno.h>
#include <sys/types.h>
/*
* Start $forks processes that run for 10% cpu time each. Set this to
* 15 * number of cpus for best effect.
*/
int forks = 15;
unsigned long run_us = 1000000000, sleep_us;
unsigned long loops_per_ms;
void terminal_error(const char *name)
{
fprintf(stderr, "\n");
perror(name);
exit (1);
}
unsigned long long get_nsecs(struct timespec *myts)
{
if (clock_gettime(CLOCK_REALTIME, myts))
terminal_error("clock_gettime");
return (myts->tv_sec * 1000000000 + myts->tv_nsec );
}
void burn_loops(unsigned long loops)
{
unsigned long i;
/*
* We need some magic here to prevent the compiler from optimising
* this loop away. Otherwise trying to emulate a fixed cpu load
* with this loop will not work.
*/
for (i = 0 ; i < loops ; i++)
asm volatile("" : : : "memory");
}
/* Use this many usecs of cpu time */
void burn_usecs(unsigned long usecs)
{
unsigned long ms_loops;
ms_loops = loops_per_ms / 1000 * usecs;
burn_loops(ms_loops);
}
void microsleep(unsigned long long usecs)
{
struct timespec req, rem;
rem.tv_sec = rem.tv_nsec = 0;
req.tv_sec = usecs / 1000000;
req.tv_nsec = (usecs - (req.tv_sec * 1000000)) * 1000;
continue_sleep:
if ((nanosleep(&req, &rem)) == -1) {
if (errno == EINTR) {
if (rem.tv_sec || rem.tv_nsec) {
req.tv_sec = rem.tv_sec;
req.tv_nsec = rem.tv_nsec;
goto continue_sleep;
}
goto out;
}
terminal_error("nanosleep");
}
out:
return;
}
/*
* In an unoptimised loop we try to benchmark how many meaningless loops
* per second we can perform on this hardware to fairly accurately
* reproduce certain percentage cpu usage
*/
void calibrate_loop(void)
{
unsigned long long start_time, loops_per_msec, run_time = 0,
min_run_us = run_us;
unsigned long loops;
struct timespec myts;
int i;
printf("Calibrating loop\n");
loops_per_msec = 1000000;
redo:
/* Calibrate to within 1% accuracy */
while (run_time > 1010000 || run_time < 990000) {
loops = loops_per_msec;
start_time = get_nsecs(&myts);
burn_loops(loops);
run_time = get_nsecs(&myts) - start_time;
loops_per_msec = (1000000 * loops_per_msec / run_time ? :
loops_per_msec);
}
/* Rechecking after a pause increases reproducibility */
microsleep(1);
loops = loops_per_msec;
start_time = get_nsecs(&myts);
burn_loops(loops);
run_time = get_nsecs(&myts) - start_time;
/* Tolerate 5% difference on checking */
if (run_time > 1050000 || run_time < 950000)
goto redo;
loops_per_ms=loops_per_msec;
printf("Calibrating sleep interval\n");
microsleep(1);
/* Find the smallest time interval close to 1ms that we can sleep */
for (i = 0; i < 100; i++) {
start_time=get_nsecs(&myts);
microsleep(1000);
run_time=get_nsecs(&myts)-start_time;
run_time /= 1000;
if (run_time < run_us && run_us > 1000)
run_us = run_time;
}
/* Then set run_us to that duration and sleep_us to 9 x that */
sleep_us = run_us * 9;
printf("Calibrating run interval\n");
microsleep(1);
/* Do a few runs to see what really gets us run_us runtime */
for (i = 0; i < 100; i++) {
start_time=get_nsecs(&myts);
burn_usecs(run_us);
run_time=get_nsecs(&myts)-start_time;
run_time /= 1000;
if (run_time < min_run_us && run_time > run_us)
min_run_us = run_time;
}
if (min_run_us < run_us)
run_us = run_us * run_us / min_run_us;
printf("Each fork will run for %lu usecs and sleep for %lu usecs\n",
run_us, sleep_us);
}
int main(void){
int i;
calibrate_loop();
printf("starting %d forks\n", forks);
for(i = 1; i < forks; i++){
if(!fork())
break;
}
while(1){
burn_usecs(run_us);
microsleep(sleep_us);
}
return 0;
}
next prev parent reply other threads:[~2007-04-06 1:04 UTC|newest]
Thread overview: 92+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-03-28 16:37 [PATCH] sched: staircase deadline misc fixes Con Kolivas
2007-03-28 17:34 ` [ck] " Prakash Punnoor
2007-04-01 6:40 ` Prakash Punnoor
[not found] ` <b14e81f00704010724i3155a16en91074ab789416f3d@mail.gmail.com>
2007-04-01 20:03 ` Prakash Punnoor
2007-03-28 18:48 ` Ingo Molnar
2007-03-28 23:44 ` Con Kolivas
2007-03-29 5:50 ` Mike Galbraith
2007-03-29 6:29 ` Mike Galbraith
2007-03-29 6:54 ` Mike Galbraith
2007-03-29 8:18 ` Mike Galbraith
2007-03-29 12:55 ` [ck] " michael chang
2007-04-03 2:35 ` Con Kolivas
2007-04-03 2:37 ` Con Kolivas
2007-04-03 5:31 ` Mike Galbraith
2007-04-03 6:00 ` Mike Galbraith
2007-04-03 6:01 ` Ingo Molnar
2007-04-03 6:11 ` Mike Galbraith
2007-04-05 11:02 ` Mike Galbraith
2007-04-05 11:09 ` Ingo Molnar
2007-04-05 11:12 ` Mike Galbraith
2007-04-05 11:15 ` Ingo Molnar
2007-04-05 13:18 ` Johannes Stezenbach
2007-04-05 15:28 ` Mike Galbraith
2007-04-05 11:54 ` [test] sched: SD-latest versus Mike's latest Ingo Molnar
2007-04-05 12:10 ` Mike Galbraith
2007-04-05 12:12 ` Ingo Molnar
2007-04-05 12:24 ` Mike Galbraith
2007-04-05 16:08 ` Con Kolivas
2007-04-05 19:05 ` Ingo Molnar
2007-04-05 20:29 ` Mike Galbraith
2007-04-06 1:03 ` Con Kolivas [this message]
2007-04-06 9:07 ` Ten percent test Mike Galbraith
2007-04-06 9:28 ` Con Kolivas
2007-04-06 10:03 ` Ingo Molnar
2007-04-06 10:40 ` Mike Galbraith
2007-04-07 6:50 ` Con Kolivas
2007-04-07 16:12 ` Gene Heskett
2007-04-07 18:08 ` Ingo Molnar
2007-04-07 18:23 ` Gene Heskett
2007-04-07 18:52 ` Ingo Molnar
2007-04-07 20:30 ` Gene Heskett
2007-04-08 10:41 ` Ingo Molnar
2007-04-08 10:58 ` Ingo Molnar
2007-04-08 17:04 ` Gene Heskett
2007-04-09 4:03 ` Mike Galbraith
2007-04-09 4:08 ` Gene Heskett
2007-04-09 5:59 ` Mike Galbraith
2007-04-09 13:01 ` Gene Heskett
2007-04-08 11:33 ` Gene Heskett
2007-04-08 11:40 ` Mike Galbraith
2007-04-08 12:02 ` Mike Galbraith
2007-04-08 17:57 ` Gene Heskett
2007-04-09 4:19 ` Mike Galbraith
2007-04-09 5:23 ` Gene Heskett
2007-04-09 6:09 ` Mike Galbraith
2007-04-08 17:56 ` Gene Heskett
2007-04-09 4:17 ` Mike Galbraith
2007-04-09 5:16 ` Gene Heskett
2007-04-09 6:06 ` Mike Galbraith
2007-04-09 8:24 ` Mike Galbraith
2007-04-08 18:51 ` Rene Herman
2007-04-09 4:23 ` Mike Galbraith
2007-04-09 12:14 ` Rene Herman
2007-04-09 13:27 ` Andreas Mohr
2007-04-09 19:54 ` Rene Herman
2007-04-09 14:15 ` Ingo Molnar
2007-04-09 17:05 ` Rene Herman
2007-04-09 17:48 ` Ingo Molnar
2007-04-09 19:09 ` Rene Herman
2007-04-09 19:56 ` Gene Heskett
2007-04-09 17:10 ` Mike Galbraith
2007-04-09 13:53 ` Ingo Molnar
2007-04-09 15:37 ` Rene Herman
2007-04-07 19:14 ` Mike Galbraith
2007-04-07 20:31 ` Gene Heskett
2007-04-09 17:51 ` William Lee Irwin III
2007-04-09 18:03 ` Ingo Molnar
2007-04-09 18:44 ` William Lee Irwin III
2007-04-07 16:32 ` Mike Galbraith
2007-04-08 13:08 ` Ed Tomlinson
2007-04-09 5:38 ` Mike Galbraith
2007-04-09 11:26 ` Ed Tomlinson
2007-04-09 16:50 ` Mike Galbraith
2007-04-22 10:48 ` [ck] " Martin Steigerwald
2007-04-22 11:15 ` Con Kolivas
2007-04-10 2:39 ` Mike Galbraith
2007-04-10 11:23 ` Ed Tomlinson
2007-04-10 12:04 ` Mike Galbraith
2007-04-06 10:48 ` Mike Galbraith
2007-04-03 10:57 ` [PATCH] sched: staircase deadline misc fixes Mike Galbraith
2007-03-29 6:36 ` Con Kolivas
2007-04-23 8:58 ` Andrew Morton
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=200704061103.34489.kernel@kolivas.org \
--to=kernel@kolivas.org \
--cc=akpm@linux-foundation.org \
--cc=ck@vds.kolivas.org \
--cc=efault@gmx.de \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@elte.hu \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox