From patchwork Mon Feb 8 16:15:03 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 8251921 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 84B6FBEEE5 for ; Mon, 8 Feb 2016 16:23:13 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id D280320389 for ; Mon, 8 Feb 2016 16:23:12 +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 26CAA202EC for ; Mon, 8 Feb 2016 16:23:12 +0000 (UTC) Received: from localhost ([::1]:46265 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aSoal-0001ME-Ec for patchwork-qemu-devel@patchwork.kernel.org; Mon, 08 Feb 2016 11:23:11 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:57303) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aSoTO-0006NI-7Y for qemu-devel@nongnu.org; Mon, 08 Feb 2016 11:15:35 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aSoTM-0002Sh-Jv for qemu-devel@nongnu.org; Mon, 08 Feb 2016 11:15:34 -0500 Received: from mail-wm0-x241.google.com ([2a00:1450:400c:c09::241]:32837) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aSoTM-0002SY-9r for qemu-devel@nongnu.org; Mon, 08 Feb 2016 11:15:32 -0500 Received: by mail-wm0-x241.google.com with SMTP id c200so2288246wme.0 for ; Mon, 08 Feb 2016 08:15:32 -0800 (PST) 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=zZKj9X9ylJRGGPQpeH+Bie0i8VkWsNYeLxnIWdsMQNI=; b=rkFTdJ4MMnkBdJokTnbv8i31A234YJI2+pxDeVTWWX8kPjHcUQDJdk9gtSqgBAPQri 3pSMbyzgOoe9bSLwkM29TfQKQcDa53OEBXGOmokWwtRqL1nzLOaSS8AZ3oqKfDfsdTPg RIXbYFQCHf1mICvScmiqm5vzMpBZbx3R4Ttd+zYYyvVF2fSASpRes6EObIXaddFFuhuM lzSl5UBxUqcRSc21S1LOUXS77fF4/UU4UTSlA3qmbaxyuDdPPYygLBa6M2xHTchZ4+ug qIX2dB6r0FxqKOaKN0jk1psCLcZ7ANFJfG6JgMFx4ap3fpiyIBjmG+5HagYSFCFBGuAp Kp0A== 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=zZKj9X9ylJRGGPQpeH+Bie0i8VkWsNYeLxnIWdsMQNI=; b=dgxB2078NF5xqW3PJ4Bx+R17q66tIQ6+chCGOQ6IrI4JSoBGZ5fwdijfNkICwLi1r9 oRvQYRr40q2CDlFuXJSvAe4jxSyHuk1R9BpmP5eL9y+3N1an+uIp5GWfRz8G9kcoMhX+ qSv0UlG+rJvFJ69bfSPAIUS2GaqcUOnGvi3s8So0aEF2GOrLgo2VwgkbULB02lTKLCB9 wlyJWkBoBMW3XkfVaRacoiJVDANJnYAkGI0IwdLhkmIrmg5xmS/XiSp6a+eS6FoRJIWC kVaKdLHjvJx7VHbMlO4woJ0QJ+5ZHHbBxlhHJ6zVd/kItcgR2mem4gUlpU335bL8OUqa 8nXw== X-Gm-Message-State: AG10YOQiZY5IGQKz03GtTflW/p8OnRq3svp2QzehINZm0U2frlrTcEnBf4pR8qaf8nW6Og== X-Received: by 10.194.113.227 with SMTP id jb3mr29255441wjb.49.1454948131852; Mon, 08 Feb 2016 08:15:31 -0800 (PST) Received: from donizetti.lan (94-39-141-130.adsl-ull.clienti.tiscali.it. [94.39.141.130]) by smtp.gmail.com with ESMTPSA id v2sm13305429wmd.24.2016.02.08.08.15.30 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 08 Feb 2016 08:15:31 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Mon, 8 Feb 2016 17:15:03 +0100 Message-Id: <1454948107-11844-13-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 2.5.0 In-Reply-To: <1454948107-11844-1-git-send-email-pbonzini@redhat.com> References: <1454948107-11844-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::241 Cc: stefanha@redhat.com Subject: [Qemu-devel] [PATCH 12/16] aio: tweak walking in dispatch phase 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+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org 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 Preparing for the following patch, use QLIST_FOREACH_SAFE and modify the placement of walking_handlers increment/decrement. Signed-off-by: Paolo Bonzini --- aio-posix.c | 27 +++++++++++++-------------- aio-win32.c | 26 ++++++++++++-------------- 2 files changed, 25 insertions(+), 28 deletions(-) diff --git a/aio-posix.c b/aio-posix.c index 4dc075c..450da51 100644 --- a/aio-posix.c +++ b/aio-posix.c @@ -295,7 +295,7 @@ bool aio_pending(AioContext *ctx) bool aio_dispatch(AioContext *ctx) { - AioHandler *node; + AioHandler *node, *tmp; bool progress = false; /* @@ -311,12 +311,10 @@ bool aio_dispatch(AioContext *ctx) * We have to walk very carefully in case aio_set_fd_handler is * called while we're walking. */ - node = QLIST_FIRST(&ctx->aio_handlers); - while (node) { - AioHandler *tmp; - int revents; + ctx->walking_handlers++; - ctx->walking_handlers++; + QLIST_FOREACH_SAFE(node, &ctx->aio_handlers, node, tmp) { + int revents; revents = node->pfd.revents & node->pfd.events; node->pfd.revents = 0; @@ -338,17 +336,18 @@ bool aio_dispatch(AioContext *ctx) progress = true; } - tmp = node; - node = QLIST_NEXT(node, node); - - ctx->walking_handlers--; - - if (!ctx->walking_handlers && tmp->deleted) { - QLIST_REMOVE(tmp, node); - g_free(tmp); + if (node->deleted) { + ctx->walking_handlers--; + if (!ctx->walking_handlers) { + QLIST_REMOVE(node, node); + g_free(node); + } + ctx->walking_handlers++; } } + ctx->walking_handlers--; + /* Run our timers */ progress |= timerlistgroup_run_timers(&ctx->tlg); diff --git a/aio-win32.c b/aio-win32.c index 86ad822..f1a8780 100644 --- a/aio-win32.c +++ b/aio-win32.c @@ -209,20 +209,18 @@ bool aio_pending(AioContext *ctx) static bool aio_dispatch_handlers(AioContext *ctx, HANDLE event) { - AioHandler *node; + AioHandler *node, *tmp; bool progress = false; + ctx->walking_handlers++; + /* * We have to walk very carefully in case aio_set_fd_handler is * called while we're walking. */ - node = QLIST_FIRST(&ctx->aio_handlers); - while (node) { - AioHandler *tmp; + QLIST_FOREACH_SAFE(node, &ctx->aio_handlers, node, tmp) { int revents = node->pfd.revents; - ctx->walking_handlers++; - if (!node->deleted && (revents || event_notifier_get_handle(node->e) == event) && node->io_notify) { @@ -257,17 +255,17 @@ static bool aio_dispatch_handlers(AioContext *ctx, HANDLE event) } } - tmp = node; - node = QLIST_NEXT(node, node); - - ctx->walking_handlers--; - - if (!ctx->walking_handlers && tmp->deleted) { - QLIST_REMOVE(tmp, node); - g_free(tmp); + if (node->deleted) { + ctx->walking_handlers--; + if (!ctx->walking_handlers) { + QLIST_REMOVE(node, node); + g_free(node); + } + ctx->walking_handlers++; } } + ctx->walking_handlers--; return progress; }