linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] tools/power turbostat: Make interval calculation per thread to reduce jitter
@ 2019-03-25 17:32 Ghannam, Yazen
  2019-04-23 17:53 ` Ghannam, Yazen
  0 siblings, 1 reply; 4+ messages in thread
From: Ghannam, Yazen @ 2019-03-25 17:32 UTC (permalink / raw)
  To: linux-pm; +Cc: Ghannam, Yazen, linux-kernel, lenb

From: Yazen Ghannam <yazen.ghannam@amd.com>

Turbostat currently normalizes TSC and other values by dividing by an
interval. This interval is the delta between the start of one global
(all counters on all CPUs) sampling and the start of another. However,
this introduces a lot of jitter into the data.

In order to reduce jitter, the interval calculation should be based on
timestamps taken per thread and close to the start of the thread's
sampling.

Define a per thread time value to hold the delta between samples taken
on the thread.

Use the timestamp taken at the beginning of sampling to calculate the
delta.

Move the thread's beginning timestamp to after the CPU migration to
avoid jitter due to the migration.

Use the global time delta for the average time delta.

Signed-off-by: Yazen Ghannam <yazen.ghannam@amd.com>
---
 tools/power/x86/turbostat/turbostat.c | 13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)

diff --git a/tools/power/x86/turbostat/turbostat.c b/tools/power/x86/turbostat/turbostat.c
index c3fad065c89c..6ebcc420021f 100644
--- a/tools/power/x86/turbostat/turbostat.c
+++ b/tools/power/x86/turbostat/turbostat.c
@@ -166,6 +166,7 @@ size_t cpu_present_setsize, cpu_affinity_setsize, cpu_subset_size;
 struct thread_data {
 	struct timeval tv_begin;
 	struct timeval tv_end;
+	struct timeval tv_delta;
 	unsigned long long tsc;
 	unsigned long long aperf;
 	unsigned long long mperf;
@@ -896,7 +897,7 @@ int format_counters(struct thread_data *t, struct core_data *c,
 	if (DO_BIC(BIC_TOD))
 		outp += sprintf(outp, "%10ld.%06ld\t", t->tv_end.tv_sec, t->tv_end.tv_usec);
 
-	interval_float = tv_delta.tv_sec + tv_delta.tv_usec/1000000.0;
+	interval_float = t->tv_delta.tv_sec + t->tv_delta.tv_usec/1000000.0;
 
 	tsc = t->tsc * tsc_tweak;
 
@@ -1279,6 +1280,7 @@ delta_thread(struct thread_data *new, struct thread_data *old,
 	 * over-write old w/ new so we can print end of interval values
 	 */
 
+	timersub(&new->tv_begin, &old->tv_begin, &old->tv_delta);
 	old->tv_begin = new->tv_begin;
 	old->tv_end = new->tv_end;
 
@@ -1374,6 +1376,8 @@ void clear_counters(struct thread_data *t, struct core_data *c, struct pkg_data
 	t->tv_begin.tv_usec = 0;
 	t->tv_end.tv_sec = 0;
 	t->tv_end.tv_usec = 0;
+	t->tv_delta.tv_sec = 0;
+	t->tv_delta.tv_usec = 0;
 
 	t->tsc = 0;
 	t->aperf = 0;
@@ -1540,6 +1544,9 @@ void compute_average(struct thread_data *t, struct core_data *c,
 
 	for_all_cpus(sum_counters, t, c, p);
 
+	/* Use the global time delta for the average. */
+	average.threads.tv_delta = tv_delta;
+
 	average.threads.tsc /= topo.num_cpus;
 	average.threads.aperf /= topo.num_cpus;
 	average.threads.mperf /= topo.num_cpus;
@@ -1729,13 +1736,13 @@ int get_counters(struct thread_data *t, struct core_data *c, struct pkg_data *p)
 	struct msr_counter *mp;
 	int i;
 
-	gettimeofday(&t->tv_begin, (struct timezone *)NULL);
-
 	if (cpu_migrate(cpu)) {
 		fprintf(outf, "Could not migrate to CPU %d\n", cpu);
 		return -1;
 	}
 
+	gettimeofday(&t->tv_begin, (struct timezone *)NULL);
+
 	if (first_counter_read)
 		get_apic_id(t);
 retry:
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* RE: [PATCH] tools/power turbostat: Make interval calculation per thread to reduce jitter
  2019-03-25 17:32 [PATCH] tools/power turbostat: Make interval calculation per thread to reduce jitter Ghannam, Yazen
@ 2019-04-23 17:53 ` Ghannam, Yazen
  2019-06-07 16:28   ` Ghannam, Yazen
  0 siblings, 1 reply; 4+ messages in thread
From: Ghannam, Yazen @ 2019-04-23 17:53 UTC (permalink / raw)
  To: Ghannam, Yazen, linux-pm, len.brown; +Cc: linux-kernel, Len Brown

> -----Original Message-----
> From: linux-kernel-owner@vger.kernel.org <linux-kernel-owner@vger.kernel.org> On Behalf Of Ghannam, Yazen
> Sent: Monday, March 25, 2019 12:33 PM
> To: linux-pm@vger.kernel.org
> Cc: Ghannam, Yazen <Yazen.Ghannam@amd.com>; linux-kernel@vger.kernel.org; lenb@kernel.org
> Subject: [PATCH] tools/power turbostat: Make interval calculation per thread to reduce jitter
> 
> From: Yazen Ghannam <yazen.ghannam@amd.com>
> 
> Turbostat currently normalizes TSC and other values by dividing by an
> interval. This interval is the delta between the start of one global
> (all counters on all CPUs) sampling and the start of another. However,
> this introduces a lot of jitter into the data.
> 
> In order to reduce jitter, the interval calculation should be based on
> timestamps taken per thread and close to the start of the thread's
> sampling.
> 
> Define a per thread time value to hold the delta between samples taken
> on the thread.
> 
> Use the timestamp taken at the beginning of sampling to calculate the
> delta.
> 
> Move the thread's beginning timestamp to after the CPU migration to
> avoid jitter due to the migration.
> 
> Use the global time delta for the average time delta.
> 
> Signed-off-by: Yazen Ghannam <yazen.ghannam@amd.com>
> ---

Hi Len,

Any comments on this patch?

Thanks,
Yazen

^ permalink raw reply	[flat|nested] 4+ messages in thread

* RE: [PATCH] tools/power turbostat: Make interval calculation per thread to reduce jitter
  2019-04-23 17:53 ` Ghannam, Yazen
