From patchwork Thu Jan 11 14:23:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pierrick Bouvier X-Patchwork-Id: 761856 Delivered-To: patch@linaro.org Received: by 2002:a5d:6e02:0:b0:337:62d3:c6d5 with SMTP id h2csp2423170wrz; Thu, 11 Jan 2024 06:26:28 -0800 (PST) X-Google-Smtp-Source: AGHT+IE5n7wzdxxK0Bn06QxfJ4t6svXfBQbDNF0Z+i5em3jjg1Nj/clXwTGL5JUD9GQpEZ/MFSZ+ X-Received: by 2002:ac8:5c45:0:b0:429:bc8e:3e0 with SMTP id j5-20020ac85c45000000b00429bc8e03e0mr895605qtj.18.1704983188407; Thu, 11 Jan 2024 06:26:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704983188; cv=none; d=google.com; s=arc-20160816; b=Ny9fQYDr8ESco3ydnxkojRQMbRLNRbq/hMxCA/a5mCHefNfwO2ruU/kVkM12boPMnC qcU0FpUE0Sfomn0Zwo+r3MkD3mQIZDEK6kgKLMD9eaKAPg5ESupMp2/MK90HDHoW91DR PnJVJ3U5d9tEjgyjwS69g2h/TO2YsKieefCCWgJb4uFoMl0nmAVemmbNG56dfSMZKtlq ZQ82YUhjd4reOHAsk3szyVZZ96DsvgFU8lm1A1d/H187+WFp/457D5VWJlTLOP/1GUDu QMYz17Bv7ldgVPExPL5mFmKLYTLKKSPgS0CebyzOf40IbEY8nnvZ5Ow80XriZh01+TVW bYbw== 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=YWE1tVGsIn0zEV+TvKSOjYsl0DanjdWaNblTi9NxIMc=; fh=4xQMyYYtmbynAmJxwWPpZ6ivTwZNkSfAt6fhFI9aNBQ=; b=D5DBEWIQ+CyAvTenvQhPl2DYGgFrtlCZO3rLhga210LPsrxibd3na5ez/M5dTsL7ML nfhmxUqiPDJbv1g2nr6Ia/GGpjsy4/KR5FxuOyP2wIuC0zyAvMKXJ6D5fMza155zujni ZswhfiC1Rab04EXEDUv0XCxTWnKNTyN8J+9BVbT0V3BdFP10M76m6bh+FvrG0XlNwGlI AfAmPHxqWR0OLDhpYxEX7CmItlp3XAjijE0iv41JuRsX4nZJ/DqSXOUQOuGCEC99HTWh jNrKISHwXJE9rUrlMk4oFj5D82w4lIaD1esZ937bZec8LvqTAgBkJlhlQ8viQ+5GRkEf +5FQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Q7ddo9eM; 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 7-20020ac85947000000b00429c529ae98si985550qtz.266.2024.01.11.06.26.28 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 11 Jan 2024 06:26: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=Q7ddo9eM; 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 1rNvys-0004SI-Ip; Thu, 11 Jan 2024 09:24:26 -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 1rNvyl-0004Q1-TP for qemu-devel@nongnu.org; Thu, 11 Jan 2024 09:24:20 -0500 Received: from mail-wr1-x431.google.com ([2a00:1450:4864:20::431]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rNvyc-0002ie-Pa for qemu-devel@nongnu.org; Thu, 11 Jan 2024 09:24:17 -0500 Received: by mail-wr1-x431.google.com with SMTP id ffacd0b85a97d-3374eb61cbcso4837049f8f.0 for ; Thu, 11 Jan 2024 06:24:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1704983044; x=1705587844; 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=YWE1tVGsIn0zEV+TvKSOjYsl0DanjdWaNblTi9NxIMc=; b=Q7ddo9eMNb/c7HnnvX0iiEmQslCFcQRu1OyxsQ2XL8gi8Z50ZTp5Pwr5n/nDv+/qvZ VvTCUTI85APJzO/82XGW2gNyT7AiIBZgLdfPGNovg8OgQTicJB+DPKwI+nLrOrfZ8s53 fk+BJ0YP6cQg08TtWCn+vtl61h5XE8HBC+hWwrEb5siPLmvZdQmialIEY911Jx3pi205 /6ulw5iA2sCjnXJdMojeUY7OmGkY7/JNELfQEigYRS3yXpUGaU9ztUI97HAVQBpDa1c7 mHygybgYGw9M3v4tbqei0wU11uOSPG8VwO7SO2f5vPCnaKNQ5M67buhiUDM/5pUchUom BOCA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704983044; x=1705587844; 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=YWE1tVGsIn0zEV+TvKSOjYsl0DanjdWaNblTi9NxIMc=; b=c0Scj9XYfhcLsHSviudowrv38U/R2RNuB+CgqPQYDDe5qSdpPYHkzQVmunqTwuImIJ ZBdLqCJUNVX6R9SE77vMo3F26HwObiKmMcQT3s7gVCXWwCoQ/ZwPIlpgPUPPKLR6Vb66 ZUwlXe8/+20se80x+TwCyvXA3YxRnKcQjJEX0kd8aIBH5WNVGi4IEI88mUe6a8lrS3b4 kWJiMcuGwCY23lC5/Zj/SvF4QVWQmd+2RIhTC8dknbf7d4Gb2oPNGaxYMqFuEpcKpFQG eHUg5ur5ZbwAWGS02sI0kp07+KJ19m/S+gKCLJAGv5HQQoUX0vRtemYQHLRD9yXLNFjQ kqyQ== X-Gm-Message-State: AOJu0YxTMgON6h55QbWST1Z0hA7snKog+CHzOEJXu2XHQDf8W4VNzNz0 mDSGd2DH5nfkAjl6Vr6jxBw62AYI4/uR+A5WKZk+poXJDo/Keg== X-Received: by 2002:adf:ffc8:0:b0:337:76ae:34ca with SMTP id x8-20020adfffc8000000b0033776ae34camr762518wrs.77.1704983044702; Thu, 11 Jan 2024 06:24:04 -0800 (PST) Received: from linaro.. ([102.35.208.160]) by smtp.gmail.com with ESMTPSA id h7-20020adff4c7000000b0033677aae2e2sm1349000wrp.107.2024.01.11.06.24.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Jan 2024 06:24:04 -0800 (PST) From: Pierrick Bouvier To: qemu-devel@nongnu.org Cc: Pierrick Bouvier , =?utf-8?q?Alex_Benn?= =?utf-8?q?=C3=A9e?= , Mahmoud Mandour , Richard Henderson , Paolo Bonzini , Alexandre Iooss Subject: [PATCH 08/12] tests/plugin/bb: migrate to new per_vcpu API Date: Thu, 11 Jan 2024 18:23:21 +0400 Message-ID: <20240111142326.1743444-9-pierrick.bouvier@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240111142326.1743444-1-pierrick.bouvier@linaro.org> References: <20240111142326.1743444-1-pierrick.bouvier@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::431; envelope-from=pierrick.bouvier@linaro.org; helo=mail-wr1-x431.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 Since we need a fixed offset between count memory location, we now need a contiguous array of CPUCount (instead of array of pointers). Signed-off-by: Pierrick Bouvier Reviewed-by: Richard Henderson --- tests/plugin/bb.c | 54 +++++++++++++++++++++++------------------------ 1 file changed, 27 insertions(+), 27 deletions(-) diff --git a/tests/plugin/bb.c b/tests/plugin/bb.c index df50d1fd3bc..644a36f3128 100644 --- a/tests/plugin/bb.c +++ b/tests/plugin/bb.c @@ -16,6 +16,8 @@ QEMU_PLUGIN_EXPORT int qemu_plugin_version = QEMU_PLUGIN_VERSION; +#define MAX_CPUS 8 + typedef struct { GMutex lock; int index; @@ -23,14 +25,10 @@ typedef struct { uint64_t insn_count; } CPUCount; -/* Used by the inline & linux-user counts */ 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 CPUCount counts[MAX_CPUS]; static void gen_one_cpu_report(CPUCount *count, GString *report) { @@ -46,18 +44,26 @@ static void plugin_exit(qemu_plugin_id_t id, void *p) { g_autoptr(GString) report = g_string_new(""); - if (do_inline || !max_cpus) { + if (do_inline) { + uint64_t total_bb = 0; + uint64_t total_insn = 0; + for (int i = 0; i < MAX_CPUS; ++i) { + total_bb += counts[i].bb_count; + total_insn += counts[i].insn_count; + } g_string_printf(report, "bb's: %" PRIu64", insns: %" PRIu64 "\n", - inline_count.bb_count, inline_count.insn_count); + total_bb, total_insn); } else { - g_ptr_array_foreach(counts, (GFunc) gen_one_cpu_report, report); + for (int i = 0; i < MAX_CPUS; ++i) { + gen_one_cpu_report(&counts[i], report); + } } qemu_plugin_outs(report->str); } static void vcpu_idle(qemu_plugin_id_t id, unsigned int cpu_index) { - CPUCount *count = g_ptr_array_index(counts, cpu_index); + CPUCount *count = &counts[cpu_index]; g_autoptr(GString) report = g_string_new(""); gen_one_cpu_report(count, report); @@ -69,8 +75,7 @@ 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 = &counts[cpu_index]; uintptr_t n_insns = (uintptr_t)udata; g_mutex_lock(&count->lock); @@ -84,11 +89,13 @@ 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); + CPUCount *first_count = &counts[0]; + qemu_plugin_register_vcpu_tb_exec_inline_per_vcpu( + tb, QEMU_PLUGIN_INLINE_ADD_U64, + &first_count->bb_count, sizeof(CPUCount), 1); + qemu_plugin_register_vcpu_tb_exec_inline_per_vcpu( + tb, QEMU_PLUGIN_INLINE_ADD_U64, + &first_count->insn_count, sizeof(CPUCount), n_insns); } else { qemu_plugin_register_vcpu_tb_exec_cb(tb, vcpu_tb_exec, QEMU_PLUGIN_CB_NO_REGS, @@ -121,17 +128,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); + g_assert(info->system.smp_vcpus <= MAX_CPUS); + for (i = 0; i < MAX_CPUS; i++) { + CPUCount *count = &counts[i]; + count->index = i; } if (idle_report) {