From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:34630) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZDaI1-0006mK-Mw for qemu-devel@nongnu.org; Fri, 10 Jul 2015 11:32:38 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZDaHy-0008F6-Gw for qemu-devel@nongnu.org; Fri, 10 Jul 2015 11:32:37 -0400 Received: from greensocs.com ([193.104.36.180]:58094) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZDaHy-0008Dh-A4 for qemu-devel@nongnu.org; Fri, 10 Jul 2015 11:32:34 -0400 Message-ID: <559FE58C.6040400@greensocs.com> Date: Fri, 10 Jul 2015 17:32:28 +0200 From: Frederic Konrad MIME-Version: 1.0 References: <1436541553-26576-1-git-send-email-fred.konrad@greensocs.com> <1436541553-26576-2-git-send-email-fred.konrad@greensocs.com> <559FE32C.5030609@redhat.com> In-Reply-To: <559FE32C.5030609@redhat.com> Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [RFC PATCH 1/3] cpus: protect queued_work_* with work_mutex. List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Paolo Bonzini , qemu-devel@nongnu.org, mttcg@greensocs.com Cc: mark.burton@greensocs.com, alex.bennee@linaro.org, a.rigo@virtualopensystems.com, guillaume.delbergue@greensocs.com On 10/07/2015 17:22, Paolo Bonzini wrote: > > On 10/07/2015 17:19, fred.konrad@greensocs.com wrote: >> + qemu_mutex_lock(&cpu->work_mutex); >> while ((wi = cpu->queued_work_first)) { >> cpu->queued_work_first = wi->next; >> wi->func(wi->data); > Please unlock the mutex while calling the callback. > > Paolo > >> @@ -905,6 +912,8 @@ static void flush_queued_work(CPUState *cpu) >> } >> } >> cpu->queued_work_last = NULL; >> + qemu_mutex_unlock(&cpu->work_mutex); >> + >> qemu_cond_broadcast(&qemu_work_cond); I think something like that can work because we don't have two flush_queued_work at the same time on the same CPU? static void flush_queued_work(CPUState *cpu) { struct qemu_work_item *wi; if (cpu->queued_work_first == NULL) { return; } qemu_mutex_lock(&cpu->work_mutex); while ((wi = cpu->queued_work_first)) { cpu->queued_work_first = wi->next; qemu_mutex_unlock(&cpu->work_mutex); wi->func(wi->data); qemu_mutex_lock(&cpu->work_mutex); wi->done = true; if (wi->free) { g_free(wi); } } cpu->queued_work_last = NULL; qemu_mutex_unlock(&cpu->work_mutex); qemu_cond_broadcast(&qemu_work_cond); } Fred