From patchwork Tue Feb 13 09:39:52 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pierrick Bouvier X-Patchwork-Id: 772276 Delivered-To: patch@linaro.org Received: by 2002:adf:9dc2:0:b0:33b:4db1:f5b3 with SMTP id q2csp169077wre; Tue, 13 Feb 2024 01:41:29 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCWraDSTpLLwU0ETNGWgVUdPC4YCcPMe1LD2uEnq8BLeCwW9Q4fuVxe9P0SNY9Mz0p/oX41GcX+vgEe985SRXak9 X-Google-Smtp-Source: AGHT+IEtFl17GlRvMuMC3Ygy4Q1XB9Z1brOkHCrlAQ+R++RRgVE+hz2zUKyb56CTtk9BHiv5O9P5 X-Received: by 2002:a0c:cd0f:0:b0:68e:eb0e:fd17 with SMTP id b15-20020a0ccd0f000000b0068eeb0efd17mr748216qvm.35.1707817288878; Tue, 13 Feb 2024 01:41:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1707817288; cv=none; d=google.com; s=arc-20160816; b=vfvZ4nf+4lxkvpfRhYCKad0/UYgmaQPKy2xY48t1lElxGm2CR1lOd6AoMOZXTbxLyV 2wJPccdBbQurul8cTsq6qLeToHqaaiw6NI40MPIoIk0sF2wMISImpFogy7pfacFj2mzV 1sUSQb5yQNSVUZghjIyAUvoro3MTD0Owi6hk/LyNugmrfYOFiKpgXvxiX9m8LOZZkw5K KAml/4QWHY7Dx5J0/qREXkQYrBbVrpuUPN2/EZ8Ojo+WTXsfXjgHYX0x0hZ7BtgHahjR 6UoO0laXVSAK6p46U8zuBqG7ez8Z6IqLePWoy27HXvk2+ynck81Tkp+QgSN6mIibNtlv JhSQ== 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=tr3Be+F/pb6UoTGk/xigsw32PICcW54rqyyS4zJsi9I=; fh=O1jN+kum9smkm7bkU+0imPG8pJg8hJLSRyGjiwU5qVM=; b=Cg4SFsjDaR5+n3U8/ue8OtE77NJ6Kk9VTbLyPE12icoQ7p4AHucC7ijWeGvoWNxjgA MSdzwKaJ1P3VqZOwKbeT2RLg03oDxtWSNllucCApLEDu2c6bpxtaWa0BUKEvv5EYTd8A xt6pdcbbX97yyPvuAtcskrm4Lz5FoeTiJ1c0VQ9y9gLATR4oN9baaByzQCg1PwTBsbyI oI4WPFdBXcRjtE0jIF9SPdvdQ064vlB+iMLjjl4WYxsgkQhMJaOa6c10WFMRBFVT0COz M1loWczVqlJq9s42pY2xmYZgo4aN6PbFKGsV2e7rjXS9zGiWOfu7Bji5xy5Ac9y/AzSl MFNg==; darn=linaro.org ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=kW7B4rIs; 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 X-Forwarded-Encrypted: i=1; AJvYcCXnB9MTb75FNl9X5KoxkasZTC0x9ZVzQIhB2HFarl4jcQ902FD8IkFB4TvxKIfHpZUa7FmQaY4GwZs8JqMYLNJ5 Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id m11-20020a0562141bcb00b0068c43de18ffsi2392748qvc.133.2024.02.13.01.41.28 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 13 Feb 2024 01:41:28 -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=kW7B4rIs; 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 1rZpHQ-00014m-GM; Tue, 13 Feb 2024 04:40:44 -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 1rZpHO-00012E-V1 for qemu-devel@nongnu.org; Tue, 13 Feb 2024 04:40:42 -0500 Received: from mail-lj1-x235.google.com ([2a00:1450:4864:20::235]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rZpHN-0000DO-8t for qemu-devel@nongnu.org; Tue, 13 Feb 2024 04:40:42 -0500 Received: by mail-lj1-x235.google.com with SMTP id 38308e7fff4ca-2d0e2adfeefso41934911fa.2 for ; Tue, 13 Feb 2024 01:40:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1707817238; x=1708422038; 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=tr3Be+F/pb6UoTGk/xigsw32PICcW54rqyyS4zJsi9I=; b=kW7B4rIsdzCg86mF8yIUte+XlsF7qMMO8pte19yPK0dm/dRhqGNUU9NH/9K3e8xo1e 1hHs2+qMxPyAgO269xnBu8VGZUAV+srggyU2TvZZF3bhRsNj034bWkMFuX9n5GFjM8YY P+/eExWYaVnsHKOiR8G8sldXldCbi4iYMPrDhE+tmDb6VyjGVo5svhUzZ0Y0+bK4/0d4 MdwfaT9wRZ/RRpsZMG05db9WRkYrsbAX9h/2AS9zoCXGOJAfhCBDdUUiM12nVLPj8CXw 7kNAxC4k0sLhYRlzboBzxp1QTPvxfyNF2WvvqdAdDiglp0rbkAZ3JgVb8klMWkBc2N89 cwZw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707817238; x=1708422038; 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=tr3Be+F/pb6UoTGk/xigsw32PICcW54rqyyS4zJsi9I=; b=AsTH0yJdn0JgyhNO1TM8FGS5PqDG5ecVZrLBsKmamvQRW0r8gGKKz2BpFwYdfodOA1 hdRBxRFt6NX3IINXpofSS12YVBEfRJtoZuzTlvH1izrzRnMCuhBleyenqb0V4TKwmSaB IupZuVYOe3Ws78p82f2GBHNaduYu1npsV01XiZUvi6NFBb8mQJX6PLVnK0wzun1cZdx8 o3m0UQir6u9AGGeHsPl9T/FteCwhArr1vBLkROWlnqkKKvmtCofP4Murgho8nCuWhN6J YvHoMFa9QQWmaoGZOCHWZB8ur6lhOBlQlkiX02qe7zkFM87mwnBCGwwsFcwH6b2iUmKz 5r7w== X-Gm-Message-State: AOJu0YzcS9SZfLgnXq1nNd83fjJJf5BxE+0QrJTU62VD95lFWPy2PtGY oXXoUOzjLTV/K8oKe6sC87T2NNvn9Kuehb9+96oEDuy74A4YdzyfwRdu6/JchrnBs4zJ7s7mkdg l X-Received: by 2002:a2e:b5a7:0:b0:2d0:d40c:e83b with SMTP id f7-20020a2eb5a7000000b002d0d40ce83bmr5510414ljn.30.1707817238531; Tue, 13 Feb 2024 01:40:38 -0800 (PST) X-Forwarded-Encrypted: i=1; AJvYcCVhsbef9t/X5AxL6Tl6B24s9WHqvyksnAG0y0rfdBUUcKOZWPNzPKl9176x5IwDlZJeI/RoRBPgGJI3pwfwF7UxcmuPKtd1ZTfWF2cUFVFRj6uuYJE5gDVAAqbsWW1erjwsa7Tt5pO56JTRHdRInnW/mSAw/OvxkNztNY7X9C8ewwFy68JrVs5iUOsTs90MoqKS1+fUMXw7j9qG0IipPns3ZzcrDd7DxzXDTqKq6nVqXLBTYgRZQ73g9anvmfFrEqXdrsggyRCjJOGx5c4E3aNqMC4GVwC+NKjOPflGPB7yxUJVYCp2J5U07urSLL3k+jQZQq+VXkEaE7O+wGMyE8Dju5DiFA== Received: from linaro.. ([102.35.208.160]) by smtp.gmail.com with ESMTPSA id cc19-20020a5d5c13000000b0033b728190c1sm8550261wrb.79.2024.02.13.01.40.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Feb 2024 01:40:38 -0800 (PST) From: Pierrick Bouvier To: qemu-devel@nongnu.org Cc: =?utf-8?q?Alex_Benn=C3=A9e?= , Yanan Wang , Marcel Apfelbaum , Paolo Bonzini , Mahmoud Mandour , Pierrick Bouvier , Alexandre Iooss , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Eduardo Habkost , Richard Henderson Subject: [PATCH v4 02/18] plugins: add qemu_plugin_num_vcpus function Date: Tue, 13 Feb 2024 13:39:52 +0400 Message-ID: <20240213094009.150349-3-pierrick.bouvier@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240213094009.150349-1-pierrick.bouvier@linaro.org> References: <20240213094009.150349-1-pierrick.bouvier@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::235; envelope-from=pierrick.bouvier@linaro.org; helo=mail-lj1-x235.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 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 --- 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 0e506ee644d..e94ae4d2abb 100644 --- a/include/qemu/qemu-plugin.h +++ b/include/qemu/qemu-plugin.h @@ -646,6 +646,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 2aaae4e47f3..dbfc5e83729 100644 --- a/plugins/api.c +++ b/plugins/api.c @@ -353,6 +353,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 49588285dd0..9e64820ad02 100644 --- a/plugins/core.c +++ b/plugins/core.c @@ -214,6 +214,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); @@ -571,3 +572,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 6088dd3714a..27fe97239be 100644 --- a/plugins/qemu-plugins.symbols +++ b/plugins/qemu-plugins.symbols @@ -17,6 +17,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_read_register;