From nobody Sat Sep 21 05:32:51 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1704983131; cv=none; d=zohomail.com; s=zohoarc; b=IYCMvaWFDSWmFWt5MnTRYg/ptAWOwhj8zw9ZnI8osd45WX+jcaaQMUWv4l4sMzefgNUItZD4dNb9H2MaLqXRRP4gyYGZwiqIsRT3qMDwS4grGhDBRWJtps2wGxW/g7QTh7zItXXWcTy7OqBovQR6vkZ761HCHkTjL8JFxbEJJEA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1704983131; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=IJ7j1cDsI/uXWEkCQ4Id/bagXB6Y2gY5m1Du+N1BU48=; b=MxxPu763wu1kMlJXYcm/DxtZhPoOrU5bcXHmIn+3HQH+Goc7qV0i+yU/aLctKLSBlJ0+Bg+H9/PNZ/7P1iITcfWr3UX201fGd2rVGVVluLQbSeYuMb4kqloRdpK3H+y2MzbFQofLHeNac+ahPnncm+bqPvpzqK9VXpapD1m6VWE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1704983131541636.1870578131201; Thu, 11 Jan 2024 06:25:31 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rNvyR-0004LB-Bk; Thu, 11 Jan 2024 09:23:59 -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 1rNvyO-0004KX-4y for qemu-devel@nongnu.org; Thu, 11 Jan 2024 09:23:56 -0500 Received: from mail-wr1-x432.google.com ([2a00:1450:4864:20::432]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rNvyG-0002Iq-Sb for qemu-devel@nongnu.org; Thu, 11 Jan 2024 09:23:52 -0500 Received: by mail-wr1-x432.google.com with SMTP id ffacd0b85a97d-3368ac0f74dso3746580f8f.0 for ; Thu, 11 Jan 2024 06:23:46 -0800 (PST) Received: from linaro.. ([102.35.208.160]) by smtp.gmail.com with ESMTPSA id h7-20020adff4c7000000b0033677aae2e2sm1349000wrp.107.2024.01.11.06.23.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Jan 2024 06:23:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1704983024; x=1705587824; 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=IJ7j1cDsI/uXWEkCQ4Id/bagXB6Y2gY5m1Du+N1BU48=; b=Qe6Nl1d2T0CXnGKGDLyVVf4YGDSlyjhfHRLj8h2nPeXFtfd4tLawDdqJNqmgoLB/kw RV/pNUfs3jLKbvUu1Wqk3x3y05J5iUBWLngcihxN9FPxsjt6JQnUovMS6Fp72MWUfGkM PL/e85f25fQRsXWfQ3SWAe2W/2i7yIAjDZh7Xc7607oanP3y0ZAifiuv8sm5u2v2RyJP y6vh/063zJd2QhSCrgNAd7ZQln/FYl1RJ245mctYMUremxlgDhFWcROYZQcqiLErQzae Z3NEfNNo8fqdbq5QUFdYB5f9A6jjWMaxx5OZ2MhkE+ZnSaglm4Z6A1D9TN5kC9KOoAKe pqZw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704983024; x=1705587824; 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=IJ7j1cDsI/uXWEkCQ4Id/bagXB6Y2gY5m1Du+N1BU48=; b=xLOH2k5vhALY/JMlqRkG1Zsb0cq8WrYBbRNyEstveIRbV3rlHw1w8TRKC84whFT4n7 rdKctalPY0jFnIu3AoqfF12K4JzeWMiz+QAnrAvRDSMDsYSrCbO4i5+wgCgiZp5Effpa o4x+T+mVO+s4Vg3aQ/RW4oSP9+VYd7CsJxAcixDM9KF0zWMctbIr3KYOuhEofvFpEDBY /UQEhwfslDueXm8HYDyfGcBESQ5i3p88QjJBpGX+enutUwcGaje+++o79oxB38UC0tvr T+zOMdJpEygU+ORAesNolQXMWILFY/o8ciRFtn8KQPArgHFY8UXfuRESU64j/KuCAP47 lZFw== X-Gm-Message-State: AOJu0Yx7Ih7E3KAxv9e1nv50TKDDOBWDJm9y4qOmumHUXhSfziJ7mhJv WdM6YcdRrA10/uyjlePWQPnyDUG2T9nHrHFSJvwyYq0PNrCPtA== X-Google-Smtp-Source: AGHT+IEuUNX3Ledm3oMOjhEYFkNf7usYSiFNsg9XTUgUTPj5CvDFDgPGC+svu/pBfWZOOMCKb0dOnA== X-Received: by 2002:a5d:480b:0:b0:337:62d3:f68a with SMTP id l11-20020a5d480b000000b0033762d3f68amr690624wrq.81.1704983024567; Thu, 11 Jan 2024 06:23:44 -0800 (PST) From: Pierrick Bouvier To: qemu-devel@nongnu.org Cc: Pierrick Bouvier , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Mahmoud Mandour , Richard Henderson , Paolo Bonzini , Alexandre Iooss Subject: [PATCH 01/12] plugins: implement inline operation with cpu_index offset Date: Thu, 11 Jan 2024 18:23:14 +0400 Message-ID: <20240111142326.1743444-2-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 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::432; envelope-from=pierrick.bouvier@linaro.org; helo=mail-wr1-x432.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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1704983132066100002 Content-Type: text/plain; charset="utf-8" Instead of working on a fixed memory location, allow to index it based on cpu_index and a given offset (ptr + cpu_index * offset). Current semantic is not modified as we use a 0 offset, thus inline operation still targets always the same memory location. Signed-off-by: Pierrick Bouvier Reviewed-by: Richard Henderson --- accel/tcg/plugin-gen.c | 60 +++++++++++++++++++++++++++++++++++------- include/qemu/plugin.h | 1 + plugins/api.c | 7 ++--- plugins/core.c | 11 +++++--- plugins/plugin.h | 5 ++-- 5 files changed, 65 insertions(+), 19 deletions(-) diff --git a/accel/tcg/plugin-gen.c b/accel/tcg/plugin-gen.c index 78b331b2510..fc9d3ee23bc 100644 --- a/accel/tcg/plugin-gen.c +++ b/accel/tcg/plugin-gen.c @@ -118,16 +118,28 @@ static void gen_empty_udata_cb(void) */ static void gen_empty_inline_cb(void) { + TCGv_i32 cpu_index =3D tcg_temp_ebb_new_i32(); + TCGv_ptr cpu_index_as_ptr =3D tcg_temp_ebb_new_ptr(); TCGv_i64 val =3D tcg_temp_ebb_new_i64(); TCGv_ptr ptr =3D tcg_temp_ebb_new_ptr(); =20 + tcg_gen_ld_i32(cpu_index, tcg_env, + -offsetof(ArchCPU, env) + offsetof(CPUState, cpu_index)= ); + /* pass an immediate !=3D 0 so that it doesn't get optimized away */ + tcg_gen_muli_i32(cpu_index, cpu_index, 0xdeadbeef); + tcg_gen_ext_i32_ptr(cpu_index_as_ptr, cpu_index); + tcg_gen_movi_ptr(ptr, 0); + tcg_gen_add_ptr(ptr, ptr, cpu_index_as_ptr); tcg_gen_ld_i64(val, ptr, 0); /* pass an immediate !=3D 0 so that it doesn't get optimized away */ tcg_gen_addi_i64(val, val, 0xdeadface); + tcg_gen_st_i64(val, ptr, 0); tcg_temp_free_ptr(ptr); tcg_temp_free_i64(val); + tcg_temp_free_ptr(cpu_index_as_ptr); + tcg_temp_free_i32(cpu_index); } =20 static void gen_empty_mem_cb(TCGv_i64 addr, uint32_t info) @@ -274,12 +286,37 @@ static TCGOp *copy_const_ptr(TCGOp **begin_op, TCGOp = *op, void *ptr) return op; } =20 +static TCGOp *copy_ld_i32(TCGOp **begin_op, TCGOp *op) +{ + return copy_op(begin_op, op, INDEX_op_ld_i32); +} + +static TCGOp *copy_ext_i32_ptr(TCGOp **begin_op, TCGOp *op) +{ + if (UINTPTR_MAX =3D=3D UINT32_MAX) { + op =3D copy_op(begin_op, op, INDEX_op_mov_i32); + } else { + op =3D copy_op(begin_op, op, INDEX_op_ext_i32_i64); + } + return op; +} + +static TCGOp *copy_add_ptr(TCGOp **begin_op, TCGOp *op) +{ + if (UINTPTR_MAX =3D=3D UINT32_MAX) { + op =3D copy_op(begin_op, op, INDEX_op_add_i32); + } else { + op =3D copy_op(begin_op, op, INDEX_op_add_i64); + } + return op; +} + static TCGOp *copy_ld_i64(TCGOp **begin_op, TCGOp *op) { if (TCG_TARGET_REG_BITS =3D=3D 32) { /* 2x ld_i32 */ - op =3D copy_op(begin_op, op, INDEX_op_ld_i32); - op =3D copy_op(begin_op, op, INDEX_op_ld_i32); + op =3D copy_ld_i32(begin_op, op); + op =3D copy_ld_i32(begin_op, op); } else { /* ld_i64 */ op =3D copy_op(begin_op, op, INDEX_op_ld_i64); @@ -315,6 +352,13 @@ static TCGOp *copy_add_i64(TCGOp **begin_op, TCGOp *op= , uint64_t v) return op; } =20 +static TCGOp *copy_mul_i32(TCGOp **begin_op, TCGOp *op, uint32_t v) +{ + op =3D copy_op(begin_op, op, INDEX_op_mul_i32); + op->args[2] =3D tcgv_i32_arg(tcg_constant_i32(v)); + return op; +} + static TCGOp *copy_st_ptr(TCGOp **begin_op, TCGOp *op) { if (UINTPTR_MAX =3D=3D UINT32_MAX) { @@ -380,18 +424,14 @@ static TCGOp *append_inline_cb(const struct qemu_plug= in_dyn_cb *cb, TCGOp *begin_op, TCGOp *op, int *unused) { - /* const_ptr */ + op =3D copy_ld_i32(&begin_op, op); + op =3D copy_mul_i32(&begin_op, op, cb->userp_offset); + op =3D copy_ext_i32_ptr(&begin_op, op); op =3D copy_const_ptr(&begin_op, op, cb->userp); - - /* ld_i64 */ + op =3D copy_add_ptr(&begin_op, op); op =3D copy_ld_i64(&begin_op, op); - - /* add_i64 */ op =3D copy_add_i64(&begin_op, op, cb->inline_insn.imm); - - /* st_i64 */ op =3D copy_st_i64(&begin_op, op); - return op; } =20 diff --git a/include/qemu/plugin.h b/include/qemu/plugin.h index 7fdc3a4849f..4548affc295 100644 --- a/include/qemu/plugin.h +++ b/include/qemu/plugin.h @@ -85,6 +85,7 @@ enum plugin_dyn_cb_subtype { struct qemu_plugin_dyn_cb { union qemu_plugin_cb_sig f; void *userp; + size_t userp_offset; enum plugin_dyn_cb_subtype type; /* @rw applies to mem callbacks only (both regular and inline) */ enum qemu_plugin_mem_rw rw; diff --git a/plugins/api.c b/plugins/api.c index 5521b0ad36c..0fcce825680 100644 --- a/plugins/api.c +++ b/plugins/api.c @@ -99,7 +99,8 @@ void qemu_plugin_register_vcpu_tb_exec_inline(struct qemu= _plugin_tb *tb, void *ptr, uint64_t imm) { if (!tb->mem_only) { - plugin_register_inline_op(&tb->cbs[PLUGIN_CB_INLINE], 0, op, ptr, = imm); + plugin_register_inline_op(&tb->cbs[PLUGIN_CB_INLINE], + 0, op, ptr, 0, imm); } } =20 @@ -120,7 +121,7 @@ void qemu_plugin_register_vcpu_insn_exec_inline(struct = qemu_plugin_insn *insn, { if (!insn->mem_only) { plugin_register_inline_op(&insn->cbs[PLUGIN_CB_INSN][PLUGIN_CB_INL= INE], - 0, op, ptr, imm); + 0, op, ptr, 0, imm); } } =20 @@ -145,7 +146,7 @@ void qemu_plugin_register_vcpu_mem_inline(struct qemu_p= lugin_insn *insn, uint64_t imm) { plugin_register_inline_op(&insn->cbs[PLUGIN_CB_MEM][PLUGIN_CB_INLINE], - rw, op, ptr, imm); + rw, op, ptr, 0, imm); } =20 void qemu_plugin_register_vcpu_tb_trans_cb(qemu_plugin_id_t id, diff --git a/plugins/core.c b/plugins/core.c index 49588285dd0..cc6d7720b1f 100644 --- a/plugins/core.c +++ b/plugins/core.c @@ -280,13 +280,15 @@ static struct qemu_plugin_dyn_cb *plugin_get_dyn_cb(G= Array **arr) =20 void plugin_register_inline_op(GArray **arr, enum qemu_plugin_mem_rw rw, - enum qemu_plugin_op op, void *ptr, + enum qemu_plugin_op op, + void *ptr, size_t offset, uint64_t imm) { struct qemu_plugin_dyn_cb *dyn_cb; =20 dyn_cb =3D plugin_get_dyn_cb(arr); dyn_cb->userp =3D ptr; + dyn_cb->userp_offset =3D offset; dyn_cb->type =3D PLUGIN_CB_INLINE; dyn_cb->rw =3D rw; dyn_cb->inline_insn.op =3D op; @@ -431,9 +433,10 @@ void qemu_plugin_flush_cb(void) plugin_cb__simple(QEMU_PLUGIN_EV_FLUSH); } =20 -void exec_inline_op(struct qemu_plugin_dyn_cb *cb) +void exec_inline_op(struct qemu_plugin_dyn_cb *cb, int cpu_index) { - uint64_t *val =3D cb->userp; + const size_t offset =3D cpu_index * cb->userp_offset; + uint64_t *val =3D (uint64_t *)((char *) cb->userp + offset); =20 switch (cb->inline_insn.op) { case QEMU_PLUGIN_INLINE_ADD_U64: @@ -466,7 +469,7 @@ void qemu_plugin_vcpu_mem_cb(CPUState *cpu, uint64_t va= ddr, vaddr, cb->userp); break; case PLUGIN_CB_INLINE: - exec_inline_op(cb); + exec_inline_op(cb, cpu->cpu_index); break; default: g_assert_not_reached(); diff --git a/plugins/plugin.h b/plugins/plugin.h index 5eb2fdbc85e..e597ef3c30e 100644 --- a/plugins/plugin.h +++ b/plugins/plugin.h @@ -66,7 +66,8 @@ struct qemu_plugin_ctx *plugin_id_to_ctx_locked(qemu_plug= in_id_t id); =20 void plugin_register_inline_op(GArray **arr, enum qemu_plugin_mem_rw rw, - enum qemu_plugin_op op, void *ptr, + enum qemu_plugin_op op, + void *ptr, size_t offset, uint64_t imm); =20 void plugin_reset_uninstall(qemu_plugin_id_t id, @@ -95,6 +96,6 @@ void plugin_register_vcpu_mem_cb(GArray **arr, enum qemu_plugin_mem_rw rw, void *udata); =20 -void exec_inline_op(struct qemu_plugin_dyn_cb *cb); +void exec_inline_op(struct qemu_plugin_dyn_cb *cb, int cpu_index); =20 #endif /* PLUGIN_H */ --=20 2.43.0 From nobody Sat Sep 21 05:32:51 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1704983112; cv=none; d=zohomail.com; s=zohoarc; b=Gs0iDlHGCzjAwdAVKhS0mm5OFC+WJEnRLQfntwORi9WgGaGVS6pEzIq1WhO1PSAQ5yT1mbxwIzoZFGIl0So9VUJ82WzssYxG44JStDDNR7ltOlUHk0wJL7uLEz3mQWLUlegYm1o4QJTCyOpR8NuBAUWmpPxguE9Yr/6J+RZpkxQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1704983112; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=9c37JOuaNhDBeKaXx4tgumlULh1m5+dxPGdg6049b/w=; b=C64r0ua8zwuK3tNz0cQzNL2rmChjHPVidFtbwHYgoKTlGwv14P0Uix1WsQlKB4cQ+XILOyxWX5I1PfrU8B+Xe7nlpcfPD5Qg34aIdjOpd2Ay+xqeU5DEDgf/CplmkEF08mT7pmpyq0FzsWBuKCyTK1Xy9NfWbiQWiYEs+5uaPmg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1704983112065830.8310455867338; Thu, 11 Jan 2024 06:25:12 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rNvyW-0004Mv-Jm; Thu, 11 Jan 2024 09:24:04 -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 1rNvyR-0004LP-Jo for qemu-devel@nongnu.org; Thu, 11 Jan 2024 09:24:00 -0500 Received: from mail-wr1-x42f.google.com ([2a00:1450:4864:20::42f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rNvyJ-0002Je-I7 for qemu-devel@nongnu.org; Thu, 11 Jan 2024 09:23:57 -0500 Received: by mail-wr1-x42f.google.com with SMTP id ffacd0b85a97d-3376555b756so3138564f8f.0 for ; Thu, 11 Jan 2024 06:23:48 -0800 (PST) Received: from linaro.. ([102.35.208.160]) by smtp.gmail.com with ESMTPSA id h7-20020adff4c7000000b0033677aae2e2sm1349000wrp.107.2024.01.11.06.23.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Jan 2024 06:23:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1704983027; x=1705587827; 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=9c37JOuaNhDBeKaXx4tgumlULh1m5+dxPGdg6049b/w=; b=FkwwlSjzBenwbfpkxNVcPtlIrh37eXa7GUBIe7cEwSi4tBh6CQ5BlwVojTq4Gv/Y6X W+Q4R3BOH2VUbI7pv54SgRnQTgP+jSpIzU7G8RkbQ7v/Fnw938Y16Gac5Q6f0pdlc+4i ShX8NvTyQYYOj/x190hSr+rWMjKGs0No59tErrYNsuLC9UKBLRRn4Aj7WmEDQtwu1cPT c1qEm/OgDz//CCXUyhnu6vrK6fx/J9dl6ZhOtPYZg9FdgQDrb10nkhZ0aYiPh/0D1od/ xigRQdNlBCTxb/Gj8hRy5hdJ06KcSeibUvDx9k3YjqxQLYJiozry5oXqb8Y31uGPseFj uhWw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704983027; x=1705587827; 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=9c37JOuaNhDBeKaXx4tgumlULh1m5+dxPGdg6049b/w=; b=t3z9vuFDbJ5MvnahYk8QO3OUU8/2ZS5cHxwF/p/PUU4Cm6uprUSPc6rf82dZaBSpsa CIn8dn8Hve14XS/agmjCluHNoB8U7X5t5NhySR7duNpqZs//I+ELDB03HsBYHo+8sgr8 P23yqwZSb/VU/5OG43B3S6f7scgImqbvlfRjsrx6uq8A7q2xAS+iqKtjklIxC99DE1uN VCqlCb/QGeLDx1wc3/yMOzJt+tfdtaT0tBFob8eiegI7zXLm+4LIObgnrQFqywqv+5ce bgXVgcJfV9bV3q84EuFxm8d8g+YfnWGoPuwPAzV14aytwaqSbJHPWKuB+JVIufA2joiZ Pdrg== X-Gm-Message-State: AOJu0YyzPHkrRPBiBDPtiou71Y8GCpwFXyiX50lL70WPx22HDq/pxPaQ rUyHvFpItP9/ofwfYyK273taBWaASf9zm/nJ0200R5Xulv5Qrg== X-Google-Smtp-Source: AGHT+IFLVTS2r2J1dDqxVzx6y1UsSSuqnNccwWUAGiXomqiX8XONmHN88U2tjtrkaMuOU8iZh8ZKcQ== X-Received: by 2002:adf:f811:0:b0:337:6208:99df with SMTP id s17-20020adff811000000b00337620899dfmr610967wrp.20.1704983027314; Thu, 11 Jan 2024 06:23:47 -0800 (PST) From: Pierrick Bouvier To: qemu-devel@nongnu.org Cc: Pierrick Bouvier , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Mahmoud Mandour , Richard Henderson , Paolo Bonzini , Alexandre Iooss Subject: [PATCH 02/12] plugins: add inline operation per vcpu Date: Thu, 11 Jan 2024 18:23:15 +0400 Message-ID: <20240111142326.1743444-3-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 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::42f; envelope-from=pierrick.bouvier@linaro.org; helo=mail-wr1-x42f.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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1704983114005100010 Content-Type: text/plain; charset="utf-8" Extends API with three new functions: qemu_plugin_register_vcpu_{tb, insn, mem}_exec_inline_per_vcpu(). Compared to non per_vcpu versions, ptr is now a base, and current cpu_index and an offset are used to compute memory location on which operation happens (ptr + cpu_index * offset). This allows to have a thread-safe version of inline operations. Having a flexible offset is useful in case a user wants to target a memory location embedded into a struct. In this case, the offset between two memory locations will be bigger than sizeof(uint64_t). Signed-off-by: Pierrick Bouvier Reviewed-by: Richard Henderson --- include/qemu/qemu-plugin.h | 56 +++++++++++++++++++++++++++++++++++- plugins/api.c | 36 ++++++++++++++++++++--- plugins/qemu-plugins.symbols | 3 ++ 3 files changed, 90 insertions(+), 5 deletions(-) diff --git a/include/qemu/qemu-plugin.h b/include/qemu/qemu-plugin.h index 4daab6efd29..8a0691a760e 100644 --- a/include/qemu/qemu-plugin.h +++ b/include/qemu/qemu-plugin.h @@ -312,6 +312,25 @@ void qemu_plugin_register_vcpu_tb_exec_inline(struct q= emu_plugin_tb *tb, enum qemu_plugin_op op, void *ptr, uint64_t imm); =20 +/** + * qemu_plugin_register_vcpu_tb_exec_inline_per_vcpu() - execution inline = op + * @tb: the opaque qemu_plugin_tb handle for the translation + * @op: the type of qemu_plugin_op (e.g. ADD_U64) + * @ptr: point to memory location for the op + * @offset: offset between two memory locations + * @imm: the op data (e.g. 1) + * + * Insert an inline op, on a memory location associated to a given + * vcpu (whose address is ptr + offset * cpu_index), + * every time a translated unit executes. + */ +QEMU_PLUGIN_API +void qemu_plugin_register_vcpu_tb_exec_inline_per_vcpu( + struct qemu_plugin_tb *tb, + enum qemu_plugin_op op, + void *ptr, size_t offset, + uint64_t imm); + /** * qemu_plugin_register_vcpu_insn_exec_cb() - register insn execution cb * @insn: the opaque qemu_plugin_insn handle for an instruction @@ -342,6 +361,23 @@ void qemu_plugin_register_vcpu_insn_exec_inline(struct= qemu_plugin_insn *insn, enum qemu_plugin_op op, void *ptr, uint64_t imm); =20 +/** + * qemu_plugin_register_vcpu_insn_exec_inline_per_vcpu() - insn exec inlin= e op + * @insn: the opaque qemu_plugin_insn handle for an instruction + * @op: the type of qemu_plugin_op (e.g. ADD_U64) + * @ptr: point to array of memory locations for the op + * @offset: offset between two memory locations + * @imm: the op data (e.g. 1) + * + * Insert an inline op to every time an instruction executes. + */ +QEMU_PLUGIN_API +void qemu_plugin_register_vcpu_insn_exec_inline_per_vcpu( + struct qemu_plugin_insn *insn, + enum qemu_plugin_op op, + void *ptr, size_t offset, + uint64_t imm); + /** * qemu_plugin_tb_n_insns() - query helper for number of insns in TB * @tb: opaque handle to TB passed to callback @@ -567,7 +603,25 @@ void qemu_plugin_register_vcpu_mem_inline(struct qemu_= plugin_insn *insn, enum qemu_plugin_op op, void *pt= r, uint64_t imm); =20 - +/** + * qemu_plugin_register_vcpu_mem_inline_per_vcpu() - inline op for mem acc= ess + * @insn: handle for instruction to instrument + * @rw: apply to reads, writes or both + * @op: the op, of type qemu_plugin_op + * @ptr: point to array of memory locations for the op + * @offset: offset between two memory locations + * @imm: immediate data for @op + * + * This registers a inline op every memory access generated by the + * instruction. + */ +QEMU_PLUGIN_API +void qemu_plugin_register_vcpu_mem_inline_per_vcpu( + struct qemu_plugin_insn *insn, + enum qemu_plugin_mem_rw rw, + enum qemu_plugin_op op, + void *ptr, size_t offset, + uint64_t imm); =20 typedef void (*qemu_plugin_vcpu_syscall_cb_t)(qemu_plugin_id_t id, unsigned int vcpu_in= dex, diff --git a/plugins/api.c b/plugins/api.c index 0fcce825680..fd6ce678501 100644 --- a/plugins/api.c +++ b/plugins/api.c @@ -97,10 +97,19 @@ void qemu_plugin_register_vcpu_tb_exec_cb(struct qemu_p= lugin_tb *tb, void qemu_plugin_register_vcpu_tb_exec_inline(struct qemu_plugin_tb *tb, enum qemu_plugin_op op, void *ptr, uint64_t imm) +{ + qemu_plugin_register_vcpu_tb_exec_inline_per_vcpu(tb, op, ptr, 0, imm); +} + +void qemu_plugin_register_vcpu_tb_exec_inline_per_vcpu( + struct qemu_plugin_tb *tb, + enum qemu_plugin_op op, + void *ptr, size_t offset, + uint64_t imm) { if (!tb->mem_only) { plugin_register_inline_op(&tb->cbs[PLUGIN_CB_INLINE], - 0, op, ptr, 0, imm); + 0, op, ptr, offset, imm); } } =20 @@ -118,10 +127,19 @@ void qemu_plugin_register_vcpu_insn_exec_cb(struct qe= mu_plugin_insn *insn, void qemu_plugin_register_vcpu_insn_exec_inline(struct qemu_plugin_insn *i= nsn, enum qemu_plugin_op op, void *ptr, uint64_t imm) +{ + qemu_plugin_register_vcpu_insn_exec_inline_per_vcpu(insn, op, ptr, 0, = imm); +} + +void qemu_plugin_register_vcpu_insn_exec_inline_per_vcpu( + struct qemu_plugin_insn *insn, + enum qemu_plugin_op op, + void *ptr, size_t offset, + uint64_t imm) { if (!insn->mem_only) { plugin_register_inline_op(&insn->cbs[PLUGIN_CB_INSN][PLUGIN_CB_INL= INE], - 0, op, ptr, 0, imm); + 0, op, ptr, offset, imm); } } =20 @@ -137,16 +155,26 @@ void qemu_plugin_register_vcpu_mem_cb(struct qemu_plu= gin_insn *insn, void *udata) { plugin_register_vcpu_mem_cb(&insn->cbs[PLUGIN_CB_MEM][PLUGIN_CB_REGULA= R], - cb, flags, rw, udata); + cb, flags, rw, udata); } =20 void qemu_plugin_register_vcpu_mem_inline(struct qemu_plugin_insn *insn, enum qemu_plugin_mem_rw rw, enum qemu_plugin_op op, void *pt= r, uint64_t imm) +{ + qemu_plugin_register_vcpu_mem_inline_per_vcpu(insn, rw, op, ptr, 0, im= m); +} + +void qemu_plugin_register_vcpu_mem_inline_per_vcpu( + struct qemu_plugin_insn *insn, + enum qemu_plugin_mem_rw rw, + enum qemu_plugin_op op, + void *ptr, size_t offset, + uint64_t imm) { plugin_register_inline_op(&insn->cbs[PLUGIN_CB_MEM][PLUGIN_CB_INLINE], - rw, op, ptr, 0, imm); + rw, op, ptr, offset, imm); } =20 void qemu_plugin_register_vcpu_tb_trans_cb(qemu_plugin_id_t id, diff --git a/plugins/qemu-plugins.symbols b/plugins/qemu-plugins.symbols index 71f6c90549d..56ba30e5a81 100644 --- a/plugins/qemu-plugins.symbols +++ b/plugins/qemu-plugins.symbols @@ -27,13 +27,16 @@ qemu_plugin_register_vcpu_init_cb; qemu_plugin_register_vcpu_insn_exec_cb; qemu_plugin_register_vcpu_insn_exec_inline; + qemu_plugin_register_vcpu_insn_exec_inline_per_vcpu; qemu_plugin_register_vcpu_mem_cb; qemu_plugin_register_vcpu_mem_inline; + qemu_plugin_register_vcpu_mem_inline_per_vcpu; qemu_plugin_register_vcpu_resume_cb; qemu_plugin_register_vcpu_syscall_cb; qemu_plugin_register_vcpu_syscall_ret_cb; qemu_plugin_register_vcpu_tb_exec_cb; qemu_plugin_register_vcpu_tb_exec_inline; + qemu_plugin_register_vcpu_tb_exec_inline_per_vcpu; qemu_plugin_register_vcpu_tb_trans_cb; qemu_plugin_reset; qemu_plugin_start_code; --=20 2.43.0 From nobody Sat Sep 21 05:32:51 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1704983100; cv=none; d=zohomail.com; s=zohoarc; b=CtEYL42cHuVYFuBhv4kyPAHwhbtfa0wBzGxIcRlatmRlydyhOcmT6Anxcgx2k7Pk5JTQ1OhlzYUjzQ/h/8hFLPdBfgU1d8cZeoUHgbKKMPaGwQzQvz+Bq6vb9NuPO9aGzKGMw6Wj+FQqcdP7gdC97fvDVIfxXQMlG8H1eURQl5g= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1704983100; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=Uz8JV8pCaZV1R2zPKE6qluGGJZ0UQ4yZCw51RxB81hM=; b=QBZRmA2iveE2+wqVOQ3HzqN4cZVhCID2pUl1S6iawwvX6G19jzK447mNR2AUMZJCjM9oDZCqJ4IswwEglKoj7h31/vDzByUirWa01m14ARJnTRcCXgjzZyHENSVf6C7ToRFFQaDj27CgBMQD1JjPaWEDoFaObFsIjg1riBTTOeI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1704983100624274.81458248711215; Thu, 11 Jan 2024 06:25:00 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rNvyU-0004M3-NE; Thu, 11 Jan 2024 09:24:02 -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 1rNvyR-0004LQ-Jh for qemu-devel@nongnu.org; Thu, 11 Jan 2024 09:24:00 -0500 Received: from mail-wr1-x42d.google.com ([2a00:1450:4864:20::42d]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rNvyL-0002OV-QO for qemu-devel@nongnu.org; Thu, 11 Jan 2024 09:23:59 -0500 Received: by mail-wr1-x42d.google.com with SMTP id ffacd0b85a97d-3373bc6d625so4635703f8f.3 for ; Thu, 11 Jan 2024 06:23:52 -0800 (PST) Received: from linaro.. ([102.35.208.160]) by smtp.gmail.com with ESMTPSA id h7-20020adff4c7000000b0033677aae2e2sm1349000wrp.107.2024.01.11.06.23.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Jan 2024 06:23:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1704983030; x=1705587830; 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=Uz8JV8pCaZV1R2zPKE6qluGGJZ0UQ4yZCw51RxB81hM=; b=z8Fd4pSPGJDC7q+zO7bfmdtfnLXCPrj2PV4yhL7WThdkjyI4h01oN+OZdTyyTZU8fZ 1W7eBh85Rj7Rf2rv68Tw4SkzpGTPuaM1BMAP0gR+Cd8F8bd7txxSdbwjMmbfxrozJNge PoEc8TwWlEvt6wsY+oYnt/YNerPueAVXJrEE48J5J06QB5gorFBWTDVVEwIDxYWVCi+p 4ZnaQXxWhA6erbO0ahqvDRonXi/8MIiQMRTJl00mh42S+/ntBKi4vOkvEk1hHV3vVkF2 J7li879BI6SZNg9AYsqIgz/wqAe+vRecLVT9OVT7NGEYyiobMDF6OCuf/RQMHuxOWu0q Bgiw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704983030; x=1705587830; 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=Uz8JV8pCaZV1R2zPKE6qluGGJZ0UQ4yZCw51RxB81hM=; b=mwvRlZXpJnsU/M8j1KVcbs8P54IjTwfMDaNhmcDby/CNuvQWulfJJTxYwbFCYDXZVA +jAxrLuEM5NVLwT6RTTSxCOiv1wFmQXreanp6kpSYL3DYOL1DPw3BIG0/QE69TVjfc5M PMd307JjSIGGAvug97BNv1ost73TTilejvhmqDleRPTHOMpgbAq0Hzm0LiWqL+XHlnit PscJOEad5q2MT/eX5HSOuA/EYWXq5zkJ5Ae20iC4xdcv55NP3W3Xjcnl/R+KXBxky+yy OLHF6o+BuZh02WQd6uO766vNujIyfmeXO0j5Wqn9lEHRoDvPGVR6zd0KhmwFuqQns/pn yREg== X-Gm-Message-State: AOJu0Yyj9pou2drFFn0QYPbYS9gzL1qLoS+hO/rOBTEeItWIVy6VUXxJ KnRNChnOIZXRR+gE6LcJ9DhVeEQPlQw1fr/sb2UHVokLri2PPw== X-Google-Smtp-Source: AGHT+IEAH0aL1j46YIMUZVn4p6Gc+I60280gsbAE3h74CoEkGdp6MmnkQcJRPMVgWUR+rU6NWEZFMg== X-Received: by 2002:a5d:4449:0:b0:336:96d:475c with SMTP id x9-20020a5d4449000000b00336096d475cmr758971wrr.5.1704983030205; Thu, 11 Jan 2024 06:23:50 -0800 (PST) From: Pierrick Bouvier To: qemu-devel@nongnu.org Cc: Pierrick Bouvier , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Mahmoud Mandour , Richard Henderson , Paolo Bonzini , Alexandre Iooss Subject: [PATCH 03/12] tests/plugin: add test plugin for inline operations Date: Thu, 11 Jan 2024 18:23:16 +0400 Message-ID: <20240111142326.1743444-4-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 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::42d; envelope-from=pierrick.bouvier@linaro.org; helo=mail-wr1-x42d.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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1704983101921100004 Content-Type: text/plain; charset="utf-8" For now, it simply performs instruction, bb and mem count, and ensure that inline vs callback versions have the same result. Later, we'll extend it when new inline operations are added. Use existing plugins to test everything works is a bit cumbersome, as different events are treated in different plugins. Thus, this new one. Signed-off-by: Pierrick Bouvier --- tests/plugin/inline.c | 183 +++++++++++++++++++++++++++++++++++++++ tests/plugin/meson.build | 2 +- 2 files changed, 184 insertions(+), 1 deletion(-) create mode 100644 tests/plugin/inline.c diff --git a/tests/plugin/inline.c b/tests/plugin/inline.c new file mode 100644 index 00000000000..6114ebca545 --- /dev/null +++ b/tests/plugin/inline.c @@ -0,0 +1,183 @@ +/* + * Copyright (C) 2023, Pierrick Bouvier + * + * Demonstrates and tests usage of inline ops. + * + * License: GNU GPL, version 2 or later. + * See the COPYING file in the top-level directory. + */ + +#include +#include +#include + +#include + +#define MAX_CPUS 8 + +static uint64_t count_tb; +static uint64_t count_tb_per_vcpu[MAX_CPUS]; +static uint64_t count_tb_inline_per_vcpu[MAX_CPUS]; +static uint64_t count_tb_inline_racy; +static uint64_t count_insn; +static uint64_t count_insn_per_vcpu[MAX_CPUS]; +static uint64_t count_insn_inline_per_vcpu[MAX_CPUS]; +static uint64_t count_insn_inline_racy; +static uint64_t count_mem; +static uint64_t count_mem_per_vcpu[MAX_CPUS]; +static uint64_t count_mem_inline_per_vcpu[MAX_CPUS]; +static uint64_t count_mem_inline_racy; +static GMutex tb_lock; +static GMutex insn_lock; +static GMutex mem_lock; + +QEMU_PLUGIN_EXPORT int qemu_plugin_version =3D QEMU_PLUGIN_VERSION; + +static uint64_t collect_per_vcpu(uint64_t *values) +{ + uint64_t count =3D 0; + for (int i =3D 0; i < MAX_CPUS; ++i) { + count +=3D values[i]; + } + return count; +} + +static void stats_insn(void) +{ + const uint64_t expected =3D count_insn; + const uint64_t per_vcpu =3D collect_per_vcpu(count_insn_per_vcpu); + const uint64_t inl_per_vcpu =3D collect_per_vcpu(count_insn_inline_per= _vcpu); + printf("insn: %" PRIu64 "\n", expected); + printf("insn: %" PRIu64 " (per vcpu)\n", per_vcpu); + printf("insn: %" PRIu64 " (per vcpu inline)\n", inl_per_vcpu); + printf("insn: %" PRIu64 " (inline racy)\n", count_insn_inline_racy); + g_assert(expected > 0); + g_assert(per_vcpu =3D=3D expected); + g_assert(inl_per_vcpu =3D=3D expected); + g_assert(count_insn_inline_racy <=3D expected); +} + +static void stats_tb(void) +{ + const uint64_t expected =3D count_tb; + const uint64_t per_vcpu =3D collect_per_vcpu(count_tb_per_vcpu); + const uint64_t inl_per_vcpu =3D collect_per_vcpu(count_tb_inline_per_v= cpu); + printf("tb: %" PRIu64 "\n", expected); + printf("tb: %" PRIu64 " (per vcpu)\n", per_vcpu); + printf("tb: %" PRIu64 " (per vcpu inline)\n", inl_per_vcpu); + printf("tb: %" PRIu64 " (inline racy)\n", count_tb_inline_racy); + g_assert(expected > 0); + g_assert(per_vcpu =3D=3D expected); + g_assert(inl_per_vcpu =3D=3D expected); + g_assert(count_tb_inline_racy <=3D expected); +} + +static void stats_mem(void) +{ + const uint64_t expected =3D count_mem; + const uint64_t per_vcpu =3D collect_per_vcpu(count_mem_per_vcpu); + const uint64_t inl_per_vcpu =3D collect_per_vcpu(count_mem_inline_per_= vcpu); + printf("mem: %" PRIu64 "\n", expected); + printf("mem: %" PRIu64 " (per vcpu)\n", per_vcpu); + printf("mem: %" PRIu64 " (per vcpu inline)\n", inl_per_vcpu); + printf("mem: %" PRIu64 " (inline racy)\n", count_mem_inline_racy); + g_assert(expected > 0); + g_assert(per_vcpu =3D=3D expected); + g_assert(inl_per_vcpu =3D=3D expected); + g_assert(count_mem_inline_racy <=3D expected); +} + +static void plugin_exit(qemu_plugin_id_t id, void *udata) +{ + for (int i =3D 0; i < MAX_CPUS; ++i) { + const uint64_t tb =3D count_tb_per_vcpu[i]; + const uint64_t tb_inline =3D count_tb_inline_per_vcpu[i]; + const uint64_t insn =3D count_insn_per_vcpu[i]; + const uint64_t insn_inline =3D count_insn_inline_per_vcpu[i]; + const uint64_t mem =3D count_mem_per_vcpu[i]; + const uint64_t mem_inline =3D count_mem_inline_per_vcpu[i]; + printf("cpu %d: tb (%" PRIu64 ", %" PRIu64 ") | " + "insn (%" PRIu64 ", %" PRIu64 ") | " + "mem (%" PRIu64 ", %" PRIu64 ")" + "\n", + i, tb, tb_inline, insn, insn_inline, mem, mem_inline); + g_assert(tb =3D=3D tb_inline); + g_assert(insn =3D=3D insn_inline); + g_assert(mem =3D=3D mem_inline); + } + + stats_tb(); + stats_insn(); + stats_mem(); +} + +static void vcpu_tb_exec(unsigned int cpu_index, void *udata) +{ + count_tb_per_vcpu[cpu_index]++; + g_mutex_lock(&tb_lock); + count_tb++; + g_mutex_unlock(&tb_lock); +} + +static void vcpu_insn_exec(unsigned int cpu_index, void *udata) +{ + count_insn_per_vcpu[cpu_index]++; + g_mutex_lock(&insn_lock); + count_insn++; + g_mutex_unlock(&insn_lock); +} + +static void vcpu_mem_access(unsigned int cpu_index, + qemu_plugin_meminfo_t info, + uint64_t vaddr, + void *userdata) +{ + count_mem_per_vcpu[cpu_index]++; + g_mutex_lock(&mem_lock); + count_mem++; + g_mutex_unlock(&mem_lock); +} + +static void vcpu_tb_trans(qemu_plugin_id_t id, struct qemu_plugin_tb *tb) +{ + qemu_plugin_register_vcpu_tb_exec_cb(tb, vcpu_tb_exec, + QEMU_PLUGIN_CB_NO_REGS, 0); + qemu_plugin_register_vcpu_tb_exec_inline(tb, QEMU_PLUGIN_INLINE_ADD_U6= 4, + &count_tb_inline_racy, 1); + qemu_plugin_register_vcpu_tb_exec_inline_per_vcpu( + tb, QEMU_PLUGIN_INLINE_ADD_U64, + count_tb_inline_per_vcpu, sizeof(uint64_t), 1); + + for (int idx =3D 0; idx < qemu_plugin_tb_n_insns(tb); ++idx) { + struct qemu_plugin_insn *insn =3D qemu_plugin_tb_get_insn(tb, idx); + qemu_plugin_register_vcpu_insn_exec_cb(insn, vcpu_insn_exec, + QEMU_PLUGIN_CB_NO_REGS, 0); + qemu_plugin_register_vcpu_insn_exec_inline( + insn, QEMU_PLUGIN_INLINE_ADD_U64, + &count_insn_inline_racy, 1); + qemu_plugin_register_vcpu_insn_exec_inline_per_vcpu( + insn, QEMU_PLUGIN_INLINE_ADD_U64, + count_insn_inline_per_vcpu, sizeof(uint64_t), 1); + qemu_plugin_register_vcpu_mem_cb(insn, &vcpu_mem_access, + QEMU_PLUGIN_CB_NO_REGS, + QEMU_PLUGIN_MEM_RW, 0); + qemu_plugin_register_vcpu_mem_inline(insn, QEMU_PLUGIN_MEM_RW, + QEMU_PLUGIN_INLINE_ADD_U64, + &count_mem_inline_racy, 1); + qemu_plugin_register_vcpu_mem_inline_per_vcpu( + insn, QEMU_PLUGIN_MEM_RW, + QEMU_PLUGIN_INLINE_ADD_U64, + count_mem_inline_per_vcpu, sizeof(uint64_t), 1); + } +} + +QEMU_PLUGIN_EXPORT +int qemu_plugin_install(qemu_plugin_id_t id, const qemu_info_t *info, + int argc, char **argv) +{ + g_assert(info->system.smp_vcpus <=3D MAX_CPUS); + qemu_plugin_register_vcpu_tb_trans_cb(id, vcpu_tb_trans); + qemu_plugin_register_atexit_cb(id, plugin_exit, NULL); + + return 0; +} diff --git a/tests/plugin/meson.build b/tests/plugin/meson.build index e18183aaeda..9eece5bab51 100644 --- a/tests/plugin/meson.build +++ b/tests/plugin/meson.build @@ -1,6 +1,6 @@ t =3D [] if get_option('plugins') - foreach i : ['bb', 'empty', 'insn', 'mem', 'syscall'] + foreach i : ['bb', 'empty', 'inline', 'insn', 'mem', 'syscall'] if host_os =3D=3D 'windows' t +=3D shared_module(i, files(i + '.c') + '../../contrib/plugins/win= 32_linker.c', include_directories: '../../include/qemu', --=20 2.43.0 From nobody Sat Sep 21 05:32:51 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1704983119; cv=none; d=zohomail.com; s=zohoarc; b=H9UZOwdeADh12L+WYH4wEwLTua2QWxoNI2a4FMrvUoUDNw0cC5ICisgxXElVEt+FIydpLbBoj64xfDPlCW077AvwaARlOIIa5Z/iC6yi5SVDvrGqrd0ANmazzHkkSkpAH9IaTauw+9cDwB4c7CKRNayg/rtKSdQS8RbA55CFWSk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1704983119; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=xFv6E5kkXfIGfEX1pT8iilVpb1LB0Hjh6FDK0KUik1o=; b=bIEQhHwq1n7uY8bK/6O5XNDhoehAOH03x/UdX/Hmwg34NYFmSW/ejaH9IG63wWPwTO2KfrBxUnQ6VZo1XXaQJ1D+eaoh2oqckKZ2h7azEkDg6IAKSQeGEc0KsjRGItt1XW/y9EXnE2xvTuPpHc4hiOW9VfEAYxtQb+e2/RBHRaY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1704983119206824.899613151665; Thu, 11 Jan 2024 06:25:19 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rNvyV-0004Mb-Dz; Thu, 11 Jan 2024 09:24:03 -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 1rNvyR-0004LR-Jx for qemu-devel@nongnu.org; Thu, 11 Jan 2024 09:24:00 -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 1rNvyN-0002QX-FI for qemu-devel@nongnu.org; Thu, 11 Jan 2024 09:23:59 -0500 Received: by mail-wr1-x436.google.com with SMTP id ffacd0b85a97d-3367a304091so4690002f8f.3 for ; Thu, 11 Jan 2024 06:23:54 -0800 (PST) Received: from linaro.. ([102.35.208.160]) by smtp.gmail.com with ESMTPSA id h7-20020adff4c7000000b0033677aae2e2sm1349000wrp.107.2024.01.11.06.23.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Jan 2024 06:23:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1704983033; x=1705587833; 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=xFv6E5kkXfIGfEX1pT8iilVpb1LB0Hjh6FDK0KUik1o=; b=GMitChlbw9fHcIenm3QtyIOZdslthxohFULnifPccdh6uFrGzVJBz2Q7Gt1HDX8Nrn v1U8bdgkpu/W5Na0DPaIPTtCWRc3wDNcZ4Zrd75HM9aDexUAAAcGv8x479a+3RgN9PPq R2kRliVelgWhp5ZcKn6+lycO2Kh7H4jSUnIaBJlgvPKYTdkRhI6DalwZ353c0XtbTrje 7z6lEk/W35bRgQPmBWP20dKNey8/xBpTEQmYZeys736segLCumkT8WUUCPVvVEjtgHz9 Of30+UhofC77QbCi2cjrtB8+xrwL5jUcinXEcZdNFHq4JlLl3ZjfqQHyv2SmD1yv5Ez7 ztJw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704983033; x=1705587833; 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=xFv6E5kkXfIGfEX1pT8iilVpb1LB0Hjh6FDK0KUik1o=; b=RrBsMJZ8kbsW7Fw/npwsDAFprTaIQheXyj+O8nTS5e4UMQVdjqQuS2t16FE/aYm0ox 4kS0xvzSUYyChsowDieIzNNWDpHeRE9hbbpyeueCbAXHl/xqeHBpisApA4KcedMlKBlP QKyN1r5hgvw8Gqbw1Y9YEpb7krWezGnV1PkRqYgqHbLygyCznCZsf6YbFNCgEBrNsDuk i5rNwVIpI121wyEl2J3xccH8OVO5lBgvjfLuwJhwWHnGznboj4OOOpI5Um63t9dF6Xwd qdSP+BC1Ign7yJ/QZQG3vrexIjELlq43dFO+HK90C7Jeih26K0+dF7P9DpEosCSX+gmJ utzQ== X-Gm-Message-State: AOJu0YwhM09oq7QH00YdeSPtMJ69XzY0Ll/Oq4dfJdXuLr7PJIKl/dpk rP/XdZy76OOPaIyGV92+0OU+rLJiFpog8j1pUTPHZe+66tg3xA== X-Google-Smtp-Source: AGHT+IFJdexCQTbgMGPOP4Amkmn/mSGTxF2FRnEe+PZ72gyeMYwSssxi2JWyLejS4xYig9kZLlZaUA== X-Received: by 2002:adf:cd07:0:b0:336:5bf4:9904 with SMTP id w7-20020adfcd07000000b003365bf49904mr430816wrm.142.1704983033223; Thu, 11 Jan 2024 06:23:53 -0800 (PST) From: Pierrick Bouvier To: qemu-devel@nongnu.org Cc: Pierrick Bouvier , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Mahmoud Mandour , Richard Henderson , Paolo Bonzini , Alexandre Iooss Subject: [PATCH 04/12] tests/plugin/inline: migrate to new per_vcpu API Date: Thu, 11 Jan 2024 18:23:17 +0400 Message-ID: <20240111142326.1743444-5-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 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; 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: -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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1704983119961100002 Content-Type: text/plain; charset="utf-8" Signed-off-by: Pierrick Bouvier --- tests/plugin/inline.c | 17 ----------------- 1 file changed, 17 deletions(-) diff --git a/tests/plugin/inline.c b/tests/plugin/inline.c index 6114ebca545..ae59f7af7a7 100644 --- a/tests/plugin/inline.c +++ b/tests/plugin/inline.c @@ -18,15 +18,12 @@ static uint64_t count_tb; static uint64_t count_tb_per_vcpu[MAX_CPUS]; static uint64_t count_tb_inline_per_vcpu[MAX_CPUS]; -static uint64_t count_tb_inline_racy; static uint64_t count_insn; static uint64_t count_insn_per_vcpu[MAX_CPUS]; static uint64_t count_insn_inline_per_vcpu[MAX_CPUS]; -static uint64_t count_insn_inline_racy; static uint64_t count_mem; static uint64_t count_mem_per_vcpu[MAX_CPUS]; static uint64_t count_mem_inline_per_vcpu[MAX_CPUS]; -static uint64_t count_mem_inline_racy; static GMutex tb_lock; static GMutex insn_lock; static GMutex mem_lock; @@ -50,11 +47,9 @@ static void stats_insn(void) printf("insn: %" PRIu64 "\n", expected); printf("insn: %" PRIu64 " (per vcpu)\n", per_vcpu); printf("insn: %" PRIu64 " (per vcpu inline)\n", inl_per_vcpu); - printf("insn: %" PRIu64 " (inline racy)\n", count_insn_inline_racy); g_assert(expected > 0); g_assert(per_vcpu =3D=3D expected); g_assert(inl_per_vcpu =3D=3D expected); - g_assert(count_insn_inline_racy <=3D expected); } =20 static void stats_tb(void) @@ -65,11 +60,9 @@ static void stats_tb(void) printf("tb: %" PRIu64 "\n", expected); printf("tb: %" PRIu64 " (per vcpu)\n", per_vcpu); printf("tb: %" PRIu64 " (per vcpu inline)\n", inl_per_vcpu); - printf("tb: %" PRIu64 " (inline racy)\n", count_tb_inline_racy); g_assert(expected > 0); g_assert(per_vcpu =3D=3D expected); g_assert(inl_per_vcpu =3D=3D expected); - g_assert(count_tb_inline_racy <=3D expected); } =20 static void stats_mem(void) @@ -80,11 +73,9 @@ static void stats_mem(void) printf("mem: %" PRIu64 "\n", expected); printf("mem: %" PRIu64 " (per vcpu)\n", per_vcpu); printf("mem: %" PRIu64 " (per vcpu inline)\n", inl_per_vcpu); - printf("mem: %" PRIu64 " (inline racy)\n", count_mem_inline_racy); g_assert(expected > 0); g_assert(per_vcpu =3D=3D expected); g_assert(inl_per_vcpu =3D=3D expected); - g_assert(count_mem_inline_racy <=3D expected); } =20 static void plugin_exit(qemu_plugin_id_t id, void *udata) @@ -142,8 +133,6 @@ static void vcpu_tb_trans(qemu_plugin_id_t id, struct q= emu_plugin_tb *tb) { qemu_plugin_register_vcpu_tb_exec_cb(tb, vcpu_tb_exec, QEMU_PLUGIN_CB_NO_REGS, 0); - qemu_plugin_register_vcpu_tb_exec_inline(tb, QEMU_PLUGIN_INLINE_ADD_U6= 4, - &count_tb_inline_racy, 1); qemu_plugin_register_vcpu_tb_exec_inline_per_vcpu( tb, QEMU_PLUGIN_INLINE_ADD_U64, count_tb_inline_per_vcpu, sizeof(uint64_t), 1); @@ -152,18 +141,12 @@ static void vcpu_tb_trans(qemu_plugin_id_t id, struct= qemu_plugin_tb *tb) struct qemu_plugin_insn *insn =3D qemu_plugin_tb_get_insn(tb, idx); qemu_plugin_register_vcpu_insn_exec_cb(insn, vcpu_insn_exec, QEMU_PLUGIN_CB_NO_REGS, 0); - qemu_plugin_register_vcpu_insn_exec_inline( - insn, QEMU_PLUGIN_INLINE_ADD_U64, - &count_insn_inline_racy, 1); qemu_plugin_register_vcpu_insn_exec_inline_per_vcpu( insn, QEMU_PLUGIN_INLINE_ADD_U64, count_insn_inline_per_vcpu, sizeof(uint64_t), 1); qemu_plugin_register_vcpu_mem_cb(insn, &vcpu_mem_access, QEMU_PLUGIN_CB_NO_REGS, QEMU_PLUGIN_MEM_RW, 0); - qemu_plugin_register_vcpu_mem_inline(insn, QEMU_PLUGIN_MEM_RW, - QEMU_PLUGIN_INLINE_ADD_U64, - &count_mem_inline_racy, 1); qemu_plugin_register_vcpu_mem_inline_per_vcpu( insn, QEMU_PLUGIN_MEM_RW, QEMU_PLUGIN_INLINE_ADD_U64, --=20 2.43.0 From nobody Sat Sep 21 05:32:51 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1704983154; cv=none; d=zohomail.com; s=zohoarc; b=YiG612Y78rrQ9wPG1Yt0juS0+FDGng76SsxSV9UMYYeDr/oZ3/04li9FLln2OMDs0G9jsnVZBJDfWQqHsvPr98k2E9pT+fvCEA7+KsROadcnILab87QgmxuGZuKvtwWDnuA9Sn272m39dx5zqTg7UrOejrrcWY/shoi3Z313iK0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1704983154; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=ln64hRwHlJJ0pQEAuAxOaAua0Oss5Jze+kXnvVQ8J9Y=; b=S8kB5fIOaYw1ZW4KVQFdL219hN8FnYi0i+dXcMIuh6+nnRAafpbLq1uPSWJyHstgz0iPAzL45NKGdOZSnaWyvjLtGoiKuY88014vcHgtbfXgBWWmIBcrdHkssm+YImhvVc70mddIjjkGkYep12GnUr9wnwvEXgEKV7PNKR7MCVY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1704983154560965.1010774431882; Thu, 11 Jan 2024 06:25:54 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rNvyX-0004NK-Ne; Thu, 11 Jan 2024 09:24: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 1rNvyT-0004Lw-GZ for qemu-devel@nongnu.org; Thu, 11 Jan 2024 09:24:01 -0500 Received: from mail-wr1-x42f.google.com ([2a00:1450:4864:20::42f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rNvyR-0002V6-Bx for qemu-devel@nongnu.org; Thu, 11 Jan 2024 09:24:00 -0500 Received: by mail-wr1-x42f.google.com with SMTP id ffacd0b85a97d-3368abe1093so4265725f8f.2 for ; Thu, 11 Jan 2024 06:23:57 -0800 (PST) Received: from linaro.. ([102.35.208.160]) by smtp.gmail.com with ESMTPSA id h7-20020adff4c7000000b0033677aae2e2sm1349000wrp.107.2024.01.11.06.23.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Jan 2024 06:23:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1704983036; x=1705587836; 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=ln64hRwHlJJ0pQEAuAxOaAua0Oss5Jze+kXnvVQ8J9Y=; b=qVCWhdnjMNRsk4KgqDKJDOleIlTIvsqnp1GHOKKcXIF7DengGwMBrBIGLMeCwfTX7w XMTuMTZg1fVn66R0WkW0j2sXALLHTbl9PIcffAuJa8VCh9u6XTBWbDse2RC2W3mPcA0B X0dQemz/ObxZkIca8udQKEJ0jhRXUmpht5xv2qKCwB+boC6NIHNj5dwJrxwIbEWSLrZn Ixh5eiO126xHcJV301zIkd2K9Ij0RJ9iThWBBM3GQ5SJZIr6NQZXexD2eiAgnOKHzUlH SF0s1qyOUSW51mf3JnGHcFsCUZ28g1eQXORzlOS2HEN/vpRlUKV8IIJdhIUaI0KE+WpV 3FfA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704983036; x=1705587836; 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=ln64hRwHlJJ0pQEAuAxOaAua0Oss5Jze+kXnvVQ8J9Y=; b=FgjFPW01w3Tqqp7x5KgDM9V1X+wkaRwmurJFfMTsKN4Hogr6oCy1CsgUvX3iZPk+Gp n7No1MdU2ACICYck5PxZOVwh7R+Xo2W2UmojX9rcX5VTuTR0tzkE6C/bFHqL9JZgEBma kXax0PLjcF3gzsG11awRRn+2M4YaXplRHeWisP6uXQCtVRse6GzwsGMf2o8wY4zOxH3c mqQStWtddbNvfSsmD78kyKS9baFkPNu9OWmua8+XrUcHF98anfQDLbG5CCNfNzT8tAWO hUfa8g+x4M/glXlO9IoQD+cPC+Q2vd1QRmBTMagE8FtTAYDcsz+MDqJNcpsX75+v4u6k 8WPg== X-Gm-Message-State: AOJu0Yw2ODJooSBOX5LsbBjyQVV6GO32ErC25XJ461QkV7M5D8YCMXZ8 jEXh19Hvy7ZMWlR+TOlJqsWikAdcHSj1XHTPJyXB2BltwU+4gg== X-Google-Smtp-Source: AGHT+IFXk2++/uRRI+OA+jtS1uUQ5ze4Rgn9uQlAGgOhgRm0Htpar0wYsO0bDy4XPnUnMOUhzLyrhA== X-Received: by 2002:adf:eb01:0:b0:336:60ea:319d with SMTP id s1-20020adfeb01000000b0033660ea319dmr574008wrn.63.1704983036016; Thu, 11 Jan 2024 06:23:56 -0800 (PST) From: Pierrick Bouvier To: qemu-devel@nongnu.org Cc: Pierrick Bouvier , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Mahmoud Mandour , Richard Henderson , Paolo Bonzini , Alexandre Iooss Subject: [PATCH 05/12] tests/plugin/mem: fix race condition with callbacks Date: Thu, 11 Jan 2024 18:23:18 +0400 Message-ID: <20240111142326.1743444-6-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 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::42f; envelope-from=pierrick.bouvier@linaro.org; helo=mail-wr1-x42f.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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1704983156089100006 Content-Type: text/plain; charset="utf-8" Introduce a lock so global count is correct. This was found by comparing with new inline per_vcpu inline op. Signed-off-by: Pierrick Bouvier Reviewed-by: Richard Henderson --- tests/plugin/mem.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/plugin/mem.c b/tests/plugin/mem.c index 44e91065ba7..beca8232342 100644 --- a/tests/plugin/mem.c +++ b/tests/plugin/mem.c @@ -22,6 +22,7 @@ static uint64_t io_count; static bool do_inline, do_callback; static bool do_haddr; static enum qemu_plugin_mem_rw rw =3D QEMU_PLUGIN_MEM_RW; +static GMutex lock; =20 static void plugin_exit(qemu_plugin_id_t id, void *p) { @@ -42,6 +43,7 @@ static void plugin_exit(qemu_plugin_id_t id, void *p) static void vcpu_mem(unsigned int cpu_index, qemu_plugin_meminfo_t meminfo, uint64_t vaddr, void *udata) { + g_mutex_lock(&lock); if (do_haddr) { struct qemu_plugin_hwaddr *hwaddr; hwaddr =3D qemu_plugin_get_hwaddr(meminfo, vaddr); @@ -53,6 +55,7 @@ static void vcpu_mem(unsigned int cpu_index, qemu_plugin_= meminfo_t meminfo, } else { cb_mem_count++; } + g_mutex_unlock(&lock); } =20 static void vcpu_tb_trans(qemu_plugin_id_t id, struct qemu_plugin_tb *tb) --=20 2.43.0 From nobody Sat Sep 21 05:32:51 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1704983111; cv=none; d=zohomail.com; s=zohoarc; b=h/aB3ZRtRL5xUubhwXJFUaZWdiuipZH0Kp5W9DihyiJmc0SWH9i1fENFlyzvor6q5NPEWgu492b4hpBa7CwR7JxgklgTuCme79Gg3eos9C3v+ulThba7LssGk8lSo08IJJgwZaBBegNipy4kG1O9//OL68f3jWdWZj8uMCb3UOg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1704983111; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=Aq5DjSOiw7b/OxzS4nPd0JW8zSf3ntDpqvE/K8se7oQ=; b=ExgDX1OjR54vLJCFmL5wosYKQzA2lIoialOKhhAj5917waxylLmDq8i6eQ/m+gz+Z7e89poqvdWVCfMIv3nFENt22Q+4ZN5E+gNrdqDSP1cSFIQYbPyzitbewoBQBR0ZR2jHdjSfn73DQOgyi+HZRUVvo4cAqHQb2mqEqV5b1zo= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1704983111625436.55110565119696; Thu, 11 Jan 2024 06:25:11 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rNvyo-0004QZ-Fq; Thu, 11 Jan 2024 09:24:22 -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 1rNvyV-0004MO-8C for qemu-devel@nongnu.org; Thu, 11 Jan 2024 09:24:03 -0500 Received: from mail-wm1-x32e.google.com ([2a00:1450:4864:20::32e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rNvyT-0002Ye-8S for qemu-devel@nongnu.org; Thu, 11 Jan 2024 09:24:02 -0500 Received: by mail-wm1-x32e.google.com with SMTP id 5b1f17b1804b1-40e60e137aaso5433935e9.0 for ; Thu, 11 Jan 2024 06:24:00 -0800 (PST) Received: from linaro.. ([102.35.208.160]) by smtp.gmail.com with ESMTPSA id h7-20020adff4c7000000b0033677aae2e2sm1349000wrp.107.2024.01.11.06.23.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Jan 2024 06:23:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1704983039; x=1705587839; 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=Aq5DjSOiw7b/OxzS4nPd0JW8zSf3ntDpqvE/K8se7oQ=; b=eSPgyD8CXHMRwKAEQhTj6eIVTxjd7eOkOTniWJcBVsBmGrEqD33/QSoxv1yOz4G8RE EBEI8p8/Ei8LKjL9OmQuJbbItZHEGcnGIHeZgO8tRtzahFd5l4DQq4PI0GQXMrr3cVpG INNtoywVk9lCEAqWtFruB8U6sODXQsJp2HMno+gdMhVHGasanzldcsX5D9jU5lXP66r8 wgLUO9xQ1FPNc38adyb7DscS6PYvV6yCXcr6p26AREL464a2y9tpNp5gI4j22BCwYWMU 05OTn/SMuRzh0fDb59ylryu/FHjkb11/ow0cyTXfW65TX2V8JXkV5i7cPyXS1Z91Ep/F gZHw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704983039; x=1705587839; 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=Aq5DjSOiw7b/OxzS4nPd0JW8zSf3ntDpqvE/K8se7oQ=; b=mLPX3fmed+XsUOFxmNRL+PI/XHQuWuCvLHbp0yM/C7ah0F8l819zJqXnCI2WXJhkXO 4g1oqUBetzAiyXEuzuLwKnRZWtM/fyPTOFD42Tj582p4s9s4EG0TFZuyZlA657rhL+DE ziunCBggZCtEJGveOIi/DWnttl9h6obBwzXW6cODuMEUGEK4yINhWgsHe2yG55YgmuB4 OexUdISku+s5HinSGi2CzCIjLRXZCTrQogvxzWviz+Z75ak9l5sNB8hTXKXNzdJ6OgKz WPqtlZE3LNUFIt6ofvS1ciW33jb1qZjUL8GxDI7IBBU9rrFla8hI9FhtCIMOo0K1vhnb Ydwg== X-Gm-Message-State: AOJu0Yzm78LjoqoyqEiDfnAUAEVUzB/pEnSdycsXFaZaEa50QnWLSHD0 8BukgB7IdniA7ZHI87dUV+mGK0u2cIsiJL0ppHMjJz+hTGr8TA== X-Google-Smtp-Source: AGHT+IGw/9BoY+T5Rx/XF42N3stGpW3rFROeoDBtVIpfUoQhBWCOEsNGA90C/tcBDp2s3NhRCrg5nA== X-Received: by 2002:a05:600c:54ed:b0:40e:5996:2291 with SMTP id jb13-20020a05600c54ed00b0040e59962291mr511531wmb.138.1704983038931; Thu, 11 Jan 2024 06:23:58 -0800 (PST) From: Pierrick Bouvier To: qemu-devel@nongnu.org Cc: Pierrick Bouvier , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Mahmoud Mandour , Richard Henderson , Paolo Bonzini , Alexandre Iooss Subject: [PATCH 06/12] tests/plugin/mem: migrate to new per_vcpu API Date: Thu, 11 Jan 2024 18:23:19 +0400 Message-ID: <20240111142326.1743444-7-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 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::32e; envelope-from=pierrick.bouvier@linaro.org; helo=mail-wm1-x32e.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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1704983111958100001 Content-Type: text/plain; charset="utf-8" Signed-off-by: Pierrick Bouvier --- tests/plugin/mem.c | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/tests/plugin/mem.c b/tests/plugin/mem.c index beca8232342..06f2d80d0ec 100644 --- a/tests/plugin/mem.c +++ b/tests/plugin/mem.c @@ -16,7 +16,9 @@ =20 QEMU_PLUGIN_EXPORT int qemu_plugin_version =3D QEMU_PLUGIN_VERSION; =20 -static uint64_t inline_mem_count; +#define MAX_CPUS 8 + +static uint64_t inline_mem_count[MAX_CPUS]; static uint64_t cb_mem_count; static uint64_t io_count; static bool do_inline, do_callback; @@ -29,7 +31,11 @@ static void plugin_exit(qemu_plugin_id_t id, void *p) g_autoptr(GString) out =3D g_string_new(""); =20 if (do_inline) { - g_string_printf(out, "inline mem accesses: %" PRIu64 "\n", inline_= mem_count); + uint64_t total =3D 0; + for (int i =3D 0; i < MAX_CPUS; ++i) { + total +=3D inline_mem_count[i]; + } + g_string_printf(out, "inline mem accesses: %" PRIu64 "\n", total); } if (do_callback) { g_string_append_printf(out, "callback mem accesses: %" PRIu64 "\n"= , cb_mem_count); @@ -67,9 +73,10 @@ static void vcpu_tb_trans(qemu_plugin_id_t id, struct qe= mu_plugin_tb *tb) struct qemu_plugin_insn *insn =3D qemu_plugin_tb_get_insn(tb, i); =20 if (do_inline) { - qemu_plugin_register_vcpu_mem_inline(insn, rw, - QEMU_PLUGIN_INLINE_ADD_U6= 4, - &inline_mem_count, 1); + qemu_plugin_register_vcpu_mem_inline_per_vcpu( + insn, rw, + QEMU_PLUGIN_INLINE_ADD_U64, + inline_mem_count, sizeof(uint64_t), 1); } if (do_callback) { qemu_plugin_register_vcpu_mem_cb(insn, vcpu_mem, @@ -109,6 +116,7 @@ QEMU_PLUGIN_EXPORT int qemu_plugin_install(qemu_plugin_= id_t id, fprintf(stderr, "boolean argument parsing failed: %s\n", o= pt); return -1; } + g_assert(info->system.smp_vcpus <=3D MAX_CPUS); } else if (g_strcmp0(tokens[0], "callback") =3D=3D 0) { if (!qemu_plugin_bool_parse(tokens[0], tokens[1], &do_callback= )) { fprintf(stderr, "boolean argument parsing failed: %s\n", o= pt); --=20 2.43.0 From nobody Sat Sep 21 05:32:51 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1704983152; cv=none; d=zohomail.com; s=zohoarc; b=KFi/JY4TDfHrkru6/GLDzywAtECauoG4/THs4plIYEaLE9u/dTfZOqjRqe/EsKazWryaujqux4KUTOVlZ9X08fj9jdo0kyB7bRwpZmACl5aLlbT4rCdoeZ1Ny54TV6RUZvjkHYV9eoVHQ0lCUVt43isbMDa2KvtCpiIIw881Fd8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1704983152; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=BTn8iqDeGr0XAAzxAxgUm6NGko/94wD5dpWMO4sCVF8=; b=WGdZNpt/7hW45YWPSliCLCkHvJga0OnqLGtIf0j6GvkSYG/xjZR3bk9ESPIryCYk5ibj9ttVrp1WEEX8FkKDJfCQ4FAvhWOUDqiBLNkuuU/yTF8sNaohqaMzIb8Z/tHyexfzQlSFaE7w3sRtPJfOt5XBm9Q6mxH8Ym1T3ucN0/8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1704983152506639.6384312223034; Thu, 11 Jan 2024 06:25:52 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rNvys-0004Sx-QK; 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 1rNvyX-0004NM-Pv for qemu-devel@nongnu.org; Thu, 11 Jan 2024 09:24:06 -0500 Received: from mail-wm1-x334.google.com ([2a00:1450:4864:20::334]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rNvyV-0002by-Kz for qemu-devel@nongnu.org; Thu, 11 Jan 2024 09:24:05 -0500 Received: by mail-wm1-x334.google.com with SMTP id 5b1f17b1804b1-40d5336986cso69028505e9.1 for ; Thu, 11 Jan 2024 06:24:03 -0800 (PST) Received: from linaro.. ([102.35.208.160]) by smtp.gmail.com with ESMTPSA id h7-20020adff4c7000000b0033677aae2e2sm1349000wrp.107.2024.01.11.06.23.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Jan 2024 06:24:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1704983042; x=1705587842; 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=BTn8iqDeGr0XAAzxAxgUm6NGko/94wD5dpWMO4sCVF8=; b=VMnAyScOHl86YYgTkYSIR5fFYzjmx2+0mRv6hEu0cq5ZABhIGfdVuMxxoBwhjAhvEG 7pjyMkUuPP60q54gXtuLKfCn+7TqjnWA1Pm26RIs+oGntkuoB5zOq7xOUxgTMpjtGDFR TRzMthr+J9d+TMfc6KRtW3+szaEPWSKLeaxaNeumIKjXHrtK5FzhCGYxAQP0EE5t9Xwe CBfGOqZXyzF4FKezt0VheCmpudMyyaa2AIOXozKtfRY/6PSr5d4kWzUXhgX4FlFUr+KI Fa2PwIorD/T+7MxLUo3fQguLuQfKZoamFzoUAXa2fl8RTPCP/REKG85U+PTAnzeKWXRU B8LQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704983042; x=1705587842; 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=BTn8iqDeGr0XAAzxAxgUm6NGko/94wD5dpWMO4sCVF8=; b=cBG/rrJmt/FyJ6Vd3OLiEwWY6+T2kXj5jEni679sZwuv2PZZjmmxfe3/MBVG2n5ZBP 5YfX3SMKLqUVjZofs9ed5B5VOWSM2p2ea+WKh/8/jbja3o8F6ADLnB1BmngQtk/uuAvW nVJUAA9UrFAaUz7qoATMloAqe2tPUZSVeqo6IYaVWSW+yXUX86Wd7ZhE26eChRAF4ZLV pQAZEripFmulpsc0+aKBXiE6qMEXlj9g8Tl39xM0ZmvG1ywS6LwNoU5kDvaft9ldMnk+ dG6qUuVYc68wAp+QvakIahULkOYHFWwymEydZURkRplXV1NwJIqKpxK7qgdHS+bn4bCw Q1hg== X-Gm-Message-State: AOJu0Yw2IGe/bAkcnrbYBbK89I+oT9UHdutOdt1bqUg2sPZzVNCn1JEY inCSgBEMPfXkE1qX8Ob2pSVPbWPzBT62iLsjLcOa1u6Bv+TZow== X-Google-Smtp-Source: AGHT+IFle3qmsRi7aJ+lk52W24+9p4cKH4le//pzFYsxyldlcVwY9IvuEKnpa0S1BGhUqDP4Mfsy8Q== X-Received: by 2002:a7b:cb96:0:b0:40e:393d:715e with SMTP id m22-20020a7bcb96000000b0040e393d715emr454996wmi.207.1704983041835; Thu, 11 Jan 2024 06:24:01 -0800 (PST) From: Pierrick Bouvier To: qemu-devel@nongnu.org Cc: Pierrick Bouvier , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Mahmoud Mandour , Richard Henderson , Paolo Bonzini , Alexandre Iooss Subject: [PATCH 07/12] tests/plugin/insn: migrate to new per_vcpu API Date: Thu, 11 Jan 2024 18:23:20 +0400 Message-ID: <20240111142326.1743444-8-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 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::334; envelope-from=pierrick.bouvier@linaro.org; helo=mail-wm1-x334.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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1704983154143100002 Content-Type: text/plain; charset="utf-8" Signed-off-by: Pierrick Bouvier Reviewed-by: Richard Henderson --- tests/plugin/insn.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/tests/plugin/insn.c b/tests/plugin/insn.c index 5fd3017c2b3..be79c5080fd 100644 --- a/tests/plugin/insn.c +++ b/tests/plugin/insn.c @@ -23,7 +23,7 @@ typedef struct { } InstructionCount; =20 static InstructionCount counts[MAX_CPUS]; -static uint64_t inline_insn_count; +static uint64_t inline_insn_count[MAX_CPUS]; =20 static bool do_inline; static bool do_size; @@ -94,8 +94,9 @@ static void vcpu_tb_trans(qemu_plugin_id_t id, struct qem= u_plugin_tb *tb) struct qemu_plugin_insn *insn =3D qemu_plugin_tb_get_insn(tb, i); =20 if (do_inline) { - qemu_plugin_register_vcpu_insn_exec_inline( - insn, QEMU_PLUGIN_INLINE_ADD_U64, &inline_insn_count, 1); + qemu_plugin_register_vcpu_insn_exec_inline_per_vcpu( + insn, QEMU_PLUGIN_INLINE_ADD_U64, + inline_insn_count, sizeof(uint64_t), 1); } else { uint64_t vaddr =3D qemu_plugin_insn_vaddr(insn); qemu_plugin_register_vcpu_insn_exec_cb( @@ -151,7 +152,11 @@ static void plugin_exit(qemu_plugin_id_t id, void *p) } } } else if (do_inline) { - g_string_append_printf(out, "insns: %" PRIu64 "\n", inline_insn_co= unt); + uint64_t total =3D 0; + for (i =3D 0; i < MAX_CPUS; ++i) { + total +=3D inline_insn_count[i]; + } + g_string_append_printf(out, "insns: %" PRIu64 "\n", total); } else { uint64_t total_insns =3D 0; for (i =3D 0; i < MAX_CPUS; i++) { @@ -195,6 +200,7 @@ QEMU_PLUGIN_EXPORT int qemu_plugin_install(qemu_plugin_= id_t id, fprintf(stderr, "boolean argument parsing failed: %s\n", o= pt); return -1; } + g_assert(info->system.smp_vcpus <=3D MAX_CPUS); } else if (g_strcmp0(tokens[0], "sizes") =3D=3D 0) { if (!qemu_plugin_bool_parse(tokens[0], tokens[1], &do_size)) { fprintf(stderr, "boolean argument parsing failed: %s\n", o= pt); --=20 2.43.0 From nobody Sat Sep 21 05:32:51 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1704983188; cv=none; d=zohomail.com; s=zohoarc; b=adkkZF6oY2x0x6VTy3CsAkADnwuvaDgguA8sT3+XuyGjPdUQWsJqdZfitI6+Q8KiRBza2LZyV3ZGXVrSiNbGVoncfB6LVPjEWfA/icn/3ZiKJb6XC4fTljhBSAj0qEVJ/n/IVVPCMQBtPQxTL7dtUaBsSHMYihQ0UGBTkZVqH+A= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1704983188; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=YWE1tVGsIn0zEV+TvKSOjYsl0DanjdWaNblTi9NxIMc=; b=dqRj2HX3TfF9nQuP5ocWfMMcojAyXR2Ih/I1pyRov1zPMOwxDX9WVArZ7BSriUUza7nu0T0tV4XAOADAK8/SHPz3wLSJ3L6cM1P6AniHxwXmJv7aHbzfDHLd00iOhaXW0WWkH3UgOXRZFeOYQDa2Gf6Q2f5X32HsMu3CMNVBUCM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1704983188852884.661362376111; Thu, 11 Jan 2024 06:26:28 -0800 (PST) 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) 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) 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-Google-Smtp-Source: AGHT+IEhVAU1KEqAlVKB3rCG+gJ/kVcvhrenPSaNuctYuC6DktDJnJg9AY05JJ8iU8A6CT7B315xrg== 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) From: Pierrick Bouvier To: qemu-devel@nongnu.org Cc: Pierrick Bouvier , =?UTF-8?q?Alex=20Benn=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 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1704983190294100002 Content-Type: text/plain; charset="utf-8" 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 @@ =20 QEMU_PLUGIN_EXPORT int qemu_plugin_version =3D QEMU_PLUGIN_VERSION; =20 +#define MAX_CPUS 8 + typedef struct { GMutex lock; int index; @@ -23,14 +25,10 @@ typedef struct { uint64_t insn_count; } CPUCount; =20 -/* 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]; =20 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 =3D g_string_new(""); =20 - if (do_inline || !max_cpus) { + if (do_inline) { + uint64_t total_bb =3D 0; + uint64_t total_insn =3D 0; + for (int i =3D 0; i < MAX_CPUS; ++i) { + total_bb +=3D counts[i].bb_count; + total_insn +=3D 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 =3D 0; i < MAX_CPUS; ++i) { + gen_one_cpu_report(&counts[i], report); + } } qemu_plugin_outs(report->str); } =20 static void vcpu_idle(qemu_plugin_id_t id, unsigned int cpu_index) { - CPUCount *count =3D g_ptr_array_index(counts, cpu_index); + CPUCount *count =3D &counts[cpu_index]; g_autoptr(GString) report =3D g_string_new(""); gen_one_cpu_report(count, report); =20 @@ -69,8 +75,7 @@ static void vcpu_idle(qemu_plugin_id_t id, unsigned int c= pu_index) =20 static void vcpu_tb_exec(unsigned int cpu_index, void *udata) { - CPUCount *count =3D max_cpus ? - g_ptr_array_index(counts, cpu_index) : &inline_count; + CPUCount *count =3D &counts[cpu_index]; =20 uintptr_t n_insns =3D (uintptr_t)udata; g_mutex_lock(&count->lock); @@ -84,11 +89,13 @@ static void vcpu_tb_trans(qemu_plugin_id_t id, struct q= emu_plugin_tb *tb) size_t n_insns =3D qemu_plugin_tb_n_insns(tb); =20 if (do_inline) { - qemu_plugin_register_vcpu_tb_exec_inline(tb, QEMU_PLUGIN_INLINE_AD= D_U64, - &inline_count.bb_count, 1= ); - qemu_plugin_register_vcpu_tb_exec_inline(tb, QEMU_PLUGIN_INLINE_AD= D_U64, - &inline_count.insn_count, - n_insns); + CPUCount *first_count =3D &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_plugi= n_id_t id, } } =20 - if (info->system_emulation && !do_inline) { - max_cpus =3D info->system.max_vcpus; - counts =3D g_ptr_array_new(); - for (i =3D 0; i < max_cpus; i++) { - CPUCount *count =3D g_new0(CPUCount, 1); - g_mutex_init(&count->lock); - count->index =3D i; - g_ptr_array_add(counts, count); - } - } else if (!do_inline) { - g_mutex_init(&inline_count.lock); + g_assert(info->system.smp_vcpus <=3D MAX_CPUS); + for (i =3D 0; i < MAX_CPUS; i++) { + CPUCount *count =3D &counts[i]; + count->index =3D i; } =20 if (idle_report) { --=20 2.43.0 From nobody Sat Sep 21 05:32:51 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1704983112; cv=none; d=zohomail.com; s=zohoarc; b=PHkR73aa4tE9C8n2V5WJFvJet9wgl0NVCxpDg2jo+cZBcxShLxVv4E/Q3ApcxoLEiIy0YNKbc5asfDBoFP+spElurIkFPPVnQhzKjbNWM5oXUCRXWTHTsL64/SNilXbrvgyOGyQ7HVXLme6tosnDkskapRHSvLGsW0VZGcpRpgc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1704983112; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=uKEHWzAFUZUFQemWuP8DkGrbgCslhiVNabDeLsILYDs=; b=csoYeMLW9bkIn4Rtm27tbUfgojCLdlJNg+G2Z5dw7oAMLMzeotr5KPkjHqLvcDw3f3HLRFfjgoJMhGTpBSCn6lZ0Z8ZPgDU29yK2JLER9iui+7xjZpNDvf6Utj7GBuWn/18F2dh13G0oNEg8PzFmXrvrZ73urXfXfG0bXvx7X/c= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 170498311206166.87799206273348; Thu, 11 Jan 2024 06:25:12 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rNvyt-0004U3-8M; Thu, 11 Jan 2024 09:24:27 -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-0004Pu-QQ for qemu-devel@nongnu.org; Thu, 11 Jan 2024 09:24:20 -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 1rNvyh-0002kr-8g for qemu-devel@nongnu.org; Thu, 11 Jan 2024 09:24:17 -0500 Received: by mail-wr1-x436.google.com with SMTP id ffacd0b85a97d-3376f71fcbbso3419644f8f.1 for ; Thu, 11 Jan 2024 06:24:09 -0800 (PST) Received: from linaro.. ([102.35.208.160]) by smtp.gmail.com with ESMTPSA id h7-20020adff4c7000000b0033677aae2e2sm1349000wrp.107.2024.01.11.06.24.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Jan 2024 06:24:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1704983047; x=1705587847; 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=uKEHWzAFUZUFQemWuP8DkGrbgCslhiVNabDeLsILYDs=; b=IY+4PP3RRnYODzQ4PCuWOUaoD/2tBQUyeKp4EfDY8W10tK9bXGmkV3FPsmfEWWoZwe mEXUyZCLTqZjXkzQKJLPj0WNwtrhTRQIquwhjVjCJaOoz9zdXWABAjjMZHgCltOsPlUj kuqsdLm7kp+62uZVoq6q//MJRguQadrBGXhV1gEsOwADcMuH1jwata35rMn0hfQfcQPq iWRyGbbbs8n0wDaGYDNW613mexlmtc0jRQQR4EfdVUSRsPBnqYg2Zwia34rHvWojDu0E RfpcilZTTrshAC4JZNxXGoVZ0pBywropKD/tuT6soDECq2RSY7ZBnmvNsgj5Q5rN8aT8 pxFA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704983047; x=1705587847; 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=uKEHWzAFUZUFQemWuP8DkGrbgCslhiVNabDeLsILYDs=; b=aBXpwVBkH2L9miWWTjFM6m/Af0rpStdtqjtELKrVqaAXLY7ZIHvI1L/tpKRXX117Z9 7bFlTGbznLkUDvyRfDP/svMBwwoDTn9cE3bj2WBCEiU8mk9PHYhNfGi4D2tIvvdlISbK kgm81fifTvfw4dAbvkEfIQPMtmPL7+Otma2en3j50PvwR/+GZSftxeyg/QF3M/eG0WIn fURWpdfmN2jcL8cYzx/Td/Fhqt0VHqeEUHDzDGKKRCylyoQYmM6h1VKScV8TNg2anPRS Sy61GN7T+R3lw5Mju8vM+g4Lrz5lmmlNsfOxw4BrtzqlCPDriGOXqSm3j4J3vmOwXznV digg== X-Gm-Message-State: AOJu0YyXIJTtm6wfprhg2qrZCnfVexMtCkHLfOqb8ITOmLx1ZhxnQz4E KCIiRq194JQj/2xl+uWH5O4RQzdsGfDUYMd5OAwRseq6hZr42g== X-Google-Smtp-Source: AGHT+IHbPTEMjQMFFOGAUXRWSV7rQCYyOTrnOQJQNB1DxsXcMgl8Q/xBdybDqw35azx938773nTiYw== X-Received: by 2002:a05:6000:1090:b0:337:68aa:c63d with SMTP id y16-20020a056000109000b0033768aac63dmr495790wrw.37.1704983047533; Thu, 11 Jan 2024 06:24:07 -0800 (PST) From: Pierrick Bouvier To: qemu-devel@nongnu.org Cc: Pierrick Bouvier , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Mahmoud Mandour , Richard Henderson , Paolo Bonzini , Alexandre Iooss Subject: [PATCH 09/12] contrib/plugins/hotblocks: migrate to new per_vcpu API Date: Thu, 11 Jan 2024 18:23:22 +0400 Message-ID: <20240111142326.1743444-10-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 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; 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: -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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1704983113954100009 Content-Type: text/plain; charset="utf-8" Signed-off-by: Pierrick Bouvier Reviewed-by: Richard Henderson --- contrib/plugins/hotblocks.c | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/contrib/plugins/hotblocks.c b/contrib/plugins/hotblocks.c index 4de1b134944..1d95ac53143 100644 --- a/contrib/plugins/hotblocks.c +++ b/contrib/plugins/hotblocks.c @@ -17,6 +17,8 @@ =20 QEMU_PLUGIN_EXPORT int qemu_plugin_version =3D QEMU_PLUGIN_VERSION; =20 +#define MAX_CPUS 8 + static bool do_inline; =20 /* Plugins need to take care of their own locking */ @@ -34,16 +36,25 @@ static guint64 limit =3D 20; */ typedef struct { uint64_t start_addr; - uint64_t exec_count; + uint64_t exec_count[MAX_CPUS]; int trans_count; unsigned long insns; } ExecCount; =20 +static uint64_t exec_count(ExecCount *e) +{ + uint64_t res =3D 0; + for (int i =3D 0; i < MAX_CPUS; ++i) { + res +=3D e->exec_count[i]; + } + return res; +} + static gint cmp_exec_count(gconstpointer a, gconstpointer b) { ExecCount *ea =3D (ExecCount *) a; ExecCount *eb =3D (ExecCount *) b; - return ea->exec_count > eb->exec_count ? -1 : 1; + return exec_count(ea) > exec_count(eb) ? -1 : 1; } =20 static void plugin_exit(qemu_plugin_id_t id, void *p) @@ -65,7 +76,7 @@ static void plugin_exit(qemu_plugin_id_t id, void *p) ExecCount *rec =3D (ExecCount *) it->data; g_string_append_printf(report, "0x%016"PRIx64", %d, %ld, %"PRI= d64"\n", rec->start_addr, rec->trans_count, - rec->insns, rec->exec_count); + rec->insns, exec_count(rec)); } =20 g_list_free(it); @@ -89,7 +100,7 @@ static void vcpu_tb_exec(unsigned int cpu_index, void *u= data) cnt =3D (ExecCount *) g_hash_table_lookup(hotblocks, (gconstpointer) h= ash); /* should always succeed */ g_assert(cnt); - cnt->exec_count++; + cnt->exec_count[cpu_index]++; g_mutex_unlock(&lock); } =20 @@ -120,8 +131,9 @@ static void vcpu_tb_trans(qemu_plugin_id_t id, struct q= emu_plugin_tb *tb) g_mutex_unlock(&lock); =20 if (do_inline) { - qemu_plugin_register_vcpu_tb_exec_inline(tb, QEMU_PLUGIN_INLINE_AD= D_U64, - &cnt->exec_count, 1); + qemu_plugin_register_vcpu_tb_exec_inline_per_vcpu( + tb, QEMU_PLUGIN_INLINE_ADD_U64, + cnt->exec_count, sizeof(uint64_t), 1); } else { qemu_plugin_register_vcpu_tb_exec_cb(tb, vcpu_tb_exec, QEMU_PLUGIN_CB_NO_REGS, @@ -149,6 +161,7 @@ int qemu_plugin_install(qemu_plugin_id_t id, const qemu= _info_t *info, =20 plugin_init(); =20 + g_assert(info->system.smp_vcpus <=3D MAX_CPUS); qemu_plugin_register_vcpu_tb_trans_cb(id, vcpu_tb_trans); qemu_plugin_register_atexit_cb(id, plugin_exit, NULL); return 0; --=20 2.43.0 From nobody Sat Sep 21 05:32:51 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1704983168; cv=none; d=zohomail.com; s=zohoarc; b=XTMYT208E/C4L5Hixpjr/cHSSsr+PbFkLwm8lgqgjaRjZWiXTidLoMhlxzDZ2m4kZtPUzPaxnX/MZ7Yso6cBdGFq+ItQClKSaO33d0YT2SgIBv6oUcD4FBb2dZTBYZAJlfRKYRjUCU5/fUJgsxphsbSfVbTQ/zvRqwIC1+ejYm0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1704983168; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=8ZO5SKzeIPzFy5xT17BpWpFDUdZJfOe9VoGxrmodP4k=; b=PzMdJ2yFQyqPX8FIfPzVPqXX6TG1siGlyCWrA+jgR3NYc+zh5BTYJOiHb2plzYT7Q3UIPDNr6Gc6iby0RuFOFRaZrABprkR3ecS51GJ6NFYCmo5/r1al7l85EcnaAz10/+clrGwLk1OrII4mk5CyabW0JCfVgsJzRvQM92xL0MI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1704983168597940.5319956446009; Thu, 11 Jan 2024 06:26:08 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rNvyt-0004UK-VB; Thu, 11 Jan 2024 09:24:27 -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-0004Q2-Ib for qemu-devel@nongnu.org; Thu, 11 Jan 2024 09:24:20 -0500 Received: from mail-wr1-x430.google.com ([2a00:1450:4864:20::430]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rNvyh-0002lF-8F for qemu-devel@nongnu.org; Thu, 11 Jan 2024 09:24:17 -0500 Received: by mail-wr1-x430.google.com with SMTP id ffacd0b85a97d-336897b6bd6so5067136f8f.2 for ; Thu, 11 Jan 2024 06:24:12 -0800 (PST) Received: from linaro.. ([102.35.208.160]) by smtp.gmail.com with ESMTPSA id h7-20020adff4c7000000b0033677aae2e2sm1349000wrp.107.2024.01.11.06.24.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Jan 2024 06:24:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1704983050; x=1705587850; 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=8ZO5SKzeIPzFy5xT17BpWpFDUdZJfOe9VoGxrmodP4k=; b=gH8qm+1uRwTu1hinB1nS2dyaevmEh3hXNsHgVzyh0R/NAt8n3ssN6VxX0I3ysmbGQD Z9P+OQwh6Zvq8nOq5rIWJQEepIcE6mTsSx/Y6g70QjXzaK4N2hzuYMla5znxYF/qrLKM EiGIatKzNX1uPJTURw869fAyt3Z1vF17vBlhpSYvpSYqhMfwYnP+40qtSiay6OpJl4+i UOSONm1ufnDY8kMSI3MreazzODI9CdyH2xQauAJvbgTTXMUq9v9H2o2bznDOze9He1DG DHrbT7D8ltMO/ppM0OckxktPM8hG1nstCzp0i7O+Bgma8YXPsolWgNJf1ZzoJN0NxC5M NOEA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704983050; x=1705587850; 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=8ZO5SKzeIPzFy5xT17BpWpFDUdZJfOe9VoGxrmodP4k=; b=tF5muU/Pg7SXS4YUPBshu7vAzT7jTqwA86Wm23ameZp68T+8ekvu0oODqV1jHPM71R lOnpRAlBlfp7sae9gIiI9ViV9NCYOQxrXZrz+P5HRRFiyTbSn2iXEFXw2zhuTMrVGnXV ssBjXaZe8St+6pjEhSGv4UWdRUAdARxckreBu8yapPloehZ4SjBaZ3sJfYzbJnWqoBvF OdJYhNxnxDQgPk1BEIzpWpmAT8ZhG6JbqzJqBc/Fh3kfaIblJXL0BFOUVd0ejm39ZF6x uPa1gpDAnwliqjeAHDCRjQLv8UW7o/MUBfWuMC55tdz/tXEbt7nefhypgxS6yE9bixbR yTLA== X-Gm-Message-State: AOJu0YzFBN9RhJ06/QrY8C5euB4QfkAIz/7ymDZTUf29bDRUSjz9FuwS ZII8/NFX6dH3P0bRo5gMPsZxkqgIn2hZcfuvf6+AF8yjUF+TIQ== X-Google-Smtp-Source: AGHT+IHAwaDo1QprEHcY4Gs7xzhHvdVLPO99Qss3H52sVwUJy51FoudvHw0i15WLH6jlYeklsM7YwA== X-Received: by 2002:a5d:490a:0:b0:337:3f72:3de2 with SMTP id x10-20020a5d490a000000b003373f723de2mr641930wrq.36.1704983050508; Thu, 11 Jan 2024 06:24:10 -0800 (PST) From: Pierrick Bouvier To: qemu-devel@nongnu.org Cc: Pierrick Bouvier , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Mahmoud Mandour , Richard Henderson , Paolo Bonzini , Alexandre Iooss Subject: [PATCH 10/12] contrib/plugins/howvec: migrate to new per_vcpu API Date: Thu, 11 Jan 2024 18:23:23 +0400 Message-ID: <20240111142326.1743444-11-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 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::430; envelope-from=pierrick.bouvier@linaro.org; helo=mail-wr1-x430.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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1704983170172100001 Content-Type: text/plain; charset="utf-8" Signed-off-by: Pierrick Bouvier Reviewed-by: Richard Henderson --- contrib/plugins/howvec.c | 33 ++++++++++++++++++++++----------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/contrib/plugins/howvec.c b/contrib/plugins/howvec.c index 644a7856bb2..46230a43927 100644 --- a/contrib/plugins/howvec.c +++ b/contrib/plugins/howvec.c @@ -22,8 +22,18 @@ =20 QEMU_PLUGIN_EXPORT int qemu_plugin_version =3D QEMU_PLUGIN_VERSION; =20 +#define MAX_CPUS 8 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0])) =20 +static uint64_t count(uint64_t *arr) +{ + uint64_t res =3D 0; + for (int i =3D 0; i < MAX_CPUS; ++i) { + res +=3D arr[i]; + } + return res; +} + typedef enum { COUNT_CLASS, COUNT_INDIVIDUAL, @@ -43,13 +53,13 @@ typedef struct { uint32_t mask; uint32_t pattern; CountType what; - uint64_t count; + uint64_t count[MAX_CPUS]; } InsnClassExecCount; =20 typedef struct { char *insn; uint32_t opcode; - uint64_t count; + uint64_t count[MAX_CPUS]; InsnClassExecCount *class; } InsnExecCount; =20 @@ -159,7 +169,7 @@ static gint cmp_exec_count(gconstpointer a, gconstpoint= er b) { InsnExecCount *ea =3D (InsnExecCount *) a; InsnExecCount *eb =3D (InsnExecCount *) b; - return ea->count > eb->count ? -1 : 1; + return count(ea->count) > count(eb->count) ? -1 : 1; } =20 static void free_record(gpointer data) @@ -180,11 +190,11 @@ static void plugin_exit(qemu_plugin_id_t id, void *p) class =3D &class_table[i]; switch (class->what) { case COUNT_CLASS: - if (class->count || verbose) { + if (count(class->count) || verbose) { g_string_append_printf(report, "Class: %-24s\t(%" PRId64 " hits)\n= ", class->class, - class->count); + count(class->count)); } break; case COUNT_INDIVIDUAL: @@ -212,7 +222,7 @@ static void plugin_exit(qemu_plugin_id_t id, void *p) "Instr: %-24s\t(%" PRId64 " hits)" "\t(op=3D0x%08x/%s)\n", rec->insn, - rec->count, + count(rec->count), rec->opcode, rec->class ? rec->class->class : "un-categorised"); @@ -233,7 +243,7 @@ static void plugin_init(void) static void vcpu_insn_exec_before(unsigned int cpu_index, void *udata) { uint64_t *count =3D (uint64_t *) udata; - (*count)++; + count[cpu_index]++; } =20 static uint64_t *find_counter(struct qemu_plugin_insn *insn) @@ -265,7 +275,7 @@ static uint64_t *find_counter(struct qemu_plugin_insn *= insn) case COUNT_NONE: return NULL; case COUNT_CLASS: - return &class->count; + return class->count; case COUNT_INDIVIDUAL: { InsnExecCount *icount; @@ -285,7 +295,7 @@ static uint64_t *find_counter(struct qemu_plugin_insn *= insn) } g_mutex_unlock(&lock); =20 - return &icount->count; + return icount->count; } default: g_assert_not_reached(); @@ -306,8 +316,9 @@ static void vcpu_tb_trans(qemu_plugin_id_t id, struct q= emu_plugin_tb *tb) =20 if (cnt) { if (do_inline) { - qemu_plugin_register_vcpu_insn_exec_inline( - insn, QEMU_PLUGIN_INLINE_ADD_U64, cnt, 1); + qemu_plugin_register_vcpu_insn_exec_inline_per_vcpu( + insn, QEMU_PLUGIN_INLINE_ADD_U64, + cnt, sizeof(uint64_t), 1); } else { qemu_plugin_register_vcpu_insn_exec_cb( insn, vcpu_insn_exec_before, QEMU_PLUGIN_CB_NO_REGS, c= nt); --=20 2.43.0 From nobody Sat Sep 21 05:32:51 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1704983158; cv=none; d=zohomail.com; s=zohoarc; b=eLeOIuhKKRynP3WLc3NwpGsw455cSPEjWRESt+quT8Ojqv34Mxf9nLx7McMraLIB4te0nFTROeGMby64NevTiuwz68FMuB0SAgb97NgP5FKbyxMOl25FYxqHmJ0ZGQMkSeGH39lXEd3pVARz4ENHusa/37CwBM+hc5exrQlZASY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1704983158; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=Zp8qrWUcSTBg18ScDzokCUU9rq/1sFICSbhnSWqMC94=; b=KBhlPPxluCx0TB+i0kxua7GyWs9l449cszCAjYRQClE0VHVhKWW/IIz0ncv/BBEeo388GFK95OMjKre+KsbcEA2ZYVal1CDrRpxVTlC3lzzMYDYFxQ//xDKdBJH7fMrst2ncuwBomSv331tau8Ms07hY14aZsKSUYak1ZJjtUr8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1704983158491451.1509532859628; Thu, 11 Jan 2024 06:25:58 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rNvyu-0004UN-5y; Thu, 11 Jan 2024 09:24:28 -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 1rNvyn-0004RT-39 for qemu-devel@nongnu.org; Thu, 11 Jan 2024 09:24:22 -0500 Received: from mail-wr1-x434.google.com ([2a00:1450:4864:20::434]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rNvyj-0002mb-9N for qemu-devel@nongnu.org; Thu, 11 Jan 2024 09:24:20 -0500 Received: by mail-wr1-x434.google.com with SMTP id ffacd0b85a97d-33748c4f33dso5226330f8f.1 for ; Thu, 11 Jan 2024 06:24:15 -0800 (PST) Received: from linaro.. ([102.35.208.160]) by smtp.gmail.com with ESMTPSA id h7-20020adff4c7000000b0033677aae2e2sm1349000wrp.107.2024.01.11.06.24.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Jan 2024 06:24:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1704983053; x=1705587853; 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=Zp8qrWUcSTBg18ScDzokCUU9rq/1sFICSbhnSWqMC94=; b=jOBzJuTAYdM4hrQg3vHJbgL0SBKDfNmaFiyqQ1indKmHghHifplZ/IK1WIq4N/Yj5P 3j9x5FUbKaREicdC59mZ16Tx3H+B1u8+c9jmWRiaGVmLghHTW0DX/4nrMulF7mJbbrnX taFa5q3hN2/6lB3iNi4XoaIqaojRpRYCI8MPqaIlDcPNA3Q3+w47BHfovuZx7dHn4Hfl 8sE/n086eGaSlJFJvLaovrDgGJBCreZ4TtWwWRPeHqxEeef6LGW42vao9UFu8ryw0SSB vWa/z86wshucagdHhNrCUXqp24Uc4fQJI06BtMzhQnP+grUHH436Qh6xML9B3FHYUdyl xKrA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704983053; x=1705587853; 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=Zp8qrWUcSTBg18ScDzokCUU9rq/1sFICSbhnSWqMC94=; b=Y94/+/Ed4YNEHsmemVNiL2TBSPU+RkWLr5lk5hsH4Lyve5Izd/9xuGHc3U6xrRxBGJ 0/N0HuxtoKe0RYYYRJu61SAKoy10ucVzq4PGGbsC3u9t5oqIo821IVD82GfvD6aigY/J A3m0jTA5uowovMRJmWXnFK9t7rMxFugvKZYUO96vhCFMolugSTEdbxArJYD+KpikK+wu YAoan/YxzFBjDa1mUMFYDReI2PWYsxFNXvExEUJx/AhnEDBan3LZg5skaxDvhjLSbuER fFoVQKrzYcmNju8C5DjCuoZ/FYdG00dl4sJM/Dy2pVs4SaMat+3gXvRKW2QZySmLZswW l+gA== X-Gm-Message-State: AOJu0YxPMgU5Jqs6m6Eg4E0Ddh7ZnQxGJv48FvMWmBPFat/h7dOXDgrD AdjB6+3MRyvoaQatXuYlGoOrjSHvUK+yYlcFla5oJey3bYvdeQ== X-Google-Smtp-Source: AGHT+IEp8rBMaXKYeM9XjQ1ZNn2LNh9Pau6jIAhZdW5iD7ovwjWAMoO3m3b4Aa1oZ+Cq8ZAtcSzdcA== X-Received: by 2002:adf:ed0a:0:b0:337:3e7d:11bc with SMTP id a10-20020adfed0a000000b003373e7d11bcmr589416wro.107.1704983053331; Thu, 11 Jan 2024 06:24:13 -0800 (PST) From: Pierrick Bouvier To: qemu-devel@nongnu.org Cc: Pierrick Bouvier , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Mahmoud Mandour , Richard Henderson , Paolo Bonzini , Alexandre Iooss Subject: [PATCH 11/12] plugins: remove non per_vcpu inline operation from API Date: Thu, 11 Jan 2024 18:23:24 +0400 Message-ID: <20240111142326.1743444-12-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 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::434; envelope-from=pierrick.bouvier@linaro.org; helo=mail-wr1-x434.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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1704983160158100001 Content-Type: text/plain; charset="utf-8" Now we have a thread-safe equivalent of inline operation, and that all plugins were changed to use it, there is no point to keep the old API. In more, it will help when we implement more functionality (conditional callbacks), as we know can assume that all inline operation have an offset associated. In case a user still want the old behaviour (target a single memory location), it's still possible to define an inline operation with a 0 offset. Bump API version as it's a breaking change for existing plugins. Signed-off-by: Pierrick Bouvier --- include/qemu/qemu-plugin.h | 59 ++++---------------------------------- plugins/api.c | 22 -------------- 2 files changed, 6 insertions(+), 75 deletions(-) diff --git a/include/qemu/qemu-plugin.h b/include/qemu/qemu-plugin.h index 8a0691a760e..65e770f5c56 100644 --- a/include/qemu/qemu-plugin.h +++ b/include/qemu/qemu-plugin.h @@ -50,11 +50,16 @@ typedef uint64_t qemu_plugin_id_t; * * The plugins export the API they were built against by exposing the * symbol qemu_plugin_version which can be checked. + * + * Version 2: + * Remove qemu_plugin_register_vcpu_{tb, insn, mem}_exec_inline. + * Those functions are replaced by *_per_vcpu variants, which guarantees + * thread-safety for operations. */ =20 extern QEMU_PLUGIN_EXPORT int qemu_plugin_version; =20 -#define QEMU_PLUGIN_VERSION 1 +#define QEMU_PLUGIN_VERSION 2 =20 /** * struct qemu_info_t - system information for plugins @@ -293,25 +298,6 @@ enum qemu_plugin_op { QEMU_PLUGIN_INLINE_ADD_U64, }; =20 -/** - * qemu_plugin_register_vcpu_tb_exec_inline() - execution inline op - * @tb: the opaque qemu_plugin_tb handle for the translation - * @op: the type of qemu_plugin_op (e.g. ADD_U64) - * @ptr: the target memory location for the op - * @imm: the op data (e.g. 1) - * - * Insert an inline op to every time a translated unit executes. - * Useful if you just want to increment a single counter somewhere in - * memory. - * - * Note: ops are not atomic so in multi-threaded/multi-smp situations - * you will get inexact results. - */ -QEMU_PLUGIN_API -void qemu_plugin_register_vcpu_tb_exec_inline(struct qemu_plugin_tb *tb, - enum qemu_plugin_op op, - void *ptr, uint64_t imm); - /** * qemu_plugin_register_vcpu_tb_exec_inline_per_vcpu() - execution inline = op * @tb: the opaque qemu_plugin_tb handle for the translation @@ -346,21 +332,6 @@ void qemu_plugin_register_vcpu_insn_exec_cb(struct qem= u_plugin_insn *insn, enum qemu_plugin_cb_flags flag= s, void *userdata); =20 -/** - * qemu_plugin_register_vcpu_insn_exec_inline() - insn execution inline op - * @insn: the opaque qemu_plugin_insn handle for an instruction - * @op: the type of qemu_plugin_op (e.g. ADD_U64) - * @ptr: the target memory location for the op - * @imm: the op data (e.g. 1) - * - * Insert an inline op to every time an instruction executes. Useful - * if you just want to increment a single counter somewhere in memory. - */ -QEMU_PLUGIN_API -void qemu_plugin_register_vcpu_insn_exec_inline(struct qemu_plugin_insn *i= nsn, - enum qemu_plugin_op op, - void *ptr, uint64_t imm); - /** * qemu_plugin_register_vcpu_insn_exec_inline_per_vcpu() - insn exec inlin= e op * @insn: the opaque qemu_plugin_insn handle for an instruction @@ -585,24 +556,6 @@ void qemu_plugin_register_vcpu_mem_cb(struct qemu_plug= in_insn *insn, enum qemu_plugin_mem_rw rw, void *userdata); =20 -/** - * qemu_plugin_register_vcpu_mem_inline() - register an inline op to any m= emory access - * @insn: handle for instruction to instrument - * @rw: apply to reads, writes or both - * @op: the op, of type qemu_plugin_op - * @ptr: pointer memory for the op - * @imm: immediate data for @op - * - * This registers a inline op every memory access generated by the - * instruction. This provides for a lightweight but not thread-safe - * way of counting the number of operations done. - */ -QEMU_PLUGIN_API -void qemu_plugin_register_vcpu_mem_inline(struct qemu_plugin_insn *insn, - enum qemu_plugin_mem_rw rw, - enum qemu_plugin_op op, void *pt= r, - uint64_t imm); - /** * qemu_plugin_register_vcpu_mem_inline_per_vcpu() - inline op for mem acc= ess * @insn: handle for instruction to instrument diff --git a/plugins/api.c b/plugins/api.c index fd6ce678501..a51585b3e53 100644 --- a/plugins/api.c +++ b/plugins/api.c @@ -94,13 +94,6 @@ void qemu_plugin_register_vcpu_tb_exec_cb(struct qemu_pl= ugin_tb *tb, } } =20 -void qemu_plugin_register_vcpu_tb_exec_inline(struct qemu_plugin_tb *tb, - enum qemu_plugin_op op, - void *ptr, uint64_t imm) -{ - qemu_plugin_register_vcpu_tb_exec_inline_per_vcpu(tb, op, ptr, 0, imm); -} - void qemu_plugin_register_vcpu_tb_exec_inline_per_vcpu( struct qemu_plugin_tb *tb, enum qemu_plugin_op op, @@ -124,13 +117,6 @@ void qemu_plugin_register_vcpu_insn_exec_cb(struct qem= u_plugin_insn *insn, } } =20 -void qemu_plugin_register_vcpu_insn_exec_inline(struct qemu_plugin_insn *i= nsn, - enum qemu_plugin_op op, - void *ptr, uint64_t imm) -{ - qemu_plugin_register_vcpu_insn_exec_inline_per_vcpu(insn, op, ptr, 0, = imm); -} - void qemu_plugin_register_vcpu_insn_exec_inline_per_vcpu( struct qemu_plugin_insn *insn, enum qemu_plugin_op op, @@ -158,14 +144,6 @@ void qemu_plugin_register_vcpu_mem_cb(struct qemu_plug= in_insn *insn, cb, flags, rw, udata); } =20 -void qemu_plugin_register_vcpu_mem_inline(struct qemu_plugin_insn *insn, - enum qemu_plugin_mem_rw rw, - enum qemu_plugin_op op, void *pt= r, - uint64_t imm) -{ - qemu_plugin_register_vcpu_mem_inline_per_vcpu(insn, rw, op, ptr, 0, im= m); -} - void qemu_plugin_register_vcpu_mem_inline_per_vcpu( struct qemu_plugin_insn *insn, enum qemu_plugin_mem_rw rw, --=20 2.43.0 From nobody Sat Sep 21 05:32:51 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1704983092; cv=none; d=zohomail.com; s=zohoarc; b=L8u6if2UCWeG+GOX1d+MlhecTO06iFNDaKaQdCyINGVw5GYiOshrhQh6QBfMv/P2fVTLRQ2p2nTgOa9pWgK2JDL9zyQaL6WCMcg+aPT614rmiFWD1/nEsgeXPn/nKldcs8v+p+yrvqI4uWZDwCGOyEZGiq/Ev68fX0ViIwQSeug= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1704983092; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=qeKSzzbqMDtEWciJm9Qsrh/SczbLK7mHOS9/ulXfvRw=; b=EeJs/9fdF99NdY59Lj+0lE6XFrSxink6eYLDRwD8V1khYYsfyJi7Gn4FhRruJztJ9L5GMDlsUJBsp/bSAT0/Ebwf3Q+uoD//Ckzes9fzD/eELdkbJMkKEltaPbdts4uDE7IgFq1ZyCXBIpX7yiHzRxxOuPK8M2XY0bchzQkJWp4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 170498309247021.473069697754227; Thu, 11 Jan 2024 06:24:52 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rNvyt-0004UH-JW; Thu, 11 Jan 2024 09:24:27 -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 1rNvym-0004RS-OA for qemu-devel@nongnu.org; Thu, 11 Jan 2024 09:24:22 -0500 Received: from mail-wr1-x42a.google.com ([2a00:1450:4864:20::42a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rNvyl-0002pL-8K for qemu-devel@nongnu.org; Thu, 11 Jan 2024 09:24:20 -0500 Received: by mail-wr1-x42a.google.com with SMTP id ffacd0b85a97d-336c5b5c163so3236972f8f.1 for ; Thu, 11 Jan 2024 06:24:17 -0800 (PST) Received: from linaro.. ([102.35.208.160]) by smtp.gmail.com with ESMTPSA id h7-20020adff4c7000000b0033677aae2e2sm1349000wrp.107.2024.01.11.06.24.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Jan 2024 06:24:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1704983056; x=1705587856; 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=qeKSzzbqMDtEWciJm9Qsrh/SczbLK7mHOS9/ulXfvRw=; b=eJLFIQ2ViPEHbpHvlkuAMDTxQdXX7VP61rA0oWJ/VzWHFYiPsovf6sfXc+ZwwzNJGb WdGKb417KFreoqXnhoN3iiLbvL//qZ2+AAoXAdtm3eMzlY2nYHDtkjhHLCNJrEvJ78pv 5k7tnNIvHi5Dt5Z/yVOJTWNo/sqe35C04RBsXm0NWG+s1dLaHuWk0cnRBjQC0OKPyJWh MKY261WV8V5p4WU22Ad90VeEyF3gFd5GcxIFwpJ0DiIFefbExzt3NvyzVg32X7loMJ6N q9X4D7S24nyCdt1H0GC6roP0x39da7CQYvOqLN0WyECWg4aWUkCuX5yCQwM75gsLwimc QRAA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704983056; x=1705587856; 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=qeKSzzbqMDtEWciJm9Qsrh/SczbLK7mHOS9/ulXfvRw=; b=HY+idrSZukelor1P62I5/3FAcg8TGVa7bWIZW3OHW7DrrrM4sTxSJzvrKFld8TIspN 8NGQZAEDJ8B2lP3f6vXGMPUhif6WQeJrJkwECL4WfdFzt6fD3FrpAuyQWSSyVIjW9y3s kg2gUYVQLXBdrxEG/tK5dYsaklsjPZLbj3SLgGGKRWj3iFFvViMsnGSKk5jZMyxKP6nx VpXECa0nTpshsD5g28eEGE1OkHu/mJMai/scD7VpsjQmAnjMM8yP5//ip/DrvcikL3ta 5/SW1BciCNDQQzx1+Fv15BDktfZH3H6cu9uFOvEBai/4V44sm61rKEeIH8vCMGG68RJY 7aaw== X-Gm-Message-State: AOJu0Yw82Gli5Mzym8sC56SEZUELGiqNbc70VIFnYiPvuSjatcD7yl86 vCGLaqLPvH0DvaDIBTYwTQII8ZT6Z8wU4MCRJmxBKPI9cCa9nA== X-Google-Smtp-Source: AGHT+IEeARrtTfqGgUuu9Pw3GZgudv3SHcls2BgzM2g/rUr8eoBbOvnKPnYx1T/EHoKks961zb4SSg== X-Received: by 2002:a5d:4585:0:b0:337:49ea:3845 with SMTP id p5-20020a5d4585000000b0033749ea3845mr505884wrq.40.1704983056189; Thu, 11 Jan 2024 06:24:16 -0800 (PST) From: Pierrick Bouvier To: qemu-devel@nongnu.org Cc: Pierrick Bouvier , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Mahmoud Mandour , Richard Henderson , Paolo Bonzini , Alexandre Iooss Subject: [PATCH 12/12] MAINTAINERS: Add myself as reviewer for TCG Plugins Date: Thu, 11 Jan 2024 18:23:25 +0400 Message-ID: <20240111142326.1743444-13-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 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::42a; envelope-from=pierrick.bouvier@linaro.org; helo=mail-wr1-x42a.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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1704983094235100005 Signed-off-by: Pierrick Bouvier Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- MAINTAINERS | 1 + 1 file changed, 1 insertion(+) diff --git a/MAINTAINERS b/MAINTAINERS index 00ec1f7ecaf..4a621aca978 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -3660,6 +3660,7 @@ TCG Plugins M: Alex Benn=C3=A9e R: Alexandre Iooss R: Mahmoud Mandour +R: Pierrick Bouvier S: Maintained F: docs/devel/tcg-plugins.rst F: plugins/ --=20 2.43.0