From patchwork Mon Mar 4 13:00:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Pierrick Bouvier X-Patchwork-Id: 777748 Delivered-To: patch@linaro.org Received: by 2002:a5d:4b84:0:b0:33d:f458:43ce with SMTP id b4csp501983wrt; Mon, 4 Mar 2024 05:03:41 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCVcMGpzSlR1aN1dgrAgKQfEPrTq621caUVWCWxFYiNIhEKRlG8KPecmtnVTLVz7+9HQuBOUqZTpwb1nZ+RPx6qW X-Google-Smtp-Source: AGHT+IG3ApBkaKJSXX1dqP4Mc69vvOLwmZcP9e0bvcMroSKUs7izTzyOubGqt7/Btnu4TnCwp+aA X-Received: by 2002:a0d:fe83:0:b0:609:891b:7490 with SMTP id o125-20020a0dfe83000000b00609891b7490mr7721295ywf.17.1709557420696; Mon, 04 Mar 2024 05:03:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1709557420; cv=none; d=google.com; s=arc-20160816; b=ykMt2Ky4bZU4HzjGpfykCl/eXAVELnfJ5sD5KkvrZNZVlUHZq6LY5gKEUzIHer1i8a abkuotps3fWXBkjyIoddCSEfpdFuCBTOg1949G1NsflAvp5cB4lY/DX3Vun445znViYw tx+7Z5LHPLJtFhcbaw0spQe7hpsgtqO1HdSX61UmW1IPyrndQCjTNBlSJYDg5RJIsfj4 BgapNp4pCOXCEZ+iVuTLnCDZ4uts7INAeGYtAtBX/5zbv7lWw03Sy966gbI+KjtCbKyq xzvSaFr7Rx9ET0Hd1x+fUlmCPKUXSzQbG7X81MCR7ahQ30Gl5TK+3o4t4kBZYEEtYw16 MoKA== 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=Mq4OUu8jsXvOi2nFV5S63Gc/Vuo5i0t7yRBCt5ueL1s=; fh=iwWe/dXLTEEuIARUcSP8U5nJm4ELeL4JuDV/CtxCtRY=; b=MxK+DyM8NnWE+9yEPjWHMVJA0Z2fVJ4dckyCm6quelYcYNri/gXysLySUxELt9RZ55 hifF+LpsPf1fVwc8/AsYgAeXnm1KWRHUhsD3FyngwYfnGVofNjVpO7LmwjG4kX4HMVXm 8jI8PEMEoLfLAQRJU3jF6mCybhAm8OwD9i+U6igKlLRJWCHKz+qarMui+oAKmJhZgL0D nPPC2IkZi/IK7OBM+jHhJuCkj6Vf/nxqEgn2dXOipVX5kHJwx7vGAQG34eXyhy8p6APU REhiSPDMTnxyTTTQMW92h9Nk7yeDE+zhEcUWhs++/r3HWsvByTXS45PZi7OJHUuqhkvK iTNw==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=IKB4Awjo; 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 o19-20020a814113000000b0060821276363si4063783ywa.158.2024.03.04.05.03.40 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 04 Mar 2024 05:03:40 -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=IKB4Awjo; 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 1rh7xF-0002Ry-5q; Mon, 04 Mar 2024 08:02:05 -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 1rh7wv-00021o-Hu for qemu-devel@nongnu.org; Mon, 04 Mar 2024 08:01:59 -0500 Received: from mail-ej1-x636.google.com ([2a00:1450:4864:20::636]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rh7ws-0000pe-1Z for qemu-devel@nongnu.org; Mon, 04 Mar 2024 08:01:45 -0500 Received: by mail-ej1-x636.google.com with SMTP id a640c23a62f3a-a3ddc13bbb3so908334866b.0 for ; Mon, 04 Mar 2024 05:01:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1709557299; x=1710162099; 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=Mq4OUu8jsXvOi2nFV5S63Gc/Vuo5i0t7yRBCt5ueL1s=; b=IKB4Awjo/KrQv+4TQ1MsHCHdKnYBk74IMjWXxzD/Ps0AtLheq6004DHdOn33Lgdt+1 k0bYP6Nc9VQNJSouZAwfveV4FHtWDVRDHKWlsELcAshZ25Vz05tiXDMVPcFaiNTQE8p+ rdBhJjBskriExkUIUlLnSJT7gIyj/k1mQAuPSxt1bwkIT49Se+RiXnd3E95nK9o0CbwU w2AUhtOnVDigWy6wfPmU8wcrXdoOFoT9pyONfS8lgqbRW5TG1l7zhH48maeaS0bFh1Sb 8PrVhuQk3+EfnFXU5qPP7Swf0oP2gz7GphAOQ1cKrrd9pOhWlB7tJy4k6YOoA2hm32Qf +Nkg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709557299; x=1710162099; 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=Mq4OUu8jsXvOi2nFV5S63Gc/Vuo5i0t7yRBCt5ueL1s=; b=uPl13Y/TLCFvWb+9ivpz4Ep8k/+APs0iInbsymPWlXl5rYzVCmxagZXV846wxwbrqY QcFzhx7aNN5/LufTXmmVp52e5i0+/YbDAZAn3Lk3/NDvoAGflOyHB9DW1IUSzAr4bUzc OAkE8eI0AliG6E59Fbgo5P0cZPfPj0ahCjYtnYlQjUjKVmbdlaXJkk3fcfcN5rGDxcBd bvze+EPXonMUhBnA1wgo46zrcQ8kdRN/kTeDNZWXqk9cG6isjW0B6oZ/kXQs2JFJf1Ok t8RngXu/DN+uuTPq6QEG3tm1ccsCOmIJMXQbWb7S8K0o4F2ZMva5+WvjGVVaSbT+g4s3 GBiw== X-Gm-Message-State: AOJu0YyxshzlgvlW1xDBcAgahZrbjCuy80tlNbRMEcLLqQJPOCjeasmM uivt7081xbC1z+6+lkLI99/uuVZRCEogVzQW9tMt/Ras039HOVag5u4U+sJqeBJYFk+9JtIPpk9 AWdI= X-Received: by 2002:a17:906:780b:b0:a3f:f8a7:e1f7 with SMTP id u11-20020a170906780b00b00a3ff8a7e1f7mr7210930ejm.5.1709557298968; Mon, 04 Mar 2024 05:01:38 -0800 (PST) Received: from debian.. ([102.35.208.160]) by smtp.gmail.com with ESMTPSA id tj7-20020a170907c24700b00a413d1eda4bsm4806136ejc.87.2024.03.04.05.01.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Mar 2024 05:01:38 -0800 (PST) From: Pierrick Bouvier To: qemu-devel@nongnu.org Cc: Yanan Wang , =?utf-8?q?Philippe_Mathieu-Daud?= =?utf-8?q?=C3=A9?= , Mahmoud Mandour , Pierrick Bouvier , Alexandre Iooss , =?utf-8?q?Alex_Benn=C3=A9e?= , Richard Henderson , Eduardo Habkost , Marcel Apfelbaum , Paolo Bonzini , Luc Michel Subject: [PATCH v7 08/12] tests/plugin/bb: migrate to new per_vcpu API Date: Mon, 4 Mar 2024 17:00:32 +0400 Message-Id: <20240304130036.124418-9-pierrick.bouvier@linaro.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240304130036.124418-1-pierrick.bouvier@linaro.org> References: <20240304130036.124418-1-pierrick.bouvier@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::636; envelope-from=pierrick.bouvier@linaro.org; helo=mail-ej1-x636.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 Reviewed-by: Luc Michel Reviewed-by: Alex Bennée Signed-off-by: Pierrick Bouvier --- 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 struct qemu_plugin_scoreboard *counts; +static qemu_plugin_u64 bb_count; +static qemu_plugin_u64 insn_count; + static bool do_inline; -static CPUCount inline_count; - /* 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);