@ 2019-06-07 16:28   ` Ghannam, Yazen
  2019-08-31 16:48     ` Len Brown
  0 siblings, 1 reply; 4+ messages in thread
From: Ghannam, Yazen @ 2019-06-07 16:28 UTC (permalink / raw)
  To: linux-pm, len.brown; +Cc: linux-kernel, Len Brown

> -----Original Message-----
> From: Ghannam, Yazen <Yazen.Ghannam@amd.com>
> Sent: Tuesday, April 23, 2019 12:53 PM
> To: Ghannam, Yazen <Yazen.Ghannam@amd.com>; linux-pm@vger.kernel.org; len.brown@intel.com
> Cc: linux-kernel@vger.kernel.org; Len Brown <lenb@kernel.org>
> Subject: RE: [PATCH] tools/power turbostat: Make interval calculation per thread to reduce jitter
> 
> > -----Original Message-----
> > From: linux-kernel-owner@vger.kernel.org <linux-kernel-owner@vger.kernel.org> On Behalf Of Ghannam, Yazen
> > Sent: Monday, March 25, 2019 12:33 PM
> > To: linux-pm@vger.kernel.org
> > Cc: Ghannam, Yazen <Yazen.Ghannam@amd.com>; linux-kernel@vger.kernel.org; lenb@kernel.org
> > Subject: [PATCH] tools/power turbostat: Make interval calculation per thread to reduce jitter
> >
> > From: Yazen Ghannam <yazen.ghannam@amd.com>
> >
> > Turbostat currently normalizes TSC and other values by dividing by an
> > interval. This interval is the delta between the start of one global
> > (all counters on all CPUs) sampling and the start of another. However,
> > this introduces a lot of jitter into the data.
> >
> > In order to reduce jitter, the interval calculation should be based on
> > timestamps taken per thread and close to the start of the thread's
> > sampling.
> >
> > Define a per thread time value to hold the delta between samples taken
> > on the thread.
> >
> > Use the timestamp taken at the beginning of sampling to calculate the
> > delta.
> >
> > Move the thread's beginning timestamp to after the CPU migration to
> > avoid jitter due to the migration.
> >
> > Use the global time delta for the average time delta.
> >
> > Signed-off-by: Yazen Ghannam <yazen.ghannam@amd.com>
> > ---
> 
> Hi Len,
> 
> Any comments on this patch?
> 

