From patchwork Tue Jul 2 01:10:14 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pierrick Bouvier X-Patchwork-Id: 809013 Delivered-To: patch@linaro.org Received: by 2002:adf:fe0a:0:b0:362:4979:7f74 with SMTP id n10csp1830637wrr; Mon, 1 Jul 2024 18:11:18 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCWJDQUrn8DbKdGVzMUCUZYDdYmvJTxqjPAjwhaGuLp45MY6qnULufMiNIz4KMUUo6mZDWWo7gQ1t1z77+8DQ6WI X-Google-Smtp-Source: AGHT+IHwaiH5HfB30O6mNSEAW+dK+jSF2dXnigFL5FTdjppUMcqackp7XEYpnSS8YcicvlZPrVuJ X-Received: by 2002:a05:622a:144e:b0:446:5f64:f3bf with SMTP id d75a77b69052e-44662ec3827mr106356291cf.63.1719882678115; Mon, 01 Jul 2024 18:11:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1719882678; cv=none; d=google.com; s=arc-20160816; b=iXBvR4gX+hoSQTqoFPJYS5UpIrO3lp89KhiL50fbsizcPypOVLdJ819DDCCsEU4egM mBPAfraTt9E++dWUTAS4XZZq3UNlxHFY1drdedmBRWNU0pcaWUPo5t2LYndPhD0MIPhc +wzqYOOmZkJ5dr/hKpBnhnu9mFLcQxfoQpLpe9ozGPFKPnJaoc+W9INjaHprgp55KfT9 aZQm6Zxz8RlyEA+lFRKOaJt0q22VsiVEJXzd4tz7JRuyC9wM0MROJ/nTpzw5qFBDKCZU TiqcxoIijZ6I8n8IggQp+1veyJwlHMToxwCO/T+l2SBWuuMWB1A+1wV1V29hM3YoMNf3 2rFQ== 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=KQGGwWjGBzDeoWSZMlw/pE8YwbdHKTdXx63bixAfqp0=; fh=Dj7LLbUmtY/f5f9pW73RWc2Os2c72ErjJBZ6EuA7pXE=; b=jIJhsb7Ee/JT+B4MK5LL66ZtKHf3ZGhd/wN7k+r07DoMFZE0aDP6q6/gVa2UqPEqO6 J6HGdwvXLE5jWkyjbBGTyo4cm6bVxweeGoGj6beXmQms63CNoLQe7DtXqyum6K4q8lYF uCF4Qb6ofyAuMGmNq1N6RKCF9viTfLNIuMrGfI7fCF7FX5+Rf5AswW+MDv1WN8vG6PHs nj4n863WVN6ERk+A0XtCsJgfF2/dn2nhnKOwoGu/EVXZFAhrQtSdVlYKuEeeTkvtH1I3 Y4Q6LF4SV24AUSdMvtZhl7vSklHrk404+yz1z+m7viKtE7bjP0oe27jsB2Nph5wOwdok W/uA==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=R0tf5gcJ; 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 d75a77b69052e-446514e2bfasi95295781cf.680.2024.07.01.18.11.17 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 01 Jul 2024 18:11:18 -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=R0tf5gcJ; 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 1sOS2i-0005UA-16; Mon, 01 Jul 2024 21:10:48 -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 1sOS2a-0005Ry-2S for qemu-devel@nongnu.org; Mon, 01 Jul 2024 21:10:40 -0400 Received: from mail-pj1-x1032.google.com ([2607:f8b0:4864:20::1032]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sOS2X-0002BF-0X for qemu-devel@nongnu.org; Mon, 01 Jul 2024 21:10:39 -0400 Received: by mail-pj1-x1032.google.com with SMTP id 98e67ed59e1d1-2c86e3fb6e7so2243242a91.1 for ; Mon, 01 Jul 2024 18:10:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1719882631; x=1720487431; 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=KQGGwWjGBzDeoWSZMlw/pE8YwbdHKTdXx63bixAfqp0=; b=R0tf5gcJf/EUOb0jQqL7qDC/Au3bC1ysk6NveT/RqtubH44dLAoHTrIO9f4MTbQcwU jmEW1tKt6sGqRUvBm0R6rHh33Y2r6OKrqWxfN+8t0LUPneiZW4g5zksaewcZXnE/rEZN GXNEe9H66Z6AL3/AO+D0c8hRSQMwX4aChNrVQbasquq8GDaEhxsYP6KZKSUBCkNjSkBW JKVy1IscD57lSo7jKZ3BAIXbOe6EoDdHnA3o27foN/+qv5VegP1psrJSCU2meP3IpJYz qP7BdL6ZgREr5rvTIqkK1UiocUlRM6HECLAOdtTIc+4RGemP5/n2C3v+iiG5tF53hKh0 zF4A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719882631; x=1720487431; 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=KQGGwWjGBzDeoWSZMlw/pE8YwbdHKTdXx63bixAfqp0=; b=Ni2JKuz7QHx8RaUMjkIgm1avdrfRWxqNAReR4QD51h9LBnYsaauZQ6fYXcFmORHVNS AfDigEZj7fvxVYSQP0gL/JEyHffkkGGbkKUt0gejzv5Jb+S7Nf+UV8sqWsCZudiZb5oA K3CXyhsdaHmEvZ9Iz+iBjHGI4/efHZ0668yilU5AAVFkoC1Hfm/3zmwl30OtsVyEwX1i t4NV/1cgfR9lY3WB2j6qAHrSAeSTaLXGsftCC+1vpCT5EWdHPK7No1/0zfWtqlCNbP+Q PRPJjJzKoHX/X/xmVcyS7gByp5wK7+ZUU78bc5NkjiTIGQQolYwbk9sxHgYO4KnhfgHq YN5Q== X-Gm-Message-State: AOJu0Ywu/UoTYbhv9pHO05js07zeZFwdqxvKY+9DFhKckaHKGshSBOql VGbA7q4UDIlvSkGNfbzmbNMmBElMXcrO3z/8ic28LICfyU9snUqlJbAdneEepPoEYrkaP63sZwH f X-Received: by 2002:a17:90a:fe13:b0:2c4:b515:46d4 with SMTP id 98e67ed59e1d1-2c93d6ef057mr3670714a91.3.1719882631002; Mon, 01 Jul 2024 18:10:31 -0700 (PDT) Received: from linaro.vn.shawcable.net ([2604:3d08:9384:1d00::2193]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2c91ce1f198sm7480317a91.2.2024.07.01.18.10.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 Jul 2024 18:10:29 -0700 (PDT) From: Pierrick Bouvier To: qemu-devel@nongnu.org Cc: Eduardo Habkost , =?utf-8?q?Alex_Benn=C3=A9e?= , Pierrick Bouvier , Paolo Bonzini , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Alexandre Iooss , Richard Henderson , Mahmoud Mandour Subject: [PATCH v3 6/7] tests/plugin/mem: add option to print memory accesses Date: Mon, 1 Jul 2024 18:10:14 -0700 Message-Id: <20240702011015.325609-7-pierrick.bouvier@linaro.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240702011015.325609-1-pierrick.bouvier@linaro.org> References: <20240702011015.325609-1-pierrick.bouvier@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::1032; envelope-from=pierrick.bouvier@linaro.org; helo=mail-pj1-x1032.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. 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..aecbad8e68d 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%"PRIx8, value.data.u8); + break; + case QEMU_PLUGIN_MEM_VALUE_U16: + g_string_append_printf(out, "0x%"PRIx16, value.data.u16); + break; + case QEMU_PLUGIN_MEM_VALUE_U32: + g_string_append_printf(out, "0x%"PRIx32, value.data.u32); + break; + case QEMU_PLUGIN_MEM_VALUE_U64: + g_string_append_printf(out, "0x%"PRIx64, value.data.u64); + break; + case QEMU_PLUGIN_MEM_VALUE_U128: + g_string_append_printf(out, "0x%.0"PRIx64"%"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);