From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:48218) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TShqF-0006Aq-Lj for qemu-devel@nongnu.org; Mon, 29 Oct 2012 01:24:52 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TShqE-0000BH-D9 for qemu-devel@nongnu.org; Mon, 29 Oct 2012 01:24:51 -0400 Received: from mail-wi0-f175.google.com ([209.85.212.175]:34478) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TShqE-0000B9-6W for qemu-devel@nongnu.org; Mon, 29 Oct 2012 01:24:50 -0400 Received: by mail-wi0-f175.google.com with SMTP id hq4so1477578wib.10 for ; Sun, 28 Oct 2012 22:24:49 -0700 (PDT) MIME-Version: 1.0 In-Reply-To: <508A652E.3010109@siemens.com> References: <1350897839-29593-1-git-send-email-pingfank@linux.vnet.ibm.com> <1350897839-29593-14-git-send-email-pingfank@linux.vnet.ibm.com> <50852299.8090109@redhat.com> <50865E3F.4010809@siemens.com> <5086656A.6060603@redhat.com> <50890087.1080706@redhat.com> <508A652E.3010109@siemens.com> From: liu ping fan Date: Mon, 29 Oct 2012 13:24:29 +0800 Message-ID: Content-Type: text/plain; charset=ISO-8859-1 Subject: Re: [Qemu-devel] [patch v4 13/16] e1000: add busy flag to anti broken device state List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Jan Kiszka Cc: Peter Maydell , Stefan Hajnoczi , Marcelo Tosatti , "qemu-devel@nongnu.org" , Avi Kivity , Anthony Liguori , Paolo Bonzini On Fri, Oct 26, 2012 at 6:25 PM, Jan Kiszka wrote: > On 2012-10-26 05:08, liu ping fan wrote: >> On Fri, Oct 26, 2012 at 11:05 AM, liu ping fan wrote: >>> On Thu, Oct 25, 2012 at 5:04 PM, Avi Kivity wrote: >>>> On 10/25/2012 11:00 AM, Peter Maydell wrote: >>>>> On 23 October 2012 10:37, Avi Kivity wrote: >>>>>> On 10/23/2012 11:32 AM, liu ping fan wrote: >>>>>>> On Tue, Oct 23, 2012 at 5:07 PM, Jan Kiszka wrote: >>>>>>>> On 2012-10-23 07:52, liu ping fan wrote: >>>>>>>>> On Mon, Oct 22, 2012 at 6:40 PM, Avi Kivity wrote: >>>>>>>>>> On 10/22/2012 11:23 AM, Liu Ping Fan wrote: >>>>>>>>> It will only record and fix the issue on one thread. But guest can >>>>>>>>> touch the emulated device on muti-threads. >>>>>>>> >>>>>>>> Sorry, what does that mean? A second VCPU accessing the device will >>>>>>>> simply be ignored when it races with another VCPU? Specifically >>>>>>>> >>>>>>> Yes, just ignored. For device which support many logic in parallel, >>>>>>> it should use independent busy flag for each logic >>>>>> >>>>>> We don't actually know that e1000 doesn't. Why won't writing into >>>>>> different registers in parallel work? >>>>> >>>>> Unless the device we're emulating supports multiple in >>>>> parallel accesses (and I bet 99.9% of the devices we model >>>>> don't) then the memory framework needs to serialise the >>>>> loads/stores. Otherwise it's just going to be excessively >>>>> hard to write a reliable device model. >>>> >>>> That's why we have a per-device lock. The busy flag breaks that model >>>> by discarding accesses that occur in parallel. >>>> >>> I think by adopting the model, we can avoid this. >>> >>> struct device_logic { >>> bool busy; >>> qemu_mutex lock; >>> QemuCond wait; >>> }; >>> >>> LOCK(logic->lock) >>> while (logic->busy) { >>> qemu_cond_wait(&logic->wait, &logic->lock); >>> } >>> .... >>> do hardware emulation >>> ... >>> logic->busy = false; >> UNLOCK(lock); <-------------------------------------- forget >>> qemu_cond_signal(&logic->wait); >>> >>> This is identical to the biglock's behavior for parallel access to >>> device for nowadays. And then, the problem left is what level for >>> parallel we want. If we expect more parallel, we need to degrade the >>> device into more logic unit. > > But where is the remaining added-value of the busy flag then? Everyone > could just as well be serialized by the lock itself. And even when > dropping the lock while running the hw emulation, that doesn't change The key is that local lock is broken, so we rely on a high level lock -- busy flag. After threading each subsystem, we will not face broken local lock issue, and can throw away this design. > anything to the semantic - and our ABBA problems I sketched yesterday. > Oh, ABBA problem can not be solved, I think we need clever deadlock detector. Regards, pingfan > Jan > > -- > Siemens AG, Corporate Technology, CT RTC ITP SDP-DE > Corporate Competence Center Embedded Linux