Hi!
> -void *thread_fn(void *val)
> +static int load_cpu(int max_freq_khz)
>  {
> -     struct timeval tv_start;
> -     struct timeval tv_end;
> -     int i, res = 0;
> -     intptr_t timeout = (intptr_t) val;
> -
> -     gettimeofday(&tv_start, NULL);
> -     tst_resm(TINFO, "load CPU0 for %ld sec...", timeout);
> +     int sum = 0, i = 0, total_time_ms;
> +     struct timespec tv_start, tv_end;
>  
> -     do {
> -             for (i = 1; i < 10000; ++i)
> -                     res += i * i;
> -             gettimeofday(&tv_end, NULL);
> -             sched_yield();
> -     } while ((tv_end.tv_sec - tv_start.tv_sec) < timeout);
> -
> -     tst_resm(TINFO, "CPU0 load done: insignificant value '%d'", res);
> +     const int max_sum = max_freq_khz / 1000;
> +     const int units = 1000000; /* Mhz */
>  
> -     return NULL;
> -}
> +     clock_gettime(CLOCK_MONOTONIC_RAW, &tv_start);
>  
> -static int load_cpu(intptr_t timeout)
> -{
> -     pthread_t thread_id;
> +     do {
> +             for (i = 0; i < units; ++i)
> +                     asm ("" : : : "memory");
> +     } while (++sum < max_sum);
>  
> -     if (pthread_create(&thread_id, 0, thread_fn,
> -             (void *) timeout) != 0) {
> -             tst_brkm(TBROK | TERRNO, cleanup,
> -                     "pthread_create failed at %s:%d",
> -                     __FILE__, __LINE__);
> -     }
> +     clock_gettime(CLOCK_MONOTONIC_RAW, &tv_end);
>  
> -     sleep(2 * timeout / 3);
> +     total_time_ms = (tv_end.tv_sec - tv_start.tv_sec) * 1000 +
> +             (tv_end.tv_nsec - tv_start.tv_nsec) / 1000000;
>  
> -     int cur_freq;
> -     SAFE_FILE_SCANF(cleanup, curspeed, "%d", &cur_freq);
> -     tst_resm(TINFO, "got cpu freq under load: %d", cur_freq);
> +     if (!total_time_ms)
> +             tst_brkm(TBROK, cleanup, "can't calc freq, time period is 0");
>  
> -     pthread_join(thread_id, NULL);
> +     tst_resm(TINFO, "elapsed time is %d ms", total_time_ms);
>  
> -     return cur_freq;
> +     return sum * 1000 / total_time_ms;

Is this conversion really necessary? I guess that we can also return
the elapsed time here and test that the time is shorted by a few
percents with boost enabled in the test_run() function.

Otherwise it looks good.

-- 
Cyril Hrubis
chru...@suse.cz

------------------------------------------------------------------------------
Comprehensive Server Monitoring with Site24x7.
Monitor 10 servers for $9/Month.
Get alerted through email, SMS, voice calls or mobile push notifications.
Take corrective actions from your mobile device.
http://pubads.g.doubleclick.net/gampad/clk?id=154624111&iu=/4140/ostg.clktrk
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

Reply via email to