From patchwork Mon Feb 26 16:56:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 775902 Delivered-To: patch@linaro.org Received: by 2002:ab3:621a:0:b0:258:3251:9e33 with SMTP id w26csp1482085lte; Mon, 26 Feb 2024 09:09:38 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCV6QzBaWStp4luHEJ5bmqT7uSeLJkGh5oM9aRehtoAWlbF1lWL1PW3FMWRshIlFMWCtR3887PQZ9rqT+WAjKbhg X-Google-Smtp-Source: AGHT+IF+2MTqSXSWmp3HCtoLw4YGpWTK4vTNM00BZIik7CVOB6bbBcrDqOxT/qR+1asmlRgPUWnJ X-Received: by 2002:a05:6830:1691:b0:6e4:8c2b:c739 with SMTP id k17-20020a056830169100b006e48c2bc739mr6721455otr.2.1708967378621; Mon, 26 Feb 2024 09:09:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1708967378; cv=none; d=google.com; s=arc-20160816; b=QrQ6Ie3DmpiwjBtDCq+GIojFufIWdtIvb0yhIoLYkkXhqfbgalOZjFNxlPCvdeJOfj sJ9NRtHCbmlviddnUQI1GGmA+pLlq1omMkIZ9/ShnY3Ag0vNiYGO4PYSNjPyHaLWppiB ZuspLMW7RR4SIxiSxLuygFQWlw0Ft59Tmzr6Qvz8zugRz4h7JpdgzcVFKsq4/cOHXZh7 JgxlAKoXyVc5z47Dqvp9bAgEhKGxGFFA/K3gCcCuCz5fSf9gECaRGkKHTLTBIwMqJ4Q9 BAq/dA+3oB/XutHVX2Bt/2Z8/id9K8BfswpT45BnNBBydzTaIPxhf7GKWsQ1sx82quck XHCQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=Xq3bg3O489fduJkQRD4v3a7EWyBdeXHXm96vjazL+zo=; fh=FlRWjczXzB3kjfNm0MZCBQ0e7zrqTwZz0mkKu1n+VQY=; b=tLIOQ8yz+2m088Uz75LgJTL/nKPbwPSAIQzONo5h7Jt9HakSCwtczbLnSqMX/GqH/W PPsxRxJxRdjUSNub5lZsfolAFfkcodBRNZ4QqXA1A4LHaYjMHg05qZUQwpLnEMnipOZQ KtrdV/GlReGKDzYPqPR/CT3AAU+nyuYya1KYsb+m6LFJRIKcXeYgdKvTnc2N1906h0fa MNSEgpmPnB8wh9wEDxcG2rscg9tGlcs08zCSgozaULhtTB4DFv7zG2BfDo3tw/+Ne+Bz Mu+RUv2zzeXtpLNy0VizWtEgzTGGwI7IDhfwHQ1kVOOV7om6gpbHBHBZZaZWx1VAzCZy CEhg==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=HXUixjkb; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id v4-20020ac87484000000b0042e5fee575bsi5270000qtq.195.2024.02.26.09.09.38 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 26 Feb 2024 09:09:38 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=HXUixjkb; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1reeIa-0006O7-V3; Mon, 26 Feb 2024 11:57:52 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1reeIX-0006Ma-De for qemu-devel@nongnu.org; Mon, 26 Feb 2024 11:57:49 -0500 Received: from mail-wr1-x434.google.com ([2a00:1450:4864:20::434]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1reeHo-0007jI-2o for qemu-devel@nongnu.org; Mon, 26 Feb 2024 11:57:49 -0500 Received: by mail-wr1-x434.google.com with SMTP id ffacd0b85a97d-33d32f74833so1881196f8f.3 for ; Mon, 26 Feb 2024 08:57:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1708966622; x=1709571422; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Xq3bg3O489fduJkQRD4v3a7EWyBdeXHXm96vjazL+zo=; b=HXUixjkbqaiZxTDyLqCoRhEqNvwEt0AwA7XVBWlhHxqoV5vXMuRwvc013urd+z3oW3 tNgwyNvjWHNTx8t6GuG8iDysOqVFPG20pqVSGA5hEKl///ta+lOzBC0Buji7WQlZ7yph godirIcpmGpS31/OJYhnXQ5rq9fvwVMerLTjwPeu9MdJNdgvVuG3mgxBHSSzjW52yLc8 FacQKnCvNCbGZ/9BXZVWDy7c1DspFfiSSS7cXeZcbKVL+iInz6Ye7Pz2rgPB7yqBAASz mETU5czV1tcsZqhyJWixCkL8Tsox/w+j8AdgpH3+f/d42GtzfgZgJ7u/T9u1ZeuOx1qP jwPQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708966622; x=1709571422; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Xq3bg3O489fduJkQRD4v3a7EWyBdeXHXm96vjazL+zo=; b=UvkEEV4FFRAWj0x9WxQ1aCi+ce2d0ZpGCDHBuPIt4yRfuLt4J66ToJcsEYIggWncUT YhHRrgFPYSXn4DWFiKCkCXm71W4OrjbQJb9BdGA9j+S7i64cAfkWJCTi9mlJYhIQ8L2N Q14HBdpQ4ExxUt5C1NuK8f81PbD3rLsbnc+dT5naavb4Z49XCvH0xhADBeyrX3vNl1Wc cs4kjE/8qDxZOi0xJ+Pb3bQy9KFPmcU3KPCkY7TkfHRglYGHmR7CRs9dJpJnq7W6DHyt z47E7SPyqbdjirZzTV20sglc8zxZBY6NFRB20usufXEkMHTwgn8KvUcV9AhoJdUCLGJh dO9w== X-Gm-Message-State: AOJu0YxLJuDGsqZCkJFpz4P2JDugNpdoAap8sU2+lo2Eb8IzBiXDldAG bgRf1SZj8FuKBDafkirPog0oqNwQL/EtaCEYkFNIpCb1G+JDhn5oJInoNRJUAvA= X-Received: by 2002:a5d:598c:0:b0:33b:4818:f438 with SMTP id n12-20020a5d598c000000b0033b4818f438mr6435914wri.50.1708966622510; Mon, 26 Feb 2024 08:57:02 -0800 (PST) Received: from draig.lan ([85.9.250.243]) by smtp.gmail.com with ESMTPSA id i13-20020adfe48d000000b0033ae7d768b2sm8724194wrm.117.2024.02.26.08.56.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Feb 2024 08:56:56 -0800 (PST) Received: from draig.lan (localhost [IPv6:::1]) by draig.lan (Postfix) with ESMTP id 464125F928; Mon, 26 Feb 2024 16:56:48 +0000 (GMT) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: Nicholas Piggin , Liu Zhiwei , =?utf-8?q?C=C3=A9dric_Le_Goater?= , Peter Maydell , =?utf-8?q?Alex_Benn=C3=A9e?= , qemu-riscv@nongnu.org, Michael Rolnik , Song Gao , Alexandre Iooss , Marcel Apfelbaum , David Hildenbrand , Pierrick Bouvier , John Snow , Eduardo Habkost , Mahmoud Mandour , qemu-arm@nongnu.org, =?utf-8?q?Phi?= =?utf-8?q?lippe_Mathieu-Daud=C3=A9?= , Paolo Bonzini , Cleber Rosa , qemu-ppc@nongnu.org, Richard Henderson , qemu-s390x@nongnu.org, Daniel Henrique Barboza , Thomas Huth , Yoshinori Sato , Yanan Wang , Brian Cain , Ilya Leoshkevich , Weiwei Li , "Edgar E. Iglesias" , Bin Meng , Laurent Vivier , Palmer Dabbelt , Daniel Henrique Barboza , Alistair Francis Subject: [PATCH v3 15/27] plugins: fix order of init/idle/resume callback Date: Mon, 26 Feb 2024 16:56:34 +0000 Message-Id: <20240226165646.425600-16-alex.bennee@linaro.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240226165646.425600-1-alex.bennee@linaro.org> References: <20240226165646.425600-1-alex.bennee@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::434; envelope-from=alex.bennee@linaro.org; helo=mail-wr1-x434.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org From: Pierrick Bouvier We found that vcpu_init_hook was called *after* idle callback. vcpu_init is called from cpu_realize_fn, while idle/resume cb are called from qemu_wait_io_event (in vcpu thread). This change ensures we only call idle and resume cb only once a plugin was init for a given vcpu. Next change in the series will run vcpu_init asynchronously, which will make it run *after* resume callback as well. So we fix this now. Reviewed-by: Richard Henderson Signed-off-by: Pierrick Bouvier Message-Id: <20240213094009.150349-4-pierrick.bouvier@linaro.org> Signed-off-by: Alex Bennée --- plugins/core.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/plugins/core.c b/plugins/core.c index caa66311351..2392bbb8889 100644 --- a/plugins/core.c +++ b/plugins/core.c @@ -391,12 +391,17 @@ void qemu_plugin_vcpu_syscall_ret(CPUState *cpu, int64_t num, int64_t ret) void qemu_plugin_vcpu_idle_cb(CPUState *cpu) { - plugin_vcpu_cb__simple(cpu, QEMU_PLUGIN_EV_VCPU_IDLE); + /* idle and resume cb may be called before init, ignore in this case */ + if (cpu->cpu_index < plugin.num_vcpus) { + plugin_vcpu_cb__simple(cpu, QEMU_PLUGIN_EV_VCPU_IDLE); + } } void qemu_plugin_vcpu_resume_cb(CPUState *cpu) { - plugin_vcpu_cb__simple(cpu, QEMU_PLUGIN_EV_VCPU_RESUME); + if (cpu->cpu_index < plugin.num_vcpus) { + plugin_vcpu_cb__simple(cpu, QEMU_PLUGIN_EV_VCPU_RESUME); + } } void qemu_plugin_register_vcpu_idle_cb(qemu_plugin_id_t id,