From patchwork Mon Feb 26 16:56:33 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: 1904560 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=HuD1Xi12; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-ppc-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Tk6Mb70Hrz23qD for ; Tue, 27 Feb 2024 04:01:15 +1100 (AEDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1reeIV-0006L6-7j; Mon, 26 Feb 2024 11:57:47 -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 1reeIS-0006HN-AU for qemu-ppc@nongnu.org; Mon, 26 Feb 2024 11:57:44 -0500 Received: from mail-lj1-x234.google.com ([2a00:1450:4864:20::234]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1reeHm-0007gI-JS for qemu-ppc@nongnu.org; Mon, 26 Feb 2024 11:57:44 -0500 Received: by mail-lj1-x234.google.com with SMTP id 38308e7fff4ca-2d2533089f6so39645431fa.1 for ; Mon, 26 Feb 2024 08:57:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1708966620; x=1709571420; 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=O9WREwsMrt85roF9DpcRAV7U4Bq5TV/wSmpsUdovSGg=; b=HuD1Xi12pMD0H6lU0yxbN0Jw85z3ziZHBhyDahD1I933mYa0+WbuLfBX2lNyNx0CGq 1nwnIRwDzt6RxcupnOL8uAufaK2S8s18bpFsv5239F4wkBzq1VeXe7c2234r8LFKB9x1 KJGwu9F+3rc4X4F8O5V/u5uFvglPGKEF+d1BAQrNzze/Zw1YAZE8uqSc2SkqlM6IpvqK jM4x3qcpK6SuAYYyl1VtN22W/iv1h/hjEgAWthHfgXRNDgdV6VQk1Qnhj4y4US9Z+3lo 8V/frVbXiyc+VV3r6ytL0fxgAUKQMN59xKq2FUymd7FZnXKUzT0YFMrMdGKl2JI8ZbJL 3VKg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708966620; x=1709571420; 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=O9WREwsMrt85roF9DpcRAV7U4Bq5TV/wSmpsUdovSGg=; b=CQV7tL0Rt04HSuroE9zLAr7/Y+Qhts3k9e7X1WHIpguLyMVi5NqEy8PMnjhCDvu1Be 5tAwJoY6D1YO5v+SkpNzZx2ZMBazMdpFXGVlYEC1plCGfZtbLUPqbcwWuUzpoNd2qO7Y dOzgWafUKSa//Y5VO61GdtHLaRxQpTxONXJp9ivUCeExKyizcsLT3gbqtffCllCe22JU l/WhMmiEhQqrURt2fPzPFL6SUHlK63+ms81Ws0Ief3NlxGFf0xU+PvPyy/HzncU30RiU EKPFlSRbpldGmoIFWuycnlWhAOAybA7zDB03YbWVqqzHis6GE0nh7I+pc5p1Z65eZBCt y7Xg== X-Forwarded-Encrypted: i=1; AJvYcCUieYzqMWkMQ4V9ZtNBfnSnj/XEd7KSU/HbYiuzYbmQEfuRUZnjaawRvJNPri4vVMt55youHJRjcIKCHhUaO+baUtKt X-Gm-Message-State: AOJu0YzhhcJR1SwBXlF/zlz02IGCBENt6NcABIHrwMNmCOTQAlz5twq9 ZR7/u9r6PSJvQyb34Vkf88mpS9ahnvqVJA/hwEooFwvRsKnnYjlt4uZCdTOpADI= X-Google-Smtp-Source: AGHT+IEGKNgu9DpHzi/KJwI3xE6CV13aAy2RsSN+TadP2TD7hu/h3L5xVf8ZvoxlraIENMTTEhY6gg== X-Received: by 2002:a2e:801a:0:b0:2d2:61e8:44eb with SMTP id j26-20020a2e801a000000b002d261e844ebmr4692112ljg.33.1708966620332; Mon, 26 Feb 2024 08:57:00 -0800 (PST) Received: from draig.lan ([85.9.250.243]) by smtp.gmail.com with ESMTPSA id bi27-20020a05600c3d9b00b00412a9a60f83sm666277wmb.3.2024.02.26.08.56.50 (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 3340D5F924; 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 14/27] plugins: add qemu_plugin_num_vcpus function Date: Mon, 26 Feb 2024 16:56:33 +0000 Message-Id: <20240226165646.425600-15-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::234; envelope-from=alex.bennee@linaro.org; helo=mail-lj1-x234.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-ppc@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-ppc-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-ppc-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Pierrick Bouvier We now keep track of how many vcpus were started. This way, a plugin can easily query number of any vcpus at any point of execution, which unifies user and system mode workflows. Signed-off-by: Pierrick Bouvier Reviewed-by: Richard Henderson Message-Id: <20240213094009.150349-3-pierrick.bouvier@linaro.org> Signed-off-by: Alex Bennée --- include/qemu/qemu-plugin.h | 3 +++ plugins/plugin.h | 4 ++++ plugins/api.c | 5 +++++ plugins/core.c | 6 ++++++ plugins/qemu-plugins.symbols | 1 + 5 files changed, 19 insertions(+) diff --git a/include/qemu/qemu-plugin.h b/include/qemu/qemu-plugin.h index e45181c793c..93981f8f89f 100644 --- a/include/qemu/qemu-plugin.h +++ b/include/qemu/qemu-plugin.h @@ -645,6 +645,9 @@ QEMU_PLUGIN_API void qemu_plugin_register_atexit_cb(qemu_plugin_id_t id, qemu_plugin_udata_cb_t cb, void *userdata); +/* returns how many vcpus were started at this point */ +int qemu_plugin_num_vcpus(void); + /** * qemu_plugin_outs() - output string via QEMU's logging system * @string: a string diff --git a/plugins/plugin.h b/plugins/plugin.h index 90f3f324ab6..00b3509f708 100644 --- a/plugins/plugin.h +++ b/plugins/plugin.h @@ -44,6 +44,8 @@ struct qemu_plugin_state { * the code cache is flushed. */ struct qht dyn_cb_arr_ht; + /* How many vcpus were started */ + int num_vcpus; }; @@ -97,4 +99,6 @@ void plugin_register_vcpu_mem_cb(GArray **arr, void exec_inline_op(struct qemu_plugin_dyn_cb *cb); +int plugin_num_vcpus(void); + #endif /* PLUGIN_H */ diff --git a/plugins/api.c b/plugins/api.c index 2926b1961a8..116b8bd603c 100644 --- a/plugins/api.c +++ b/plugins/api.c @@ -342,6 +342,11 @@ const char *qemu_plugin_hwaddr_device_name(const struct qemu_plugin_hwaddr *h) #endif } +int qemu_plugin_num_vcpus(void) +{ + return plugin_num_vcpus(); +} + /* * Plugin output */ diff --git a/plugins/core.c b/plugins/core.c index ee2fa41af9e..caa66311351 100644 --- a/plugins/core.c +++ b/plugins/core.c @@ -213,6 +213,7 @@ void qemu_plugin_vcpu_init_hook(CPUState *cpu) bool success; qemu_rec_mutex_lock(&plugin.lock); + plugin.num_vcpus = MAX(plugin.num_vcpus, cpu->cpu_index + 1); plugin_cpu_update__locked(&cpu->cpu_index, NULL, NULL); success = g_hash_table_insert(plugin.cpu_ht, &cpu->cpu_index, &cpu->cpu_index); @@ -570,3 +571,8 @@ static void __attribute__((__constructor__)) plugin_init(void) QHT_MODE_AUTO_RESIZE); atexit(qemu_plugin_atexit_cb); } + +int plugin_num_vcpus(void) +{ + return plugin.num_vcpus; +} diff --git a/plugins/qemu-plugins.symbols b/plugins/qemu-plugins.symbols index ca806000d54..adb67608598 100644 --- a/plugins/qemu-plugins.symbols +++ b/plugins/qemu-plugins.symbols @@ -16,6 +16,7 @@ qemu_plugin_mem_is_sign_extended; qemu_plugin_mem_is_store; qemu_plugin_mem_size_shift; + qemu_plugin_num_vcpus; qemu_plugin_outs; qemu_plugin_path_to_binary; qemu_plugin_register_atexit_cb;