From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59935) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XjUsl-0006AO-GN for qemu-devel@nongnu.org; Wed, 29 Oct 2014 11:10:04 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XjUsX-0003K4-Ih for qemu-devel@nongnu.org; Wed, 29 Oct 2014 11:09:55 -0400 Received: from mail-lb0-x230.google.com ([2a00:1450:4010:c04::230]:41669) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XjUsX-0003Js-6r for qemu-devel@nongnu.org; Wed, 29 Oct 2014 11:09:41 -0400 Received: by mail-lb0-f176.google.com with SMTP id z11so659119lbi.21 for ; Wed, 29 Oct 2014 08:09:38 -0700 (PDT) Date: Wed, 29 Oct 2014 15:09:34 +0000 From: Stefan Hajnoczi Message-ID: <20141029150934.GF19774@stefanha-thinkpad.redhat.com> References: <1414510422-8277-1-git-send-email-rehs@gmx.de> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="HCdXmnRlPgeNBad2" Content-Disposition: inline In-Reply-To: <1414510422-8277-1-git-send-email-rehs@gmx.de> Subject: Re: [Qemu-devel] [PATCH] Simple performance logging and network limiting based on trace option List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Harald Schieche Cc: Stefan Weil , qemu-devel@nongnu.org, Stefan Hajnoczi , Anthony Liguori --HCdXmnRlPgeNBad2 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Tue, Oct 28, 2014 at 04:33:42PM +0100, Harald Schieche wrote: Missing commit description: What problem are you trying to solve? The "Signed-off-by" goes here. > diff --git a/block/raw-posix.c b/block/raw-posix.c > index 475cf74..3c5cc71 100644 > --- a/block/raw-posix.c > +++ b/block/raw-posix.c > @@ -1031,6 +1031,27 @@ static int aio_worker(void *arg) > return ret; > } > =20 > +static void log_guest_storage_performance(void) > +{ > + /* > + * Performance logging isn't specified yet. > + * Therefore we're using existing tracing. > + */ > + static int64_t logged_clock; > + static int64_t counter; There can be multiple threads, static variables will not work. > + int64_t clock =3D get_clock(); > + > + counter++; > + if (clock - logged_clock >=3D 1000000000LL) { You are trying to identify calls to log_guest_storage_performance() that are more than 1 second apart? I'm not sure what you're trying to measure. It is simplest to have unconditional trace events and calculate latencies during trace file analysis. That way no arbitrary constants like 1 second are hard-coded into QEMU. > diff --git a/net/queue.c b/net/queue.c > index f948318..2b0fef7 100644 > --- a/net/queue.c > +++ b/net/queue.c > @@ -23,7 +23,9 @@ > =20 > #include "net/queue.h" > #include "qemu/queue.h" > +#include "qemu/timer.h" > #include "net/net.h" > +#include "trace.h" > =20 > /* The delivery handler may only return zero if it will call > * qemu_net_queue_flush() when it determines that it is once again able > @@ -58,6 +60,15 @@ struct NetQueue { > unsigned delivering : 1; > }; > =20 > +static int64_t bandwidth_limit; /* maximum number of bits per second= */ Throttling should be per-device, not global. > + > +void qemu_net_set_bandwidth_limit(int64_t limit) > +{ > + bandwidth_limit =3D limit; > + trace_qemu_net_set_bandwidth_limit(limit); > +} > + > + > NetQueue *qemu_new_net_queue(void *opaque) > { > NetQueue *queue; > @@ -175,6 +186,48 @@ static ssize_t qemu_net_queue_deliver_iov(NetQueue *= queue, > return ret; > } > =20 > +static int64_t limit_network_performance(int64_t start_clock, > + int64_t bytes) > +{ > + int64_t clock =3D get_clock(); > + int64_t sleep_usecs =3D 0; > + if (bandwidth_limit > 0) { > + sleep_usecs =3D (bytes * 8 * 1000000LL) / bandwidth_limit - > + (clock - start_clock) / 1000LL; > + } > + if (sleep_usecs > 0) { > + usleep(sleep_usecs); This does more than limit the network performance, it can also freeze the guest. QEMU is event-driven. The event loop thread is not allowed to block or sleep - otherwise the vcpu threads will block when they try to acquire the QEMU global mutex. --HCdXmnRlPgeNBad2 Content-Type: application/pgp-signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v1 iQEcBAEBAgAGBQJUUQMuAAoJEJykq7OBq3PIwQ4H/iau8ahUAoah444nogJDygwl UZcEV9Yjh/OVHIwVFQUhyEdD8dy/iP4H+qe5lyI7Ji3k4Ok4km50KBjAYbZEhNEo IWG54KavRGH9zGdfM1AKfJLR1a3TYwdvBMwP7bpXt9mxbAPSOr5FHaA2L3EnHzVO VMb2pt7HI1aKTIgx0mCYBFemyLOERWw/wcGoGNx5egL2TDdlnTc6j8D2sAzWGlNq bBzNSpLCklbWGtBx5QZBldsh/FVlqTiLmEx/c4iIgBSvaCTdEx8aj8+Lb6ftAdiw VJV5MjGFx8enMA36rHLKE2qGJaT3OcglKr4tcCcCaeIxkDDEdwawC9+mKJ0Y/74= =Vcsa -----END PGP SIGNATURE----- --HCdXmnRlPgeNBad2--