From nobody Tue May 7 09:25:28 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1565837074; cv=none; d=zoho.com; s=zohoarc; b=Ie2j030j89Vkc35Xsjs7rBy3X5tjTkoUKCohnzU2y37sMGL21RJwOTnp7qn41fCAHk9MlRNiHGdfqTxA8JQZFjYR61r5XLMSZubYm+ScTy7Y5JAx123LaSNOZ1lucYTPNKd05b9MbNxmqE+opM1RYzTkohjbHGpzPdOnD0gc88U= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1565837074; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=vErop0rGwk60sa3Qa4x2OiK1fh1r4aRc9p7r0AqR3oI=; b=KV7/Cj3ZJDeTdB4lh0hhJ0+tghMHicSVe7ccQdGnunoMp3X254ExIvT0yJc4H2JwPbHPUjjH/c0M/PiLfg6lreseocslSsLeMMjxnGkxApw0+J5BkPZ9LYPkP3NPrIThofS4WZi4LKf1ZWy7E/9c+BQiRWeJ9sOI7LaWW4WMyOo= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1565837074087874.9606704940751; Wed, 14 Aug 2019 19:44:34 -0700 (PDT) Received: from localhost ([::1]:37710 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1hy5ke-0006Sn-Hm for importer@patchew.org; Wed, 14 Aug 2019 22:44:32 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:48592) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1hy5MP-0000a5-W4 for qemu-devel@nongnu.org; Wed, 14 Aug 2019 22:19:31 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hy5MO-0001bV-75 for qemu-devel@nongnu.org; Wed, 14 Aug 2019 22:19:29 -0400 Received: from mail-qt1-x843.google.com ([2607:f8b0:4864:20::843]:35415) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hy5MO-0001b8-2F for qemu-devel@nongnu.org; Wed, 14 Aug 2019 22:19:28 -0400 Received: by mail-qt1-x843.google.com with SMTP id u34so950783qte.2 for ; Wed, 14 Aug 2019 19:19:28 -0700 (PDT) Received: from localhost.localdomain ([2804:14c:482:121::1]) by smtp.googlemail.com with ESMTPSA id o5sm757943qkf.10.2019.08.14.19.19.25 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Wed, 14 Aug 2019 19:19:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=vErop0rGwk60sa3Qa4x2OiK1fh1r4aRc9p7r0AqR3oI=; b=Ph8XWJkK+6L+jNeXmHhkWiUCXrKNQYGI/LDLm5spgCRQW7kHFusJs/qpisw7IUmnM4 LZu91l43c8MTepbeJTSq99ZQT3FdwxJp52kR3MiYKx8NKwtFHqo5pl5ipD2YwzmRflGK 1lDjMc6XiNRZsbMhppebY2BPyW4hkh3RgHPwxX2Xj2PM0f2xOisePOTBn+BmLhgL1wiy f9anGDcAJaTrStzC1rTQPD6jRetQGf7YxIohFeES6F1XAcGin+wIZ+IBs3TFDz6XI8wW Z25AbPWE6a+kwkFiAEHcVicyN8zcaqBkqevAFXFBUsYhn2e4e+aDhRZKXF902yeYjfqR wR+A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=vErop0rGwk60sa3Qa4x2OiK1fh1r4aRc9p7r0AqR3oI=; b=Mm3djhYIQNHad/BPv05i+pM+lWKMw1JSJsgvFbiZ4mVu+VzBLOEu0HG7rcAFTgm0pO LX+s7W+yovWvQAZLnNUhKGToD3L61i4221PY9PyKu/7oU1hBFyoUJNWZzRPBIwNTDSxX Tk7kIXGijNkfGfwOpcICrBCY9i65KMkRyYyV2Jy2NSvOP5MLy0jVAJYOvr8ex2ukDUp7 fl/rfXGvaUzBiUnE3C7LyYifw0fOlnVTwAhC7YaQcNAbo5fyh1ewAd1kKSMkVR1p+gFi u76IX8WQkxvC2EQ+0TJqcyqLWdOo6ggxt3q367l9egqpNbmJkLyXoLKGsYx9knMwUaGM DGlw== X-Gm-Message-State: APjAAAXXqbRVghzrzhrHhDJLiWc0XDFYw8yTZYlkucb2QhIZPN+eGArM GXIYRHncqQC21YDBU30a74V2gGCZne0= X-Google-Smtp-Source: APXvYqxQhm32tXzVXJOo13OJKMd53oCQN4XSQOThEopKA2oS+nKUmkhvIO1oG+AAAaG/NiBw57whng== X-Received: by 2002:ac8:764f:: with SMTP id i15mr2039555qtr.194.1565835567208; Wed, 14 Aug 2019 19:19:27 -0700 (PDT) From: vandersonmr To: qemu-devel@nongnu.org Date: Wed, 14 Aug 2019 23:18:48 -0300 Message-Id: <20190815021857.19526-2-vandersonmr2@gmail.com> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190815021857.19526-1-vandersonmr2@gmail.com> References: <20190815021857.19526-1-vandersonmr2@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::843 Subject: [Qemu-devel] [PATCH v5 01/10] accel: introducing TBStatistics structure X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Paolo Bonzini , vandersonmr , Richard Henderson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" To store statistics for each TB, we created a TBStatistics structure which is linked with the TBs. TBStatistics can stay alive after tb_flush and be relinked to a regenerated TB. So the statistics can be accumulated even through flushes. The goal is to have all present and future qemu/tcg statistics and meta-data stored in this new structure. Signed-off-by: Vanderson M. do Rosario Reviewed-by: Alex Benn=C3=A9e --- accel/tcg/Makefile.objs | 2 +- accel/tcg/perf/Makefile.objs | 1 + accel/tcg/tb-stats.c | 39 ++++++++++++++++++++++++ accel/tcg/translate-all.c | 57 ++++++++++++++++++++++++++++++++++++ include/exec/exec-all.h | 15 +++------- include/exec/tb-context.h | 12 ++++++++ include/exec/tb-hash.h | 7 +++++ include/exec/tb-stats.h | 43 +++++++++++++++++++++++++++ util/log.c | 2 ++ 9 files changed, 166 insertions(+), 12 deletions(-) create mode 100644 accel/tcg/perf/Makefile.objs create mode 100644 accel/tcg/tb-stats.c create mode 100644 include/exec/tb-stats.h diff --git a/accel/tcg/Makefile.objs b/accel/tcg/Makefile.objs index d381a02f34..49ffe81b5d 100644 --- a/accel/tcg/Makefile.objs +++ b/accel/tcg/Makefile.objs @@ -2,7 +2,7 @@ obj-$(CONFIG_SOFTMMU) +=3D tcg-all.o obj-$(CONFIG_SOFTMMU) +=3D cputlb.o obj-y +=3D tcg-runtime.o tcg-runtime-gvec.o obj-y +=3D cpu-exec.o cpu-exec-common.o translate-all.o -obj-y +=3D translator.o +obj-y +=3D translator.o tb-stats.o =20 obj-$(CONFIG_USER_ONLY) +=3D user-exec.o obj-$(call lnot,$(CONFIG_SOFTMMU)) +=3D user-exec-stub.o diff --git a/accel/tcg/perf/Makefile.objs b/accel/tcg/perf/Makefile.objs new file mode 100644 index 0000000000..f82fba35e5 --- /dev/null +++ b/accel/tcg/perf/Makefile.objs @@ -0,0 +1 @@ +obj-y +=3D jitdump.o diff --git a/accel/tcg/tb-stats.c b/accel/tcg/tb-stats.c new file mode 100644 index 0000000000..02844717cb --- /dev/null +++ b/accel/tcg/tb-stats.c @@ -0,0 +1,39 @@ +#include "qemu/osdep.h" + +#include "disas/disas.h" + +#include "exec/tb-stats.h" + +void init_tb_stats_htable_if_not(void) +{ + if (tb_stats_collection_enabled() && !tb_ctx.tb_stats.map) { + qht_init(&tb_ctx.tb_stats, tb_stats_cmp, + CODE_GEN_HTABLE_SIZE, QHT_MODE_AUTO_RESIZE); + } +} + +void enable_collect_tb_stats(void) +{ + init_tb_stats_htable_if_not(); + tcg_collect_tb_stats =3D TB_STATS_RUNNING; +} + +void disable_collect_tb_stats(void) +{ + tcg_collect_tb_stats =3D TB_STATS_PAUSED; +} + +void pause_collect_tb_stats(void) +{ + tcg_collect_tb_stats =3D TB_STATS_STOPPED; +} + +bool tb_stats_collection_enabled(void) +{ + return tcg_collect_tb_stats =3D=3D TB_STATS_RUNNING; +} + +bool tb_stats_collection_paused(void) +{ + return tcg_collect_tb_stats =3D=3D TB_STATS_PAUSED; +} diff --git a/accel/tcg/translate-all.c b/accel/tcg/translate-all.c index 5d1e08b169..b7bccacd3b 100644 --- a/accel/tcg/translate-all.c +++ b/accel/tcg/translate-all.c @@ -1118,6 +1118,23 @@ static inline void code_gen_alloc(size_t tb_size) } } =20 +/* + * This is the more or less the same compare as tb_cmp(), but the + * data persists over tb_flush. We also aggregate the various + * variations of cflags under one record and ignore the details of + * page overlap (although we can count it). + */ +bool tb_stats_cmp(const void *ap, const void *bp) +{ + const TBStatistics *a =3D ap; + const TBStatistics *b =3D bp; + + return a->phys_pc =3D=3D b->phys_pc && + a->pc =3D=3D b->pc && + a->cs_base =3D=3D b->cs_base && + a->flags =3D=3D b->flags; +} + static bool tb_cmp(const void *ap, const void *bp) { const TranslationBlock *a =3D ap; @@ -1137,6 +1154,7 @@ static void tb_htable_init(void) unsigned int mode =3D QHT_MODE_AUTO_RESIZE; =20 qht_init(&tb_ctx.htable, tb_cmp, CODE_GEN_HTABLE_SIZE, mode); + init_tb_stats_htable_if_not(); } =20 /* Must be called before using the QEMU cpus. 'tb_size' is the size @@ -1666,6 +1684,34 @@ tb_link_page(TranslationBlock *tb, tb_page_addr_t ph= ys_pc, return tb; } =20 +static TBStatistics *tb_get_stats(tb_page_addr_t phys_pc, target_ulong pc, + target_ulong cs_base, uint32_t flags, + TranslationBlock *current_tb) +{ + TBStatistics *new_stats =3D g_new0(TBStatistics, 1); + uint32_t hash =3D tb_stats_hash_func(phys_pc, pc, flags); + void *existing_stats =3D NULL; + new_stats->phys_pc =3D phys_pc; + new_stats->pc =3D pc; + new_stats->cs_base =3D cs_base; + new_stats->flags =3D flags; + new_stats->tb =3D current_tb; + + qht_insert(&tb_ctx.tb_stats, new_stats, hash, &existing_stats); + + if (unlikely(existing_stats)) { + /* + * If there is already a TBStatistic for this TB from a previous f= lush + * then just make the new TB point to the older TBStatistic + */ + g_free(new_stats); + return existing_stats; + } else { + return new_stats; + } +} + + /* Called with mmap_lock held for user mode emulation. */ TranslationBlock *tb_gen_code(CPUState *cpu, target_ulong pc, target_ulong cs_base, @@ -1732,6 +1778,17 @@ TranslationBlock *tb_gen_code(CPUState *cpu, ti =3D profile_getclock(); #endif =20 + /* + * We want to fetch the stats structure before we start code + * generation so we can count interesting things about this + * generation. + */ + if (tb_stats_collection_enabled()) { + tb->tb_stats =3D tb_get_stats(phys_pc, pc, cs_base, flags, tb); + } else { + tb->tb_stats =3D NULL; + } + tcg_func_start(tcg_ctx); =20 tcg_ctx->cpu =3D env_cpu(env); diff --git a/include/exec/exec-all.h b/include/exec/exec-all.h index 16034ee651..24bd6a0a0c 100644 --- a/include/exec/exec-all.h +++ b/include/exec/exec-all.h @@ -22,21 +22,11 @@ =20 #include "exec/tb-context.h" #include "sysemu/cpus.h" +#include "exec/tb-stats.h" =20 /* allow to see translation results - the slowdown should be negligible, s= o we leave it */ #define DEBUG_DISAS =20 -/* Page tracking code uses ram addresses in system mode, and virtual - addresses in userspace mode. Define tb_page_addr_t to be an appropriate - type. */ -#if defined(CONFIG_USER_ONLY) -typedef abi_ulong tb_page_addr_t; -#define TB_PAGE_ADDR_FMT TARGET_ABI_FMT_lx -#else -typedef ram_addr_t tb_page_addr_t; -#define TB_PAGE_ADDR_FMT RAM_ADDR_FMT -#endif - #include "qemu/log.h" =20 void gen_intermediate_code(CPUState *cpu, TranslationBlock *tb, int max_in= sns); @@ -403,6 +393,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; }; =20 extern bool parallel_cpus; diff --git a/include/exec/tb-context.h b/include/exec/tb-context.h index feb585e0a7..3cfb62a338 100644 --- a/include/exec/tb-context.h +++ b/include/exec/tb-context.h @@ -23,6 +23,17 @@ #include "qemu/thread.h" #include "qemu/qht.h" =20 +/* Page tracking code uses ram addresses in system mode, and virtual + addresses in userspace mode. Define tb_page_addr_t to be an appropriate + type. */ +#if defined(CONFIG_USER_ONLY) +typedef abi_ulong tb_page_addr_t; +#define TB_PAGE_ADDR_FMT TARGET_ABI_FMT_lx +#else +typedef ram_addr_t tb_page_addr_t; +#define TB_PAGE_ADDR_FMT RAM_ADDR_FMT +#endif + #define CODE_GEN_HTABLE_BITS 15 #define CODE_GEN_HTABLE_SIZE (1 << CODE_GEN_HTABLE_BITS) =20 @@ -35,6 +46,7 @@ struct TBContext { =20 /* statistics */ unsigned tb_flush_count; + struct qht tb_stats; }; =20 extern TBContext tb_ctx; diff --git a/include/exec/tb-hash.h b/include/exec/tb-hash.h index 4f3a37d927..54c477fe79 100644 --- a/include/exec/tb-hash.h +++ b/include/exec/tb-hash.h @@ -64,4 +64,11 @@ uint32_t tb_hash_func(tb_page_addr_t phys_pc, target_ulo= ng pc, uint32_t flags, return qemu_xxhash7(phys_pc, pc, flags, cf_mask, trace_vcpu_dstate); } =20 +static inline +uint32_t tb_stats_hash_func(tb_page_addr_t phys_pc, target_ulong pc, + uint32_t flags) +{ + return qemu_xxhash5(phys_pc, pc, flags); +} + #endif diff --git a/include/exec/tb-stats.h b/include/exec/tb-stats.h new file mode 100644 index 0000000000..cc8f8a6ce6 --- /dev/null +++ b/include/exec/tb-stats.h @@ -0,0 +1,43 @@ +#ifndef TB_STATS_H + +#define TB_STATS_H + +#include "exec/cpu-common.h" +#include "exec/tb-context.h" +#include "tcg.h" + +typedef struct TBStatistics TBStatistics; + +/* + * 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; + target_ulong pc; + uint32_t flags; + /* cs_base isn't included in the hash but we do check for matches */ + target_ulong cs_base; + /* current TB linked to this TBStatistics */ + TranslationBlock *tb; +}; + +bool tb_stats_cmp(const void *ap, const void *bp); + +void init_tb_stats_htable_if_not(void); + +/* TBStatistic collection controls */ +enum TBStatsStatus { TB_STATS_RUNNING, TB_STATS_PAUSED, TB_STATS_STOPPED }; +extern int tcg_collect_tb_stats; + +void enable_collect_tb_stats(void); +void disable_collect_tb_stats(void); +void pause_collect_tb_stats(void); +bool tb_stats_collection_enabled(void); +bool tb_stats_collection_paused(void); + +#endif diff --git a/util/log.c b/util/log.c index 1d1b33f7d9..393a17115b 100644 --- a/util/log.c +++ b/util/log.c @@ -31,6 +31,8 @@ int qemu_loglevel; static int log_append =3D 0; static GArray *debug_regions; =20 +int tcg_collect_tb_stats; + /* Return the number of characters emitted. */ int qemu_log(const char *fmt, ...) { --=20 2.22.0 From nobody Tue May 7 09:25:28 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1565837567; cv=none; d=zoho.com; s=zohoarc; b=L+PfVn/kA0kkdPVkcRxSc04NThgivokgJge5hjZH0sQvjkPaxuLsWS7zsSrAK8NMN0FdvjUFT0OH9OR27QtoZUzn4H/2fiXJkgwPH5m3L8fw+u/cdPfm+cUo29NQLV9Ij0idTHJtbIXXJLKWiUaia7btrfSMOa7z13IvNpYInoc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1565837567; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=J+5X1vqIJ+CD8k9SeFSpb++0TRf0wiFY3wllBJkAPIA=; b=XRGZxQ+Hk3I/llAclwDXeprNkYrhzQyWFd8s3RQLavVfs3rOxMdzTd2FPq43gyoOXUvJt999nt5A3IWZhvz+AAwnvxU4fv6+KVBTX0ZVKma3f5QDGXCGiToIAnuTAd8P8WlNUdFtc7nZrYecig/yDKkwZX3m0CFZjRGWXgPnGZM= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1565837567925592.3018198694191; Wed, 14 Aug 2019 19:52:47 -0700 (PDT) Received: from localhost ([::1]:37838 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1hy5sc-0000IP-E7 for importer@patchew.org; Wed, 14 Aug 2019 22:52:46 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:48602) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1hy5MR-0000cg-M7 for qemu-devel@nongnu.org; Wed, 14 Aug 2019 22:19:33 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hy5MQ-0001ct-4r for qemu-devel@nongnu.org; Wed, 14 Aug 2019 22:19:31 -0400 Received: from mail-qt1-x842.google.com ([2607:f8b0:4864:20::842]:43950) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hy5MQ-0001cW-0s for qemu-devel@nongnu.org; Wed, 14 Aug 2019 22:19:30 -0400 Received: by mail-qt1-x842.google.com with SMTP id b11so896310qtp.10 for ; Wed, 14 Aug 2019 19:19:29 -0700 (PDT) Received: from localhost.localdomain ([2804:14c:482:121::1]) by smtp.googlemail.com with ESMTPSA id o5sm757943qkf.10.2019.08.14.19.19.27 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Wed, 14 Aug 2019 19:19:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=J+5X1vqIJ+CD8k9SeFSpb++0TRf0wiFY3wllBJkAPIA=; b=Zt6yOYhX/JUQTU0CZIygrs8nebTthCFg2PCVCrQXGP9dB4E6ewDN+MhPefNB2iczO+ VW04FHGkHkiHh/3sZk0wFjXHjSsESmdCLRfebhyg/KoU/l7afMXX7JWZC79xk7Mun7qi 1ZD2DS9xUh5YhSpgVFzwqj4I/4yymA0xPWrlH/rC1Vlm+2yy+kbs8B5rxcnXH5c6p//l 2Ceiu9vHt/kTl4kjlZVv49nSuaDt88CyviXzTE7VDvhykC1bAteS1hydRDszUQu47qgB /pnbbt3h6Vi/vJZKRMr3PP2HTXTbGnjAI+3Kmn4v3P6Q8zRN27a3en3/JVnBw7U59n78 0M3g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=J+5X1vqIJ+CD8k9SeFSpb++0TRf0wiFY3wllBJkAPIA=; b=s3/6oqJ77OogV77TC8rPahvs6qpRBmXAfW08sTGasCiv0+j7aWunhtTqf045MgyElM c/b0e7hbkz46fbAcYmKmGkhrbqT2/dnwzoo2m7G5v0/+nRtmkg5T6mmcJwDKH90HNYGj OQUn02rOJrE+uWK8wMsGi4T9txNdRhyrQpZuJyol7cnvg5d7Lj2WVHQ/i5Tq15xVtd1c NXe4sOzQKQu+4HybSjxixV9wEdCt+RqY7xa0YosNUqXqSz3A5a0ckRnt/LPge42jAPnr PB1lNW9Btopi0v9bx5lLyNcnyAsb/rV1Ld7qeY/V2AcGk37ncOFTYY4oCzk06m7lQ4kr rkKw== X-Gm-Message-State: APjAAAWFEMfw1zuBwBHDA1ypXgZQBhlqrA3RGiYn3dl1OFUFXWWXzOkk SMD1UQOGamJtHISQoRt5TLw+wk8K70Y= X-Google-Smtp-Source: APXvYqww0qGRNdCUI99I5TpSjb8KaWtrtTPDaEOCm8iC+0LstSU6t/Fp7mq5P95zdAZIaBWtIt1AgQ== X-Received: by 2002:ac8:5354:: with SMTP id d20mr1996415qto.119.1565835569197; Wed, 14 Aug 2019 19:19:29 -0700 (PDT) From: vandersonmr To: qemu-devel@nongnu.org Date: Wed, 14 Aug 2019 23:18:49 -0300 Message-Id: <20190815021857.19526-3-vandersonmr2@gmail.com> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190815021857.19526-1-vandersonmr2@gmail.com> References: <20190815021857.19526-1-vandersonmr2@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::842 Subject: [Qemu-devel] [PATCH v5 02/10] accel: collecting TB execution count X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Paolo Bonzini , vandersonmr , Richard Henderson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" If a TB has a TBS (TBStatistics) with the TB_EXEC_STATS enabled, then we instrument the start code of this TB to atomically count the number of times it is executed. We count both the number of "normal" executions and atomic executions of a TB. The execution count of the TB is stored in its respective TBS. All TBStatistics are created by default with the flags from default_tbstats_flag. Signed-off-by: Vanderson M. do Rosario --- accel/tcg/cpu-exec.c | 4 ++++ accel/tcg/tb-stats.c | 5 +++++ accel/tcg/tcg-runtime.c | 7 +++++++ accel/tcg/tcg-runtime.h | 2 ++ accel/tcg/translate-all.c | 7 +++++++ accel/tcg/translator.c | 1 + include/exec/gen-icount.h | 9 +++++++++ include/exec/tb-stats.h | 19 +++++++++++++++++++ util/log.c | 1 + 9 files changed, 55 insertions(+) diff --git a/accel/tcg/cpu-exec.c b/accel/tcg/cpu-exec.c index 6c85c3ee1e..e54be69499 100644 --- a/accel/tcg/cpu-exec.c +++ b/accel/tcg/cpu-exec.c @@ -252,6 +252,10 @@ void cpu_exec_step_atomic(CPUState *cpu) =20 start_exclusive(); =20 + if (tb_stats_enabled(tb, TB_EXEC_STATS)) { + tb->tb_stats->executions.atomic++; + } + /* Since we got here, we know that parallel_cpus must be true. */ parallel_cpus =3D false; in_exclusive_region =3D true; diff --git a/accel/tcg/tb-stats.c b/accel/tcg/tb-stats.c index 02844717cb..3489133e9e 100644 --- a/accel/tcg/tb-stats.c +++ b/accel/tcg/tb-stats.c @@ -37,3 +37,8 @@ bool tb_stats_collection_paused(void) { return tcg_collect_tb_stats =3D=3D TB_STATS_PAUSED; } + +uint32_t get_default_tbstats_flag(void) +{ + return default_tbstats_flag; +} diff --git a/accel/tcg/tcg-runtime.c b/accel/tcg/tcg-runtime.c index 8a1e408e31..6f4aafba11 100644 --- a/accel/tcg/tcg-runtime.c +++ b/accel/tcg/tcg-runtime.c @@ -167,3 +167,10 @@ void HELPER(exit_atomic)(CPUArchState *env) { cpu_loop_exit_atomic(env_cpu(env), GETPC()); } + +void HELPER(inc_exec_freq)(void *ptr) +{ + TBStatistics *stats =3D (TBStatistics *) ptr; + g_assert(stats); + atomic_inc(&stats->executions.normal); +} diff --git a/accel/tcg/tcg-runtime.h b/accel/tcg/tcg-runtime.h index 4fa61b49b4..bf0b75dbe8 100644 --- a/accel/tcg/tcg-runtime.h +++ b/accel/tcg/tcg-runtime.h @@ -28,6 +28,8 @@ DEF_HELPER_FLAGS_1(lookup_tb_ptr, TCG_CALL_NO_WG_SE, ptr,= env) =20 DEF_HELPER_FLAGS_1(exit_atomic, TCG_CALL_NO_WG, noreturn, env) =20 +DEF_HELPER_FLAGS_1(inc_exec_freq, TCG_CALL_NO_RWG, void, ptr) + #ifdef CONFIG_SOFTMMU =20 DEF_HELPER_FLAGS_5(atomic_cmpxchgb, TCG_CALL_NO_WG, diff --git a/accel/tcg/translate-all.c b/accel/tcg/translate-all.c index b7bccacd3b..df08d183df 100644 --- a/accel/tcg/translate-all.c +++ b/accel/tcg/translate-all.c @@ -1785,6 +1785,13 @@ TranslationBlock *tb_gen_code(CPUState *cpu, */ if (tb_stats_collection_enabled()) { tb->tb_stats =3D tb_get_stats(phys_pc, pc, cs_base, flags, tb); + uint32_t flag =3D get_default_tbstats_flag(); + + if (qemu_log_in_addr_range(tb->pc)) { + if (flag & TB_EXEC_STATS) { + tb->tb_stats->stats_enabled |=3D TB_EXEC_STATS; + } + } } else { tb->tb_stats =3D NULL; } diff --git a/accel/tcg/translator.c b/accel/tcg/translator.c index 9226a348a3..396a11e828 100644 --- a/accel/tcg/translator.c +++ b/accel/tcg/translator.c @@ -46,6 +46,7 @@ void translator_loop(const TranslatorOps *ops, DisasConte= xtBase *db, =20 ops->init_disas_context(db, cpu); tcg_debug_assert(db->is_jmp =3D=3D DISAS_NEXT); /* no early exit */ + gen_tb_exec_count(tb); =20 /* Reset the temp count so that we can identify leaks */ tcg_clear_temp_count(); diff --git a/include/exec/gen-icount.h b/include/exec/gen-icount.h index f7669b6841..b3efe41894 100644 --- a/include/exec/gen-icount.h +++ b/include/exec/gen-icount.h @@ -7,6 +7,15 @@ =20 static TCGOp *icount_start_insn; =20 +static inline void gen_tb_exec_count(TranslationBlock *tb) +{ + if (tb_stats_enabled(tb, TB_EXEC_STATS)) { + TCGv_ptr ptr =3D tcg_const_ptr(tb->tb_stats); + gen_helper_inc_exec_freq(ptr); + tcg_temp_free_ptr(ptr); + } +} + static inline void gen_tb_start(TranslationBlock *tb) { TCGv_i32 count, imm; diff --git a/include/exec/tb-stats.h b/include/exec/tb-stats.h index cc8f8a6ce6..0265050b79 100644 --- a/include/exec/tb-stats.h +++ b/include/exec/tb-stats.h @@ -6,6 +6,9 @@ #include "exec/tb-context.h" #include "tcg.h" =20 +#define tb_stats_enabled(tb, JIT_STATS) \ + (tb && tb->tb_stats && (tb->tb_stats->stats_enabled & JIT_STATS)) + typedef struct TBStatistics TBStatistics; =20 /* @@ -22,6 +25,15 @@ struct TBStatistics { uint32_t flags; /* cs_base isn't included in the hash but we do check for matches */ target_ulong cs_base; + + uint32_t stats_enabled; + + /* Execution stats */ + struct { + unsigned long normal; + unsigned long atomic; + } executions; + /* current TB linked to this TBStatistics */ TranslationBlock *tb; }; @@ -32,7 +44,12 @@ void init_tb_stats_htable_if_not(void); =20 /* TBStatistic collection controls */ enum TBStatsStatus { TB_STATS_RUNNING, TB_STATS_PAUSED, TB_STATS_STOPPED }; + +#define TB_NOTHING 0 +#define TB_EXEC_STATS 1 + extern int tcg_collect_tb_stats; +extern uint32_t default_tbstats_flag; =20 void enable_collect_tb_stats(void); void disable_collect_tb_stats(void); @@ -40,4 +57,6 @@ void pause_collect_tb_stats(void); bool tb_stats_collection_enabled(void); bool tb_stats_collection_paused(void); =20 +uint32_t get_default_tbstats_flag(void); + #endif diff --git a/util/log.c b/util/log.c index 393a17115b..29021a4584 100644 --- a/util/log.c +++ b/util/log.c @@ -32,6 +32,7 @@ static int log_append =3D 0; static GArray *debug_regions; =20 int tcg_collect_tb_stats; +uint32_t default_tbstats_flag; =20 /* Return the number of characters emitted. */ int qemu_log(const char *fmt, ...) --=20 2.22.0 From nobody Tue May 7 09:25:28 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1565836251; cv=none; d=zoho.com; s=zohoarc; b=fOZs4a/5jbwDwgfAnvpvV+/x3p1vvI3CsL8zUF6zdW5OukGRNGxM42fTBGXhGgFfohEYd4ZzjAjY3O58XU/Ny8EEtDlIq9ccek9+2F2thwXQLg36ApzCsSeDgY4EnZpwySWUsVYC33fY36P7WTC/rYxhDsMxO3QF7EmTmcv/zL4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1565836251; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=pMPv8x3diYkvzJObvdKKYdrD97zC94XRrQ1bguEiCd4=; b=kvhPuiIiY7mWLwNSTo5qX/KosErScPfc6LgNRRc/kWXcgfJ/nRiDJ8cuubsJRSn5MbDkHUcO0ehYT0ZjBP5oPzqtZTgbO3GTdEUWid5FSe9t4Cfr5VjKJtyUKBuPxvMhfuxoot6HARsqzuQivCj6ghJiHDFzJYVvolopJ0ePMI0= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1565836251884752.1216505672938; Wed, 14 Aug 2019 19:30:51 -0700 (PDT) Received: from localhost ([::1]:37548 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1hy5XN-0005Kz-9Z for importer@patchew.org; Wed, 14 Aug 2019 22:30:49 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:48617) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1hy5MT-0000gK-VU for qemu-devel@nongnu.org; Wed, 14 Aug 2019 22:19:35 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hy5MS-0001fG-Ia for qemu-devel@nongnu.org; Wed, 14 Aug 2019 22:19:33 -0400 Received: from mail-qt1-x844.google.com ([2607:f8b0:4864:20::844]:34434) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hy5MS-0001f2-E8 for qemu-devel@nongnu.org; Wed, 14 Aug 2019 22:19:32 -0400 Received: by mail-qt1-x844.google.com with SMTP id q4so961697qtp.1 for ; Wed, 14 Aug 2019 19:19:32 -0700 (PDT) Received: from localhost.localdomain ([2804:14c:482:121::1]) by smtp.googlemail.com with ESMTPSA id o5sm757943qkf.10.2019.08.14.19.19.29 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Wed, 14 Aug 2019 19:19:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=pMPv8x3diYkvzJObvdKKYdrD97zC94XRrQ1bguEiCd4=; b=gsvkq52UuLBj0Cuc6zE0h+odY9SdwPikaLeTKJpopDjce70xx67aUJzUkx1i9y7e5t dmK5/PIQ+bBPPtGq8g5xqNQZksxFPLq/9q10YZ95W8fjX0pgbMywUCyPrFbGfRI1h8dl Uu1SdXhPuurMEB5wa9mrsjmaibMpzU6STKwYw/GT58aXUHjhB2fG61kABvizL39V9LVO AZkXjaFkJ8oZh/Ups4nBCzGPia1Q7llGCEkiZOi+aLVhbBz5ULT7gmbJKf6NPBTT0vsZ y7zkZGQ6dP3h5RaU/JKEqdmDybr3cPNfHQ1E6RLrg23V5YgnHuA8rHBU1ZCYcy0qrmh2 8JcQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=pMPv8x3diYkvzJObvdKKYdrD97zC94XRrQ1bguEiCd4=; b=o7bGKoLsWfIg9GbIP7qjA0eDqE361QwkJaWU1Yw7RjmbPr9qzRiQpQmlGmR1JOIOUF hFDaobt0XmjjC6hIk9lttaufdxx/bMLTug98lJiG5IUkgVwmwfOel6xi5IKCPDnds/dE XmhwXhT0Lgz78AqEwj8yp8deGvT7DcCnZKBp6d0KIfJNGAwuUIiGYgl0RogNUNZR9HWq wWl4SbOnBe5nlW+BDCe2LMeumDlhCWp8IcDPw3Hi9FJdT+GRp92AOojSMzU/83ytDg88 8v2cRA33q+Sf2GRPGxpJ8ifcitxs6zi7/gNSXmSebF5U3p8+tOCn0vVpOP4BvcMjQ2Ks gMSg== X-Gm-Message-State: APjAAAWFIm+XPgCLtHXlzaPbAm7KP7uBPZvsspBbgTdKg2FiY9WICxlw LQJdQ8vIRlTqULdZSsTyU0F69hsrntk= X-Google-Smtp-Source: APXvYqwvRiamSquzaj5Wmg9WV2rSG2mbnF5Q/7iQnpxzYwCccn7RlnIga5fSqNqh1Tr7JAZaZ2E06Q== X-Received: by 2002:ac8:7182:: with SMTP id w2mr2042878qto.156.1565835571500; Wed, 14 Aug 2019 19:19:31 -0700 (PDT) From: vandersonmr To: qemu-devel@nongnu.org Date: Wed, 14 Aug 2019 23:18:50 -0300 Message-Id: <20190815021857.19526-4-vandersonmr2@gmail.com> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190815021857.19526-1-vandersonmr2@gmail.com> References: <20190815021857.19526-1-vandersonmr2@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::844 Subject: [Qemu-devel] [PATCH v5 03/10] accel: collecting JIT statistics X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Paolo Bonzini , vandersonmr , Richard Henderson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" If a TB has a TBS (TBStatistics) with the TB_JIT_STATS enabled then we collect statistics of its translation processes and code translation. Collecting the number of host instructions seems to be not simple as it would imply in having to modify several target source files. So, for now, we are only collecting the size of the host gen code. Signed-off-by: Vanderson M. do Rosario Reviewed-by: Alex Benn=C3=A9e --- accel/tcg/translate-all.c | 14 ++++++++++++++ accel/tcg/translator.c | 4 ++++ include/exec/tb-stats.h | 15 +++++++++++++++ tcg/tcg.c | 23 +++++++++++++++++++++++ tcg/tcg.h | 2 ++ 5 files changed, 58 insertions(+) diff --git a/accel/tcg/translate-all.c b/accel/tcg/translate-all.c index df08d183df..85c6b7b409 100644 --- a/accel/tcg/translate-all.c +++ b/accel/tcg/translate-all.c @@ -1696,6 +1696,7 @@ static TBStatistics *tb_get_stats(tb_page_addr_t phys= _pc, target_ulong pc, new_stats->cs_base =3D cs_base; new_stats->flags =3D flags; new_stats->tb =3D current_tb; + new_stats->translations.total =3D 1; =20 qht_insert(&tb_ctx.tb_stats, new_stats, hash, &existing_stats); =20 @@ -1705,6 +1706,7 @@ static TBStatistics *tb_get_stats(tb_page_addr_t phys= _pc, target_ulong pc, * then just make the new TB point to the older TBStatistic */ g_free(new_stats); + ((TBStatistics *) existing_stats)->tb =3D current_tb; return existing_stats; } else { return new_stats; @@ -1792,6 +1794,11 @@ TranslationBlock *tb_gen_code(CPUState *cpu, tb->tb_stats->stats_enabled |=3D TB_EXEC_STATS; } } + + if (flag & TB_JIT_STATS) { + tb->tb_stats->stats_enabled |=3D TB_JIT_STATS; + atomic_inc(&tb->tb_stats->translations.total); + } } else { tb->tb_stats =3D NULL; } @@ -1869,6 +1876,10 @@ TranslationBlock *tb_gen_code(CPUState *cpu, atomic_set(&prof->search_out_len, prof->search_out_len + search_size); #endif =20 + if (tb_stats_enabled(tb, TB_JIT_STATS)) { + atomic_add(&tb->tb_stats->code.out_len, gen_code_size); + } + #ifdef DEBUG_DISAS if (qemu_loglevel_mask(CPU_LOG_TB_OUT_ASM) && qemu_log_in_addr_range(tb->pc)) { @@ -1926,6 +1937,9 @@ TranslationBlock *tb_gen_code(CPUState *cpu, phys_page2 =3D -1; if ((pc & TARGET_PAGE_MASK) !=3D virt_page2) { phys_page2 =3D get_page_addr_code(env, virt_page2); + if (tb_stats_enabled(tb, TB_JIT_STATS)) { + atomic_inc(&tb->tb_stats->translations.spanning); + } } /* * No explicit memory barrier is required -- tb_link_page() makes the diff --git a/accel/tcg/translator.c b/accel/tcg/translator.c index 396a11e828..834265d5be 100644 --- a/accel/tcg/translator.c +++ b/accel/tcg/translator.c @@ -117,6 +117,10 @@ void translator_loop(const TranslatorOps *ops, DisasCo= ntextBase *db, db->tb->size =3D db->pc_next - db->pc_first; db->tb->icount =3D db->num_insns; =20 + if (tb_stats_enabled(tb, TB_JIT_STATS)) { + atomic_add(&db->tb->tb_stats->code.num_guest_inst, db->num_insns); + } + #ifdef DEBUG_DISAS if (qemu_loglevel_mask(CPU_LOG_TB_IN_ASM) && qemu_log_in_addr_range(db->pc_first)) { diff --git a/include/exec/tb-stats.h b/include/exec/tb-stats.h index 0265050b79..3c219123c2 100644 --- a/include/exec/tb-stats.h +++ b/include/exec/tb-stats.h @@ -34,6 +34,20 @@ struct TBStatistics { unsigned long atomic; } executions; =20 + struct { + unsigned num_guest_inst; + unsigned num_tcg_ops; + unsigned num_tcg_ops_opt; + unsigned spills; + unsigned out_len; + } code; + + struct { + unsigned long total; + unsigned long uncached; + unsigned long spanning; + } translations; + /* current TB linked to this TBStatistics */ TranslationBlock *tb; }; @@ -47,6 +61,7 @@ enum TBStatsStatus { TB_STATS_RUNNING, TB_STATS_PAUSED, T= B_STATS_STOPPED }; =20 #define TB_NOTHING 0 #define TB_EXEC_STATS 1 +#define TB_JIT_STATS (1 << 2) =20 extern int tcg_collect_tb_stats; extern uint32_t default_tbstats_flag; diff --git a/tcg/tcg.c b/tcg/tcg.c index be2c33c400..446e3d1708 100644 --- a/tcg/tcg.c +++ b/tcg/tcg.c @@ -3126,6 +3126,11 @@ static void temp_sync(TCGContext *s, TCGTemp *ts, TC= GRegSet allocated_regs, case TEMP_VAL_REG: tcg_out_st(s, ts->type, ts->reg, ts->mem_base->reg, ts->mem_offset); + + /* Count number of spills */ + if (tb_stats_enabled(s->current_tb, TB_JIT_STATS)) { + atomic_inc(&s->current_tb->tb_stats->code.spills); + } break; =20 case TEMP_VAL_MEM: @@ -3997,6 +4002,8 @@ int tcg_gen_code(TCGContext *s, TranslationBlock *tb) int i, num_insns; TCGOp *op; =20 + s->current_tb =3D tb; + #ifdef CONFIG_PROFILER { int n =3D 0; @@ -4028,6 +4035,14 @@ int tcg_gen_code(TCGContext *s, TranslationBlock *tb) } #endif =20 + if (tb_stats_enabled(tb, TB_JIT_STATS)) { + int n =3D 0; + QTAILQ_FOREACH(op, &s->ops, link) { + n++; + } + atomic_add(&tb->tb_stats->code.num_tcg_ops, n); + } + #ifdef CONFIG_DEBUG_TCG /* Ensure all labels referenced have been emitted. */ { @@ -4094,6 +4109,14 @@ int tcg_gen_code(TCGContext *s, TranslationBlock *tb) } #endif =20 + if (tb_stats_enabled(tb, TB_JIT_STATS)) { + int n =3D 0; + QTAILQ_FOREACH(op, &s->ops, link) { + n++; + } + atomic_add(&tb->tb_stats->code.num_tcg_ops_opt, n); + } + tcg_reg_alloc_start(s); =20 s->code_buf =3D tb->tc.ptr; diff --git a/tcg/tcg.h b/tcg/tcg.h index b411e17a28..bf6f3bcba3 100644 --- a/tcg/tcg.h +++ b/tcg/tcg.h @@ -738,6 +738,8 @@ struct TCGContext { =20 uint16_t gen_insn_end_off[TCG_MAX_INSNS]; target_ulong gen_insn_data[TCG_MAX_INSNS][TARGET_INSN_START_WORDS]; + + TranslationBlock *current_tb; }; =20 extern TCGContext tcg_init_ctx; --=20 2.22.0 From nobody Tue May 7 09:25:28 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1565837653; cv=none; d=zoho.com; s=zohoarc; b=UrJMSurdRIaAgek2PVIqA754JWNCc5Bt15mfta495tKGJgapIafCzWTG1yDWwKclwSrY2dXl7YYFmLQ+WNdO8KIPIYIy+/LFUlNM0FQAnsug66Muf7Tvp969L//e/UEFYHPkNvJmPltu+Xgfs5Fpubuq3wJg+IKHhRxmtW+Wjwk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1565837653; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=2Yv6wTOkBqxVW7RZ4OHuXaluAUzTVR8VNqi6QnFmx9U=; b=BRjrFXtA483NCCGBETYmjg9zSEWAgpcAQ1IjMwvwBJ4tV7TFRTzl79pXnECg7JUQx33lCnOUbFFBjDKuoW78Jdb1/nMj7gvQkYaB0F913oPED9fPo4ed46zSV3c22UvDECXiy4tTcR0MMJQSCmaIjlShwfGTtj1/wXaL/mqdVVw= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1565837653071212.8628004050397; Wed, 14 Aug 2019 19:54:13 -0700 (PDT) Received: from localhost ([::1]:37884 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1hy5tv-00026W-Aj for importer@patchew.org; Wed, 14 Aug 2019 22:54:07 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:48636) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1hy5MW-0000kH-It for qemu-devel@nongnu.org; Wed, 14 Aug 2019 22:19:38 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hy5MU-0001iM-EK for qemu-devel@nongnu.org; Wed, 14 Aug 2019 22:19:36 -0400 Received: from mail-qk1-x742.google.com ([2607:f8b0:4864:20::742]:35359) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hy5MU-0001i9-9N for qemu-devel@nongnu.org; Wed, 14 Aug 2019 22:19:34 -0400 Received: by mail-qk1-x742.google.com with SMTP id r21so831176qke.2 for ; Wed, 14 Aug 2019 19:19:34 -0700 (PDT) Received: from localhost.localdomain ([2804:14c:482:121::1]) by smtp.googlemail.com with ESMTPSA id o5sm757943qkf.10.2019.08.14.19.19.31 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Wed, 14 Aug 2019 19:19:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=2Yv6wTOkBqxVW7RZ4OHuXaluAUzTVR8VNqi6QnFmx9U=; b=J+irm5sOWKeYD29RVNUwxSOHgZIzM0huC2r+Mb0/QmirEaXqYWZ1HqViayocJnR+cd wHpykxdTvk9VFtfkU22u24Tq5a5Lpc2hdqaS2NDzNWBtoUSNbAlcXpXjYd+aMKPJNG7d D3ZqawrlFs2fiqDGJRBCeta5i4qCtlkF9Crck+wa9aIc6jUXcy8pdSHbKYSdBEY5LtZA WLuAb1y4npFjZvLLLPHGFm421pyh4cm6EaHqth7APRVY08FDTeVaEmLfU2qIQLIi5UGK fXW9/U++0hWOtnZ3ZlK3gPb573sV03wfRgXnbcYL0pZb/GaXehmxJOg8gb/bKw9jyIOY fHow== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=2Yv6wTOkBqxVW7RZ4OHuXaluAUzTVR8VNqi6QnFmx9U=; b=VVSUdDlu5ISgeuRZbEsq3D4xRn2uYUfuN7FOJPk9zsDabmyHeQr1bN8tVijVU152E4 Zhe+AF8eAhLk4fuPsPi+slPQnxnREHBFvXV0fhdykcy8gwXHBpzNqmLsUcniUT96HGN9 o+NCYKrjd251/Xn4FgsfBXF+bHukDOV6q3crcEsuPIXja8F7jMGulVpXQoSN7KaH7H2T 8oeyZi9TU9DDQpXGpl8+/8gNh8ZB1htReQTQRDLF5dzfIxNLXyXB/iLXv7uoq/RCPlCs p6eVy/kN0zw7ssfD6D/N6J0EzpciILpXeC1XhovSoNxPb7R98h4vFStU1SdrlxZ3+IPB w6lQ== X-Gm-Message-State: APjAAAWDigfoH9msBZVD9aMek2UFgC6UFKhjZf5167vYhoqraYLwpfrJ ZPQ7c05/q7bNhZylM4muFPSPLlNOTlY= X-Google-Smtp-Source: APXvYqzrE0QX4hUngmdcQWq/m6O3ppLQ7KLVDg6wQelAOUWZUPmq+yWvHY7jCi8CuU4h8RRlqTzWEQ== X-Received: by 2002:a05:620a:13d1:: with SMTP id g17mr2004770qkl.499.1565835573476; Wed, 14 Aug 2019 19:19:33 -0700 (PDT) From: vandersonmr To: qemu-devel@nongnu.org Date: Wed, 14 Aug 2019 23:18:51 -0300 Message-Id: <20190815021857.19526-5-vandersonmr2@gmail.com> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190815021857.19526-1-vandersonmr2@gmail.com> References: <20190815021857.19526-1-vandersonmr2@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::742 Subject: [Qemu-devel] [PATCH v5 04/10] accel: replacing part of CONFIG_PROFILER with TBStats X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Paolo Bonzini , vandersonmr , Richard Henderson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" We add some of the statistics collected in the TCGProfiler into the TBStats, having the statistics not only for the whole emulation but for each TB. Then, we removed these stats from TCGProfiler and reconstruct the information for the "info jit" using the sum of all TBStats statistics. The goal is to have one unique and better way of collecting emulation statistics. Moreover, checking dynamiclly if the profiling is enabled showed to have an insignificant impact on the performance: https://wiki.qemu.org/Internships/ProjectIdeas/TCGCodeQuality#Overheads. Signed-off-by: Vanderson M. do Rosario Reviewed-by: Alex Benn=C3=A9e --- accel/tcg/tb-stats.c | 95 +++++++++++++++++++++++++++++++++++++++ accel/tcg/translate-all.c | 8 +--- include/exec/tb-stats.h | 11 +++++ tcg/tcg.c | 93 +++++--------------------------------- tcg/tcg.h | 10 ----- 5 files changed, 118 insertions(+), 99 deletions(-) diff --git a/accel/tcg/tb-stats.c b/accel/tcg/tb-stats.c index 3489133e9e..9b720d9b86 100644 --- a/accel/tcg/tb-stats.c +++ b/accel/tcg/tb-stats.c @@ -1,9 +1,104 @@ #include "qemu/osdep.h" =20 #include "disas/disas.h" +#include "exec/exec-all.h" +#include "tcg.h" + +#include "qemu/qemu-print.h" =20 #include "exec/tb-stats.h" =20 +struct jit_profile_info { + uint64_t translations; + uint64_t aborted; + uint64_t ops; + unsigned ops_max; + uint64_t del_ops; + uint64_t temps; + unsigned temps_max; + uint64_t host; + uint64_t guest; + uint64_t search_data; +}; + +/* accumulate the statistics from all TBs */ +static void collect_jit_profile_info(void *p, uint32_t hash, void *userp) +{ + struct jit_profile_info *jpi =3D userp; + TBStatistics *tbs =3D p; + + jpi->translations +=3D tbs->translations.total; + jpi->ops +=3D tbs->code.num_tcg_ops; + if (stat_per_translation(tbs, code.num_tcg_ops) > jpi->ops_max) { + jpi->ops_max =3D stat_per_translation(tbs, code.num_tcg_ops); + } + jpi->del_ops +=3D tbs->code.deleted_ops; + jpi->temps +=3D tbs->code.temps; + if (stat_per_translation(tbs, code.temps) > jpi->temps_max) { + jpi->temps_max =3D stat_per_translation(tbs, code.temps); + } + jpi->host +=3D tbs->code.out_len; + jpi->guest +=3D tbs->code.in_len; + jpi->search_data +=3D tbs->code.search_out_len; +} + +/* dump JIT statisticis using TCGProfile and TBStats */ +void dump_jit_profile_info(TCGProfile *s) +{ + if (!tb_stats_collection_enabled()) { + return; + } + + struct jit_profile_info *jpi =3D g_new0(struct jit_profile_info, 1); + + qht_iter(&tb_ctx.tb_stats, collect_jit_profile_info, jpi); + + if (jpi->translations) { + qemu_printf("translated TBs %" PRId64 "\n", jpi->translations= ); + qemu_printf("avg ops/TB %0.1f max=3D%d\n", + jpi->ops / (double) jpi->translations, jpi->ops_max); + qemu_printf("deleted ops/TB %0.2f\n", + jpi->del_ops / (double) jpi->translations); + qemu_printf("avg temps/TB %0.2f max=3D%d\n", + jpi->temps / (double) jpi->translations, jpi->temps_max); + qemu_printf("avg host code/TB %0.1f\n", + jpi->host / (double) jpi->translations); + qemu_printf("avg search data/TB %0.1f\n", + jpi->search_data / (double) jpi->translations); + + if (s) { + int64_t tot =3D s->interm_time + s->code_time; + qemu_printf("JIT cycles %" PRId64 " (%0.3f s at 2.4 G= Hz)\n", + tot, tot / 2.4e9); + qemu_printf("cycles/op %0.1f\n", + jpi->ops ? (double)tot / jpi->ops : 0); + qemu_printf("cycles/in byte %0.1f\n", + jpi->guest ? (double)tot / jpi->guest : 0); + qemu_printf("cycles/out byte %0.1f\n", + jpi->host ? (double)tot / jpi->host : 0); + qemu_printf("cycles/search byte %0.1f\n", + jpi->search_data ? (double)tot / jpi->search_data = : 0); + if (tot =3D=3D 0) { + tot =3D 1; + } + qemu_printf(" gen_interm time %0.1f%%\n", + (double)s->interm_time / tot * 100.0); + qemu_printf(" gen_code time %0.1f%%\n", + (double)s->code_time / tot * 100.0); + qemu_printf("optim./code time %0.1f%%\n", + (double)s->opt_time / (s->code_time ? s->code_time= : 1) + * 100.0); + qemu_printf("liveness/code time %0.1f%%\n", + (double)s->la_time / (s->code_time ? s->code_time : 1)= * 100.0); + qemu_printf("cpu_restore count %" PRId64 "\n", + s->restore_count); + qemu_printf(" avg cycles %0.1f\n", + s->restore_count ? (double)s->restore_time / s->restor= e_count : 0); + } + } +} + + void init_tb_stats_htable_if_not(void) { if (tb_stats_collection_enabled() && !tb_ctx.tb_stats.map) { diff --git a/accel/tcg/translate-all.c b/accel/tcg/translate-all.c index 85c6b7b409..708d55db02 100644 --- a/accel/tcg/translate-all.c +++ b/accel/tcg/translate-all.c @@ -1775,8 +1775,6 @@ TranslationBlock *tb_gen_code(CPUState *cpu, tb_overflow: =20 #ifdef CONFIG_PROFILER - /* includes aborted translations because of exceptions */ - atomic_set(&prof->tb_count1, prof->tb_count1 + 1); ti =3D profile_getclock(); #endif =20 @@ -1824,7 +1822,6 @@ TranslationBlock *tb_gen_code(CPUState *cpu, } =20 #ifdef CONFIG_PROFILER - atomic_set(&prof->tb_count, prof->tb_count + 1); atomic_set(&prof->interm_time, prof->interm_time + profile_getclock() = - ti); ti =3D profile_getclock(); #endif @@ -1871,13 +1868,12 @@ TranslationBlock *tb_gen_code(CPUState *cpu, =20 #ifdef CONFIG_PROFILER atomic_set(&prof->code_time, prof->code_time + profile_getclock() - ti= ); - atomic_set(&prof->code_in_len, prof->code_in_len + tb->size); - atomic_set(&prof->code_out_len, prof->code_out_len + gen_code_size); - atomic_set(&prof->search_out_len, prof->search_out_len + search_size); #endif =20 if (tb_stats_enabled(tb, TB_JIT_STATS)) { + atomic_add(&tb->tb_stats->code.in_len, tb->size); atomic_add(&tb->tb_stats->code.out_len, gen_code_size); + atomic_add(&tb->tb_stats->code.search_out_len, search_size); } =20 #ifdef DEBUG_DISAS diff --git a/include/exec/tb-stats.h b/include/exec/tb-stats.h index 3c219123c2..dbb52db23c 100644 --- a/include/exec/tb-stats.h +++ b/include/exec/tb-stats.h @@ -9,6 +9,9 @@ #define tb_stats_enabled(tb, JIT_STATS) \ (tb && tb->tb_stats && (tb->tb_stats->stats_enabled & JIT_STATS)) =20 +#define stat_per_translation(stat, name) \ + (stat->translations.total ? stat->name / stat->translations.total : 0) + typedef struct TBStatistics TBStatistics; =20 /* @@ -39,7 +42,13 @@ struct TBStatistics { unsigned num_tcg_ops; unsigned num_tcg_ops_opt; unsigned spills; + + /* CONFIG_PROFILE */ + unsigned temps; + unsigned deleted_ops; + unsigned in_len; unsigned out_len; + unsigned search_out_len; } code; =20 struct { @@ -56,6 +65,8 @@ bool tb_stats_cmp(const void *ap, const void *bp); =20 void init_tb_stats_htable_if_not(void); =20 +void dump_jit_profile_info(TCGProfile *s); + /* TBStatistic collection controls */ enum TBStatsStatus { TB_STATS_RUNNING, TB_STATS_PAUSED, TB_STATS_STOPPED }; =20 diff --git a/tcg/tcg.c b/tcg/tcg.c index 446e3d1708..46b31a2f68 100644 --- a/tcg/tcg.c +++ b/tcg/tcg.c @@ -2295,9 +2295,9 @@ void tcg_op_remove(TCGContext *s, TCGOp *op) QTAILQ_INSERT_TAIL(&s->free_ops, op, link); s->nb_ops--; =20 -#ifdef CONFIG_PROFILER - atomic_set(&s->prof.del_op_count, s->prof.del_op_count + 1); -#endif + if (tb_stats_enabled(s->current_tb, TB_JIT_STATS)) { + atomic_inc(&s->current_tb->tb_stats->code.deleted_ops); + } } =20 static TCGOp *tcg_op_alloc(TCGOpcode opc) @@ -3914,16 +3914,6 @@ void tcg_profile_snapshot(TCGProfile *prof, bool cou= nters, bool table) =20 if (counters) { PROF_ADD(prof, orig, cpu_exec_time); - PROF_ADD(prof, orig, tb_count1); - PROF_ADD(prof, orig, tb_count); - PROF_ADD(prof, orig, op_count); - PROF_MAX(prof, orig, op_count_max); - PROF_ADD(prof, orig, temp_count); - PROF_MAX(prof, orig, temp_count_max); - PROF_ADD(prof, orig, del_op_count); - PROF_ADD(prof, orig, code_in_len); - PROF_ADD(prof, orig, code_out_len); - PROF_ADD(prof, orig, search_out_len); PROF_ADD(prof, orig, interm_time); PROF_ADD(prof, orig, code_time); PROF_ADD(prof, orig, la_time); @@ -4003,26 +3993,17 @@ int tcg_gen_code(TCGContext *s, TranslationBlock *t= b) TCGOp *op; =20 s->current_tb =3D tb; - -#ifdef CONFIG_PROFILER - { + if (tb_stats_enabled(tb, TB_JIT_STATS)) { int n =3D 0; =20 QTAILQ_FOREACH(op, &s->ops, link) { n++; } - atomic_set(&prof->op_count, prof->op_count + n); - if (n > prof->op_count_max) { - atomic_set(&prof->op_count_max, n); - } + atomic_add(&tb->tb_stats->code.num_tcg_ops, n); =20 n =3D s->nb_temps; - atomic_set(&prof->temp_count, prof->temp_count + n); - if (n > prof->temp_count_max) { - atomic_set(&prof->temp_count_max, n); - } + atomic_add(&tb->tb_stats->code.temps, n); } -#endif =20 #ifdef DEBUG_DISAS if (unlikely(qemu_loglevel_mask(CPU_LOG_TB_OP) @@ -4229,70 +4210,16 @@ int tcg_gen_code(TCGContext *s, TranslationBlock *t= b) return tcg_current_code_size(s); } =20 -#ifdef CONFIG_PROFILER void tcg_dump_info(void) { + TCGProfile *s =3D NULL; +#ifdef CONFIG_PROFILER TCGProfile prof =3D {}; - const TCGProfile *s; - int64_t tb_count; - int64_t tb_div_count; - int64_t tot; - tcg_profile_snapshot_counters(&prof); s =3D &prof; - tb_count =3D s->tb_count; - tb_div_count =3D tb_count ? tb_count : 1; - tot =3D s->interm_time + s->code_time; - - qemu_printf("JIT cycles %" PRId64 " (%0.3f s at 2.4 GHz)\n", - tot, tot / 2.4e9); - qemu_printf("translated TBs %" PRId64 " (aborted=3D%" PRId64 - " %0.1f%%)\n", - tb_count, s->tb_count1 - tb_count, - (double)(s->tb_count1 - s->tb_count) - / (s->tb_count1 ? s->tb_count1 : 1) * 100.0); - qemu_printf("avg ops/TB %0.1f max=3D%d\n", - (double)s->op_count / tb_div_count, s->op_count_max); - qemu_printf("deleted ops/TB %0.2f\n", - (double)s->del_op_count / tb_div_count); - qemu_printf("avg temps/TB %0.2f max=3D%d\n", - (double)s->temp_count / tb_div_count, s->temp_count_max); - qemu_printf("avg host code/TB %0.1f\n", - (double)s->code_out_len / tb_div_count); - qemu_printf("avg search data/TB %0.1f\n", - (double)s->search_out_len / tb_div_count); - =20 - qemu_printf("cycles/op %0.1f\n", - s->op_count ? (double)tot / s->op_count : 0); - qemu_printf("cycles/in byte %0.1f\n", - s->code_in_len ? (double)tot / s->code_in_len : 0); - qemu_printf("cycles/out byte %0.1f\n", - s->code_out_len ? (double)tot / s->code_out_len : 0); - qemu_printf("cycles/search byte %0.1f\n", - s->search_out_len ? (double)tot / s->search_out_len : 0); - if (tot =3D=3D 0) { - tot =3D 1; - } - qemu_printf(" gen_interm time %0.1f%%\n", - (double)s->interm_time / tot * 100.0); - qemu_printf(" gen_code time %0.1f%%\n", - (double)s->code_time / tot * 100.0); - qemu_printf("optim./code time %0.1f%%\n", - (double)s->opt_time / (s->code_time ? s->code_time : 1) - * 100.0); - qemu_printf("liveness/code time %0.1f%%\n", - (double)s->la_time / (s->code_time ? s->code_time : 1) * 1= 00.0); - qemu_printf("cpu_restore count %" PRId64 "\n", - s->restore_count); - qemu_printf(" avg cycles %0.1f\n", - s->restore_count ? (double)s->restore_time / s->restore_co= unt : 0); -} -#else -void tcg_dump_info(void) -{ - qemu_printf("[TCG profiler not compiled]\n"); -} #endif + dump_jit_profile_info(s); +} =20 #ifdef ELF_HOST_MACHINE /* In order to use this feature, the backend needs to do three things: diff --git a/tcg/tcg.h b/tcg/tcg.h index bf6f3bcba3..026a066b9a 100644 --- a/tcg/tcg.h +++ b/tcg/tcg.h @@ -644,16 +644,6 @@ QEMU_BUILD_BUG_ON(NB_OPS > (1 << 8)); =20 typedef struct TCGProfile { int64_t cpu_exec_time; - int64_t tb_count1; - int64_t tb_count; - int64_t op_count; /* total insn count */ - int op_count_max; /* max insn per TB */ - int temp_count_max; - int64_t temp_count; - int64_t del_op_count; - int64_t code_in_len; - int64_t code_out_len; - int64_t search_out_len; int64_t interm_time; int64_t code_time; int64_t la_time; --=20 2.22.0 From nobody Tue May 7 09:25:28 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1565836446; cv=none; d=zoho.com; s=zohoarc; b=WUBpesrln8aoV+aJKFjopeuGSlKSh+t1yD3OM/oREpFooryVVUDHd3RrhUeuBHRJDMmRkxXmwW3tbS0X1F1/dx35oQZP+gv+eg5H0KP7JBVd4SeIKLdxTXT4ScInjdnAYKd4s9XXGhSNoEdzIF7twHCHl6QZggKm6Watpr6acfA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1565836446; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=WZ+ap7PqHS1Lv3NWUDj5Iw5/ChRjYMSE1waxMmaXLsk=; b=WZaAAbgZ9PKP5Ddjh8+Dgaybi7GHOKlmQAAIDYl3UfpUoJ82H+8zbmUcQlN6eWFcNJMitRirHhvGMEw/qohLOSS4W55ARKqnO+AGb6eh0U7COo0DpNEg4fvEd0jssYG2TMiXwbIpXrFW2p1a+JUNURac4NEA8i8KXFwgs/Zhf60= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1565836446181949.094751302063; Wed, 14 Aug 2019 19:34:06 -0700 (PDT) Received: from localhost ([::1]:37586 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1hy5aW-0000j0-3q for importer@patchew.org; Wed, 14 Aug 2019 22:34:04 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:48653) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1hy5MZ-0000pK-Mv for qemu-devel@nongnu.org; Wed, 14 Aug 2019 22:19:42 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hy5MX-0001kR-8b for qemu-devel@nongnu.org; Wed, 14 Aug 2019 22:19:39 -0400 Received: from mail-qk1-x743.google.com ([2607:f8b0:4864:20::743]:42928) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hy5MX-0001kJ-38 for qemu-devel@nongnu.org; Wed, 14 Aug 2019 22:19:37 -0400 Received: by mail-qk1-x743.google.com with SMTP id 201so746164qkm.9 for ; Wed, 14 Aug 2019 19:19:37 -0700 (PDT) Received: from localhost.localdomain ([2804:14c:482:121::1]) by smtp.googlemail.com with ESMTPSA id o5sm757943qkf.10.2019.08.14.19.19.33 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Wed, 14 Aug 2019 19:19:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=WZ+ap7PqHS1Lv3NWUDj5Iw5/ChRjYMSE1waxMmaXLsk=; b=VFa2TusAlezE5VNWo+6dIpbUWADubqF6O++wGRVGWwctOZF7jIJZKdNmIn7sdjCqU4 NtL8mHblqD7xdUnHKVR95BlG0uYz0jjyH5IALMgG0QM2BQEJ7mNSpQhxpgy60vhqgBkf NFyqTOr9jbCdV1y6r2GoWQtt8Pg2PScoyO2HLUgjiPedt573g0FyMwQLufrrbZ5RCred nbr3dfMS9ntuMA6CozwYQr19m6bQNDZ2sWOr2wllq+w/uIkOaSt7wF7ZpEIiJ32DBCZh vFQPWhbFgm9J8KDf3yD8KCOrYIEwJGyvZslF5URC/3FgjsoGE3BxeF4yZCoof2TKZLrM mp3Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=WZ+ap7PqHS1Lv3NWUDj5Iw5/ChRjYMSE1waxMmaXLsk=; b=rV1JFD/f6LjLlREkLJpTsXAahetfHiOhmBo8/KHqs+prsRXhOA1mI70ePPe0danHF1 kJyRcUXnMBDfhIIJUOPzToBTgAr1cKkIjHpu65Ts5YuZ1m9PPvdnmrikkCaDfbguGVwe fjlLZUd6HilN3Im9jhSSQeyMkrAtrU0rJJeItmBQ+5vuKevTaTnpQdIOuFiRgsZZqdKH 1K4RAbqiShi6Brmd2dAv6CEiwPLrXupYwSAfD/lbHSfML+JNuRoDFN+WRM/4F+yNd7xj p1dO4b2kshM2ZAdW3Q3NyuK633t3sP1ap763U50/hlPgBKSS2uA1jkC2WfgEV+wjnP3f ApIA== X-Gm-Message-State: APjAAAWpe/fNBmxrzDosC2NVz8QobhL/fwFgow/ZGdAL7Wbt2o+M3WRB fD4k1hI2fTVWRUfM0KDJ22OXKExN48BIwQ== X-Google-Smtp-Source: APXvYqwPG1OK8ksScjQ+zkgu1DIcgAZ1Gh7aV4Qe3bTKoR4VvpktbF86yA7UpuZblefge8G/557Bkw== X-Received: by 2002:a37:ae42:: with SMTP id x63mr2070812qke.41.1565835576004; Wed, 14 Aug 2019 19:19:36 -0700 (PDT) From: vandersonmr To: qemu-devel@nongnu.org Date: Wed, 14 Aug 2019 23:18:52 -0300 Message-Id: <20190815021857.19526-6-vandersonmr2@gmail.com> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190815021857.19526-1-vandersonmr2@gmail.com> References: <20190815021857.19526-1-vandersonmr2@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::743 Subject: [Qemu-devel] [PATCH v5 05/10] accel: adding TB_JIT_TIME and full replacing CONFIG_PROFILER X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Paolo Bonzini , vandersonmr , Markus Armbruster , "Dr. David Alan Gilbert" , Richard Henderson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Replace all others CONFIG_PROFILER statistics and migrate it to TBStatistics system. However, TCGProfiler still exists and can be use to store global statistics and times. All TB related statistics goes to TBStatistics. Signed-off-by: Vanderson M. do Rosario --- accel/tcg/tb-stats.c | 95 ++++++++++++++++++++--------- accel/tcg/translate-all.c | 47 ++++++++------- configure | 3 - cpus.c | 14 ++--- include/exec/tb-stats.h | 21 ++++++- include/qemu/timer.h | 5 +- monitor/misc.c | 28 ++------- tcg/tcg.c | 124 +++++++++++--------------------------- tcg/tcg.h | 10 +-- vl.c | 8 +-- 10 files changed, 161 insertions(+), 194 deletions(-) diff --git a/accel/tcg/tb-stats.c b/accel/tcg/tb-stats.c index 9b720d9b86..2bb1fde837 100644 --- a/accel/tcg/tb-stats.c +++ b/accel/tcg/tb-stats.c @@ -8,6 +8,8 @@ =20 #include "exec/tb-stats.h" =20 +uint64_t dev_time; + struct jit_profile_info { uint64_t translations; uint64_t aborted; @@ -19,6 +21,13 @@ struct jit_profile_info { uint64_t host; uint64_t guest; uint64_t search_data; + + uint64_t interm_time; + uint64_t code_time; + uint64_t restore_count; + uint64_t restore_time; + uint64_t opt_time; + uint64_t la_time; }; =20 /* accumulate the statistics from all TBs */ @@ -40,6 +49,29 @@ static void collect_jit_profile_info(void *p, uint32_t h= ash, void *userp) jpi->host +=3D tbs->code.out_len; jpi->guest +=3D tbs->code.in_len; jpi->search_data +=3D tbs->code.search_out_len; + + jpi->interm_time +=3D stat_per_translation(tbs, time.interm); + jpi->code_time +=3D stat_per_translation(tbs, time.code); + jpi->opt_time +=3D stat_per_translation(tbs, time.opt); + jpi->la_time +=3D stat_per_translation(tbs, time.la); + jpi->restore_time +=3D tbs->time.restore; + jpi->restore_count +=3D tbs->time.restore_count; +} + +void dump_jit_exec_time_info(uint64_t dev_time) +{ + static uint64_t last_cpu_exec_time; + uint64_t cpu_exec_time; + uint64_t delta; + + cpu_exec_time =3D tcg_cpu_exec_time(); + delta =3D cpu_exec_time - last_cpu_exec_time; + + qemu_printf("async time %" PRId64 " (%0.3f)\n", + dev_time, dev_time / (double) NANOSECONDS_PER_SECOND); + qemu_printf("qemu time %" PRId64 " (%0.3f)\n", + delta, delta / (double) NANOSECONDS_PER_SECOND); + last_cpu_exec_time =3D cpu_exec_time; } =20 /* dump JIT statisticis using TCGProfile and TBStats */ @@ -66,36 +98,45 @@ void dump_jit_profile_info(TCGProfile *s) qemu_printf("avg search data/TB %0.1f\n", jpi->search_data / (double) jpi->translations); =20 + uint64_t tot =3D jpi->interm_time + jpi->code_time; + + qemu_printf("JIT cycles %" PRId64 " (%0.3fs at 2.4 GHz)\n= ", + tot, tot / 2.4e9); + qemu_printf("cycles/op %0.1f\n", + jpi->ops ? (double)tot / jpi->ops : 0); + qemu_printf("cycles/in byte %0.1f\n", + jpi->guest ? (double)tot / jpi->guest : 0); + qemu_printf("cycles/out byte %0.1f\n", + jpi->host ? (double)tot / jpi->host : 0); + qemu_printf("cycles/search byte %0.1f\n", + jpi->search_data ? (double)tot / jpi->search_data : 0); + if (tot =3D=3D 0) { + tot =3D 1; + } + + qemu_printf(" gen_interm time %0.1f%%\n", + (double)jpi->interm_time / tot * 100.0); + qemu_printf(" gen_code time %0.1f%%\n", + (double)jpi->code_time / tot * 100.0); + + qemu_printf("optim./code time %0.1f%%\n", + (double)jpi->opt_time / (jpi->code_time ? jpi->code_time := 1) + * 100.0); + qemu_printf("liveness/code time %0.1f%%\n", + (double)jpi->la_time / (jpi->code_time ? jpi->code_time : = 1) * 100.0); + + qemu_printf("cpu_restore count %" PRId64 "\n", + jpi->restore_count); + qemu_printf(" avg cycles %0.1f\n", + jpi->restore_count ? (double)jpi->restore_time / jpi->rest= ore_count : 0); + if (s) { - int64_t tot =3D s->interm_time + s->code_time; - qemu_printf("JIT cycles %" PRId64 " (%0.3f s at 2.4 G= Hz)\n", - tot, tot / 2.4e9); - qemu_printf("cycles/op %0.1f\n", - jpi->ops ? (double)tot / jpi->ops : 0); - qemu_printf("cycles/in byte %0.1f\n", - jpi->guest ? (double)tot / jpi->guest : 0); - qemu_printf("cycles/out byte %0.1f\n", - jpi->host ? (double)tot / jpi->host : 0); - qemu_printf("cycles/search byte %0.1f\n", - jpi->search_data ? (double)tot / jpi->search_data = : 0); - if (tot =3D=3D 0) { - tot =3D 1; - } - qemu_printf(" gen_interm time %0.1f%%\n", - (double)s->interm_time / tot * 100.0); - qemu_printf(" gen_code time %0.1f%%\n", - (double)s->code_time / tot * 100.0); - qemu_printf("optim./code time %0.1f%%\n", - (double)s->opt_time / (s->code_time ? s->code_time= : 1) - * 100.0); - qemu_printf("liveness/code time %0.1f%%\n", - (double)s->la_time / (s->code_time ? s->code_time : 1)= * 100.0); - qemu_printf("cpu_restore count %" PRId64 "\n", - s->restore_count); - qemu_printf(" avg cycles %0.1f\n", - s->restore_count ? (double)s->restore_time / s->restor= e_count : 0); + qemu_printf("cpu exec time %" PRId64 " (%0.3fs)\n", + s->cpu_exec_time, s->cpu_exec_time / (double) NANOSECONDS_= PER_SECOND); } } + + g_free(jpi); } =20 =20 diff --git a/accel/tcg/translate-all.c b/accel/tcg/translate-all.c index 708d55db02..b94a1d67b6 100644 --- a/accel/tcg/translate-all.c +++ b/accel/tcg/translate-all.c @@ -337,10 +337,11 @@ static int cpu_restore_state_from_tb(CPUState *cpu, T= ranslationBlock *tb, CPUArchState *env =3D cpu->env_ptr; uint8_t *p =3D tb->tc.ptr + tb->tc.size; int i, j, num_insns =3D tb->icount; -#ifdef CONFIG_PROFILER - TCGProfile *prof =3D &tcg_ctx->prof; - int64_t ti =3D profile_getclock(); -#endif + uint64_t ti =3D 0; + + if (tb_stats_enabled(tb, TB_JIT_TIME)) { + ti =3D profile_getclock(); + } =20 searched_pc -=3D GETPC_ADJ; =20 @@ -370,11 +371,11 @@ static int cpu_restore_state_from_tb(CPUState *cpu, T= ranslationBlock *tb, } restore_state_to_opc(env, tb, data); =20 -#ifdef CONFIG_PROFILER - atomic_set(&prof->restore_time, - prof->restore_time + profile_getclock() - ti); - atomic_set(&prof->restore_count, prof->restore_count + 1); -#endif + if (tb_stats_enabled(tb, TB_JIT_TIME)) { + atomic_add(&tb->tb_stats->time.restore, profile_getclock() - ti); + atomic_inc(&tb->tb_stats->time.restore_count); + } + return 0; } =20 @@ -1725,10 +1726,8 @@ TranslationBlock *tb_gen_code(CPUState *cpu, target_ulong virt_page2; tcg_insn_unit *gen_code_buf; int gen_code_size, search_size, max_insns; -#ifdef CONFIG_PROFILER - TCGProfile *prof =3D &tcg_ctx->prof; - int64_t ti; -#endif + uint64_t ti =3D 0; + assert_memory_lock(); =20 phys_pc =3D get_page_addr_code(env, pc); @@ -1774,9 +1773,6 @@ TranslationBlock *tb_gen_code(CPUState *cpu, tcg_ctx->tb_cflags =3D cflags; tb_overflow: =20 -#ifdef CONFIG_PROFILER - ti =3D profile_getclock(); -#endif =20 /* * We want to fetch the stats structure before we start code @@ -1797,6 +1793,11 @@ TranslationBlock *tb_gen_code(CPUState *cpu, tb->tb_stats->stats_enabled |=3D TB_JIT_STATS; atomic_inc(&tb->tb_stats->translations.total); } + + if (flag & TB_JIT_TIME) { + tb->tb_stats->stats_enabled |=3D TB_JIT_TIME; + ti =3D profile_getclock(); + } } else { tb->tb_stats =3D NULL; } @@ -1821,10 +1822,10 @@ TranslationBlock *tb_gen_code(CPUState *cpu, tcg_ctx->tb_jmp_target_addr =3D tb->jmp_target_arg; } =20 -#ifdef CONFIG_PROFILER - atomic_set(&prof->interm_time, prof->interm_time + profile_getclock() = - ti); - ti =3D profile_getclock(); -#endif + if (tb_stats_enabled(tb, TB_JIT_TIME)) { + atomic_add(&tb->tb_stats->time.interm, profile_getclock() - ti); + ti =3D profile_getclock(); + } =20 gen_code_size =3D tcg_gen_code(tcg_ctx, tb); if (unlikely(gen_code_size < 0)) { @@ -1866,9 +1867,9 @@ TranslationBlock *tb_gen_code(CPUState *cpu, } tb->tc.size =3D gen_code_size; =20 -#ifdef CONFIG_PROFILER - atomic_set(&prof->code_time, prof->code_time + profile_getclock() - ti= ); -#endif + if (tb_stats_enabled(tb, TB_JIT_TIME)) { + atomic_add(&tb->tb_stats->time.code, profile_getclock() - ti); + } =20 if (tb_stats_enabled(tb, TB_JIT_STATS)) { atomic_add(&tb->tb_stats->code.in_len, tb->size); diff --git a/configure b/configure index 714e7fb6a1..0b3c45c05b 100755 --- a/configure +++ b/configure @@ -6614,9 +6614,6 @@ fi if test "$static" =3D "yes" ; then echo "CONFIG_STATIC=3Dy" >> $config_host_mak fi -if test "$profiler" =3D "yes" ; then - echo "CONFIG_PROFILER=3Dy" >> $config_host_mak -fi if test "$slirp" !=3D "no"; then echo "CONFIG_SLIRP=3Dy" >> $config_host_mak echo "CONFIG_SMBD_COMMAND=3D\"$smbd\"" >> $config_host_mak diff --git a/cpus.c b/cpus.c index 927a00aa90..d8e4e89c19 100644 --- a/cpus.c +++ b/cpus.c @@ -1423,21 +1423,17 @@ static void process_icount_data(CPUState *cpu) static int tcg_cpu_exec(CPUState *cpu) { int ret; -#ifdef CONFIG_PROFILER - int64_t ti; -#endif + uint64_t ti; =20 assert(tcg_enabled()); -#ifdef CONFIG_PROFILER ti =3D profile_getclock(); -#endif + cpu_exec_start(cpu); ret =3D cpu_exec(cpu); cpu_exec_end(cpu); -#ifdef CONFIG_PROFILER - atomic_set(&tcg_ctx->prof.cpu_exec_time, - tcg_ctx->prof.cpu_exec_time + profile_getclock() - ti); -#endif + + atomic_add(&tcg_ctx->prof.cpu_exec_time, profile_getclock() - ti); + return ret; } =20 diff --git a/include/exec/tb-stats.h b/include/exec/tb-stats.h index dbb52db23c..1dcfcdf9e8 100644 --- a/include/exec/tb-stats.h +++ b/include/exec/tb-stats.h @@ -57,22 +57,39 @@ struct TBStatistics { unsigned long spanning; } translations; =20 + struct { + uint64_t restore; + uint64_t restore_count; + uint64_t interm; + uint64_t code; + uint64_t opt; + uint64_t la; + } time; + /* current TB linked to this TBStatistics */ TranslationBlock *tb; }; =20 bool tb_stats_cmp(const void *ap, const void *bp); =20 +void dump_jit_exec_time_info(uint64_t dev_time); + void init_tb_stats_htable_if_not(void); =20 void dump_jit_profile_info(TCGProfile *s); =20 /* TBStatistic collection controls */ -enum TBStatsStatus { TB_STATS_RUNNING, TB_STATS_PAUSED, TB_STATS_STOPPED }; +enum TBStatsStatus { + TB_STATS_DISABLED =3D 0, + TB_STATS_RUNNING, + TB_STATS_PAUSED, + TB_STATS_STOPPED +}; =20 #define TB_NOTHING 0 #define TB_EXEC_STATS 1 -#define TB_JIT_STATS (1 << 2) +#define TB_JIT_STATS 2 +#define TB_JIT_TIME 4 =20 extern int tcg_collect_tb_stats; extern uint32_t default_tbstats_flag; diff --git a/include/qemu/timer.h b/include/qemu/timer.h index 5d978e1634..27571a7037 100644 --- a/include/qemu/timer.h +++ b/include/qemu/timer.h @@ -1037,13 +1037,10 @@ static inline int64_t cpu_get_host_ticks(void) } #endif =20 -#ifdef CONFIG_PROFILER static inline int64_t profile_getclock(void) { return get_clock(); } =20 -extern int64_t dev_time; -#endif - +extern uint64_t dev_time; #endif diff --git a/monitor/misc.c b/monitor/misc.c index 00338c002a..4839d6875f 100644 --- a/monitor/misc.c +++ b/monitor/misc.c @@ -472,6 +472,11 @@ static void hmp_info_jit(Monitor *mon, const QDict *qd= ict) =20 static void hmp_info_opcount(Monitor *mon, const QDict *qdict) { + if (!tb_stats_collection_enabled()) { + error_report("TB information not being recorded."); + return; + } + dump_opcount_info(); } #endif @@ -1082,32 +1087,11 @@ static void hmp_info_mtree(Monitor *mon, const QDic= t *qdict) mtree_info(flatview, dispatch_tree, owner); } =20 -#ifdef CONFIG_PROFILER - -int64_t dev_time; - static void hmp_info_profile(Monitor *mon, const QDict *qdict) { - static int64_t last_cpu_exec_time; - int64_t cpu_exec_time; - int64_t delta; - - cpu_exec_time =3D tcg_cpu_exec_time(); - delta =3D cpu_exec_time - last_cpu_exec_time; - - monitor_printf(mon, "async time %" PRId64 " (%0.3f)\n", - dev_time, dev_time / (double)NANOSECONDS_PER_SECOND); - monitor_printf(mon, "qemu time %" PRId64 " (%0.3f)\n", - delta, delta / (double)NANOSECONDS_PER_SECOND); - last_cpu_exec_time =3D cpu_exec_time; + dump_jit_exec_time_info(dev_time); dev_time =3D 0; } -#else -static void hmp_info_profile(Monitor *mon, const QDict *qdict) -{ - monitor_printf(mon, "Internal profiler not compiled\n"); -} -#endif =20 /* Capture support */ static QLIST_HEAD (capture_list_head, CaptureState) capture_head; diff --git a/tcg/tcg.c b/tcg/tcg.c index 46b31a2f68..1cd07c6c47 100644 --- a/tcg/tcg.c +++ b/tcg/tcg.c @@ -3885,82 +3885,34 @@ static void tcg_reg_alloc_call(TCGContext *s, TCGOp= *op) } } =20 -#ifdef CONFIG_PROFILER - /* avoid copy/paste errors */ #define PROF_ADD(to, from, field) \ do { \ (to)->field +=3D atomic_read(&((from)->field)); \ } while (0) =20 -#define PROF_MAX(to, from, field) \ - do { \ - typeof((from)->field) val__ =3D atomic_read(&((from)->field)); \ - if (val__ > (to)->field) { \ - (to)->field =3D val__; \ - } \ - } while (0) - -/* Pass in a zero'ed @prof */ -static inline -void tcg_profile_snapshot(TCGProfile *prof, bool counters, bool table) +static void collect_tcg_profiler(TCGProfile *prof) { + int i; unsigned int n_ctxs =3D atomic_read(&n_tcg_ctxs); - unsigned int i; =20 for (i =3D 0; i < n_ctxs; i++) { TCGContext *s =3D atomic_read(&tcg_ctxs[i]); const TCGProfile *orig =3D &s->prof; =20 - if (counters) { - PROF_ADD(prof, orig, cpu_exec_time); - PROF_ADD(prof, orig, interm_time); - PROF_ADD(prof, orig, code_time); - PROF_ADD(prof, orig, la_time); - PROF_ADD(prof, orig, opt_time); - PROF_ADD(prof, orig, restore_count); - PROF_ADD(prof, orig, restore_time); - } - if (table) { - int i; + PROF_ADD(prof, orig, cpu_exec_time); =20 - for (i =3D 0; i < NB_OPS; i++) { - PROF_ADD(prof, orig, table_op_count[i]); - } + for (i =3D 0; i < NB_OPS; i++) { + PROF_ADD(prof, orig, table_op_count[i]); } } } =20 -#undef PROF_ADD -#undef PROF_MAX - -static void tcg_profile_snapshot_counters(TCGProfile *prof) -{ - tcg_profile_snapshot(prof, true, false); -} - -static void tcg_profile_snapshot_table(TCGProfile *prof) -{ - tcg_profile_snapshot(prof, false, true); -} - -void tcg_dump_op_count(void) -{ - TCGProfile prof =3D {}; - int i; - - tcg_profile_snapshot_table(&prof); - for (i =3D 0; i < NB_OPS; i++) { - qemu_printf("%s %" PRId64 "\n", tcg_op_defs[i].name, - prof.table_op_count[i]); - } -} - -int64_t tcg_cpu_exec_time(void) +uint64_t tcg_cpu_exec_time(void) { unsigned int n_ctxs =3D atomic_read(&n_tcg_ctxs); unsigned int i; - int64_t ret =3D 0; + uint64_t ret =3D 0; =20 for (i =3D 0; i < n_ctxs; i++) { const TCGContext *s =3D atomic_read(&tcg_ctxs[i]); @@ -3970,25 +3922,9 @@ int64_t tcg_cpu_exec_time(void) } return ret; } -#else -void tcg_dump_op_count(void) -{ - qemu_printf("[TCG profiler not compiled]\n"); -} - -int64_t tcg_cpu_exec_time(void) -{ - error_report("%s: TCG profiler not compiled", __func__); - exit(EXIT_FAILURE); -} -#endif - =20 int tcg_gen_code(TCGContext *s, TranslationBlock *tb) { -#ifdef CONFIG_PROFILER - TCGProfile *prof =3D &s->prof; -#endif int i, num_insns; TCGOp *op; =20 @@ -4041,18 +3977,18 @@ int tcg_gen_code(TCGContext *s, TranslationBlock *t= b) } #endif =20 -#ifdef CONFIG_PROFILER - atomic_set(&prof->opt_time, prof->opt_time - profile_getclock()); -#endif + if (tb_stats_enabled(tb, TB_JIT_TIME)) { + atomic_add(&tb->tb_stats->time.opt, -profile_getclock()); + } =20 #ifdef USE_TCG_OPTIMIZATIONS tcg_optimize(s); #endif =20 -#ifdef CONFIG_PROFILER - atomic_set(&prof->opt_time, prof->opt_time + profile_getclock()); - atomic_set(&prof->la_time, prof->la_time - profile_getclock()); -#endif + if (tb_stats_enabled(tb, TB_JIT_TIME)) { + atomic_add(&tb->tb_stats->time.opt, profile_getclock()); + atomic_add(&tb->tb_stats->time.la, -profile_getclock()); + } =20 reachable_code_pass(s); liveness_pass_1(s); @@ -4075,9 +4011,9 @@ int tcg_gen_code(TCGContext *s, TranslationBlock *tb) } } =20 -#ifdef CONFIG_PROFILER - atomic_set(&prof->la_time, prof->la_time + profile_getclock()); -#endif + if (tb_stats_enabled(tb, TB_JIT_TIME)) { + atomic_set(&tb->tb_stats->time.la, profile_getclock()); + } =20 #ifdef DEBUG_DISAS if (unlikely(qemu_loglevel_mask(CPU_LOG_TB_OP_OPT) @@ -4110,14 +4046,17 @@ int tcg_gen_code(TCGContext *s, TranslationBlock *t= b) s->pool_labels =3D NULL; #endif =20 + if (!tb_stats_collection_enabled()) { + QTAILQ_FOREACH(op, &s->ops, link) { + TCGOpcode opc =3D op->opc; + atomic_add(&s->prof.table_op_count[opc], 1); + } + } + num_insns =3D -1; QTAILQ_FOREACH(op, &s->ops, link) { TCGOpcode opc =3D op->opc; =20 -#ifdef CONFIG_PROFILER - atomic_set(&prof->table_op_count[opc], prof->table_op_count[opc] += 1); -#endif - switch (opc) { case INDEX_op_mov_i32: case INDEX_op_mov_i64: @@ -4210,14 +4149,23 @@ int tcg_gen_code(TCGContext *s, TranslationBlock *t= b) return tcg_current_code_size(s); } =20 +void tcg_dump_op_count(void) +{ + TCGProfile prof =3D {}; + int i; + + collect_tcg_profiler(&prof); + for (i =3D 0; i < NB_OPS; i++) { + qemu_printf("%s %" PRId64 "\n", tcg_op_defs[i].name, prof.table_op= _count[i]); + } +} + void tcg_dump_info(void) { TCGProfile *s =3D NULL; -#ifdef CONFIG_PROFILER TCGProfile prof =3D {}; - tcg_profile_snapshot_counters(&prof); s =3D &prof; -#endif + collect_tcg_profiler(s); dump_jit_profile_info(s); } =20 diff --git a/tcg/tcg.h b/tcg/tcg.h index 026a066b9a..12f54283db 100644 --- a/tcg/tcg.h +++ b/tcg/tcg.h @@ -644,12 +644,6 @@ QEMU_BUILD_BUG_ON(NB_OPS > (1 << 8)); =20 typedef struct TCGProfile { int64_t cpu_exec_time; - int64_t interm_time; - int64_t code_time; - int64_t la_time; - int64_t opt_time; - int64_t restore_count; - int64_t restore_time; int64_t table_op_count[NB_OPS]; } TCGProfile; =20 @@ -677,9 +671,7 @@ struct TCGContext { =20 tcg_insn_unit *code_ptr; =20 -#ifdef CONFIG_PROFILER TCGProfile prof; -#endif =20 #ifdef CONFIG_DEBUG_TCG int temps_in_use; @@ -1011,7 +1003,7 @@ int tcg_check_temp_count(void); #define tcg_check_temp_count() 0 #endif =20 -int64_t tcg_cpu_exec_time(void); +uint64_t tcg_cpu_exec_time(void); void tcg_dump_info(void); void tcg_dump_op_count(void); =20 diff --git a/vl.c b/vl.c index b426b32134..ef7737a7bc 100644 --- a/vl.c +++ b/vl.c @@ -1781,17 +1781,11 @@ static bool main_loop_should_exit(void) =20 static void main_loop(void) { -#ifdef CONFIG_PROFILER - int64_t ti; -#endif + uint64_t ti; while (!main_loop_should_exit()) { -#ifdef CONFIG_PROFILER ti =3D profile_getclock(); -#endif main_loop_wait(false); -#ifdef CONFIG_PROFILER dev_time +=3D profile_getclock() - ti; -#endif } } =20 --=20 2.22.0 From nobody Tue May 7 09:25:28 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1565837258; cv=none; d=zoho.com; s=zohoarc; b=hJTgL+raUKlGDKxbKGuvvzngh0acPnqOGKG8kDOBPtscs8Fo2ZeDZOslGqUKyhNN7++XnfPMJwwhvxZbDkwvVVzBnHsRKhtHrPnNskUSa/OhcvQC3GqqP7e4chGdys12w3GdJa8gKi+Lryfi37RFITRp0ixFxDipIzchcFCcaJ8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1565837258; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=Wb4KcoWnaCnYbF72DRr9dR9BuvxlxCZEPYlHe1HxHes=; b=kDbfwCcGKWQ334aqNF5iFYwA75ZET6kSO5/TGDRcKOuEC7XNESFfMfoa5mWF8YPAVeapmHm6nrdC3nYjgADBNHaIy6CfNICLspbnbdQ8AYhWs6QuvRWoujOpvOmO8AdJmFd/RSX5orRMUXj4aIQ2uKNooG79UYymhGCgXQ6uL4k= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 156583725811849.562447625297295; Wed, 14 Aug 2019 19:47:38 -0700 (PDT) Received: from localhost ([::1]:37760 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1hy5na-0001Nv-7j for importer@patchew.org; Wed, 14 Aug 2019 22:47:34 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:48660) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1hy5Ma-0000qZ-Ig for qemu-devel@nongnu.org; Wed, 14 Aug 2019 22:19:41 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hy5MZ-0001me-0X for qemu-devel@nongnu.org; Wed, 14 Aug 2019 22:19:40 -0400 Received: from mail-qt1-x844.google.com ([2607:f8b0:4864:20::844]:44450) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hy5MY-0001mP-T3 for qemu-devel@nongnu.org; Wed, 14 Aug 2019 22:19:38 -0400 Received: by mail-qt1-x844.google.com with SMTP id 44so889662qtg.11 for ; Wed, 14 Aug 2019 19:19:38 -0700 (PDT) Received: from localhost.localdomain ([2804:14c:482:121::1]) by smtp.googlemail.com with ESMTPSA id o5sm757943qkf.10.2019.08.14.19.19.36 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Wed, 14 Aug 2019 19:19:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Wb4KcoWnaCnYbF72DRr9dR9BuvxlxCZEPYlHe1HxHes=; b=PDY8tVWtz9ZEd2wVc6ThuiHPtaDV73Z27I5in8d5oLUVv7BJ6/PCP/tLHqFIbf6nGM xoCOeEacn007gPZ+NZOb8lmCWb5pYyJk1MHAB2QE2Vl89kJF7pEwiR2dUev29BUNC6j5 F8jw1BDoViQSdKuj9ejWgaSMCk4wQyIlAnyn8Rc3IyOX2VIGhvoiXw8Jyc6XOrWpqZy7 Fo+bKY+tgrILJgqOU0jVGP2V8w838fZov2gBr8DQay98445YqxYdG6cJtbGS4CWtmEwS v+XF3j6J13fVORh2i4X81k+9a6He/T3+jfVEEPfzvCRYmKfFuubrYhLe9pm9bH3P0SzN 2C8A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Wb4KcoWnaCnYbF72DRr9dR9BuvxlxCZEPYlHe1HxHes=; b=bSc6NLjUD2W+C4Y8mgr7y5ojRkWMWAAzOfzsMk3GnTRMaZv4oV/jNAFj3GYHYDbS/h 7ABuBHlF7Rsc0/YrWx4kqtDtKddPD5VgZ+8bxM0vzCH2/7RX/OSEwnvTap3g/+ieibMl QnNV99HbKyVhp9LGOWzYRTZ+coWF3uk/OTKMQUowZmxbPh/89oJTywHRuMs95spE6u+b Scko+Kp36kMWnvAIhtJAzhFtdYdBBWj/nbb2XH0rQgM/00BZ1Ms5nQvpO0EiaV658Rqk B5gz2FdTha8TpwQXUZHT6e/DhoHGoAq7cf2BqHlTRbzzQ2spInHAVtbB9mPnhyAks+Vl 2HzQ== X-Gm-Message-State: APjAAAWfdm0ac2nPCit9SnE+uf8DUH6MZYK1N1yftAUkCW5n6fVCImRD z6qWv6YQvcxTFNtiQH7IP+rs+v4RyCs= X-Google-Smtp-Source: APXvYqwVZijoYBGnZMtpa/+zotDo0Nus1YjM4Vt+ugKHwyGvVSssLW6cGvJXGm+3NkDrTfrIVLe+Mw== X-Received: by 2002:a0c:96a8:: with SMTP id a37mr1881222qvd.132.1565835578028; Wed, 14 Aug 2019 19:19:38 -0700 (PDT) From: vandersonmr To: qemu-devel@nongnu.org Date: Wed, 14 Aug 2019 23:18:53 -0300 Message-Id: <20190815021857.19526-7-vandersonmr2@gmail.com> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190815021857.19526-1-vandersonmr2@gmail.com> References: <20190815021857.19526-1-vandersonmr2@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::844 Subject: [Qemu-devel] [PATCH v5 06/10] log: adding -d tb_stats to control tbstats X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Paolo Bonzini , vandersonmr , Richard Henderson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Adding -d tb_stats to control TBStatistics collection: -d tb_stats[[,level=3D(+all+jit+exec+time)][,dump_limit=3D]] "dump_limit" is used to limit the number of dumped TBStats in linux-user mode. [all+jit+exec+time] control the profilling level used by the TBStats. Can be used as follow: -d tb_stats -d tb_stats,level=3Djit+time -d tb_stats,dump_limit=3D15 ... Signed-off-by: Vanderson M. do Rosario --- accel/tcg/tb-stats.c | 1 + accel/tcg/translator.c | 1 + include/exec/gen-icount.h | 1 + include/exec/tb-stats.h | 15 --------------- include/qemu-common.h | 15 +++++++++++++++ include/qemu/log.h | 1 + tcg/tcg.c | 1 + util/log.c | 35 +++++++++++++++++++++++++++++++++++ 8 files changed, 55 insertions(+), 15 deletions(-) diff --git a/accel/tcg/tb-stats.c b/accel/tcg/tb-stats.c index 2bb1fde837..dddb9d4537 100644 --- a/accel/tcg/tb-stats.c +++ b/accel/tcg/tb-stats.c @@ -3,6 +3,7 @@ #include "disas/disas.h" #include "exec/exec-all.h" #include "tcg.h" +#include "qemu-common.h" =20 #include "qemu/qemu-print.h" =20 diff --git a/accel/tcg/translator.c b/accel/tcg/translator.c index 834265d5be..ea7c3a9f77 100644 --- a/accel/tcg/translator.c +++ b/accel/tcg/translator.c @@ -16,6 +16,7 @@ #include "exec/gen-icount.h" #include "exec/log.h" #include "exec/translator.h" +#include "qemu-common.h" =20 /* Pairs with tcg_clear_temp_count. To be called by #TranslatorOps.{translate_insn,tb_stop} if diff --git a/include/exec/gen-icount.h b/include/exec/gen-icount.h index b3efe41894..6f54586dd6 100644 --- a/include/exec/gen-icount.h +++ b/include/exec/gen-icount.h @@ -2,6 +2,7 @@ #define GEN_ICOUNT_H =20 #include "qemu/timer.h" +#include "qemu-common.h" =20 /* Helpers for instruction counting code generation. */ =20 diff --git a/include/exec/tb-stats.h b/include/exec/tb-stats.h index 1dcfcdf9e8..c0948e606a 100644 --- a/include/exec/tb-stats.h +++ b/include/exec/tb-stats.h @@ -79,21 +79,6 @@ void init_tb_stats_htable_if_not(void); void dump_jit_profile_info(TCGProfile *s); =20 /* TBStatistic collection controls */ -enum TBStatsStatus { - TB_STATS_DISABLED =3D 0, - TB_STATS_RUNNING, - TB_STATS_PAUSED, - TB_STATS_STOPPED -}; - -#define TB_NOTHING 0 -#define TB_EXEC_STATS 1 -#define TB_JIT_STATS 2 -#define TB_JIT_TIME 4 - -extern int tcg_collect_tb_stats; -extern uint32_t default_tbstats_flag; - void enable_collect_tb_stats(void); void disable_collect_tb_stats(void); void pause_collect_tb_stats(void); diff --git a/include/qemu-common.h b/include/qemu-common.h index 0235cd3b91..362e48c445 100644 --- a/include/qemu-common.h +++ b/include/qemu-common.h @@ -130,4 +130,19 @@ void page_size_init(void); * returned. */ bool dump_in_progress(void); =20 +enum TBStatsStatus { + TB_STATS_DISABLED =3D 0, + TB_STATS_RUNNING, + TB_STATS_PAUSED, + TB_STATS_STOPPED +}; + +#define TB_NOTHING 0 +#define TB_EXEC_STATS 1 +#define TB_JIT_STATS 2 +#define TB_JIT_TIME 4 + +extern int tcg_collect_tb_stats; +extern uint32_t default_tbstats_flag; + #endif diff --git a/include/qemu/log.h b/include/qemu/log.h index b097a6cae1..a8d1997cde 100644 --- a/include/qemu/log.h +++ b/include/qemu/log.h @@ -45,6 +45,7 @@ static inline bool qemu_log_separate(void) /* LOG_TRACE (1 << 15) is defined in log-for-trace.h */ #define CPU_LOG_TB_OP_IND (1 << 16) #define CPU_LOG_TB_FPU (1 << 17) +#define CPU_LOG_TB_STATS (1 << 18) =20 /* Lock output for a series of related logs. Since this is not needed * for a single qemu_log / qemu_log_mask / qemu_log_mask_and_addr, we diff --git a/tcg/tcg.c b/tcg/tcg.c index 1cd07c6c47..c6c9c938dc 100644 --- a/tcg/tcg.c +++ b/tcg/tcg.c @@ -35,6 +35,7 @@ #include "qemu/host-utils.h" #include "qemu/qemu-print.h" #include "qemu/timer.h" +#include "qemu-common.h" =20 /* Note: the long term plan is to reduce the dependencies on the QEMU CPU definitions. Currently they are used for qemu_ld/st diff --git a/util/log.c b/util/log.c index 29021a4584..09cfb13b45 100644 --- a/util/log.c +++ b/util/log.c @@ -19,17 +19,20 @@ =20 #include "qemu/osdep.h" #include "qemu/log.h" +#include "qemu/qemu-print.h" #include "qemu/range.h" #include "qemu/error-report.h" #include "qapi/error.h" #include "qemu/cutils.h" #include "trace/control.h" +#include "qemu-common.h" =20 static char *logfilename; FILE *qemu_logfile; int qemu_loglevel; static int log_append =3D 0; static GArray *debug_regions; +int32_t max_num_hot_tbs_to_dump; =20 int tcg_collect_tb_stats; uint32_t default_tbstats_flag; @@ -276,6 +279,9 @@ const QEMULogItem qemu_log_items[] =3D { { CPU_LOG_TB_NOCHAIN, "nochain", "do not chain compiled TBs so that \"exec\" and \"cpu\" show\n" "complete traces" }, + { CPU_LOG_TB_STATS, "tb_stats[[,level=3D(+all+jit+exec+time)][,dump_li= mit=3D]]", + "enable collection of TBs statistics" + "(and dump until given a limit if in user mode).\n" }, { 0, NULL, NULL }, }; =20 @@ -297,6 +303,35 @@ int qemu_str_to_log_mask(const char *str) trace_enable_events((*tmp) + 6); mask |=3D LOG_TRACE; #endif + } else if (g_str_has_prefix(*tmp, "tb_stats")) { + mask |=3D CPU_LOG_TB_STATS; + default_tbstats_flag =3D TB_JIT_STATS | TB_EXEC_STATS | TB_JIT= _TIME; + tcg_collect_tb_stats =3D TB_STATS_RUNNING; + } else if (tcg_collect_tb_stats =3D=3D TB_STATS_RUNNING && + g_str_has_prefix(*tmp, "dump_limit=3D")) { + + max_num_hot_tbs_to_dump =3D atoi((*tmp) + 11); + } else if (tcg_collect_tb_stats =3D=3D TB_STATS_RUNNING && + g_str_has_prefix(*tmp, "level=3D")) { + + default_tbstats_flag =3D 0; + char **level_parts =3D g_strsplit(*tmp + 6, "+", 0); + char **level_tmp; + for (level_tmp =3D level_parts; level_tmp && *level_tmp; level= _tmp++) { + if (g_str_equal(*level_tmp, "jit")) { + default_tbstats_flag |=3D TB_JIT_STATS; + } else if (g_str_equal(*level_tmp, "exec")) { + default_tbstats_flag |=3D TB_EXEC_STATS; + } else if (g_str_equal(*level_tmp, "time")) { + default_tbstats_flag |=3D TB_JIT_TIME; + } else if (g_str_equal(*level_tmp, "all")) { + default_tbstats_flag |=3D TB_JIT_STATS | TB_EXEC_STATS= | TB_JIT_TIME; + } else { + fprintf(stderr, "no option level=3D%s, valid options a= re:" + "all, jit, exec or/and time\n", *level_tmp); + exit(1); + } + } } else { for (item =3D qemu_log_items; item->mask !=3D 0; item++) { if (g_str_equal(*tmp, item->name)) { --=20 2.22.0 From nobody Tue May 7 09:25:28 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1565836608; cv=none; d=zoho.com; s=zohoarc; b=Z9j9cF/RokVr7aAXlNKMhQbM1gvO/lJ6TT2X/xm3I5180O+g2zfRzFDWAxEyq3LGigKvkZUhaEkgZYexo1rTZnAM2YESEWXXeMw6TVPjWI/+dh5Al7EeZjDsSfLsA3sJ0wwRP0O4oBCoC6fnHetDN5ZqCav19PDjDEOXfW7tIP4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1565836608; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=/wKEh8R9oXktuvoll7cq+fyvOK89+EADH9w4rkEVis0=; b=ZWGZam6627muPH8WfopBBLp06PVZ+EEKe21iNMSF8XeuRtvHVVnGXMX+GTlZTuFISpc0/EBgJzcDpFMg0R2DksUaeQ/0OKRzJQ2eU49yaOQvDGrzWv5Nul9AIHUR5NXnFKI4D9LNPxJy/6ci5u+24XnPVvkLIItMEMWpDrGCTxo= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1565836608985481.29147079176073; Wed, 14 Aug 2019 19:36:48 -0700 (PDT) Received: from localhost ([::1]:37614 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1hy5d9-0004ID-17 for importer@patchew.org; Wed, 14 Aug 2019 22:36:47 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:48681) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1hy5Md-0000v2-E0 for qemu-devel@nongnu.org; Wed, 14 Aug 2019 22:19:45 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hy5Mb-0001of-Il for qemu-devel@nongnu.org; Wed, 14 Aug 2019 22:19:43 -0400 Received: from mail-qt1-x841.google.com ([2607:f8b0:4864:20::841]:37464) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hy5Mb-0001oG-E1 for qemu-devel@nongnu.org; Wed, 14 Aug 2019 22:19:41 -0400 Received: by mail-qt1-x841.google.com with SMTP id y26so937128qto.4 for ; Wed, 14 Aug 2019 19:19:41 -0700 (PDT) Received: from localhost.localdomain ([2804:14c:482:121::1]) by smtp.googlemail.com with ESMTPSA id o5sm757943qkf.10.2019.08.14.19.19.38 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Wed, 14 Aug 2019 19:19:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=/wKEh8R9oXktuvoll7cq+fyvOK89+EADH9w4rkEVis0=; b=PSViwpWfjyAsbmCeQsLu/PE/JmpS6gywSzSs2pjOlV1x5IbXjFd9IjmLpabRPx0pAY XRlrVWW9I/SLiyoKov5KTJHmzlr2kaoItf/zvjgkhLgkutGuiPvCPmNprfUDzcgYLn9X Ek9QySMulZ+GlPvZJFJ7ufkpSVGClu7Up7XZdwKyAyhP4zCk68b8kLFPG94gJbnU0Oxv ui+Q3/UdlKIWjSkMDTmY8w+dxhUx1R6Oy+qAh2B/aXevIuB/O4mtSbPrC2dGr2RpuBmD qbtb6HgIhhJnxtTN6+GCEaqHrq9P6qyj/+TGZC93jy1u/KOkG4LIDs4+qv5QCto/+pxf lBxQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=/wKEh8R9oXktuvoll7cq+fyvOK89+EADH9w4rkEVis0=; b=QL1nr9+mcUxSlnh3SHFn3/aY4ENs/yRFI/7471T78Mayvz+VwrrAmDVrPTTUVsrJbE kABRLLEDrMuxR6fOcCqwpJZFDGpCCIBQZ2luRRX53xc1+ll0f8gh2Ncq+/r3Mm/0EYSI 5v82cPS4ghOYuBtwO9s4Cn4TfZi+3UxAkRkZuqz0YN/EFLYw7ByLtAzDLQKgFY9qBSf/ /swsHb0+f5p1TLk1BAI9KhAxxoGUTFMSUo7VuhsnLorZJc4LwJNYWMNKW1KYYFM5HsCQ 11/Wi0UmdYkk1BN1whcOpgD9y5vgESZywh8ktUPEdekE2fbDZ7zBsqTI/s/BOiWCgdKG W9dQ== X-Gm-Message-State: APjAAAWZxCud6tWd8arLOV4EsaS7G4wWc96v7Ojh4bsA5D92ZGEpA7j9 TfGNuqFAdopkfCYB8IKBIKuJ5rdCYkZmhQ== X-Google-Smtp-Source: APXvYqzvlAZjJTqtA2iqtAfU8iQZSrjCSXA/4xxuD75ISYuB78EZAOwuUA7Yebe+77zrmoFPs80Zcw== X-Received: by 2002:aed:2d67:: with SMTP id h94mr2044378qtd.154.1565835580430; Wed, 14 Aug 2019 19:19:40 -0700 (PDT) From: vandersonmr To: qemu-devel@nongnu.org Date: Wed, 14 Aug 2019 23:18:54 -0300 Message-Id: <20190815021857.19526-8-vandersonmr2@gmail.com> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190815021857.19526-1-vandersonmr2@gmail.com> References: <20190815021857.19526-1-vandersonmr2@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::841 Subject: [Qemu-devel] [PATCH v5 07/10] monitor: adding tb_stats hmp command X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Paolo Bonzini , vandersonmr , "Dr. David Alan Gilbert" , Markus Armbruster , Richard Henderson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Adding tb_stats [start|pause|stop|filter] command to hmp. This allows controlling the collection of statistics. It is also possible to set the level of collection: all, jit, or exec. tb_stats filter allow to only collect statistics for the TB in the last_search list. 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 worthwhile. Signed-off-by: Vanderson M. do Rosario Acked-by: Dr. David Alan Gilbert --- accel/tcg/tb-stats.c | 111 ++++++++++++++++++++++++++++++++++++++++ hmp-commands.hx | 17 ++++++ include/exec/tb-stats.h | 12 +++++ include/qemu-common.h | 1 + monitor/misc.c | 49 ++++++++++++++++++ vl.c | 6 +++ 6 files changed, 196 insertions(+) diff --git a/accel/tcg/tb-stats.c b/accel/tcg/tb-stats.c index dddb9d4537..f28fd7b434 100644 --- a/accel/tcg/tb-stats.c +++ b/accel/tcg/tb-stats.c @@ -9,6 +9,9 @@ =20 #include "exec/tb-stats.h" =20 +/* only accessed in safe work */ +static GList *last_search; + uint64_t dev_time; =20 struct jit_profile_info { @@ -140,6 +143,96 @@ void dump_jit_profile_info(TCGProfile *s) g_free(jpi); } =20 +static void free_tbstats(void *p, uint32_t hash, void *userp) +{ + g_free(p); +} + +static void clean_tbstats(void) +{ + /* remove all tb_stats */ + qht_iter(&tb_ctx.tb_stats, free_tbstats, NULL); + qht_destroy(&tb_ctx.tb_stats); +} + +void do_hmp_tbstats_safe(CPUState *cpu, run_on_cpu_data icmd) +{ + struct TbstatsCommand *cmdinfo =3D icmd.host_ptr; + int cmd =3D cmdinfo->cmd; + uint32_t level =3D cmdinfo->level; + + switch (cmd) { + case START: + if (tb_stats_collection_paused()) { + set_tbstats_flags(level); + } else { + if (tb_stats_collection_enabled()) { + qemu_printf("TB information already being recorded"); + return; + } + qht_init(&tb_ctx.tb_stats, tb_stats_cmp, CODE_GEN_HTABLE_SIZE, + QHT_MODE_AUTO_RESIZE); + } + + set_default_tbstats_flag(level); + enable_collect_tb_stats(); + tb_flush(cpu); + break; + case PAUSE: + if (!tb_stats_collection_enabled()) { + qemu_printf("TB information not being recorded"); + return; + } + + /* Continue to create TBStatistic structures but stop collecting s= tatistics */ + pause_collect_tb_stats(); + set_default_tbstats_flag(TB_NOTHING); + set_tbstats_flags(TB_PAUSED); + tb_flush(cpu); + break; + case STOP: + if (!tb_stats_collection_enabled()) { + qemu_printf("TB information not being recorded"); + return; + } + + /* Dissalloc all TBStatistics structures and stop creating new one= s */ + disable_collect_tb_stats(); + clean_tbstats(); + tb_flush(cpu); + break; + case FILTER: + if (!tb_stats_collection_enabled()) { + qemu_printf("TB information not being recorded"); + return; + } + if (!last_search) { + qemu_printf("no search on record! execute info tbs before filt= ering!"); + return; + } + + set_default_tbstats_flag(TB_NOTHING); + + /* Set all tbstats as paused, then return only the ones from last_= search */ + pause_collect_tb_stats(); + set_tbstats_flags(TB_PAUSED); + + for (GList *iter =3D last_search; iter; iter =3D g_list_next(iter)= ) { + TBStatistics *tbs =3D iter->data; + tbs->stats_enabled =3D level; + } + + tb_flush(cpu); + + break; + default: /* INVALID */ + g_assert_not_reached(); + break; + } + + g_free(cmdinfo); +} + =20 void init_tb_stats_htable_if_not(void) { @@ -175,6 +268,24 @@ bool tb_stats_collection_paused(void) return tcg_collect_tb_stats =3D=3D TB_STATS_PAUSED; } =20 +static void reset_tbstats_flag(void *p, uint32_t hash, void *userp) +{ + uint32_t flag =3D *((int *)userp); + TBStatistics *tbs =3D p; + tbs->stats_enabled =3D flag; +} + +void set_default_tbstats_flag(uint32_t flag) +{ + default_tbstats_flag =3D flag; +} + +void set_tbstats_flags(uint32_t flag) +{ + /* iterate over tbstats setting their flag as TB_NOTHING */ + qht_iter(&tb_ctx.tb_stats, reset_tbstats_flag, &flag); +} + uint32_t get_default_tbstats_flag(void) { return default_tbstats_flag; diff --git a/hmp-commands.hx b/hmp-commands.hx index bfa5681dd2..419898751e 100644 --- a/hmp-commands.hx +++ b/hmp-commands.hx @@ -1885,6 +1885,23 @@ STEXI @findex qemu-io Executes a qemu-io command on the given block device. =20 +ETEXI +#if defined(CONFIG_TCG) + { + .name =3D "tb_stats", + .args_type =3D "command:s,level:s?", + .params =3D "command [stats_level]", + .help =3D "Control tb statistics collection:" + "tb_stats (start|pause|stop|filter) [all|jit_stats= |exec_stats]", + .cmd =3D hmp_tbstats, + }, +#endif + +STEXI +@item tb_stats +@findex +Control recording tb statistics + ETEXI =20 { diff --git a/include/exec/tb-stats.h b/include/exec/tb-stats.h index c0948e606a..9271b90924 100644 --- a/include/exec/tb-stats.h +++ b/include/exec/tb-stats.h @@ -6,6 +6,9 @@ #include "exec/tb-context.h" #include "tcg.h" =20 +enum SortBy { SORT_BY_HOTNESS, SORT_BY_HG /* Host/Guest */, SORT_BY_SPILLS= }; +enum TbstatsCmd { START, PAUSE, STOP, FILTER }; + #define tb_stats_enabled(tb, JIT_STATS) \ (tb && tb->tb_stats && (tb->tb_stats->stats_enabled & JIT_STATS)) =20 @@ -74,10 +77,18 @@ bool tb_stats_cmp(const void *ap, const void *bp); =20 void dump_jit_exec_time_info(uint64_t dev_time); =20 +void set_tbstats_flags(uint32_t flags); void init_tb_stats_htable_if_not(void); =20 void dump_jit_profile_info(TCGProfile *s); =20 +struct TbstatsCommand { + enum TbstatsCmd cmd; + uint32_t level; +}; + +void do_hmp_tbstats_safe(CPUState *cpu, run_on_cpu_data icmd); + /* TBStatistic collection controls */ void enable_collect_tb_stats(void); void disable_collect_tb_stats(void); @@ -85,6 +96,7 @@ void pause_collect_tb_stats(void); bool tb_stats_collection_enabled(void); bool tb_stats_collection_paused(void); =20 +void set_default_tbstats_flag(uint32_t flag); uint32_t get_default_tbstats_flag(void); =20 #endif diff --git a/include/qemu-common.h b/include/qemu-common.h index 362e48c445..ab736a1b05 100644 --- a/include/qemu-common.h +++ b/include/qemu-common.h @@ -141,6 +141,7 @@ enum TBStatsStatus { #define TB_EXEC_STATS 1 #define TB_JIT_STATS 2 #define TB_JIT_TIME 4 +#define TB_PAUSED 8 =20 extern int tcg_collect_tb_stats; extern uint32_t default_tbstats_flag; diff --git a/monitor/misc.c b/monitor/misc.c index 4839d6875f..6902e8addb 100644 --- a/monitor/misc.c +++ b/monitor/misc.c @@ -74,6 +74,8 @@ #include "sysemu/cpus.h" #include "qemu/cutils.h" #include "tcg/tcg.h" +#include "exec/tb-stats.h" +#include "qemu-common.h" =20 #if defined(TARGET_S390X) #include "hw/s390x/storage-keys.h" @@ -459,6 +461,49 @@ static void hmp_info_registers(Monitor *mon, const QDi= ct *qdict) } =20 #ifdef CONFIG_TCG +static void hmp_tbstats(Monitor *mon, const QDict *qdict) +{ + if (!tcg_enabled()) { + error_report("TB information is only available with accel=3Dtcg"); + return; + } + + char *cmd =3D (char *) qdict_get_try_str(qdict, "command"); + enum TbstatsCmd icmd =3D -1; + + if (strcmp(cmd, "start") =3D=3D 0) { + icmd =3D START; + } else if (strcmp(cmd, "pause") =3D=3D 0) { + icmd =3D PAUSE; + } else if (strcmp(cmd, "stop") =3D=3D 0) { + icmd =3D STOP; + } else if (strcmp(cmd, "filter") =3D=3D 0) { + icmd =3D FILTER; + } else { + error_report("invalid command!"); + return; + } + + char *slevel =3D (char *) qdict_get_try_str(qdict, "level"); + uint32_t level =3D TB_EXEC_STATS | TB_JIT_STATS | TB_JIT_TIME; + if (slevel) { + if (strcmp(slevel, "jit") =3D=3D 0) { + level =3D TB_JIT_STATS; + } else if (strcmp(slevel, "exec") =3D=3D 0) { + level =3D TB_EXEC_STATS; + } else if (strcmp(slevel, "time") =3D=3D 0) { + level =3D TB_JIT_TIME; + } + } + + struct TbstatsCommand *tbscommand =3D g_new0(struct TbstatsCommand, 1); + tbscommand->cmd =3D icmd; + tbscommand->level =3D level; + async_safe_run_on_cpu(first_cpu, do_hmp_tbstats_safe, + RUN_ON_CPU_HOST_PTR(tbscommand)); + +} + static void hmp_info_jit(Monitor *mon, const QDict *qdict) { if (!tcg_enabled()) { @@ -1089,8 +1134,12 @@ static void hmp_info_mtree(Monitor *mon, const QDict= *qdict) =20 static void hmp_info_profile(Monitor *mon, const QDict *qdict) { +#ifdef CONFIG_TCG dump_jit_exec_time_info(dev_time); dev_time =3D 0; +#else + error_report("TCG should be enabled!"); +#endif } =20 /* Capture support */ diff --git a/vl.c b/vl.c index ef7737a7bc..326090c36a 100644 --- a/vl.c +++ b/vl.c @@ -1781,11 +1781,17 @@ static bool main_loop_should_exit(void) =20 static void main_loop(void) { +#ifdef CONFIG_TCG uint64_t ti; +#endif while (!main_loop_should_exit()) { +#ifdef CONFIG_TCG ti =3D profile_getclock(); +#endif main_loop_wait(false); +#ifdef CONFIG_TCG dev_time +=3D profile_getclock() - ti; +#endif } } =20 --=20 2.22.0 From nobody Tue May 7 09:25:28 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1565837760; cv=none; d=zoho.com; s=zohoarc; b=oF22oqjXcGmtXkQ54sWxw6wjg9+0R93l1bc0RLeQG/eHQJlVKxU5N4ZWmY3Pu16+pJlBtkpCVTB4tgbpFDrbskXsy+2r5XDAfy5/M9fS1H3E6c7CFaCx4MQFWju6auMaSxkT1L+NH8zm1ck8t8x6jFXUikveUvynK2Po7Iain6Q= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1565837760; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=WSDfMgBc9FbkiGNR4Cnxk5bgFksmEKOgvYdXh+VD+X0=; b=feBGyE6EP25adyQZPk+pfeAnRWU7Q7MfyLcf/GXmTkH2EBdR9pzImoxG6GH7JnkTuJ6LHWk2qpF0xxS4/K9KWN7+0ZV2eHn3/yTU8VdQK4wDQcFUUddqcrS30woU3KANp/HAhtSWg9NROFij55j0jbV6ENCeV5uswS+D1FgCAAk= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1565837760460408.2396499543281; Wed, 14 Aug 2019 19:56:00 -0700 (PDT) Received: from localhost ([::1]:37904 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1hy5vi-0004pf-UX for importer@patchew.org; Wed, 14 Aug 2019 22:55:58 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:48694) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1hy5Mh-0000zl-0g for qemu-devel@nongnu.org; Wed, 14 Aug 2019 22:19:49 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hy5Me-0001qt-5P for qemu-devel@nongnu.org; Wed, 14 Aug 2019 22:19:46 -0400 Received: from mail-qt1-x843.google.com ([2607:f8b0:4864:20::843]:35418) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hy5Md-0001qj-Vh for qemu-devel@nongnu.org; Wed, 14 Aug 2019 22:19:44 -0400 Received: by mail-qt1-x843.google.com with SMTP id u34so951322qte.2 for ; Wed, 14 Aug 2019 19:19:43 -0700 (PDT) Received: from localhost.localdomain ([2804:14c:482:121::1]) by smtp.googlemail.com with ESMTPSA id o5sm757943qkf.10.2019.08.14.19.19.40 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Wed, 14 Aug 2019 19:19:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=WSDfMgBc9FbkiGNR4Cnxk5bgFksmEKOgvYdXh+VD+X0=; b=PUWLmKtj4sz0Y/OiRcTfG1EzzJWj6yXxzCOqbxuOB9Ko4PCbVWeux0IJ/txNK+ysCk r5hE0loKi7aTajDeAH7kNImVuXFjW/ISq9xvMm2e6D/J5rsEJahKNwQ7xaUZXUjuDGMD NSX/aW6jCgPLCHHiCYg3ZS+95xtz/fLxuEAWDJ8/HKQ7+rE3498Bllw1qywq8xBE0U7X wdzatwpIBxoos8upVGaNXouejkC3IEhGEyCE7I2bVEP8EOP6YNB1mefgdQYL6I+D2y8o wl9njt3DWVuF4WWvLH591uyT9Q5AHmUypQg7wt2qLyRg+mSe0R1tDcCZV+Svp7JTMyAm 3l1g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=WSDfMgBc9FbkiGNR4Cnxk5bgFksmEKOgvYdXh+VD+X0=; b=fW/uNQkynvcGH1HqEhnvG8Uvi6Owk5wAVPpKJ8kBYdHPxvld7ViEeu5YRpXgJstkeY MpYbd0aA/r2TDJlDHJUWiiu4x9Qrol/KVDMPg2a1e2utOybPUtpqDZGAJ5fw80H0uB1t eAbX9rTPuYmFJDMcQTBBCmAXYnzKlZGCgLXbac2qkb6iSCTSY045C7JXq5UAl6O9xhoV vA0wFuu242LoQSCQWuNc7WA3OuA4TYFtNGEx3dOly3awAWNZnOlQMOU+oRzRJL0Q2iI2 4vGo34Ze0ZAlqIr4YP6x4i4koLOokJyqOfEE83RTei/sODxOxdGwbq92Lc2RDqDNK9TH koSg== X-Gm-Message-State: APjAAAU5aAUw8k3fwFuOBR7C+ATqgLfWvMkD4L9nVFJMtR9wxgWMY6pP P3SskagI9TRo6sgMz9YEvYfNVPW44yMerw== X-Google-Smtp-Source: APXvYqzGVpY7jp5YwJ+AzDgTC+Be4qat71xYknx2NlTNqL6zMjbcyPKuKmVnrmjvKKgzp/XbYLSvcw== X-Received: by 2002:aed:35b4:: with SMTP id c49mr1961112qte.313.1565835582936; Wed, 14 Aug 2019 19:19:42 -0700 (PDT) From: vandersonmr To: qemu-devel@nongnu.org Date: Wed, 14 Aug 2019 23:18:55 -0300 Message-Id: <20190815021857.19526-9-vandersonmr2@gmail.com> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190815021857.19526-1-vandersonmr2@gmail.com> References: <20190815021857.19526-1-vandersonmr2@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::843 Subject: [Qemu-devel] [PATCH v5 08/10] Adding info [tbs|tb|coverset] commands to HMP. These commands allow the exploration of TBs generated by the TCG. Understand which one hotter, with more guest/host instructions... and examine their guest, host and IR code. X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Paolo Bonzini , vandersonmr , "Dr. David Alan Gilbert" , Markus Armbruster , Richard Henderson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" 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. Signed-off-by: Vanderson M. do Rosario --- accel/tcg/tb-stats.c | 398 ++++++++++++++++++++++++++++++++++- accel/tcg/translate-all.c | 2 +- disas.c | 31 ++- hmp-commands-info.hx | 24 +++ include/exec/tb-stats.h | 43 +++- include/qemu/log-for-trace.h | 4 + include/qemu/log.h | 2 + monitor/misc.c | 74 +++++++ util/log.c | 52 ++++- 9 files changed, 609 insertions(+), 21 deletions(-) diff --git a/accel/tcg/tb-stats.c b/accel/tcg/tb-stats.c index f28fd7b434..f5e519bdb7 100644 --- a/accel/tcg/tb-stats.c +++ b/accel/tcg/tb-stats.c @@ -11,9 +11,36 @@ =20 /* only accessed in safe work */ static GList *last_search; - +int id =3D 1; /* display_id increment counter */ uint64_t dev_time; =20 +static TBStatistics *get_tbstats_by_id(int id) +{ + GList *iter; + + for (iter =3D last_search; iter; iter =3D g_list_next(iter)) { + TBStatistics *tbs =3D iter->data; + if (tbs && tbs->display_id =3D=3D id) { + return tbs; + break; + } + } + return NULL; +} + +static TBStatistics *get_tbstats_by_addr(target_ulong pc) +{ + GList *iter; + for (iter =3D last_search; iter; iter =3D g_list_next(iter)) { + TBStatistics *tbs =3D iter->data; + if (tbs && tbs->pc =3D=3D pc) { + return tbs; + break; + } + } + return NULL; +} + struct jit_profile_info { uint64_t translations; uint64_t aborted; @@ -155,6 +182,7 @@ static void clean_tbstats(void) qht_destroy(&tb_ctx.tb_stats); } =20 + void do_hmp_tbstats_safe(CPUState *cpu, run_on_cpu_data icmd) { struct TbstatsCommand *cmdinfo =3D icmd.host_ptr; @@ -242,6 +270,374 @@ void init_tb_stats_htable_if_not(void) } } =20 +static void collect_tb_stats(void *p, uint32_t hash, void *userp) +{ + last_search =3D g_list_prepend(last_search, p); +} + +static void dump_tb_targets(TBStatistics *tbs) +{ + if (tbs && tbs->tb) { + uintptr_t dst1 =3D atomic_read(tbs->tb->jmp_dest); + uintptr_t dst2 =3D atomic_read(tbs->tb->jmp_dest + 1); + TranslationBlock* tb_dst1 =3D dst1 > 1 ? (TranslationBlock *) dst1= : 0; + TranslationBlock* tb_dst2 =3D dst2 > 1 ? (TranslationBlock *) dst2= : 0; + target_ulong pc1 =3D tb_dst1 ? tb_dst1->pc : 0; + target_ulong pc2 =3D tb_dst2 ? tb_dst2->pc : 0; + + /* if there is no display id from the last_search, then create one= */ + TBStatistics *tbstats_pc1 =3D get_tbstats_by_addr(pc1); + TBStatistics *tbstats_pc2 =3D get_tbstats_by_addr(pc2); + + if (!tbstats_pc1 && tb_dst1 && tb_dst1->tb_stats) { + last_search =3D g_list_append(last_search, tb_dst1->tb_stats); + tbstats_pc1 =3D tb_dst1->tb_stats; + } + + if (!tbstats_pc2 && tb_dst2 && tb_dst2->tb_stats) { + last_search =3D g_list_append(last_search, tb_dst2->tb_stats); + tbstats_pc2 =3D tb_dst2->tb_stats; + } + + if (tbstats_pc1 && tbstats_pc1->display_id =3D=3D 0) { + tbstats_pc1->display_id =3D id++; + } + + if (tbstats_pc2 && tbstats_pc2->display_id =3D=3D 0) { + tbstats_pc2->display_id =3D id++; + } + + if (pc1 && !pc2) { + qemu_log("\t| targets: 0x"TARGET_FMT_lx" (id:%d)\n", + pc1, tb_dst1 ? tbstats_pc1->display_id : -1); + } else if (pc1 && pc2) { + qemu_log("\t| targets: 0x"TARGET_FMT_lx" (id:%d), " + "0x"TARGET_FMT_lx" (id:%d)\n", + pc1, tb_dst1 ? tbstats_pc1->display_id : -1, + pc2, tb_dst2 ? tbstats_pc2->display_id : -1); + } else { + qemu_log("\t| targets: no direct target\n"); + } + } +} + +static void dump_tb_header(TBStatistics *tbs) +{ + unsigned g =3D stat_per_translation(tbs, code.num_guest_inst); + unsigned ops =3D stat_per_translation(tbs, code.num_tcg_ops); + unsigned ops_opt =3D stat_per_translation(tbs, code.num_tcg_ops_opt); + unsigned spills =3D stat_per_translation(tbs, code.spills); + unsigned h =3D stat_per_translation(tbs, code.out_len); + + float guest_host_prop =3D g ? ((float) h / g) : 0; + + qemu_log("TB id:%d | phys:0x"TB_PAGE_ADDR_FMT" virt:0x"TARGET_FMT_lx + " flags:%#08x\n", tbs->display_id, tbs->phys_pc, tbs->pc, tbs= ->flags); + + if (tbs_stats_enabled(tbs, TB_EXEC_STATS)) { + qemu_log("\t| exec:%lu/%lu\n", tbs->executions.normal, tbs->execut= ions.atomic); + } + + if (tbs_stats_enabled(tbs, TB_JIT_STATS)) { + qemu_log("\t| trans:%lu ints: g:%u op:%u op_opt:%u spills:%d" + "\n\t| h/g (host bytes / guest insts): %f\n", + tbs->translations.total, g, ops, ops_opt, spills, guest_host_= prop); + } + + if (tbs_stats_enabled(tbs, TB_JIT_TIME)) { + qemu_log("\t| time to gen at 2.4GHz =3D> code:%0.2lf(ns) IR:%0.2lf= (ns)\n", + tbs->time.code / 2.4, tbs->time.interm / 2.4); + } + + dump_tb_targets(tbs); + qemu_log("\n"); +} + +static gint +inverse_sort_tbs(gconstpointer p1, gconstpointer p2, gpointer psort_by) +{ + const TBStatistics *tbs1 =3D (TBStatistics *) p1; + const TBStatistics *tbs2 =3D (TBStatistics *) p2; + int sort_by =3D *((int *) psort_by); + unsigned long c1 =3D 0; + unsigned long c2 =3D 0; + + if (likely(sort_by =3D=3D SORT_BY_SPILLS)) { + c1 =3D stat_per_translation(tbs1, code.spills); + c2 =3D stat_per_translation(tbs2, code.spills); + } else if (likely(sort_by =3D=3D SORT_BY_HOTNESS)) { + c1 =3D stat_per_translation(tbs1, executions.normal); + c2 =3D stat_per_translation(tbs2, executions.normal); + } else if (likely(sort_by =3D=3D SORT_BY_HG)) { + if (tbs1->code.num_guest_inst =3D=3D 0) { + return -1; + } + if (tbs2->code.num_guest_inst =3D=3D 0) { + return 1; + } + + float a =3D + (float) stat_per_translation(tbs1, code.out_len) / tbs1->code.= num_guest_inst; + float b =3D + (float) stat_per_translation(tbs2, code.out_len) / tbs2->code.= num_guest_inst; + c1 =3D a <=3D b ? 0 : 1; + c2 =3D a <=3D b ? 1 : 0; + } + + return c1 < c2 ? 1 : c1 =3D=3D c2 ? 0 : -1; +} + +static void dump_last_search_headers(int count) +{ + if (!last_search) { + qemu_log("No data collected yet\n"); + return; + } + + GList *i; + for (i =3D last_search; i && count--; i =3D i->next) { + TBStatistics *tbs =3D (TBStatistics *) i->data; + dump_tb_header(tbs); + } +} + +static void do_dump_coverset_info(int percentage) +{ + uint64_t total_exec_count =3D 0; + uint64_t covered_exec_count =3D 0; + unsigned coverset_size =3D 0; + id =3D 1; + GList *i; + + g_list_free(last_search); + last_search =3D NULL; + + qht_iter(&tb_ctx.tb_stats, collect_tb_stats, NULL); + + int sort_by =3D SORT_BY_HOTNESS; + last_search =3D g_list_sort_with_data(last_search, inverse_sort_tbs, &= sort_by); + + if (!last_search) { + qemu_log("No data collected yet\n"); + return; + } + + /* Compute total execution count for all tbs */ + for (i =3D last_search; i; i =3D i->next) { + TBStatistics *tbs =3D (TBStatistics *) i->data; + total_exec_count +=3D tbs->executions.normal * tbs->code.num_guest= _inst; + } + + for (i =3D last_search; i; i =3D i->next) { + TBStatistics *tbs =3D (TBStatistics *) i->data; + covered_exec_count +=3D tbs->executions.normal * tbs->code.num_gue= st_inst; + tbs->display_id =3D id++; + coverset_size++; + + /* Iterate and display tbs until reach the percentage count cover = */ + if ((covered_exec_count * 100) / total_exec_count > percentage) { + break; + } + } + + qemu_log("\n------------------------------\n"); + qemu_log("# of TBs to reach %d%% of the total of guest insts exec: %u\= t", + percentage, coverset_size); + qemu_log("Total of guest insts exec: %lu\n", total_exec_count); + qemu_log("\n------------------------------\n"); + + /* free the unused bits */ + if (i) { + if (i->next) { + i->next->prev =3D NULL; + } + g_list_free(i->next); + i->next =3D NULL; + } + + dump_last_search_headers(coverset_size); +} + +static void do_dump_tbs_info(int total, int sort_by) +{ + id =3D 1; + GList *i; + int count =3D total; + + g_list_free(last_search); + last_search =3D NULL; + + qht_iter(&tb_ctx.tb_stats, collect_tb_stats, NULL); + + last_search =3D g_list_sort_with_data(last_search, inverse_sort_tbs, + &sort_by); + + + if (!last_search) { + qemu_printf("No data collected yet!\n"); + return; + } + + for (i =3D last_search; i && count--; i =3D i->next) { + TBStatistics *tbs =3D (TBStatistics *) i->data; + tbs->display_id =3D id++; + } + + /* free the unused bits */ + if (i) { + if (i->next) { + i->next->prev =3D NULL; + } + g_list_free(i->next); + i->next =3D NULL; + } + + dump_last_search_headers(total); +} + +static void +do_dump_coverset_info_safe(CPUState *cpu, run_on_cpu_data percentage) +{ + qemu_log_to_monitor(true); + do_dump_coverset_info(percentage.host_int); + qemu_log_to_monitor(false); +} + +struct tbs_dump_info { + int count; + int sort_by; +}; + +static void do_dump_tbs_info_safe(CPUState *cpu, run_on_cpu_data tbdi) +{ + struct tbs_dump_info *info =3D tbdi.host_ptr; + qemu_log_to_monitor(true); + do_dump_tbs_info(info->count, info->sort_by); + qemu_log_to_monitor(false); + g_free(info); +} + +/* + * When we dump_tbs_info on a live system via the HMP we want to + * ensure the system is quiessent before we start outputting stuff. + * Otherwise we could pollute the output with other logging output. + */ +void dump_coverset_info(int percentage, bool use_monitor) +{ + if (use_monitor) { + async_safe_run_on_cpu(first_cpu, do_dump_coverset_info_safe, + RUN_ON_CPU_HOST_INT(percentage)); + } else { + do_dump_coverset_info(percentage); + } +} + +void dump_tbs_info(int count, int sort_by, bool use_monitor) +{ + if (use_monitor) { + struct tbs_dump_info *tbdi =3D g_new(struct tbs_dump_info, 1); + tbdi->count =3D count; + tbdi->sort_by =3D sort_by; + async_safe_run_on_cpu(first_cpu, do_dump_tbs_info_safe, + RUN_ON_CPU_HOST_PTR(tbdi)); + } else { + do_dump_tbs_info(count, sort_by); + } +} + +static GString *get_code_string(TBStatistics *tbs, int log_flags) +{ + int old_log_flags =3D qemu_loglevel; + + CPUState *cpu =3D first_cpu; + uint32_t cflags =3D curr_cflags() | CF_NOCACHE; + TranslationBlock *tb =3D NULL; + + GString *code_s =3D g_string_new(NULL); + qemu_log_to_string(true, code_s); + + qemu_set_log(log_flags); + + if (sigsetjmp(cpu->jmp_env, 0) =3D=3D 0) { + mmap_lock(); + tb =3D tb_gen_code(cpu, tbs->pc, tbs->cs_base, tbs->flags, cflags); + tb_phys_invalidate(tb, -1); + mmap_unlock(); + } else { + /* + * The mmap_lock is dropped by tb_gen_code if it runs out of + * memory. + */ + fprintf(stderr, "%s: dbg failed!\n", __func__); + qemu_log("\ncould not gen code for this TB\n"); + assert_no_pages_locked(); + } + + qemu_set_log(old_log_flags); + qemu_log_to_string(false, NULL); + + if (tb) { + tcg_tb_remove(tb); + } + + return code_s; +} + +static void do_tb_dump_with_statistics(TBStatistics *tbs, int log_flags) +{ + qemu_log("\n------------------------------\n\n"); + dump_tb_header(tbs); + + GString *code_s =3D get_code_string(tbs, log_flags); + qemu_log("%s", code_s->str); + g_string_free(code_s, true); + qemu_log("------------------------------\n"); +} + +struct tb_dump_info { + int id; + int log_flags; + bool use_monitor; +}; + +static void do_dump_tb_info_safe(CPUState *cpu, run_on_cpu_data info) +{ + struct tb_dump_info *tbdi =3D (struct tb_dump_info *) info.host_ptr; + + if (!last_search) { + qemu_log("no search on record\n"); + return; + } + + qemu_log_to_monitor(tbdi->use_monitor); + + TBStatistics *tbs =3D get_tbstats_by_id(tbdi->id); + if (tbs) { + do_tb_dump_with_statistics(tbs, tbdi->log_flags); + } else { + qemu_log("no TB statitics found with id %d\n", tbdi->id); + } + + qemu_log_to_monitor(false); + + g_free(tbdi); +} + +void dump_tb_info(int id, int log_mask, bool use_monitor) +{ + struct tb_dump_info *tbdi =3D g_new(struct tb_dump_info, 1); + + tbdi->id =3D id; + tbdi->log_flags =3D log_mask; + tbdi->use_monitor =3D use_monitor; + + async_safe_run_on_cpu(first_cpu, do_dump_tb_info_safe, + RUN_ON_CPU_HOST_PTR(tbdi)); + + /* tbdi free'd by do_dump_tb_info_safe */ +} + + void enable_collect_tb_stats(void) { init_tb_stats_htable_if_not(); diff --git a/accel/tcg/translate-all.c b/accel/tcg/translate-all.c index b94a1d67b6..0807411a8c 100644 --- a/accel/tcg/translate-all.c +++ b/accel/tcg/translate-all.c @@ -1779,7 +1779,7 @@ TranslationBlock *tb_gen_code(CPUState *cpu, * generation so we can count interesting things about this * generation. */ - if (tb_stats_collection_enabled()) { + if (tb_stats_collection_enabled() && !(tb->cflags & CF_NOCACHE)) { tb->tb_stats =3D tb_get_stats(phys_pc, pc, cs_base, flags, tb); uint32_t flag =3D get_default_tbstats_flag(); =20 diff --git a/disas.c b/disas.c index 3e2bfa572b..d5292d4246 100644 --- a/disas.c +++ b/disas.c @@ -8,6 +8,8 @@ #include "disas/disas.h" #include "disas/capstone.h" =20 +#include "qemu/log-for-trace.h" + typedef struct CPUDebug { struct disassemble_info info; CPUState *cpu; @@ -420,6 +422,22 @@ static bool cap_disas_monitor(disassemble_info *info, = uint64_t pc, int count) # define cap_disas_monitor(i, p, c) false #endif /* CONFIG_CAPSTONE */ =20 +static int fprintf_log(struct _IO_FILE *a, const char *b, ...) +{ + va_list ap; + va_start(ap, b); + + if (!to_string) { + vfprintf(a, b, ap); + } else { + qemu_vlog(b, ap); + } + + va_end(ap); + + return 1; +} + /* Disassemble this for me please... (debugging). */ void target_disas(FILE *out, CPUState *cpu, target_ulong code, target_ulong size) @@ -429,7 +447,7 @@ void target_disas(FILE *out, CPUState *cpu, target_ulon= g code, int count; CPUDebug s; =20 - INIT_DISASSEMBLE_INFO(s.info, out, fprintf); + INIT_DISASSEMBLE_INFO(s.info, out, fprintf_log); =20 s.cpu =3D cpu; s.info.read_memory_func =3D target_read_memory; @@ -460,11 +478,12 @@ void target_disas(FILE *out, CPUState *cpu, target_ul= ong code, } =20 for (pc =3D code; size > 0; pc +=3D count, size -=3D count) { - fprintf(out, "0x" TARGET_FMT_lx ": ", pc); - count =3D s.info.print_insn(pc, &s.info); - fprintf(out, "\n"); - if (count < 0) - break; + fprintf_log(out, "0x" TARGET_FMT_lx ": ", pc); + count =3D s.info.print_insn(pc, &s.info); + fprintf_log(out, "\n"); + if (count < 0) { + break; + } if (size < count) { fprintf(out, "Disassembler disagrees with translator over instructi= on " diff --git a/hmp-commands-info.hx b/hmp-commands-info.hx index c59444c461..6691303c59 100644 --- a/hmp-commands-info.hx +++ b/hmp-commands-info.hx @@ -289,6 +289,30 @@ ETEXI .help =3D "show dynamic compiler info", .cmd =3D hmp_info_jit, }, + { + .name =3D "tbs", + .args_type =3D "number:i?,sortedby:s?", + .params =3D "[number sortedby]", + .help =3D "show a [number] translated blocks sorted by [sort= edby]" + "sortedby opts: hotness hg spills", + .cmd =3D hmp_info_tbs, + }, + { + .name =3D "tb", + .args_type =3D "id:i,flags:s?", + .params =3D "id [log1[,...] flags]", + .help =3D "show information about one translated block by id= ." + "a dump flag can be used to set dump code level: out= _asm in_asm op", + .cmd =3D hmp_info_tb, + }, + { + .name =3D "coverset", + .args_type =3D "coverage:i?", + .params =3D "[coverage]", + .help =3D "show hottest translated blocks neccesary to cover" + "[coverage]% of the execution count", + .cmd =3D hmp_info_coverset, + }, #endif =20 STEXI diff --git a/include/exec/tb-stats.h b/include/exec/tb-stats.h index 9271b90924..dc2a8155a0 100644 --- a/include/exec/tb-stats.h +++ b/include/exec/tb-stats.h @@ -9,8 +9,11 @@ enum SortBy { SORT_BY_HOTNESS, SORT_BY_HG /* Host/Guest */, SORT_BY_SPILLS= }; enum TbstatsCmd { START, PAUSE, STOP, FILTER }; =20 +#define tbs_stats_enabled(tbs, JIT_STATS) \ + (tbs && (tbs->stats_enabled & JIT_STATS)) + #define tb_stats_enabled(tb, JIT_STATS) \ - (tb && tb->tb_stats && (tb->tb_stats->stats_enabled & JIT_STATS)) + (tb && tb->tb_stats && tbs_stats_enabled(tb->tb_stats, JIT_STATS)) =20 #define stat_per_translation(stat, name) \ (stat->translations.total ? stat->name / stat->translations.total : 0) @@ -56,7 +59,6 @@ struct TBStatistics { =20 struct { unsigned long total; - unsigned long uncached; unsigned long spanning; } translations; =20 @@ -69,6 +71,9 @@ struct TBStatistics { uint64_t la; } time; =20 + /* HMP information - used for referring to previous search */ + int display_id; + /* current TB linked to this TBStatistics */ TranslationBlock *tb; }; @@ -89,6 +94,40 @@ struct TbstatsCommand { =20 void do_hmp_tbstats_safe(CPUState *cpu, run_on_cpu_data icmd); =20 +/** + * dump_coverset_info: report the hottest blocks to cover n% of execution + * + * @percentage: cover set percentage + * @use_monitor: redirect output to monitor + * + * Report the hottest blocks to either the log or monitor + */ +void dump_coverset_info(int percentage, bool use_monitor); + + +/** + * dump_tbs_info: report the hottest blocks + * + * @count: the limit of hotblocks + * @sort_by: property in which the dump will be sorted + * @use_monitor: redirect output to monitor + * + * Report the hottest blocks to either the log or monitor + */ +void dump_tbs_info(int count, int sort_by, bool use_monitor); + +/** + * dump_tb_info: dump information about one TB + * + * @id: the display id of the block (from previous search) + * @mask: the temporary logging mask + * @Use_monitor: redirect output to monitor + * + * Re-run a translation of a block at addr for the purposes of debug output + */ +void dump_tb_info(int id, int log_mask, bool use_monitor); + + /* TBStatistic collection controls */ void enable_collect_tb_stats(void); void disable_collect_tb_stats(void); diff --git a/include/qemu/log-for-trace.h b/include/qemu/log-for-trace.h index 2f0a5b080e..3de88484cb 100644 --- a/include/qemu/log-for-trace.h +++ b/include/qemu/log-for-trace.h @@ -20,6 +20,9 @@ =20 /* Private global variable, don't use */ extern int qemu_loglevel; +extern bool to_string; + +extern int32_t max_num_hot_tbs_to_dump; =20 #define LOG_TRACE (1 << 15) =20 @@ -31,5 +34,6 @@ static inline bool qemu_loglevel_mask(int mask) =20 /* main logging function */ int GCC_FMT_ATTR(1, 2) qemu_log(const char *fmt, ...); +int qemu_vlog(const char *fmt, va_list va); =20 #endif diff --git a/include/qemu/log.h b/include/qemu/log.h index a8d1997cde..804cf90f0f 100644 --- a/include/qemu/log.h +++ b/include/qemu/log.h @@ -114,6 +114,8 @@ typedef struct QEMULogItem { extern const QEMULogItem qemu_log_items[]; =20 void qemu_set_log(int log_flags); +void qemu_log_to_monitor(bool enable); +void qemu_log_to_string(bool enable, GString *s); void qemu_log_needs_buffers(void); void qemu_set_log_filename(const char *filename, Error **errp); void qemu_set_dfilter_ranges(const char *ranges, Error **errp); diff --git a/monitor/misc.c b/monitor/misc.c index 6902e8addb..4af70dba92 100644 --- a/monitor/misc.c +++ b/monitor/misc.c @@ -504,6 +504,80 @@ static void hmp_tbstats(Monitor *mon, const QDict *qdi= ct) =20 } =20 +static void hmp_info_tbs(Monitor *mon, const QDict *qdict) +{ + int number_int; + const char *sortedby_str =3D NULL; + if (!tcg_enabled()) { + error_report("TB information is only available with accel=3Dtcg"); + return; + } + if (!tb_ctx.tb_stats.map) { + error_report("no TB information recorded"); + return; + } + + number_int =3D qdict_get_try_int(qdict, "number", 10); + sortedby_str =3D qdict_get_try_str(qdict, "sortedby"); + + int sortedby =3D SORT_BY_HOTNESS; + if (sortedby_str =3D=3D NULL || strcmp(sortedby_str, "hotness") =3D=3D= 0) { + sortedby =3D SORT_BY_HOTNESS; + } else if (strcmp(sortedby_str, "hg") =3D=3D 0) { + sortedby =3D SORT_BY_HG; + } else if (strcmp(sortedby_str, "spills") =3D=3D 0) { + sortedby =3D SORT_BY_SPILLS; + } else { + error_report("valid sort options are: hotness hg spills"); + return; + } + + dump_tbs_info(number_int, sortedby, true); +} + +static void hmp_info_tb(Monitor *mon, const QDict *qdict) +{ + const int id =3D qdict_get_int(qdict, "id"); + const char *flags =3D qdict_get_try_str(qdict, "flags"); + int mask; + + if (!tcg_enabled()) { + error_report("TB information is only available with accel=3Dtcg"); + return; + } + + mask =3D flags ? qemu_str_to_log_mask(flags) : CPU_LOG_TB_IN_ASM; + + if (!mask) { + error_report("Unable to parse log flags, see 'help log'"); + return; + } + + dump_tb_info(id, mask, true); +} + +static void hmp_info_coverset(Monitor *mon, const QDict *qdict) +{ + int coverage; + if (!tcg_enabled()) { + error_report("TB information is only available with accel=3Dtcg"); + return; + } + if (!tb_stats_collection_enabled()) { + error_report("TB information not being recorded"); + return; + } + + coverage =3D qdict_get_try_int(qdict, "coverage", 90); + + if (coverage < 0 || coverage > 100) { + error_report("Coverset percentage should be between 0 and 100"); + return; + } + + dump_coverset_info(coverage, true); +} + static void hmp_info_jit(Monitor *mon, const QDict *qdict) { if (!tcg_enabled()) { diff --git a/util/log.c b/util/log.c index 09cfb13b45..7d28a844c1 100644 --- a/util/log.c +++ b/util/log.c @@ -33,28 +33,58 @@ int qemu_loglevel; static int log_append =3D 0; static GArray *debug_regions; int32_t max_num_hot_tbs_to_dump; +static bool to_monitor; +bool to_string; =20 int tcg_collect_tb_stats; uint32_t default_tbstats_flag; =20 -/* Return the number of characters emitted. */ -int qemu_log(const char *fmt, ...) +GString *string; + +int qemu_vlog(const char *fmt, va_list va) { int ret =3D 0; - if (qemu_logfile) { - va_list ap; - va_start(ap, fmt); - ret =3D vfprintf(qemu_logfile, fmt, ap); - va_end(ap); - - /* Don't pass back error results. */ - if (ret < 0) { - ret =3D 0; + if (to_string) { + if (string) { + g_string_append_vprintf(string, fmt, va); } + } else if (to_monitor) { + ret =3D qemu_vprintf(fmt, va); + } else if (qemu_logfile) { + ret =3D vfprintf(qemu_logfile, fmt, va); + } + + /* Don't pass back error results. */ + if (ret < 0) { + ret =3D 0; } return ret; } =20 +/* Return the number of characters emitted. */ +int qemu_log(const char *fmt, ...) +{ + int ret =3D 0; + va_list ap; + va_start(ap, fmt); + + ret =3D qemu_vlog(fmt, ap); + + va_end(ap); + return ret; +} + +void qemu_log_to_monitor(bool enable) +{ + to_monitor =3D enable; +} + +void qemu_log_to_string(bool enable, GString *s) +{ + to_string =3D enable; + string =3D s; +} + static bool log_uses_own_buffers; =20 /* enable or disable low levels log */ --=20 2.22.0 From nobody Tue May 7 09:25:28 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1565837727; cv=none; d=zoho.com; s=zohoarc; b=UETz6g0pKPlPZPf4+KsMeMEaJdjXiZ0xamTzxb9h0MLh+opuT8eA/6lUiXFwbzLo4mjd+pBuWkPCa66UmWq+hh2XupvsIoW5MeGVkrex83tpZpCV1Rrm3xYY/Etk/jUUQ3k1ADiOb1p/NR4Yrol217n6Makp/v9LjbXjdFPssHI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1565837727; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=4TBbUXS4Lp57EZ4FvONnoIYEkWhrcydGdcmd671J9as=; b=RPlD3SGfJ5Q4vBOgLBAVShJaFMh9HC9269BjoCbFX3dsidFwAEzINubAyq+RtXhCHQMPWhi8yDgTRbEqcUyJSpxnqliAIIU6Be3ZHQneLSAe9D7UbJJgW3AmnuYEqrnhVIjlOkGsm1SC3XDzFFnPois37t132oUS4GbPdaL06ME= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1565837727266406.24408630661844; Wed, 14 Aug 2019 19:55:27 -0700 (PDT) Received: from localhost ([::1]:37901 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1hy5vC-0003yj-1o for importer@patchew.org; Wed, 14 Aug 2019 22:55:26 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:48706) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1hy5Mi-00011q-FT for qemu-devel@nongnu.org; Wed, 14 Aug 2019 22:19:49 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hy5Mg-0001uG-TP for qemu-devel@nongnu.org; Wed, 14 Aug 2019 22:19:48 -0400 Received: from mail-qk1-x741.google.com ([2607:f8b0:4864:20::741]:46422) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hy5Mg-0001sw-OY for qemu-devel@nongnu.org; Wed, 14 Aug 2019 22:19:46 -0400 Received: by mail-qk1-x741.google.com with SMTP id p13so724216qkg.13 for ; Wed, 14 Aug 2019 19:19:46 -0700 (PDT) Received: from localhost.localdomain ([2804:14c:482:121::1]) by smtp.googlemail.com with ESMTPSA id o5sm757943qkf.10.2019.08.14.19.19.43 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Wed, 14 Aug 2019 19:19:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=4TBbUXS4Lp57EZ4FvONnoIYEkWhrcydGdcmd671J9as=; b=CfmU6OeF+sztQRmvfcdtR9aKIYOYe3tCuUxhrV7mXi2g13jwCv8gilnNXDbH6J9geA 5RZo505e24DNQnCL4IaTWJUTwTDcspsJnM3uQpGSnMza5eFPYiTsICCE39k8ZKAjfwDx 6hA9BTjY1UUG73xuq9YAAOnblL+wINOZQfRVEdaXvnACgwbj2rOXZ+47msGml5dmuOfv kOn7CJtWh9VbsU1nP2Laq2DOSYiAMVWCaAJtZn+fBy3Y9VloNEqFKa2p93hNyS/h52id fbQcnkvbEcOJo2Jt+3TIhpmqGU5ZIG0ep3D38Suwib7kirC4F9KeEoKF/4FYPNm068x4 gsNQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=4TBbUXS4Lp57EZ4FvONnoIYEkWhrcydGdcmd671J9as=; b=IZpqw21bnh9z3x3EFJcCOXMe5QADwaVZrrhG19fgEjWu7pGuAr7EWOAzoDxVHxzSL9 ymnginLXP+PLlDxsNSeQ2DMmfqhPABMDsYw3KdMl2lTDrkJrKAJWmSYgFf8YwjMfu77a QhZFEFTB2OUYA39LTGCvyBdm4LdIm3Qohff5xpF2DoZlhQAkLCzJiBeEkAMQXNtIXHTO 0qLeBGK+xsbN0qKYMyX9Z2hZCvjiAyVW0OcR9FuF9QGtWD+UZC4VH8P5jboQx5BRKm5c nXEGT7hfJgmQxW83uakwWRdWf1n/UFP71HxXHaacmI9I2yw5GjwIQfhP1tQJX8XGkRur yNBQ== X-Gm-Message-State: APjAAAWbqHOpOUrCFLVykLezcI80YroLHWvKusRsjE2FGSw8pG0Ro++G kYZScQU/54IzsL+FMG8i2VBFvXirFM6vhA== X-Google-Smtp-Source: APXvYqz5c5POy/LRC9qn6x17l8OS3B1Z+/Rmgtqq9EyoYY7yuTIbATx4lU57rkwnd8kFD5QQ5QAJBw== X-Received: by 2002:a37:a744:: with SMTP id q65mr2085171qke.151.1565835585381; Wed, 14 Aug 2019 19:19:45 -0700 (PDT) From: vandersonmr To: qemu-devel@nongnu.org Date: Wed, 14 Aug 2019 23:18:56 -0300 Message-Id: <20190815021857.19526-10-vandersonmr2@gmail.com> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190815021857.19526-1-vandersonmr2@gmail.com> References: <20190815021857.19526-1-vandersonmr2@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::741 Subject: [Qemu-devel] [PATCH v5 09/10] monitor: adding new info cfg command X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Paolo Bonzini , vandersonmr , "Dr. David Alan Gilbert" , Markus Armbruster , Richard Henderson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Adding "info cfg id depth" commands to HMP. This command allow the exploration a TB neighbors by dumping [and opening] a .dot file with the TB CFG neighbors colorized by their hotness. 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. Signed-off-by: Vanderson M. do Rosario --- accel/tcg/tb-stats.c | 177 ++++++++++++++++++++++++++++++++++++++++ hmp-commands-info.hx | 7 ++ include/exec/tb-stats.h | 1 + monitor/misc.c | 22 +++++ 4 files changed, 207 insertions(+) diff --git a/accel/tcg/tb-stats.c b/accel/tcg/tb-stats.c index f5e519bdb7..5fda2bed9e 100644 --- a/accel/tcg/tb-stats.c +++ b/accel/tcg/tb-stats.c @@ -637,6 +637,182 @@ void dump_tb_info(int id, int log_mask, bool use_moni= tor) /* tbdi free'd by do_dump_tb_info_safe */ } =20 +/* TB CFG xdot/dot dump implementation */ +#define MAX_CFG_NUM_NODES 1000 +static int cfg_tb_id; +static GHashTable *cfg_nodes; +static uint64_t root_count; + +static void fputs_jump(TBStatistics *from, TBStatistics *to, FILE *dot) +{ + if (!from || !to) { + return; + } + + int *from_id =3D (int *) g_hash_table_lookup(cfg_nodes, from); + int *to_id =3D (int *) g_hash_table_lookup(cfg_nodes, to); + + if (!from_id || !to_id) { + return; + } + + GString *line =3D g_string_new(NULL); + + g_string_printf(line, " node_%d -> node_%d;\n", *from_id, *to_id); + + fputs(line->str, dot); + + g_string_free(line, true); +} + +static void fputs_tbstats(TBStatistics *tbs, FILE *dot, int log_flags) +{ + if (!tbs) { + return; + } + + GString *line =3D g_string_new(NULL);; + + uint32_t color =3D 0xFF666; + uint64_t count =3D tbs->executions.normal; + if (count > 1.6 * root_count) { + color =3D 0xFF000; + } else if (count > 1.2 * root_count) { + color =3D 0xFF333; + } else if (count < 0.4 * root_count) { + color =3D 0xFFCCC; + } else if (count < 0.8 * root_count) { + color =3D 0xFF999; + } + + GString *code_s =3D get_code_string(tbs, log_flags); + + for (int i =3D 0; i < code_s->len; i++) { + if (code_s->str[i] =3D=3D '\n') { + code_s->str[i] =3D ' '; + code_s =3D g_string_insert(code_s, i, "\\l"); + i +=3D 2; + } + } + + g_string_printf(line, + " node_%d [fillcolor=3D\"#%xFF0000\" shape=3D\"record\" " + "label=3D\"TB %d\\l" + "-------------\\l" + "PC:\t0x"TARGET_FMT_lx"\\l" + "exec count:\t%lu\\l" + "\\l %s\"];\n", + cfg_tb_id, color, cfg_tb_id, tbs->pc, + tbs->executions.normal, code_s->str); + + fputs(line->str, dot); + + int *id =3D g_new(int, 1); + *id =3D cfg_tb_id; + g_hash_table_insert(cfg_nodes, tbs, id); + + cfg_tb_id++; + + g_string_free(line, true); + g_string_free(code_s, true); +} + +static void fputs_preorder_walk(TBStatistics *tbs, int depth, FILE *dot, i= nt log_flags) +{ + if (tbs && depth > 0 + && cfg_tb_id < MAX_CFG_NUM_NODES + && !g_hash_table_contains(cfg_nodes, tbs)) { + + fputs_tbstats(tbs, dot, log_flags); + + if (tbs->tb) { + TranslationBlock *left_tb =3D NULL; + TranslationBlock *right_tb =3D NULL; + if (tbs->tb->jmp_dest[0]) { + left_tb =3D (TranslationBlock *) atomic_read(tbs->tb->jmp_= dest); + } + if (tbs->tb->jmp_dest[1]) { + right_tb =3D (TranslationBlock *) atomic_read(tbs->tb->jmp= _dest + 1); + } + + if (left_tb) { + fputs_preorder_walk(left_tb->tb_stats, depth - 1, dot, log= _flags); + fputs_jump(tbs, left_tb->tb_stats, dot); + } + if (right_tb) { + fputs_preorder_walk(right_tb->tb_stats, depth - 1, dot, lo= g_flags); + fputs_jump(tbs, right_tb->tb_stats, dot); + } + } + } +} + +struct PreorderInfo { + TBStatistics *tbs; + int depth; + int log_flags; +}; + +static void fputs_preorder_walk_safe(CPUState *cpu, run_on_cpu_data icmd) +{ + struct PreorderInfo *info =3D icmd.host_ptr; + + GString *file_name =3D g_string_new(NULL);; + g_string_printf(file_name, "/tmp/qemu-cfg-tb-%d-%d.dot", id, info->dep= th); + FILE *dot =3D fopen(file_name->str, "w+"); + + fputs( + "digraph G {\n" + " mclimit=3D1.5;\n" + " rankdir=3DTD; ordering=3Dout;\n" + " graph[fontsize=3D10 fontname=3D\"Verdana\"];\n" + " color=3D\"#efefef\";\n" + " node[shape=3Dbox style=3Dfilled fontsize=3D8 fontname=3D\"= Verdana\" fillcolor=3D\"#efefef\"];\n" + " edge[fontsize=3D8 fontname=3D\"Verdana\"];\n" + , dot); + + cfg_nodes =3D g_hash_table_new(NULL, NULL); + fputs_preorder_walk(info->tbs, info->depth, dot, info->log_flags); + g_hash_table_destroy(cfg_nodes); + + fputs("}\n\0", dot); + fclose(dot); + +#ifdef __linux__ + pid_t pid =3D fork(); + if (pid =3D=3D 0) { + char *args[] =3D {(char *) "xdot", file_name->str, NULL}; + execvp(args[0], args); + } +#endif + + qemu_log("CFG dumped: %s\n", file_name->str); + + g_string_free(file_name, true); + g_free(info); +} + +void dump_tb_cfg(int id, int depth, int log_flags) +{ + cfg_tb_id =3D 1; + root_count =3D 0; + + /* do a pre-order walk in the CFG with a limited depth */ + TBStatistics *root =3D get_tbstats_by_id(id); + if (root) { + root_count =3D root->executions.normal; + } + + struct PreorderInfo *info =3D g_new(struct PreorderInfo, 1); + info->tbs =3D root; + info->depth =3D depth + 1; + info->log_flags =3D log_flags; + async_safe_run_on_cpu(first_cpu, fputs_preorder_walk_safe, + RUN_ON_CPU_HOST_PTR(info)); +} + +/* TBStatistic collection controls */ + =20 void enable_collect_tb_stats(void) { @@ -686,3 +862,4 @@ uint32_t get_default_tbstats_flag(void) { return default_tbstats_flag; } + diff --git a/hmp-commands-info.hx b/hmp-commands-info.hx index 6691303c59..afbc80d3b1 100644 --- a/hmp-commands-info.hx +++ b/hmp-commands-info.hx @@ -305,6 +305,13 @@ ETEXI "a dump flag can be used to set dump code level: out= _asm in_asm op", .cmd =3D hmp_info_tb, }, + { + .name =3D "cfg", + .args_type =3D "id:i,depth:i?,flags:s?", + .params =3D "id [depth flags]", + .help =3D "plot CFG around TB with the given id", + .cmd =3D hmp_info_cfg, + }, { .name =3D "coverset", .args_type =3D "coverage:i?", diff --git a/include/exec/tb-stats.h b/include/exec/tb-stats.h index dc2a8155a0..d67f1966ec 100644 --- a/include/exec/tb-stats.h +++ b/include/exec/tb-stats.h @@ -127,6 +127,7 @@ void dump_tbs_info(int count, int sort_by, bool use_mon= itor); */ void dump_tb_info(int id, int log_mask, bool use_monitor); =20 +void dump_tb_cfg(int id, int depth, int log_flags); =20 /* TBStatistic collection controls */ void enable_collect_tb_stats(void); diff --git a/monitor/misc.c b/monitor/misc.c index 4af70dba92..da886e805c 100644 --- a/monitor/misc.c +++ b/monitor/misc.c @@ -556,6 +556,28 @@ static void hmp_info_tb(Monitor *mon, const QDict *qdi= ct) dump_tb_info(id, mask, true); } =20 +static void hmp_info_cfg(Monitor *mon, const QDict *qdict) +{ + const int id =3D qdict_get_int(qdict, "id"); + const int depth =3D qdict_get_try_int(qdict, "depth", 3); + const char *flags =3D qdict_get_try_str(qdict, "flags"); + int mask; + + if (!tcg_enabled()) { + error_report("TB information is only available with accel=3Dtcg"); + return; + } + + mask =3D flags ? qemu_str_to_log_mask(flags) : CPU_LOG_TB_IN_ASM; + + if (!mask) { + error_report("Unable to parse log flags, see 'help log'"); + return; + } + + dump_tb_cfg(id, depth, mask); +} + static void hmp_info_coverset(Monitor *mon, const QDict *qdict) { int coverage; --=20 2.22.0 From nobody Tue May 7 09:25:28 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1565836734; cv=none; d=zoho.com; s=zohoarc; b=NfOamz+RShzbQJg2U4rFyNnhB7/+BJpfofIXjtCdGhRFBnU95RPW3No70Ui77Ls4w3AMFa09NT5KeODPHpnz2v06N6oF8HulVT/9nJ+UJhGcyj5qLnTY0me6LEU3YU0MMWv6R0cAnDYs6ALiHJYXvxKkGPiUiD7ue9wmKNBv7ro= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1565836734; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=xH2u0/l2SqxJvZU8OkINvq+WEc2i5lm3OL3evVav5e8=; b=YBsmbP1b/iHdofem3GCOha8OPxzj8wdSNGgI+LSldGVco9qwbmO28UIdAIlso74YRLoWH01N0mVJXksGZf/kyZysc+QgRbFZI4ADT8YpNKdLwybPQ+QE3dXyqZHGG8YNESge3KHYkg4J6swXeoFtfBPbAADYU+WCa8x09UUMnZo= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1565836734612278.63897758780047; Wed, 14 Aug 2019 19:38:54 -0700 (PDT) Received: from localhost ([::1]:37642 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1hy5fA-0007pk-VT for importer@patchew.org; Wed, 14 Aug 2019 22:38:53 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:48710) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1hy5Mi-00012G-Um for qemu-devel@nongnu.org; Wed, 14 Aug 2019 22:19:49 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hy5Mh-0001xU-VT for qemu-devel@nongnu.org; Wed, 14 Aug 2019 22:19:48 -0400 Received: from mail-qt1-x841.google.com ([2607:f8b0:4864:20::841]:42814) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hy5Mh-0001wf-RY for qemu-devel@nongnu.org; Wed, 14 Aug 2019 22:19:47 -0400 Received: by mail-qt1-x841.google.com with SMTP id t12so904592qtp.9 for ; Wed, 14 Aug 2019 19:19:47 -0700 (PDT) Received: from localhost.localdomain ([2804:14c:482:121::1]) by smtp.googlemail.com with ESMTPSA id o5sm757943qkf.10.2019.08.14.19.19.45 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Wed, 14 Aug 2019 19:19:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=xH2u0/l2SqxJvZU8OkINvq+WEc2i5lm3OL3evVav5e8=; b=PPigVSIvqqoUz+yKwIcmJpybQ2D2IxQ+eyIAXlsxj0q7rtVrAWBIH8wPb+ffMpJYoG 2MbR7TXa4CyKQ3Oq9Nu4W2VGpxWx0o4vQRJkfknW2Q8UoKhNv2FBDwBvApu4j1RZYikX XYOiHj37u5KRZlTVTPN/uLQFtIkfwy/pnEjrkjhcW67WrllSPqgyatCa2XghRAMDzO9m XQeXIoGNZDHs+oGFcw7TRSGW8q6SnhCUoDPack8E6YVD16XNONq0+aGttdc2bAj3eupz 3y7nEzA2aWDaHrzLYSAXqtNZmnMFA9SzEEvJ3E1FQibONWBZUozi2EVY8JjSw9rVHBgR BneA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=xH2u0/l2SqxJvZU8OkINvq+WEc2i5lm3OL3evVav5e8=; b=sjAiJ5IOPk9NDqxHMIKwXuuY8Vi/uwd9xcbj+joQls2fazD6TWqjaS945v+Y7Rrl+r 9wTDCsQmdHXfKcgcNqoYiP7B9YRddrO7kYyvicB3g33+FzJbgjyxgT4ip3BH0ve2t2nR U6EAB1NDGLLTY1RDP5r7jA4o97WhOCOwK4vBadgJP0E59g00iBhwpsyYm63xqbladwlK HPN+8ZCaEjKCNCOs24eg43QYCsRaErAWZwdQfh8aRQw6d8pBePOFcRCqXuERHnvRTHtx 1Fj4wMG936pRxkZtl3QJ1S0jqL03eBGr8xJ6st15/H8oTr62DgC8PxStnCyyRoUt7az5 G69A== X-Gm-Message-State: APjAAAVOEbdAVTGb2dA32l/4DEEIDFKFmZTB4GsObgYZqzmJaPE5Ezih WrftW7y332+ZgkfCyD8nJXgkIR1NDqZVXg== X-Google-Smtp-Source: APXvYqzgokjF3SKSmsltzGEtxbxu7xkGLnYJd8upYJ7hbd9lCH/KDpn1KI7Zg6AlHKawBfmqNHV0bg== X-Received: by 2002:aed:2e02:: with SMTP id j2mr1966540qtd.89.1565835587177; Wed, 14 Aug 2019 19:19:47 -0700 (PDT) From: vandersonmr To: qemu-devel@nongnu.org Date: Wed, 14 Aug 2019 23:18:57 -0300 Message-Id: <20190815021857.19526-11-vandersonmr2@gmail.com> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190815021857.19526-1-vandersonmr2@gmail.com> References: <20190815021857.19526-1-vandersonmr2@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::841 Subject: [Qemu-devel] [PATCH v5 10/10] linux-user: dumping hot TBs at the end of the execution X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Riku Voipio , vandersonmr , Laurent Vivier Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" dumps, in linux-user mode, the hottest TBs if -d tb_stats is used. Signed-off-by: Vanderson M. do Rosario --- linux-user/exit.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/linux-user/exit.c b/linux-user/exit.c index bdda720553..7226104959 100644 --- a/linux-user/exit.c +++ b/linux-user/exit.c @@ -28,6 +28,10 @@ extern void __gcov_dump(void); =20 void preexit_cleanup(CPUArchState *env, int code) { + if (tb_stats_collection_enabled()) { + dump_tbs_info(max_num_hot_tbs_to_dump, SORT_BY_HOTNESS, false); + } + #ifdef TARGET_GPROF _mcleanup(); #endif --=20 2.22.0