From nobody Fri Apr 26 06:33:11 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1620041268; cv=none; d=zohomail.com; s=zohoarc; b=MIoMc6UlU0MbeiPsRbbr1QvCYvve7kieGDBR2k202VZMrAsB5l9Q3+naI3ZE10HFqkmdoQJfkx4UcVVndlmaRiweDgQFY1xsLm8p55X3HqzFpszRsJFsExcZBthOBcolKayBijAMC+XgEqAFk0hVMOOMhLsxeWTZwc79kK3BmBQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1620041268; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=GJVqL7YxAZ4sEYqWvKgnyVTzcE0p9RgiVvKoiF/1R3Q=; b=n+wojPehg8gmZYlNusHUlCUjwaff9kCP9oqx9NK2gSQF7NnHQwTD1cs6CGGvtp3CYDeQ63fDzge2IaNRz4DaXtbPA6FuZz3Xi4B7/awBhdngPcb/iy8n9j6uVJKP373RdxN9PHCswyMeY7prN7AAANoPfpdEQB4W1T3V00QnKB8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1620041268337509.8193590848716; Mon, 3 May 2021 04:27:48 -0700 (PDT) Received: from localhost ([::1]:41200 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ldWjq-000179-5s for importer@patchew.org; Mon, 03 May 2021 07:27:46 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40972) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ldWi4-0008KK-Nd for qemu-devel@nongnu.org; Mon, 03 May 2021 07:25:56 -0400 Received: from mail-ed1-x535.google.com ([2a00:1450:4864:20::535]:37776) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ldWi3-0003X0-7o for qemu-devel@nongnu.org; Mon, 03 May 2021 07:25:56 -0400 Received: by mail-ed1-x535.google.com with SMTP id y26so5858043eds.4 for ; Mon, 03 May 2021 04:25:54 -0700 (PDT) Received: from localhost.localdomain ([2001:b07:6468:f312:63a7:c72e:ea0e:6045]) by smtp.gmail.com with ESMTPSA id gn36sm2981317ejc.23.2021.05.03.04.25.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 03 May 2021 04:25:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=GJVqL7YxAZ4sEYqWvKgnyVTzcE0p9RgiVvKoiF/1R3Q=; b=H75yEHN7fH+XeLepX8Qc42hirNkYR30MCw1r+m5OvRfRY+OBTQn2Tp+zs4nFKiy3SH 2KstRs3vuqOoPz+FGz8UWQu32Nrbtg4VddcJxhFx6ReFnPYUFFmsRd+fm1vgDXBz1QIG 0ivI0jn8uAdoG3LA8ID0T3IG1/KrpRSaePxzXmrFp0WBtpC8dEMRMEAXH892FsCSPXkX Lv7D80VUD2v1ndaQi6sPMk95b0psLV2gelbfk1YxCNnAxF+GeXAoZo7P7QbwHr3ECJMp kNzRxlHBrH7kqQfSzyB+ZHqy0nhr5UcUREjIirIyz5oE5kmNY5QRRpHYhofM4B15+NGX b8gA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=GJVqL7YxAZ4sEYqWvKgnyVTzcE0p9RgiVvKoiF/1R3Q=; b=KDIAI8E5ujd9+oWon0kVomyIpiTFcbSpXwLwEr5Iy0fx6CLcEXg4+6CMVnZuOJOppp L6Sxb/NXWz/ycxRUnf+vAzbkdfG0RjaNaV3BHV/Wri6ZZzrvzY5QmIYZpC/SPeOZ2SUr YCqIYvLPWudMMv7RuqRswXceuY3Z+Sb8Lv/L+UgIO+pwQR8ll3rZVP0EN3NsHgaEpu4Q u1lCYEQAIBbEu9Pl14tJlW0RddXyQAOLnU3Xmm6bw7LAaXtm1jHIY1nQIfI2gSK9pKfP GxMY9DHiGFhwp1zH/FS0tZkX0HH4UhsdhnN4zhOM30qGlNxrJv8V9dlo8SQJxyfQbYei vDnw== X-Gm-Message-State: AOAM5302gI7xhco8UhquAEv4/1FWWsQGAlB3HZSW9E1MaNNf6pMRIGxZ OqYvF4JK3TstYhJgrq3sBAe1ozutM+4= X-Google-Smtp-Source: ABdhPJy9v/ULA2bFwUCxcmVrJCyx/bXcHO5KhimJ7ZyAw9AUbIA3+Nqx50MRFA4f6GVLoGofN9BAPA== X-Received: by 2002:a05:6402:11ca:: with SMTP id j10mr15161093edw.184.1620041153978; Mon, 03 May 2021 04:25:53 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PATCH 1/6] coroutine-sleep: use a stack-allocated timer Date: Mon, 3 May 2021 13:25:45 +0200 Message-Id: <20210503112550.478521-2-pbonzini@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210503112550.478521-1-pbonzini@redhat.com> References: <20210503112550.478521-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::535; envelope-from=paolo.bonzini@gmail.com; helo=mail-ed1-x535.google.com X-Spam_score_int: -14 X-Spam_score: -1.5 X-Spam_bar: - X-Spam_report: (-1.5 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.249, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.25, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: eesposit@redhat.com, stefanha@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" The lifetime of the timer is well-known (it cannot outlive qemu_co_sleep_ns_wakeable, because it's deleted by the time the coroutine resumes), so it is not necessary to place it on the heap. Signed-off-by: Paolo Bonzini Reviewed-by: Vladimir Sementsov-Ogievskiy --- util/qemu-coroutine-sleep.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/util/qemu-coroutine-sleep.c b/util/qemu-coroutine-sleep.c index 8c4dac4fd7..eec6e81f3f 100644 --- a/util/qemu-coroutine-sleep.c +++ b/util/qemu-coroutine-sleep.c @@ -21,7 +21,7 @@ static const char *qemu_co_sleep_ns__scheduled =3D "qemu_= co_sleep_ns"; =20 struct QemuCoSleepState { Coroutine *co; - QEMUTimer *ts; + QEMUTimer ts; QemuCoSleepState **user_state_pointer; }; =20 @@ -35,7 +35,7 @@ void qemu_co_sleep_wake(QemuCoSleepState *sleep_state) if (sleep_state->user_state_pointer) { *sleep_state->user_state_pointer =3D NULL; } - timer_del(sleep_state->ts); + timer_del(&sleep_state->ts); aio_co_wake(sleep_state->co); } =20 @@ -50,7 +50,6 @@ void coroutine_fn qemu_co_sleep_ns_wakeable(QEMUClockType= type, int64_t ns, AioContext *ctx =3D qemu_get_current_aio_context(); QemuCoSleepState state =3D { .co =3D qemu_coroutine_self(), - .ts =3D aio_timer_new(ctx, type, SCALE_NS, co_sleep_cb, &state), .user_state_pointer =3D sleep_state, }; =20 @@ -63,10 +62,11 @@ void coroutine_fn qemu_co_sleep_ns_wakeable(QEMUClockTy= pe type, int64_t ns, abort(); } =20 + aio_timer_init(ctx, &state.ts, type, SCALE_NS, co_sleep_cb, &state); if (sleep_state) { *sleep_state =3D &state; } - timer_mod(state.ts, qemu_clock_get_ns(type) + ns); + timer_mod(&state.ts, qemu_clock_get_ns(type) + ns); qemu_coroutine_yield(); if (sleep_state) { /* @@ -75,5 +75,4 @@ void coroutine_fn qemu_co_sleep_ns_wakeable(QEMUClockType= type, int64_t ns, */ assert(*sleep_state =3D=3D NULL); } - timer_free(state.ts); } --=20 2.31.1 From nobody Fri Apr 26 06:33:11 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1620041276; cv=none; d=zohomail.com; s=zohoarc; b=M9KdwjXnDc5xOT55HnhM2K/EUaGdiAXwBWq48U9g2K2wHa1ertxD1d4gEOsIIn2C9NR5MWsJQAeCkPBfmJazMNibPUJqY9BSnPkB0laW6EDg5b2NaKmvye4svHFsKPT34KbLX4nem+VuFXOCrGRaHkBHCwQKcxmoP9OkhxIXTmI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1620041276; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=dTX1qlMVrqn0zkYoEbmN6njTA5ZU+LQuOVOSTFV+c4o=; b=dduzrgaH5M60oYTYRYiursb8Na8VY8vzYSXohyrBkgbdHaA2UGN4JqeTr0rv1QiiUihK7MXa+ux5l7b67je0S4zLZmk2xrskwLh5vIe1uqLGMIUMGgPJt35g02VuJX6Mbzy/wuoFVpohjpbQOz5OhmgMSP6OAjKsD0Zt0bgce54= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 162004127699230.690466536686927; Mon, 3 May 2021 04:27:56 -0700 (PDT) Received: from localhost ([::1]:41448 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ldWjx-0001DR-OC for importer@patchew.org; Mon, 03 May 2021 07:27:54 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40988) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ldWi6-0008KV-0I for qemu-devel@nongnu.org; Mon, 03 May 2021 07:25:58 -0400 Received: from mail-ed1-x529.google.com ([2a00:1450:4864:20::529]:42925) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ldWi4-0003XB-75 for qemu-devel@nongnu.org; Mon, 03 May 2021 07:25:57 -0400 Received: by mail-ed1-x529.google.com with SMTP id j28so5823901edy.9 for ; Mon, 03 May 2021 04:25:55 -0700 (PDT) Received: from localhost.localdomain ([2001:b07:6468:f312:63a7:c72e:ea0e:6045]) by smtp.gmail.com with ESMTPSA id gn36sm2981317ejc.23.2021.05.03.04.25.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 03 May 2021 04:25:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=dTX1qlMVrqn0zkYoEbmN6njTA5ZU+LQuOVOSTFV+c4o=; b=WDATq7UIhzfD2OnvlG++ZnbUl+HkR0n5eHFVpHnUS64nZEAuWynqHfQHoZlMkCNmnd XMW9J/ZUl824wVtePzGF5QDa55AZGXj1Cem3MMjidiEAndaRhYWenWPuYtC1GtGGjTcb sVCWwE/IozbE5sb7r5RrKD36BAdqJLZ7mp7T1ShS+5/sKr7xg1UzD1EU4bEB/3mSoDC4 rZzzSNUSdHBsZ8LlxPXWPcHeIkm93ZRnWMZTfsV4pR13wGLEpQqR8y1SjcdjpGSgeaf1 GZr+6T1gyCxCCWGTXZVP65OSd1RD2+VW/lv4Rt8KGnRlluZcZXEdXh+LR8B5D56m7fnQ MIfg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=dTX1qlMVrqn0zkYoEbmN6njTA5ZU+LQuOVOSTFV+c4o=; b=Nu7M6Tfo82hsf6hSi7kZZK//0T19gm1mxMN/GhdbLZnOO258GjKr0gvKHpcr194HZK JxCCprjMAOdwwIerP8KebSDRSBiha59iyTO+YWE5ZJeAfrgOygpAGtVEQ8xGRUpwO0Iw DhCskO1vE26ZXPPV6kf2mKMIZZYZ2aHh3ZLftR2Yxn0SQ/DmvzwTA+mCOtwJEiAGQKxG OEicSr243VOTozizK7Jp7g2JEf4thtRu6r/yw4Gbc7czO8EddSzWTmDo7yH575pR4z0P eNe3457uTzLCPrQ92NX4XUfR+OTDA55u8BwaeD3Fs5uBTqssnEzeOMRPVVXn4fwP3JfU zPgg== X-Gm-Message-State: AOAM532dSZpxzF6FsdpOiGRgQXfFgMCFyN3Vv2esrNeZyNR1LXvqfSeI TTjGibHhcBSKTyBewNpJ+XVqhFohmRo= X-Google-Smtp-Source: ABdhPJy0xC11js1GuAIjQ/4i7NCnKSJzQ9f3TZfBKKaU3H3jz74t52SKOxwVqnAJetcSlqXjkDLKAw== X-Received: by 2002:a50:fc99:: with SMTP id f25mr19484673edq.147.1620041154884; Mon, 03 May 2021 04:25:54 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PATCH 2/6] coroutine-sleep: disallow NULL QemuCoSleepState** argument Date: Mon, 3 May 2021 13:25:46 +0200 Message-Id: <20210503112550.478521-3-pbonzini@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210503112550.478521-1-pbonzini@redhat.com> References: <20210503112550.478521-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::529; envelope-from=paolo.bonzini@gmail.com; helo=mail-ed1-x529.google.com X-Spam_score_int: -14 X-Spam_score: -1.5 X-Spam_bar: - X-Spam_report: (-1.5 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.249, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.25, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: eesposit@redhat.com, stefanha@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Simplify the code by removing conditionals. qemu_co_sleep_ns can simply use point the argument to an on-stack temporary. Signed-off-by: Paolo Bonzini Reviewed-by: Vladimir Sementsov-Ogievskiy --- include/qemu/coroutine.h | 5 +++-- util/qemu-coroutine-sleep.c | 18 +++++------------- 2 files changed, 8 insertions(+), 15 deletions(-) diff --git a/include/qemu/coroutine.h b/include/qemu/coroutine.h index ce5b9c6851..c5d7742989 100644 --- a/include/qemu/coroutine.h +++ b/include/qemu/coroutine.h @@ -295,7 +295,7 @@ typedef struct QemuCoSleepState QemuCoSleepState; =20 /** * Yield the coroutine for a given duration. During this yield, @sleep_sta= te - * (if not NULL) is set to an opaque pointer, which may be used for + * is set to an opaque pointer, which may be used for * qemu_co_sleep_wake(). Be careful, the pointer is set back to zero when = the * timer fires. Don't save the obtained value to other variables and don't= call * qemu_co_sleep_wake from another aio context. @@ -304,7 +304,8 @@ void coroutine_fn qemu_co_sleep_ns_wakeable(QEMUClockTy= pe type, int64_t ns, QemuCoSleepState **sleep_state= ); static inline void coroutine_fn qemu_co_sleep_ns(QEMUClockType type, int64= _t ns) { - qemu_co_sleep_ns_wakeable(type, ns, NULL); + QemuCoSleepState *unused =3D NULL; + qemu_co_sleep_ns_wakeable(type, ns, &unused); } =20 /** diff --git a/util/qemu-coroutine-sleep.c b/util/qemu-coroutine-sleep.c index eec6e81f3f..3f6f637e81 100644 --- a/util/qemu-coroutine-sleep.c +++ b/util/qemu-coroutine-sleep.c @@ -32,9 +32,7 @@ void qemu_co_sleep_wake(QemuCoSleepState *sleep_state) qemu_co_sleep_ns__scheduled, NU= LL); =20 assert(scheduled =3D=3D qemu_co_sleep_ns__scheduled); - if (sleep_state->user_state_pointer) { - *sleep_state->user_state_pointer =3D NULL; - } + *sleep_state->user_state_pointer =3D NULL; timer_del(&sleep_state->ts); aio_co_wake(sleep_state->co); } @@ -63,16 +61,10 @@ void coroutine_fn qemu_co_sleep_ns_wakeable(QEMUClockTy= pe type, int64_t ns, } =20 aio_timer_init(ctx, &state.ts, type, SCALE_NS, co_sleep_cb, &state); - if (sleep_state) { - *sleep_state =3D &state; - } + *sleep_state =3D &state; timer_mod(&state.ts, qemu_clock_get_ns(type) + ns); qemu_coroutine_yield(); - if (sleep_state) { - /* - * Note that *sleep_state is cleared during qemu_co_sleep_wake - * before resuming this coroutine. - */ - assert(*sleep_state =3D=3D NULL); - } + + /* qemu_co_sleep_wake clears *sleep_state before resuming this corouti= ne. */ + assert(*sleep_state =3D=3D NULL); } --=20 2.31.1 From nobody Fri Apr 26 06:33:11 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1620041432; cv=none; d=zohomail.com; s=zohoarc; b=fKU84e4GWHp8SrMgyeGM5LyG+ZYYBt3D72+fBTWdZeBuurx31gKx7HXopc/JUQeTrhg/JyqY/qBE1NgiQWLhkEGQ3XpEG3VjJFk7YLSLAuvinOqernkFRZGOtQWvXTFdP/xreFcKh5GZrkNM4FiA4uizezD6md6iy8GTnPndP6Q= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1620041432; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=KlDK80YilGQbH9G5IoPdIukwRost8JFR5BmMZD0EMTE=; b=kfpWtrZK3TcbpDki0MnRsoM5Jpoxb0ZbF1FqjEi0m+LwSBpXbjVENlh6jj4tSU65t19bPOUvlDvk5TatrAgygSoylokY2ZlE+2Kf6XesODzD3NEze4hZaEnAuHzrFMxNwyonRNhrVCKfCX6865ufcGERwktdgRb4qQ5idpi1wgk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1620041432140147.4356831133125; Mon, 3 May 2021 04:30:32 -0700 (PDT) Received: from localhost ([::1]:47248 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ldWmV-0003aX-32 for importer@patchew.org; Mon, 03 May 2021 07:30:31 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:41000) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ldWi6-0008Ks-Tt for qemu-devel@nongnu.org; Mon, 03 May 2021 07:25:58 -0400 Received: from mail-ed1-x530.google.com ([2a00:1450:4864:20::530]:43737) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ldWi5-0003Xv-AB for qemu-devel@nongnu.org; Mon, 03 May 2021 07:25:58 -0400 Received: by mail-ed1-x530.google.com with SMTP id e7so5815554edu.10 for ; Mon, 03 May 2021 04:25:56 -0700 (PDT) Received: from localhost.localdomain ([2001:b07:6468:f312:63a7:c72e:ea0e:6045]) by smtp.gmail.com with ESMTPSA id gn36sm2981317ejc.23.2021.05.03.04.25.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 03 May 2021 04:25:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=KlDK80YilGQbH9G5IoPdIukwRost8JFR5BmMZD0EMTE=; b=vbI2V7KLVpVA3Z5mSZOHO/6riMWZFW/hpNb+K96MSAVF4Le4ZzE3docY+pUiJ176Hd x/c/42Kv2uoCBHKop/wRWcYqE/TSghrPu5oTjt152w+BiZt9LawyH9FDW5cqy6dPanNV PjpCJprO3/ICCbciUq3O57BvzD8el01RGeDtj6Hflfn168RALJ1AyqhYesTI1V+yPrDb 5P3BJ7Rd+3f4cfa11DlWctoM8SqCwhwrzRRK+vktZg4OWbuLmP28JTeBm9gv2RgP5dKd 5CT2UTboH7jjITvxKdpQ1H2NI6PzYj+2FVmBOHPbyh/KIFJIki/o8d0vkob26QvpFCHV TziQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=KlDK80YilGQbH9G5IoPdIukwRost8JFR5BmMZD0EMTE=; b=jUlxYeoKUGAB2qdvClvUGvWSCyxH8k7ziFjlzgUyZLC9mWZJG8XvpH3aEpXdn5k+if 3Rh2NjNb2OYdq9SXwX7yHlYuNyBP4hFxgbOCfO47gL8RKPWEExMKcFBvbu3CqlWF0gRc YadIRBes0oGsk6mLgr+3owwIXFlwKe2Ia8JyyJvyBeaJdeZsttAsj0VqOwqfhTi+TDTw FYG2d+Ul/6xiZ51S7kT6hjbAm9pGkO40f4YFTUPqLwywLdiMyKCzjKMehHZ8zRpo41cP rv3pa0/fjxpNu6R69GhqfvknxD+lIsKKBvV3sk4MJWjFI/554HMAtCgtg0YRdEdB5VGx 2RJw== X-Gm-Message-State: AOAM531rv/Lw4Y1EDqcPnaswzpWvbHbA/CKr9nAS3Bu/MoMIlecu1rUe 6tF/FfHXkJr2zUn7GQk7Zy7spurWM+c= X-Google-Smtp-Source: ABdhPJylOI75404DBqoEyLb9E7UYc5Sk196DMUJiAKARvLL32IUY0Kgclyc12sqI6CtblpOsBT7oSQ== X-Received: by 2002:a05:6402:17fc:: with SMTP id t28mr19534467edy.283.1620041155894; Mon, 03 May 2021 04:25:55 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PATCH 3/6] coroutine-sleep: allow qemu_co_sleep_wake that wakes nothing Date: Mon, 3 May 2021 13:25:47 +0200 Message-Id: <20210503112550.478521-4-pbonzini@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210503112550.478521-1-pbonzini@redhat.com> References: <20210503112550.478521-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::530; envelope-from=paolo.bonzini@gmail.com; helo=mail-ed1-x530.google.com X-Spam_score_int: -14 X-Spam_score: -1.5 X-Spam_bar: - X-Spam_report: (-1.5 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.249, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.25, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: eesposit@redhat.com, stefanha@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" All callers of qemu_co_sleep_wake are checking whether they are passing a NULL argument inside the pointer-to-pointer: do the check in qemu_co_sleep_wake itself. As a side effect, qemu_co_sleep_wake can be called more than once and it will only wake the coroutine once; after the first time, the argument will be set to NULL via *sleep_state->user_state_pointer. Signed-off-by: Paolo Bonzini Reviewed-by: Vladimir Sementsov-Ogievskiy --- block/block-copy.c | 4 +--- block/nbd.c | 8 ++------ util/qemu-coroutine-sleep.c | 21 ++++++++++++--------- 3 files changed, 15 insertions(+), 18 deletions(-) diff --git a/block/block-copy.c b/block/block-copy.c index 9b4af00614..f896dc56f2 100644 --- a/block/block-copy.c +++ b/block/block-copy.c @@ -674,9 +674,7 @@ out: =20 void block_copy_kick(BlockCopyCallState *call_state) { - if (call_state->sleep_state) { - qemu_co_sleep_wake(call_state->sleep_state); - } + qemu_co_sleep_wake(call_state->sleep_state); } =20 /* diff --git a/block/nbd.c b/block/nbd.c index 1d4668d42d..1c6315b168 100644 --- a/block/nbd.c +++ b/block/nbd.c @@ -289,9 +289,7 @@ static void coroutine_fn nbd_client_co_drain_begin(Bloc= kDriverState *bs) BDRVNBDState *s =3D (BDRVNBDState *)bs->opaque; =20 s->drained =3D true; - if (s->connection_co_sleep_ns_state) { - qemu_co_sleep_wake(s->connection_co_sleep_ns_state); - } + qemu_co_sleep_wake(s->connection_co_sleep_ns_state); =20 nbd_co_establish_connection_cancel(bs, false); =20 @@ -330,9 +328,7 @@ static void nbd_teardown_connection(BlockDriverState *b= s) =20 s->state =3D NBD_CLIENT_QUIT; if (s->connection_co) { - if (s->connection_co_sleep_ns_state) { - qemu_co_sleep_wake(s->connection_co_sleep_ns_state); - } + qemu_co_sleep_wake(s->connection_co_sleep_ns_state); nbd_co_establish_connection_cancel(bs, true); } if (qemu_in_coroutine()) { diff --git a/util/qemu-coroutine-sleep.c b/util/qemu-coroutine-sleep.c index 3f6f637e81..096eea3444 100644 --- a/util/qemu-coroutine-sleep.c +++ b/util/qemu-coroutine-sleep.c @@ -27,19 +27,22 @@ struct QemuCoSleepState { =20 void qemu_co_sleep_wake(QemuCoSleepState *sleep_state) { - /* Write of schedule protected by barrier write in aio_co_schedule */ - const char *scheduled =3D qatomic_cmpxchg(&sleep_state->co->scheduled, - qemu_co_sleep_ns__scheduled, NU= LL); + if (sleep_state) { + /* Write of schedule protected by barrier write in aio_co_schedule= */ + const char *scheduled =3D qatomic_cmpxchg(&sleep_state->co->schedu= led, + qemu_co_sleep_ns__scheduled= , NULL); =20 - assert(scheduled =3D=3D qemu_co_sleep_ns__scheduled); - *sleep_state->user_state_pointer =3D NULL; - timer_del(&sleep_state->ts); - aio_co_wake(sleep_state->co); + assert(scheduled =3D=3D qemu_co_sleep_ns__scheduled); + *sleep_state->user_state_pointer =3D NULL; + timer_del(&sleep_state->ts); + aio_co_wake(sleep_state->co); + } } =20 static void co_sleep_cb(void *opaque) { - qemu_co_sleep_wake(opaque); + QemuCoSleepState **sleep_state =3D opaque; + qemu_co_sleep_wake(*sleep_state); } =20 void coroutine_fn qemu_co_sleep_ns_wakeable(QEMUClockType type, int64_t ns, @@ -60,7 +63,7 @@ void coroutine_fn qemu_co_sleep_ns_wakeable(QEMUClockType= type, int64_t ns, abort(); } =20 - aio_timer_init(ctx, &state.ts, type, SCALE_NS, co_sleep_cb, &state); + aio_timer_init(ctx, &state.ts, type, SCALE_NS, co_sleep_cb, sleep_stat= e); *sleep_state =3D &state; timer_mod(&state.ts, qemu_clock_get_ns(type) + ns); qemu_coroutine_yield(); --=20 2.31.1 From nobody Fri Apr 26 06:33:11 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1620041276; cv=none; d=zohomail.com; s=zohoarc; b=iRIDL2QsGCK6CobCzNvDX+yGtfiIVXdzxrmZvugMTsFo+mtkLOct+i8nPw3AsHxFxUxChPwP4aZPlxkyF0pdenuFrt7H5129vFZIuxVROFvd2IGX+YaqWT/PaPE1inE80rnNhyy9J7qiY5c4w5WK5w+4sXoGn0ClRkiL9FoY2m0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1620041276; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=gAYRYwWRZ16e9tOKn/1g9T/J1cAn4xBH38wpU2HJJek=; b=jFYhXEBveiKDzNV33yFMTS9C5O9Joy8Vmk6+UmvQtRnlNb74Rwy+CsuQWg34rt+zaTDuH0zYHln8WTPfZUdfrbwhR2MP+fKTrdaxD8Fd2qEr7GTihsOGRrYiYNETIt+XS/5c6zb6YJzIPkrMAWqeU+w00Zy/tgi5znKhYduOjBU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1620041276971962.6534980808325; Mon, 3 May 2021 04:27:56 -0700 (PDT) Received: from localhost ([::1]:41434 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ldWjy-0001D7-OP for importer@patchew.org; Mon, 03 May 2021 07:27:54 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:41018) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ldWi7-0008Lm-Ri for qemu-devel@nongnu.org; Mon, 03 May 2021 07:25:59 -0400 Received: from mail-ej1-x636.google.com ([2a00:1450:4864:20::636]:41982) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ldWi6-0003Ym-8x for qemu-devel@nongnu.org; Mon, 03 May 2021 07:25:59 -0400 Received: by mail-ej1-x636.google.com with SMTP id zg3so7286113ejb.8 for ; Mon, 03 May 2021 04:25:57 -0700 (PDT) Received: from localhost.localdomain ([2001:b07:6468:f312:63a7:c72e:ea0e:6045]) by smtp.gmail.com with ESMTPSA id gn36sm2981317ejc.23.2021.05.03.04.25.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 03 May 2021 04:25:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=gAYRYwWRZ16e9tOKn/1g9T/J1cAn4xBH38wpU2HJJek=; b=XEoNr/3WotaFEKaLOaGqzK6QkhRgJvoKO2G+n0tZ8v45pS3gZsNDC33LdnA3L8m9QN i6A8QLFEoWaL1DjiYZtFGFH/561gEEQj6l9VUSCRX5vOIhcBuQjBUT9N0LrXGXXHVWZ9 eEJQpe/1+e6yMFadszDNw1+452J3tQy8y4HO6kDKyWBICVmanICM3jrWzwb4sC5CDxWR 0VDblUYE1aPNb8sBDPU6LksWr3KMlWkoRuznxA5nmOySXzjjzQk1PmRHhOLtyHWQV7Vd wZtG7hM96NErWXlXJRDysq0IUdVe5gvQHVwFtxj7WFoS0SZVrTSO4WJEyCjUsQ7+YB5k LuIg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=gAYRYwWRZ16e9tOKn/1g9T/J1cAn4xBH38wpU2HJJek=; b=XgIJzTMm328U0PA18Vm0BRjRROKxVuQa5PqsjdrWbfZ4hV9czPtL5aGZEVo7GH5itu 7s6UtUrjKmtHayFwIFEPUGKqx7FIfF3Dc4Y6RwPKOif+2ZaqtIINsmEuV581JuiXdbeg 7MpPqnLRu3EOlJUGhN3r9317sUFUsFpTlRurE6gKJ3KLna7byTTc6kNAeRHlbHNXGP8r 7HXOeX8PfBQDTdOGHYHsQT4nWStTTCiIWsyMolrVBrYO9YE4P4KcRuF8snkdB7+JsGeN JpkoLks7q8Tp44Yqfxmpv4NfdnOFVU9GRfiCdGIP5UmsbGUlpKpHrhRWyYHlB8zBf5y/ CeEw== X-Gm-Message-State: AOAM5320fFVi66XZBw8KHd/zstBsGInlwcQNTHcakRROHqGFrvytmqEp dY6X3N58XoWvYqNL6nxgpTeNOE/Ug8w= X-Google-Smtp-Source: ABdhPJxo0GYPf95ZoOKkYEcz/xClQRuM33Uk5S3ctmDVdtK6GZH2wFoS5yHHHy+AnsGUtDooKK6yDA== X-Received: by 2002:a17:906:1957:: with SMTP id b23mr16266840eje.209.1620041157001; Mon, 03 May 2021 04:25:57 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PATCH 4/6] coroutine-sleep: move timer out of QemuCoSleepState Date: Mon, 3 May 2021 13:25:48 +0200 Message-Id: <20210503112550.478521-5-pbonzini@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210503112550.478521-1-pbonzini@redhat.com> References: <20210503112550.478521-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::636; envelope-from=paolo.bonzini@gmail.com; helo=mail-ej1-x636.google.com X-Spam_score_int: -14 X-Spam_score: -1.5 X-Spam_bar: - X-Spam_report: (-1.5 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.249, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.25, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: eesposit@redhat.com, stefanha@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" This simplification is enabled by the previous patch. Now aio_co_wake will only be called once, therefore we do not care about a spurious firing of the timer after a qemu_co_sleep_wake. Signed-off-by: Paolo Bonzini Reviewed-by: Vladimir Sementsov-Ogievskiy --- util/qemu-coroutine-sleep.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/util/qemu-coroutine-sleep.c b/util/qemu-coroutine-sleep.c index 096eea3444..68e9505b2e 100644 --- a/util/qemu-coroutine-sleep.c +++ b/util/qemu-coroutine-sleep.c @@ -21,7 +21,6 @@ static const char *qemu_co_sleep_ns__scheduled =3D "qemu_= co_sleep_ns"; =20 struct QemuCoSleepState { Coroutine *co; - QEMUTimer ts; QemuCoSleepState **user_state_pointer; }; =20 @@ -34,7 +33,6 @@ void qemu_co_sleep_wake(QemuCoSleepState *sleep_state) =20 assert(scheduled =3D=3D qemu_co_sleep_ns__scheduled); *sleep_state->user_state_pointer =3D NULL; - timer_del(&sleep_state->ts); aio_co_wake(sleep_state->co); } } @@ -49,6 +47,7 @@ void coroutine_fn qemu_co_sleep_ns_wakeable(QEMUClockType= type, int64_t ns, QemuCoSleepState **sleep_state) { AioContext *ctx =3D qemu_get_current_aio_context(); + QEMUTimer ts; QemuCoSleepState state =3D { .co =3D qemu_coroutine_self(), .user_state_pointer =3D sleep_state, @@ -63,10 +62,11 @@ void coroutine_fn qemu_co_sleep_ns_wakeable(QEMUClockTy= pe type, int64_t ns, abort(); } =20 - aio_timer_init(ctx, &state.ts, type, SCALE_NS, co_sleep_cb, sleep_stat= e); + aio_timer_init(ctx, &ts, type, SCALE_NS, co_sleep_cb, sleep_state); *sleep_state =3D &state; - timer_mod(&state.ts, qemu_clock_get_ns(type) + ns); + timer_mod(&ts, qemu_clock_get_ns(type) + ns); qemu_coroutine_yield(); + timer_del(&ts); =20 /* qemu_co_sleep_wake clears *sleep_state before resuming this corouti= ne. */ assert(*sleep_state =3D=3D NULL); --=20 2.31.1 From nobody Fri Apr 26 06:33:11 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1620041590; cv=none; d=zohomail.com; s=zohoarc; b=Aopw8As9tvl75bmR6Oe/pHYY9nRAV6VFg05W7doJu1SpLovAASZHN3TlAZ7PoEybaYvRTri0oB2ugeQXiVXus+/fqjlM8OFgEHLwoezuNKpPDtYMy00v+BooXtDt5ywGXqAFMGhlRmQ7pAYBgCrrbYKaKKthf2CKM2iH7LHbLBQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1620041590; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=5p+3yN+Yh1iAcodyMR7jx5UwKvprh6OFt0ccBlBRot8=; b=hNldmDuS9QiC77iSGFUahyygJ3bsG++B22RThVQvTIzOa5hlfZ0OVxtkoSxk+TPVgzXhqgYUAL/RJNqB07DTbilFtKHoQmD0YBSXqoj/0/1A0X/TbKEqfVRWqirPMYlbQvh1I041i0myQBMuhx/Kry9DUC/Ykwa2UwWmX13iK2w= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 162004159050880.50285603584905; Mon, 3 May 2021 04:33:10 -0700 (PDT) Received: from localhost ([::1]:52616 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ldWp3-0005xl-GN for importer@patchew.org; Mon, 03 May 2021 07:33:09 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:41044) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ldWi9-0008Mq-3Y for qemu-devel@nongnu.org; Mon, 03 May 2021 07:26:01 -0400 Received: from mail-ej1-x62e.google.com ([2a00:1450:4864:20::62e]:44817) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ldWi7-0003Zc-8W for qemu-devel@nongnu.org; Mon, 03 May 2021 07:26:00 -0400 Received: by mail-ej1-x62e.google.com with SMTP id gx5so7277284ejb.11 for ; Mon, 03 May 2021 04:25:58 -0700 (PDT) Received: from localhost.localdomain ([2001:b07:6468:f312:63a7:c72e:ea0e:6045]) by smtp.gmail.com with ESMTPSA id gn36sm2981317ejc.23.2021.05.03.04.25.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 03 May 2021 04:25:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=5p+3yN+Yh1iAcodyMR7jx5UwKvprh6OFt0ccBlBRot8=; b=mp8UP3TSyZLSKoFBZcPEcXtP8F9vR0olIsWhw5qjpSGsACjd0ZNgqJecRaIyCcQBHB BqscV7xkjO5Lb++njUkrGu472EMUhmMbx3UFcnmLqnV8QTXg6ufDptM0fi4qHorpJ8qu RC31VfEaLqiaJflZM8a63z2C09sTUAxL3mrG6Y1/520RmCJzX9VUJsvOHXgHt2LpRD9Q SgmHxdIY+22QsHuOV7oOXdbm1opSOaDxd/3k6UsK/DmI0ht1Y1C/Bfm5mnrAvKfwqm0j HrqgKCBLEspV175OHEwn8W/vCmHbvZUcRR5YSQru3LZTFJEh1qrdVm2Qlem+D29Q0jAj 1zJg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=5p+3yN+Yh1iAcodyMR7jx5UwKvprh6OFt0ccBlBRot8=; b=QzrNGrx2bTQQS2SsIPXJk2NCLcJbpVxK06+0bFg8JdvUHOUBc6mQxjAg7gwJNqknv3 8rmyicyRykJyckb0p1J+VRXOhuCQkC69Kc4IbNRMVDVHpTZGovXZe9Vzs75gsA+RcnA2 aUlLJFp0oYaKrHjngYa1zIPjEvpiUPloyKd0IBV+pzMn4f7Zri9BoDUfDCbr5bOMveVP Hn0znz3UxL+MJXWcNfpMj13EPjJSoxIOGC/3LJySyYG/cn79rtn52Cakm6IIQZJ5ReJX xeho74gwShqPRmIxaZw8zCo/TEfVu97Q1riNtMwCGkLN4DooYmsUNY2KsCoEvVbMH2tq R5gA== X-Gm-Message-State: AOAM533zRiQVv74+RL4qIN/dLGMxFu80Uwe0OHxPMSdm3w8fdXaiLk2c 5pP+TJTzW+5U368o1yFLQsmACUISHro= X-Google-Smtp-Source: ABdhPJw9ToxtysrL50qnJpddm4hRfAHS6BvTzXoQNyFgvNcNtpy85ilyhOnGviWDbIhUcpXmRUGaYQ== X-Received: by 2002:a17:906:2510:: with SMTP id i16mr16059269ejb.488.1620041157912; Mon, 03 May 2021 04:25:57 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PATCH 5/6] coroutine-sleep: replace QemuCoSleepState pointer with struct in the API Date: Mon, 3 May 2021 13:25:49 +0200 Message-Id: <20210503112550.478521-6-pbonzini@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210503112550.478521-1-pbonzini@redhat.com> References: <20210503112550.478521-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::62e; envelope-from=paolo.bonzini@gmail.com; helo=mail-ej1-x62e.google.com X-Spam_score_int: -14 X-Spam_score: -1.5 X-Spam_bar: - X-Spam_report: (-1.5 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.249, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.25, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: eesposit@redhat.com, stefanha@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Right now, users of qemu_co_sleep_ns_wakeable are passing a pointer to QemuCoSleepState by reference to the function, but QemuCoSleepState really is just a Coroutine*. Making the content of the struct public is just as efficient and lets us skip the user_state_pointer indirection: the Coroutine* is cleared directly, rather than the pointer to it. Since the usage is changed, take the occasion to rename the struct to QemuCoSleep. Signed-off-by: Paolo Bonzini Reviewed-by: Vladimir Sementsov-Ogievskiy --- block/block-copy.c | 8 +++---- block/nbd.c | 10 ++++----- include/qemu/coroutine.h | 22 +++++++++---------- util/qemu-coroutine-sleep.c | 43 ++++++++++++++++--------------------- 4 files changed, 39 insertions(+), 44 deletions(-) diff --git a/block/block-copy.c b/block/block-copy.c index f896dc56f2..c2e5090412 100644 --- a/block/block-copy.c +++ b/block/block-copy.c @@ -50,7 +50,7 @@ typedef struct BlockCopyCallState { /* State */ int ret; bool finished; - QemuCoSleepState *sleep_state; + QemuCoSleep sleep; bool cancelled; =20 /* OUT parameters */ @@ -625,8 +625,8 @@ block_copy_dirty_clusters(BlockCopyCallState *call_stat= e) if (ns > 0) { block_copy_task_end(task, -EAGAIN); g_free(task); - qemu_co_sleep_ns_wakeable(QEMU_CLOCK_REALTIME, ns, - &call_state->sleep_state); + qemu_co_sleep_ns_wakeable(&call_state->sleep, + QEMU_CLOCK_REALTIME, ns); continue; } } @@ -674,7 +674,7 @@ out: =20 void block_copy_kick(BlockCopyCallState *call_state) { - qemu_co_sleep_wake(call_state->sleep_state); + qemu_co_sleep_wake(&call_state->sleep); } =20 /* diff --git a/block/nbd.c b/block/nbd.c index 1c6315b168..616f9ae6c4 100644 --- a/block/nbd.c +++ b/block/nbd.c @@ -116,7 +116,7 @@ typedef struct BDRVNBDState { CoQueue free_sema; Coroutine *connection_co; Coroutine *teardown_co; - QemuCoSleepState *connection_co_sleep_ns_state; + QemuCoSleep reconnect_sleep; bool drained; bool wait_drained_end; int in_flight; @@ -289,7 +289,7 @@ static void coroutine_fn nbd_client_co_drain_begin(Bloc= kDriverState *bs) BDRVNBDState *s =3D (BDRVNBDState *)bs->opaque; =20 s->drained =3D true; - qemu_co_sleep_wake(s->connection_co_sleep_ns_state); + qemu_co_sleep_wake(&s->reconnect_sleep); =20 nbd_co_establish_connection_cancel(bs, false); =20 @@ -328,7 +328,7 @@ static void nbd_teardown_connection(BlockDriverState *b= s) =20 s->state =3D NBD_CLIENT_QUIT; if (s->connection_co) { - qemu_co_sleep_wake(s->connection_co_sleep_ns_state); + qemu_co_sleep_wake(&s->reconnect_sleep); nbd_co_establish_connection_cancel(bs, true); } if (qemu_in_coroutine()) { @@ -685,8 +685,8 @@ static coroutine_fn void nbd_co_reconnect_loop(BDRVNBDS= tate *s) } bdrv_inc_in_flight(s->bs); } else { - qemu_co_sleep_ns_wakeable(QEMU_CLOCK_REALTIME, timeout, - &s->connection_co_sleep_ns_state); + qemu_co_sleep_ns_wakeable(&s->reconnect_sleep, + QEMU_CLOCK_REALTIME, timeout); if (s->drained) { continue; } diff --git a/include/qemu/coroutine.h b/include/qemu/coroutine.h index c5d7742989..77cb8ce459 100644 --- a/include/qemu/coroutine.h +++ b/include/qemu/coroutine.h @@ -291,21 +291,21 @@ void qemu_co_rwlock_wrlock(CoRwlock *lock); */ void qemu_co_rwlock_unlock(CoRwlock *lock); =20 -typedef struct QemuCoSleepState QemuCoSleepState; +typedef struct QemuCoSleep { + Coroutine *to_wake; +} QemuCoSleep; =20 /** - * Yield the coroutine for a given duration. During this yield, @sleep_sta= te - * is set to an opaque pointer, which may be used for - * qemu_co_sleep_wake(). Be careful, the pointer is set back to zero when = the - * timer fires. Don't save the obtained value to other variables and don't= call - * qemu_co_sleep_wake from another aio context. + * Yield the coroutine for a given duration. During this yield, @w + * can be used with qemu_co_sleep_wake() to terminate the sleep. */ -void coroutine_fn qemu_co_sleep_ns_wakeable(QEMUClockType type, int64_t ns, - QemuCoSleepState **sleep_state= ); +void coroutine_fn qemu_co_sleep_ns_wakeable(QemuCoSleep *w, + QEMUClockType type, int64_t ns= ); + static inline void coroutine_fn qemu_co_sleep_ns(QEMUClockType type, int64= _t ns) { - QemuCoSleepState *unused =3D NULL; - qemu_co_sleep_ns_wakeable(type, ns, &unused); + QemuCoSleep w =3D { 0 }; + qemu_co_sleep_ns_wakeable(&w, type, ns); } =20 /** @@ -314,7 +314,7 @@ static inline void coroutine_fn qemu_co_sleep_ns(QEMUCl= ockType type, int64_t ns) * qemu_co_sleep_ns() and should be checked to be non-NULL before calling * qemu_co_sleep_wake(). */ -void qemu_co_sleep_wake(QemuCoSleepState *sleep_state); +void qemu_co_sleep_wake(QemuCoSleep *w); =20 /** * Yield until a file descriptor becomes readable diff --git a/util/qemu-coroutine-sleep.c b/util/qemu-coroutine-sleep.c index 68e9505b2e..89c3b758c5 100644 --- a/util/qemu-coroutine-sleep.c +++ b/util/qemu-coroutine-sleep.c @@ -19,42 +19,37 @@ =20 static const char *qemu_co_sleep_ns__scheduled =3D "qemu_co_sleep_ns"; =20 -struct QemuCoSleepState { +void qemu_co_sleep_wake(QemuCoSleep *w) +{ Coroutine *co; - QemuCoSleepState **user_state_pointer; -}; =20 -void qemu_co_sleep_wake(QemuCoSleepState *sleep_state) -{ - if (sleep_state) { + co =3D w->to_wake; + w->to_wake =3D NULL; + if (co) { /* Write of schedule protected by barrier write in aio_co_schedule= */ - const char *scheduled =3D qatomic_cmpxchg(&sleep_state->co->schedu= led, - qemu_co_sleep_ns__scheduled= , NULL); + const char *scheduled =3D qatomic_cmpxchg(&co->scheduled, + qemu_co_sleep_ns__schedule= d, NULL); =20 assert(scheduled =3D=3D qemu_co_sleep_ns__scheduled); - *sleep_state->user_state_pointer =3D NULL; - aio_co_wake(sleep_state->co); + aio_co_wake(co); } } =20 static void co_sleep_cb(void *opaque) { - QemuCoSleepState **sleep_state =3D opaque; - qemu_co_sleep_wake(*sleep_state); + QemuCoSleep *w =3D opaque; + qemu_co_sleep_wake(w); } =20 -void coroutine_fn qemu_co_sleep_ns_wakeable(QEMUClockType type, int64_t ns, - QemuCoSleepState **sleep_state) +void coroutine_fn qemu_co_sleep_ns_wakeable(QemuCoSleep *w, + QEMUClockType type, int64_t ns) { + Coroutine *co =3D qemu_coroutine_self(); AioContext *ctx =3D qemu_get_current_aio_context(); QEMUTimer ts; - QemuCoSleepState state =3D { - .co =3D qemu_coroutine_self(), - .user_state_pointer =3D sleep_state, - }; =20 - const char *scheduled =3D qatomic_cmpxchg(&state.co->scheduled, NULL, - qemu_co_sleep_ns__scheduled); + const char *scheduled =3D qatomic_cmpxchg(&co->scheduled, NULL, + qemu_co_sleep_ns__scheduled); if (scheduled) { fprintf(stderr, "%s: Co-routine was already scheduled in '%s'\n", @@ -62,12 +57,12 @@ void coroutine_fn qemu_co_sleep_ns_wakeable(QEMUClockTy= pe type, int64_t ns, abort(); } =20 - aio_timer_init(ctx, &ts, type, SCALE_NS, co_sleep_cb, sleep_state); - *sleep_state =3D &state; + w->to_wake =3D co; + aio_timer_init(ctx, &ts, type, SCALE_NS, co_sleep_cb, w), timer_mod(&ts, qemu_clock_get_ns(type) + ns); qemu_coroutine_yield(); timer_del(&ts); =20 - /* qemu_co_sleep_wake clears *sleep_state before resuming this corouti= ne. */ - assert(*sleep_state =3D=3D NULL); + /* w->to_wake is cleared before resuming this coroutine. */ + assert(w->to_wake =3D=3D NULL); } --=20 2.31.1 From nobody Fri Apr 26 06:33:11 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1620041577; cv=none; d=zohomail.com; s=zohoarc; b=UezanvZUdu5l0t4L2dB4iro0TgWKXhg4FdLWztJMwE13++fQoq5edVMwIxaUwE3E5bZbM4tJqxzS5bCxhcbGk5LaM2C3Kgk6iTKVCTNWVmOAfJzZOGkVEXQyOTW2hsPDyCajyGb4AN9XxpY1IQi+kn9emugfYv91NQf4pu3re6c= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1620041577; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=TkN11ZFUhG5EwQKBzw6s1Q7HDR8GxGfhT1cjSruZpQM=; b=buljNXrfmzXnEJ6IYabScA806HkDKuTI6lhoraCUDUK98IBKtWcgAYl8Zj6v8ZcWf437wHGYpUFhF2QkcCKol50DG/guPoLCk+5AuMjo2jv2w1grt9u9yHGDp+TPXB4744bpuzFISV+eYs/YGNMWo0c8MaSvaRZ2BN5aJNqAh3o= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1620041577781953.4927468527053; Mon, 3 May 2021 04:32:57 -0700 (PDT) Received: from localhost ([::1]:52252 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ldWop-0005nN-8W for importer@patchew.org; Mon, 03 May 2021 07:32:55 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:41050) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ldWi9-0008OX-SU for qemu-devel@nongnu.org; Mon, 03 May 2021 07:26:01 -0400 Received: from mail-ed1-x534.google.com ([2a00:1450:4864:20::534]:34533) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ldWi8-0003aP-4A for qemu-devel@nongnu.org; Mon, 03 May 2021 07:26:01 -0400 Received: by mail-ed1-x534.google.com with SMTP id i3so5865505edt.1 for ; Mon, 03 May 2021 04:25:59 -0700 (PDT) Received: from localhost.localdomain ([2001:b07:6468:f312:63a7:c72e:ea0e:6045]) by smtp.gmail.com with ESMTPSA id gn36sm2981317ejc.23.2021.05.03.04.25.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 03 May 2021 04:25:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=TkN11ZFUhG5EwQKBzw6s1Q7HDR8GxGfhT1cjSruZpQM=; b=gY4MwFJnZl+kETO2gvfLrblyZ8H3muGeeRCr+mdfb5hG8j2yH6KG6rKN3wEJST64pS 2DJ8GZ5BSKDEbBOnGBW9pL2390ERQHh4a5FS3phkAXYueeAd/bAww17Eo0qBr1i15t3+ Woh4N2xKWl2yQzGYEezmbfimIEUGSDgZ8tHjODDaPsjmPiQCjCtgBzoMQuTdIYsPqgiz QXIRuqfJcY5meV/FI23OTujjS47dmdLY14SEAZRen5UECx8kmaz3LRnx7fpQ1rZs/7Es RG3ZdvNXa68lvp+U3akHJthw/B2tkiW2lUl47x6N5H+4/tN+VNTq4F4KexNKzdLvdadX hQMg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=TkN11ZFUhG5EwQKBzw6s1Q7HDR8GxGfhT1cjSruZpQM=; b=AA1et/ocLREJdSpVXsadZXJrmC7jiiP5QllEEJmtrxfK2f3sHEqt0UbdoTmQ9oZib2 YoCITWUKDOW0T2+RkPHbKGnVkzhEtj1Yhy7pWM6Ou+tEavqpGAwO1Y4/9kDVWf0QoTOw rJ78hBUQEZSFMpSIkjztc7LovmmWQsZmSbLqYqwrcLi/C8gimoBAMajCDFqETqE6G7Tk W+C4uGgJKRSW78ff7zzzbPTo0SKZf0rzNpD8lGgg+0LnKNeqoqSjGcOMPzOjxapLGcCB v56aTGKMBrQFyrFvgc7K1pz1A+Dfi4qK4iJff+0HhaxBrWOcAOhQ9frEmlVgPb3Q8bLv 46/g== X-Gm-Message-State: AOAM533xo7hfbKJw+79eeyb0zwGknSwKKlA5ZqRQ751KB1wsnoEbs/8n hRCHl8qG6GDbzJs7tm8T82nlaMuZo3k= X-Google-Smtp-Source: ABdhPJzKuQ8087hr+02KMLukTMMcxaMci4c40h3BZ3AZr7vBSoHfmtDJ/Zp3HIWfMwgMzhS/yoTs6A== X-Received: by 2002:a05:6402:3072:: with SMTP id bs18mr15021156edb.367.1620041158823; Mon, 03 May 2021 04:25:58 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PATCH 6/6] coroutine-sleep: introduce qemu_co_sleep Date: Mon, 3 May 2021 13:25:50 +0200 Message-Id: <20210503112550.478521-7-pbonzini@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210503112550.478521-1-pbonzini@redhat.com> References: <20210503112550.478521-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::534; envelope-from=paolo.bonzini@gmail.com; helo=mail-ed1-x534.google.com X-Spam_score_int: -14 X-Spam_score: -1.5 X-Spam_bar: - X-Spam_report: (-1.5 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.249, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.25, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: eesposit@redhat.com, stefanha@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Allow using QemuCoSleep to sleep forever until woken by qemu_co_sleep_wake. This makes the logic of qemu_co_sleep_ns_wakeable easy to understand. In the future we could introduce an API that can work even if the sleep and wake happen from different threads. For now, initializing w->to_wake after timer_mod is fine because the timer can only fire in the same AioContext. Signed-off-by: Paolo Bonzini Reviewed-by: Vladimir Sementsov-Ogievskiy --- include/qemu/coroutine.h | 5 +++++ util/qemu-coroutine-sleep.c | 20 +++++++++++++------- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/include/qemu/coroutine.h b/include/qemu/coroutine.h index 77cb8ce459..b53e9632b9 100644 --- a/include/qemu/coroutine.h +++ b/include/qemu/coroutine.h @@ -302,6 +302,11 @@ typedef struct QemuCoSleep { void coroutine_fn qemu_co_sleep_ns_wakeable(QemuCoSleep *w, QEMUClockType type, int64_t ns= ); =20 +/** + * Yield the coroutine until the next call to qemu_co_sleep_wake. + */ +void coroutine_fn qemu_co_sleep(QemuCoSleep *w); + static inline void coroutine_fn qemu_co_sleep_ns(QEMUClockType type, int64= _t ns) { QemuCoSleep w =3D { 0 }; diff --git a/util/qemu-coroutine-sleep.c b/util/qemu-coroutine-sleep.c index 89c3b758c5..df6edba2e4 100644 --- a/util/qemu-coroutine-sleep.c +++ b/util/qemu-coroutine-sleep.c @@ -41,12 +41,9 @@ static void co_sleep_cb(void *opaque) qemu_co_sleep_wake(w); } =20 -void coroutine_fn qemu_co_sleep_ns_wakeable(QemuCoSleep *w, - QEMUClockType type, int64_t ns) +void coroutine_fn qemu_co_sleep(QemuCoSleep *w) { Coroutine *co =3D qemu_coroutine_self(); - AioContext *ctx =3D qemu_get_current_aio_context(); - QEMUTimer ts; =20 const char *scheduled =3D qatomic_cmpxchg(&co->scheduled, NULL, qemu_co_sleep_ns__scheduled); @@ -58,11 +55,20 @@ void coroutine_fn qemu_co_sleep_ns_wakeable(QemuCoSleep= *w, } =20 w->to_wake =3D co; - aio_timer_init(ctx, &ts, type, SCALE_NS, co_sleep_cb, w), - timer_mod(&ts, qemu_clock_get_ns(type) + ns); qemu_coroutine_yield(); - timer_del(&ts); =20 /* w->to_wake is cleared before resuming this coroutine. */ assert(w->to_wake =3D=3D NULL); } + +void coroutine_fn qemu_co_sleep_ns_wakeable(QemuCoSleep *w, + QEMUClockType type, int64_t ns) +{ + AioContext *ctx =3D qemu_get_current_aio_context(); + QEMUTimer ts; + + aio_timer_init(ctx, &ts, type, SCALE_NS, co_sleep_cb, w); + timer_mod(&ts, qemu_clock_get_ns(type) + ns); + qemu_co_sleep(w); + timer_del(&ts); +} --=20 2.31.1