From patchwork Thu Sep 21 14:45:34 2017 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: 113269 Delivered-To: patch@linaro.org Received: by 10.140.106.117 with SMTP id d108csp2112725qgf; Thu, 21 Sep 2017 07:45:59 -0700 (PDT) X-Received: by 10.200.37.157 with SMTP id e29mr3388783qte.271.1506005159614; Thu, 21 Sep 2017 07:45:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1506005159; cv=none; d=google.com; s=arc-20160816; b=bYKFEkOqNsagXHhZuxE6OkGB4DQuCoONbvzmS9CU/bkvMHCoXxTzghauXz1wUXUm1A clZzdrhWOwUhVmXkkLY7rZ0Bdn3Eoh1/fV/N4pvb9Ac2h9ezDOSeFX7SAowwNjUlR4Rt iN+PgRzyxogBE7sVyR43plub4Yvwx057RO1wg2SqdTMkbovP45PBds/OWPA5l4+s6u26 XIpJuDp9AjnSoG50352vpIp7F0Gc5XqzsZdBW05LXXcjT9lEyzcl4iVBWjQXoqngPhur 35WkQ2nZj3aMSgiD80g2OQC9LtPPGmIPHfdGZYuYxb7+7pkMUYWjIJ6QSPUEZ7AIv9PG SJUw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject :content-transfer-encoding:mime-version:message-id:date:to:from :dkim-signature:arc-authentication-results; bh=1CdUT8HMJmkAR7b7iMMG+la/pcLaXdcXqx70gOJy2D8=; b=GLPTLdEQrb5US5Jhk0kTuCK317qLRNPaxlLNewzEUUXFB4FRSjh5c/FtGJMzRfrOq7 cFNtjcgIWsDL5/Em6J4S/VU111eczCqm3eKg7TIUeOWv/XrcAoHpf9HWCFwoCqs3+5Np X/CaLEsYgeORY/gdKDSveF5ed9+bOCRygtD32d86IEBrHOqOwR3St0ZUVwFLxccA5nSN R5jduj/DLz7S+WPWVysi/fEbs68VTesn59yb3weelLRPwmLSLvqQV08HiSwU+U0Fxhko ieqQI86fVQegOLmdSdlQBGGvNaulne3JlGyKRT4SxgwbXap4HAziTlEOzhBJTwXj8B2+ sZ+g== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=QvLNHe/h; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom=qemu-devel-bounces+patch=linaro.org@nongnu.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id n55si809560qta.8.2017.09.21.07.45.59 for (version=TLS1 cipher=AES128-SHA bits=128/128); Thu, 21 Sep 2017 07:45:59 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=QvLNHe/h; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom=qemu-devel-bounces+patch=linaro.org@nongnu.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:54069 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dv2jl-0002Ym-GY for patch@linaro.org; Thu, 21 Sep 2017 10:45:57 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53331) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dv2jX-0002YI-Ob for qemu-devel@nongnu.org; Thu, 21 Sep 2017 10:45:45 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dv2jT-0003XC-Hi for qemu-devel@nongnu.org; Thu, 21 Sep 2017 10:45:43 -0400 Received: from mail-wm0-x22d.google.com ([2a00:1450:400c:c09::22d]:45482) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dv2jT-0003WZ-B4 for qemu-devel@nongnu.org; Thu, 21 Sep 2017 10:45:39 -0400 Received: by mail-wm0-x22d.google.com with SMTP id q124so2569742wmb.0 for ; Thu, 21 Sep 2017 07:45:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=1CdUT8HMJmkAR7b7iMMG+la/pcLaXdcXqx70gOJy2D8=; b=QvLNHe/hGJO6F4NYaubp5Qrr13aN8oo72PuBxwE5NCThnAyvVWdPH6I0UD7QOnmayG uE8DHZpudpRjUyEKZO2Cvrzkvr+/tpA84grJ7THMrwwDEmVr6vajHQVSPv1KwLDkh9Db VGqn3nTUasz319J6c3sQcR6AkwNA7gJAqQEGM= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=1CdUT8HMJmkAR7b7iMMG+la/pcLaXdcXqx70gOJy2D8=; b=pW/FN7aIz6RQdKKj/nPz+rFcdHEFJOFn9M7UGe1l1nZhwhoxsRFPFaa23871pDFAJ3 Iue4HMd314Z8taf814WA25aS1izObgofXFdIqFkpgCPlysNysqVTfiBcyE7nHNnCQfbt InbOy/jzoN5yz1SYrY0N/bNdEjCXXpPwE4I8GZM5avLlhLliJ8pKYSV98Vi+0aJHXw77 pN82EtmLS9QQCk1XpanwNMzhe0pczSSgVUu2AsrLBewny9rymIfsVHm1/pZrOTYVKR9a RjciMiQncv5pWXx+GvEF6i3SS1Opy+7zEln17IgXmbhCkuQsN/bu+ZZmPIlQvrT/GjVf edQw== X-Gm-Message-State: AHPjjUjXr9TowBTxjsikCt8G66FIGjZ8Tp5HurO5KO6GziTaJyT/q5T1 g3r+6gWgKgU089n7IDn7JW59CA== X-Google-Smtp-Source: AOwi7QAWjDCzfyTVD1c6BmBbb9UDOYSq9xbjNl1U6dADeBEXSYHN238YtVliQLU8CXFpFmt51yB6Fg== X-Received: by 10.28.236.212 with SMTP id h81mr1230626wmi.42.1506005137867; Thu, 21 Sep 2017 07:45:37 -0700 (PDT) Received: from zen.linaro.local ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id 137sm2269348wmp.7.2017.09.21.07.45.36 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 21 Sep 2017 07:45:36 -0700 (PDT) Received: from zen.linaroharston (localhost [127.0.0.1]) by zen.linaro.local (Postfix) with ESMTP id 5DBDB3E05A7; Thu, 21 Sep 2017 15:45:40 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Date: Thu, 21 Sep 2017 15:45:34 +0100 Message-Id: <20170921144534.22674-1-alex.bennee@linaro.org> X-Mailer: git-send-email 2.14.1 MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:400c:c09::22d Subject: [Qemu-devel] [RFC PATCH] monitor: add info translate (HACK!) X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Crosthwaite , "Dr. David Alan Gilbert" , Markus Armbruster , Paolo Bonzini , =?utf-8?q?Alex_Benn=C3=A9e?= , Richard Henderson Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Currently investigating translation involves enabling debugging flags and potentially generating large amounts of debug information and sifting through it. -dfilter helps but often you want to investigate what's going on in a live system. This patch is an attempt at that. It adds a "info translate" command which is passed an address. It then grabs the tb_lock, fiddles with the loglevel flags and then does a un-cached translation, spewing the output on stderr. There are a number of open questions: - there is currently no safe way to re-direct log output - messing with internal qemu_loglevel flags is *eewww* - we don't deal with translation flags We could deal with the inherent racey behaviour by pushing the output to a async safe function. It also might make sense to be able to introspect what TB's exist in a given range and then use that information to re-run the translation live. Signed-off-by: Alex Bennée --- accel/tcg/translate-all.c | 23 +++++++++++++++++++++++ hmp-commands-info.hx | 16 ++++++++++++++++ include/exec/cpu-all.h | 2 ++ monitor.c | 15 +++++++++++++++ 4 files changed, 56 insertions(+) -- 2.14.1 diff --git a/accel/tcg/translate-all.c b/accel/tcg/translate-all.c index 2d1ed06065..09fc698bb0 100644 --- a/accel/tcg/translate-all.c +++ b/accel/tcg/translate-all.c @@ -1947,6 +1947,29 @@ void dump_opcount_info(FILE *f, fprintf_function cpu_fprintf) tcg_dump_op_count(f, cpu_fprintf); } +/* + * To dump translation info we temporally translate the given address + * while tweak the log flags to dump information. + * + * It might make more sense to push this off to an safe async function + * to do this in a less racey manner. + */ + +void dump_translate_info(FILE *f, fprintf_function cpu_fprintf, + target_ulong addr, int flags) +{ + int old_flags = qemu_loglevel; + + /* grab the lock, currently that means no other translation */ + tb_lock(); + qemu_loglevel = flags; + + tb_gen_code(first_cpu, addr, 0, 0, CF_NOCACHE | CF_IGNORE_ICOUNT); + + qemu_loglevel = old_flags; + tb_unlock(); +} + #else /* CONFIG_USER_ONLY */ void cpu_interrupt(CPUState *cpu, int mask) diff --git a/hmp-commands-info.hx b/hmp-commands-info.hx index 1c6772597d..68f64aff7e 100644 --- a/hmp-commands-info.hx +++ b/hmp-commands-info.hx @@ -292,6 +292,22 @@ STEXI @item info opcount @findex opcount Show dynamic compiler opcode counters +ETEXI + +#if defined(CONFIG_TCG) + { + .name = "translate", + .args_type = "addr:l,flags:s", + .params = "addr [flags]", + .help = "show translation info", + .cmd = hmp_info_translate, + }, +#endif + +STEXI +@item info translate +@findex translate +Show dynamic compiler info. ETEXI { diff --git a/include/exec/cpu-all.h b/include/exec/cpu-all.h index ffe43d5654..456fd03f44 100644 --- a/include/exec/cpu-all.h +++ b/include/exec/cpu-all.h @@ -340,6 +340,8 @@ CPUArchState *cpu_copy(CPUArchState *env); void dump_exec_info(FILE *f, fprintf_function cpu_fprintf); void dump_opcount_info(FILE *f, fprintf_function cpu_fprintf); +void dump_translate_info(FILE *f, fprintf_function cpu_fprintf, + target_ulong addr, int flags); #endif /* !CONFIG_USER_ONLY */ int cpu_memory_rw_debug(CPUState *cpu, target_ulong addr, diff --git a/monitor.c b/monitor.c index cd831eaab4..f0cdd54cfb 100644 --- a/monitor.c +++ b/monitor.c @@ -1115,6 +1115,21 @@ static void hmp_info_opcount(Monitor *mon, const QDict *qdict) { dump_opcount_info((FILE *)mon, monitor_fprintf); } + +static void hmp_info_translate(Monitor *mon, const QDict *qdict) +{ + target_ulong addr; + + if (!tcg_enabled()) { + error_report("translation information is only available with accel=tcg"); + return; + } + + addr = qdict_get_int(qdict, "addr"); + + dump_translate_info((FILE *)mon, monitor_fprintf, addr, + CPU_LOG_TB_IN_ASM | CPU_LOG_TB_OUT_ASM | CPU_LOG_TB_OP); +} #endif static void hmp_info_history(Monitor *mon, const QDict *qdict)