From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:48319) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TEHBM-0007LO-Kw for qemu-devel@nongnu.org; Wed, 19 Sep 2012 06:07:01 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TEHBL-0006Jz-JM for qemu-devel@nongnu.org; Wed, 19 Sep 2012 06:07:00 -0400 Received: from mx1.redhat.com ([209.132.183.28]:21111) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TEHBL-0006Jv-A4 for qemu-devel@nongnu.org; Wed, 19 Sep 2012 06:06:59 -0400 Message-ID: <5059993C.1070506@redhat.com> Date: Wed, 19 Sep 2012 13:06:52 +0300 From: Avi Kivity MIME-Version: 1.0 References: <50597D1F.3070607@redhat.com> <50598B58.4010704@redhat.com> <50598D0D.2090608@redhat.com> <50598EB2.5040101@redhat.com> <505995B7.4010709@redhat.com> In-Reply-To: <505995B7.4010709@redhat.com> Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [big lock] Discussion about the convention of device's DMA each other after breaking down biglock List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Paolo Bonzini Cc: Jan Kiszka , Marcelo Tosatti , liu ping fan , Anthony Liguori , qemu-devel@nongnu.org On 09/19/2012 12:51 PM, Paolo Bonzini wrote: > Il 19/09/2012 11:21, Avi Kivity ha scritto: >>> > I don't know if the front-end (device) lock should come before or after >>> > the back-end (e.g. netdev) lock in the hierarchy, but that's another story. >> I would say device -> backend. It's natural if the backend is the timer >> subsystem, so extend it from there to the block and network layers. Of >> course callbacks want it to be the other way round. > > Yes, that's what I wasn't sure about. In many cases I believe callbacks > can just release the backend lock. It works for timers, for example: > > for(;;) { > ts = clock->active_timers; > if (!qemu_timer_expired_ns(ts, current_time)) { > break; > } > /* remove timer from the list before calling the callback */ > clock->active_timers = ts->next; > ts->next = NULL; > > /* run the callback (the timer list can be modified) */ > - ts->cb(ts->opaque); > + cb = ts->cb; > + opaque = ts->opaque; > + unlock(); > + cb(opaque); > + lock(); > } > > (The hunch is that ts could be deleted exactly at the moment the > callback is unlocked. This can be solved with ref/unref on the opaque > value, as you mention below). Are you saying that this works as is or not? It does seem broken wrt deletion; after qemu_del_timer() completes the caller expects the callback not to be called. This isn't trivial to guarantee, we need something like dispatch_timer(): pending += 1 timer.ref() drop lock timer.cb() take lock timer.unref() pending -= 1 notify del_timer(): take lock timer.unlink() while pending: wait for notification drop lock but, if del_timer is called with the device lock held, we deadlock. ugh. -- error compiling committee.c: too many arguments to function