From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42073) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b5KUo-0002Gm-1s for qemu-devel@nongnu.org; Tue, 24 May 2016 18:08:14 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1b5KUh-0001g2-Ut for qemu-devel@nongnu.org; Tue, 24 May 2016 18:08:12 -0400 Received: from out2-smtp.messagingengine.com ([66.111.4.26]:56079) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b5KUf-0001cJ-Fo for qemu-devel@nongnu.org; Tue, 24 May 2016 18:08:07 -0400 Date: Tue, 24 May 2016 18:07:55 -0400 From: "Emilio G. Cota" Message-ID: <20160524220755.GA25193@flamenco> References: <1463196873-17737-1-git-send-email-cota@braap.org> <1463196873-17737-14-git-send-email-cota@braap.org> <574367EB.8030101@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <574367EB.8030101@gmail.com> Subject: Re: [Qemu-devel] [PATCH v5 13/18] qht: support parallel writes List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Sergey Fedorov Cc: QEMU Developers , MTTCG Devel , Alex =?iso-8859-1?Q?Benn=E9e?= , Paolo Bonzini , Peter Crosthwaite , Richard Henderson On Mon, May 23, 2016 at 23:28:27 +0300, Sergey Fedorov wrote: > What if we turn qht::lock into a mutex and change the function as follows: > > static inline > struct qht_bucket *qht_bucket_lock__no_stale(struct qht *ht, > uint32_t hash, > struct qht_map > **pmap) > { > struct qht_bucket *b; > struct qht_map *map; > > map = atomic_rcu_read(&ht->map); > b = qht_map_to_bucket(map, hash); > > qemu_spin_lock(&b->lock); > /* 'ht->map' access is serialized by 'b->lock' here */ > if (likely(map == ht->map)) { > /* no resize in progress; we're done */ > *pmap = map; > return b; > } > qemu_spin_unlock(&b->lock); > > /* resize in progress; retry grabbing 'ht->lock' */ > qemu_mutex_lock(&ht->lock); > b = qht_map_to_bucket(ht->map, hash); > *pmap = ht->map; > qemu_spin_lock(&b->lock); > qemu_mutex_unlock(&ht->lock); > > return b; > } > > > With this implementation we could: > (1) get rid of qht_map::stale > (2) don't waste cycles waiting for resize to complete I'll include this in v6. Thanks, Emilio