From patchwork Wed Jul 16 16:31:08 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ming Lei X-Patchwork-Id: 370794 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 260161400AF for ; Thu, 17 Jul 2014 02:32:22 +1000 (EST) Received: from localhost ([::1]:40261 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1X7S7w-0001z0-8N for incoming@patchwork.ozlabs.org; Wed, 16 Jul 2014 12:32:20 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53031) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1X7S7P-0001CU-Qf for qemu-devel@nongnu.org; Wed, 16 Jul 2014 12:31:54 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1X7S7J-0000ua-3g for qemu-devel@nongnu.org; Wed, 16 Jul 2014 12:31:47 -0400 Received: from mail-pa0-f53.google.com ([209.85.220.53]:59588) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1X7S7I-0000uU-Tx for qemu-devel@nongnu.org; Wed, 16 Jul 2014 12:31:41 -0400 Received: by mail-pa0-f53.google.com with SMTP id kq14so1570478pab.26 for ; Wed, 16 Jul 2014 09:31:40 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=GdPWDN5cCbiuo7WY6t5fVHnc3Pt5QnN9vw/MKBZ4hVw=; b=V0bWH4tfWzFhHlJrgDzIRAxNyaX4F3AXPf4Xn7yBlFkaI5tt/CA+3rXpOP+5lLxgVO x13a8BKxrxm70g+EP+ROXdHlX7UuO9IjrfgVpeXPIoWy5iQljzApav3tydyT8T1A7UM/ KKj2zOpfprDFfa1KTNxfJQDqbvkB76LOmByj+5mJLAwCKfHLVIjfKbsoQOCFkaw+Yjvo G6gj2FirpJqoQ/yM9TDyO6MTnHkP4w/s8boxR8ctdzhc4MeANvgfBV8BfiwCaYN2OpFd a4zbxEF52RedEKftg9u14sXLwX2lxtOLpx1Fbb6bdR11w9Y9xU5oYFMNQb00rfZPkWzZ DvIw== X-Received: by 10.70.44.101 with SMTP id d5mr31182148pdm.82.1405528300103; Wed, 16 Jul 2014 09:31:40 -0700 (PDT) Received: from localhost ([183.37.245.13]) by mx.google.com with ESMTPSA id wn7sm72414582pab.18.2014.07.16.09.31.36 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Wed, 16 Jul 2014 09:31:39 -0700 (PDT) From: Ming Lei To: qemu-devel@nongnu.org, Paolo Bonzini , Stefan Hajnoczi Date: Thu, 17 Jul 2014 00:31:08 +0800 Message-Id: <1405528281-23744-2-git-send-email-ming.lei@canonical.com> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1405528281-23744-1-git-send-email-ming.lei@canonical.com> References: <1405528281-23744-1-git-send-email-ming.lei@canonical.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.85.220.53 Cc: Kevin Wolf , Ming Lei , Fam Zheng , "Michael S. Tsirkin" Subject: [Qemu-devel] [PATCH RFC 01/14] qemu coroutine: support bypass mode 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 This patch introduces several APIs for supporting bypass qemu coroutine in case of being not necessary and for performance's sake. Signed-off-by: Ming Lei --- include/block/coroutine.h | 7 +++++++ include/block/coroutine_int.h | 5 +++++ qemu-coroutine-lock.c | 4 ++-- qemu-coroutine.c | 33 +++++++++++++++++++++++++++++++++ 4 files changed, 47 insertions(+), 2 deletions(-) diff --git a/include/block/coroutine.h b/include/block/coroutine.h index b9b7f48..9bd64da 100644 --- a/include/block/coroutine.h +++ b/include/block/coroutine.h @@ -234,4 +234,11 @@ void coroutine_fn yield_until_fd_readable(int fd); */ void qemu_coroutine_adjust_pool_size(int n); +/* qemu coroutine bypass APIs */ +void qemu_coroutine_set_bypass(bool bypass); +bool qemu_coroutine_bypassed(Coroutine *self); +bool qemu_coroutine_self_bypassed(void); +void qemu_coroutine_set_var(void *var); +void *qemu_coroutine_get_var(void); + #endif /* QEMU_COROUTINE_H */ diff --git a/include/block/coroutine_int.h b/include/block/coroutine_int.h index f133d65..106d0b2 100644 --- a/include/block/coroutine_int.h +++ b/include/block/coroutine_int.h @@ -39,6 +39,11 @@ struct Coroutine { Coroutine *caller; QSLIST_ENTRY(Coroutine) pool_next; + bool bypass; + + /* only used in bypass mode */ + void *opaque; + /* Coroutines that should be woken up when we yield or terminate */ QTAILQ_HEAD(, Coroutine) co_queue_wakeup; QTAILQ_ENTRY(Coroutine) co_queue_next; diff --git a/qemu-coroutine-lock.c b/qemu-coroutine-lock.c index e4860ae..7c69ff6 100644 --- a/qemu-coroutine-lock.c +++ b/qemu-coroutine-lock.c @@ -82,13 +82,13 @@ static bool qemu_co_queue_do_restart(CoQueue *queue, bool single) bool coroutine_fn qemu_co_queue_next(CoQueue *queue) { - assert(qemu_in_coroutine()); + assert(qemu_in_coroutine() || qemu_coroutine_self_bypassed()); return qemu_co_queue_do_restart(queue, true); } void coroutine_fn qemu_co_queue_restart_all(CoQueue *queue) { - assert(qemu_in_coroutine()); + assert(qemu_in_coroutine() || qemu_coroutine_self_bypassed()); qemu_co_queue_do_restart(queue, false); } diff --git a/qemu-coroutine.c b/qemu-coroutine.c index bd574aa..324f5ad 100644 --- a/qemu-coroutine.c +++ b/qemu-coroutine.c @@ -157,3 +157,36 @@ void qemu_coroutine_adjust_pool_size(int n) qemu_mutex_unlock(&pool_lock); } + +void qemu_coroutine_set_bypass(bool bypass) +{ + Coroutine *self = qemu_coroutine_self(); + + self->bypass = bypass; +} + +bool qemu_coroutine_bypassed(Coroutine *self) +{ + return self->bypass; +} + +bool qemu_coroutine_self_bypassed(void) +{ + Coroutine *self = qemu_coroutine_self(); + + return qemu_coroutine_bypassed(self); +} + +void qemu_coroutine_set_var(void *var) +{ + Coroutine *self = qemu_coroutine_self(); + + self->opaque = var; +} + +void *qemu_coroutine_get_var(void) +{ + Coroutine *self = qemu_coroutine_self(); + + return self->opaque; +}