From patchwork Fri Apr 15 11:31:56 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 8850331 Return-Path: X-Original-To: patchwork-qemu-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id C26FBC0553 for ; Fri, 15 Apr 2016 11:32:34 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 03DB520295 for ; Fri, 15 Apr 2016 11:32:34 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 33EFD201C7 for ; Fri, 15 Apr 2016 11:32:33 +0000 (UTC) Received: from localhost ([::1]:60466 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ar1zE-0005mO-35 for patchwork-qemu-devel@patchwork.kernel.org; Fri, 15 Apr 2016 07:32:32 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:55213) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ar1z1-0005im-Pn for qemu-devel@nongnu.org; Fri, 15 Apr 2016 07:32:21 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ar1yx-0008MA-It for qemu-devel@nongnu.org; Fri, 15 Apr 2016 07:32:19 -0400 Received: from mail-wm0-x244.google.com ([2a00:1450:400c:c09::244]:32917) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ar1yx-0008KV-8u for qemu-devel@nongnu.org; Fri, 15 Apr 2016 07:32:15 -0400 Received: by mail-wm0-x244.google.com with SMTP id y144so5413022wmd.0 for ; Fri, 15 Apr 2016 04:32:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=OxJl1nO2OC0TN0Jl/Xd4rpz4S7u5rKm4H4Cflf3Ng8A=; b=wgT//VMn7zmu4oGaEliOpklDhuTkDekhI5rU8+EPBvbCT1nktK/c4kFl1fePJiZvyz MEoUPOaalODwUPd8BKo52wKEaJ0utEtHBYzNvc6jUIC9NPbp01BwaGcTOOc0sEiLXP2b wRkSHUgJW44ZBFIf1Fp7RNbVkFfkyDyga7UcpSlAigidnUnQs1a6ZN4GYORQz0PZNbjf ttbpNleeW1R54iNKmvaJ2TFlwIumeajYkRnpBRc9h3velv//Fr9kU5DTyrouFup/batK F1gVbxgUQ8KoMz0xKmV7CrI022sJii2/XwnIW/dYx31A0fBo9KQEbRbadgGfXCnGhzk/ u/Tw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=OxJl1nO2OC0TN0Jl/Xd4rpz4S7u5rKm4H4Cflf3Ng8A=; b=kRfbE8C2iGmG13S87OrmdArMse7oVWjid0m1hk8RhgLslBP8bRx5JiJiukO7aDSlHT SEy5ZxTHe1NVKw3177wRGE6k7H0bqe+vqxZPHbKlmXBCuaiCV6bRrBkh7sxya/nCDNwK DsOIBy6cN31GfhMG5p7uYK6jQo1++tUL5rEIEjWMntXSK78LdDzN3saqFSymzuCBDHSG wl0G1mlOYpJiN8D+ReBBC+1mbdxPpOQVW36xfpkwC5q6LKzOg8bYRShSbwljZiDxMgcY zwAcW1ILq0ReprQukfqnmMgWFTAegxUutiC4kkpD7k9LtYLTtmJyHL+kEU7/qatyO+W2 KzOQ== X-Gm-Message-State: AOPr4FVZuo1ZgtYGMpMuCQGv+5XZ98S5igobZ/+5qTP/UfsNLmQWlUHb7X31QNrvfJn5RQ== X-Received: by 10.28.126.210 with SMTP id z201mr3828471wmc.74.1460719934678; Fri, 15 Apr 2016 04:32:14 -0700 (PDT) Received: from donizetti.redhat.com (94-39-141-76.adsl-ull.clienti.tiscali.it. [94.39.141.76]) by smtp.gmail.com with ESMTPSA id qt3sm15217493wjc.32.2016.04.15.04.32.13 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 15 Apr 2016 04:32:13 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Fri, 15 Apr 2016 13:31:56 +0200 Message-Id: <1460719926-12950-2-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 2.5.5 In-Reply-To: <1460719926-12950-1-git-send-email-pbonzini@redhat.com> References: <1460719926-12950-1-git-send-email-pbonzini@redhat.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2a00:1450:400c:c09::244 Subject: [Qemu-devel] [PATCH 01/11] coroutine: use QSIMPLEQ instead of QTAILQ X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, berto@igalia.com, famz@redhat.com, stefanha@redhat.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP CoQueue do not need to remove any element but the head of the list; processing is always strictly FIFO. Therefore, the simpler singly-linked QSIMPLEQ can be used instead. Signed-off-by: Paolo Bonzini Reviewed-by: Stefan Hajnoczi --- include/qemu/coroutine.h | 2 +- include/qemu/coroutine_int.h | 4 ++-- util/qemu-coroutine-lock.c | 22 +++++++++++----------- util/qemu-coroutine.c | 2 +- 4 files changed, 15 insertions(+), 15 deletions(-) diff --git a/include/qemu/coroutine.h b/include/qemu/coroutine.h index 305fe76..63ae7fe 100644 --- a/include/qemu/coroutine.h +++ b/include/qemu/coroutine.h @@ -102,7 +102,7 @@ bool qemu_in_coroutine(void); * are built. */ typedef struct CoQueue { - QTAILQ_HEAD(, Coroutine) entries; + QSIMPLEQ_HEAD(, Coroutine) entries; } CoQueue; /** diff --git a/include/qemu/coroutine_int.h b/include/qemu/coroutine_int.h index 42d6838..581a7f5 100644 --- a/include/qemu/coroutine_int.h +++ b/include/qemu/coroutine_int.h @@ -41,8 +41,8 @@ struct Coroutine { QSLIST_ENTRY(Coroutine) pool_next; /* Coroutines that should be woken up when we yield or terminate */ - QTAILQ_HEAD(, Coroutine) co_queue_wakeup; - QTAILQ_ENTRY(Coroutine) co_queue_next; + QSIMPLEQ_HEAD(, Coroutine) co_queue_wakeup; + QSIMPLEQ_ENTRY(Coroutine) co_queue_next; }; Coroutine *qemu_coroutine_new(void); diff --git a/util/qemu-coroutine-lock.c b/util/qemu-coroutine-lock.c index da37ca7..cf53693 100644 --- a/util/qemu-coroutine-lock.c +++ b/util/qemu-coroutine-lock.c @@ -31,13 +31,13 @@ void qemu_co_queue_init(CoQueue *queue) { - QTAILQ_INIT(&queue->entries); + QSIMPLEQ_INIT(&queue->entries); } void coroutine_fn qemu_co_queue_wait(CoQueue *queue) { Coroutine *self = qemu_coroutine_self(); - QTAILQ_INSERT_TAIL(&queue->entries, self, co_queue_next); + QSIMPLEQ_INSERT_TAIL(&queue->entries, self, co_queue_next); qemu_coroutine_yield(); assert(qemu_in_coroutine()); } @@ -55,8 +55,8 @@ void qemu_co_queue_run_restart(Coroutine *co) Coroutine *next; trace_qemu_co_queue_run_restart(co); - while ((next = QTAILQ_FIRST(&co->co_queue_wakeup))) { - QTAILQ_REMOVE(&co->co_queue_wakeup, next, co_queue_next); + while ((next = QSIMPLEQ_FIRST(&co->co_queue_wakeup))) { + QSIMPLEQ_REMOVE_HEAD(&co->co_queue_wakeup, co_queue_next); qemu_coroutine_enter(next, NULL); } } @@ -66,13 +66,13 @@ static bool qemu_co_queue_do_restart(CoQueue *queue, bool single) Coroutine *self = qemu_coroutine_self(); Coroutine *next; - if (QTAILQ_EMPTY(&queue->entries)) { + if (QSIMPLEQ_EMPTY(&queue->entries)) { return false; } - while ((next = QTAILQ_FIRST(&queue->entries)) != NULL) { - QTAILQ_REMOVE(&queue->entries, next, co_queue_next); - QTAILQ_INSERT_TAIL(&self->co_queue_wakeup, next, co_queue_next); + while ((next = QSIMPLEQ_FIRST(&queue->entries)) != NULL) { + QSIMPLEQ_REMOVE_HEAD(&queue->entries, co_queue_next); + QSIMPLEQ_INSERT_TAIL(&self->co_queue_wakeup, next, co_queue_next); trace_qemu_co_queue_next(next); if (single) { break; @@ -97,19 +97,19 @@ bool qemu_co_enter_next(CoQueue *queue) { Coroutine *next; - next = QTAILQ_FIRST(&queue->entries); + next = QSIMPLEQ_FIRST(&queue->entries); if (!next) { return false; } - QTAILQ_REMOVE(&queue->entries, next, co_queue_next); + QSIMPLEQ_REMOVE_HEAD(&queue->entries, co_queue_next); qemu_coroutine_enter(next, NULL); return true; } bool qemu_co_queue_empty(CoQueue *queue) { - return QTAILQ_FIRST(&queue->entries) == NULL; + return QSIMPLEQ_FIRST(&queue->entries) == NULL; } void qemu_co_mutex_init(CoMutex *mutex) diff --git a/util/qemu-coroutine.c b/util/qemu-coroutine.c index 5816702..b7cb636 100644 --- a/util/qemu-coroutine.c +++ b/util/qemu-coroutine.c @@ -76,7 +76,7 @@ Coroutine *qemu_coroutine_create(CoroutineEntry *entry) } co->entry = entry; - QTAILQ_INIT(&co->co_queue_wakeup); + QSIMPLEQ_INIT(&co->co_queue_wakeup); return co; }