From patchwork Fri Aug 25 15:52:26 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Evgeny Yakovlev X-Patchwork-Id: 9922365 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 0B3C8602BD for ; Fri, 25 Aug 2017 15:54:29 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id F2196283A5 for ; Fri, 25 Aug 2017 15:54:28 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E70DB283BB; Fri, 25 Aug 2017 15:54:28 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=ham version=3.3.1 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.wl.linuxfoundation.org (Postfix) with ESMTPS id EAA8B283BD for ; Fri, 25 Aug 2017 15:54:27 +0000 (UTC) Received: from localhost ([::1]:53856 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dlGwF-00064l-1b for patchwork-qemu-devel@patchwork.kernel.org; Fri, 25 Aug 2017 11:54:27 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36304) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dlGuV-0005XK-Up for qemu-devel@nongnu.org; Fri, 25 Aug 2017 11:52:40 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dlGuR-00024i-Um for qemu-devel@nongnu.org; Fri, 25 Aug 2017 11:52:40 -0400 Received: from forwardcorp1o.cmail.yandex.net ([37.9.109.47]:55794) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dlGuR-00022W-K8 for qemu-devel@nongnu.org; Fri, 25 Aug 2017 11:52:35 -0400 Received: from smtpcorp1p.mail.yandex.net (smtpcorp1p.mail.yandex.net [IPv6:2a02:6b8:0:1472:2741:0:8b6:10]) by forwardcorp1o.cmail.yandex.net (Yandex) with ESMTP id 121CA20B54; Fri, 25 Aug 2017 18:52:30 +0300 (MSK) Received: from smtpcorp1p.mail.yandex.net (localhost.localdomain [127.0.0.1]) by smtpcorp1p.mail.yandex.net (Yandex) with ESMTP id 0B2636E40DC8; Fri, 25 Aug 2017 18:52:30 +0300 (MSK) Received: from unknown (unknown [2a02:6b8:0:40c:50b6:478d:cbd0:e84a]) by smtpcorp1p.mail.yandex.net (nwsmtp/Yandex) with ESMTPSA id TOecnH0c5v-qTRKqQ7V; Fri, 25 Aug 2017 18:52:30 +0300 (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (Client certificate not present) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1503676350; bh=V64gihF6Uz8bUa6z0xjs/jpHwHdXRAAzRJtFHoykuZ8=; h=From:To:Cc:Subject:Date:Message-Id; b=yOI8ttroAVA801w1+9HQYjSc43l95rykRVDCyDvfsaX6oPq8xoUtma//GwIUIvHOt Y/yNuxCOLw+YTuYBWgu/npEBdyA4SRr6flEaJ+NchD8dBpzXkdcfM+tUCbNWuvBE5d Qjt/tUqu+vQVyDAlesFrLVWykJQY4Gx8YrfwlVm0= Authentication-Results: smtpcorp1p.mail.yandex.net; dkim=pass header.i=@yandex-team.ru From: Evgeny Yakovlev To: qemu-devel@nongnu.org, jcody@redhat.com Date: Fri, 25 Aug 2017 18:52:26 +0300 Message-Id: <1503676346-3762-1-git-send-email-wrfsh@yandex-team.ru> X-Mailer: git-send-email 2.7.4 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 37.9.109.47 Subject: [Qemu-devel] [PATCH] block/curl: wake read completion coroutine only if necessary 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: asmetanin@yandex-team.ru, Evgeny Yakovlev Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP When curl_co_preadv is called it sets up an ACB block which points to current coroutine. It will then call curl_setup_preadv and wait until request is completed by polling return status and yeilding: curl_setup_preadv(bs, &acb); while (acb.ret == -EINPROGRESS) { qemu_coroutine_yield(); } curl_setup_preadv will ask libcurl to handle read request and to use curl_read_cb as completion callback for each completed chunk. When curl_read_cb sees request as completed it will attempt to wake up issuing coroutine assuming that yield was called previously: qemu_mutex_unlock(&s->s->mutex); aio_co_wake(acb->co); qemu_mutex_lock(&s->s->mutex); However if request is short enough (< 16K in our test) curl_read_cb will be called right away before returning from libcurl to curl_setup_preadv. Request will be completed before yield was called from the same coroutine, which asserts in aio_co_enter. This change attempts to fix this by waking completion coroutine only if it is not the current one. Signed-off-by: Evgeny Yakovlev --- block/curl.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/block/curl.c b/block/curl.c index 2a244e2..b1106d6 100644 --- a/block/curl.c +++ b/block/curl.c @@ -271,9 +271,12 @@ static size_t curl_read_cb(void *ptr, size_t size, size_t nmemb, void *opaque) acb->ret = 0; s->acb[i] = NULL; - qemu_mutex_unlock(&s->s->mutex); - aio_co_wake(acb->co); - qemu_mutex_lock(&s->s->mutex); + + if (qemu_coroutine_self() != acb->co) { + qemu_mutex_unlock(&s->s->mutex); + aio_co_wake(acb->co); + qemu_mutex_lock(&s->s->mutex); + } } }