From: Cyril Hrubis <chrubis@suse.cz>
To: Alexey Kodanev <alexey.kodanev@oracle.com>
Cc: vasily.isaenko@oracle.com, ltp-list@lists.sourceforge.net
Subject: Re: [LTP] [PATCH v3] device-drivers/ltp_acpi_cpufreq: use simple counter instead of cur_freq
Date: Tue, 11 Nov 2014 14:45:56 +0100 [thread overview]
Message-ID: <20141111134555.GA32196@rei> (raw)
In-Reply-To: <1415268497-8921-1-git-send-email-alexey.kodanev@oracle.com>
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
chrubis@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
prev parent reply other threads:[~2014-11-11 13:46 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-11-06 10:08 [LTP] [PATCH v3] device-drivers/ltp_acpi_cpufreq: use simple counter instead of cur_freq Alexey Kodanev
2014-11-11 13:45 ` Cyril Hrubis [this message]
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=20141111134555.GA32196@rei \
--to=chrubis@suse.cz \
--cc=alexey.kodanev@oracle.com \
--cc=ltp-list@lists.sourceforge.net \
--cc=vasily.isaenko@oracle.com \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.