From patchwork Mon Sep 14 00:01:45 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 249745 Delivered-To: patch@linaro.org Received: by 2002:a92:5ad1:0:0:0:0:0 with SMTP id b78csp1199163ilg; Sun, 13 Sep 2020 17:02:17 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy9oXe1EipQIi5cMdw4bQvEsr796OUaGQXrWdsXaP/EGiAN9RmxASAJ+2Qbi26jTXaew7Jc X-Received: by 2002:a25:c00e:: with SMTP id c14mr10244514ybf.262.1600041737114; Sun, 13 Sep 2020 17:02:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1600041737; cv=none; d=google.com; s=arc-20160816; b=zU46XWChDD3GrzslBQPfIjbXY4zkG/+U39J9OoOFN+nqYRh+VanDEheoyZttatlBAS 5QI0LElruE2n7bGslTAS3De4x01m52WAZB0VF7ybFhx4ZPlEaUWk8FPbD4d81lM/I7HO I6MlFeyDRyeIvwfxSk9Tj02VtvhWUnO52K2H2o/lF5LxKrkTrN+BADed20ad/tCuXgPY uxnRiw1+lN+1LKDMPImCPmHy7LpJyMKCeQWc5LiSocNcFrkNF24U/2XYaIuW2SSpuImD VFbH7LcOzfYlSrnJz7hA5EDxGJgYk/R83C46L+PTpYMlZVVWhQL2OSIznWYwoWkt46ME tVqw== 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:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=O5tftEr4wcy+EcfeUo13CTd2wMJ9pZ9l7p7m81TmeOA=; b=CpFJTm01Rn4582CaVPkoeirQ8X49x4McH2LeCaO6z+UCKt+4Ee7kwdLWwQJLxlVvOG 7U1RxyclF+uugvdGGN/YPtGGidqDOU8d2gyBEbSNMUr4Ssi2p4PJrUwU1b1qahVBEAI1 OS9xKUUrMb/tIfgqQ2mHWzsLNo41mz1AQ/dMqIElpE2yGHxETatxNDGso6uiYufz1PMR 2Bdn0PpBQFjqzLxPTRCOYGIFq0u1eYWGQEyRXNG78SBM6qlL5DTJ40mih7eS2ESNBo/x OmvhIBCGEKb0Igh0DlsONJDfstDXaZACgq8c5z9yaGttiFBpYUypWYNpuqKPlS4APrrW 4XRg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=a4jx8KNt; 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=fail (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 i67si9874470ybi.220.2020.09.13.17.02.17 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sun, 13 Sep 2020 17:02: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=fail header.i=@linaro.org header.s=google header.b=a4jx8KNt; 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=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:56536 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kHbwm-0002bk-HQ for patch@linaro.org; Sun, 13 Sep 2020 20:02:16 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43530) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kHbwZ-0002Y9-35 for qemu-devel@nongnu.org; Sun, 13 Sep 2020 20:02:03 -0400 Received: from mail-pg1-x530.google.com ([2607:f8b0:4864:20::530]:36394) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kHbwW-0004Bl-QZ for qemu-devel@nongnu.org; Sun, 13 Sep 2020 20:02:02 -0400 Received: by mail-pg1-x530.google.com with SMTP id f2so8059297pgd.3 for ; Sun, 13 Sep 2020 17:02:00 -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:in-reply-to:references :mime-version:content-transfer-encoding; bh=O5tftEr4wcy+EcfeUo13CTd2wMJ9pZ9l7p7m81TmeOA=; b=a4jx8KNtbPTtoVGXQhAkL61kwJ/+cCW577j+6XALCPm4TfyPNmIBEnol5PMTaZ/8Fe TBCkRYp52Et7uZNMb/Bm4YCsRvnUDJgfD78RWC0EyYp/CozSZH7uYpfH97CKwYgu9RAM 5sg6D1QP95zzbYLiyEcnHccaT7WVtsNp6RJfHjNqQaikPiJNfIL0lCB0l4Ri22zWXIrK Q31naU314Lga14bIcpsfuLyHEQYmwmRfPNhQBzZ0JCz7ODt/N+exrKFNhsMABgE46YY7 reE8DetEZz0C2ZHmPyerlgoj+draJxhljEJmm6VEkcmTbIaaPQ+mrXqVXUT1s+6oeSNV EDIw== 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=O5tftEr4wcy+EcfeUo13CTd2wMJ9pZ9l7p7m81TmeOA=; b=s9EwnesMr6UFoMFQ3afWx52d/HeFz0oBC4WG8wkq64CBXuNgMtA6mASUfOucb//4iZ fpTwp1OPGgWm+CvJOciSxvXYKNPiQgaJ53X1f2ph8ne1+9/XIIxtzCyWf1g9BHJhjg76 xw06b8FYeIAF4YaMvTZqcUTTmWgNINA4hjD+gVUFxH/Q5ryGUpeOiSn7TwnWjP7XlvL4 SX/Yt84xZN6iNtQbH3KUXbnfjR4zDpDC+ACwir/+eXvareDrXICkfErsVWuCil0r22i4 6MT9M11qiz1eah9p2GHB8JTyCkID0CDtyz94rtyZ2GT3aDsCgXu+JtX4TNfwLMERGvtv dXVw== X-Gm-Message-State: AOAM531ZO+FpsgaALISTT9ceecvhADVtJ9uYjesjwCq9xY6/FT/Cr8Vs Cz/FM5URLZPPau+wyzSPhjU4MHEu4pWT7g== X-Received: by 2002:a17:902:8605:b029:d0:cbe1:e773 with SMTP id f5-20020a1709028605b02900d0cbe1e773mr12522978plo.26.1600041719103; Sun, 13 Sep 2020 17:01:59 -0700 (PDT) Received: from localhost.localdomain ([71.212.141.89]) by smtp.gmail.com with ESMTPSA id 31sm6538252pgs.59.2020.09.13.17.01.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 13 Sep 2020 17:01:58 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH 03/11] disas: Move host asm annotations to tb_gen_code Date: Sun, 13 Sep 2020 17:01:45 -0700 Message-Id: <20200914000153.1725632-4-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200914000153.1725632-1-richard.henderson@linaro.org> References: <20200914000153.1725632-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::530; envelope-from=richard.henderson@linaro.org; helo=mail-pg1-x530.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. 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.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: luoyonggang@gmail.com, alex.bennee@linaro.org, thuth@redhat.com Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Instead of creating GStrings and passing them into log_disas, just print the annotations directly in tb_gen_code. Fix the annotations for the slow paths of the TB, after the part implementing the final guest instruction. Signed-off-by: Richard Henderson --- include/disas/disas.h | 2 +- include/exec/log.h | 4 ++-- accel/tcg/translate-all.c | 24 +++++++++++++++--------- disas.c | 29 +++++++++-------------------- tcg/tcg.c | 4 ++-- 5 files changed, 29 insertions(+), 34 deletions(-) -- 2.25.1 diff --git a/include/disas/disas.h b/include/disas/disas.h index 1b6e035e32..36c33f6f19 100644 --- a/include/disas/disas.h +++ b/include/disas/disas.h @@ -7,7 +7,7 @@ #include "cpu.h" /* Disassemble this for me please... (debugging). */ -void disas(FILE *out, void *code, unsigned long size, const char *note); +void disas(FILE *out, void *code, unsigned long size); void target_disas(FILE *out, CPUState *cpu, target_ulong code, target_ulong size); diff --git a/include/exec/log.h b/include/exec/log.h index 3ed797c1c8..fcc7b9e00b 100644 --- a/include/exec/log.h +++ b/include/exec/log.h @@ -56,13 +56,13 @@ static inline void log_target_disas(CPUState *cpu, target_ulong start, rcu_read_unlock(); } -static inline void log_disas(void *code, unsigned long size, const char *note) +static inline void log_disas(void *code, unsigned long size) { QemuLogFile *logfile; rcu_read_lock(); logfile = atomic_rcu_read(&qemu_logfile); if (logfile) { - disas(logfile->fd, code, size, note); + disas(logfile->fd, code, size); } rcu_read_unlock(); } diff --git a/accel/tcg/translate-all.c b/accel/tcg/translate-all.c index 2d83013633..2874104a6a 100644 --- a/accel/tcg/translate-all.c +++ b/accel/tcg/translate-all.c @@ -1815,10 +1815,9 @@ TranslationBlock *tb_gen_code(CPUState *cpu, qemu_log_in_addr_range(tb->pc)) { FILE *logfile = qemu_log_lock(); int code_size, data_size = 0; - g_autoptr(GString) note = g_string_new("[tb header & initial instruction]"); - size_t chunk_start = 0; + size_t chunk_start; int insn = 0; - qemu_log("OUT: [size=%d]\n", gen_code_size); + if (tcg_ctx->data_gen_ptr) { code_size = tcg_ctx->data_gen_ptr - tb->tc.ptr; data_size = gen_code_size - code_size; @@ -1827,26 +1826,33 @@ TranslationBlock *tb_gen_code(CPUState *cpu, } /* Dump header and the first instruction */ + qemu_log("OUT: [size=%d]\n", gen_code_size); + qemu_log(" -- guest addr 0x" TARGET_FMT_lx " + tb prologue\n", + tcg_ctx->gen_insn_data[insn][0]); chunk_start = tcg_ctx->gen_insn_end_off[insn]; - log_disas(tb->tc.ptr, chunk_start, note->str); + log_disas(tb->tc.ptr, chunk_start); /* * Dump each instruction chunk, wrapping up empty chunks into * the next instruction. The whole array is offset so the * first entry is the beginning of the 2nd instruction. */ - while (insn <= tb->icount && chunk_start < code_size) { + while (insn < tb->icount) { size_t chunk_end = tcg_ctx->gen_insn_end_off[insn]; if (chunk_end > chunk_start) { - g_string_printf(note, "[guest addr: " TARGET_FMT_lx "]", - tcg_ctx->gen_insn_data[insn][0]); - log_disas(tb->tc.ptr + chunk_start, chunk_end - chunk_start, - note->str); + qemu_log(" -- guest addr 0x" TARGET_FMT_lx "\n", + tcg_ctx->gen_insn_data[insn][0]); + log_disas(tb->tc.ptr + chunk_start, chunk_end - chunk_start); chunk_start = chunk_end; } insn++; } + if (chunk_start < code_size) { + qemu_log(" -- tb slow paths + alignment\n"); + log_disas(tb->tc.ptr + chunk_start, code_size - chunk_start); + } + /* Finally dump any data we may have after the block */ if (data_size) { int i; diff --git a/disas.c b/disas.c index c1397d3933..a4304e8137 100644 --- a/disas.c +++ b/disas.c @@ -262,8 +262,7 @@ static void cap_dump_insn_units(disassemble_info *info, cs_insn *insn, } } -static void cap_dump_insn(disassemble_info *info, cs_insn *insn, - const char *note) +static void cap_dump_insn(disassemble_info *info, cs_insn *insn) { fprintf_function print = info->fprintf_func; int i, n, split; @@ -284,11 +283,7 @@ static void cap_dump_insn(disassemble_info *info, cs_insn *insn, } /* Print the actual instruction. */ - print(info->stream, " %-8s %s", insn->mnemonic, insn->op_str); - if (note) { - print(info->stream, "\t\t%s", note); - } - print(info->stream, "\n"); + print(info->stream, " %-8s %s\n", insn->mnemonic, insn->op_str); /* Dump any remaining part of the insn on subsequent lines. */ for (i = split; i < n; i += split) { @@ -320,7 +315,7 @@ static bool cap_disas_target(disassemble_info *info, uint64_t pc, size_t size) size -= tsize; while (cs_disasm_iter(handle, &cbuf, &csize, &pc, insn)) { - cap_dump_insn(info, insn, NULL); + cap_dump_insn(info, insn); } /* If the target memory is not consumed, go back for more... */ @@ -349,8 +344,7 @@ static bool cap_disas_target(disassemble_info *info, uint64_t pc, size_t size) } /* Disassemble SIZE bytes at CODE for the host. */ -static bool cap_disas_host(disassemble_info *info, void *code, size_t size, - const char *note) +static bool cap_disas_host(disassemble_info *info, void *code, size_t size) { csh handle; const uint8_t *cbuf; @@ -366,8 +360,7 @@ static bool cap_disas_host(disassemble_info *info, void *code, size_t size, pc = (uintptr_t)code; while (cs_disasm_iter(handle, &cbuf, &size, &pc, insn)) { - cap_dump_insn(info, insn, note); - note = NULL; + cap_dump_insn(info, insn); } if (size != 0) { (*info->fprintf_func)(info->stream, @@ -411,7 +404,7 @@ static bool cap_disas_monitor(disassemble_info *info, uint64_t pc, int count) csize += tsize; if (cs_disasm_iter(handle, &cbuf, &csize, &pc, insn)) { - cap_dump_insn(info, insn, NULL); + cap_dump_insn(info, insn); if (--count <= 0) { break; } @@ -425,7 +418,7 @@ static bool cap_disas_monitor(disassemble_info *info, uint64_t pc, int count) #endif /* !CONFIG_USER_ONLY */ #else # define cap_disas_target(i, p, s) false -# define cap_disas_host(i, p, s, n) false +# define cap_disas_host(i, p, s) false # define cap_disas_monitor(i, p, c) false # define cap_disas_plugin(i, p, c) false #endif /* CONFIG_CAPSTONE */ @@ -595,7 +588,7 @@ char *plugin_disas(CPUState *cpu, uint64_t addr, size_t size) } /* Disassemble this for me please... (debugging). */ -void disas(FILE *out, void *code, unsigned long size, const char *note) +void disas(FILE *out, void *code, unsigned long size) { uintptr_t pc; int count; @@ -673,7 +666,7 @@ void disas(FILE *out, void *code, unsigned long size, const char *note) print_insn = print_insn_hppa; #endif - if (s.info.cap_arch >= 0 && cap_disas_host(&s.info, code, size, note)) { + if (s.info.cap_arch >= 0 && cap_disas_host(&s.info, code, size)) { return; } @@ -683,10 +676,6 @@ void disas(FILE *out, void *code, unsigned long size, const char *note) for (pc = (uintptr_t)code; size > 0; pc += count, size -= count) { fprintf(out, "0x%08" PRIxPTR ": ", pc); count = print_insn(pc, &s.info); - if (note) { - fprintf(out, "\t\t%s", note); - note = NULL; - } fprintf(out, "\n"); if (count < 0) { break; diff --git a/tcg/tcg.c b/tcg/tcg.c index 62f299e36e..9a111ce604 100644 --- a/tcg/tcg.c +++ b/tcg/tcg.c @@ -1101,7 +1101,7 @@ void tcg_prologue_init(TCGContext *s) size_t data_size = prologue_size - code_size; size_t i; - log_disas(buf0, code_size, NULL); + log_disas(buf0, code_size); for (i = 0; i < data_size; i += sizeof(tcg_target_ulong)) { if (sizeof(tcg_target_ulong) == 8) { @@ -1115,7 +1115,7 @@ void tcg_prologue_init(TCGContext *s) } } } else { - log_disas(buf0, prologue_size, NULL); + log_disas(buf0, prologue_size); } qemu_log("\n"); qemu_log_flush();