From patchwork Tue Mar 5 12:09:57 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: 13582335 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id D4849C54E49 for ; Tue, 5 Mar 2024 12:21:42 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rhTnE-0004jg-Sy; Tue, 05 Mar 2024 07:21:13 -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 1rhTlH-0000lR-VQ for qemu-devel@nongnu.org; Tue, 05 Mar 2024 07:19:13 -0500 Received: from mail-wm1-x331.google.com ([2a00:1450:4864:20::331]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rhTky-0003GU-Hx for qemu-devel@nongnu.org; Tue, 05 Mar 2024 07:19:11 -0500 Received: by mail-wm1-x331.google.com with SMTP id 5b1f17b1804b1-412ecc1064cso4654475e9.2 for ; Tue, 05 Mar 2024 04:18:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1709641129; x=1710245929; 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=0DbWEIw6HJ+uey+RCD8YTAnKD0TfXpa90qc4hKJ7nSE=; b=KWKcKfJzKqBBucjYSsJ5A2c9BXeBXRO8B+4p4RZZofN4nnAjCSxoj+vLv82yVIgZkr owOuhjRXoVsXi5clnFaCed2K1ej418maCJM7h25+ZQQgEt87c0cp6hhuUr4ocYZ+2evA 15TU9OCUiztfN+3tYfw1nxVD161AZmfqlTufR+Zy/92Dw+AraMzxgMLMTuJyOjHGUxYx uZ2A89U5k0RzGThrMCFE04xc5qnOzxUteqM2jq565wKee2h2zCLPjwqrk9UdybVkfjgS RAmyxcdkXYGYCRWqJF8Xy5FFP1hHcTPVWZh5xHs039AjsqFmYMMCjWq9tiKxQ+p4kN26 jIvw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709641129; x=1710245929; 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=0DbWEIw6HJ+uey+RCD8YTAnKD0TfXpa90qc4hKJ7nSE=; b=LemkFSOjxgKf1ofmCSI9rmkqc6xZNRHxGsJZejx3JZ78m8S/mS0/hNPOQA8fnQsgm7 BSPlPie6EFrVVcc3gkhlIuZ8J+Dnn+AXxd0uhjbZRy5uqpQe0LaxFEzqVGujSVqz8w9h Vk1noAbCUVjTUSjP9zZF6uxTHSfHol2sIolInqV0tKTj5GxPHHQtyt6pdUOgiLfCWizm zjmM4IJfjKfovhj79200cTvylVkddjMnXE9KCwWXGasrNL19Fmbdd1AiuWtlHixVSz7u 1i4d/h2sHJAvYY22oi9URO5BzZQO8J1UzrDuhA9Q9sFYIB5j9Px1kzjMLGHOWCwEMmRO nOEg== X-Gm-Message-State: AOJu0Ywlocbw2Gc4U7ZV2a5bPCgoJw3c5NTAb7+kGYGvE/NXJhIUzF6k O6nzYqLzFvDWO/E4eiWc4B0iTWzDedkRj+IN48EDpw4MkbxyHe/Kvm10M+nUj2E= X-Google-Smtp-Source: AGHT+IGfyy+dD2vdSUvdl9WkKm29wASBydjUohaSp1SjKoA9U9LJjqipZCm5xHC/sVcSl1NaJU59kw== X-Received: by 2002:a05:600c:5253:b0:40e:d30b:6129 with SMTP id fc19-20020a05600c525300b0040ed30b6129mr9771561wmb.13.1709641129102; Tue, 05 Mar 2024 04:18:49 -0800 (PST) Received: from draig.lan ([85.9.250.243]) by smtp.gmail.com with ESMTPSA id o14-20020a05600c510e00b00412aff7874esm17909157wms.48.2024.03.05.04.18.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 Mar 2024 04:18:47 -0800 (PST) Received: from draig.lan (localhost [IPv6:::1]) by draig.lan (Postfix) with ESMTP id 745EA5F9EB; Tue, 5 Mar 2024 12:10:07 +0000 (GMT) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: Wainer dos Santos Moschetta , Alistair Francis , Nicholas Piggin , Liu Zhiwei , Richard Henderson , Yanan Wang , qemu-s390x@nongnu.org, "Edgar E. Iglesias" , Eduardo Habkost , Daniel Henrique Barboza , Michael Rolnik , Daniel Henrique Barboza , =?utf-8?q?Alex_Benn=C3=A9e?= , Laurent Vivier , Yoshinori Sato , Laurent Vivier , Thomas Huth , Peter Maydell , Mahmoud Mandour , Brad Smith , Alistair Francis , Brian Cain , Cleber Rosa , John Snow , Marcel Apfelbaum , Pierrick Bouvier , Palmer Dabbelt , Riku Voipio , qemu-arm@nongnu.org, qemu-ppc@nongnu.org, Weiwei Li , Bin Meng , =?utf-8?q?C=C3=A9dric_Le_Goater?= , Beraldo Leal , Kyle Evans , David Hildenbrand , Song Gao , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Paolo Bonzini , Alexandre Iooss , Warner Losh , qemu-riscv@nongnu.org, Ilya Leoshkevich , Luc Michel Subject: [PATCH 21/29] tests/plugin/bb: migrate to new per_vcpu API Date: Tue, 5 Mar 2024 12:09:57 +0000 Message-Id: <20240305121005.3528075-22-alex.bennee@linaro.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240305121005.3528075-1-alex.bennee@linaro.org> References: <20240305121005.3528075-1-alex.bennee@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::331; envelope-from=alex.bennee@linaro.org; helo=mail-wm1-x331.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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org From: Pierrick Bouvier Reviewed-by: Luc Michel Reviewed-by: Alex Bennée Signed-off-by: Pierrick Bouvier Message-Id: <20240304130036.124418-9-pierrick.bouvier@linaro.org> Signed-off-by: Alex Bennée --- tests/plugin/bb.c | 63 +++++++++++++++++++---------------------------- 1 file changed, 26 insertions(+), 37 deletions(-) diff --git a/tests/plugin/bb.c b/tests/plugin/bb.c index df50d1fd3bc..36776dee1e1 100644 --- a/tests/plugin/bb.c +++ b/tests/plugin/bb.c @@ -17,27 +17,25 @@ QEMU_PLUGIN_EXPORT int qemu_plugin_version = QEMU_PLUGIN_VERSION; typedef struct { - GMutex lock; - int index; uint64_t bb_count; uint64_t insn_count; } CPUCount; -/* Used by the inline & linux-user counts */ -static bool do_inline; -static CPUCount inline_count; +static struct qemu_plugin_scoreboard *counts; +static qemu_plugin_u64 bb_count; +static qemu_plugin_u64 insn_count; +static bool do_inline; /* Dump running CPU total on idle? */ static bool idle_report; -static GPtrArray *counts; -static int max_cpus; -static void gen_one_cpu_report(CPUCount *count, GString *report) +static void gen_one_cpu_report(CPUCount *count, GString *report, + unsigned int cpu_index) { if (count->bb_count) { g_string_append_printf(report, "CPU%d: " "bb's: %" PRIu64", insns: %" PRIu64 "\n", - count->index, + cpu_index, count->bb_count, count->insn_count); } } @@ -46,20 +44,23 @@ static void plugin_exit(qemu_plugin_id_t id, void *p) { g_autoptr(GString) report = g_string_new(""); - if (do_inline || !max_cpus) { - g_string_printf(report, "bb's: %" PRIu64", insns: %" PRIu64 "\n", - inline_count.bb_count, inline_count.insn_count); - } else { - g_ptr_array_foreach(counts, (GFunc) gen_one_cpu_report, report); + for (int i = 0; i < qemu_plugin_num_vcpus(); ++i) { + CPUCount *count = qemu_plugin_scoreboard_find(counts, i); + gen_one_cpu_report(count, report, i); } + g_string_append_printf(report, "Total: " + "bb's: %" PRIu64", insns: %" PRIu64 "\n", + qemu_plugin_u64_sum(bb_count), + qemu_plugin_u64_sum(insn_count)); qemu_plugin_outs(report->str); + qemu_plugin_scoreboard_free(counts); } static void vcpu_idle(qemu_plugin_id_t id, unsigned int cpu_index) { - CPUCount *count = g_ptr_array_index(counts, cpu_index); + CPUCount *count = qemu_plugin_scoreboard_find(counts, cpu_index); g_autoptr(GString) report = g_string_new(""); - gen_one_cpu_report(count, report); + gen_one_cpu_report(count, report, cpu_index); if (report->len > 0) { g_string_prepend(report, "Idling "); @@ -69,14 +70,11 @@ static void vcpu_idle(qemu_plugin_id_t id, unsigned int cpu_index) static void vcpu_tb_exec(unsigned int cpu_index, void *udata) { - CPUCount *count = max_cpus ? - g_ptr_array_index(counts, cpu_index) : &inline_count; + CPUCount *count = qemu_plugin_scoreboard_find(counts, cpu_index); uintptr_t n_insns = (uintptr_t)udata; - g_mutex_lock(&count->lock); count->insn_count += n_insns; count->bb_count++; - g_mutex_unlock(&count->lock); } static void vcpu_tb_trans(qemu_plugin_id_t id, struct qemu_plugin_tb *tb) @@ -84,11 +82,10 @@ static void vcpu_tb_trans(qemu_plugin_id_t id, struct qemu_plugin_tb *tb) size_t n_insns = qemu_plugin_tb_n_insns(tb); if (do_inline) { - qemu_plugin_register_vcpu_tb_exec_inline(tb, QEMU_PLUGIN_INLINE_ADD_U64, - &inline_count.bb_count, 1); - qemu_plugin_register_vcpu_tb_exec_inline(tb, QEMU_PLUGIN_INLINE_ADD_U64, - &inline_count.insn_count, - n_insns); + qemu_plugin_register_vcpu_tb_exec_inline_per_vcpu( + tb, QEMU_PLUGIN_INLINE_ADD_U64, bb_count, 1); + qemu_plugin_register_vcpu_tb_exec_inline_per_vcpu( + tb, QEMU_PLUGIN_INLINE_ADD_U64, insn_count, n_insns); } else { qemu_plugin_register_vcpu_tb_exec_cb(tb, vcpu_tb_exec, QEMU_PLUGIN_CB_NO_REGS, @@ -121,18 +118,10 @@ QEMU_PLUGIN_EXPORT int qemu_plugin_install(qemu_plugin_id_t id, } } - if (info->system_emulation && !do_inline) { - max_cpus = info->system.max_vcpus; - counts = g_ptr_array_new(); - for (i = 0; i < max_cpus; i++) { - CPUCount *count = g_new0(CPUCount, 1); - g_mutex_init(&count->lock); - count->index = i; - g_ptr_array_add(counts, count); - } - } else if (!do_inline) { - g_mutex_init(&inline_count.lock); - } + counts = qemu_plugin_scoreboard_new(sizeof(CPUCount)); + bb_count = qemu_plugin_scoreboard_u64_in_struct(counts, CPUCount, bb_count); + insn_count = qemu_plugin_scoreboard_u64_in_struct( + counts, CPUCount, insn_count); if (idle_report) { qemu_plugin_register_vcpu_idle_cb(id, vcpu_idle);