From patchwork Tue Oct 3 18:30:43 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 728806 Delivered-To: patch@linaro.org Received: by 2002:a5d:60c8:0:b0:31d:da82:a3b4 with SMTP id x8csp2285575wrt; Tue, 3 Oct 2023 11:32:42 -0700 (PDT) X-Google-Smtp-Source: AGHT+IH/w6aXv87pb574bAAGYOYOu8my+0bXVhLBE+uvKgkupBsttHSJUBqYAxalTxr7qV6ibA2p X-Received: by 2002:a05:6214:460b:b0:647:2b16:d154 with SMTP id oq11-20020a056214460b00b006472b16d154mr200018qvb.1.1696357962444; Tue, 03 Oct 2023 11:32:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696357962; cv=none; d=google.com; s=arc-20160816; b=bHo/FJHC4O8Gh0mQs5Yqdt1/7i64j2O96fPMZ64NadVGlki5TbPDEzwQJnW8SM4F6j Qtkw/zVv/eFWHuqGxCrXxkpSVummxFyda+qncuZ8mJdiA4R/U4vRUhKM/zyHEWzNh3Ih Lrd7QmCquLVujRNvJ+pyGQVTG9XImIdlXVqqNVDPs1fp3dEnTDXI/H9eqfKTgP7Nt1FN PE7HOM3kbpqkxq7wmTeipxy3c2iY4PEFkru1lRIcfZiYKgCnHIG6BpAiIAY6prXQdld5 1s1YMudEiG1EsjLl4XBwDvGeVAgLlP2kStnJ7USM/7EDNDGAFroPB+95FvJTtZsrPLly nECw== 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=ecP8STEStoBluKX5+obvIdHtKNkY82tQDQM5NMPt78I=; fh=JxWBtSZstwhZxj1nqbhkYnE1e7Ds6gYyoAtro8tkvc0=; b=Bb9Wn0Q6/mk50h2L41EkJq6uNjcs8g9YwaGQTvVYK/3BT2QHSuNGI8TEjbigSwL1ak O1zUBC7PRDAfHEAyecdXbFPwk8VFutK+sW6p+9Bam1k6Q8jITwRNLu06n4iHN0Ms4/Fg F188BfpohZV2uwQj0IE6qnUTuQp2iJaOChUA2R/2m19iSxIoAYpymfBszpOfcxQaemZW pEB638GvLDjzC36zp2mnAgeAelTUZVJf+9xp/4yMWz1x9gWuoENSGozD6QBqsETQ/j64 Gq2WBXgyGPO/yp+oZMYFisCykURv5Z6NCbfGFUkePcS1MENp1fsrWKOR0HiSZ7wZPthD OxiA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=KW1NRT+V; 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 i13-20020a0cf10d000000b0065af5b26469si742164qvl.386.2023.10.03.11.32.42 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 03 Oct 2023 11:32:42 -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=KW1NRT+V; 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 1qnkAp-00081h-Qp; Tue, 03 Oct 2023 14:31:11 -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 1qnkAm-0007xM-72 for qemu-devel@nongnu.org; Tue, 03 Oct 2023 14:31:08 -0400 Received: from mail-pl1-x62b.google.com ([2607:f8b0:4864:20::62b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qnkAh-0001e9-4h for qemu-devel@nongnu.org; Tue, 03 Oct 2023 14:31:07 -0400 Received: by mail-pl1-x62b.google.com with SMTP id d9443c01a7336-1c77449a6daso10944525ad.0 for ; Tue, 03 Oct 2023 11:31:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1696357861; x=1696962661; 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=ecP8STEStoBluKX5+obvIdHtKNkY82tQDQM5NMPt78I=; b=KW1NRT+Vrj7AyajfUuC6QqLBCWkR0VSZlncdq36Um3xAo4QzPdwvZttBWCTbQ/p/k2 u3q9C0ThNovEW3PXE78jSruMxn/Z0PImFC78RtVp5hpEq/Y0A5BKySX+IobQTlSCeQn2 QR+Oqo9x6odOP1ArOH5sSSj8XxAX5wBDpc1+f0rRxqgi3xtHY1c0pSpyd/XJSkT12ad9 /+xxD8VLwMsaSr6LMk6/43t9ObI75N6Zmf7LwmesulCgDGP5hXkqzHI7wS6uorS6KCBW F3rMrgAKA78qrBEz7AVoFXJQCVcBiiJoC9P1TLX5BzW6K4pezTg5gPp4jAISf5lJMYl9 G0yQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696357861; x=1696962661; 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=ecP8STEStoBluKX5+obvIdHtKNkY82tQDQM5NMPt78I=; b=fqyNULuRu7mXLddMx5lPQhf2hEMbiAF8qvTfHS3xCHQQjoxVPLXWAWRKEboZ7hlvbl LZfTuX+jWA4n7gHzswaEDQ4epaDFU1IERl7xTkhZvDt2Ov9nOaaahbZuuRUJDM8f/4m1 8E6vMUvmpkZO9l54ergxVixD5GNZ6hAnv6ePls40fWhgXOjw+tkgVDTizeSnvAcxLgZn KWYHyqduaRpYw81OPRExvg8e42mA/L3TS6HBLFM+7+Pjut8Dk90v1x3ff5tosQbWeyEf Sh1/LlbLrMGCCjKGBMQwTMw2FFnXBlgiN9MChDe/s+j+Ugbn03mmFC4ggj2pudEZHLfT x8Vw== X-Gm-Message-State: AOJu0YybJXezpgyJ8otUzJeqgblJkC5W/LIHYV8iMZuv08YWuG4jEp5L GD9qo1UowSWvS84AgKNhHIhX9V5wBB6cyYnVpUM= X-Received: by 2002:a17:902:da84:b0:1c1:ed61:e058 with SMTP id j4-20020a170902da8400b001c1ed61e058mr467242plx.16.1696357860611; Tue, 03 Oct 2023 11:31:00 -0700 (PDT) Received: from stoup.. ([71.212.149.95]) by smtp.gmail.com with ESMTPSA id g7-20020a170902934700b001b7cbc5871csm1920432plp.53.2023.10.03.11.31.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Oct 2023 11:31:00 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: fei2.wu@intel.com Subject: [PATCH v17 01/16] accel/tcg: Move HMP info jit and info opcount code Date: Tue, 3 Oct 2023 11:30:43 -0700 Message-Id: <20231003183058.1639121-2-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231003183058.1639121-1-richard.henderson@linaro.org> References: <20231003183058.1639121-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::62b; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x62b.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 Move all of it into accel/tcg/monitor.c. This puts everything about tcg that is only used by the monitor in the same place. Signed-off-by: Richard Henderson Reviewed-by: Philippe Mathieu-Daudé Tested-by: Philippe Mathieu-Daudé Reviewed-by: Alex Bennée --- accel/tcg/internal-common.h | 2 - include/exec/cputlb.h | 1 - include/tcg/tcg.h | 3 - accel/tcg/cputlb.c | 15 ---- accel/tcg/monitor.c | 154 ++++++++++++++++++++++++++++++++++++ accel/tcg/translate-all.c | 127 ----------------------------- tcg/tcg.c | 10 --- 7 files changed, 154 insertions(+), 158 deletions(-) diff --git a/accel/tcg/internal-common.h b/accel/tcg/internal-common.h index 3b2277e6e9..edefd0dcb7 100644 --- a/accel/tcg/internal-common.h +++ b/accel/tcg/internal-common.h @@ -14,8 +14,6 @@ extern int64_t max_delay; extern int64_t max_advance; -void dump_exec_info(GString *buf); - /* * Return true if CS is not running in parallel with other cpus, either * because there are no other cpus or we are within an exclusive context. diff --git a/include/exec/cputlb.h b/include/exec/cputlb.h index 19b16e58f8..6da1462c4f 100644 --- a/include/exec/cputlb.h +++ b/include/exec/cputlb.h @@ -26,6 +26,5 @@ /* cputlb.c */ void tlb_protect_code(ram_addr_t ram_addr); void tlb_unprotect_code(ram_addr_t ram_addr); -void tlb_flush_counts(size_t *full, size_t *part, size_t *elide); #endif #endif diff --git a/include/tcg/tcg.h b/include/tcg/tcg.h index 680ff00722..82b4625773 100644 --- a/include/tcg/tcg.h +++ b/include/tcg/tcg.h @@ -842,9 +842,6 @@ static inline TCGv_ptr tcg_temp_new_ptr(void) return temp_tcgv_ptr(t); } -void tcg_dump_info(GString *buf); -void tcg_dump_op_count(GString *buf); - #define TCG_CT_CONST 1 /* any constant of register size */ typedef struct TCGArgConstraint { diff --git a/accel/tcg/cputlb.c b/accel/tcg/cputlb.c index b8c5e345b8..13986820fe 100644 --- a/accel/tcg/cputlb.c +++ b/accel/tcg/cputlb.c @@ -321,21 +321,6 @@ static void flush_all_helper(CPUState *src, run_on_cpu_func fn, } } -void tlb_flush_counts(size_t *pfull, size_t *ppart, size_t *pelide) -{ - CPUState *cpu; - size_t full = 0, part = 0, elide = 0; - - CPU_FOREACH(cpu) { - full += qatomic_read(&cpu->neg.tlb.c.full_flush_count); - part += qatomic_read(&cpu->neg.tlb.c.part_flush_count); - elide += qatomic_read(&cpu->neg.tlb.c.elide_flush_count); - } - *pfull = full; - *ppart = part; - *pelide = elide; -} - static void tlb_flush_by_mmuidx_async_work(CPUState *cpu, run_on_cpu_data data) { uint16_t asked = data.host_int; diff --git a/accel/tcg/monitor.c b/accel/tcg/monitor.c index caf1189e0b..093efe9714 100644 --- a/accel/tcg/monitor.c +++ b/accel/tcg/monitor.c @@ -8,6 +8,7 @@ #include "qemu/osdep.h" #include "qemu/accel.h" +#include "qemu/qht.h" #include "qapi/error.h" #include "qapi/type-helpers.h" #include "qapi/qapi-commands-machine.h" @@ -17,6 +18,7 @@ #include "sysemu/tcg.h" #include "tcg/tcg.h" #include "internal-common.h" +#include "tb-context.h" static void dump_drift_info(GString *buf) @@ -50,6 +52,153 @@ static void dump_accel_info(GString *buf) one_insn_per_tb ? "on" : "off"); } +static void print_qht_statistics(struct qht_stats hst, GString *buf) +{ + uint32_t hgram_opts; + size_t hgram_bins; + char *hgram; + + if (!hst.head_buckets) { + return; + } + g_string_append_printf(buf, "TB hash buckets %zu/%zu " + "(%0.2f%% head buckets used)\n", + hst.used_head_buckets, hst.head_buckets, + (double)hst.used_head_buckets / + hst.head_buckets * 100); + + hgram_opts = QDIST_PR_BORDER | QDIST_PR_LABELS; + hgram_opts |= QDIST_PR_100X | QDIST_PR_PERCENT; + if (qdist_xmax(&hst.occupancy) - qdist_xmin(&hst.occupancy) == 1) { + hgram_opts |= QDIST_PR_NODECIMAL; + } + hgram = qdist_pr(&hst.occupancy, 10, hgram_opts); + g_string_append_printf(buf, "TB hash occupancy %0.2f%% avg chain occ. " + "Histogram: %s\n", + qdist_avg(&hst.occupancy) * 100, hgram); + g_free(hgram); + + hgram_opts = QDIST_PR_BORDER | QDIST_PR_LABELS; + hgram_bins = qdist_xmax(&hst.chain) - qdist_xmin(&hst.chain); + if (hgram_bins > 10) { + hgram_bins = 10; + } else { + hgram_bins = 0; + hgram_opts |= QDIST_PR_NODECIMAL | QDIST_PR_NOBINRANGE; + } + hgram = qdist_pr(&hst.chain, hgram_bins, hgram_opts); + g_string_append_printf(buf, "TB hash avg chain %0.3f buckets. " + "Histogram: %s\n", + qdist_avg(&hst.chain), hgram); + g_free(hgram); +} + +struct tb_tree_stats { + size_t nb_tbs; + size_t host_size; + size_t target_size; + size_t max_target_size; + size_t direct_jmp_count; + size_t direct_jmp2_count; + size_t cross_page; +}; + +static gboolean tb_tree_stats_iter(gpointer key, gpointer value, gpointer data) +{ + const TranslationBlock *tb = value; + struct tb_tree_stats *tst = data; + + tst->nb_tbs++; + tst->host_size += tb->tc.size; + tst->target_size += tb->size; + if (tb->size > tst->max_target_size) { + tst->max_target_size = tb->size; + } + if (tb->page_addr[1] != -1) { + tst->cross_page++; + } + if (tb->jmp_reset_offset[0] != TB_JMP_OFFSET_INVALID) { + tst->direct_jmp_count++; + if (tb->jmp_reset_offset[1] != TB_JMP_OFFSET_INVALID) { + tst->direct_jmp2_count++; + } + } + return false; +} + +static void tlb_flush_counts(size_t *pfull, size_t *ppart, size_t *pelide) +{ + CPUState *cpu; + size_t full = 0, part = 0, elide = 0; + + CPU_FOREACH(cpu) { + full += qatomic_read(&cpu->neg.tlb.c.full_flush_count); + part += qatomic_read(&cpu->neg.tlb.c.part_flush_count); + elide += qatomic_read(&cpu->neg.tlb.c.elide_flush_count); + } + *pfull = full; + *ppart = part; + *pelide = elide; +} + +static void tcg_dump_info(GString *buf) +{ + g_string_append_printf(buf, "[TCG profiler not compiled]\n"); +} + +static void dump_exec_info(GString *buf) +{ + struct tb_tree_stats tst = {}; + struct qht_stats hst; + size_t nb_tbs, flush_full, flush_part, flush_elide; + + tcg_tb_foreach(tb_tree_stats_iter, &tst); + nb_tbs = tst.nb_tbs; + /* XXX: avoid using doubles ? */ + g_string_append_printf(buf, "Translation buffer state:\n"); + /* + * Report total code size including the padding and TB structs; + * otherwise users might think "-accel tcg,tb-size" is not honoured. + * For avg host size we use the precise numbers from tb_tree_stats though. + */ + g_string_append_printf(buf, "gen code size %zu/%zu\n", + tcg_code_size(), tcg_code_capacity()); + g_string_append_printf(buf, "TB count %zu\n", nb_tbs); + g_string_append_printf(buf, "TB avg target size %zu max=%zu bytes\n", + nb_tbs ? tst.target_size / nb_tbs : 0, + tst.max_target_size); + g_string_append_printf(buf, "TB avg host size %zu bytes " + "(expansion ratio: %0.1f)\n", + nb_tbs ? tst.host_size / nb_tbs : 0, + tst.target_size ? + (double)tst.host_size / tst.target_size : 0); + g_string_append_printf(buf, "cross page TB count %zu (%zu%%)\n", + tst.cross_page, + nb_tbs ? (tst.cross_page * 100) / nb_tbs : 0); + g_string_append_printf(buf, "direct jump count %zu (%zu%%) " + "(2 jumps=%zu %zu%%)\n", + tst.direct_jmp_count, + nb_tbs ? (tst.direct_jmp_count * 100) / nb_tbs : 0, + tst.direct_jmp2_count, + nb_tbs ? (tst.direct_jmp2_count * 100) / nb_tbs : 0); + + qht_statistics_init(&tb_ctx.htable, &hst); + print_qht_statistics(hst, buf); + qht_statistics_destroy(&hst); + + g_string_append_printf(buf, "\nStatistics:\n"); + g_string_append_printf(buf, "TB flush count %u\n", + qatomic_read(&tb_ctx.tb_flush_count)); + g_string_append_printf(buf, "TB invalidate count %u\n", + qatomic_read(&tb_ctx.tb_phys_invalidate_count)); + + tlb_flush_counts(&flush_full, &flush_part, &flush_elide); + g_string_append_printf(buf, "TLB full flushes %zu\n", flush_full); + g_string_append_printf(buf, "TLB partial flushes %zu\n", flush_part); + g_string_append_printf(buf, "TLB elided flushes %zu\n", flush_elide); + tcg_dump_info(buf); +} + HumanReadableText *qmp_x_query_jit(Error **errp) { g_autoptr(GString) buf = g_string_new(""); @@ -66,6 +215,11 @@ HumanReadableText *qmp_x_query_jit(Error **errp) return human_readable_text_from_str(buf); } +static void tcg_dump_op_count(GString *buf) +{ + g_string_append_printf(buf, "[TCG profiler not compiled]\n"); +} + HumanReadableText *qmp_x_query_opcount(Error **errp) { g_autoptr(GString) buf = g_string_new(""); diff --git a/accel/tcg/translate-all.c b/accel/tcg/translate-all.c index 8cb6ad3511..e579b0891d 100644 --- a/accel/tcg/translate-all.c +++ b/accel/tcg/translate-all.c @@ -645,133 +645,6 @@ void cpu_io_recompile(CPUState *cpu, uintptr_t retaddr) cpu_loop_exit_noexc(cpu); } -static void print_qht_statistics(struct qht_stats hst, GString *buf) -{ - uint32_t hgram_opts; - size_t hgram_bins; - char *hgram; - - if (!hst.head_buckets) { - return; - } - g_string_append_printf(buf, "TB hash buckets %zu/%zu " - "(%0.2f%% head buckets used)\n", - hst.used_head_buckets, hst.head_buckets, - (double)hst.used_head_buckets / - hst.head_buckets * 100); - - hgram_opts = QDIST_PR_BORDER | QDIST_PR_LABELS; - hgram_opts |= QDIST_PR_100X | QDIST_PR_PERCENT; - if (qdist_xmax(&hst.occupancy) - qdist_xmin(&hst.occupancy) == 1) { - hgram_opts |= QDIST_PR_NODECIMAL; - } - hgram = qdist_pr(&hst.occupancy, 10, hgram_opts); - g_string_append_printf(buf, "TB hash occupancy %0.2f%% avg chain occ. " - "Histogram: %s\n", - qdist_avg(&hst.occupancy) * 100, hgram); - g_free(hgram); - - hgram_opts = QDIST_PR_BORDER | QDIST_PR_LABELS; - hgram_bins = qdist_xmax(&hst.chain) - qdist_xmin(&hst.chain); - if (hgram_bins > 10) { - hgram_bins = 10; - } else { - hgram_bins = 0; - hgram_opts |= QDIST_PR_NODECIMAL | QDIST_PR_NOBINRANGE; - } - hgram = qdist_pr(&hst.chain, hgram_bins, hgram_opts); - g_string_append_printf(buf, "TB hash avg chain %0.3f buckets. " - "Histogram: %s\n", - qdist_avg(&hst.chain), hgram); - g_free(hgram); -} - -struct tb_tree_stats { - size_t nb_tbs; - size_t host_size; - size_t target_size; - size_t max_target_size; - size_t direct_jmp_count; - size_t direct_jmp2_count; - size_t cross_page; -}; - -static gboolean tb_tree_stats_iter(gpointer key, gpointer value, gpointer data) -{ - const TranslationBlock *tb = value; - struct tb_tree_stats *tst = data; - - tst->nb_tbs++; - tst->host_size += tb->tc.size; - tst->target_size += tb->size; - if (tb->size > tst->max_target_size) { - tst->max_target_size = tb->size; - } - if (tb_page_addr1(tb) != -1) { - tst->cross_page++; - } - if (tb->jmp_reset_offset[0] != TB_JMP_OFFSET_INVALID) { - tst->direct_jmp_count++; - if (tb->jmp_reset_offset[1] != TB_JMP_OFFSET_INVALID) { - tst->direct_jmp2_count++; - } - } - return false; -} - -void dump_exec_info(GString *buf) -{ - struct tb_tree_stats tst = {}; - struct qht_stats hst; - size_t nb_tbs, flush_full, flush_part, flush_elide; - - tcg_tb_foreach(tb_tree_stats_iter, &tst); - nb_tbs = tst.nb_tbs; - /* XXX: avoid using doubles ? */ - g_string_append_printf(buf, "Translation buffer state:\n"); - /* - * Report total code size including the padding and TB structs; - * otherwise users might think "-accel tcg,tb-size" is not honoured. - * For avg host size we use the precise numbers from tb_tree_stats though. - */ - g_string_append_printf(buf, "gen code size %zu/%zu\n", - tcg_code_size(), tcg_code_capacity()); - g_string_append_printf(buf, "TB count %zu\n", nb_tbs); - g_string_append_printf(buf, "TB avg target size %zu max=%zu bytes\n", - nb_tbs ? tst.target_size / nb_tbs : 0, - tst.max_target_size); - g_string_append_printf(buf, "TB avg host size %zu bytes " - "(expansion ratio: %0.1f)\n", - nb_tbs ? tst.host_size / nb_tbs : 0, - tst.target_size ? - (double)tst.host_size / tst.target_size : 0); - g_string_append_printf(buf, "cross page TB count %zu (%zu%%)\n", - tst.cross_page, - nb_tbs ? (tst.cross_page * 100) / nb_tbs : 0); - g_string_append_printf(buf, "direct jump count %zu (%zu%%) " - "(2 jumps=%zu %zu%%)\n", - tst.direct_jmp_count, - nb_tbs ? (tst.direct_jmp_count * 100) / nb_tbs : 0, - tst.direct_jmp2_count, - nb_tbs ? (tst.direct_jmp2_count * 100) / nb_tbs : 0); - - qht_statistics_init(&tb_ctx.htable, &hst); - print_qht_statistics(hst, buf); - qht_statistics_destroy(&hst); - - g_string_append_printf(buf, "\nStatistics:\n"); - g_string_append_printf(buf, "TB flush count %u\n", - qatomic_read(&tb_ctx.tb_flush_count)); - g_string_append_printf(buf, "TB invalidate count %u\n", - qatomic_read(&tb_ctx.tb_phys_invalidate_count)); - - tlb_flush_counts(&flush_full, &flush_part, &flush_elide); - g_string_append_printf(buf, "TLB full flushes %zu\n", flush_full); - g_string_append_printf(buf, "TLB partial flushes %zu\n", flush_part); - g_string_append_printf(buf, "TLB elided flushes %zu\n", flush_elide); - tcg_dump_info(buf); -} - #else /* CONFIG_USER_ONLY */ void cpu_interrupt(CPUState *cpu, int mask) diff --git a/tcg/tcg.c b/tcg/tcg.c index f664cf1484..71c25f1974 100644 --- a/tcg/tcg.c +++ b/tcg/tcg.c @@ -5919,11 +5919,6 @@ static void tcg_out_st_helper_args(TCGContext *s, const TCGLabelQemuLdst *ldst, tcg_out_helper_load_common_args(s, ldst, parm, info, next_arg); } -void tcg_dump_op_count(GString *buf) -{ - g_string_append_printf(buf, "[TCG profiler not compiled]\n"); -} - int tcg_gen_code(TCGContext *s, TranslationBlock *tb, uint64_t pc_start) { int i, start_words, num_insns; @@ -6120,11 +6115,6 @@ int tcg_gen_code(TCGContext *s, TranslationBlock *tb, uint64_t pc_start) return tcg_current_code_size(s); } -void tcg_dump_info(GString *buf) -{ - g_string_append_printf(buf, "[TCG profiler not compiled]\n"); -} - #ifdef ELF_HOST_MACHINE /* In order to use this feature, the backend needs to do three things: From patchwork Tue Oct 3 18:30:44 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 728804 Delivered-To: patch@linaro.org Received: by 2002:a5d:60c8:0:b0:31d:da82:a3b4 with SMTP id x8csp2285446wrt; Tue, 3 Oct 2023 11:32:19 -0700 (PDT) X-Google-Smtp-Source: AGHT+IF0t9aVk+QTPbr7Fd8Vy1oqpp1Op6/r1wmFAR3otaTlXvfxgCcwFvuNdfZTwbHaGtNrc4Ln X-Received: by 2002:a05:6214:3383:b0:63d:2567:f255 with SMTP id mv3-20020a056214338300b0063d2567f255mr135086qvb.24.1696357939279; Tue, 03 Oct 2023 11:32:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696357939; cv=none; d=google.com; s=arc-20160816; b=SY/KjZZJhs7xQCmFkrr4uZcTzr89l9rUnFocXObcJbgJekmHTOUVYXfvxkedy+ZqvB OOeLldj8vQy+n6luzIJ3j8s2ijI2aFCqxC8AsyvTBGyc7XouwHHp8zz2K7qGSN3jQlor MUQY0cH8wYow/vS+HJiXMlnaVQv2+Affn7Rrtv5oRZJD4czDQuz/b0CrQPJ8MCs+fEoH xdIgSVygdqjQNw7PeK7m/vEVEMQyJrV3oS8TV1QrXC7nzATb7IAkui5p6Y0fpbAd6wJ3 +fuBT/h3gKfQVMe0xmq7Vc22WSOV1NvUYgWSyHQrtXr6s28j3RUISVuwMHaXKUIp4sCE VONA== 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=MeJK52obcjftsHra4OOU5xIwq9R14g84P4JBuSuP22k=; fh=JxWBtSZstwhZxj1nqbhkYnE1e7Ds6gYyoAtro8tkvc0=; b=RtuYAbmvES257ljIUbqWQceibk0CQU9wdhSbUXHQEtulp/B6Dy6fYlPT81CABSSrYp A0rRMw86ejPFrYX1ZMAeOf/CqDBnMQW5gEpT2SHFgpHftTOxmd5nvfuPIKhU9H2TqmiF ENiwrGyBrE4zXc5w4XGRMVWNxN9Cx6bs7wxEAWSNydEtvZwQSlyyeaJPPDDMIsDeg5s1 hucvlF8Jv55+EstI3lbcLe9cUW3DEHGn1+B2GCSnGWjUxWAd+BMoYKNfIbCPXjY0gcmG 5OSZaAK1FEz7JOfBTe4xq9eBQvrLTrSGl0HUipx0VzWh3i/8hOj6oExwy5U+9sBRiu7t 0XDQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=th4i0MyO; 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 t18-20020a0ce2d2000000b006563889d9e8si754387qvl.428.2023.10.03.11.32.19 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 03 Oct 2023 11:32:19 -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=th4i0MyO; 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 1qnkAp-00081V-Qz; Tue, 03 Oct 2023 14:31:11 -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 1qnkAm-0007xH-1h for qemu-devel@nongnu.org; Tue, 03 Oct 2023 14:31:08 -0400 Received: from mail-pf1-x429.google.com ([2607:f8b0:4864:20::429]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qnkAg-0001eE-Qd for qemu-devel@nongnu.org; Tue, 03 Oct 2023 14:31:07 -0400 Received: by mail-pf1-x429.google.com with SMTP id d2e1a72fcca58-694ed84c981so978479b3a.3 for ; Tue, 03 Oct 2023 11:31:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1696357861; x=1696962661; 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=MeJK52obcjftsHra4OOU5xIwq9R14g84P4JBuSuP22k=; b=th4i0MyO/UplOqIOh+M7Q9kvnw1MY1IlMVsa0/O/pZmDaYaWyk/VB9cZ786PfQ3MYF JEghl1v/ux1OsvIRtE9LvFspAqhxWPs8SCCIKbvkh8bIhEdgDE7F62kbCfTlrJnI4QmF 5DavCrnh5aQ9PIHjePDvE88ZD3DpGyyec65tXAUAnBb+MoCS+5a9gIZKV8pQQQ3PzdBZ ZgzUWQITN7TPB9lPz0e44InJLz6DqcvuhOyGeuvRg8QbNXCBFU3QhaaEetU5PrWW79v+ S7OleuENFhdkPJ9WvSY5M9bMLECsYgKyfHHaJ8qJjnOgAi8rhmXMT0vtxMNcQC++lGDB xtDQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696357861; x=1696962661; 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=MeJK52obcjftsHra4OOU5xIwq9R14g84P4JBuSuP22k=; b=tFL6AamKS5yFofkqVjXUZ220XE+672hseb2V0PstUxW3+BTOh85S+U9FSocb8lV6Dk CNqkFvQXSZvZ3mCWwqCL+q1NkhUJnX89NuMt92CmcgPpPZA92NuKeBM01dZBRoN96lav nTJ3vSG9Z0UHSWOstxVB7tYKMNBZ0iaUCOnTH2GifQ3GviI+TUU9rIVbuzPwI0cXhSsi M9oENogY3REbRXF0j+YTbx1hOhgK0NPOatrQw9qpw+jU9J8yW3V3IBUk8LTD3i272pHs hGh7K3ommScIDyx/OS5gA/IcsMnbFon3Wc/RABYsgJQNLF2dUZlJGRX/CgoA1qauYgo3 KdLQ== X-Gm-Message-State: AOJu0YxF5B/6RBn8QCytSOoqoKE0q5ENNwfazooAk7bO1d0dkbuyspff l9CCLggvmMPM/tfrpFU/f9Zo/PpgW+xzKt+mrtI= X-Received: by 2002:a05:6a20:12d6:b0:15d:bc0f:9b64 with SMTP id v22-20020a056a2012d600b0015dbc0f9b64mr298632pzg.45.1696357861378; Tue, 03 Oct 2023 11:31:01 -0700 (PDT) Received: from stoup.. ([71.212.149.95]) by smtp.gmail.com with ESMTPSA id g7-20020a170902934700b001b7cbc5871csm1920432plp.53.2023.10.03.11.31.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Oct 2023 11:31:01 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: fei2.wu@intel.com Subject: [PATCH v17 02/16] tcg: Record orig_nb_ops TCGContext Date: Tue, 3 Oct 2023 11:30:44 -0700 Message-Id: <20231003183058.1639121-3-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231003183058.1639121-1-richard.henderson@linaro.org> References: <20231003183058.1639121-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::429; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x429.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 Remember the value of nb_ops before optimization. To be copied into TBStatistics when desired. Signed-off-by: Richard Henderson Reviewed-by: Alex Bennée --- include/tcg/tcg.h | 3 +++ tcg/tcg.c | 2 ++ 2 files changed, 5 insertions(+) diff --git a/include/tcg/tcg.h b/include/tcg/tcg.h index 82b4625773..e49574b7c7 100644 --- a/include/tcg/tcg.h +++ b/include/tcg/tcg.h @@ -564,6 +564,9 @@ struct TCGContext { uint16_t gen_insn_end_off[TCG_MAX_INSNS]; uint64_t *gen_insn_data; + /* Used by TBStatistics */ + int orig_nb_ops; + /* Exit to translator on overflow. */ sigjmp_buf jmp_trans; }; diff --git a/tcg/tcg.c b/tcg/tcg.c index 71c25f1974..e90b0a0c69 100644 --- a/tcg/tcg.c +++ b/tcg/tcg.c @@ -5924,6 +5924,8 @@ int tcg_gen_code(TCGContext *s, TranslationBlock *tb, uint64_t pc_start) int i, start_words, num_insns; TCGOp *op; + s->orig_nb_ops = s->nb_ops; + if (unlikely(qemu_loglevel_mask(CPU_LOG_TB_OP) && qemu_log_in_addr_range(pc_start))) { FILE *logfile = qemu_log_trylock(); From patchwork Tue Oct 3 18:30:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 728811 Delivered-To: patch@linaro.org Received: by 2002:a5d:60c8:0:b0:31d:da82:a3b4 with SMTP id x8csp2285808wrt; Tue, 3 Oct 2023 11:33:16 -0700 (PDT) X-Google-Smtp-Source: AGHT+IH+7iCeQ2dF4fg4EOyEChzx0Kq8TnCrIjXi3+AUiPprAr9ltdieOuzkggCtCblNGXnbkGQI X-Received: by 2002:a0c:b250:0:b0:658:a108:574c with SMTP id k16-20020a0cb250000000b00658a108574cmr179767qve.3.1696357996341; Tue, 03 Oct 2023 11:33:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696357996; cv=none; d=google.com; s=arc-20160816; b=SOdct70Sk0OUzPOsoxjFanziSkEanmcYme6R+w5atBQHcXjluqW9OMpY45Dtf/rhlL kOg7ZCyt1cRGNtzBAk8YeZZEwJ7ll3OP37cfgrmd9rGeHriRuiwt4UVI5B6UAGgaTXWJ eYCCE3dlN9M/QmF43YRuc2y6LK96yGzyJj/Bvas5T6B57uHI8dJMjEP5WtE09h0Eq2ae LqvYg0yPViIJhefmbPJMuYXeAUIcucxHLoe34h0xQrsQyoQOxMnsyBq4WCPKY3zFGGCs kJkPtwpp4rQuM9JIOcs5nuJXW91lCzwoyMGGCax7oVFxZGLHs5UN38k+8xsm3QggEO2H ekZg== 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=6qLsUwKkMfH3SdTbz6XhvzJrYIqkyqmV5ZdXlf3DNHM=; fh=JxWBtSZstwhZxj1nqbhkYnE1e7Ds6gYyoAtro8tkvc0=; b=YnGP1f4vIdrWvveAT19Psjrxs72wqG/dPvyo9GSIz096L6Iczbn/LbB7PVOSoybmwU Bh2X0oJyHyyJqo76HBIaifToQHEzm0uXYiB2a2L7PqwA7llqICPZZ9JqtGHSAgOX40uQ fYPaEA5NKrwGOhNpk4cAabOdOpLRmNZGFQ2uwlpnyxPScOqaIPil3QdFNrYs41Evp+nx hkKaYVJk5WEUwJgY/orezkoP9R0i03hAmxx0gZby8oKtQod7YnnQU2ZUPH0HlQ45wYul +vilpE7xarnsgACbObliJSgTHhp/yxtTbNdn2h6JSTXu6MON0YQRYCg9tQ4wvEQJs7in TbsQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=VTkaiEeO; 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 u21-20020a0cb415000000b0064f3f53bca5si758085qve.119.2023.10.03.11.33.16 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 03 Oct 2023 11:33:16 -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=VTkaiEeO; 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 1qnkAq-00083m-M2; Tue, 03 Oct 2023 14:31:12 -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 1qnkAm-0007xX-G9 for qemu-devel@nongnu.org; Tue, 03 Oct 2023 14:31:08 -0400 Received: from mail-pl1-x631.google.com ([2607:f8b0:4864:20::631]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qnkAi-0001eL-PX for qemu-devel@nongnu.org; Tue, 03 Oct 2023 14:31:08 -0400 Received: by mail-pl1-x631.google.com with SMTP id d9443c01a7336-1c3f97f2239so10079505ad.0 for ; Tue, 03 Oct 2023 11:31:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1696357862; x=1696962662; 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=6qLsUwKkMfH3SdTbz6XhvzJrYIqkyqmV5ZdXlf3DNHM=; b=VTkaiEeOe+GiTMMXkxsJdljGfWgqtaUnipVYLl/jvQZrwTZKJ0fPQumwwcg5//XTT/ XUvXcvXfZHfYlU6mSPV+xEolDX28j1OAHFo+IcIkUxAjs8t3o3OBQpJZQOq6Hl4FSbpA MS2Q88yTGBWhseh7xyxHklydDYtmEJdV6W+kO2aXD8wanzJBdMbgHyt5Rtym4IT4DxXJ ZayaY3ikOqbJcLCBXsla5itW5ZytYf3hIclWFsDorA0qtpZH2n6KS6SaIUKGo95Vmv7w OgX9Gd28Gk3LkXxcZ77jwyR8CO69vmPj2t/gx/MEkK3lDDO6wmFF26P/roGt36NGbJGi 2aKg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696357862; x=1696962662; 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=6qLsUwKkMfH3SdTbz6XhvzJrYIqkyqmV5ZdXlf3DNHM=; b=L43IZGOd8mDODBPfb5MG1vNyWU/wSnbU/RgBXS63nVFdPRnxSnhLX/svOcy1XoeqWi mpfxPmXZDsOad1n/iWIseELPuOWpxmrLadouj7sGIdoLw7GKn+2+ZXUI7OM6Qwk7ZMtx 3Xw+6fuxEMxiQ/FuNSX2neJIb+z9+krfU34lEl5N8APQh7Fu2h/xjXABo4cZrI4ET+2y Q6wGE6F6qDqTwjVBjpkG4x5nM/k+htvhT9NU2wqCU/OMe4POohVeYsyvpy5vvewOd+Sk 9OrADfImTHCTGBGfzpA7cMKIFofTG68az74O+vI5+18lfZ3Ku2cgZleAdSA29RLeUxwb xHlw== X-Gm-Message-State: AOJu0YyDwnnLvWHqiXXa8HV4L295P6bVPrUcKuZjgHY5zKrLKU/MtPPf k4aBFOUG5coCzC63/jscw1jZyxNO+wtUvKuPB4M= X-Received: by 2002:a17:902:cec4:b0:1bb:ce4a:5893 with SMTP id d4-20020a170902cec400b001bbce4a5893mr433536plg.30.1696357862370; Tue, 03 Oct 2023 11:31:02 -0700 (PDT) Received: from stoup.. ([71.212.149.95]) by smtp.gmail.com with ESMTPSA id g7-20020a170902934700b001b7cbc5871csm1920432plp.53.2023.10.03.11.31.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Oct 2023 11:31:01 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: fei2.wu@intel.com Subject: [PATCH v17 03/16] tcg: Record nb_deleted_ops in TCGContext Date: Tue, 3 Oct 2023 11:30:45 -0700 Message-Id: <20231003183058.1639121-4-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231003183058.1639121-1-richard.henderson@linaro.org> References: <20231003183058.1639121-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::631; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x631.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 Record the number of ops that are removed during optimization. To be copied into TBStatistics when desired. Signed-off-by: Richard Henderson Reviewed-by: Alex Bennée --- include/tcg/tcg.h | 1 + tcg/tcg.c | 2 ++ 2 files changed, 3 insertions(+) diff --git a/include/tcg/tcg.h b/include/tcg/tcg.h index e49574b7c7..d60349878f 100644 --- a/include/tcg/tcg.h +++ b/include/tcg/tcg.h @@ -566,6 +566,7 @@ struct TCGContext { /* Used by TBStatistics */ int orig_nb_ops; + int nb_deleted_ops; /* Exit to translator on overflow. */ sigjmp_buf jmp_trans; diff --git a/tcg/tcg.c b/tcg/tcg.c index e90b0a0c69..60be2f429c 100644 --- a/tcg/tcg.c +++ b/tcg/tcg.c @@ -1494,6 +1494,7 @@ void tcg_func_start(TCGContext *s) s->nb_ops = 0; s->nb_labels = 0; + s->nb_deleted_ops = 0; s->current_frame_offset = s->frame_start; #ifdef CONFIG_DEBUG_TCG @@ -3049,6 +3050,7 @@ void tcg_op_remove(TCGContext *s, TCGOp *op) QTAILQ_REMOVE(&s->ops, op, link); QTAILQ_INSERT_TAIL(&s->free_ops, op, link); s->nb_ops--; + s->nb_deleted_ops++; } void tcg_remove_ops_after(TCGOp *op) From patchwork Tue Oct 3 18:30:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 728815 Delivered-To: patch@linaro.org Received: by 2002:a5d:60c8:0:b0:31d:da82:a3b4 with SMTP id x8csp2285988wrt; Tue, 3 Oct 2023 11:33:45 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHk0fzQ/w1Agp6Nzurd9iSLIBuotI1eauuFHv//Zudpt51yUIb9GWnDBgmBre1LNJ75M2bT X-Received: by 2002:a25:2412:0:b0:d80:9ef:928d with SMTP id k18-20020a252412000000b00d8009ef928dmr70789ybk.38.1696358025218; Tue, 03 Oct 2023 11:33:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696358025; cv=none; d=google.com; s=arc-20160816; b=kNN64tj8CjOu0b810tRI88Ns5gxqvakZCHm7Qb3T2BIpwr5hfMk5MhvZFcWulRGV2W FH+FoXmJIx7TGU5XWJWGyH9qYT2+5fcsoGLYeplIiJp4ilbQnsp4EAGRRB2iORDKIS4Q D/bKrtkQtUirsPuHsjihv519GlMVaTpNofXaPLb3febXJsiQfKFm7FIQ1Ok2jDsDxj1W uLEv3Sak+gzjJxD6TLYTkMl0D+DU6Ljbt0/XCf3BKAF52bFkfgQkAhoGIgNPdf4J+j8K mhuKgBVwNFnoX8vnpI9WdhCsUqL5B0DHon/ElZda2UljF+tdnPfENqsrbQTDMWRN0WWG NAMQ== 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=GGIr9qTLkG6qDPefA3k2dSggXrteDRo4H56lowl7XH4=; fh=JxWBtSZstwhZxj1nqbhkYnE1e7Ds6gYyoAtro8tkvc0=; b=cHob4yT7zxhABavx6sWVygPTjGpS9ocM5LKSkWvafT8ueeYuPMKX6/Xmow2PDyM7iU TkYMTwTY3tMaC8CoL6cGbokABNtT0lEu+M5kY0aXwx7ANJH3x/X0LsvgXoln1ESFZNCC AP9+RjVn2vpGLwbehO94GE+ezaZGJs5LvLh2wG8dv3Qaz2GD9KCI4AHFDEf9MqUR02qn wrTV50a9xbl5p2dOCLnY35/OhFW9dstB7JoKceQWj3ffjXeyfLGKzsFOTqClnUMrZycB lTyxNkzG0BcE4qC8zVTrKwIwd+dQsswo1aGDg3WPbKDx76WbydrPxjbt7JpQAZ4MZ1a6 OV5g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=cAf6gcKS; 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 rg3-20020a05620a8ec300b0077596c392f6si740266qkn.630.2023.10.03.11.33.45 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 03 Oct 2023 11:33:45 -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=cAf6gcKS; 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 1qnkAs-00084T-49; Tue, 03 Oct 2023 14:31:14 -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 1qnkAn-00081C-Qf for qemu-devel@nongnu.org; Tue, 03 Oct 2023 14:31:11 -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 1qnkAj-0001eZ-RZ for qemu-devel@nongnu.org; Tue, 03 Oct 2023 14:31:09 -0400 Received: by mail-pl1-x62e.google.com with SMTP id d9443c01a7336-1c60a514f3aso9876375ad.3 for ; Tue, 03 Oct 2023 11:31:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1696357863; x=1696962663; 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=GGIr9qTLkG6qDPefA3k2dSggXrteDRo4H56lowl7XH4=; b=cAf6gcKSGWuWIKayNzbLU6u0lc4dEsDQajDn0v6rIl0Q6grdpU+HJxMWAzB1fBeJBH kV04nWoyxyxUMixScDkEVUfi2D08x/6Of8INTnWbxEoK+FHnN9mIXxHyANFXkoBye/tq 0TKkq3xZ16IpzK9dj+21uERk9vLuqddIHI6npMP00Qat8oU4jhxc6bp38szqhHPiSYQz UuJuVOK3gZTg7aojNiyAjd66VpOsUujXv+VkN5xSQRCrxFSZIykKUWoQdIRt4Hbofrhm sxREoj2gvSEMmazp2qZyWXm0MPl9llsg2JEXumQyawfbTdPfa9CpFqtX0ewkp0RziLGq EiKA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696357863; x=1696962663; 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=GGIr9qTLkG6qDPefA3k2dSggXrteDRo4H56lowl7XH4=; b=c3rWhZh5BzW4xKxHN8NecUNrcgPmcDiEPErpIa5z4vk39r1szou7QARRccpHpAGtVy CI75Vc8C2NlcNrVzAHb3yQ4jfmoUq8yG/L30Sg5pBIsFrnNwUrxC98ZYhJ3yYSpCdL3C qp8ilgS76VQS7xljWZVYNq/79HYrgFS/qI6/+GYpHYyXN0nu1rwxIv6LdR2KLMRjm3qk dBebWzTlKadMfLcDX2pi13+YQ+k2suvC8hgxjgNW1gcXaY3s9l+BNtjqS3geGF7FLb0X 6GWHrQklWd70yAD59WHQ5lS/TlzBi06Zne5mFIGmsuqFItqSxlATw/Zlry+r5rbYyQm6 z5rg== X-Gm-Message-State: AOJu0Yz8X5DAz8wXQY1j4rC9atcA+6+wDqNMjdo02jsxHGBNx+/p8Z5j 8IehM5D0wagSbvdeHNMnykMH39e5B1swokPhtP4= X-Received: by 2002:a17:902:dacd:b0:1bb:2020:be0d with SMTP id q13-20020a170902dacd00b001bb2020be0dmr506455plx.14.1696357863437; Tue, 03 Oct 2023 11:31:03 -0700 (PDT) Received: from stoup.. ([71.212.149.95]) by smtp.gmail.com with ESMTPSA id g7-20020a170902934700b001b7cbc5871csm1920432plp.53.2023.10.03.11.31.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Oct 2023 11:31:02 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: fei2.wu@intel.com Subject: [PATCH v17 04/16] tcg: Record nb_spills in TCGContext Date: Tue, 3 Oct 2023 11:30:46 -0700 Message-Id: <20231003183058.1639121-5-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231003183058.1639121-1-richard.henderson@linaro.org> References: <20231003183058.1639121-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::62e; envelope-from=richard.henderson@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 Record the number of times a temporary is forced into memory and the store would not have been required if there an infinite number of call-saved cpu registers available. This excludes stores that are required by semantics to return computed values to their home slot in ENV, i.e. NEED_SYNC_ARG. To be copied into TBStatistics when desired. Signed-off-by: Richard Henderson Reviewed-by: Alex Bennée --- include/tcg/tcg.h | 1 + tcg/tcg.c | 36 +++++++++++++++++++++++------------- 2 files changed, 24 insertions(+), 13 deletions(-) diff --git a/include/tcg/tcg.h b/include/tcg/tcg.h index d60349878f..c2b1a2e187 100644 --- a/include/tcg/tcg.h +++ b/include/tcg/tcg.h @@ -567,6 +567,7 @@ struct TCGContext { /* Used by TBStatistics */ int orig_nb_ops; int nb_deleted_ops; + int nb_spills; /* Exit to translator on overflow. */ sigjmp_buf jmp_trans; diff --git a/tcg/tcg.c b/tcg/tcg.c index 60be2f429c..471e5eaad9 100644 --- a/tcg/tcg.c +++ b/tcg/tcg.c @@ -1495,6 +1495,7 @@ void tcg_func_start(TCGContext *s) s->nb_ops = 0; s->nb_labels = 0; s->nb_deleted_ops = 0; + s->nb_spills = 0; s->current_frame_offset = s->frame_start; #ifdef CONFIG_DEBUG_TCG @@ -4118,8 +4119,11 @@ static inline void temp_dead(TCGContext *s, TCGTemp *ts) is non-zero, subsequently release the temporary; if it is positive, the temp is dead; if it is negative, the temp is free. */ static void temp_sync(TCGContext *s, TCGTemp *ts, TCGRegSet allocated_regs, - TCGRegSet preferred_regs, int free_or_dead) + TCGRegSet preferred_regs, int free_or_dead, + bool account_spill) { + bool did_spill = false; + if (!temp_readonly(ts) && !ts->mem_coherent) { if (!ts->mem_allocated) { temp_allocate_frame(s, ts); @@ -4132,6 +4136,7 @@ static void temp_sync(TCGContext *s, TCGTemp *ts, TCGRegSet allocated_regs, if (free_or_dead && tcg_out_sti(s, ts->type, ts->val, ts->mem_base->reg, ts->mem_offset)) { + did_spill = account_spill; break; } temp_load(s, ts, tcg_target_available_regs[ts->type], @@ -4139,6 +4144,7 @@ static void temp_sync(TCGContext *s, TCGTemp *ts, TCGRegSet allocated_regs, /* fallthrough */ case TEMP_VAL_REG: + did_spill = account_spill; tcg_out_st(s, ts->type, ts->reg, ts->mem_base->reg, ts->mem_offset); break; @@ -4155,6 +4161,9 @@ static void temp_sync(TCGContext *s, TCGTemp *ts, TCGRegSet allocated_regs, if (free_or_dead) { temp_free_or_dead(s, ts, free_or_dead); } + if (did_spill) { + s->nb_spills += 1; + } } /* free register 'reg' by spilling the corresponding temporary if necessary */ @@ -4162,7 +4171,7 @@ static void tcg_reg_free(TCGContext *s, TCGReg reg, TCGRegSet allocated_regs) { TCGTemp *ts = s->reg_to_temp[reg]; if (ts != NULL) { - temp_sync(s, ts, allocated_regs, 0, -1); + temp_sync(s, ts, allocated_regs, 0, -1, true); } } @@ -4442,7 +4451,8 @@ static void tcg_reg_alloc_do_movi(TCGContext *s, TCGTemp *ots, ots->val = val; ots->mem_coherent = 0; if (NEED_SYNC_ARG(0)) { - temp_sync(s, ots, s->reserved_regs, preferred_regs, IS_DEAD_ARG(0)); + temp_sync(s, ots, s->reserved_regs, preferred_regs, + IS_DEAD_ARG(0), false); } else if (IS_DEAD_ARG(0)) { temp_dead(s, ots); } @@ -4544,7 +4554,7 @@ static void tcg_reg_alloc_mov(TCGContext *s, const TCGOp *op) ots->mem_coherent = 0; if (NEED_SYNC_ARG(0)) { - temp_sync(s, ots, allocated_regs, 0, 0); + temp_sync(s, ots, allocated_regs, 0, 0, false); } } @@ -4621,7 +4631,7 @@ static void tcg_reg_alloc_dup(TCGContext *s, const TCGOp *op) break; } /* Sync the temp back to its slot and load from there. */ - temp_sync(s, its, s->reserved_regs, 0, 0); + temp_sync(s, its, s->reserved_regs, 0, 0, true); } /* fall through */ @@ -4652,7 +4662,7 @@ static void tcg_reg_alloc_dup(TCGContext *s, const TCGOp *op) temp_dead(s, its); } if (NEED_SYNC_ARG(0)) { - temp_sync(s, ots, s->reserved_regs, 0, 0); + temp_sync(s, ots, s->reserved_regs, 0, 0, false); } if (IS_DEAD_ARG(0)) { temp_dead(s, ots); @@ -4870,7 +4880,7 @@ static void tcg_reg_alloc_op(TCGContext *s, const TCGOp *op) * Cross register class move not supported. Sync the * temp back to its slot and load from there. */ - temp_sync(s, ts, i_allocated_regs, 0, 0); + temp_sync(s, ts, i_allocated_regs, 0, 0, true); tcg_out_ld(s, ts->type, reg, ts->mem_base->reg, ts->mem_offset); } @@ -5019,7 +5029,7 @@ static void tcg_reg_alloc_op(TCGContext *s, const TCGOp *op) tcg_debug_assert(!temp_readonly(ts)); if (NEED_SYNC_ARG(i)) { - temp_sync(s, ts, o_allocated_regs, 0, IS_DEAD_ARG(i)); + temp_sync(s, ts, o_allocated_regs, 0, IS_DEAD_ARG(i), false); } else if (IS_DEAD_ARG(i)) { temp_dead(s, ts); } @@ -5086,8 +5096,8 @@ static bool tcg_reg_alloc_dup2(TCGContext *s, const TCGOp *op) itsl == itsh + (HOST_BIG_ENDIAN ? 1 : -1)) { TCGTemp *its = itsl - HOST_BIG_ENDIAN; - temp_sync(s, its + 0, s->reserved_regs, 0, 0); - temp_sync(s, its + 1, s->reserved_regs, 0, 0); + temp_sync(s, its + 0, s->reserved_regs, 0, 0, true); + temp_sync(s, its + 1, s->reserved_regs, 0, 0, true); if (tcg_out_dupm_vec(s, vtype, MO_64, ots->reg, its->mem_base->reg, its->mem_offset)) { @@ -5107,7 +5117,7 @@ static bool tcg_reg_alloc_dup2(TCGContext *s, const TCGOp *op) temp_dead(s, itsh); } if (NEED_SYNC_ARG(0)) { - temp_sync(s, ots, s->reserved_regs, 0, IS_DEAD_ARG(0)); + temp_sync(s, ots, s->reserved_regs, 0, IS_DEAD_ARG(0), false); } else if (IS_DEAD_ARG(0)) { temp_dead(s, ots); } @@ -5125,7 +5135,7 @@ static void load_arg_reg(TCGContext *s, TCGReg reg, TCGTemp *ts, * Cross register class move not supported. Sync the * temp back to its slot and load from there. */ - temp_sync(s, ts, allocated_regs, 0, 0); + temp_sync(s, ts, allocated_regs, 0, 0, true); tcg_out_ld(s, ts->type, reg, ts->mem_base->reg, ts->mem_offset); } @@ -5307,7 +5317,7 @@ static void tcg_reg_alloc_call(TCGContext *s, TCGOp *op) for (i = 0; i < nb_oargs; i++) { TCGTemp *ts = arg_temp(op->args[i]); if (NEED_SYNC_ARG(i)) { - temp_sync(s, ts, s->reserved_regs, 0, IS_DEAD_ARG(i)); + temp_sync(s, ts, s->reserved_regs, 0, IS_DEAD_ARG(i), false); } else if (IS_DEAD_ARG(i)) { temp_dead(s, ts); } From patchwork Tue Oct 3 18:30:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 728809 Delivered-To: patch@linaro.org Received: by 2002:a5d:60c8:0:b0:31d:da82:a3b4 with SMTP id x8csp2285717wrt; Tue, 3 Oct 2023 11:33:01 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHE+FZj/4D9dQG/PuHfe0mTi4MOBN5bSM9ST8LrNOmjsBweo6RHe6d16MPnlF2iiCd1IGGX X-Received: by 2002:a05:620a:470b:b0:76f:1742:2f6c with SMTP id bs11-20020a05620a470b00b0076f17422f6cmr388075qkb.66.1696357981077; Tue, 03 Oct 2023 11:33:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696357981; cv=none; d=google.com; s=arc-20160816; b=mrMyiVNixLQ4nUN/EKH2xPOKwmqSXqNvc9TOhJ1djO0NNC0zFn7vXAzHQD9MMuBA3v fCVUtOtPVICoXzV+MoTRIxH9HF4qlNet87T6ZDjrvD3g1Ok/+CSGKa1ulYFyLk76RmNm LfS4Y58PMbNzAk37yUscZeMnjEafeOnKnHTJkZzK4xvOdJuPbXGhEBKPyu7a317XWeol aIzWlwB58ODcCWLBhJo6PIvfXzsggkGnzGned7lCkE/v7+vuQVbBTLGpCKVQTOS3N/1H DEb/GokeAf3zsgPw/Ol/+qw85LVMWXaVA6FUmCbNDT53UcfREyNwKpDAPows0Eg4JC1i y2UA== 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=y0G1CiW3vTsjcXjVH+akh2U1DVquXavshsyj/TJNLXs=; fh=1TCam3QlFITXZC8R+eWmP65yi78iwdHBw+O/tdslAtY=; b=gCk548W3bxCL2XPH2K2FXd/nI7l0/0Oa0gpvI0gSYJqTVqplJlkEB2uxr8wLGqoJfY iJojUTM286HLczeTdi+SJasmgazJFl/2IxHCVrVdWTFnWfo8UJQjoJkG1vO96ec4iiSM y1bkybpctouzoF90j2NBHVgTY2xTnBktWiWdb4Z3fTNOKH6l0qmtKqGXYI3LHjQaIh3U 5DwSqVySlWAN80X9bO3kTxlBVfaFc4kxWPyBQVRaPaaB1KB6jPy3Ve31MXxvgAlvWwC+ btcl9GyFheD0Flgqtf5tUkU/Q6GnGaFugiZHMADE58W7xn30RIUryv2xSKrIJJT16ejA Ta6A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=qQMjje2h; 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 dx14-20020a05620a608e00b00773d32bc746si748913qkb.401.2023.10.03.11.33.00 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 03 Oct 2023 11:33:01 -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=qQMjje2h; 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 1qnkAr-00084J-Gq; Tue, 03 Oct 2023 14:31:13 -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 1qnkAp-00082b-4b for qemu-devel@nongnu.org; Tue, 03 Oct 2023 14:31:11 -0400 Received: from mail-pg1-x535.google.com ([2607:f8b0:4864:20::535]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qnkAj-0001ek-PX for qemu-devel@nongnu.org; Tue, 03 Oct 2023 14:31:09 -0400 Received: by mail-pg1-x535.google.com with SMTP id 41be03b00d2f7-5859b06509cso864164a12.2 for ; Tue, 03 Oct 2023 11:31:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1696357864; x=1696962664; 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=y0G1CiW3vTsjcXjVH+akh2U1DVquXavshsyj/TJNLXs=; b=qQMjje2hv4SfrrNt5ttn5/R8/LKV/5MTWOP2uAf3C0EBdPP+Ujy3vP6jCmOvoR5m5L 2lbsG2fN/c3h1lN22YLXeMIVyZcDe4es7GkMr2FrcR2QhwlUEf2DZ8iq57J7snRFYCv1 XTMNaOMg1Ld9LSurl8ty2s2oZumVnAqwnnpu+fIcJwl1iT442AD/htdqHZyied8o7uSj 4jkR+MS6DlM3THABgvTvce037qvC5FJyCVA4/MQgq98ByBypd7AemM9P9nq+S/0KQnhx 9mXn3h28UhR1tVdvmvdf0aQTph+HWg2ranGwizxYCsmPVc806RKlss9TkFV5XJ2Hgk1c soAA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696357864; x=1696962664; 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=y0G1CiW3vTsjcXjVH+akh2U1DVquXavshsyj/TJNLXs=; b=t0ufQSZPIF17V/iAycfC2+A0CK48xr4qkZoYhjxQyMC/eFrjgz++Q7TlacrperrNMi Rgu+WtmuWf7iRG72+hshw7PeyWk/rpmBLa+wE0f3X7FQnU0KEc3YzBOnBjSKGjtsyDnA BbvJHSeixsVXMRoIwTKZRu/fwgKGTt1nyE2wDAXG3jwBQSAhl/axdMG32L162ULf6tlA 435TwdDtYZyhYyRW7nnc5vUVYeY8HBBt4RxcvwAV70uvGJW/8uPLGoEdn/G/n1GPNacX epNRKNzeCp+N56iE2a70E/0lwc1uHMQYW0YrG7v+1H2cJiixzAOs4b2asQwDLRiSqHAo CaeA== X-Gm-Message-State: AOJu0YxLm75eH7s1LW/S+V21ElmOihLQiQQpJvUCC0cFhR/c3kau9ogB sEJjg9rKN36SNNi/lBareX/ARH+4fmmox5Cl1tQ= X-Received: by 2002:a17:902:d702:b0:1c5:f4c7:b4e4 with SMTP id w2-20020a170902d70200b001c5f4c7b4e4mr337594ply.39.1696357864406; Tue, 03 Oct 2023 11:31:04 -0700 (PDT) Received: from stoup.. ([71.212.149.95]) by smtp.gmail.com with ESMTPSA id g7-20020a170902934700b001b7cbc5871csm1920432plp.53.2023.10.03.11.31.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Oct 2023 11:31:04 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: fei2.wu@intel.com, "Vanderson M . do Rosario" Subject: [PATCH v17 05/16] accel/tcg: Add TBStatistics structure Date: Tue, 3 Oct 2023 11:30:47 -0700 Message-Id: <20231003183058.1639121-6-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231003183058.1639121-1-richard.henderson@linaro.org> References: <20231003183058.1639121-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::535; envelope-from=richard.henderson@linaro.org; helo=mail-pg1-x535.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 Add code to allocate, reset, and free the structures along with their corresponding TranslationBlocks. We do not yet collect, display, or enable the statistics. Signed-off-by: Vanderson M. do Rosario Signed-off-by: Fei Wu [rth: Significantly reorganized.] Signed-off-by: Richard Henderson Reviewed-by: Alex Bennée --- accel/tcg/tb-context.h | 2 +- include/exec/translation-block.h | 3 + include/qemu/typedefs.h | 1 + include/tcg/tb-stats.h | 132 +++++++++++++++++++++++++++++++ accel/tcg/tb-maint.c | 3 +- accel/tcg/tb-stats.c | 85 ++++++++++++++++++++ accel/tcg/translate-all.c | 19 +++++ accel/tcg/meson.build | 1 + 8 files changed, 244 insertions(+), 2 deletions(-) create mode 100644 include/tcg/tb-stats.h create mode 100644 accel/tcg/tb-stats.c diff --git a/accel/tcg/tb-context.h b/accel/tcg/tb-context.h index cac62d9749..4b1abe392b 100644 --- a/accel/tcg/tb-context.h +++ b/accel/tcg/tb-context.h @@ -29,8 +29,8 @@ typedef struct TBContext TBContext; struct TBContext { - struct qht htable; + struct qht stats; /* statistics */ unsigned tb_flush_count; diff --git a/include/exec/translation-block.h b/include/exec/translation-block.h index b785751774..4206a72600 100644 --- a/include/exec/translation-block.h +++ b/include/exec/translation-block.h @@ -141,6 +141,9 @@ struct TranslationBlock { uintptr_t jmp_list_head; uintptr_t jmp_list_next[2]; uintptr_t jmp_dest[2]; + + /* Pointer to a struct where statistics from the TB is stored */ + TBStatistics *tb_stats; }; /* The alignment given to TranslationBlock during allocation. */ diff --git a/include/qemu/typedefs.h b/include/qemu/typedefs.h index 5abdbc3874..68011da95b 100644 --- a/include/qemu/typedefs.h +++ b/include/qemu/typedefs.h @@ -131,6 +131,7 @@ typedef struct Range Range; typedef struct ReservedRegion ReservedRegion; typedef struct SHPCDevice SHPCDevice; typedef struct SSIBus SSIBus; +typedef struct TBStatistics TBStatistics; typedef struct TCGHelperInfo TCGHelperInfo; typedef struct TranslationBlock TranslationBlock; typedef struct VirtIODevice VirtIODevice; diff --git a/include/tcg/tb-stats.h b/include/tcg/tb-stats.h new file mode 100644 index 0000000000..1ec0d13eff --- /dev/null +++ b/include/tcg/tb-stats.h @@ -0,0 +1,132 @@ +/* + * QEMU System Emulator, Code Quality Monitor System + * + * Copyright (c) 2019 Vanderson M. do Rosario + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#ifndef TCG_TB_STATS_H +#define TCG_TB_STATS_H 1 + +#include "qemu/thread.h" +#include "exec/translation-block.h" + +enum { + TB_STATS_EXEC = 1u << 0, + TB_STATS_JIT = 1u << 1, + + TB_STATS_NONE = 0, + TB_STATS_ALL = TB_STATS_EXEC | TB_STATS_JIT, +}; + +extern uint32_t tb_stats_enabled; + +/** + * tb_stats_init: + * @flags: TB_STATS_* flags to enable. + * + * Initialize translation block statistics, enabling @flags. + * If @flags is 0, disable all statistics. + */ +void tb_stats_init(uint32_t flags); + +/* + * This struct stores statistics such as execution count of the + * TranslationBlocks. Each sets of TBs for a given phys_pc/pc/flags + * has its own TBStatistics which will persist over tb_flush. + * + * We include additional counters to track number of translations as + * well as variants for compile flags. + */ +struct TBStatistics { + tb_page_addr_t phys_pc; + vaddr pc; + uint32_t flags; + uint64_t flags2; + + /* Execution stats */ + struct { + unsigned long normal; + unsigned long atomic; + /* filled only when dumping x% cover set */ + double coverage; + } executions; + + /* JIT Stats - protected by lock */ + QemuMutex jit_stats_lock; + + /* Sum of all operations for all translations */ + struct { + unsigned long num_guest_inst; + unsigned long num_tcg_ops; + unsigned long num_tcg_ops_opt; + unsigned long spills; + + unsigned long temps; + unsigned long deleted_ops; + unsigned long in_len; + unsigned long out_len; + unsigned long search_out_len; + } code; + + struct { + unsigned long total; + unsigned long spanning; + } translations; + + /* + * All persistent (cached) TranslationBlocks using + * this TBStats structure. Has to be reset on a tb_flush. + */ + GPtrArray *tbs; +}; + +/** + * tb_stats_enabled: + * @tb: TranslationBlock + * @f: flag to check + * + * Return true if any stats are enabled for @tb and + * if @f is enabled globally. + */ +static inline bool tb_stats_enabled_for_tb(TranslationBlock *tb, uint32_t f) +{ + return unlikely(tb_stats_enabled & f) && tb->tb_stats; +} + +/** + * tb_stats_reset_tbs: reset the linked array of TBs + * + * Reset the list of tbs for a given array. Should be called from + * safe work during tb_flush. + */ +void tb_stats_reset_tbs(void); + +/** + * tb_stats_lookup: + * + * If any tb_stats are enabled, return a new or existing struct + * for the tuple (phys_pc, pc, flags, flags2). To be used when + * building a new TranslationBlock. + */ +TBStatistics *tb_stats_lookup(tb_page_addr_t phys_pc, vaddr pc, + uint32_t flags, uint64_t flags2); + +#endif /* TCG_TB_STATS_H */ diff --git a/accel/tcg/tb-maint.c b/accel/tcg/tb-maint.c index e678d20dc2..9025459fb1 100644 --- a/accel/tcg/tb-maint.c +++ b/accel/tcg/tb-maint.c @@ -27,6 +27,7 @@ #include "exec/translate-all.h" #include "sysemu/tcg.h" #include "tcg/tcg.h" +#include "tcg/tb-stats.h" #include "tb-hash.h" #include "tb-context.h" #include "internal-common.h" @@ -772,7 +773,7 @@ static void do_tb_flush(CPUState *cpu, run_on_cpu_data tb_flush_count) qht_reset_size(&tb_ctx.htable, CODE_GEN_HTABLE_SIZE); tb_remove_all(); - + tb_stats_reset_tbs(); tcg_region_reset_all(); /* XXX: flush processor icache at this point if cache flush is expensive */ qatomic_inc(&tb_ctx.tb_flush_count); diff --git a/accel/tcg/tb-stats.c b/accel/tcg/tb-stats.c new file mode 100644 index 0000000000..424c9a90ec --- /dev/null +++ b/accel/tcg/tb-stats.c @@ -0,0 +1,85 @@ +/* + * QEMU System Emulator, Code Quality Monitor System + * + * Copyright (c) 2019 Vanderson M. do Rosario + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#include "qemu/osdep.h" +#include "qemu/xxhash.h" +#include "tcg/tb-stats.h" +#include "tb-context.h" + +uint32_t tb_stats_enabled; + +static bool tb_stats_cmp(const void *ap, const void *bp) +{ + const TBStatistics *a = ap; + const TBStatistics *b = bp; + + return a->phys_pc == b->phys_pc && + a->pc == b->pc && + a->flags == b->flags && + a->flags2 == b->flags2; + +} + +static void tb_stats_free(void *p, uint32_t hash, void *userp) +{ + TBStatistics *s = p; + + qemu_mutex_destroy(&s->jit_stats_lock); + g_ptr_array_free(s->tbs, true); + g_free(s); +} + +void tb_stats_init(uint32_t flags) +{ + tb_stats_enabled = flags; + if (flags) { + if (!tb_ctx.stats.map) { + qht_init(&tb_ctx.stats, tb_stats_cmp, + CODE_GEN_HTABLE_SIZE, QHT_MODE_AUTO_RESIZE); + } + } else { + qht_iter(&tb_ctx.stats, tb_stats_free, NULL); + qht_destroy(&tb_ctx.stats); + } +} + +static void tb_stats_reset(void *p, uint32_t hash, void *userp) +{ + TBStatistics *s = p; + g_ptr_array_set_size(s->tbs, 0); +} + +void tb_stats_reset_tbs(void) +{ + if (tb_ctx.stats.map) { + qht_iter(&tb_ctx.stats, tb_stats_reset, NULL); + } +} + +TBStatistics *tb_stats_lookup(tb_page_addr_t phys_pc, vaddr pc, + uint32_t flags, uint64_t flags2) +{ + TBStatistics *s; + uint32_t h; + void *existing; + + s = g_new0(TBStatistics, 1); + s->phys_pc = phys_pc; + s->pc = pc; + s->flags = flags; + s->flags2 = flags2; + s->tbs = g_ptr_array_new(); + qemu_mutex_init(&s->jit_stats_lock); + + h = qemu_xxhash7(phys_pc, pc, flags2, flags); + if (!qht_insert(&tb_ctx.stats, s, h, &existing)) { + tb_stats_free(s, 0, NULL); + return existing; + } + return s; +} diff --git a/accel/tcg/translate-all.c b/accel/tcg/translate-all.c index e579b0891d..6e64ae2dbe 100644 --- a/accel/tcg/translate-all.c +++ b/accel/tcg/translate-all.c @@ -65,6 +65,7 @@ #include "internal-target.h" #include "perf.h" #include "tcg/insn-start-words.h" +#include "tcg/tb-stats.h" TBContext tb_ctx; @@ -353,6 +354,24 @@ TranslationBlock *tb_gen_code(CPUState *cpu, tcg_ctx->guest_mo = TCG_MO_ALL; #endif + /* + * Insert the TB into the corresponding stats structure, if required. + * Do this before code generation so that translator_loop can see + * the structure address. + */ + tb->tb_stats = NULL; + if (unlikely(tb_stats_enabled) && qemu_log_in_addr_range(pc)) { + TBStatistics *s = tb_stats_lookup(phys_pc, + cflags & CF_PCREL ? 0 : pc, + flags, cs_base); + if (s) { + tb->tb_stats = s; + qemu_mutex_lock(&s->jit_stats_lock); + g_ptr_array_add(s->tbs, tb); + qemu_mutex_unlock(&s->jit_stats_lock); + } + } + restart_translate: trace_translate_block(tb, pc, tb->tc.ptr); diff --git a/accel/tcg/meson.build b/accel/tcg/meson.build index 8783edd06e..34312f7a8b 100644 --- a/accel/tcg/meson.build +++ b/accel/tcg/meson.build @@ -6,6 +6,7 @@ tcg_ss.add(files( 'tcg-all.c', 'cpu-exec.c', 'tb-maint.c', + 'tb-stats.c', 'tcg-runtime-gvec.c', 'tcg-runtime.c', 'translate-all.c', From patchwork Tue Oct 3 18:30:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 728813 Delivered-To: patch@linaro.org Received: by 2002:a5d:60c8:0:b0:31d:da82:a3b4 with SMTP id x8csp2285902wrt; Tue, 3 Oct 2023 11:33:32 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGa01rQBl/nKbymnNh6D5jHe+r2KejlDOxhUNCSTu9IPm1uRE+zuVDq9x/J4tdoAX/PxJdv X-Received: by 2002:ac8:7f55:0:b0:418:134f:17f4 with SMTP id g21-20020ac87f55000000b00418134f17f4mr205815qtk.22.1696358011791; Tue, 03 Oct 2023 11:33:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696358011; cv=none; d=google.com; s=arc-20160816; b=lgpoO59xVlbkMuL918PjS1fCGXznq6ifD5sbUzjpaQH9c6VXzC3BAXmwgc+zeENmdf 7Mch4CQzdYQ9+rUDr8z8Fb10xlr9M8i/AZHe5VdxdtqUnFTCfXvDX3lpi1wV9O+zdk01 mRahVpVIYjanYnC3dJhikYuGlYzAHwr8eCNP5hsBy4XhoSmFDWaZlxtnlkRGG0igjGgw 1/w4SpikmVTA0E0rg0QSmOafco3hGBU8AmrQPCsJjB41tpRnlLxWIAaf7h1ifZIQ7WGV 0wW0iipecQjtQbv2hwwc8gtWLu9whV848y2lwD9jhwH3rzpwOzUnhXJKT/lz5TVjLhZL glYA== 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=kobt9ITR02o3tC8SBBDgsqKPWPKYYPtp7QPvo0pQJWc=; fh=hCvX1k4zpzw9ZEQhAZzxrlFCd0WjbvmvmJzyvJcpNYw=; b=qL31UZZXdXaGkmpS3ZWcbMp6LGcJQfbLfIoqqnWkpYxhf7PLrUkB8rrbgbSrVu8tVd IGcZJuswwH4LyodG77V9iU4z1tdOukw2EqHJszqCl2xnClXNHyMHhjdJxlnyQ1OZHLY+ 8iZ1/DznxT6sdyjMaryuNk+U9J+FmkhCO3D6sKbS5h35qGAZQWyeQBvMTd1BdIdyd4tU PyMnmqGguwWsm1wbCuNMY4UVIJRUMBksABRDKeYTfd37RWnGIx034rVb6R33S3cbtutp UxlKDUSuHbyBgGxjv2HmKhZcv7CEft2Npfw1sEg3iy74vu7uO/3XI+9HgvByMVmsYLII Of1Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=b8vXXcBk; 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 e2-20020ac84e42000000b00417f817da78si774819qtw.565.2023.10.03.11.33.31 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 03 Oct 2023 11:33:31 -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=b8vXXcBk; 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 1qnkAt-00085E-7k; Tue, 03 Oct 2023 14:31:15 -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 1qnkAq-00083M-60 for qemu-devel@nongnu.org; Tue, 03 Oct 2023 14:31:12 -0400 Received: from mail-pl1-x629.google.com ([2607:f8b0:4864:20::629]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qnkAm-0001ez-U7 for qemu-devel@nongnu.org; Tue, 03 Oct 2023 14:31:11 -0400 Received: by mail-pl1-x629.google.com with SMTP id d9443c01a7336-1c871a095ceso4606525ad.2 for ; Tue, 03 Oct 2023 11:31:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1696357865; x=1696962665; 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=kobt9ITR02o3tC8SBBDgsqKPWPKYYPtp7QPvo0pQJWc=; b=b8vXXcBkI/NL18Tmlr3wgAshM+MKRul8N0CXEQZCZg8iawa+IKDZSfK885cUoumTro A6KREANkiwTrFiFe2Zs3FJypbwv7si1au8JWlgCOCQ8Wwb6oD/P4cR+dUTO4qnsIN+dE DDtkB80m84EN4iVEeeNdmg0sNbRNVZOAjJkGvBSL9r6+ESfyqyRo5FD5mRO56qh1HFaz EwkhIsm2ORz9tcYUCALQFYWIfAfjA1nN9sBf16jzIUIusJV1DSK1j8v/MDil5rt7eSz1 hI5rvNR2pH3Wn99IZBmRZX2WnGiVy3cX+kXXt0j3BJJ1J3DTmfDoLqgMQUxiauPBYLGO mS+w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696357865; x=1696962665; 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=kobt9ITR02o3tC8SBBDgsqKPWPKYYPtp7QPvo0pQJWc=; b=Y8rH4FydVEpbEiahDwnlG4OXGaeJxWNZouEGebc6HTsNX94yOcIe4oRioqZjBAMUe3 eo7nsjQtmkYEMbu4y3tts7N44jQkOiZ+vRExKvUrd38BXCpqDxnPJ0IyQo/oGnxHTHjg SV7af2jMgvLEDU1dyu08lJdSz3Ms2BXCOlZ5HZ2Fmuk0J87u7sEbqw5kuMGJEA7AtmQt P5lLPAwhNvz1r5OiDF1hPi8ayicC3Gujr2hkFhDT6a/0163sXwYdyQqqIz5ZPjLQJTH3 3gOPOKrOzPsnjnhkNxrQ9CTh2vbBJg2vxYWiUp+7wiRWFS095qQYK6lt9S4cEh9iAWpR 7W+w== X-Gm-Message-State: AOJu0Yz15b9DfHt+Er+9FrDrpsa2jlem4kx7EhcQafMF2xCtC7qzb7zN /ZikW19EiWGHgvID1PY8MTMULQyIBPwszHFyBfc= X-Received: by 2002:a17:902:ab82:b0:1c7:365a:566d with SMTP id f2-20020a170902ab8200b001c7365a566dmr314417plr.66.1696357865384; Tue, 03 Oct 2023 11:31:05 -0700 (PDT) Received: from stoup.. ([71.212.149.95]) by smtp.gmail.com with ESMTPSA id g7-20020a170902934700b001b7cbc5871csm1920432plp.53.2023.10.03.11.31.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Oct 2023 11:31:05 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: fei2.wu@intel.com, "Vanderson M. do Rosario" , =?utf-8?q?Alex_Benn=C3=A9e?= Subject: [PATCH v17 06/16] accel/tcg: Collect TB execution statistics Date: Tue, 3 Oct 2023 11:30:48 -0700 Message-Id: <20231003183058.1639121-7-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231003183058.1639121-1-richard.henderson@linaro.org> References: <20231003183058.1639121-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::629; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x629.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 From: "Vanderson M. do Rosario" Collect atomic and normal execution counts for TBs which have allocated a stats structure. Signed-off-by: Vanderson M. do Rosario Signed-off-by: Alex Bennée Signed-off-by: Fei Wu Signed-off-by: Richard Henderson --- accel/tcg/cpu-exec.c | 6 ++++++ accel/tcg/translator.c | 28 ++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/accel/tcg/cpu-exec.c b/accel/tcg/cpu-exec.c index 1a5bc90220..1114eae5c4 100644 --- a/accel/tcg/cpu-exec.c +++ b/accel/tcg/cpu-exec.c @@ -26,6 +26,7 @@ #include "disas/disas.h" #include "exec/exec-all.h" #include "tcg/tcg.h" +#include "tcg/tb-stats.h" #include "qemu/atomic.h" #include "qemu/rcu.h" #include "exec/log.h" @@ -601,6 +602,11 @@ void cpu_exec_step_atomic(CPUState *cpu) } cpu_exec_enter(cpu); + + if (tb_stats_enabled_for_tb(tb, TB_STATS_EXEC)) { + tb->tb_stats->executions.atomic++; + } + /* execute the generated code */ trace_exec_tb(tb, pc); cpu_tb_exec(cpu, tb, &tb_exit); diff --git a/accel/tcg/translator.c b/accel/tcg/translator.c index e7abcd86c1..eac281b229 100644 --- a/accel/tcg/translator.c +++ b/accel/tcg/translator.c @@ -14,6 +14,8 @@ #include "exec/translator.h" #include "exec/plugin-gen.h" #include "tcg/tcg-op-common.h" +#include "tcg/tcg-temp-internal.h" +#include "tcg/tb-stats.h" #include "internal-target.h" static void set_can_do_io(DisasContextBase *db, bool val) @@ -112,6 +114,31 @@ static void gen_tb_end(const TranslationBlock *tb, uint32_t cflags, } } +static void gen_tb_exec_count(TranslationBlock *tb) +{ + if (tb_stats_enabled_for_tb(tb, TB_STATS_EXEC)) { + TCGv_ptr ptr = tcg_temp_ebb_new_ptr(); + + tcg_gen_movi_ptr(ptr, (intptr_t)&tb->tb_stats->executions.normal); + if (sizeof(tb->tb_stats->executions.normal) == 4) { + TCGv_i32 t = tcg_temp_ebb_new_i32(); + tcg_gen_ld_i32(t, ptr, 0); + tcg_gen_addi_i32(t, t, 1); + tcg_gen_st_i32(t, ptr, 0); + tcg_temp_free_i32(t); + } else if (sizeof(tb->tb_stats->executions.normal) == 8) { + TCGv_i64 t = tcg_temp_ebb_new_i64(); + tcg_gen_ld_i64(t, ptr, 0); + tcg_gen_addi_i64(t, t, 1); + tcg_gen_st_i64(t, ptr, 0); + tcg_temp_free_i64(t); + } else { + qemu_build_not_reached_always(); + } + tcg_temp_free_ptr(ptr); + } +} + bool translator_use_goto_tb(DisasContextBase *db, vaddr dest) { /* Suppress goto_tb if requested. */ @@ -148,6 +175,7 @@ void translator_loop(CPUState *cpu, TranslationBlock *tb, int *max_insns, /* Start translating. */ icount_start_insn = gen_tb_start(db, cflags); + gen_tb_exec_count(tb); ops->tb_start(db, cpu); tcg_debug_assert(db->is_jmp == DISAS_NEXT); /* no early exit */ From patchwork Tue Oct 3 18:30:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 728817 Delivered-To: patch@linaro.org Received: by 2002:a5d:60c8:0:b0:31d:da82:a3b4 with SMTP id x8csp2286197wrt; Tue, 3 Oct 2023 11:34:16 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEviccDh1vDxe1TAbWOziwUgcT7A5jX5SdjIpNU/CmZtodxrABRNvqQRZAsJfMzNXzlJYtq X-Received: by 2002:a0c:dd87:0:b0:658:a043:376b with SMTP id v7-20020a0cdd87000000b00658a043376bmr200835qvk.8.1696358056322; Tue, 03 Oct 2023 11:34:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696358056; cv=none; d=google.com; s=arc-20160816; b=ankzU27k8AhgROR8ccCI2A+fNQFD8uF/O83tDxbR+mV1M1d+1+vEE6eIyCNvcLo4Cs 3oCCo8Gx4JKedFtU0RU5cUUD3ui52LdEEBWl0hmjo9TmL8DjG50Zx9XU9u7SdoasrQg9 kbT7Y1qAMkcBg6aIZZpydrwjNLJOVUTU/8u8mzbktzU/Q55c7u4moPewGFLoDlq3kPOi Edm68IpUHHnnkF1E0ZGYjzNq6QIdKeYghGPw8ezH2BHkDnEuLPgFDC3lSLhljJZtPtrt AaUOpsZ3ceng7TusxFWPoJiH/7JPywW5OZsia5gLo27ez4bJVkeA/5CCET/3YMilzqCR kqyA== 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=HBgYnkG/UUhR0Bh5p/v3uxe98ghyIsuRr/l/CO8AZ6c=; fh=Grk8ert1aVMPN1jf5/SpIQC06nonvH9hdZT9h94lZCY=; b=POVwFfFFjQoGOI8BQ9F39BvNTRcGpa4Y8WPdCFVlSYHoMpxTmiiwEx1mwIa2OdtnKZ PMLNWhMRGXbSXUm48YbCDorrBBvzfOEnM/uWjt9Y0n6Csw8FfB8k/EZsbD07hpDwn0ps mKXf/TP9c7CCwLhV1BcqssWO3RtkGFXvYzJtg4P2n98XEPYqqHGehzcLBPXMZifX8D/3 aLr+YC3eEVHXhXOmAx4KXTaqHnXyhVCwdPFTRkxw/d7ZbqSOZ/cHhSF79TbPmHzp158y 8ypRoszTPpdYDOP0czURnAx/o2dvUiePQuWw5ElSlbD3AYJd8D6UgjHWxDpsAdMBOAcc vAjw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=u9lLVIA4; 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 ea12-20020a05620a488c00b0077263dd03f3si768604qkb.33.2023.10.03.11.34.16 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 03 Oct 2023 11:34:16 -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=u9lLVIA4; 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 1qnkAs-00084m-DA; Tue, 03 Oct 2023 14:31:14 -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 1qnkAp-00082c-6g for qemu-devel@nongnu.org; Tue, 03 Oct 2023 14:31:11 -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 1qnkAm-0001fC-Hk for qemu-devel@nongnu.org; Tue, 03 Oct 2023 14:31:09 -0400 Received: by mail-pl1-x62e.google.com with SMTP id d9443c01a7336-1c3d6d88231so9724895ad.0 for ; Tue, 03 Oct 2023 11:31:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1696357866; x=1696962666; 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=HBgYnkG/UUhR0Bh5p/v3uxe98ghyIsuRr/l/CO8AZ6c=; b=u9lLVIA4NclPLI3sHPa5yioF0FdxTGF2iPhDNXAL53dwo+mexG2nqkO6kSbIEuIqjc CfKJvpFighYNMgBvDXLP2mYOOVWeGotg53KLYhAcpOrnJZDXKdvvNejSEOQso12RhT59 8cITiY7JeFVfHX/tl4ovZSUbW8wtV+AmdMBRycGTMsHDKP+h+ayWN7J0lM7lUjTxK4Q9 Pgh6lXOmb8MhQjl3YCAG/gE6hu4gT0L7+LFstOcAPpGIZBp6FUOsevzFQq2XyXol/dJO 09xQYktTilCcO4AzJMpWdqr0EqiSJLdw4PuEc3XVNz3idJGWiLFnhdVNURYftYj0bWq9 W9fw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696357866; x=1696962666; 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=HBgYnkG/UUhR0Bh5p/v3uxe98ghyIsuRr/l/CO8AZ6c=; b=Iad87YVqdIJZO4X5CLSJZ9zWPldjR1Su3r+fUK/48TX+eZZ7hbRJPHCaeJ9wYFBx5E /105B3TUbkyL+5V0QSvTaE14ldD0jreY+GrXXwLgGRfechBw6F6C2UEwfYn26NZJw4U+ CMda+tG6d0PjxrN1Mt6EWhP+tEiGQztkRd5+nRpvTd0wPF0rcnQEfHpAstkQG9wLFnKp 3qmhJuudqRIQITv8XC5NQqhLJ5oQcsIezyyzjmsn4Tp6hKQzba31k6v338iauzwXR6n/ mDHiODw0XELveuBU8cA1ZTjYSoVCPjCN9iPCorCMJyaCxVNfwC5S27ek0rAHsOggaHL4 OIFA== X-Gm-Message-State: AOJu0Yz6nDQmuUmGJ4t1tukhu2pTb6LgCtbSfvP/LI7hmZKnimScV73A YHiZIGXM8Z68miEvN7mnnXsWbMHWWGkJxU9BBos= X-Received: by 2002:a17:902:bc4b:b0:1bf:728:745b with SMTP id t11-20020a170902bc4b00b001bf0728745bmr332700plz.49.1696357866237; Tue, 03 Oct 2023 11:31:06 -0700 (PDT) Received: from stoup.. ([71.212.149.95]) by smtp.gmail.com with ESMTPSA id g7-20020a170902934700b001b7cbc5871csm1920432plp.53.2023.10.03.11.31.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Oct 2023 11:31:05 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: fei2.wu@intel.com, "Vanderson M . do Rosario" , =?utf-8?q?Alex_Benn=C3=A9e?= Subject: [PATCH v17 07/16] accel/tcg: Collect TB jit statistics Date: Tue, 3 Oct 2023 11:30:49 -0700 Message-Id: <20231003183058.1639121-8-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231003183058.1639121-1-richard.henderson@linaro.org> References: <20231003183058.1639121-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::62e; envelope-from=richard.henderson@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 Collect items like input and output code size, guest instruction count, intermediate ops, spills, etc. Signed-off-by: Vanderson M. do Rosario Signed-off-by: Alex Bennée Signed-off-by: Fei Wu [rth: Consolidated at the end of translation.] Signed-off-by: Richard Henderson Reviewed-by: Philippe Mathieu-Daudé --- accel/tcg/translate-all.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/accel/tcg/translate-all.c b/accel/tcg/translate-all.c index 6e64ae2dbe..ad4538f169 100644 --- a/accel/tcg/translate-all.c +++ b/accel/tcg/translate-all.c @@ -557,6 +557,27 @@ TranslationBlock *tb_gen_code(CPUState *cpu, return tb; } + /* Record JIT statistics, if required. */ + if (unlikely(tb_stats_enabled & TB_STATS_JIT)) { + TBStatistics *s = tb->tb_stats; + if (s) { + s->code.num_tcg_ops += tcg_ctx->orig_nb_ops; + s->code.num_tcg_ops_opt += tcg_ctx->nb_ops; + s->code.temps += tcg_ctx->nb_temps; + s->code.deleted_ops += tcg_ctx->nb_deleted_ops; + s->code.spills += tcg_ctx->nb_spills; + + s->code.num_guest_inst += tb->icount; + s->code.in_len += tb->size; + s->code.out_len += tb->tc.size; + s->code.search_out_len += search_size; + s->translations.total += 1; + if (tb_page_addr1(tb) != -1) { + s->translations.spanning += 1; + } + } + } + /* * Insert TB into the corresponding region tree before publishing it * through QHT. Otherwise rewinding happened in the TB might fail to From patchwork Tue Oct 3 18:30:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 728812 Delivered-To: patch@linaro.org Received: by 2002:a5d:60c8:0:b0:31d:da82:a3b4 with SMTP id x8csp2285825wrt; Tue, 3 Oct 2023 11:33:18 -0700 (PDT) X-Google-Smtp-Source: AGHT+IE6Zj0aE+CdTE9XZGxCNHkUt1eCzG1D1Feruk8BNAvmc4eutgXnwe7MqNZ8/z/BePFcMEnV X-Received: by 2002:ac8:7d4f:0:b0:412:21f4:6f9c with SMTP id h15-20020ac87d4f000000b0041221f46f9cmr315022qtb.60.1696357997945; Tue, 03 Oct 2023 11:33:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696357997; cv=none; d=google.com; s=arc-20160816; b=Js9rQHWv+CgAviAZLlCa4fUYUGzbbQBs8fbHyAxJm98mgtutKxci1NBrowIdbiIPnQ 0og6EJPlkOdTMJ9iEKh4hW9LSMdEF7Cj7tNT0s2GiDQaHR7RIW0TIaJt4BkHldwCzY0k ULkXQPH2RVJy96Q3pDapWBnGzQQjcPhryOS3NlcVo3vgggBpZfTqIYpfg3JOnjLoxL2d ru8rmwMnul0AUxJ2U/hXXsDqPJMxSqF6hhflHMvUVeI1wOxAihzghVmp0Qit/2FHPb6I gp3ywfmTiQXVJzRVqPh+5iUaflyR0HH4s6BSnDdoMoj5uQ9J5jmoxA4mYcdUTSeAdbN4 q66g== 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=XnJ57/DCzka0bx3FOdRsvPKfSH9sE7SIww+OcI5Yp3Y=; fh=5Ef+GGgUKhMqUJ634tl8oclCuvdgCDBmJobFnWqHX6s=; b=0bv+oxsCsJSLp7iwZf+rTJLF5vqL/EWJRUOq+G6LuOCZYr6bLSPRxCjnCdk2zUdAVA 9jIWYQFaZgFYLko2kbiJLsZOIE8oQ3J9/GhhsblnIZnnucMXjYuIBzuFmhviWo18cxFq EYQoGzbXUcRZDsF1733JMx2+oA5U0oMGe5CR/EBO1snDWdSvO9kg4Bz7Gz5sMjb65Py3 D3bRHMgOSaNnalYeO1aZerDXKSo5CmbOu48YmFhRqtG7x9QU4FsGt2RyRH+1KFCzFNaU qXqchF/l72uisKD3uKYVhZRuhWJDsg+RvQ/NKpLLDJ/91n2Qe4UlaYAfQuvX43IvEDd8 bbXw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=IQJOWpj4; 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 v41-20020a05622a18a900b00411f7e63bd3si774005qtc.522.2023.10.03.11.33.17 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 03 Oct 2023 11:33: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=IQJOWpj4; 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 1qnkAr-000849-CR; Tue, 03 Oct 2023 14:31:13 -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 1qnkAo-00081k-S1 for qemu-devel@nongnu.org; Tue, 03 Oct 2023 14:31:10 -0400 Received: from mail-pl1-x630.google.com ([2607:f8b0:4864:20::630]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qnkAm-0001fO-O1 for qemu-devel@nongnu.org; Tue, 03 Oct 2023 14:31:10 -0400 Received: by mail-pl1-x630.google.com with SMTP id d9443c01a7336-1c61bde0b4bso10798895ad.3 for ; Tue, 03 Oct 2023 11:31:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1696357867; x=1696962667; 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=XnJ57/DCzka0bx3FOdRsvPKfSH9sE7SIww+OcI5Yp3Y=; b=IQJOWpj4ZMH2cFnFwIq5NcIk9e0MxkSlc6pz/kQQbELbkNdyWhGT2tXfvpn536VZJK pebn8V2gGKSc+3F3CsuHhtnCkSqi9Hl8ATp5XWaW/PAy10fK40YEQwYgR8rHCbUm8OqU ttL47BPHrGvWeUMF8ulN9NDdUkSllJEMJbo5aQeUpimu7m+Sy6QH3GG9uPY724Q3wlPG xLsvKSm1y/yyvlFG3sb6DOh3xpFu1IOKG/KI4N4cxHkkMGjAAW2xNkDtLwAUAJ/QOysL K7vdBEGDoc3ibRxLHEc/re7ooGKeQjdXLuaS8RRa9ldA/E3lm7fkRzmIfDB2KcLqYpzl HAPA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696357867; x=1696962667; 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=XnJ57/DCzka0bx3FOdRsvPKfSH9sE7SIww+OcI5Yp3Y=; b=GgMQK1d4rcDRBkIi6MnmYFOVMwkkhoG7BNifcigAF24HHVldXeUe/aXLHfz9ZaaM7a 5Gk8fu/9Q0isSkeXzotbbKIYFsQBY+cBiHpTntM4cNfxyD4hJMeVmQv9LDYA3omE4VH6 bhc/X5L8+PiAQ/MwmZvkVGu/wfvvTpZPDqHPdV6SJOWRg5iGG1yaZ11noAgPu3ZGtmiC byTxaHXaj2N2uT48tjcZWT62JfJw60AZwDJeFLSA9uPZUXW9b0u+9b64kMPquE2lBNnL YOC0WNAlWIVYCxF4SyzkFWFQR5B1kT8ZEkE2RVb10Gl58OAdO736ERuwFtMHLMMTTmTa ZbkA== X-Gm-Message-State: AOJu0YzxH3ZkreQNMcfrlsaTP+0UFkzmnihSbhm319IP23X21RyUA+mt 2j3IDBC84HqD/4AOWfS4IzlBZJztpuuYIqeRDmo= X-Received: by 2002:a17:903:32cb:b0:1c3:2ee6:3811 with SMTP id i11-20020a17090332cb00b001c32ee63811mr425165plr.8.1696357867317; Tue, 03 Oct 2023 11:31:07 -0700 (PDT) Received: from stoup.. ([71.212.149.95]) by smtp.gmail.com with ESMTPSA id g7-20020a170902934700b001b7cbc5871csm1920432plp.53.2023.10.03.11.31.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Oct 2023 11:31:06 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: fei2.wu@intel.com, "Vanderson M. do Rosario" , "Dr . David Alan Gilbert" , =?utf-8?q?Alex_Benn=C3=A9e?= Subject: [PATCH v17 08/16] accel/tcg: Add tb_stats hmp command Date: Tue, 3 Oct 2023 11:30:50 -0700 Message-Id: <20231003183058.1639121-9-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231003183058.1639121-1-richard.henderson@linaro.org> References: <20231003183058.1639121-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::630; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x630.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 From: "Vanderson M. do Rosario" Add tb_stats [start|stop|status] command to hmp. This allows controlling the collection of statistics. The goal of this command is to allow the dynamic exploration of the TCG behavior and quality. Therefore, for now, a corresponding QMP command is not considered worthwhile. Acked-by: Dr. David Alan Gilbert Signed-off-by: Vanderson M. do Rosario Signed-off-by: Alex Bennée Signed-off-by: Fei Wu [rth: Significantly reorganized.] Signed-off-by: Richard Henderson --- accel/tcg/monitor.c | 70 ++++++++++++++++++++++++++++++++++++++++++++- hmp-commands.hx | 15 ++++++++++ 2 files changed, 84 insertions(+), 1 deletion(-) diff --git a/accel/tcg/monitor.c b/accel/tcg/monitor.c index 093efe9714..370fea883c 100644 --- a/accel/tcg/monitor.c +++ b/accel/tcg/monitor.c @@ -12,11 +12,15 @@ #include "qapi/error.h" #include "qapi/type-helpers.h" #include "qapi/qapi-commands-machine.h" +#include "qapi/qmp/qdict.h" #include "monitor/monitor.h" +#include "monitor/hmp.h" #include "sysemu/cpus.h" #include "sysemu/cpu-timers.h" #include "sysemu/tcg.h" #include "tcg/tcg.h" +#include "tcg/tb-stats.h" +#include "exec/tb-flush.h" #include "internal-common.h" #include "tb-context.h" @@ -235,10 +239,74 @@ HumanReadableText *qmp_x_query_opcount(Error **errp) return human_readable_text_from_str(buf); } +static void tb_stats_init_safe(CPUState *cpu, run_on_cpu_data icmd) +{ + uint32_t flags = icmd.host_int; + + tb_stats_init(flags); + tb_flush(cpu); +} + +static void hmp_tbstats(Monitor *mon, const QDict *qdict) +{ + uint32_t flags = TB_STATS_NONE; + const char *cmd; + + if (!tcg_enabled()) { + monitor_printf(mon, "Only available with accel=tcg\n"); + return; + } + + cmd = qdict_get_try_str(qdict, "command"); + + if (strcmp(cmd, "start") == 0) { + const char *sflag = qdict_get_try_str(qdict, "flag"); + + flags = TB_STATS_ALL; + if (sflag) { + if (strcmp(sflag, "all") == 0) { + flags = TB_STATS_ALL; + } else if (strcmp(sflag, "jit") == 0) { + flags = TB_STATS_JIT; + } else if (strcmp(sflag, "exec") == 0) { + flags = TB_STATS_EXEC; + } else { + monitor_printf(mon, "Invalid argument to tb_stats start\n"); + return; + } + } + + if (tb_stats_enabled) { + monitor_printf(mon, "TB statistics already being recorded\n"); + return; + } + } else if (strcmp(cmd, "stop") == 0) { + if (!tb_stats_enabled) { + monitor_printf(mon, "TB statistics not being recorded\n"); + return; + } + } else if (strcmp(cmd, "status") == 0) { + if (tb_stats_enabled) { + monitor_printf(mon, "TB statistics are enabled:%s%s\n", + tb_stats_enabled & TB_STATS_EXEC ? " EXEC" : "", + tb_stats_enabled & TB_STATS_JIT ? " JIT" : ""); + } else { + monitor_printf(mon, "TB statistics are disabled\n"); + } + return; + } else { + monitor_printf(mon, "Invalid command\n"); + return; + } + + async_safe_run_on_cpu(first_cpu, tb_stats_init_safe, + RUN_ON_CPU_HOST_INT(flags)); +} + static void hmp_tcg_register(void) { monitor_register_hmp_info_hrt("jit", qmp_x_query_jit); monitor_register_hmp_info_hrt("opcount", qmp_x_query_opcount); + monitor_register_hmp("tb_stats", false, hmp_tbstats); } - type_init(hmp_tcg_register); diff --git a/hmp-commands.hx b/hmp-commands.hx index 63eac22734..e1d78ab69d 100644 --- a/hmp-commands.hx +++ b/hmp-commands.hx @@ -1673,6 +1673,21 @@ SRST Executes a qemu-io command on the given block device. ERST +#if defined(CONFIG_TCG) + { + .name = "tb_stats", + .args_type = "command:s,flag:s?", + .params = "command [flag]", + .help = "Control tb statistics collection:" + "tb_stats (start|stop|status) [all|jit|exec]", + }, +#endif + +SRST +``tb_stats`` *command* *flag* + Control recording tb statistics +ERST + { .name = "qom-list", .args_type = "path:s?", From patchwork Tue Oct 3 18:30:51 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 728807 Delivered-To: patch@linaro.org Received: by 2002:a5d:60c8:0:b0:31d:da82:a3b4 with SMTP id x8csp2285683wrt; Tue, 3 Oct 2023 11:32:56 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEUSnnsatYZd0u2LV/Mqbb4YyxInpBn1gFI2PIe9zduffEpW52buy1DUXUwv/Bnmmm2At48 X-Received: by 2002:a0c:b3d2:0:b0:64f:67ae:a132 with SMTP id b18-20020a0cb3d2000000b0064f67aea132mr149190qvf.23.1696357976360; Tue, 03 Oct 2023 11:32:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696357976; cv=none; d=google.com; s=arc-20160816; b=dQjA1q8WMPbwrzREl4vewDuZbZPjLcbI7qLzY9Jo2IAwmCnST2Bz+5BTCS50ClQYND ZCfTS1gOIM9bILCvjH/+u10f4h7Lni0H5m+bb+fkFWfNPJbZiwu17RnsgKe+WbNz89mN galjZCTh0crwJ8Y7EiPmx3MpmroL2mHBIM0D75JTjNjwyERX6/zGbdZqRkMyp0zR5wYC pmJDIjqB6TB1rPPslm3IqBsmFmaX912W9EhCT+k4k1bywngromLZ0ZU5UVgooNhRlJhY G4+AB82SCUUQs46tNOdfJDFkgmCyJGnOGdo9ZuVs3J2IPCYXraKdLHcTYTAk/jDotL1E vwmw== 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=vzdMnZ/qp0IZVfsWupkBnwKkbY4o53yFm+NGR5vmj5I=; fh=JxWBtSZstwhZxj1nqbhkYnE1e7Ds6gYyoAtro8tkvc0=; b=ezYG0Gf/SYHHGnv6jGPrv1GAMkMgoVXDekHiLxDmYoMJf1NfOH6nlOKCxk0yjze4l2 vA3hob7DYfUm/R1oehPyMNa/mGwyzTB+z3w08BdRgLvVas9ZUaIOlpW5r52o7Baaa3Em kpd6sbunmwYXxsrKSiXCjDp+tuyQ1XbQikXU0RWsw28pKrqMKuEs7KhqO8EJE9mor+H3 sNi39W4cLSpwJ8doIXBTaOY/ToWHcbcTr/rXhDcw7DFVOob1PgNc9FoykgkRrBec9Umh 3Ry4m/szl/GR+iSbxnA/sLbQr0cmsIJYiGKc7/q2YdQq+8+jg0X+PhFpsBFzMe9Ws11P ncmQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=zIhJYxRj; 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 p5-20020a0c8c85000000b0065d124684b0si747318qvb.340.2023.10.03.11.32.56 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 03 Oct 2023 11:32:56 -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=zIhJYxRj; 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 1qnkB6-00089E-Ao; Tue, 03 Oct 2023 14:31:28 -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 1qnkB0-00088N-GU for qemu-devel@nongnu.org; Tue, 03 Oct 2023 14:31:22 -0400 Received: from mail-pf1-x435.google.com ([2607:f8b0:4864:20::435]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qnkAp-0001fw-0Z for qemu-devel@nongnu.org; Tue, 03 Oct 2023 14:31:22 -0400 Received: by mail-pf1-x435.google.com with SMTP id d2e1a72fcca58-692ada71d79so967287b3a.1 for ; Tue, 03 Oct 2023 11:31:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1696357868; x=1696962668; 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=vzdMnZ/qp0IZVfsWupkBnwKkbY4o53yFm+NGR5vmj5I=; b=zIhJYxRjwahxpVlq4tEF2wLTtjU78anIkXvVl8oFB2GuvaGdZmh/3VQBRgQ2zFL67R /Jv79Qhwnj6hGq2AEOGZF2PDyxjLEG/hulvQ3WpnAPzm6GkInbgC7aQGdtNCqX1wN7t8 5lOZ2w9kvVR3Envpg84w/lwnWgL6EBt42H8+kYYHw2IPf7YIXajmsKrI+waVZU03ld10 ooD4BkfcwdftFXTjlsBA+C9szhLXRejmF/tRpQdAOvAUW4Y1miWom9hPRL3z7dgttbqr 0B67V5bWgiekBRRaNFIoZgDQj7Qd+7o+Tn8ONienSkl/1kEup2jnLZw0nFa/J9Mo7TQH Gd4g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696357868; x=1696962668; 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=vzdMnZ/qp0IZVfsWupkBnwKkbY4o53yFm+NGR5vmj5I=; b=qWZdp7GILw8FqZSdbLte0q6Z/ki0fjEicrK38z8w/jRPJfnEDn84evcCTsPoRYdtvZ A9wD6qgHOoXzxyffpPkgxHnQwClZXpbKDK/YXAhkuunnDzx+30vJDKrVuQcNzOSu6maZ clAgtsBl1G/KeUjoJD6tmY1JOVAf6/w4H7djLbm1q+aX0x3ziwBAOFh/HlTvtwEfZrsi eEppxjV4GNds+C+txcxkVkNKMFJXNBwCXi6UFbQ1VHSfob4+s9mkxBjIdEFa5I1qCKDs Vdhqdsfnoxd+eF5cYPSh88MgkPOR+Ygr9tBVoWYrYhetLBdSlqzfsrqM1sN4sIaCHd5G U8CQ== X-Gm-Message-State: AOJu0YxHMJmiabmvsRgD03SU9ict/IVyD6IPi39K9czYYDOYLcP9Y7Bg kkMisV7G6N7KSlW4dromOJ1Qfgs4imNoKoRHKUk= X-Received: by 2002:a05:6a20:9694:b0:15e:707c:904 with SMTP id hp20-20020a056a20969400b0015e707c0904mr250590pzc.24.1696357868289; Tue, 03 Oct 2023 11:31:08 -0700 (PDT) Received: from stoup.. ([71.212.149.95]) by smtp.gmail.com with ESMTPSA id g7-20020a170902934700b001b7cbc5871csm1920432plp.53.2023.10.03.11.31.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Oct 2023 11:31:07 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: fei2.wu@intel.com Subject: [PATCH v17 09/16] util/log: Add Error argument to qemu_str_to_log_mask Date: Tue, 3 Oct 2023 11:30:51 -0700 Message-Id: <20231003183058.1639121-10-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231003183058.1639121-1-richard.henderson@linaro.org> References: <20231003183058.1639121-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::435; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x435.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, 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 Do not rely on return value of 0 to indicate error, pass along an Error pointer to be set. Signed-off-by: Richard Henderson --- include/qemu/log.h | 2 +- bsd-user/main.c | 6 ++++-- linux-user/main.c | 7 +++++-- monitor/hmp-cmds.c | 5 +++-- softmmu/vl.c | 7 +++++-- util/log.c | 5 +++-- 6 files changed, 21 insertions(+), 11 deletions(-) diff --git a/include/qemu/log.h b/include/qemu/log.h index df59bfabcd..9b92d2663e 100644 --- a/include/qemu/log.h +++ b/include/qemu/log.h @@ -87,7 +87,7 @@ bool qemu_set_log_filename(const char *filename, Error **errp); bool qemu_set_log_filename_flags(const char *name, int flags, Error **errp); void qemu_set_dfilter_ranges(const char *ranges, Error **errp); bool qemu_log_in_addr_range(uint64_t addr); -int qemu_str_to_log_mask(const char *str); +int qemu_str_to_log_mask(const char *str, Error **errp); /* Print a usage message listing all the valid logging categories * to the specified FILE*. diff --git a/bsd-user/main.c b/bsd-user/main.c index 703f3e2c41..a981239a0b 100644 --- a/bsd-user/main.c +++ b/bsd-user/main.c @@ -411,8 +411,10 @@ int main(int argc, char **argv) { int mask = 0; if (log_mask) { - mask = qemu_str_to_log_mask(log_mask); - if (!mask) { + Error *err = NULL; + mask = qemu_str_to_log_mask(log_mask, &err); + if (err) { + error_report_err(err); qemu_print_log_usage(stdout); exit(1); } diff --git a/linux-user/main.c b/linux-user/main.c index 0c23584a96..d0464736cc 100644 --- a/linux-user/main.c +++ b/linux-user/main.c @@ -264,8 +264,11 @@ static void handle_arg_help(const char *arg) static void handle_arg_log(const char *arg) { - last_log_mask = qemu_str_to_log_mask(arg); - if (!last_log_mask) { + Error *err = NULL; + + last_log_mask = qemu_str_to_log_mask(arg, &err); + if (err) { + error_report_err(err); qemu_print_log_usage(stdout); exit(EXIT_FAILURE); } diff --git a/monitor/hmp-cmds.c b/monitor/hmp-cmds.c index 6c559b48c8..c4bd97d467 100644 --- a/monitor/hmp-cmds.c +++ b/monitor/hmp-cmds.c @@ -291,8 +291,9 @@ void hmp_log(Monitor *mon, const QDict *qdict) if (!strcmp(items, "none")) { mask = 0; } else { - mask = qemu_str_to_log_mask(items); - if (!mask) { + mask = qemu_str_to_log_mask(items, &err); + if (err) { + error_free(err); hmp_help_cmd(mon, "log"); return; } diff --git a/softmmu/vl.c b/softmmu/vl.c index 98e071e63b..02193696b9 100644 --- a/softmmu/vl.c +++ b/softmmu/vl.c @@ -2486,8 +2486,11 @@ static void qemu_process_early_options(void) { int mask = 0; if (log_mask) { - mask = qemu_str_to_log_mask(log_mask); - if (!mask) { + Error *err = NULL; + + mask = qemu_str_to_log_mask(log_mask, &err); + if (err) { + error_report_err(err); qemu_print_log_usage(stdout); exit(1); } diff --git a/util/log.c b/util/log.c index def88a9402..b5f08db202 100644 --- a/util/log.c +++ b/util/log.c @@ -500,8 +500,8 @@ const QEMULogItem qemu_log_items[] = { { 0, NULL, NULL }, }; -/* takes a comma separated list of log masks. Return 0 if error. */ -int qemu_str_to_log_mask(const char *str) +/* Takes a comma separated list of log masks. */ +int qemu_str_to_log_mask(const char *str, Error **errp) { const QEMULogItem *item; int mask = 0; @@ -524,6 +524,7 @@ int qemu_str_to_log_mask(const char *str) goto found; } } + error_setg(errp, "Invalid -d option \"%s\"", *tmp); goto error; found: mask |= item->mask; From patchwork Tue Oct 3 18:30:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 728808 Delivered-To: patch@linaro.org Received: by 2002:a5d:60c8:0:b0:31d:da82:a3b4 with SMTP id x8csp2285691wrt; Tue, 3 Oct 2023 11:32:57 -0700 (PDT) X-Google-Smtp-Source: AGHT+IF7pJl/4cza4s6L98iYwX+hm7p0YMXZ1mb0bIHZG1J7ON7truvM4ZqLJvtSyLNWuceIxlhj X-Received: by 2002:a25:c5c6:0:b0:d84:bf67:c775 with SMTP id v189-20020a25c5c6000000b00d84bf67c775mr97002ybe.17.1696357977289; Tue, 03 Oct 2023 11:32:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696357977; cv=none; d=google.com; s=arc-20160816; b=HeWXQqz+RTg4CnTpZ8KOvMmcO7zuGFuzJlluV0zFNgGu04jUI8GK1wjTzp5s+XrLJi 8S3AEYDUxrQgwWLKvkKKOwtQ8ThGJLu6oyro7bYMMLHFR2YpOzPKWHJqBzhUf2tz6JLf eP8NPnbn9iwfpLM4xFiw4ZvHlPQ/AiAoCNHpHhxrcxdT0MMOtA+G5X1x9thj/8rJWqHD 3qVZAf1+2tHsbniVf/4Na/i7uEKVr4I7IEb45CKZ6glSPiikzP4oSL57JFX0OzdL3Xyt D+kuumJAK9SfbhORy+/cCWyR+E99Ex9LwZIIf0oxjHvctenPbXii+EQALjY7lLEpiMVJ cx5A== 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=MD25jSGXV56D96OuAdfZq5dSUt2s3HFUz4HxD2v8rb0=; fh=Grk8ert1aVMPN1jf5/SpIQC06nonvH9hdZT9h94lZCY=; b=GqS11zdpPMmAxDhsqcS3Z5QdSw4ONKRihXJoZh7X0j1XWDJ/vsJ8Jvbqv+qwcn/YF5 GB9ncI/xsnyT9/DeLQ5epxEHr3vdjeO1kJiu/fHY24slqbX6iRvhLXrwVfeHoovpF00F ZxoHoGm/svGsRkG+dDnZIhaPvSDn2KqwghJ6J2fc3P2Hg66yB5WcnQK2FsL2mziHTcJn keI0t2iRq7rzDEPOEnQwbvCadE9r6naqd2RpQb71R6gEwDkIpV29aJf0eJ8f3ND38LiC Np6GhZs7jVSnvEiUdJ/Wx7FiOZY230XYZ7C3HgA+NOm0rExHsfa19K2d1WCrhfRYVOVH +TgQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=wH1VXlWC; 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 g11-20020a0ce4cb000000b0065afd35c75dsi739552qvm.70.2023.10.03.11.32.57 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 03 Oct 2023 11:32:57 -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=wH1VXlWC; 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 1qnkAv-000877-Re; Tue, 03 Oct 2023 14:31:17 -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 1qnkAu-00086b-JK for qemu-devel@nongnu.org; Tue, 03 Oct 2023 14:31:16 -0400 Received: from mail-pl1-x633.google.com ([2607:f8b0:4864:20::633]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qnkAp-0001gE-NL for qemu-devel@nongnu.org; Tue, 03 Oct 2023 14:31:16 -0400 Received: by mail-pl1-x633.google.com with SMTP id d9443c01a7336-1c3f97f2239so10080975ad.0 for ; Tue, 03 Oct 2023 11:31:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1696357869; x=1696962669; 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=MD25jSGXV56D96OuAdfZq5dSUt2s3HFUz4HxD2v8rb0=; b=wH1VXlWCJ2Mh3egL1omTGdqNB29L5dbjwuAyNzwXOiu+8/OvOj772lWj9KdVkiT74P VisN9Ps4GKc0zyF2JyAW835QLj+A+JqU6CsW5lM53g848+vFOfDRZbXXyb5cvrZSqR7W cV9aS6Tjk2lnEA/btr6dbTt2nEJXeBfQbBL11SPWMJSZCQHYTe6XZ+ZChCAIegz2U3lK 4b6RAkct684yHvA0Zs8v2f/KypZBeiBnqQMhcOBdIgP0BjJxzEeurfW2Z55y2zym0lRc 6wrA7djQwqgtSHXnCGitROM2079/sher+7oKimsTZMTYu42Ekw4ciHIP3j/zUYGTFWw0 Ecgw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696357869; x=1696962669; 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=MD25jSGXV56D96OuAdfZq5dSUt2s3HFUz4HxD2v8rb0=; b=Pu1qUJC4UhN1OL1nMtI27NKF0K38Xbov13KwnpgSVHxRvtcJPy83URBVVc2NHxgec7 VgYeiGnu2AOGqsygA6K5NCXew3+FcNl1WiRFrQpCE7m46HNmjanar9FGNijs6p9PLOv/ 8W89KiCZqXv6aZ+rhd+b5gkn+LNfiQ2p9XtfwP33y5Di8HvdsGWizOUAGU7RVwtZ9e3I fpDP8oS6DdRtouadZor4b1lYDtqc0dtLJEQNNF9SJGpzNV2t1vNUAWAs6ZYbX3yuIbn+ kQ1soAyCNo5LQ9NIBNERpKnImtfu9GOYWE4ENbyBz7p2G2FOlWlJvxPSzOSVX8aPD0kF OscA== X-Gm-Message-State: AOJu0YwEguaWxmZeWSOEL5RmTwp93dVA6RdFRU0+7vUpb890WoVpjCey fdF2BT7h0WNShrNqOkMbCr3QN/qf9oNsf5e1Gag= X-Received: by 2002:a17:903:1c1:b0:1c0:c4be:62ca with SMTP id e1-20020a17090301c100b001c0c4be62camr417335plh.17.1696357869317; Tue, 03 Oct 2023 11:31:09 -0700 (PDT) Received: from stoup.. ([71.212.149.95]) by smtp.gmail.com with ESMTPSA id g7-20020a170902934700b001b7cbc5871csm1920432plp.53.2023.10.03.11.31.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Oct 2023 11:31:08 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: fei2.wu@intel.com, "Vanderson M . do Rosario" , =?utf-8?q?Alex_Benn=C3=A9e?= Subject: [PATCH v17 10/16] util/log: Add -d tb_stats Date: Tue, 3 Oct 2023 11:30:52 -0700 Message-Id: <20231003183058.1639121-11-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231003183058.1639121-1-richard.henderson@linaro.org> References: <20231003183058.1639121-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::633; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x633.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, T_SPF_TEMPERROR=0.01 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 From: Fei Wu Enable TBStatistics collection from startup. Signed-off-by: Vanderson M. do Rosario Signed-off-by: Alex Bennée Signed-off-by: Fei Wu [rth: Change "tb_stats_foo" to "tb_stats:foo"] Signed-off-by: Richard Henderson --- stubs/tb-stats.c | 16 ++++++++++++++++ util/log.c | 36 +++++++++++++++++++++++++++++++----- stubs/meson.build | 1 + 3 files changed, 48 insertions(+), 5 deletions(-) create mode 100644 stubs/tb-stats.c diff --git a/stubs/tb-stats.c b/stubs/tb-stats.c new file mode 100644 index 0000000000..ceaa1622ce --- /dev/null +++ b/stubs/tb-stats.c @@ -0,0 +1,16 @@ +/* + * TB Stats Stubs + * + * Copyright (c) 2019 + * Written by Alex Bennée + * + * This code is licensed under the GNU GPL v2, or later. + */ + + +#include "qemu/osdep.h" +#include "tcg/tb-stats.h" + +void tb_stats_init(uint32_t flags) +{ +} diff --git a/util/log.c b/util/log.c index b5f08db202..0cb987fb74 100644 --- a/util/log.c +++ b/util/log.c @@ -30,6 +30,9 @@ #ifdef CONFIG_LINUX #include #endif +#ifdef CONFIG_TCG +#include "tcg/tb-stats.h" +#endif typedef struct RCUCloseFILE { @@ -509,22 +512,41 @@ int qemu_str_to_log_mask(const char *str, Error **errp) char **tmp; for (tmp = parts; tmp && *tmp; tmp++) { - if (g_str_equal(*tmp, "all")) { + char *t = *tmp; + + if (g_str_equal(t, "all")) { for (item = qemu_log_items; item->mask != 0; item++) { mask |= item->mask; } #ifdef CONFIG_TRACE_LOG - } else if (g_str_has_prefix(*tmp, "trace:") && (*tmp)[6] != '\0') { - trace_enable_events((*tmp) + 6); + } else if (g_str_has_prefix(t, "trace:") && t[6] != '\0') { + trace_enable_events(t + 6); mask |= LOG_TRACE; +#endif +#ifdef CONFIG_TCG + } else if (g_str_has_prefix(t, "tb_stats:") && t[9] != '\0') { + int flags = TB_STATS_NONE; + char *v = t + 9; + + if (g_str_equal(v, "all")) { + flags = TB_STATS_ALL; + } else if (g_str_equal(v, "jit")) { + flags = TB_STATS_JIT; + } else if (g_str_equal(v, "exec")) { + flags = TB_STATS_EXEC; + } else { + error_setg(errp, "Invalid -d option \"%s\"", t); + goto error; + } + tb_stats_init(flags); #endif } else { for (item = qemu_log_items; item->mask != 0; item++) { - if (g_str_equal(*tmp, item->name)) { + if (g_str_equal(t, item->name)) { goto found; } } - error_setg(errp, "Invalid -d option \"%s\"", *tmp); + error_setg(errp, "Invalid -d option \"%s\"", t); goto error; found: mask |= item->mask; @@ -546,6 +568,10 @@ void qemu_print_log_usage(FILE *f) for (item = qemu_log_items; item->mask != 0; item++) { fprintf(f, "%-15s %s\n", item->name, item->help); } +#ifdef CONFIG_TCG + fprintf(f, "tb_stats:WHICH enable translation block statistics" + " (all, exec, jit)\n"); +#endif #ifdef CONFIG_TRACE_LOG fprintf(f, "trace:PATTERN enable trace events\n"); fprintf(f, "\nUse \"-d trace:help\" to get a list of trace events.\n\n"); diff --git a/stubs/meson.build b/stubs/meson.build index ef6e39a64d..37ca25ea01 100644 --- a/stubs/meson.build +++ b/stubs/meson.build @@ -65,4 +65,5 @@ else stub_ss.add(files('qdev.c')) endif stub_ss.add(files('semihost-all.c')) +stub_ss.add(files('tb-stats.c')) stub_ss.add(when: 'CONFIG_VFIO_USER_SERVER', if_false: files('vfio-user-obj.c')) From patchwork Tue Oct 3 18:30:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 728814 Delivered-To: patch@linaro.org Received: by 2002:a5d:60c8:0:b0:31d:da82:a3b4 with SMTP id x8csp2285975wrt; Tue, 3 Oct 2023 11:33:43 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGF6BXm63mqTcDlaM5NrgpIPfwuaivb9C/YCF4RRF5lhTAFTiXAlg2KhvOToLo1HRYJbDT/ X-Received: by 2002:a05:620a:2a01:b0:775:bf2a:8df3 with SMTP id o1-20020a05620a2a0100b00775bf2a8df3mr554500qkp.7.1696358023129; Tue, 03 Oct 2023 11:33:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696358023; cv=none; d=google.com; s=arc-20160816; b=ZJnuyo803g6YD4QnuANl8iAABMsuwWf1wjTGyCjTjFwbVZbmKfrvSLUBqUZdMqhqNQ ZkpvAVv9JzW8E9Jfrp1oo5ntFWQHe3g0MzZjgrnLVMOX/bbPwT2Ozw/vGgThoOtdC4xc ZUvqnRJVF7688NjUVjeh2NhhM+kXwyROpOQQjSdW6F/zeW0/jW8NW/NWoSt0Xec6Ua/3 3CbcpEaVxSwRWvqiioQhkOI2Xe5wp5ymPsvx6j4iL6RJKPYhnA5DVjLAB2VE6xU4jJI5 eqA9MCG6GDTmRK9IuwLNSt/pHjQVA+OPFy9SX6hWiS3MMbLaDf9BpmRy/ZYvvupkd9yD rHsw== 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=KBfciibLofu5L0+I9/ztUVWgK/K31GmArzTT+bxRF1g=; fh=hCvX1k4zpzw9ZEQhAZzxrlFCd0WjbvmvmJzyvJcpNYw=; b=KyiXWvskbwn91tlFQZake50VbY7sbFffgZEzv8bIQFUAc9hzmD7apYGazDvOAe6QPI /hjotrpydm4UycYm5uHUif41rMSBlbKpIjAKmjRH479at0hA03k0LR/NMejBDr0aJay8 WVI4QB5ZWY8IjEGiXJRlD3rXOgEzqE3zrCO4/f9t0H9aTmN/xb/m+EzN5tblkGvcgyhv LJWTrKzXflDqAyfZOAdSkyEdNY4L0PlurgygnVlucDksICrEb3+6WTPv4EbvcUQXq8ad bKiNBdDSulUp7WjbnpPtaNWzKCjqF2s7GfWCtQFxXZ2tuCGGLc8DL8K10htEzm9xGWih WEhA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=F66fFEaY; 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 m11-20020a05620a24cb00b007758f54999bsi761333qkn.626.2023.10.03.11.33.42 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 03 Oct 2023 11:33:43 -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=F66fFEaY; 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 1qnkAu-00086D-0b; Tue, 03 Oct 2023 14:31:16 -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 1qnkAr-00084L-QQ for qemu-devel@nongnu.org; Tue, 03 Oct 2023 14:31:13 -0400 Received: from mail-pl1-x62f.google.com ([2607:f8b0:4864:20::62f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qnkAp-0001gU-Mw for qemu-devel@nongnu.org; Tue, 03 Oct 2023 14:31:13 -0400 Received: by mail-pl1-x62f.google.com with SMTP id d9443c01a7336-1c735473d1aso9837995ad.1 for ; Tue, 03 Oct 2023 11:31:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1696357870; x=1696962670; 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=KBfciibLofu5L0+I9/ztUVWgK/K31GmArzTT+bxRF1g=; b=F66fFEaYnoF5sb+kI28ylJu78XhYquQsEA02+Clzk30mFzJD6ap9y13otp7VCYH11E KNOAHXawZzDL4mAZpqhuFQyPkd9EX+O7Cod2t6iv/ap4EbIxXiMkuZLPhuZ1RI/rfq6W 3MZ/PBXFc8TvKjSWVfyJ1vsdxBNfwg52WuXy94tvj1HFI8hJvYInP5dyivXf0DmOavog Gj44yHnGRcSjbpZxlOXOFY/HKdsOkXVPBwwQ+UeQxUEwJzDVGBtYHXOM+4rFNE/7l3CO d4O2Y9OGNr+D8DFT/ys5PGqnLy29PoIhKT3Dop1C366zg1GIm28ptK5HeeasuMMzCm3+ OwFg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696357870; x=1696962670; 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=KBfciibLofu5L0+I9/ztUVWgK/K31GmArzTT+bxRF1g=; b=XL8Q7NxO+wx04FE6U24Ffm+gbYd1TDjYMvsosPNVUqGZWqrhg52wH412P6GqvD6fof /DxSzo5Cz2v44yvOjUBiUyZSDUODnFg8HvCu5aCru6J/4WBvDOg/slyMQyrnUHoPj/jL HFaAPJAeH6Tgc1z6GzvMUH0tK2uPownl7LACI0M4njKSLGsCkvnp7Yed2I/QZY6JLn0J c77TJJXfT/7ammCgdvy0ADQXY8A1d+f/Y5tV//zDv28nCTIq7YMEPORwEwmFtR/XbI0U 93JIY+pDQtzUiXoaIDPOEMt6P1FexHGycnzHohNZYL4VEpbiP9Hoyt+I5rhCuYLaUjWz zaFQ== X-Gm-Message-State: AOJu0Yy4slHssrQ/aGJOaB+ud40SkLxSJ+euEy2t2289xl57QpYyqQn1 Wbj0zjTvLt3+O1Dv49LQ6bTS0x5jZabo1YA7qtE= X-Received: by 2002:a17:902:d511:b0:1c3:a2ea:64cb with SMTP id b17-20020a170902d51100b001c3a2ea64cbmr503207plg.53.1696357870324; Tue, 03 Oct 2023 11:31:10 -0700 (PDT) Received: from stoup.. ([71.212.149.95]) by smtp.gmail.com with ESMTPSA id g7-20020a170902934700b001b7cbc5871csm1920432plp.53.2023.10.03.11.31.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Oct 2023 11:31:09 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: fei2.wu@intel.com, "Vanderson M. do Rosario" , =?utf-8?q?Alex_Benn=C3=A9e?= Subject: [PATCH v17 11/16] accel/tcg: Add tb_stats_collect and tb_stats_dump Date: Tue, 3 Oct 2023 11:30:53 -0700 Message-Id: <20231003183058.1639121-12-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231003183058.1639121-1-richard.henderson@linaro.org> References: <20231003183058.1639121-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::62f; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x62f.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 From: "Vanderson M. do Rosario" These functions will be used together to output statistics. Signed-off-by: Vanderson M. do Rosario Signed-off-by: Alex Bennée Signed-off-by: Fei Wu [rth: Split out of a larger patch] Signed-off-by: Richard Henderson --- include/tcg/tb-stats.h | 25 +++++++++ accel/tcg/tb-stats.c | 119 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 144 insertions(+) diff --git a/include/tcg/tb-stats.h b/include/tcg/tb-stats.h index 1ec0d13eff..edee73b63b 100644 --- a/include/tcg/tb-stats.h +++ b/include/tcg/tb-stats.h @@ -129,4 +129,29 @@ void tb_stats_reset_tbs(void); TBStatistics *tb_stats_lookup(tb_page_addr_t phys_pc, vaddr pc, uint32_t flags, uint64_t flags2); +/** + * tb_stats_collect: + * @max: maximum number of results + * @sort: sort function + * + * Collect all TBStatistics and return the first @max items, + * as dictated by the sort criteria. + */ +GPtrArray *tb_stats_collect(unsigned max, GCompareFunc sort); + +/* Sort functions for tb_stats_collect. */ +gint tb_stats_sort_by_spills(gconstpointer, gconstpointer); +gint tb_stats_sort_by_coverage(gconstpointer, gconstpointer); +gint tb_stats_sort_by_hg(gconstpointer, gconstpointer); + +/** + * tb_stats_dump: + * @s: structure to dump + * @index: label to emit + * + * Return a string with the rendering of the data in @s; + * @index is included in the output. + */ +GString *tb_stats_dump(TBStatistics *s, unsigned index); + #endif /* TCG_TB_STATS_H */ diff --git a/accel/tcg/tb-stats.c b/accel/tcg/tb-stats.c index 424c9a90ec..b2c9445b67 100644 --- a/accel/tcg/tb-stats.c +++ b/accel/tcg/tb-stats.c @@ -83,3 +83,122 @@ TBStatistics *tb_stats_lookup(tb_page_addr_t phys_pc, vaddr pc, } return s; } + +static void tb_stats_collect_iter(void *p, uint32_t hash, void *u) +{ + g_ptr_array_add(u, p); +} + +static void calculate_coverages(GPtrArray *array) +{ + double total_exec_count = 0; + guint i, n = array->len; + + for (i = 0; i < n; ++i) { + TBStatistics *s = g_ptr_array_index(array, i); + double avg_insns = 1; + double exec_count; + + if (s->translations.total) { + avg_insns = s->code.num_guest_inst / (double)s->translations.total; + } + exec_count = ((double)s->executions.atomic + s->executions.normal) + / avg_insns; + s->executions.coverage = exec_count; + total_exec_count += exec_count; + } + + for (i = 0; i < n; ++i) { + TBStatistics *s = g_ptr_array_index(array, i); + s->executions.coverage /= total_exec_count; + } +} + +GPtrArray *tb_stats_collect(unsigned max, GCompareFunc sort) +{ + GPtrArray *array = g_ptr_array_new(); + + /* + * Collect all TBStatistics and sort. + * Note that coverage data requires both execution and jit collection. + */ + qht_iter(&tb_ctx.stats, tb_stats_collect_iter, array); + calculate_coverages(array); + g_ptr_array_sort(array, sort); + + /* Truncate to the first MAX entries. */ + if (max < array->len) { + g_ptr_array_set_size(array, max); + } + return array; +} + +gint tb_stats_sort_by_spills(gconstpointer p1, gconstpointer p2) +{ + const TBStatistics *s1 = *(TBStatistics **)p1; + const TBStatistics *s2 = *(TBStatistics **)p2; + double c1 = (double)s1->code.spills / s1->translations.total; + double c2 = (double)s2->code.spills / s2->translations.total; + + return c1 < c2 ? 1 : c1 == c2 ? 0 : -1; +} + +gint tb_stats_sort_by_coverage(gconstpointer p1, gconstpointer p2) +{ + const TBStatistics *s1 = *(TBStatistics **)p1; + const TBStatistics *s2 = *(TBStatistics **)p2; + double c1 = s1->executions.coverage; + double c2 = s2->executions.coverage; + + return c1 < c2 ? 1 : c1 == c2 ? 0 : -1; +} + +gint tb_stats_sort_by_hg(gconstpointer p1, gconstpointer p2) +{ + const TBStatistics *s1 = *(TBStatistics **)p1; + const TBStatistics *s2 = *(TBStatistics **)p2; + double c1 = (double)s1->code.out_len / s1->code.num_guest_inst; + double c2 = (double)s2->code.out_len / s2->code.num_guest_inst; + + return c1 < c2 ? 1 : c1 == c2 ? 0 : -1; +} + +GString *tb_stats_dump(TBStatistics *s, unsigned index) +{ + unsigned n = s->tbs->len; + unsigned invalid = 0; + GString *buf; + + for (unsigned i = 0; i < n; ++i) { + TranslationBlock *tb = g_ptr_array_index(s->tbs, i); + if (tb->cflags & CF_INVALID) { + invalid += 1; + } + } + + buf = g_string_new(""); + g_string_append_printf(buf, + "TB id:%u | phys:0x" TB_PAGE_ADDR_FMT " virt=%" VADDR_PRIx + " flags:0x%08x invalid:%u/%u\n", + index, s->phys_pc, s->pc, s->flags, invalid, n - invalid); + + if (tb_stats_enabled & TB_STATS_EXEC) { + g_string_append_printf(buf, + "\t| exec:%lu/%lu coverage:%.2f%%\n", + s->executions.normal, s->executions.atomic, + s->executions.coverage * 100); + } + + if (tb_stats_enabled & TB_STATS_JIT) { + g_string_append_printf(buf, + "\t| trans:%lu inst: g:%lu op:%lu op_opt:%lu spills:%ld\n" + "\t| h/g (host bytes / guest insts): %f\n", + s->translations.total, + s->code.num_guest_inst / s->translations.total, + s->code.num_tcg_ops / s->translations.total, + s->code.num_tcg_ops_opt / s->translations.total, + s->code.spills / s->translations.total, + (double)s->code.out_len / s->code.num_guest_inst); + } + return buf; +} From patchwork Tue Oct 3 18:30:54 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 728816 Delivered-To: patch@linaro.org Received: by 2002:a5d:60c8:0:b0:31d:da82:a3b4 with SMTP id x8csp2286030wrt; Tue, 3 Oct 2023 11:33:53 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHlmz58vV3pLtN3/n7LcLrEJ7DHupFdIvUbJvl2KNbLubI+/Lj5sSgPpFDC8uKOmUFW8AEl X-Received: by 2002:a05:620a:2888:b0:768:1572:e9af with SMTP id j8-20020a05620a288800b007681572e9afmr499980qkp.8.1696358033023; Tue, 03 Oct 2023 11:33:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696358033; cv=none; d=google.com; s=arc-20160816; b=vHqShl/9bVCDCUbACxjvDYbDk4d7rLOxvgBRWRktDS6FSbjXrFGrq2AzCL5FpPhlBh 4pHRUXi0HoZkWLUjKIZM0rhxK3+B+KwPHrWXL7CfCKKivnID0/G2IuCoCZX+g0Gp9aJv C8/vZsc9BLSI8YEe6QqORHNz7nfwXLDKYcS7kO3plwIzyRUmVTynW27DRGBNvufbLyXc cmKbWiu/528L47+J2fUiD0m7p/1sxvmnTt3Ie6ox3pOUl1g2sNoEx8yMZAqEfUiVWlu0 /c3uCalMyu8C3l9dkXOORSCOsdShRbDfwlTEpfjfmG80Lt2u9pVNQCaWxeh9m2F/GB8k bmRQ== 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=A7XCl0qp/obfnCpndkgxp3n8szX7HRfUMiRlfSbBwN0=; fh=JxWBtSZstwhZxj1nqbhkYnE1e7Ds6gYyoAtro8tkvc0=; b=WljsmQPPZV4N27qDzAk284szKRH35rYTfaUObX0M7AjYi9OhgsfwoIylJWpRCvHHPB rFqpZL7DqP1LASYp0zNyBOVaDVMc9E2knapmff5JWEqGVEZfu+yjPVBExB6vGXDvU+vp TOvS3g0tDsqH11NQ1os2FYRIWFT81640YDMLTflQw+Z7nJD6uHWehp6ceJ8WBpLkZ4Ic UilGn6ynHUHmaiq7VtK1Uhsv8m46JwzDiBCQ0az901HtyFPvPh/ohhoLxsBabLZl8RDW g/tKnwUDG/D1GARYuZis1WyUabmVX0pJKkjfduLRj94AzRNOl0M+ivoHAxiuszRF0a+1 nMDw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=IZC+cuCP; 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 bi41-20020a05620a31a900b007759ca17486si767579qkb.560.2023.10.03.11.33.52 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 03 Oct 2023 11:33:53 -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=IZC+cuCP; 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 1qnkAv-000870-0L; Tue, 03 Oct 2023 14:31:17 -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 1qnkAs-000851-VB for qemu-devel@nongnu.org; Tue, 03 Oct 2023 14:31:14 -0400 Received: from mail-pl1-x62c.google.com ([2607:f8b0:4864:20::62c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qnkAr-0001gl-4k for qemu-devel@nongnu.org; Tue, 03 Oct 2023 14:31:14 -0400 Received: by mail-pl1-x62c.google.com with SMTP id d9443c01a7336-1c5ff5f858dso9834145ad.2 for ; Tue, 03 Oct 2023 11:31:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1696357871; x=1696962671; 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=A7XCl0qp/obfnCpndkgxp3n8szX7HRfUMiRlfSbBwN0=; b=IZC+cuCPV9xju/wVWSzvrRQbflt5yNBkSfW2yuHVeznB2G+/NQX0AIi//0tDLdxK5R g0LIdWG2o9tPoqYezIVbaLJRP9WeLFTA3/DnerNSY1dHfRhHCnToI9grWm+JUIxe2YKo YFuQJMFE+X1wB2DOMgtrd0DhOeDBXjjm4I4HLGggUVQ0VI2AyscUhvzojjmQCdi0Jl4W 5+UqolGtf6t6EFu5dNqLWKE0MTsD80wEQ25AKPu8lVmZ3pv3UJqsc7+3ApR7hnC8Ri1h vE93K2Gk2Oh0Lh84EVS916TBomLLXK7xsCeTNPBNftcIQ4jLUa7y5ddMNFSOnz4RH0xR w8uw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696357871; x=1696962671; 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=A7XCl0qp/obfnCpndkgxp3n8szX7HRfUMiRlfSbBwN0=; b=aeh4jXH1jZQKH+2NMaU3TXhkTJ5hVVopM+5i69iXh181Tls1K13iprerPw308qQomD 5VJaUpDtd/36x6ZaQJy68ikRJJOJg2A3OKNtuPUSK66ehlhT3EyDu2FXZKeHIne+OwXQ DlxpaC+xLS3sFHlCO3VmEEDhdDqV0s3eoGVAeE8CEBe/MG+HSuR+LrHZU+5YuwsFLspi aAVPSYdM7BqhYXR0Mr2xe8O1nemk0P5G+crm6AXlqNTmd4TEHVJxjHZxSZINuYE6166X QrxEl9BiLeTSsxQGEclco9vJ5vlyAYfsNcFgYSwaLtox7m6BC6s1nYJ7VxqN4v8G6Bjj PRZg== X-Gm-Message-State: AOJu0YyU8lgFGNTrSwn5SGDgWba4cQ3SJpZXcV6czxk/UlvkQBysmqse iU+AlJS34gtn/6YLNsmIoQbyAc7jVCTsGNdmej8= X-Received: by 2002:a17:903:187:b0:1c3:749f:6a5d with SMTP id z7-20020a170903018700b001c3749f6a5dmr430295plg.4.1696357871395; Tue, 03 Oct 2023 11:31:11 -0700 (PDT) Received: from stoup.. ([71.212.149.95]) by smtp.gmail.com with ESMTPSA id g7-20020a170902934700b001b7cbc5871csm1920432plp.53.2023.10.03.11.31.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Oct 2023 11:31:10 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: fei2.wu@intel.com Subject: [PATCH v17 12/16] softmmu: Export qemu_ram_ptr_length Date: Tue, 3 Oct 2023 11:30:54 -0700 Message-Id: <20231003183058.1639121-13-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231003183058.1639121-1-richard.henderson@linaro.org> References: <20231003183058.1639121-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::62c; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x62c.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 Signed-off-by: Richard Henderson Reviewed-by: Philippe Mathieu-Daudé --- include/exec/memory.h | 2 ++ softmmu/physmem.c | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/include/exec/memory.h b/include/exec/memory.h index ef23d65afc..ebdecf64a6 100644 --- a/include/exec/memory.h +++ b/include/exec/memory.h @@ -2874,6 +2874,8 @@ MemTxResult flatview_read_continue(FlatView *fv, hwaddr addr, hwaddr len, hwaddr addr1, hwaddr l, MemoryRegion *mr); void *qemu_map_ram_ptr(RAMBlock *ram_block, ram_addr_t addr); +void *qemu_ram_ptr_length(RAMBlock *ram_block, ram_addr_t addr, + hwaddr *size, bool lock); /* Internal functions, part of the implementation of address_space_read_cached * and address_space_write_cached. */ diff --git a/softmmu/physmem.c b/softmmu/physmem.c index 309653c722..69a853c27a 100644 --- a/softmmu/physmem.c +++ b/softmmu/physmem.c @@ -2182,8 +2182,8 @@ void *qemu_map_ram_ptr(RAMBlock *ram_block, ram_addr_t addr) * * Called within RCU critical section. */ -static void *qemu_ram_ptr_length(RAMBlock *ram_block, ram_addr_t addr, - hwaddr *size, bool lock) +void *qemu_ram_ptr_length(RAMBlock *ram_block, ram_addr_t addr, + hwaddr *size, bool lock) { RAMBlock *block = ram_block; if (*size == 0) { From patchwork Tue Oct 3 18:30:55 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 728802 Delivered-To: patch@linaro.org Received: by 2002:a5d:60c8:0:b0:31d:da82:a3b4 with SMTP id x8csp2285329wrt; Tue, 3 Oct 2023 11:32:03 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFeuUv9wy8ezFWlHgUZYgcyK5y4sdxXdPhhsw1c0rbNQcwrVEksAEAbd31boD7TpizhuZqH X-Received: by 2002:a0d:e610:0:b0:59f:6a35:3ccd with SMTP id p16-20020a0de610000000b0059f6a353ccdmr424773ywe.8.1696357923233; Tue, 03 Oct 2023 11:32:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696357923; cv=none; d=google.com; s=arc-20160816; b=cldsQu9AS2tx8pvgvRbSnjd45DQ7AcaplWArHetvAwRDz6NKOqdmc85FU6PCBLj+yh 4AaLqbmKd87xIa2fxDRpmdLJnnsbdWvMouueM1WAKboZK/WW/LpgOZDQrdyWdilSXS4b 7cZ3uMEm1baIcQ7jKXNHGcLIMTstanAmFjny9gvRBE+jIW7zO0UAMpuF3Syg/p/2ltRx k3ZgBCfwt024ipzUxzL3SfKKqEPKvtpZ8WJg+FL/WoSyqcd8mrKX+BnXyYx2MNov89/c b6SrKQXD3nSecFZGPSIteIihUrjh9sKKG/dvA6lv8Ls9FFxre7YHnDGf4iQettTK6d28 CCVw== 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=Nl5bSvinzi/NL70KSvl04+OPB0c89FFjcDMoM7uppFI=; fh=hCvX1k4zpzw9ZEQhAZzxrlFCd0WjbvmvmJzyvJcpNYw=; b=ug+v9T/LzP7rLdI5MQVeFWddJxaQ2TVre1xUeJkpH4UsycEvDPeZCNURue6h1IqK30 L5k9pKyuSShu4zFZ24zR9LWm2fTsLBMwBkovKBMF6FJ4qjRGt1UR/JpQH4bwL1UxGMub CMr4yXGx9YjW35IpYpK4v5KKrQdDOG3ZIXUZIrnZJImK8yntxOmkV3b38Z3Gg523UhKP iI2GgUhQcnvFN3r+05K11TKVuuWJLHFueAGZJHIzPseCnrbdmqGEs9xXBXiZCgVvlKvp vDYNO+TaXhib3CSqPVadCAQrSdyhR72vZQ0jaEhWJwjRDCSi3FYaw/kBrZ3/SjY9WZ3a 2ESA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=cVRaEPyK; 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 h19-20020ac85e13000000b004180fb583dfsi785357qtx.241.2023.10.03.11.32.02 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 03 Oct 2023 11:32:03 -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=cVRaEPyK; 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 1qnkAy-00087g-C6; Tue, 03 Oct 2023 14:31:20 -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 1qnkAt-000869-QV for qemu-devel@nongnu.org; Tue, 03 Oct 2023 14:31:15 -0400 Received: from mail-pf1-x42f.google.com ([2607:f8b0:4864:20::42f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qnkAr-0001gz-U5 for qemu-devel@nongnu.org; Tue, 03 Oct 2023 14:31:15 -0400 Received: by mail-pf1-x42f.google.com with SMTP id d2e1a72fcca58-69101022969so969511b3a.3 for ; Tue, 03 Oct 2023 11:31:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1696357872; x=1696962672; 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=Nl5bSvinzi/NL70KSvl04+OPB0c89FFjcDMoM7uppFI=; b=cVRaEPyKFETaGwy0DuTVM5w8uJ3gM7ixFypp2IufexG9vM8+TRyvzUrzeIZrgysRR8 wTwn3ThrGQwJJBui95yIPNF8RY2aMWL2j4JA43osYTTiVXBxovK/LvWvvsh+Xz0zRwaH YHXx6O6p0PDzFKtgBMG9IN0dakNzG9J8FR5PTCaJXDHwx5ZYr+FmJx7edd/ir95RMcNg Fo2gKy0lu2rFDSlvhJi7nZvGtr/0NRTJNjtPXFu3PVpd9++oR0B+cx2IUna1tx98AFCC KNiaViB1vMTgNWh8zXoDdDFCqduq1jDerLXQmuShFNPsvIV3Eqai5vUAKnmsHCaWlALU ZRaQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696357872; x=1696962672; 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=Nl5bSvinzi/NL70KSvl04+OPB0c89FFjcDMoM7uppFI=; b=UwEZ716qeqdrJvAeo8MQ/G7I+K7xLnOSbnVSJwpOiVNK0suBue/AtSXcAith6jVxjG 2zh0QuvrP3jRGmpReW4iiKrZp9fiLMqkUH7OvsMo3+bFKoyM+slkJQpTNld7h/sTmQYO 5ncKPITIsSZajSo7erXYEx5XAiHtiOW+28z2JCyXOqtyTZ0fALQovwEsUK6+9O2jmWER n4BL/N2LmYrAp4x9RKWSKG1xmiCEy9e5fN/jLplEWMxzCr92fKvS0NoAnFx5lh4yGcuh pCzsemNCU0cauGIE56JU8IpSMxNPDrVEJMq7pC6MWcUjpaYmq6BWPsoL985EULVmEiO9 7l6A== X-Gm-Message-State: AOJu0Yxyc5l33ELeFo2CZDVs73kp/pXwfFbwOS7iDN5e4bXhjmSEQYvO rLxJOXqBrSj61BUFn16rHEBoVTcWCYpA2DtSIBg= X-Received: by 2002:a05:6a21:328a:b0:14d:7b6:cf2f with SMTP id yt10-20020a056a21328a00b0014d07b6cf2fmr263862pzb.47.1696357872372; Tue, 03 Oct 2023 11:31:12 -0700 (PDT) Received: from stoup.. ([71.212.149.95]) by smtp.gmail.com with ESMTPSA id g7-20020a170902934700b001b7cbc5871csm1920432plp.53.2023.10.03.11.31.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Oct 2023 11:31:11 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: fei2.wu@intel.com, "Vanderson M. do Rosario" , =?utf-8?q?Alex_Benn=C3=A9e?= Subject: [PATCH v17 13/16] disas: Allow monitor_disas to read from ram_addr_t Date: Tue, 3 Oct 2023 11:30:55 -0700 Message-Id: <20231003183058.1639121-14-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231003183058.1639121-1-richard.henderson@linaro.org> References: <20231003183058.1639121-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::42f; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x42f.google.com X-Spam_score_int: 0 X-Spam_score: -0.1 X-Spam_bar: / X-Spam_report: (-0.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, PDS_OTHER_BAD_TLD=1.998, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no 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: "Vanderson M. do Rosario" Introduce a MonitorDisasSpace to replace the current is_physical boolean argument to monitor_disas. Generate an error if we attempt to read past the end of a single RAMBlock. Signed-off-by: Vanderson M. do Rosario Signed-off-by: Alex Bennée Signed-off-by: Fei Wu [rth: Split out of a larger patch; validate the RAMBlock size] Signed-off-by: Richard Henderson --- include/disas/disas.h | 8 +++++++- disas/disas-mon.c | 32 ++++++++++++++++++++++++++++++-- monitor/hmp-cmds-target.c | 27 ++++++++++++++++----------- 3 files changed, 53 insertions(+), 14 deletions(-) diff --git a/include/disas/disas.h b/include/disas/disas.h index 176775eff7..cd99b0ccd0 100644 --- a/include/disas/disas.h +++ b/include/disas/disas.h @@ -5,8 +5,14 @@ void disas(FILE *out, const void *code, size_t size); void target_disas(FILE *out, CPUState *cpu, uint64_t code, size_t size); +typedef enum { + MON_DISAS_GVA, /* virtual */ + MON_DISAS_GPA, /* physical */ + MON_DISAS_GRA, /* ram_addr_t */ +} MonitorDisasSpace; + void monitor_disas(Monitor *mon, CPUState *cpu, uint64_t pc, - int nb_insn, bool is_physical); + int nb_insn, MonitorDisasSpace space); char *plugin_disas(CPUState *cpu, uint64_t addr, size_t size); diff --git a/disas/disas-mon.c b/disas/disas-mon.c index 48ac492c6c..d486f64c92 100644 --- a/disas/disas-mon.c +++ b/disas/disas-mon.c @@ -23,9 +23,27 @@ physical_read_memory(bfd_vma memaddr, bfd_byte *myaddr, int length, return res == MEMTX_OK ? 0 : EIO; } +static int +ram_addr_read_memory(bfd_vma memaddr, bfd_byte *myaddr, int length, + struct disassemble_info *info) +{ + hwaddr hw_length; + void *p; + + RCU_READ_LOCK_GUARD(); + + hw_length = length; + p = qemu_ram_ptr_length(NULL, memaddr, &hw_length, false); + if (hw_length < length) { + return EIO; + } + memcpy(myaddr, p, length); + return 0; +} + /* Disassembler for the monitor. */ void monitor_disas(Monitor *mon, CPUState *cpu, uint64_t pc, - int nb_insn, bool is_physical) + int nb_insn, MonitorDisasSpace space) { int count, i; CPUDebug s; @@ -35,8 +53,18 @@ void monitor_disas(Monitor *mon, CPUState *cpu, uint64_t pc, s.info.fprintf_func = disas_gstring_printf; s.info.stream = (FILE *)ds; /* abuse this slot */ - if (is_physical) { + switch (space) { + case MON_DISAS_GVA: + /* target_read_memory set in disas_initialize_debug_target */ + break; + case MON_DISAS_GPA: s.info.read_memory_func = physical_read_memory; + break; + case MON_DISAS_GRA: + s.info.read_memory_func = ram_addr_read_memory; + break; + default: + g_assert_not_reached(); } s.info.buffer_vma = pc; diff --git a/monitor/hmp-cmds-target.c b/monitor/hmp-cmds-target.c index d9fbcac08d..476cf68e81 100644 --- a/monitor/hmp-cmds-target.c +++ b/monitor/hmp-cmds-target.c @@ -120,21 +120,20 @@ void hmp_info_registers(Monitor *mon, const QDict *qdict) } static void memory_dump(Monitor *mon, int count, int format, int wsize, - hwaddr addr, int is_physical) + hwaddr addr, MonitorDisasSpace space) { int l, line_size, i, max_digits, len; uint8_t buf[16]; uint64_t v; CPUState *cs = mon_get_cpu(mon); - if (!cs && (format == 'i' || !is_physical)) { + if (space == MON_DISAS_GVA || format == 'i') { monitor_printf(mon, "Can not dump without CPU\n"); return; } if (format == 'i') { - monitor_disas(mon, cs, addr, count, is_physical); - return; + monitor_disas(mon, cs, addr, count, space); } len = wsize * count; @@ -163,15 +162,21 @@ static void memory_dump(Monitor *mon, int count, int format, int wsize, } while (len > 0) { - if (is_physical) { - monitor_printf(mon, HWADDR_FMT_plx ":", addr); - } else { + switch (space) { + case MON_DISAS_GVA: monitor_printf(mon, TARGET_FMT_lx ":", (target_ulong)addr); + break; + case MON_DISAS_GPA: + monitor_printf(mon, HWADDR_FMT_plx ":", addr); + break; + default: + g_assert_not_reached(); } l = len; - if (l > line_size) + if (l > line_size) { l = line_size; - if (is_physical) { + } + if (space == MON_DISAS_GPA) { AddressSpace *as = cs ? cs->as : &address_space_memory; MemTxResult r = address_space_read(as, addr, MEMTXATTRS_UNSPECIFIED, buf, l); @@ -235,7 +240,7 @@ void hmp_memory_dump(Monitor *mon, const QDict *qdict) int size = qdict_get_int(qdict, "size"); target_long addr = qdict_get_int(qdict, "addr"); - memory_dump(mon, count, format, size, addr, 0); + memory_dump(mon, count, format, size, addr, MON_DISAS_GVA); } void hmp_physical_memory_dump(Monitor *mon, const QDict *qdict) @@ -245,7 +250,7 @@ void hmp_physical_memory_dump(Monitor *mon, const QDict *qdict) int size = qdict_get_int(qdict, "size"); hwaddr addr = qdict_get_int(qdict, "addr"); - memory_dump(mon, count, format, size, addr, 1); + memory_dump(mon, count, format, size, addr, MON_DISAS_GPA); } void *gpa2hva(MemoryRegion **p_mr, hwaddr addr, uint64_t size, Error **errp) From patchwork Tue Oct 3 18:30:56 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 728803 Delivered-To: patch@linaro.org Received: by 2002:a5d:60c8:0:b0:31d:da82:a3b4 with SMTP id x8csp2285373wrt; Tue, 3 Oct 2023 11:32:09 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGVpArh13MtT1kz9oOEXajCb4BjQ4rFPSesIi2Ja2fxV7g/LtpI6BXWCGXExJWvI8bxUGq0 X-Received: by 2002:ac8:7c47:0:b0:417:fa78:58a4 with SMTP id o7-20020ac87c47000000b00417fa7858a4mr234641qtv.42.1696357928933; Tue, 03 Oct 2023 11:32:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696357928; cv=none; d=google.com; s=arc-20160816; b=ImSvQ1JPv2yULkkA3vfC5gZ0PgJb5zz1dPgUY8YIMF6UN6dSUMNepE1xHqd2qx8kLY Jc+aOcPYrzXOJyFSuQnAuHnCbj5DLujPP4hE8pRYPzbnn2NP1yTC2KxOBh6H9Lt2x6dP TDxgWMt8VN+DFvxCCMJ/1ffe+qBVNYGakGVX5KmltbRpfYlYI4nDy81Tlhfe8Zdo09Hz 9loGdCo7V1Qw0Kh0RCWD5xhu1l8PF8x6aP9GXCMehKv0ShH+UdKW+L9fWLIvR8AgvdzB OkIzeaCA1ZYyk5gZcPO4fjePOo1bdhtQWpsz0mf6V/O2rOeSaxvcLGmEPPRqEDansQ0L 4Nig== 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=POqUGdOlnRWwwN/7EyrWIkFLDkOwEr6+ScS6TPAGSfI=; fh=JxWBtSZstwhZxj1nqbhkYnE1e7Ds6gYyoAtro8tkvc0=; b=eh1XvJZDItLXKCii3vfPWmtggGFQgbBHpfop0UxQ93koLj/ean4xUdBfA5DYzMYcn1 BEeGaekkRGWdNFVN5sEzWPBg01cIwIxCrYSc/o7+VhZtrCshaYU9DzWC6Mm2JqN/3pPU 9B3v7gu/hmVZaULIxIpJGdpCz22WJ+FqMAffAgp8ll39daXWtyRPYjA6o410ayBTSaGH GdZzJ7xqBS1uiv7AJUQi8i9NpOvGmGAgrSl4ZFBObM2a7NpsY+e8HyRU1UIoQiIMwEhr FUabf6Heh8DqpZh7dh8cRGmrN7fsu5NRHRBoOmF8rc82Yy2vfI90e36zah+etonQvPWY 5v/A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=T0TIP8A7; 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 v18-20020a05622a131200b00418009e63b4si777344qtk.135.2023.10.03.11.32.08 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 03 Oct 2023 11:32:08 -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=T0TIP8A7; 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 1qnkAw-000879-CW; Tue, 03 Oct 2023 14:31:18 -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 1qnkAu-00086g-Ng for qemu-devel@nongnu.org; Tue, 03 Oct 2023 14:31:16 -0400 Received: from mail-pl1-x635.google.com ([2607:f8b0:4864:20::635]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qnkAs-0001hD-TJ for qemu-devel@nongnu.org; Tue, 03 Oct 2023 14:31:16 -0400 Received: by mail-pl1-x635.google.com with SMTP id d9443c01a7336-1c60cec8041so9028365ad.3 for ; Tue, 03 Oct 2023 11:31:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1696357873; x=1696962673; 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=POqUGdOlnRWwwN/7EyrWIkFLDkOwEr6+ScS6TPAGSfI=; b=T0TIP8A7ufHt9wc3Uc0qx/A9hX1HbfKth08yfvzvRz9N+08yrthZN5BoBTH/u+/OfA rI7wwlVyWb6RZmYPDAr9J3m3C+wpgV28hLnBl1ym5PRLxPSpGNfpPuu8ePg2D+uj4O6a Z6OqPAndFkYbDdEl8qM8meNe1dgxmElJPkpeGmhhe+OzKz/tWC66az7KkJlOgsGv3eww hj9/aoU3V8npGku1GYUn1RerEQVDVw1eRHQRNYEuDKUSkLQVi1Q+s+lh/z69+02nNMif 3vDD/oFrQwgxTrRX5N6OiJpJCOs7OrlL5Od9peoTCOeN2vfynq0I4wOs6cWg5MyKqXia pQeQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696357873; x=1696962673; 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=POqUGdOlnRWwwN/7EyrWIkFLDkOwEr6+ScS6TPAGSfI=; b=Ii8fVdJayTakgEmKmpHcxsfp+dRMH+CtJV+z6ol1S5b46zA7nHC2hT90ajGVs8SIdY d+YRm12wWo0lk4SP/aTP8q4JF/Gsgokmn7tEEQAPzKQUZ2BcTwExqtm0o0JhsHmuqfkU azpPX0TVBpAEWGB97J+KObstbWPgORwq0DqcSNTUvJQcwl6EKOOljGoZRmEB8WO8TWRf NYR0RJBCP/ZwoPSbRostke/TSS64gojRdUkjbHwq3lrWeBA1PBh1ShWlIl3F6OSconh3 LQhlogxX+MZ42xj9N2pXX/S1d0bx3r96E0fOCr92i4rgo5/fJabmIr2ZCl3V7QrkERrn nFFg== X-Gm-Message-State: AOJu0YyTC1eb2IW5GJj64k2KQto+qj0/CoVS/IIlY5p7fPD+6BmCUqIQ 1zLFp/CMf5fJ+aVNLk9mHJUJQkM2lXEMcDoWmIY= X-Received: by 2002:a17:902:ab82:b0:1c1:e7b2:27ad with SMTP id f2-20020a170902ab8200b001c1e7b227admr316096plr.60.1696357873399; Tue, 03 Oct 2023 11:31:13 -0700 (PDT) Received: from stoup.. ([71.212.149.95]) by smtp.gmail.com with ESMTPSA id g7-20020a170902934700b001b7cbc5871csm1920432plp.53.2023.10.03.11.31.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Oct 2023 11:31:13 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: fei2.wu@intel.com Subject: [PATCH v17 14/16] monitor: Change MonitorDec.get_value return type to int64_t Date: Tue, 3 Oct 2023 11:30:56 -0700 Message-Id: <20231003183058.1639121-15-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231003183058.1639121-1-richard.henderson@linaro.org> References: <20231003183058.1639121-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::635; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x635.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 This matches the type of the pval parameter to get_monitor_def. This means that "monitor/hmp-target.h" itself is now target independent, even if monitor/hmp-target.c isn't. Signed-off-by: Richard Henderson Reviewed-by: Alex Bennée Reviewed-by: Alex Bennée --- include/monitor/hmp-target.h | 5 +---- monitor/hmp-target.c | 2 ++ target/i386/monitor.c | 4 ++-- target/ppc/ppc-qmp-cmds.c | 20 ++++++++++---------- target/sparc/monitor.c | 8 ++++---- 5 files changed, 19 insertions(+), 20 deletions(-) diff --git a/include/monitor/hmp-target.h b/include/monitor/hmp-target.h index d78e979f05..730507bd65 100644 --- a/include/monitor/hmp-target.h +++ b/include/monitor/hmp-target.h @@ -25,16 +25,13 @@ #ifndef MONITOR_HMP_TARGET_H #define MONITOR_HMP_TARGET_H -#include "cpu.h" - #define MD_TLONG 0 #define MD_I32 1 struct MonitorDef { const char *name; int offset; - target_long (*get_value)(Monitor *mon, const struct MonitorDef *md, - int val); + int64_t (*get_value)(Monitor *mon, const struct MonitorDef *md, int val); int type; }; diff --git a/monitor/hmp-target.c b/monitor/hmp-target.c index 1eb72ac1bf..ed7149b5ff 100644 --- a/monitor/hmp-target.c +++ b/monitor/hmp-target.c @@ -35,6 +35,8 @@ #include "qapi/qapi-commands-machine.h" #include "qapi/error.h" #include "qemu/cutils.h" +#include "cpu-param.h" +#include "exec/target_long.h" #if defined(TARGET_S390X) #include "hw/s390x/storage-keys.h" diff --git a/target/i386/monitor.c b/target/i386/monitor.c index 6512846327..6759ec7ca0 100644 --- a/target/i386/monitor.c +++ b/target/i386/monitor.c @@ -600,8 +600,8 @@ void hmp_mce(Monitor *mon, const QDict *qdict) } } -static target_long monitor_get_pc(Monitor *mon, const struct MonitorDef *md, - int val) +static int64_t monitor_get_pc(Monitor *mon, const struct MonitorDef *md, + int val) { CPUArchState *env = mon_get_cpu_env(mon); return env->eip + env->segs[R_CS].base; diff --git a/target/ppc/ppc-qmp-cmds.c b/target/ppc/ppc-qmp-cmds.c index f9acc21056..ea2c152228 100644 --- a/target/ppc/ppc-qmp-cmds.c +++ b/target/ppc/ppc-qmp-cmds.c @@ -32,8 +32,8 @@ #include "cpu-models.h" #include "cpu-qom.h" -static target_long monitor_get_ccr(Monitor *mon, const struct MonitorDef *md, - int val) +static int64_t monitor_get_ccr(Monitor *mon, const struct MonitorDef *md, + int val) { CPUArchState *env = mon_get_cpu_env(mon); unsigned int u; @@ -43,15 +43,15 @@ static target_long monitor_get_ccr(Monitor *mon, const struct MonitorDef *md, return u; } -static target_long monitor_get_xer(Monitor *mon, const struct MonitorDef *md, - int val) +static int64_t monitor_get_xer(Monitor *mon, const struct MonitorDef *md, + int val) { CPUArchState *env = mon_get_cpu_env(mon); return cpu_read_xer(env); } -static target_long monitor_get_decr(Monitor *mon, const struct MonitorDef *md, - int val) +static int64_t monitor_get_decr(Monitor *mon, const struct MonitorDef *md, + int val) { CPUArchState *env = mon_get_cpu_env(mon); if (!env->tb_env) { @@ -60,8 +60,8 @@ static target_long monitor_get_decr(Monitor *mon, const struct MonitorDef *md, return cpu_ppc_load_decr(env); } -static target_long monitor_get_tbu(Monitor *mon, const struct MonitorDef *md, - int val) +static int64_t monitor_get_tbu(Monitor *mon, const struct MonitorDef *md, + int val) { CPUArchState *env = mon_get_cpu_env(mon); if (!env->tb_env) { @@ -70,8 +70,8 @@ static target_long monitor_get_tbu(Monitor *mon, const struct MonitorDef *md, return cpu_ppc_load_tbu(env); } -static target_long monitor_get_tbl(Monitor *mon, const struct MonitorDef *md, - int val) +static int64_t monitor_get_tbl(Monitor *mon, const struct MonitorDef *md, + int val) { CPUArchState *env = mon_get_cpu_env(mon); if (!env->tb_env) { diff --git a/target/sparc/monitor.c b/target/sparc/monitor.c index 73f15aa272..24cc3dbf68 100644 --- a/target/sparc/monitor.c +++ b/target/sparc/monitor.c @@ -40,8 +40,8 @@ void hmp_info_tlb(Monitor *mon, const QDict *qdict) } #ifndef TARGET_SPARC64 -static target_long monitor_get_psr(Monitor *mon, const struct MonitorDef *md, - int val) +static int64_t monitor_get_psr(Monitor *mon, const struct MonitorDef *md, + int val) { CPUArchState *env = mon_get_cpu_env(mon); @@ -49,8 +49,8 @@ static target_long monitor_get_psr(Monitor *mon, const struct MonitorDef *md, } #endif -static target_long monitor_get_reg(Monitor *mon, const struct MonitorDef *md, - int val) +static int64_t monitor_get_reg(Monitor *mon, const struct MonitorDef *md, + int val) { CPUArchState *env = mon_get_cpu_env(mon); return env->regwptr[val]; From patchwork Tue Oct 3 18:30:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 728810 Delivered-To: patch@linaro.org Received: by 2002:a5d:60c8:0:b0:31d:da82:a3b4 with SMTP id x8csp2285782wrt; Tue, 3 Oct 2023 11:33:10 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHJ0vHSBCZnxV3wl+sV31Vf8uE6Mvj6U3tnY8vilKixWlCaBzxYkJ553lDglNfDE68tHoix X-Received: by 2002:ad4:598f:0:b0:658:3af3:3d9a with SMTP id ek15-20020ad4598f000000b006583af33d9amr185191qvb.1.1696357990732; Tue, 03 Oct 2023 11:33:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696357990; cv=none; d=google.com; s=arc-20160816; b=m7G1GP3adGUPgoQ4GDM8s5NaMnxAR1r8YgZdcxYcOfRoHU1NY7B6PKsk/LkRZHDVyq c4vF1BVC5A0ru4PgCGJL8xGpCRW0vk2rq/YD+h+qceY9g7HuFfr968QCEj3ExLdAFClx jU0PHCGEfYdIzuztAbnJhWWjNOQHrSNREEKGso4OIB6naXI140xoRpEtqMTYEoxCSEcP daB3ReH23fbNZxMjAtWCCRypwqWTsOAxNNvZjjvhaV53PlCvGWsCkm3VJycbHYgKYiiM /djy8KP6DL0bV49drmunrp90gxRl2Q7lXnQ+9H5oe4QZbmE1NTnPDUJWyH6WJBU8w5uo Huwg== 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=4tSjnCwo3pjRgK09vqvCcwYk3QeyeC6thVIvJ/sf7yQ=; fh=hCvX1k4zpzw9ZEQhAZzxrlFCd0WjbvmvmJzyvJcpNYw=; b=HfvygvuKzwOIMVggFpYrjIpGpsxcAmGGurFjqKiijnduYLLbN8LXQcHBak/QOpEg+/ cQ+JdD0uHmegYQ7I1GHeQIQVEFrPnCuhCK6l7XbinTu5c5ZVo+fLnS8hCCteVBYbGFY3 +eN+dgDgTrQJZB5E5H4xnVX1Z+/ShWZtaOXrpDO+9dy5M6QMIsPqFcaz9+n/QU9EYM7z cjSRzwVIlUmSpSZpS41bfLwua5fvEiz9hy6RkqE+txAYpj5UNZmOeV1WaMBxXIoFHTs0 ogr27X4E8dqV8naqHhPH4i+tl3c+Ps6JAODFZVoZeOVOe8JDNbGrRdGsVq+hyu1+nD1i ObkA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=uiXs2b2k; 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 bq13-20020a05620a468d00b00767c77c80b5si736566qkb.477.2023.10.03.11.33.10 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 03 Oct 2023 11:33:10 -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=uiXs2b2k; 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 1qnkB2-00088g-8n; Tue, 03 Oct 2023 14:31:24 -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 1qnkAx-00087h-P8 for qemu-devel@nongnu.org; Tue, 03 Oct 2023 14:31:20 -0400 Received: from mail-pl1-x62d.google.com ([2607:f8b0:4864:20::62d]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qnkAu-0001hL-Lc for qemu-devel@nongnu.org; Tue, 03 Oct 2023 14:31:19 -0400 Received: by mail-pl1-x62d.google.com with SMTP id d9443c01a7336-1c62d61dc96so9275535ad.0 for ; Tue, 03 Oct 2023 11:31:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1696357874; x=1696962674; 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=4tSjnCwo3pjRgK09vqvCcwYk3QeyeC6thVIvJ/sf7yQ=; b=uiXs2b2kPfZBv5r3POhKAuAqyI0JfNAnA+wvBvbcJmOd4opSmIMu0JcrZ6HcUTaxBL NtKYXEN9YUcnxArYNvs6yTWWiGxAOaNnfLVALi7YUjUlAxLMHEXokWeC2NmksBe44JLf qtJnVG8Mi0oQspKmalHnBwEc2Ig+fDeWXW/elmEAh7IBrSa1+ZmWdI4zaAeZ0V7vY+A/ CaLHR5jPTROPfPq16GC9ItMiCmc4DL+rMZiX1T0pQn0ne7Dr+Tk92mar9tDo6RGc+ENO YyzTIL27VsgpEKvFDKEC1l5LryFSg7MlyYHYhZv7bGiskomZYPXg9wHU4gp0U7zqJYch 4Dcg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696357874; x=1696962674; 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=4tSjnCwo3pjRgK09vqvCcwYk3QeyeC6thVIvJ/sf7yQ=; b=cnJtr0Vv2pgNphR1NefLrNZ0pBkgGo3gRQ1HZZqBc7pNhy5h2mkrhEx2TM6k5yKNN+ 50BNFJsbqdFXR+JweBtASLtqRRECO14XBVLJDrkaeLm3ZcJZaWAu8l+/gGZ4ndfVe/ES yEHJB6mWTJJ+01sbHHPhJR8yBcUgyC+uV1aAMNF44nO8CrU1irM/EPNHXauAf0NBgpv0 BZowhJOZbhqauAGSz55J/+FrphlvfUfYzGVSMK1Xk6UXzwqiGpxTh7PX9L3qJ3iuxWm3 VUjtrMkYrTAaaWo28zfRat3hJJMYDk1OTeNGGFrOD2QCYNvNUrhurSx7KnkvAnL1yZOp ahVw== X-Gm-Message-State: AOJu0Yz5/ueZEXOAvgDlK0SbOklsGd11wfihG5E7miJdwNjWE7VxVGNf ft4HLjZD9bro7rGrG2VdQto9O5x94efKja2ETw8= X-Received: by 2002:a17:902:ee89:b0:1c1:f5a6:bdfa with SMTP id a9-20020a170902ee8900b001c1f5a6bdfamr389810pld.7.1696357874205; Tue, 03 Oct 2023 11:31:14 -0700 (PDT) Received: from stoup.. ([71.212.149.95]) by smtp.gmail.com with ESMTPSA id g7-20020a170902934700b001b7cbc5871csm1920432plp.53.2023.10.03.11.31.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Oct 2023 11:31:13 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: fei2.wu@intel.com, "Vanderson M. do Rosario" , =?utf-8?q?Alex_Benn=C3=A9e?= Subject: [PATCH v17 15/16] accel/tcg: Add info [tb-list|tb] commands to HMP Date: Tue, 3 Oct 2023 11:30:57 -0700 Message-Id: <20231003183058.1639121-16-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231003183058.1639121-1-richard.henderson@linaro.org> References: <20231003183058.1639121-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::62d; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x62d.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 From: "Vanderson M. do Rosario" These commands allow the exploration of TBs generated by the TCG. Understand which one hotter, with more guest/host instructions, and examine the guest code. The goal of this command is to allow the dynamic exploration of TCG behavior and code quality. Therefore, for now, a corresponding QMP command is not worthwhile. Example of output: ------------------------------ TB id:0 | phys:0xa21f562e virt:0x0000000000000000 flags:0x00028010 0 inv/1 | exec:6171503732/0 guest inst cov:94.77% | trans:1 ints: g:8 op:28 op_opt:24 spills:0 | h/g (host bytes / guest insts): 37.000000 0xa21f562e: 00002797 auipc a5,8192 # 0xa21f762e 0xa21f5632: a2278793 addi a5,a5,-1502 0xa21f5636: 639c ld a5,0(a5) 0xa21f5638: 00178713 addi a4,a5,1 0xa21f563c: 00002797 auipc a5,8192 # 0xa21f763c 0xa21f5640: a1478793 addi a5,a5,-1516 0xa21f5644: e398 sd a4,0(a5) 0xa21f5646: b7e5 j -24 # 0xa21f562e Signed-off-by: Vanderson M. do Rosario Signed-off-by: Alex Bennée Signed-off-by: Fei Wu [rth: Split out of a larger patch] Signed-off-by: Richard Henderson --- accel/tcg/tb-context.h | 2 + accel/tcg/monitor.c | 91 ++++++++++++++++++++++++++++++++++++++++++ accel/tcg/tb-stats.c | 2 + hmp-commands-info.hx | 14 +++++++ 4 files changed, 109 insertions(+) diff --git a/accel/tcg/tb-context.h b/accel/tcg/tb-context.h index 4b1abe392b..29d87200b6 100644 --- a/accel/tcg/tb-context.h +++ b/accel/tcg/tb-context.h @@ -35,6 +35,8 @@ struct TBContext { /* statistics */ unsigned tb_flush_count; unsigned tb_phys_invalidate_count; + + GPtrArray *last_search; }; extern TBContext tb_ctx; diff --git a/accel/tcg/monitor.c b/accel/tcg/monitor.c index 370fea883c..1be3218715 100644 --- a/accel/tcg/monitor.c +++ b/accel/tcg/monitor.c @@ -15,12 +15,14 @@ #include "qapi/qmp/qdict.h" #include "monitor/monitor.h" #include "monitor/hmp.h" +#include "monitor/hmp-target.h" #include "sysemu/cpus.h" #include "sysemu/cpu-timers.h" #include "sysemu/tcg.h" #include "tcg/tcg.h" #include "tcg/tb-stats.h" #include "exec/tb-flush.h" +#include "disas/disas.h" #include "internal-common.h" #include "tb-context.h" @@ -303,10 +305,99 @@ static void hmp_tbstats(Monitor *mon, const QDict *qdict) RUN_ON_CPU_HOST_INT(flags)); } +static void hmp_info_tblist(Monitor *mon, const QDict *qdict) +{ + int max; + const char *sortedby_str; + GCompareFunc sort; + GPtrArray *array; + + if (!tcg_enabled()) { + monitor_printf(mon, "Only available with accel=tcg\n"); + return; + } + if (!tb_stats_enabled) { + monitor_printf(mon, "TB statistics not being recorded\n"); + return; + } + + max = qdict_get_try_int(qdict, "number", 10); + sortedby_str = qdict_get_try_str(qdict, "sortedby"); + + if (sortedby_str == NULL || g_str_equal(sortedby_str, "hotness")) { + sort = tb_stats_sort_by_coverage; + } else if (g_str_equal(sortedby_str, "hg")) { + sort = tb_stats_sort_by_hg; + } else if (g_str_equal(sortedby_str, "spills")) { + sort = tb_stats_sort_by_spills; + } else { + monitor_printf(mon, "Sort options are: hotness, hg, spills\n"); + return; + } + + g_ptr_array_unref(tb_ctx.last_search); + tb_ctx.last_search = NULL; + + array = tb_stats_collect(max, sort); + max = array->len; + if (max == 0) { + monitor_printf(mon, "No TB statistics collected\n"); + g_ptr_array_free(array, true); + return; + } + + for (int i = 0; i < max; ++i) { + TBStatistics *s = g_ptr_array_index(array, i); + g_autoptr(GString) buf = tb_stats_dump(s, i); + monitor_puts(mon, buf->str); + } + + /* Remember for the next "info tb" */ + tb_ctx.last_search = array; +} + +static void hmp_info_tb(Monitor *mon, const QDict *qdict) +{ + GPtrArray *array; + int id; + + if (!tcg_enabled()) { + monitor_printf(mon, "Only available with accel=tcg\n"); + return; + } + + array = g_ptr_array_ref(tb_ctx.last_search); + if (!array) { + monitor_printf(mon, "No TB statistics collected\n"); + return; + } + + id = qdict_get_int(qdict, "id"); + if (id < array->len) { + TBStatistics *s = g_ptr_array_index(array, id); + g_autoptr(GString) buf = tb_stats_dump(s, id); + monitor_puts(mon, buf->str); + + for (int i = s->tbs->len - 1; i >= 0; --i) { + TranslationBlock *tb = g_ptr_array_index(s->tbs, i); + if (!(tb->cflags & CF_INVALID)) { + monitor_disas(mon, mon_get_cpu(mon), s->phys_pc, + tb->icount, MON_DISAS_GRA); + } + } + } else { + monitor_printf(mon, "TB %d information not recorded\n", id); + } + + g_ptr_array_unref(array); +} + static void hmp_tcg_register(void) { monitor_register_hmp_info_hrt("jit", qmp_x_query_jit); monitor_register_hmp_info_hrt("opcount", qmp_x_query_opcount); monitor_register_hmp("tb_stats", false, hmp_tbstats); + monitor_register_hmp("tb-list", true, hmp_info_tblist); + monitor_register_hmp("tb", true, hmp_info_tb); } type_init(hmp_tcg_register); diff --git a/accel/tcg/tb-stats.c b/accel/tcg/tb-stats.c index b2c9445b67..0f84c14a88 100644 --- a/accel/tcg/tb-stats.c +++ b/accel/tcg/tb-stats.c @@ -43,6 +43,8 @@ void tb_stats_init(uint32_t flags) CODE_GEN_HTABLE_SIZE, QHT_MODE_AUTO_RESIZE); } } else { + g_ptr_array_unref(tb_ctx.last_search); + tb_ctx.last_search = NULL; qht_iter(&tb_ctx.stats, tb_stats_free, NULL); qht_destroy(&tb_ctx.stats); } diff --git a/hmp-commands-info.hx b/hmp-commands-info.hx index f5b37eb74a..8e9b64cf7f 100644 --- a/hmp-commands-info.hx +++ b/hmp-commands-info.hx @@ -262,6 +262,20 @@ ERST .params = "", .help = "show dynamic compiler info", }, + { + .name = "tb-list", + .args_type = "number:i?,sortedby:s?", + .params = "[number sortedby]", + .help = "show a [number] translated blocks sorted by [sortedby]" + "sortedby opts: hotness hg spills", + }, + { + .name = "tb", + .args_type = "id:i", + .params = "id", + .help = "show information about one translated block by id," + "from the result of a previous \"info tb-list\"", + }, #endif SRST From patchwork Tue Oct 3 18:30:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 728801 Delivered-To: patch@linaro.org Received: by 2002:a5d:60c8:0:b0:31d:da82:a3b4 with SMTP id x8csp2285328wrt; Tue, 3 Oct 2023 11:32:03 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGe86KM0OrRFdekIOL3giwDKRJu5uF2sqVncM8UxneXFeNJ+CxJXOt5vlVTb+/2ktdc6Mxm X-Received: by 2002:a25:870e:0:b0:d78:2967:93ea with SMTP id a14-20020a25870e000000b00d78296793eamr70131ybl.1.1696357923234; Tue, 03 Oct 2023 11:32:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696357923; cv=none; d=google.com; s=arc-20160816; b=wIOTIy7PEbXjlr5VkCt/sg/ux1GaEMc6J5Fwtkfcdd3eA4tT2EluvxyztEqFwlqnr6 WjC+6gBM6X+x6rQcMIuXmRYKpqhLFPNpTWB0VSn2aZfFrfTS0FlgO81LZJ8rvVmzqeDz mlurIUHga8+RZrgMeC/4NobtU0Olus6OSNk4/GFOxvIhvLzZUHwUNV/tm72BNKjvw11x /pQMVGOOzbDDj6tPtUswtFUuBNhWJP8qBWP4UtErf59VkgUoZH1ZU7U6XVFWemNpQOTK jVcKhis7Ymv2O6z/ioROProgEI2PC8YODUMEgF28pTocBQUeejmi0SDXzjr5jLnG4YOk ZBjA== 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=dU5PrzEh8RB8pR6X9cq1FoT7Iyzl/Xdd//HRPtAH/3k=; fh=JxWBtSZstwhZxj1nqbhkYnE1e7Ds6gYyoAtro8tkvc0=; b=Cs7VrhHu0c8h2T8NfDOX1xPmzT4X9QFKIfjmVKnzelTOayxbCrmurE9ozuUIfCtjxq QWeK6iOg3+Y2OEzPdHGNd1CmPOwuJg094afgJ2bAsC6wVAVORdxGIJ6kpBDYWSkdhBZZ x+Fp0Nk+T9np9gt8X2vtUQOqc087hx61OslJp1hmNZyZfYvNoPZO8V/XxVQzcgE5lwf2 8B1wwYfVD3XYRbOF0eZZaDNiU5xgmPTC/Ls6MCw/geQU36VBV6rFWdz3arWoiryR5ur0 LKRocbFQHvAvjKRdbNXo+8IPxnKCX3scd/z9KMRa6MMckQ0Ei2F6u06UmbCsUFTTVce3 dK+w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=os2wkwbn; 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 s17-20020a0cdc11000000b00656474144e8si751367qvk.435.2023.10.03.11.32.02 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 03 Oct 2023 11:32:03 -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=os2wkwbn; 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 1qnkB0-00088O-Jx; Tue, 03 Oct 2023 14:31:22 -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 1qnkAw-00087B-C4 for qemu-devel@nongnu.org; Tue, 03 Oct 2023 14:31:18 -0400 Received: from mail-pl1-x633.google.com ([2607:f8b0:4864:20::633]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qnkAu-0001hT-AA for qemu-devel@nongnu.org; Tue, 03 Oct 2023 14:31:18 -0400 Received: by mail-pl1-x633.google.com with SMTP id d9443c01a7336-1c0ecb9a075so9569675ad.2 for ; Tue, 03 Oct 2023 11:31:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1696357875; x=1696962675; 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=dU5PrzEh8RB8pR6X9cq1FoT7Iyzl/Xdd//HRPtAH/3k=; b=os2wkwbnjEnWR4VqxbOz+4Zhia/xT6n4++S+MjvIXmKMXc4qpifcDw7jIUVRPl0LnW J+1apyn3b9dwqhmuBvjPXH506DOuK9cwTZeXDpQbBpxPwb/iULjsmuEPisqm31U3AewB Ywu1K8gDsUept5M209FR/7kwa3VTpBR9TrUJW5jea2YGsEAk7wTrCvZrVk/B0Yyo9o6i TFjmsGKGhlo/bftwcegmz17/s6TCg8tYBbeFWJfqKXaTt1CEfNCMxp1xV7Nn/yEeRprm E0SW5yCHKN6J/VM4UtIPMkJJs0gOSSxsUa3IQkj6Vua/MkdvzNpO39J3UcgwrWCnkfXK 5vDA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696357875; x=1696962675; 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=dU5PrzEh8RB8pR6X9cq1FoT7Iyzl/Xdd//HRPtAH/3k=; b=ZXVis++V0SPFE58TLzvokPoiLMI91DPeLv5/lH0VFmgQ2qetu0VaIRZqsaQ1ySiy6O MBPtSEQ7zkjWH1A9EwITRq04wAVjPaoNOyrEIW0WucTyEBMVP5ah/eIqXkQY8te49CBw j2ZQPUSo0+wTF3FfN8xb7ky1CT7W9+odRy/qf3vyiIowEAOVWjW3uskiM4WO3XkShS2F PU3XaYlqz9Crrk6OtagIjS6kI6B6IjBWQqih+Os9lGAAk/nMlcnSReTtGrpKEskQbd4r sP+X2dROv2OxzLHqVyK5e5vw+V+a6a6iUF8hAcLccn6ZkVOGqoE2yN28e+82XFI8Mz8b 95Lg== X-Gm-Message-State: AOJu0YzZ4DATKISnuWSnGGY+fDOuC+Iej0xGPebiEgcqxX5/sDFQkgw3 gF1W3LJZlwzWpWlI6YY73wR7KkeSSzqKY/nDXAc= X-Received: by 2002:a17:902:720a:b0:1bc:7001:6e62 with SMTP id ba10-20020a170902720a00b001bc70016e62mr291906plb.35.1696357875010; Tue, 03 Oct 2023 11:31:15 -0700 (PDT) Received: from stoup.. ([71.212.149.95]) by smtp.gmail.com with ESMTPSA id g7-20020a170902934700b001b7cbc5871csm1920432plp.53.2023.10.03.11.31.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Oct 2023 11:31:14 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: fei2.wu@intel.com Subject: [PATCH v17 16/16] accel/tcg: Dump hot TBs at the end of the execution Date: Tue, 3 Oct 2023 11:30:58 -0700 Message-Id: <20231003183058.1639121-17-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231003183058.1639121-1-richard.henderson@linaro.org> References: <20231003183058.1639121-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::633; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x633.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 From: Fei Wu Dump the hottest TBs if -d tb_stats:{all,jit,exec}[:dump_num_at_exit] Signed-off-by: Fei Wu Signed-off-by: Richard Henderson --- bsd-user/bsd-proc.h | 2 ++ include/tcg/tb-stats.h | 10 +++++++++- accel/tcg/monitor.c | 8 +++++--- accel/tcg/tb-stats.c | 27 ++++++++++++++++++++++++++- linux-user/exit.c | 10 ++++++---- softmmu/runstate.c | 2 ++ stubs/tb-stats.c | 6 +++++- util/log.c | 20 ++++++++++++++++---- 8 files changed, 71 insertions(+), 14 deletions(-) diff --git a/bsd-user/bsd-proc.h b/bsd-user/bsd-proc.h index 0e1d461c4c..84b52b399a 100644 --- a/bsd-user/bsd-proc.h +++ b/bsd-user/bsd-proc.h @@ -21,12 +21,14 @@ #define BSD_PROC_H_ #include +#include "tcg/tb-stats.h" /* exit(2) */ static inline abi_long do_bsd_exit(void *cpu_env, abi_long arg1) { gdb_exit(arg1); qemu_plugin_user_exit(); + tb_stats_dump_atexit(); _exit(arg1); return 0; diff --git a/include/tcg/tb-stats.h b/include/tcg/tb-stats.h index edee73b63b..d3cca94f84 100644 --- a/include/tcg/tb-stats.h +++ b/include/tcg/tb-stats.h @@ -41,11 +41,12 @@ extern uint32_t tb_stats_enabled; /** * tb_stats_init: * @flags: TB_STATS_* flags to enable. + * @atexit: count of hottest tbs to log. * * Initialize translation block statistics, enabling @flags. * If @flags is 0, disable all statistics. */ -void tb_stats_init(uint32_t flags); +void tb_stats_init(uint32_t flags, uint32_t atexit); /* * This struct stores statistics such as execution count of the @@ -154,4 +155,11 @@ gint tb_stats_sort_by_hg(gconstpointer, gconstpointer); */ GString *tb_stats_dump(TBStatistics *s, unsigned index); +/** + * tb_stats_dump_atexit: + * + * Log any requested TBs at end of execution. + */ +void tb_stats_dump_atexit(void); + #endif /* TCG_TB_STATS_H */ diff --git a/accel/tcg/monitor.c b/accel/tcg/monitor.c index 1be3218715..7719583654 100644 --- a/accel/tcg/monitor.c +++ b/accel/tcg/monitor.c @@ -245,7 +245,7 @@ static void tb_stats_init_safe(CPUState *cpu, run_on_cpu_data icmd) { uint32_t flags = icmd.host_int; - tb_stats_init(flags); + tb_stats_init(flags, 0); tb_flush(cpu); } @@ -335,8 +335,10 @@ static void hmp_info_tblist(Monitor *mon, const QDict *qdict) return; } - g_ptr_array_unref(tb_ctx.last_search); - tb_ctx.last_search = NULL; + if (tb_ctx.last_search) { + g_ptr_array_unref(tb_ctx.last_search); + tb_ctx.last_search = NULL; + } array = tb_stats_collect(max, sort); max = array->len; diff --git a/accel/tcg/tb-stats.c b/accel/tcg/tb-stats.c index 0f84c14a88..62a6228799 100644 --- a/accel/tcg/tb-stats.c +++ b/accel/tcg/tb-stats.c @@ -8,10 +8,12 @@ #include "qemu/osdep.h" #include "qemu/xxhash.h" +#include "qemu/log.h" #include "tcg/tb-stats.h" #include "tb-context.h" uint32_t tb_stats_enabled; +static uint32_t tb_stats_atexit; static bool tb_stats_cmp(const void *ap, const void *bp) { @@ -34,7 +36,7 @@ static void tb_stats_free(void *p, uint32_t hash, void *userp) g_free(s); } -void tb_stats_init(uint32_t flags) +void tb_stats_init(uint32_t flags, uint32_t atexit) { tb_stats_enabled = flags; if (flags) { @@ -48,6 +50,14 @@ void tb_stats_init(uint32_t flags) qht_iter(&tb_ctx.stats, tb_stats_free, NULL); qht_destroy(&tb_ctx.stats); } + + /* + * This function is also used by HMP, when atexit is 0. + * Preserve the value set from the command-line. + */ + if (atexit) { + tb_stats_atexit = atexit; + } } static void tb_stats_reset(void *p, uint32_t hash, void *userp) @@ -204,3 +214,18 @@ GString *tb_stats_dump(TBStatistics *s, unsigned index) } return buf; } + +void tb_stats_dump_atexit(void) +{ + if (tb_stats_enabled && tb_stats_atexit) { + g_autoptr(GPtrArray) array = + tb_stats_collect(tb_stats_atexit, tb_stats_sort_by_coverage); + + for (uint32_t i = 0, n = array->len; i < n; ++i) { + TBStatistics *s = g_ptr_array_index(array, i); + g_autoptr(GString) str = tb_stats_dump(s, i); + + qemu_log("%s\n", str->str); + } + } +} diff --git a/linux-user/exit.c b/linux-user/exit.c index 50266314e0..4487aaac7e 100644 --- a/linux-user/exit.c +++ b/linux-user/exit.c @@ -22,6 +22,7 @@ #include "qemu.h" #include "user-internals.h" #include "qemu/plugin.h" +#include "tcg/tb-stats.h" #ifdef CONFIG_GCOV extern void __gcov_dump(void); @@ -30,9 +31,10 @@ extern void __gcov_dump(void); void preexit_cleanup(CPUArchState *env, int code) { #ifdef CONFIG_GCOV - __gcov_dump(); + __gcov_dump(); #endif - gdb_exit(code); - qemu_plugin_user_exit(); - perf_exit(); + gdb_exit(code); + qemu_plugin_user_exit(); + perf_exit(); + tb_stats_dump_atexit(); } diff --git a/softmmu/runstate.c b/softmmu/runstate.c index 1652ed0439..2c6fb9bff1 100644 --- a/softmmu/runstate.c +++ b/softmmu/runstate.c @@ -59,6 +59,7 @@ #include "sysemu/runstate-action.h" #include "sysemu/sysemu.h" #include "sysemu/tpm.h" +#include "tcg/tb-stats.h" #include "trace.h" static NotifierList exit_notifiers = @@ -846,6 +847,7 @@ void qemu_cleanup(void) /* No more vcpu or device emulation activity beyond this point */ vm_shutdown(); replay_finish(); + tb_stats_dump_atexit(); /* * We must cancel all block jobs while the block layer is drained, diff --git a/stubs/tb-stats.c b/stubs/tb-stats.c index ceaa1622ce..f9e4ef5d04 100644 --- a/stubs/tb-stats.c +++ b/stubs/tb-stats.c @@ -11,6 +11,10 @@ #include "qemu/osdep.h" #include "tcg/tb-stats.h" -void tb_stats_init(uint32_t flags) +void tb_stats_init(uint32_t flags, uint32_t atexit) +{ +} + +void tb_stats_dump_atexit(void) { } diff --git a/util/log.c b/util/log.c index 0cb987fb74..789b19a226 100644 --- a/util/log.c +++ b/util/log.c @@ -526,19 +526,31 @@ int qemu_str_to_log_mask(const char *str, Error **errp) #ifdef CONFIG_TCG } else if (g_str_has_prefix(t, "tb_stats:") && t[9] != '\0') { int flags = TB_STATS_NONE; + unsigned atexit = 0; char *v = t + 9; + char *e = strchr(v, ':'); + size_t len; - if (g_str_equal(v, "all")) { + if (e) { + len = e - v; + if (qemu_strtoui(e + 1, NULL, 10, &atexit) < 0) { + error_setg(errp, "Invalid -d option \"%s\"", t); + goto error; + } + } else { + len = strlen(v); + } + if (strncmp(v, "all", len) == 0) { flags = TB_STATS_ALL; - } else if (g_str_equal(v, "jit")) { + } else if (strncmp(v, "jit", len) == 0) { flags = TB_STATS_JIT; - } else if (g_str_equal(v, "exec")) { + } else if (strncmp(v, "exec", len) == 0) { flags = TB_STATS_EXEC; } else { error_setg(errp, "Invalid -d option \"%s\"", t); goto error; } - tb_stats_init(flags); + tb_stats_init(flags, atexit); #endif } else { for (item = qemu_log_items; item->mask != 0; item++) {