Received: from eggs.gnu.org ([2001:4830:134:3::10]:49836) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YTBnV-0002gO-1e for qemu-devel@nongnu.org; Wed, 04 Mar 2015 11:05:25 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YTBnP-0007iq-0a for qemu-devel@nongnu.org; Wed, 04 Mar 2015 11:05:19 -0500 Received: from mx1.redhat.com ([209.132.183.28]:38117) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YTBnO-0007im-OT for qemu-devel@nongnu.org; Wed, 04 Mar 2015 11:05:14 -0500 Date: Wed, 4 Mar 2015 10:04:27 -0600 From: Stefan Hajnoczi Message-ID: <20150304160427.GC15637@stefanha-thinkpad.redhat.com> References: <142929b6b5adbf371309043d23864c22b0afdec4.1423842044.git.berto@igalia.com> <20150303210006.GG15846@stefanha-thinkpad.redhat.com> <20150304135341.GA11084@igalia.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="E/DnYTRukya0zdZ1" Content-Disposition: inline In-Reply-To: <20150304135341.GA11084@igalia.com> Subject: Re: [Qemu-devel] [PATCH 7/9] throttle: Add throttle group support List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Alberto Garcia Cc: Kevin Wolf , Stefan Hajnoczi , qemu-devel@nongnu.org --E/DnYTRukya0zdZ1 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Wed, Mar 04, 2015 at 02:53:42PM +0100, Alberto Garcia wrote: > On Tue, Mar 03, 2015 at 03:00:06PM -0600, Stefan Hajnoczi wrote: >=20 > > > + throttle_group_lock(bs->throttle_state); > > > + bdrv_throttle_group_remove(bs); > > > + throttle_group_unlock(bs->throttle_state); > > > + > > > + throttle_group_unref(bs->throttle_state); > > > + bs->throttle_state =3D NULL; > > > + > > > throttle_timers_destroy(&bs->throttle_timers); > > > } > > > =20 > > > static void bdrv_throttle_read_timer_cb(void *opaque) > > > { > > > BlockDriverState *bs =3D opaque; > > > - throttle_timer_fired(&bs->throttle_state, false); > > > + > > > + throttle_group_lock(bs->throttle_state); > > > + throttle_timer_fired(bs->throttle_state, false); > > > + throttle_group_unlock(bs->throttle_state); > >=20 > > This pattern suggests throttle_timer_fired() should acquire the lock > > internally instead. >=20 > The idea is that the ThrottleState code itself doesn't know anything > about locks or groups. As I understood it Beno=EEt designed the > ThrottleState code to be independent from the block layer and reusable > for other things (that's why it's in util/). Then ThrottleGroup could offer an API throttle_group_timer_fired() that does the locking. The advantage of encapsulating locking in ThrottleGroup is that callers don't have to remember the take the lock. (But they must still be careful about sequences of calls which will not be atomic.) Stefan --E/DnYTRukya0zdZ1 Content-Type: application/pgp-signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v1 iQEcBAEBAgAGBQJU9y0LAAoJEJykq7OBq3PIbmAH/jpOI3wVvYV4WlBo5b5n1Yqa Gx/ZKHwJCn0G+dvmVOl/gscyHbBgvSTJ7tjW/YxB8M87xdv8AXz/0/okDmovXdJS qlropQ6BPkhFJqiUFG8nztA1a0JgQj+8AVFHRlga70TzfmwlOSpOlY7lj2KKCYT7 j6tC8ATyGfZFwDuyk6ytqgRH+jXKiOGTbW8XXfK0rXTwZjsbiEm5lN4JQkTawy0Q dIv04++O+NnMIOV0SW6Rj11zXzb8IHSOqiOeCNC4kTBsT77Oz9tgAgKu3d20oXzU wcKt04qOL5SA2bZ/in34S6j+V7+LjziHYOMypJKk+z4rIlEmQMCwEOIQy4BS6pU= =pQGB -----END PGP SIGNATURE----- --E/DnYTRukya0zdZ1--