From patchwork Wed Jul 24 19:47:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pierrick Bouvier X-Patchwork-Id: 814178 Delivered-To: patch@linaro.org Received: by 2002:adf:e641:0:b0:367:895a:4699 with SMTP id b1csp94918wrn; Wed, 24 Jul 2024 12:48:45 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCV81+D+wYa/TmDLA8eqDqRaoq4ls/QhjQtAeUlqNUiDw+gwVWRcOizEzi0Gjmu0NkGB3Ck6yM7O4R0ZXtgqA/5p X-Google-Smtp-Source: AGHT+IFaAg+XZxfAtuoIysK0JwKN6NFvxNIodMOgkxHQOi1k8RNeXN74mgfwZmd3PtpTLktLzKkB X-Received: by 2002:a05:620a:4041:b0:79f:17d9:d86b with SMTP id af79cd13be357-7a1d449ee64mr107506885a.12.1721850525642; Wed, 24 Jul 2024 12:48:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1721850525; cv=none; d=google.com; s=arc-20160816; b=KTph2m7PQojGTMX/rmDj1v/Ppe/+Jpcfn7LEoQBHSquUJuqP4RsPf1y7Z0U/PyDiQO 6dDNjTbHRsuQOQi5O7xXSc5fLOfl3SIX4fjv3fZe4NO1796mxbJgT7/h7DXRQFS9p1wU 1KVczbm1R7Y9J4cCNOL3kjP1S7vry2LLDKOZ+tPojjDu+BspAWhpIpH1I+GbNO0IbiWu YdmDsQImPJUdcq+gvOppdi/fo3Mz0iD68T4lrYs46gdSRgI3KjJT0mq3pcoVecwJQFRm kdtr0XG584K80no7bj+vdgafzefjs+2wUjgZerl1lUtXUiP/XhSQichZBoSNUjxz4oZ8 Firw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=Q3v41GFzb0/piPBsIvskwb3RVBKxsZFvBfDW4N/dtnI=; fh=xnCpbbVYJFFG+A0G6b4cSDVMgju0ymiCog0e/FTUtiE=; b=Z/b1kOWVhWBP7IWGG8vuC4314dxGnevunt2drfbT1IxSv7ebG56PKkDSH/We/jcbu2 cPCerm2oy2oKNCixMT9hrSnpKcQhFYbU8LwVoMRe7GR80/Btz6g3T8YQ1cQJD3tm44sF PLYO5Gh3LGPiVcLXD1Wp4LAV4FEQpxFz09rKnBpm0BbLfTt35P1wY8LVUIsowl3pRsK4 XBnw5ZgyjIoOltzdv698KOA/qV96207ZToScOmGO+Xsi0kv04uxv5NhTDzJ5HeUatoB2 OMG7ihdDeAGw2TkIpJ7xloJUfEu39yba30M0VBaS///VoIq6t7SZiS0KvUcEPIo5hmOi nyNQ==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="aWv3/x5V"; 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 af79cd13be357-7a198f9440asi1307475885a.65.2024.07.24.12.48.45 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 24 Jul 2024 12:48:45 -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="aWv3/x5V"; 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 1sWhxs-00033U-VB; Wed, 24 Jul 2024 15:47:57 -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 1sWhxT-0002Mr-Cm for qemu-devel@nongnu.org; Wed, 24 Jul 2024 15:47:32 -0400 Received: from mail-pf1-x431.google.com ([2607:f8b0: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 1sWhxP-0006ET-S3 for qemu-devel@nongnu.org; Wed, 24 Jul 2024 15:47:31 -0400 Received: by mail-pf1-x431.google.com with SMTP id d2e1a72fcca58-70d333d57cdso128269b3a.3 for ; Wed, 24 Jul 2024 12:47:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1721850443; x=1722455243; 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=Q3v41GFzb0/piPBsIvskwb3RVBKxsZFvBfDW4N/dtnI=; b=aWv3/x5VJiq0Z5PRpTpsnruxWRmNoFnNZRq0lisOciH4IakGwlCMTNnX6j85TZaR7/ R5gOzLS7A8PdH8HWclcf+IvxwUHS2o0md5//9ZVP95vptkxjWe0KtzrtIPxMb8orRY4T su/UW99bSxERM9x+icyJqr9hC8O0HYXuypJHdDVlLPG0e/gqXdh0b4LPe+YlV0LpZlzI 0xAoFOYKU0OmgsAPcV3h8HPIoKy4O3lvW9x1c9DWHQ7aJ/XbD1sLmT/gXUXTSrdzB8BT RFKe6jz18vxslAdnDsHbpkq3u0AisLy7G7QAQjDBgsdIhyHvsq0zTUS2klT3uZBsvbWn xVrg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1721850443; x=1722455243; 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=Q3v41GFzb0/piPBsIvskwb3RVBKxsZFvBfDW4N/dtnI=; b=UL9I+uCUuQZrpoOeUlBMsRmDMmgz5LnwXFP9qEq1VRGwkonaR7IyHRxoVxhhvEYl+7 C4K3tiWahRuSe4Ddn5kwdEVahyqDh7tVT5/VIld4MX0QhGj463N4FxNDWoLsVEhXGr93 qIwdMuD6UBrbo8znzsklkaadqJzoh1sN9NS6pTWJ4at/4Tmz0dMHVAXSXvJRKHcNFqu4 Q/poJZbQToRZX/7Iy8StVU4Lvq4xtJPb3hKvt3zuhO7jTGO1cLxIt5rsBj30NACHajlk ZlMpVy+2opihh9fpJjLiVdvdnE3fxn7IQm6rdQSZ4wOgN9DK6V86BJRchVgp7vtBFec1 74SQ== X-Gm-Message-State: AOJu0Yztw45E/TQCQbyI9D98R3aK0giBmlFw/LVvPjQzhXrK/pTTesUY UJfTC/70+Mbo0TvuF/iBLiFma3OeyemhtkiSTVgB/jVRs6GoQ2OTh3vGh1t3H2zSETExldHZlbX k4Cg= X-Received: by 2002:a05:6a20:2590:b0:1c4:2134:dd52 with SMTP id adf61e73a8af0-1c4727e1437mr1099922637.3.1721850443185; Wed, 24 Jul 2024 12:47:23 -0700 (PDT) Received: from linaro.vn.shawcable.net ([2604:3d08:9384:1d00::b861]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-70d19c52a62sm6339116b3a.124.2024.07.24.12.47.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Jul 2024 12:47:22 -0700 (PDT) From: Pierrick Bouvier To: qemu-devel@nongnu.org Cc: Alexandre Iooss , Zhao Liu , Mahmoud Mandour , Yanan Wang , Pierrick Bouvier , Eduardo Habkost , Paolo Bonzini , =?utf-8?q?Alex_Benn=C3=A9e?= , =?utf-8?q?Philippe_M?= =?utf-8?q?athieu-Daud=C3=A9?= , Richard Henderson , Marcel Apfelbaum , Xingtao Yao Subject: [PATCH v7 5/6] tests/plugin/mem: add option to print memory accesses Date: Wed, 24 Jul 2024 12:47:07 -0700 Message-Id: <20240724194708.1843704-6-pierrick.bouvier@linaro.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240724194708.1843704-1-pierrick.bouvier@linaro.org> References: <20240724194708.1843704-1-pierrick.bouvier@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::431; envelope-from=pierrick.bouvier@linaro.org; helo=mail-pf1-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 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/plugin/mem.c | 69 +++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 68 insertions(+), 1 deletion(-) diff --git a/tests/plugin/mem.c b/tests/plugin/mem.c index b650dddcce1..086e6f5bdfc 100644 --- a/tests/plugin/mem.c +++ b/tests/plugin/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);