/* Here is the program that I use: */
#define M *1000000
#include <stdio.h>
#include <sys/time.h>
#include <unistd.h>
#include <stdlib.h>
void count (int c)
{
while (c-- > 0);
}
int main (int argc, char **argv)
{
int i;
struct timeval st, et;
int c = 100 M;
int dt;
int n = 500;
int bad=1;
if (argc <= 1) {
gettimeofday (&st, NULL);
count (c);
gettimeofday (&et, NULL);
dt = (et.tv_sec - st.tv_sec) * 1000000 +
(et.tv_usec - st.tv_usec);
printf ("Counted to %d in %d us\n", c, dt);
c /= dt/8000;
printf ("That means that I can count to %d in 8ms.\n", c);
/* Next time give that number as first argument */
exit (0);
} else {
c = atoi (argv[1]);
if (argc > 2) {
n = atoi (argv[2]);
}
}
for (i=0;i<n;i++) {
count (c);
if (bad) usleep (1);
}
printf ("Counted to %d\n", c * n);
exit (0);
}
/* ----------------------- */
ozon /home/wolff> time ./testit
Counted to 100000000 in 1674492 us
That means that I can count to 478468 in 8ms.
1.680u 0.000s 0:01.68 100.0% 0+0k 0+0io 55pf+0w
ozon /home/wolff> time ./testit 478468
Counted to 239234000
0.020u 0.000s 0:05.01 0.3% 0+0k 0+0io 56pf+0w
ozon /home/wolff> time ./testit 47846800 5
Counted to 239234000
4.020u 0.000s 0:04.22 95.2% 0+0k 0+0io 56pf+0w
ozon /home/wolff> cat /proc/version
Linux version 2.2.5 (wolff@cave) (gcc version 2.7.2.1) #1 Mon Apr 12 11:19:19 MEST 1999
The "verification" run has 5 "usleeps" in it, because I'm too lazy to
multiply 478468 by 5.
So, by usleeping 500 times, the running time increases by 20%, and
the accounted running time goes from 4.02 to 0.02....
Also note that 2.2 sleeps for 2ms (incorrect?) while 2.0.x sleeps for
12 ms at a time....
I'm suggesting that Rik's new algorithm will allow this program to
grab about 80% of the CPU even if there is another CPU-hogger around.
(of course, none of this is accounted, so looking at "top" is not
going to tell you that this program is taking 80%, you have to deduce
that because it is taking 5 seconds realtime to count to 239234000...)
Roger.
-- ** R.E.Wolff@BitWizard.nl ** http://www.BitWizard.nl/ ** +31-15-2137555 ** *-- BitWizard writes Linux device drivers for any device you may have! --* ------ Microsoft SELLS you Windows, Linux GIVES you the whole house ------
- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.rutgers.edu Please read the FAQ at http://www.tux.org/lkml/