From patchwork Fri Feb 16 16:30:16 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: 773361 Delivered-To: patch@linaro.org Received: by 2002:a5d:4943:0:b0:33b:4db1:f5b3 with SMTP id r3csp28032wrs; Fri, 16 Feb 2024 08:39:05 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCW7hQq+E/JmM/4jM2GPDlRtRN8FBkBoyZYpSKtr4ILBw4hS1BkDVfA8pY+lTI/y3T/K3QG+91Qq6djSGNzm5YYw X-Google-Smtp-Source: AGHT+IGWTsuBmIVaEd9E/eJeI+q0MHqTW+fqzpPsgVYxuOD8MUYW60pWkolA4ZxOC6U238CfZus+ X-Received: by 2002:ac8:578e:0:b0:42d:b1e9:75bc with SMTP id v14-20020ac8578e000000b0042db1e975bcmr5215130qta.42.1708101545281; Fri, 16 Feb 2024 08:39:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1708101545; cv=none; d=google.com; s=arc-20160816; b=vQcGL/yG5bAFrx/aTfr3R8ezsFR21LUvLsfhp/hgACexw2yD8trJX2Y0D733yD7xjx hHxKBvoVHwZnUE7cKVcNp9FjMUWp3qp71aQfTSZA6jOMC+5CXkC+aEJ0lS3hN0tRnB85 XeNKTMECqU+mmF9xxf5IM1iZyZLrEa7nE/WJvBxeC6XQ2JU0lDH4wlXMGQDpp4BRzSe0 knZ9uuD9T9YFYd70jkPGPCQ+3MuNxVZ7Ef0y5FZ/WIcJ4dPfFQ/QgJYqn/0Xuo7tkY8L l77UKkdB4W46pCi3+vr72aTUuL/3cTdvvPfGbDxJB/9eGk7EhYW9+KEr6oVqGnw917nb m/GQ== 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=BiCuxLgE2Qo8NnA5oZWxFqr6rT9EcPosGDdXLEV2jRw=; b=K5klrriOsffB6/833Bof0/qqfykO+9hkOAUPsxiIsjU0R76PfgMkHDNrvH/MDKRnpF RmZBfa2wXaLq7ROrZXcWus8daCSxWeuFOpcZUxOlR6j/0UMNMSlPGtdC4Sd7HGFW03rw nuj+01m0Cr6bTShsURtCS6byCAvkqz6PQ5dGFfe5gXjsK/GcxCGCijx7rjLW3A5Nw1mf ZNWYUOhE7y04TmrN8ttD/z+t8Y42Vmg9tLPztEPcpTs2KaTpRWIKGym50ZVWiQJqHc12 MtLUm1OKPD4ECiAaSj7RXbmthImm59JtyznIRapaxLLzsS1STlk4wdC5o2851C2uOQHj +DWg==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=AkNDxkuI; 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 i1-20020ac871c1000000b0042c16287221si160225qtp.343.2024.02.16.08.39.05 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 16 Feb 2024 08:39:05 -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=AkNDxkuI; 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 1rb1Dm-0001UC-Tw; Fri, 16 Feb 2024 11:37:54 -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 1rb1Dl-0001SR-Lv for qemu-devel@nongnu.org; Fri, 16 Feb 2024 11:37:53 -0500 Received: from mail-wr1-x429.google.com ([2a00:1450:4864:20::429]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rb1DY-000462-1U for qemu-devel@nongnu.org; Fri, 16 Feb 2024 11:37:53 -0500 Received: by mail-wr1-x429.google.com with SMTP id ffacd0b85a97d-33d07ee22eeso619313f8f.0 for ; Fri, 16 Feb 2024 08:37:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1708101458; x=1708706258; 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=AkNDxkuIHxHQFNZUp/7MrvxkivggZjgRSvuOUTGJhOAIq6+wi/S/I1TwQQGYMu6QUL GvPveafpCl7b4n5aiYD9Vt6bDEF2h2WDLiEZXk2fZX1lprTfLjyXit2EBmLjEr9imY5o dWJ9wgKEIS82uewDUz/y0dJQ/nj0w1jmwjbtZ88SMd9wHmp3qM6Di67uj75qxT5klDLu yZdIMqFLqr6igdtNDDA2kuIS8gjJYI0ToGv4dWq8ih33DelKMJFqfkTfmCYjWuDoYD7y jQd/8iL7gE/vRe44kR1xcAloD8Yo60JmwmT/f/qbb8oNRVi969SFIM0sml4QKU9bsXNy MCLA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708101458; x=1708706258; 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=ZP4lzVReTSoU/72y42o0mxdB7cddigcvh+17hx6/+NHZp2l8GwTVsvY1gRGji/v7lg S7CQB87X5pXU+FKO6yISk03LUC0Qcq5FPsfo4cM73up58SBfDfkJJ2GAKxYx6xnFx/iW vkAbQ/pduVwrj6RPXrvKE+Z2w+pjLflg2gURzXaz4jkzD29zP7KvXdZc5oizHPFZSLCF MAIjaqrfD7iSFIr8Mr7oq/6ceOKjmHXBtIe7ra3NbKDlTQ+Vi/MqM+0DYQgTwOG9I7g2 sOZyfygCBHAiYUNxGhQVZrxTMgBCixtCenshAlkRCcO4qI/EUzBOQyvbYZRV2W13TyAz a/Mw== X-Gm-Message-State: AOJu0YyfojKleMjFrDplb0UCOiOpOZuVvWypJHgkWH9UcjXcK5CcNS9Q b9Y1B5bCY8xgQQuhAmrUr3OKdlKrC5NzH+aRT3rBWfnNOTTonXtm+DmYEhikeHA= X-Received: by 2002:adf:f50e:0:b0:33b:304d:36b7 with SMTP id q14-20020adff50e000000b0033b304d36b7mr4393268wro.56.1708101458266; Fri, 16 Feb 2024 08:37:38 -0800 (PST) Received: from draig.lan ([85.9.250.243]) by smtp.gmail.com with ESMTPSA id o11-20020adfcf0b000000b0033b4dae972asm2631828wrj.37.2024.02.16.08.37.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Feb 2024 08:37:35 -0800 (PST) Received: from draig.lan (localhost [IPv6:::1]) by draig.lan (Postfix) with ESMTP id AE4365F9E0; Fri, 16 Feb 2024 16:30:27 +0000 (GMT) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: Yoshinori Sato , David Hildenbrand , Weiwei Li , Richard Henderson , Michael Rolnik , Ilya Leoshkevich , Peter Maydell , qemu-ppc@nongnu.org, Paolo Bonzini , qemu-riscv@nongnu.org, Cleber Rosa , Thomas Huth , Song Gao , qemu-arm@nongnu.org, Pierrick Bouvier , John Snow , =?utf-8?q?Alex_Benn=C3=A9e?= , =?utf-8?q?C=C3=A9dri?= =?utf-8?q?c_Le_Goater?= , Nicholas Piggin , qemu-s390x@nongnu.org, Laurent Vivier , "Edgar E. Iglesias" , Daniel Henrique Barboza , Yanan Wang , Palmer Dabbelt , Marcel Apfelbaum , Brian Cain , Mahmoud Mandour , Alexandre Iooss , Bin Meng , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Daniel Henrique Barboza , Eduardo Habkost , Alistair Francis , Liu Zhiwei Subject: [PATCH 14/23] plugins: fix order of init/idle/resume callback Date: Fri, 16 Feb 2024 16:30:16 +0000 Message-Id: <20240216163025.424857-15-alex.bennee@linaro.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240216163025.424857-1-alex.bennee@linaro.org> References: <20240216163025.424857-1-alex.bennee@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::429; envelope-from=alex.bennee@linaro.org; helo=mail-wr1-x429.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=unavailable 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,