From patchwork Thu Feb 29 05:25:02 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pierrick Bouvier X-Patchwork-Id: 776885 Delivered-To: patch@linaro.org Received: by 2002:adf:e94d:0:b0:33d:f458:43ce with SMTP id m13csp652003wrn; Wed, 28 Feb 2024 21:27:06 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCXrSJo0ZVhRAtKSDqMd1maTZZzQnLXuWen0seLPSQZOB1wDje9Exry/5Tays47QvsnkS6NiLfg0GuDs1ffP94Qi X-Google-Smtp-Source: AGHT+IGEN8HuyiV1VTFF7H4tNY4Axu/h9vUu4Ivp9VaXiupa2p0JHbM7n2AkZCHRZBrtnA6+5V8v X-Received: by 2002:a05:6214:2b48:b0:68f:ff45:8793 with SMTP id jy8-20020a0562142b4800b0068fff458793mr1385361qvb.25.1709184426400; Wed, 28 Feb 2024 21:27:06 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1709184426; cv=none; d=google.com; s=arc-20160816; b=ZTp0w/UHGCPinT7SDVtFW+rRzk6YimQydlK6sopYq8e2R5dHp4W/44nP+8bNNgJFqP LniaOSGpNXXO3VfwakTh5pmvowuQ5EQ01chZdkQIGl2/6Tg7eDz2t4gv8u7iQLOuvSiw ogMgG6kl0KzY0zE/udNpbT8wh+wjzvLLuGktBtut2d6r3IKY+7G0QqlmRTKWdAAiKJ3t GONanGLtWPucQrMTW0sSWRxODTrteIRaW6JKn9svdRbsey/AVDj687QNIZJ4zcTABybl DEs8XuFxQ6/MKm57n11PW6nRrKUUVRRwgdTQlpmsrHxkCDZ7UtyUqpNF/RdBaKwSR8dI qudA== 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=ppE1notIMZL45Hs6pC/NlspuyTzo8NjjnmHK5ZpYTNo=; fh=L0hh/ue2K8HHkGVTIweE28wZeVS7aL+T29VaciJhggs=; b=NpAfWd1my2rce7UPEJhSvco5gqW1pg/1r3zQ3tJwILNcTwP0vAZ6EyzplJ6GEIDihh pEdEs7IE2HnlyW55Czb56sWoRAAXOLidcaKssaBQIjnwHjwgyDJLaGSMaBkg9P9/L47j aXWWrFj5RPcaQAFz6oprAfBPWULs567DuGFDBAtjCptjzq5t+BuiO1Ye7W1glEBSVrfv nvk19/87dtWxKks8JrYs/Tyst+AaJ8WwFLRNApjXbU1Cwl0luuzEFvPEMsNY5VIIlREV 17l0qqdlq5DAyj1AgmjPu6nFUKbH8ynRnW9vlzMy/qVsG1xwDLT/+sV6MmHXymewY7Ez 3/Dw==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=AGcRFjWX; 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 4-20020a0562140d0400b0068f610acb50si647916qvh.613.2024.02.28.21.27.06 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 28 Feb 2024 21:27:06 -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=AGcRFjWX; 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 1rfYvb-0002op-Tt; Thu, 29 Feb 2024 00:25:55 -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 1rfYvZ-0002o9-VM for qemu-devel@nongnu.org; Thu, 29 Feb 2024 00:25:53 -0500 Received: from mail-wr1-x436.google.com ([2a00:1450:4864:20::436]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rfYvV-0005zR-0V for qemu-devel@nongnu.org; Thu, 29 Feb 2024 00:25:53 -0500 Received: by mail-wr1-x436.google.com with SMTP id ffacd0b85a97d-33de6da5565so284511f8f.2 for ; Wed, 28 Feb 2024 21:25:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1709184345; x=1709789145; 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=ppE1notIMZL45Hs6pC/NlspuyTzo8NjjnmHK5ZpYTNo=; b=AGcRFjWX6e5NrHfn7l8x6uLb7O4Fq3GdX5FehSsPlaMWF6SzBGGtK15L0mb5mwa9vf kaJmVqz2+nJq6rWQR2yI+b7ebbBE5gCC6SRjm0CqkAi7yZ7YZtUr+DPZHL4mgdB9oXrh NkbkHlYNJE9SAs5Sh/FAtH9ZoFU0yIa8SSpl602jvd/5lXDpFspymJX4tQe4z30jzGC2 qma7gwCgWvl8JzABz6a59sZ5osn1zKdxL4/HDdv+jrEZ9xUMyfhsQUpozKp/TQW6NTCy 9Uw1AKvQxq00CYdgkNOjOOvOPoRzCD7Of1gyl3EkRzIdbGrBOZm5dIEQqnw4YDiqITie 5zHA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709184345; x=1709789145; 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=ppE1notIMZL45Hs6pC/NlspuyTzo8NjjnmHK5ZpYTNo=; b=jxSDHfQ2TTKqJmvC74WddScq6ifQGhx4uD/vr2iVUZX+QV8kq0Hc0hKddZz2dRU+/P CU8n1T8EuKr3T8hi8z79M8qKDr4706OBVpezzFuUQ7dKtk0e3TecEEMyOXOz8iQ8WC4q XAUvwj1ZmzjSYSKgacJt/wXPQkBV9aY1teTyUxwNU8VI4WYsi3PnBJw3XNGn/cpd8FaA tS7ZMuyCUm4SmyaDsxsMqnCE5jFl1/3uxuzcQRde+emApbZr4zW3VCUv0mZGycT4F6aO tA62zQaGf8EkkLH/U5jlUnYAH80HHWmGI2zlOG3HmViYXW2tqiaycr+93DO2Y7HX+H8K FYTg== X-Gm-Message-State: AOJu0Yzf2rb7HY7kIUKwU6IYq03HV4Z8wPRkoEzgDo9tnHFlkJ6z37Z0 5GUtfPhJ7Dy4KCzDZcJCReUXBCCzhCVb/ZJtTUhcRnSMlukAeCskQpfenmzk2wve6FJRr64B9XI KrSc= X-Received: by 2002:a5d:4b8a:0:b0:33d:96c7:ae3d with SMTP id b10-20020a5d4b8a000000b0033d96c7ae3dmr503207wrt.16.1709184345745; Wed, 28 Feb 2024 21:25:45 -0800 (PST) Received: from linaro.. ([102.35.208.160]) by smtp.gmail.com with ESMTPSA id e14-20020adffc4e000000b0033dfa7ecd33sm660241wrs.61.2024.02.28.21.25.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Feb 2024 21:25:45 -0800 (PST) From: Pierrick Bouvier To: qemu-devel@nongnu.org Cc: =?utf-8?q?Alex_Benn=C3=A9e?= , Mahmoud Mandour , Eduardo Habkost , =?utf-8?q?Philippe_Mathieu-Daud?= =?utf-8?q?=C3=A9?= , Yanan Wang , Pierrick Bouvier , Richard Henderson , Marcel Apfelbaum , Paolo Bonzini , Alexandre Iooss , Luc Michel Subject: [PATCH v6 08/12] tests/plugin/bb: migrate to new per_vcpu API Date: Thu, 29 Feb 2024 09:25:02 +0400 Message-ID: <20240229052506.933222-9-pierrick.bouvier@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240229052506.933222-1-pierrick.bouvier@linaro.org> References: <20240229052506.933222-1-pierrick.bouvier@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::436; envelope-from=pierrick.bouvier@linaro.org; helo=mail-wr1-x436.google.com X-Spam_score_int: -16 X-Spam_score: -1.7 X-Spam_bar: - X-Spam_report: (-1.7 / 5.0 requ) BAYES_00=-1.9, DKIM_INVALID=0.1, DKIM_SIGNED=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=no 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 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);