Received: from eggs.gnu.org ([2001:4830:134:3::10]:36532) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1X35Wf-0002Le-Vi for qemu-devel@nongnu.org; Fri, 04 Jul 2014 11:35:58 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1X35WT-00083y-Rf for qemu-devel@nongnu.org; Fri, 04 Jul 2014 11:35:49 -0400 Received: from [2001:41d0:8:2b42::1] (port=34584 helo=greensocs.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1X35WT-00083g-L6 for qemu-devel@nongnu.org; Fri, 04 Jul 2014 11:35:37 -0400 Message-ID: <53B6C9C6.7060602@greensocs.com> Date: Fri, 04 Jul 2014 17:35:34 +0200 From: Frederic Konrad MIME-Version: 1.0 Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: quoted-printable Subject: [Qemu-devel] Atomic instruction. List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel Cc: Peter Maydell , Mark Burton , fred.konrad@greensocs.com Hi everybody, We are experimenting with multi-core QEMU. We have Multiple QEMU cores=20 running on multiple host threads and we are now looking at the issue of =91atomic= =92 instructions. Our initial thought was to push some sort of set of flags out to the memo= ry chain (eg: ATOMIC or NORMAL much as the H/W would do). However, this is=20 a lot of changes and there seems to be a choice of a number of different ways of=20 doing this. We think the best approach overall is to leave the current mechanisms for guaranteeing the functionality of e.g. load/store exclusive in place. That is to say, right now, for instance for ARM, QEMU stores the addr/val= of loads, and compare them to ensure they have not been changed on store. Effectively it does a load-compair-store for the store. This is a =91belt and braces=92 implementation of the H/W, but it=92s goo= d. I believe it is valid to say that - so long as each core can guarantee=20 that the =91load-compair-store=92 is somehow atomic, then it is perfectly=20 satisfactory for each QEMU core to hold it=92s own value for the =91old value=92 etc, and = this mechanism will still work. The issue will only be to ensure that the load-compair-store is atomic - = and only in the =91store exclusive=92. Overall, this mechanism does not actually mirror the hardware we are=20 modelling, so overall we think it would be easier and more re-usable to provide two = new OP=92s in the TCG, one to lock a mutex, one to release it. For QEMU=92s on a single host thread, the implementation of these can be=20 empty, and generate no code. For QEMU=92s that are intended to run on multiple host threads, we can=20 have code that calls out to a helper that will take or release this mutex. Clearly we are a long way from a patch set that would be helpful=20 upstream, but we would very much appreciate feedback on this approach. Thanks, Fred