linux-pm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Doug Smythies" <dsmythies@telus.net>
To: 'Len Brown' <lenb@kernel.org>
Cc: 'Len Brown' <len.brown@intel.com>, linux-pm@vger.kernel.org
Subject: RE: [PATCH 06/16] tools/power turbostat: allow sub-sec intervals
Date: Sat, 27 Feb 2016 19:43:06 -0800	[thread overview]
Message-ID: <001201d171da$22f11850$68d348f0$@net> (raw)
In-Reply-To: <24781860a144a6792cb7697307f36b4486b611da.1456563103.git.len.brown@intel.com>

Hi Len,

On 2016.02.27 01:01 Len Brown wrote:

> From: Len Brown <len.brown@intel.com>
>
> turbostat -i interval_sec
>
> will sample and display statistics every interval_sec.
> interval_sec used to be a whole number of seconds,
> but now we accept a decimal, as small as 0.001 sec (1 ms).

Shouldn't you be cautious allowing this?
At such a high sampling rate, the user can significantly
effect the system being measured with turbostat's own overhead.

I tried down to 1 millisecond, and noted greatly
reduced C6 time (my processor only goes to C6), greatly increased
busy% for all CPU's, over 4 watts extra package power, ...

>
> Signed-off-by: Len Brown <len.brown@intel.com>
> ---
> tools/power/x86/turbostat/turbostat.8 |  2 +-
> tools/power/x86/turbostat/turbostat.c | 20 ++++++++++++++++----
> 2 files changed, 17 insertions(+), 5 deletions(-)
>
> diff --git a/tools/power/x86/turbostat/turbostat.8 b/tools/power/x86/turbostat/turbostat.8
> index 622db68..8a9727b 100644
> --- a/tools/power/x86/turbostat/turbostat.8
> +++ b/tools/power/x86/turbostat/turbostat.8
> @@ -34,7 +34,7 @@ name as necessary to disambiguate it from others is necessary.  Note that option
>  \fB--debug\fP displays additional system configuration information.  Invoking this parameter
>  more than once may also enable internal turbostat debug information.
>  .PP
> -\fB--interval seconds\fP overrides the default 5-second measurement interval.
> +\fB--interval decimal_seconds\fP overrides the default 5.0 second measurement interval.
>  .PP
>  \fB--help\fP displays usage for the most common parameters.
>  .PP

Don't you also need to update these lines?:

- .RB [ "\--interval seconds" ]
+ .RB [ "\--interval decimal_seconds" ]

- The 5-second interval can be changed with th "-i sec" option.
+ The 5-second interval can be changed with the "--interval decimal_seconds" option.