Hi Len,

Just wanted to check in. Do you have any comments on this patch?

Thanks,
Yazen

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] tools/power turbostat: Make interval calculation per thread to reduce jitter
  2019-06-07 16:28   ` Ghannam, Yazen
@ 2019-08-31 16:48     ` Len Brown
  0 siblings, 0 replies; 4+ messages in thread
From: Len Brown @ 2019-08-31 16:48 UTC (permalink / raw)
  To: Ghannam, Yazen; +Cc: linux-pm, len.brown, linux-kernel

Yeah, I like this patch, and I have applied it.

thanks!
-Len

On Fri, Jun 7, 2019 at 12:28 PM Ghannam, Yazen <Yazen.Ghannam@amd.com> wrote:
>
> > -----Original Message-----
> > From: Ghannam, Yazen <Yazen.Ghannam@amd.com>
> > Sent: Tuesday, April 23, 2019 12:53 PM
> > To: Ghannam, Yazen <Yazen.Ghannam@amd.com>; linux-pm@vger.kernel.org; len.brown@intel.com
> > Cc: linux-kernel@vger.kernel.org; Len Brown <lenb@kernel.org>
> > Subject: RE: [PATCH] tools/power turbostat: Make interval calculation per thread to reduce jitter
> >
> > > -----Original Message-----
> > > From: linux-kernel-owner@vger.kernel.org <linux-kernel-owner@vger.kernel.org> On Behalf Of Ghannam, Yazen
> > > Sent: Monday, March 25, 2019 12:33 PM
> > > To: linux-pm@vger.kernel.org
> > > Cc: Ghannam, Yazen <Yazen.Ghannam@amd.com>; linux-kernel@vger.kernel.org; lenb@kernel.org
> > > Subject: [PATCH] tools/power turbostat: Make interval calculation per thread to reduce jitter
> > >
> > > From: Yazen Ghannam <yazen.ghannam@amd.com>
> > >
> > > Turbostat currently normalizes TSC and other values by dividing by an
> > > interval. This interval is the delta between the start of one global
> > > (all counters on all CPUs) sampling and the start of another. However,
> > > this introduces a lot of jitter into the data.
> > >
> > > In order to reduce jitter, the interval calculation should be based on
> > > timestamps taken per thread and close to the start of the thread's
> > > sampling.
> > >
> > > Define a per thread time value to hold the delta between samples taken
> > > on the thread.
> > >
> > > Use the timestamp taken at the beginning of sampling to calculate the
> > > delta.
> > >
> > > Move the thread's beginning timestamp to after the CPU migration to
> > > avoid jitter due to the migration.
> > >
> > > Use the global time delta for the average time delta.
> > >
> > > Signed-off-by: Yazen Ghannam <yazen.ghannam@amd.com>
> > > ---
> >
> > Hi Len,
> >
> > Any comments on this patch?
> >
>
> Hi Len,
>
> Just wanted to check in. Do you have any comments on this patch?
>
> Thanks,
> Yazen



-- 
Len Brown, Intel Open Source Technology Center

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2019-08-31 16:48 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-03-25 17:32 [PATCH] tools/power turbostat: Make interval calculation per thread to reduce jitter Ghannam, Yazen
2019-04-23 17:53 ` Ghannam, Yazen
2019-06-07 16:28   ` Ghannam, Yazen
2019-08-31 16:48     ` Len Brown

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).