From patchwork Fri Jul 5 00:34:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pierrick Bouvier X-Patchwork-Id: 810345 Delivered-To: patch@linaro.org Received: by 2002:adf:a199:0:b0:367:895a:4699 with SMTP id u25csp1388122wru; Thu, 4 Jul 2024 17:35:17 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCWxNlxR0JSmoz7TcNvOikt2nGecNo1cdFZHNUZ4NUgAeMtY3pOXGBjX3PidYb1rU3e/2+2X9p12ZLsnC2pFN4Vx X-Google-Smtp-Source: AGHT+IE0obQUlBf91txxEtkt46isfap2dnQ7BV8Ox27gmewTXrhzQ1cmcpdfgBheu99Y7EzS4lUo X-Received: by 2002:a25:b121:0:b0:df4:b01b:3d21 with SMTP id 3f1490d57ef6-e03c19e9ee8mr3601679276.49.1720139717117; Thu, 04 Jul 2024 17:35:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1720139717; cv=none; d=google.com; s=arc-20160816; b=Qo16E2nAAAjgjMIS+kFv8Vn1nWJJ3sxJ/plvHLVSBQQNmDkuCg4a5exCWZpgyft3Oc aE/MRRev+QiVHiOKICPBYrFYXlXASVRXhX2/Cssf2NVb4pN0XjBLwOi6PCLfPND+bRmg Ta+WKMqmbGV09OoN6qPXFRhTJB8UmowIq8WghNnE9IWhcW9yqTEuNnRu0H8lcZTpF/I9 WkgrMBh0rLZtPlxpgHjRdHEGMHTj764ar1HVLicavAbm0ok7CrWmyuIDlWdqm0v7oX9w eTTcE55BlOjD76SoVhmgzruZRzgGrY09eY8nBaS67nI1taaHLmOkZL5K6SmtnnEendNh 09rw== 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=pLoy+86fAS0seygToReysvwiKoc42KvDoYrVATorcNM=; fh=2IzZKSAfkxDgXTtM7kFa1jWu0SUssVJhWA7cdsHH2KE=; b=fMreENX6JoWINYuOjaCrHsFXCOrCqJQRl/Qb/SCS4/N2FuAFgPga8itTcs4JuiA6pp SKMTsWC86jkqdTd6kBWvdWSR5ptS2SXr40B0Qmw43i3T71n/3/fPVgc/YF7WJvFwMiZY 9AT0HiUZGd2Mkb4IAPk1E+oVuC5h6iYW6iF0sMBEwMuO5ePw2eT8mM+sPXhnvlfVPOX6 Na/US9WcOUXyIx469RSPmNrZhOD+gRPm01C6VPFBuZdAxTHtf23i3O3dGInwn4S8P1ru ihMfBsM0fhcW0PZC14uuZLorz3F5L6t5qUjzFeCPQRr7qbG77Ln3S7BQnLxTQzPMiUmk 5/lw==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=miPJh4In; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id 6a1803df08f44-6b5df9bfbeesi53592966d6.588.2024.07.04.17.35.16 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 04 Jul 2024 17:35:17 -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=miPJh4In; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sPWuo-00038I-U4; Thu, 04 Jul 2024 20:35:06 -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 1sPWun-00030x-5T for qemu-devel@nongnu.org; Thu, 04 Jul 2024 20:35:05 -0400 Received: from mail-pl1-x62e.google.com ([2607:f8b0:4864:20::62e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sPWul-000087-61 for qemu-devel@nongnu.org; Thu, 04 Jul 2024 20:35:04 -0400 Received: by mail-pl1-x62e.google.com with SMTP id d9443c01a7336-1fafb9a33b3so6132575ad.1 for ; Thu, 04 Jul 2024 17:35:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1720139701; x=1720744501; 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=pLoy+86fAS0seygToReysvwiKoc42KvDoYrVATorcNM=; b=miPJh4InyiaoHTYWbWeB7lXlWY2Q+7SBo3YWfHTiCXkbWHj0/HnmG6Kv0EwjGl8HAa 2MitpWuNeg4Y2pz31IggiCoLadjbK7ooM2UIoysmNRhYiGaCW1KeakQp2KgdfOQ9nkAn Y+2Z90kNRyUkhppq/tf6ayatrR0tyhDExFrrjLF2m/qCp/MopNBIlRShgdtC6DpWk1Zv PI4chre2lUoZ0RlVwsHDoFLCFiayaTJ/u8yffmX/btwBr2gRFOcG4lqOJWBuQuzhrK1x Ri0djAf0qUqiLr42YYyEkTnBjkoqIfVxK3f92a6aYEM+NEEpTPvrVBHk7CprCwizkkf6 3NPw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720139701; x=1720744501; 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=pLoy+86fAS0seygToReysvwiKoc42KvDoYrVATorcNM=; b=FkZWt2StUGv5PZH3RV+sJlEhfNra98Rt+DBtOHGqRbG/ps0h13SHFS+HPcV+F1GaPy APm5G1oh9PkmA/wnPsUqt3OUapD3FQs/t0WXCuJYGK/AHskjBlE6XDNeUCXOAFmfIXqd ceHau4Ud0aZqHY5G67EBZxUTD0hOJDsnirS21b74jfO059Z43B55DTfXhI+ejv2kE0D+ VvKe3eQvBc4iKXu1/B65JiUaSNlrF7+TYlV5DzTq6qfvVsUn4ToqYsW2v2WUTXNyKU3w 3E/0LgJq4AA5RDWEXw9ZXR7SR8FG9PTb9knmwZJabGq47urVzL+UL8u7DjsfoforyW9H RdrQ== X-Gm-Message-State: AOJu0YzNlycSssnfmBll2sLh1HSBRY/chkvnhoS/TKGY1q9Cy3C5J3B7 paKhaeMFaPXDX/wygJ8yxljqHR/TF62i0En37Vz1BJpP8XTvQ0YDT+hk6NxXdD6BXLV9LO2FHjS bDLI= X-Received: by 2002:a17:902:eccd:b0:1fb:2b6b:2789 with SMTP id d9443c01a7336-1fb33e84c98mr24969155ad.37.1720139700930; Thu, 04 Jul 2024 17:35:00 -0700 (PDT) Received: from linaro.vn.shawcable.net ([2604:3d08:9384:1d00::2193]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1fb1a075616sm39008595ad.15.2024.07.04.17.34.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Jul 2024 17:35:00 -0700 (PDT) From: Pierrick Bouvier To: qemu-devel@nongnu.org Cc: Alexandre Iooss , Richard Henderson , Marcel Apfelbaum , Pierrick Bouvier , =?utf-8?q?Alex_Benn=C3=A9e?= , Paolo Bonzini , Yanan Wang , Mahmoud Mandour , Eduardo Habkost , =?utf-8?q?Philippe_Mathieu-Daud?= =?utf-8?q?=C3=A9?= Subject: [PATCH v5 6/7] tests/plugin/mem: add option to print memory accesses Date: Thu, 4 Jul 2024 17:34:20 -0700 Message-Id: <20240705003421.750895-7-pierrick.bouvier@linaro.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240705003421.750895-1-pierrick.bouvier@linaro.org> References: <20240705003421.750895-1-pierrick.bouvier@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::62e; envelope-from=pierrick.bouvier@linaro.org; helo=mail-pl1-x62e.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 Signed-off-by: Pierrick Bouvier Reviewed-by: Xingtao Yao --- 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);