> diff --git a/tools/power/x86/turbostat/turbostat.c b/tools/power/x86/turbostat/turbostat.c
> index c600340..e411cc4 100644
> --- a/tools/power/x86/turbostat/turbostat.c
> +++ b/tools/power/x86/turbostat/turbostat.c
> @@ -38,12 +38,13 @@
>  #include <string.h>
>  #include <ctype.h>
>  #include <sched.h>
> +#include <time.h>
>  #include <cpuid.h>
>  #include <linux/capability.h>
>  #include <errno.h>
> 
>  char *proc_stat = "/proc/stat";
> -unsigned int interval_sec = 5;
> +struct timespec interval_ts = {5, 0};
>  unsigned int debug;
>  unsigned int rapl_joules;
>  unsigned int summary_only;
> @@ -1728,7 +1729,7 @@ restart:
>  			re_initialize();
>  			goto restart;
>  		}
> -		sleep(interval_sec);
> +		nanosleep(&interval_ts, NULL);
>  		retval = for_all_cpus(get_counters, ODD_COUNTERS);
>  		if (retval < -1) {
>  			exit(retval);
> @@ -1742,7 +1743,7 @@ restart:
>  		compute_average(EVEN_COUNTERS);
>  		format_all_counters(EVEN_COUNTERS);
>  		flush_stdout();
> -		sleep(interval_sec);
> +		nanosleep(&interval_ts, NULL);

In the limit of a very high sampling rate, doesn't the assumption
that the time spent in turbostat itself is negligible become
invalid?
And shouldn't the sleep time be compensated accordingly?

Perhaps something like (sorry for format, and not tested):

void __usleep(int us) {
   struct timespec time;

   time.tv_sec = us / 1000;
   time.tv_nsec = (us - time.tv_sec * 1000) * 1000;
   while(nanosleep(&time, &time) == -1 && errno == EINTR)
      continue;
}

unsigned long long stamp(void){
   struct timeval tv;

   gettimeofday(&tv, NULL);

   return (unsigned long long)tv.tv_sec * 1000000 + tv.tv_usec;
} /* endprocedure */

   now = stamp();
   if ((long long)(now - begin) < total ) {
      current_sleep = total - (now - begin);
      __usleep(current_sleep);
   } /* endif */
   begin += total;

Where total is the sample interval, in uSec, and begin was initialized
somewhere outside this loop.

Even if the time spent in turbostat is still almost negligible,
this will prevent sampling time error accumulation, by sleeping just
a little less every so often. However, there is also some extra
overhead, which is also undesirable.

>  		retval = for_all_cpus(get_counters, EVEN_COUNTERS);
>  		if (retval < -1) {
>  			exit(retval);
> @@ -3347,7 +3348,18 @@ void cmdline(int argc, char **argv)
>  			help();
>  			exit(1);
>  		case 'i':
> -			interval_sec = atoi(optarg);
> +			{
> +				double interval = strtod(optarg, NULL);
> +
> +				if (interval < 0.001) {
> +					fprintf(stderr, "interval %f seconds is too small\n",
> +						interval);
> +					exit(2);
> +				}
> +
> +				interval_ts.tv_sec = interval;
> +				interval_ts.tv_nsec = (interval - interval_ts.tv_sec) * 1000000000;
> +			}
>  			break;
>  		case 'J':
>  			rapl_joules++;
> -- 
> 2.7.1.339.g0233b80

... Doug



  reply	other threads:[~2016-02-28  3:43 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-02-27  9:00 [PATCH 0/16] turbostat updates Len Brown
2016-02-27  9:00 ` [PATCH 01/16] tools/power turbostat: decode more CPUID fields Len Brown
2016-02-27  9:00   ` [PATCH 02/16] tools/power turbostat: CPUID(0x16) leaf shows base, max, and bus frequency Len Brown
2016-02-27  9:00   ` [PATCH 03/16] x86 msr-index: Simplify syntax for HWP fields Len Brown
2016-02-27  9:00   ` [PATCH 04/16] tools/power turbostat: decode HWP registers Len Brown
2016-02-27  9:00   ` [PATCH 05/16] tools/power turbostat: Decode MSR_MISC_PWR_MGMT Len Brown
2016-02-27  9:01   ` [PATCH 06/16] tools/power turbostat: allow sub-sec intervals Len Brown
2016-02-28  3:43     ` Doug Smythies [this message]
2016-03-01  2:07       ` Brown, Len
2016-03-13  7:57       ` Len Brown
2016-02-27  9:01   ` [PATCH 07/16] tools/power turbostat: Intel Xeon x200: fix erroneous bclk value Len Brown
2016-02-27  9:01   ` [PATCH 08/16] tools/power turbostat: Intel Xeon x200: fix turbo-ratio decoding Len Brown
2016-02-27  9:01   ` [PATCH 09/16] tools/power turbostat: re-name "%Busy" field to "Busy%" Len Brown
2016-02-27  9:01   ` [PATCH 10/16] tools/power turbostat: add --out option for saving output in a file Len Brown
2016-02-27  9:01   ` [PATCH 11/16] tools/power turbostat: fix compiler warnings Len Brown
2016-02-27  9:01   ` [PATCH 12/16] tools/power turbostat: make fewer systems calls Len Brown
2016-02-27  9:01   ` [PATCH 13/16] tools/power turbostat: show IRQs per CPU Len Brown
2016-02-27  9:01   ` [PATCH 14/16] tools/power turbostat: show GFXMHz Len Brown
2016-02-27  9:01   ` [PATCH 15/16] tools/power turbostat: show GFX%rc6 Len Brown
2016-02-27  9:01   ` [PATCH 16/16] tools/power turbostat: detect and work around syscall jitter Len Brown

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='001201d171da$22f11850$68d348f0$@net' \
    --to=dsmythies@telus.net \
    --cc=len.brown@intel.com \
    --cc=lenb@kernel.org \
    --cc=linux-pm@vger.kernel.org \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).