From nobody Sun May 5 12:11:54 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1503676481733153.07993667353344; Fri, 25 Aug 2017 08:54:41 -0700 (PDT) Received: from localhost ([::1]:53857 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dlGwS-0006Mm-IR for importer@patchew.org; Fri, 25 Aug 2017 11:54:40 -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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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 =3D=3D -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, siz= e_t nmemb, void *opaque) =20 acb->ret =3D 0; s->acb[i] =3D NULL; - qemu_mutex_unlock(&s->s->mutex); - aio_co_wake(acb->co); - qemu_mutex_lock(&s->s->mutex); + + if (qemu_coroutine_self() !=3D acb->co) { + qemu_mutex_unlock(&s->s->mutex); + aio_co_wake(acb->co); + qemu_mutex_lock(&s->s->mutex); + } } } =20 --=20 2.7.4