From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:57968) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aSuSG-0005Qo-Nb for qemu-devel@nongnu.org; Mon, 08 Feb 2016 17:38:49 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aSuSC-0003F7-NF for qemu-devel@nongnu.org; Mon, 08 Feb 2016 17:38:48 -0500 Received: from mx1.redhat.com ([209.132.183.28]:39575) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aSuSC-0003Ez-FW for qemu-devel@nongnu.org; Mon, 08 Feb 2016 17:38:44 -0500 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by mx1.redhat.com (Postfix) with ESMTPS id DD3ECC0C2345 for ; Mon, 8 Feb 2016 22:38:43 +0000 (UTC) References: <1454948107-11844-1-git-send-email-pbonzini@redhat.com> <1454948107-11844-10-git-send-email-pbonzini@redhat.com> From: Eric Blake Message-ID: <56B918F2.9020107@redhat.com> Date: Mon, 8 Feb 2016 15:38:42 -0700 MIME-Version: 1.0 In-Reply-To: <1454948107-11844-10-git-send-email-pbonzini@redhat.com> Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="v06eIiuecDR2SelNolSICHWQLQJ7WuoK4" Subject: Re: [Qemu-devel] [PATCH 09/16] qemu-thread: introduce QemuLockCnt List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Paolo Bonzini , qemu-devel@nongnu.org Cc: stefanha@redhat.com This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --v06eIiuecDR2SelNolSICHWQLQJ7WuoK4 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable On 02/08/2016 09:15 AM, Paolo Bonzini wrote: > A QemuLockCnt comprises a counter and a mutex, with primitives > to increment and decrement the counter, and to take and release the > mutex. It can be used to do lock-free visits to a data structure > whenever mutexes would be too heavy-weight and the critical section > is too long for RCU. >=20 > This could be implemented simply by protecting the counter with the > mutex, but QemuLockCnt is harder to misuse and more efficient. >=20 > Signed-off-by: Paolo Bonzini > --- > docs/lockcnt.txt | 343 ++++++++++++++++++++++++++++++++++++++++++= ++++++++ > include/qemu/thread.h | 17 +++ > util/Makefile.objs | 1 + > util/lockcnt.c | 122 ++++++++++++++++++ > 4 files changed, 483 insertions(+) > create mode 100644 docs/lockcnt.txt > create mode 100644 util/lockcnt.c >=20 > diff --git a/docs/lockcnt.txt b/docs/lockcnt.txt > new file mode 100644 > index 0000000..fc5d240 > --- /dev/null > +++ b/docs/lockcnt.txt > @@ -0,0 +1,343 @@ > +DOCUMENTATION FOR LOCKED COUNTERS (aka QemuLockCnt) > +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D Worth an explicit mention that this document is GPLv2+ (or an explicit choice of a different license)? > + > +QEMU often uses reference counts to track data structures that are bei= ng > +accessed and should not be freed. For example, a loop that invoke s/invoke/invokes/ > +callbacks like this is not safe: > + but overall a nice writeup. I'll leave the code review to others, though. > +++ b/util/lockcnt.c > @@ -0,0 +1,122 @@ > +/* > + * QemuLockCnt implementation > + * > + * Copyright Red Hat, Inc. 2015 > + * > + * Author: > + * Paolo Bonzini > + */ > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include You'll want to use qemu/osdep.h in place of several of these headers. --=20 Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org --v06eIiuecDR2SelNolSICHWQLQJ7WuoK4 Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v2 Comment: Public key at http://people.redhat.com/eblake/eblake.gpg Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/ iQEcBAEBCAAGBQJWuRjyAAoJEKeha0olJ0NqbM0H/jC0CKMgXtMGbqlWS65Jjidg mDx50RzS9Wg558TJ2lDTIipq2b1f1EUhFgdhbiKk00TdQW9AcSSSVNPKhGfc3E0W o+mCK7aVKG6fpAfY7X6LFjzBDpd6YzXcnd4cvf3EnOpIxtQ70K8TouCiBvF0zkCG xC4Srvg3HpPsuRVen/3wDkt7vg54zMINy1BPusSheUb2LZ2VZmmIpDJ6djCoMfEi tJzS9kBiPzxMlXiAvpPd+GYnHrebcuKXid5x5L06sxIAuix4ABfFQ79o2bm51izM 8sLt7/jUrPK3+HUA4xSVkaFwZLI9VDHgwvUio6eS8QlJebw09+iRwhv2NaBGyx4= =k4Gk -----END PGP SIGNATURE----- --v06eIiuecDR2SelNolSICHWQLQJ7WuoK4--