From patchwork Tue Sep 10 17:20:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pierrick Bouvier X-Patchwork-Id: 827031 Delivered-To: patch@linaro.org Received: by 2002:adf:ab1c:0:b0:367:895a:4699 with SMTP id q28csp423723wrc; Tue, 10 Sep 2024 10:22:30 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCVu/TXkmSPRu7qAdkRBAziVj/FrPzJQRNVX38Grp5Nj2qh+F+Rdz31Ktaq7lPTx3M5KUExZyA==@linaro.org X-Google-Smtp-Source: AGHT+IFW1J4FZZ4hXVtXBMghg5EQ5RpMBXGBftel7LtmXeqfJ4AqsoA3QZ3smvUCo7ia4tI/dnze X-Received: by 2002:a05:622a:1828:b0:458:4457:8e69 with SMTP id d75a77b69052e-45844579181mr31605691cf.20.1725988950337; Tue, 10 Sep 2024 10:22:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1725988950; cv=none; d=google.com; s=arc-20240605; b=TI9gmgAVZKvzSyCAO+O2/qkjpETB7Uujy27vb8xHK44sqTFrrVO6bVfHtLy7bNilBD K1PKByvRjFSMWFxCJns/W4XyGCYJ751oO3uAM7QVLuGEO4Olip03wAHpM+zrih5q7RUN RabtPk9YImJpRvtF5dgb9Xst1Lmae6vQafNkiio0css5aR2WwQ0C5HwrWO/s/Dd06vBZ Ex+FoGlV9+z8c98FjBL46oeP9yx9HZtU9MzFkjXIrTajNzcQ9SeX5xVILFxIMo11iRdK bJ3Op9j7arW4ousJAfowTbGpKZfPIkJd5RnZ+2JIYDLUypsy0vNTuUchGrdOCv2x1Ylv 1UkQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=7ZhXggMzxS5/Hj/Hre+veFUkbwOhjo3lATccHPiXGdo=; fh=OhV3JIe6s7BYVATlKJ3Ib2ybA9N3ZJt49O4IlF1MoN4=; b=McRAn1XwavFRY+N0Nz/CFmR+GnDEe6Jy+H3ffJQubgICMOhWpL8m3kiASd4QYxKXTG VV3fRVv4ZuWWuxP1fsTmXMrStHREaGozfnuVTcgcT2utkoRQ2hE3ljPmydxbYj7ofndv A9YfuQRPPKHaaZIkkd405horjRVOOlTjHCZyQ6EADvFXgVUAwTXZs2ACpC39+uN1i9h0 K83E5LzRyYF9SI7PA7JWnmw1MlUMLNlc7jTJtlRQp8S0Ce90LOI9wATj7pEfHOww2ufL dgH8372jbSA7+dRfCX+16qiAgNDnRCKQA7/bCNXYKQ+eVWZPayN9Hy04gc58yP1PZLsv mYQg==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=mMlMdXp+; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org; dara=neutral header.i=@linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id d75a77b69052e-45822faffb0si80633511cf.592.2024.09.10.10.22.30 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 10 Sep 2024 10:22:30 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=mMlMdXp+; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org; dara=neutral header.i=@linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1so4Y1-0003iH-JO; Tue, 10 Sep 2024 13:21:01 -0400 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 1so4Xw-0003PK-Rp for qemu-devel@nongnu.org; Tue, 10 Sep 2024 13:20:56 -0400 Received: from mail-pj1-x102b.google.com ([2607:f8b0:4864:20::102b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1so4Xt-0002ny-8U for qemu-devel@nongnu.org; Tue, 10 Sep 2024 13:20:56 -0400 Received: by mail-pj1-x102b.google.com with SMTP id 98e67ed59e1d1-2d8f06c2459so3777484a91.0 for ; Tue, 10 Sep 2024 10:20:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1725988852; x=1726593652; 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=7ZhXggMzxS5/Hj/Hre+veFUkbwOhjo3lATccHPiXGdo=; b=mMlMdXp+JDkMNPYFRSItEdB7pQdTvYVQoswW0llIFVNMV1B9Q4rnwvZ6dpGcJGJws6 fmUTLDVsoE4jo3amGF6tgl0gkmTM/+OC5BwRXtWDUOhFS7r+meiYpKpjFtgVWMlRSwe1 DZaLiUlVlUB0kFWITJlWduqctlpUjElEq3m4BSQdwmhl5FYqePPp/maaa90y9A+WmBCu RVsOg98Se3/4nJjTYc0x8Pzf0l1RjMojDmZTakB4mFlH0lU0P9kpuCKbl/JY3PIoUrD7 pVshQhK0F6ExrhYugF0KSeaV3tf/UXD/YhB4VluxUH0UKpUaRlknfF3THTHT/jVAuVhS s4Vg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725988852; x=1726593652; 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=7ZhXggMzxS5/Hj/Hre+veFUkbwOhjo3lATccHPiXGdo=; b=XhivUtuJ+Af5UU8jAtsx4XqN+VYYyYxn3K10e3uyHkciqu6TJ5qDwWTWJBTZrRIsWJ cHj09Nf6XNhUvOcTNZap5VMDkwTNSZmBQZjByPgIVTl3XtjIh4cOdzCvM8TaisZiFDKs hVxCzv1dEPfdbwmGxXj7348gNJFxfcxNUndwbaheK/iF2g/UO88xsFkn9e/51BfQ4LZl yg9bX4aNrkd4jE2rJod31bvRnqBwD29HfDsYrQJCQsUIAeBsJ6vDr61IYhDEXgdx5KGq kpurvyEO/jqqrE1dlBOTmMkAxC+ieiiGgiY1tST7g/LuZp7VtkkfxqPV6LesntXj+J41 +L7g== X-Gm-Message-State: AOJu0YxfVnXQ2AECFt/I2udseC7HJz9pJy64TmlukTYkukxnMyAvjsIY WTZnq3JZ57IIyMjTjt/0Q5tkKAwVjN0wwL+hWHxsiS2edw5HFCZYEalAjYydDezgBqEife3WTsv A/NPnlA== X-Received: by 2002:a17:90b:3007:b0:2d8:f0b4:9acb with SMTP id 98e67ed59e1d1-2dad513545emr14225866a91.34.1725988851772; Tue, 10 Sep 2024 10:20:51 -0700 (PDT) Received: from linaro.vn.shawcable.net ([2604:3d08:9384:1d00::9633]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2db049883e5sm6685310a91.50.2024.09.10.10.20.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Sep 2024 10:20:51 -0700 (PDT) From: Pierrick Bouvier To: qemu-devel@nongnu.org Cc: Nicholas Piggin , Daniel Henrique Barboza , Alexandre Iooss , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , =?utf-8?q?Alex?= =?utf-8?q?_Benn=C3=A9e?= , Eduardo Habkost , Richard Henderson , Pierrick Bouvier , Paolo Bonzini , Marcel Apfelbaum , Yanan Wang , Mahmoud Mandour , qemu-ppc@nongnu.org, Zhao Liu , Xingtao Yao Subject: [PATCH v8 5/6] tests/tcg/plugins/mem: add option to print memory accesses Date: Tue, 10 Sep 2024 10:20:32 -0700 Message-Id: <20240910172033.1427812-6-pierrick.bouvier@linaro.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240910172033.1427812-1-pierrick.bouvier@linaro.org> References: <20240910172033.1427812-1-pierrick.bouvier@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::102b; envelope-from=pierrick.bouvier@linaro.org; helo=mail-pj1-x102b.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 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org By using "print-accesses=true" option, mem plugin will now print every value accessed, with associated size, type (store vs load), symbol, instruction address and phys/virt address accessed. Reviewed-by: Richard Henderson Reviewed-by: Xingtao Yao Signed-off-by: Pierrick Bouvier --- tests/tcg/plugins/mem.c | 69 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 68 insertions(+), 1 deletion(-) diff --git a/tests/tcg/plugins/mem.c b/tests/tcg/plugins/mem.c index b650dddcce1..086e6f5bdfc 100644 --- a/tests/tcg/plugins/mem.c +++ b/tests/tcg/plugins/mem.c @@ -21,10 +21,15 @@ typedef struct { uint64_t io_count; } CPUCount; +typedef struct { + uint64_t vaddr; + const char *sym; +} InsnInfo; + static struct qemu_plugin_scoreboard *counts; static qemu_plugin_u64 mem_count; static qemu_plugin_u64 io_count; -static bool do_inline, do_callback; +static bool do_inline, do_callback, do_print_accesses; static bool do_haddr; static enum qemu_plugin_mem_rw rw = QEMU_PLUGIN_MEM_RW; @@ -60,6 +65,44 @@ static void vcpu_mem(unsigned int cpu_index, qemu_plugin_meminfo_t meminfo, } } +static void print_access(unsigned int cpu_index, qemu_plugin_meminfo_t meminfo, + uint64_t vaddr, void *udata) +{ + InsnInfo *insn_info = udata; + unsigned size = 8 << qemu_plugin_mem_size_shift(meminfo); + const char *type = qemu_plugin_mem_is_store(meminfo) ? "store" : "load"; + qemu_plugin_mem_value value = qemu_plugin_mem_get_value(meminfo); + uint64_t hwaddr = + qemu_plugin_hwaddr_phys_addr(qemu_plugin_get_hwaddr(meminfo, vaddr)); + g_autoptr(GString) out = g_string_new(""); + g_string_printf(out, + "0x%"PRIx64",%s,0x%"PRIx64",0x%"PRIx64",%d,%s,", + insn_info->vaddr, insn_info->sym, + vaddr, hwaddr, size, type); + switch (value.type) { + case QEMU_PLUGIN_MEM_VALUE_U8: + g_string_append_printf(out, "0x%02"PRIx8, value.data.u8); + break; + case QEMU_PLUGIN_MEM_VALUE_U16: + g_string_append_printf(out, "0x%04"PRIx16, value.data.u16); + break; + case QEMU_PLUGIN_MEM_VALUE_U32: + g_string_append_printf(out, "0x%08"PRIx32, value.data.u32); + break; + case QEMU_PLUGIN_MEM_VALUE_U64: + g_string_append_printf(out, "0x%016"PRIx64, value.data.u64); + break; + case QEMU_PLUGIN_MEM_VALUE_U128: + g_string_append_printf(out, "0x%016"PRIx64"%016"PRIx64, + value.data.u128.high, value.data.u128.low); + break; + default: + g_assert_not_reached(); + } + g_string_append_printf(out, "\n"); + qemu_plugin_outs(out->str); +} + static void vcpu_tb_trans(qemu_plugin_id_t id, struct qemu_plugin_tb *tb) { size_t n = qemu_plugin_tb_n_insns(tb); @@ -79,6 +122,16 @@ static void vcpu_tb_trans(qemu_plugin_id_t id, struct qemu_plugin_tb *tb) QEMU_PLUGIN_CB_NO_REGS, rw, NULL); } + if (do_print_accesses) { + /* we leak this pointer, to avoid locking to keep track of it */ + InsnInfo *insn_info = g_malloc(sizeof(InsnInfo)); + const char *sym = qemu_plugin_insn_symbol(insn); + insn_info->sym = sym ? sym : ""; + insn_info->vaddr = qemu_plugin_insn_vaddr(insn); + qemu_plugin_register_vcpu_mem_cb(insn, print_access, + QEMU_PLUGIN_CB_NO_REGS, + rw, (void *) insn_info); + } } } @@ -117,6 +170,12 @@ QEMU_PLUGIN_EXPORT int qemu_plugin_install(qemu_plugin_id_t id, fprintf(stderr, "boolean argument parsing failed: %s\n", opt); return -1; } + } else if (g_strcmp0(tokens[0], "print-accesses") == 0) { + if (!qemu_plugin_bool_parse(tokens[0], tokens[1], + &do_print_accesses)) { + fprintf(stderr, "boolean argument parsing failed: %s\n", opt); + return -1; + } } else { fprintf(stderr, "option parsing failed: %s\n", opt); return -1; @@ -129,6 +188,14 @@ QEMU_PLUGIN_EXPORT int qemu_plugin_install(qemu_plugin_id_t id, return -1; } + if (do_print_accesses) { + g_autoptr(GString) out = g_string_new(""); + g_string_printf(out, + "insn_vaddr,insn_symbol,mem_vaddr,mem_hwaddr," + "access_size,access_type,mem_value\n"); + qemu_plugin_outs(out->str); + } + counts = qemu_plugin_scoreboard_new(sizeof(CPUCount)); mem_count = qemu_plugin_scoreboard_u64_in_struct( counts, CPUCount, mem_count);