From patchwork Wed Aug 3 14:14:22 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Wolf X-Patchwork-Id: 108220 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [140.186.70.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 4D37FB71E3 for ; Thu, 4 Aug 2011 00:28:47 +1000 (EST) Received: from localhost ([::1]:49901 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QocR6-0006Zl-Ul for incoming@patchwork.ozlabs.org; Wed, 03 Aug 2011 10:28:40 -0400 Received: from eggs.gnu.org ([140.186.70.92]:50170) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QocB6-0001sy-Ju for qemu-devel@nongnu.org; Wed, 03 Aug 2011 10:12:09 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1QocB2-0007sa-W2 for qemu-devel@nongnu.org; Wed, 03 Aug 2011 10:12:08 -0400 Received: from mx1.redhat.com ([209.132.183.28]:33094) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QocB2-0007sP-NW for qemu-devel@nongnu.org; Wed, 03 Aug 2011 10:12:04 -0400 Received: from int-mx12.intmail.prod.int.phx2.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.25]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id p73EC3w6008858 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Wed, 3 Aug 2011 10:12:03 -0400 Received: from dhcp-5-188.str.redhat.com (dhcp-5-175.str.redhat.com [10.32.5.175]) by int-mx12.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id p73EBSMv026900; Wed, 3 Aug 2011 10:12:02 -0400 From: Kevin Wolf To: anthony@codemonkey.ws Date: Wed, 3 Aug 2011 16:14:22 +0200 Message-Id: <1312380864-15605-28-git-send-email-kwolf@redhat.com> In-Reply-To: <1312380864-15605-1-git-send-email-kwolf@redhat.com> References: <1312380864-15605-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.25 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 209.132.183.28 Cc: kwolf@redhat.com, qemu-devel@nongnu.org Subject: [Qemu-devel] [PATCH 27/29] coroutines: Use one global bottom half for CoQueue X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Now that AsyncContexts don't exist any more, we can use one global bottom half for restarting coroutines instead of allocating a new one every time (before removing AsyncContexts, the problem with having a global BH was that it had to belong to a single AsyncContexts and wouldn't be executed in a different one - which leads to deadlocks) Signed-off-by: Kevin Wolf --- qemu-coroutine-lock.c | 19 ++++++------------- 1 files changed, 6 insertions(+), 13 deletions(-) diff --git a/qemu-coroutine-lock.c b/qemu-coroutine-lock.c index abaa1f7..a80f437 100644 --- a/qemu-coroutine-lock.c +++ b/qemu-coroutine-lock.c @@ -30,14 +30,10 @@ static QTAILQ_HEAD(, Coroutine) unlock_bh_queue = QTAILQ_HEAD_INITIALIZER(unlock_bh_queue); - -struct unlock_bh { - QEMUBH *bh; -}; +static QEMUBH* unlock_bh; static void qemu_co_queue_next_bh(void *opaque) { - struct unlock_bh *unlock_bh = opaque; Coroutine *next; trace_qemu_co_queue_next_bh(); @@ -45,14 +41,15 @@ static void qemu_co_queue_next_bh(void *opaque) QTAILQ_REMOVE(&unlock_bh_queue, next, co_queue_next); qemu_coroutine_enter(next, NULL); } - - qemu_bh_delete(unlock_bh->bh); - qemu_free(unlock_bh); } void qemu_co_queue_init(CoQueue *queue) { QTAILQ_INIT(&queue->entries); + + if (!unlock_bh) { + unlock_bh = qemu_bh_new(qemu_co_queue_next_bh, NULL); + } } void coroutine_fn qemu_co_queue_wait(CoQueue *queue) @@ -65,7 +62,6 @@ void coroutine_fn qemu_co_queue_wait(CoQueue *queue) bool qemu_co_queue_next(CoQueue *queue) { - struct unlock_bh *unlock_bh; Coroutine *next; next = QTAILQ_FIRST(&queue->entries); @@ -73,10 +69,7 @@ bool qemu_co_queue_next(CoQueue *queue) QTAILQ_REMOVE(&queue->entries, next, co_queue_next); QTAILQ_INSERT_TAIL(&unlock_bh_queue, next, co_queue_next); trace_qemu_co_queue_next(next); - - unlock_bh = qemu_malloc(sizeof(*unlock_bh)); - unlock_bh->bh = qemu_bh_new(qemu_co_queue_next_bh, unlock_bh); - qemu_bh_schedule(unlock_bh->bh); + qemu_bh_schedule(unlock_bh); } return (next != NULL);