On Thu, 2008-11-20 at 15:44 +0530, Sripathi Kodi wrote:
> Hi,
> 
> 
> The routine busy_work_us(), which is the busy work loop function in 
> realtime test suite is supposed run for as many microseconds as 
> requested for. However, I have observed that it runs too fast on some 
> hardware. I looked at the code and saw that we are statically setting 
> the loop counters, which means the duration of the busy loop varies 
> with the cpu speed. Further, the busy loop is affected by compiler 
> optimizations. On some hardware it provides only 50% of requested 
> delay, whereas with -O3, it finishes even faster.
> 
> What we need is a method to dynamically tune the delay loop based on the 
> machine where the test is being run. It should not be affected by 
> compiler optimizations as well. The following patch does that. It applies
> on the latest cvs.
> 
> Thanks,
> Sripathi.
> 
> Signed-off-by: Sripathi Kodi <[EMAIL PROTECTED]>

Thanks.

Regards--
Subrata

> Acked-by: Chirag <chirag at linux.vnet.ibm.com>
> 
> diff -uprN ltp_org/testcases/realtime/include/librttest.h 
> ltp/testcases/realtime/include/librttest.h
> --- ltp_org/testcases/realtime/include/librttest.h    2008-11-20 
> 03:58:01.000000000 -0500
> +++ ltp/testcases/realtime/include/librttest.h        2008-11-20 
> 03:58:11.000000000 -0500
> @@ -63,7 +63,8 @@ extern int optind, opterr, optopt;
>  extern char *optarg;
> 
>  #define _MAXTHREADS 256
> -#define ITERS_PER_US 12 /* appropriate for a 2393.174 MHz 64 bit CPU */
> +#define CALIBRATE_LOOPS 100000 
> +unsigned long iters_per_us;
> 
>  #define NS_PER_MS 1000000
>  #define NS_PER_US 1000
> diff -uprN ltp_org/testcases/realtime/lib/librttest.c 
> ltp/testcases/realtime/lib/librttest.c
> --- ltp_org/testcases/realtime/lib/librttest.c        2008-11-20 
> 03:58:01.000000000 -0500
> +++ ltp/testcases/realtime/lib/librttest.c    2008-11-20 03:58:11.000000000 
> -0500
> @@ -82,6 +82,21 @@ void rt_help(void)
>       printf("  -c            Set pass criteria\n");
>  }
> 
> +/* Calibrate the busy work loop */
> +void calibrate_busyloop(void)
> +{
> +     volatile int i = CALIBRATE_LOOPS;
> +     nsec_t start, end;
> +
> +     start = rt_gettime();
> +     while (--i > 0) {
> +             continue;
> +     }
> +     end = rt_gettime();
> +
> +     iters_per_us = (CALIBRATE_LOOPS * NS_PER_US) / (end-start);
> +}
> +
>  int rt_init(const char *options, int (*parse_arg)(int option, char *value), 
> int argc, char *argv[])
>  {
>       int use_buffer = 1;
> @@ -147,6 +162,8 @@ int rt_init(const char *options, int (*p
>       if (use_buffer)
>               buffer_init();
> 
> +     calibrate_busyloop();
> +
>       /*
>        * atexit() order matters here - buffer_print() will be called before
>        * buffer_fini().
> @@ -466,23 +483,18 @@ void *busy_work_ms(int ms)
> 
>  void *busy_work_us(int us)
>  {
> -     int i;
> -     int scale;
> -     double pi_scaled;
> -     double pi_value;
> +     volatile int i;
>       nsec_t start, now;
>       int delta; /* time in us */
> -     volatile double a=16, b=1.0, c=5.0, d=4, e=1.0, f=239.0;
> 
> -     scale = us * ITERS_PER_US;
> -     pi_scaled = 0;
> +     i = us * iters_per_us;
> +
>       start = rt_gettime();
> -     for (i = 0; i < scale; i++) {
> -             double pi = a*atan(b/c) - d*atan(e/f);
> -             pi_scaled += pi;
> +     while (--i > 0) {
> +             continue;
>       }
> -     pi_value = pi_scaled / scale;
>       now = rt_gettime();
> +
>       delta = (now - start)/NS_PER_US;
>       /* uncomment to tune to your machine */
>          /* printf("busy_work_us requested: %dus  actual: %dus\n", us, 
> delta); */


-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list

Reply via email to