Hi!
> +void *thread_fn(void *val)
> +{
> +     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);
> +
> +     do {
> +             for (i = 1; i < 1000; ++i)
> +                     res += i * i;
> +             gettimeofday(&tv_end, NULL);

One more thing, you should probably add sched_yield() here to make sure
the load_cpu() is executed after the sleep() has finished.

> +     } while ((tv_end.tv_sec - tv_start.tv_sec) < timeout);
> +
> +     tst_resm(TINFO, "CPU0 load done: insignificant value '%d'", res);
> +
> +     return NULL;
> +}
> +
> +static int load_cpu(intptr_t timeout)
> +{
> +     pthread_t thread_id;
> +
> +     if (pthread_create(&thread_id, 0, thread_fn,
> +             (intptr_t *) timeout) != 0) {
> +             tst_brkm(TBROK | TERRNO, cleanup,
> +                     "pthread_create failed at %s:%d",
> +                     __FILE__, __LINE__);
> +     }
> +
> +     sleep(2 * timeout / 3);
> +
> +     int cur_freq;
> +     SAFE_FILE_SCANF(cleanup, curspeed, "%d", &cur_freq);
> +     tst_resm(TINFO, "got cpu freq under load: %d", cur_freq);
> +
> +     pthread_join(thread_id, NULL);
> +
> +     return cur_freq;
> +}

-- 
Cyril Hrubis
[email protected]

------------------------------------------------------------------------------
DreamFactory - Open Source REST & JSON Services for HTML5 & Native Apps
OAuth, Users, Roles, SQL, NoSQL, BLOB Storage and External API Access
Free app hosting. Or install the open source package on any LAMP server.
Sign up and see examples for AngularJS, jQuery, Sencha Touch and Native!
http://pubads.g.doubleclick.net/gampad/clk?id=63469471&iu=/4140/ostg.clktrk
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list

Reply via email to