From patchwork Mon Sep 16 08:53:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 828992 Delivered-To: patch@linaro.org Received: by 2002:a05:6000:4187:b0:367:895a:4699 with SMTP id ei7csp681781wrb; Mon, 16 Sep 2024 01:56:54 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCWGIhUZkiZumMR+2K6vUJN4PzwCgwojFtTCmOCog+FaBe3IEDMFtLQOXH1v0WbvAA+zEky7Lg==@linaro.org X-Google-Smtp-Source: AGHT+IFzBtkWAJvvuG7AXtMoOFoZSojqNywVX3r5Pg9ouwdcQPoEe9SwNeMQnJTl38VmNOa0l5Wu X-Received: by 2002:ad4:5011:0:b0:6c5:8ecd:41fc with SMTP id 6a1803df08f44-6c58ecd430bmr86482716d6.15.1726477014321; Mon, 16 Sep 2024 01:56:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1726477014; cv=none; d=google.com; s=arc-20240605; b=fOERNz6ghMQqoQgaNt2xGeGBHTgNC99C/kgvRNq6n27h+gJN+DvlYEsZANCdby16sv lkTtdBY/CJocIHRnaldIkZmKQwgZW1+5uw/Z/rPOhxiC6ag0lGB5x8W6pa1BMQ90fgkZ sSqamMst9o2nf3NcFE2r7oD2zV5rjdvSC+oWqrUVgdtdi5vax2NVuTFRiI97IK6vfRZE rhEXUjYClKAkMc2Js6ivRY/jutnCSGtJEOzxaWy0bDu8F4FAILpsvMkhE7wzAgqlPPqo Rhtdy8r3ODlR+ER8w9q9YBeAcALU9qm8I88YKmn/66y5IwWaTKR/1OSVO9gPVYIDmKmG kQsg== 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=R3mmoZsXxDlfMOCui4cd46NxPRxHQYb5G17T8SSWAU4=; fh=J7xxoiH/FgLINVeQdLJSQ9A6Jne2JYMDx39ZFxN4EsU=; b=UEyO4UoKkTg1f8/8Vb6NxNIKam76TE2AOcubdk6JgSGwrsY3RmIu/+DoksiHM7As7b nUSFPDjWSsOqS5Z1em4k1a8UzFF1aPpCW88OZBEnXEy1AwgS/H1ICckxnVilj8SwNspH 4UtBRSJ/yl9xVuBqjsjtnGfGZBtgoYZ6NtnBeFYgN79SARgQbmoa9qLxCejS/DXRxAHR hd0WWFEVgN45ZXy5sgyAonTF6tfqhDGcpj3j8WOOEF5A4fFTp7VdBnyAkZhnkQPj0QPb AIeYidKvv25rB3ZnimPipuOW3dBD9uuduoYC5j/MQdgB6bVWhhXHqmfcTWm3/y6075eA T/Jg==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=lY7O8PMT; 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 6a1803df08f44-6c58c7f9e34si53195956d6.607.2024.09.16.01.56.54 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 16 Sep 2024 01:56:54 -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=lY7O8PMT; 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 1sq7VW-0001dX-VC; Mon, 16 Sep 2024 04:54:55 -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 1sq7V4-0000Ha-TC for qemu-devel@nongnu.org; Mon, 16 Sep 2024 04:54:26 -0400 Received: from mail-wr1-x42c.google.com ([2a00:1450:4864:20::42c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sq7Un-0005DM-RN for qemu-devel@nongnu.org; Mon, 16 Sep 2024 04:54:26 -0400 Received: by mail-wr1-x42c.google.com with SMTP id ffacd0b85a97d-374c7d14191so3247170f8f.0 for ; Mon, 16 Sep 2024 01:54:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1726476848; x=1727081648; 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=R3mmoZsXxDlfMOCui4cd46NxPRxHQYb5G17T8SSWAU4=; b=lY7O8PMTukMMCH+Vhn5rT6ODQKoeV4hvffJr0twrSpk7ZWszM3Pr1+7qogO5hfEtXg lICjYWuH3BBkyq6U3EStb3AiiwSE1Ib/R0Ke7+YsqWRfH2GOKH17kM5g6soBXIQugM3y 2TeVspcyLO1DCE4JBxwjCALyUa8FSV5NJPNWGxJ+98QRXO21KMD999MhS056AkoXvNUd OMdSwPba2+yxAlVMEvFLCGxhar0k5NGEkRm42oZvgkl4igTT11Q3YxFzdEewAmkhWitj BF14Pm4ImiX5Y5XOA5rVPMXQ42Jn+X1GXHB2slKJ0Q67iNU7Ex0GDGJpM7JP9sW7rfc4 0Kmg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726476848; x=1727081648; 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=R3mmoZsXxDlfMOCui4cd46NxPRxHQYb5G17T8SSWAU4=; b=k62CpwY196TmcEt/Z8FX5lY8s7rRJYsZy5sA9lt8FxahxDeSlP6seKx/1+Lz6ZKeaS rvi2CdqbjBcn1uUroZ9xRJ3tclWxzxItuugklYepCMUi+lwP1XOuWKC2YxH/6ZlGNNnA ATFetnhY+DMvpfMmmTP1TtxoExD5fgkSXhkfThI859S6we69WZWzsRKCwKKOGg4G0h2R kfGX2eMTcQNM3kBSpjKx2tdPOIGwn9zOqMNXCvOHh6g6rQ5c+ztdlwjBGF4tJEK92cY7 s7oDs8LJnMRxvPWP7NGTAfT23emrqfD/LW9tRoIL058fxpP715GPIqZD3I7pTnjXJOlZ 2IMw== X-Gm-Message-State: AOJu0Yzx5BH0HjteKRKqAqyyQQrUKeoenF9kv0vcEhI8knndffBskRB4 Mr/1x5wzV+c/jFWynxQIIxFQetQSXmei+/o5SRM6UhdMKBnN3qW7VIFuxg4t5u0= X-Received: by 2002:a5d:598a:0:b0:374:c6b6:c656 with SMTP id ffacd0b85a97d-378c27f94bbmr10245527f8f.21.1726476848139; Mon, 16 Sep 2024 01:54:08 -0700 (PDT) Received: from draig.lan ([85.9.250.243]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-378e73e80dbsm6620754f8f.33.2024.09.16.01.54.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Sep 2024 01:54:04 -0700 (PDT) Received: from draig.lan (localhost [IPv6:::1]) by draig.lan (Postfix) with ESMTP id 117885F94D; Mon, 16 Sep 2024 09:54:01 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: qemu-s390x@nongnu.org, Thomas Huth , Richard Henderson , qemu-ppc@nongnu.org, Ilya Leoshkevich , Paolo Bonzini , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Marcel Apfelbaum , Alexandre Iooss , Eduardo Habkost , Daniel Henrique Barboza , Yanan Wang , Nicholas Piggin , David Hildenbrand , devel@lists.libvirt.org, Mahmoud Mandour , Zhao Liu , =?utf-8?q?Alex_Benn=C3=A9e?= , Pierrick Bouvier , Xingtao Yao Subject: [PATCH v2 08/18] tests/tcg/plugins/mem: add option to print memory accesses Date: Mon, 16 Sep 2024 09:53:50 +0100 Message-Id: <20240916085400.1046925-9-alex.bennee@linaro.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20240916085400.1046925-1-alex.bennee@linaro.org> References: <20240916085400.1046925-1-alex.bennee@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::42c; envelope-from=alex.bennee@linaro.org; helo=mail-wr1-x42c.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=unavailable 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 From: Pierrick Bouvier 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 Message-Id: <20240724194708.1843704-6-pierrick.bouvier@linaro.org> Signed-off-by: Alex Bennée --- 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 b650dddcce..086e6f5bdf 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);