Received: from eggs.gnu.org ([2001:4830:134:3::10]:55076) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YlciA-0005F7-7T for qemu-devel@nongnu.org; Fri, 24 Apr 2015 08:28:06 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Ylci7-0006zz-07 for qemu-devel@nongnu.org; Fri, 24 Apr 2015 08:28:02 -0400 Received: from mx1.redhat.com ([209.132.183.28]:37148) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Ylci6-0006zv-Mu for qemu-devel@nongnu.org; Fri, 24 Apr 2015 08:27:58 -0400 Date: Fri, 24 Apr 2015 14:27:52 +0200 From: Radim =?utf-8?B?S3LEjW3DocWZ?= Message-ID: <20150424122751.GA22555@potion.brq.redhat.com> References: <1428363937-19003-1-git-send-email-sullivan.james.f@gmail.com> <1428363937-19003-2-git-send-email-sullivan.james.f@gmail.com> <20150423134939.GA1992@potion.brq.redhat.com> <55393B52.8030509@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <55393B52.8030509@gmail.com> Content-Transfer-Encoding: quoted-printable Subject: Re: [Qemu-devel] [PATCH v2 RESEND 1/5] apic: Implement LAPIC low priority arbitration functions List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: James Sullivan Cc: pbonzini@redhat.com, mst@redhat.com, qemu-devel@nongnu.org, jan.kiszka@siemens.com 2015-04-23 12:34-0600, James Sullivan: > On 04/23/2015 07:49 AM, Radim Kr=C4=8Dm=C3=A1=C5=99 wrote: >> 2015-04-06 17:45-0600, James Sullivan: >>> Currently, apic_get_arb_pri() is unimplemented and returns 0. >>> >>> Implemented apic_get_arb_pri() and added two helper functions >>> apic_compare_prio() and apic_lowest_prio() to be used for LAPIC >>> arbitration. >>> >>> Signed-off-by: James Sullivan >>> --- >>> + for (i =3D 0; i < MAX_APIC_WORDS; i++) { >>> + if (deliver_bitmask[i]) { >>> + d =3D i * 32 + apic_ffs_bit(deliver_bitmask[i]); >>> + if (!lowest || apic_compare_prio(local_apics[d], lowest)= < 0) { >>> + lowest =3D local_apics[d]; >>=20 >> deliver_bitmask is 8 times u32 to express all 255 possible APICs. >> apic_ffs_bit() takes the last set bit, so this loop incorrectly >> considers only up to 8 candidates for lowest priority delivery. >> foreach_apic() could be used when fixing it, which would also avoid a >> 'local_apic[d] =3D=3D NULL' crash. >>=20 >=20 > Dumb mistake, I'll fix the former point. I shied away from > foreach_apic() because I think it's a bit messy to embed a block or an > `if` statement into the macro like so: >=20 > foreach_apic(apic,bmask, > if (cond) > foo(); > ); >=20 > But if people are okay with that sort of thing we can switch to it. Yeah, I wouldn't use it either :) It could use the canonical form (and optimizations for sparse bitmasks) foreach(...) code; Moving this logic to the loop in [4/4] would be an elegant solution. > > (For consideration: > > APM 2-16.2.2 Lowest Priority Messages and Arbitration > > If there is a tie for lowest priority, the local APIC with the hig= hest > > APIC ID is selected. > >=20 > > Intel is undefined in spec and picks the lowest APIC ID in practice.= ) > >=20 >=20 > Pretty quick change there, set lowest =3D local_apics[d] when > apic_compare_prio(local_apics[d], lowest) <=3D 0 rather than < 0 local_apics[] aren't indexed by APIC ID, which brings two complications - QEMU allows writing to APIC ID. Luckily, the spec allows us to make it read only, but even then - local_apics[] might not be ordered like their APIC IDs; (I don't know) and future development can change that, so we should also encode the expecation somewhere. (Comments don't work very well.) Taking a look at the real APIC ID would be safest. (Silently ignoring it is also a viable option.)