Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1KQNXp-0007JA-Rz for qemu-devel@nongnu.org; Tue, 05 Aug 2008 10:29:50 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1KQNXj-0007Hy-Hm for qemu-devel@nongnu.org; Tue, 05 Aug 2008 10:29:48 -0400 Received: from [199.232.76.173] (port=37937 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1KQNXj-0007Hu-Dx for qemu-devel@nongnu.org; Tue, 05 Aug 2008 10:29:43 -0400 Received: from ecfrec.frec.bull.fr ([129.183.4.8]:46058) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1KQNXi-0005l9-IV for qemu-devel@nongnu.org; Tue, 05 Aug 2008 10:29:43 -0400 Subject: Re: [Qemu-devel] [patch 1/5][v2] Extract code from get_cluster_offset() From: Laurent Vivier In-Reply-To: <48986078.6060701@suse.de> References: <20080729141352.573798859@bull.net> <20080729141447.164763280@bull.net> <48986078.6060701@suse.de> Content-Type: text/plain; charset=utf-8 Date: Tue, 05 Aug 2008 16:28:27 +0200 Message-Id: <1217946507.3865.24.camel@frecb07144> Mime-Version: 1.0 Content-Transfer-Encoding: quoted-printable Reply-To: qemu-devel@nongnu.org List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Kevin Wolf Cc: qemu-devel@nongnu.org Le mardi 05 ao=C3=BBt 2008 =C3=A0 16:15 +0200, Kevin Wolf a =C3=A9crit : > Laurent Vivier schrieb: > > Extract code from get_cluster_offset() into new functions: > >=20 > > - seek_l2_table() > >=20 > > Search an l2 offset in the l2_cache table. > >=20 > > - l2_load() > >=20 > > Read the l2 entry from disk > >=20 > > - l2_allocate() > >=20 > > Allocate a new l2 entry. > >=20 > > Signed-off-by: Laurent Vivier >=20 > Acked-by: Kevin Wolf >=20 >=20 > However, unrelated to your patch, I noticed that you touch code which > could use more comments in some places. (Oh btw, why do you explain the > new functions in the patch header but not in the code itself? But okay, > these are more or less obvious.) OK, you're right, I'll add some comments. > > +static uint64_t *seek_l2_table(BDRVQcowState *s, uint64_t l2_offset) > > +{ > > + int i,j; > > + > > + for(i =3D 0; i < L2_CACHE_SIZE; i++) { > > + if (l2_offset =3D=3D s->l2_cache_offsets[i]) { > > + /* increment the hit count */ > > + if (++s->l2_cache_counts[i] =3D=3D 0xffffffff) { > > + for(j =3D 0; j < L2_CACHE_SIZE; j++) { > > + s->l2_cache_counts[j] >>=3D 1; > > + } > > + } >=20 > This if block is one of them. While it's quite obvious that some counte= r > is incremented, the action to avoid an overflow isn't. Why don't we do > something like if (count < 0xffffffff) count++? >=20 > And l2_cache_counts is a bad name anyway, IMHO. I first thought of > something like a reference counter (and then it would be definitely > worth a comment; now it is debatable). l2_cache_hits could be a better = name. It is a cut&paste... so I don't know what it is really doing and I don't want to modify something that has no direct link to the goal I reach... even a variable name. I'm currently testing these patches with encrypted disk and compressed disk, and I've found a bug with encrypted one. I'll repost patches soon. Thank you for your comments, Laurent --=20 ----------------- Laurent.Vivier@bull.net ------------------ "La perfection est atteinte non quand il ne reste rien =C3=A0 ajouter mais quand il ne reste rien =C3=A0 enlever." Saint Exup=C3=A9ry