From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58706) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XR0H4-0000bS-Tl for qemu-devel@nongnu.org; Mon, 08 Sep 2014 10:50:40 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XR0H0-0003c1-Fq for qemu-devel@nongnu.org; Mon, 08 Sep 2014 10:50:34 -0400 Received: from lputeaux-656-01-25-125.w80-12.abo.wanadoo.fr ([80.12.84.125]:60385 helo=paradis.irqsave.net) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XR0H0-0003bv-9x for qemu-devel@nongnu.org; Mon, 08 Sep 2014 10:50:30 -0400 Date: Mon, 8 Sep 2014 16:49:38 +0200 From: =?iso-8859-1?Q?Beno=EEt?= Canet Message-ID: <20140908144936.GA5723@irqsave.net> References: <1410178693-23370-1-git-send-email-benoit.canet@nodalink.com> <1410178693-23370-4-git-send-email-benoit.canet@nodalink.com> <540DBD46.7030207@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline In-Reply-To: <540DBD46.7030207@redhat.com> Content-Transfer-Encoding: quoted-printable Subject: Re: [Qemu-devel] [PATCH v2 3/3] util: Add an utility infrastructure used to compute an average on a time slice List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Paolo Bonzini Cc: peter.maydell@linaro.org, qemu-devel@nongnu.org, =?iso-8859-1?Q?Beno=EEt?= Canet The Monday 08 Sep 2014 =E0 16:29:26 (+0200), Paolo Bonzini wrote : > Il 08/09/2014 14:18, Beno=EEt Canet ha scritto: > > The algorithm used was defined on the list while discussing the new I= O accounting > > overhaul. > > See http://lists.nongnu.org/archive/html/qemu-devel/2014-08/msg04954.= html > >=20 > > Also the module takes care of computing minimal and maximal values ov= er the time > > slice duration. > >=20 > > Signed-off-by: Beno=EEt Canet >=20 > If you add >=20 > int64_t cpu_get_clock(void) > { > return my_clock_value; > } >=20 > to the test, and use a QEMU_CLOCK_VIRTUAL-based average, you should be > able to advance the clock directly in the test with no need for sleep() > and with 100% deterministic results. >=20 > >=20 > > +/* Check if the ta->periods seconds time slice has expired > > + * > > + * If the slice has expired the counters will be reseted > > + * > > + * @ta: the timed average structure used > > + */ > > +static void timed_average_check_expiration(TimedAverage *ta) > > +{ > > + int64_t now =3D qemu_clock_get_ns(ta->clock_type); > > + > > + /* if we are still in the period slice do nothing */ > > + if (now < ta->expiration) { > > + return; > > + } > > + > > + /* the slice has expired -> create a new slice */ > > + ta->min =3D UINT64_MAX; > > + ta->sum =3D 0; > > + ta->max =3D 0; > > + ta->count =3D 0; > > + timed_average_set_expiration(ta); > > +} >=20 Thanks for reviewing. > This can produce very noisy results if you invoke min/avg/max at the > wrong time. Some alternatives include: >=20 > - create two windows, with twice the suggested expiration period, and > return min/avg/max from the oldest window. Example >=20 > t=3D0 |t=3D1 |t=3D2 |t=3D3 |= t=3D4 > wnd0: [0,1) |wnd0: [1,3) | |wnd0: [3,5) | > wnd1: [0,2) | |wnd1: [2,4) | | >=20 > Values are returned from: >=20 > wnd0---------|wnd1---------|wnd0---------|wnd1---------| This is neat. As I think that knowing the minimal and maximal latencies of a block devi= ce would be handy I will implement this. Best regards Beno=EEt >=20 >=20 > - if you do not need min/max, you can use exponential smoothing, with a > weighted factor that depends on the time since the last sample. > http://www.drdobbs.com/tools/discontiguous-exponential-averaging/184410= 671 > -- for example, giving 90% weight to the last second. Of course the > exponential nature means that, in that case, 1-sqrt(10%)=3D68.3% weight= is > given to the last half second, 21.6% weight is given to the previous > half second, and 10% to the entire previous history. This cannot give > min/max, but can give avg/stdev. >=20 > Paolo >=20