From nobody Sat May 4 22:40:56 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=1567097428; cv=none; d=zoho.com; s=zohoarc; b=j7R7v691kiaVnNO/faOeOcY2MzwY+CvaLS1ip6thuD0dBQpJFBxZVrw4K6yvoAmBQXMMkqA4qYLg8YEgLMwDgtTa7lqCw6Kc0/UAWn1pPKCcK1Wqpb1oN65/qFZKcSyMHB7BM/2W8z+6zdBB6KK9/gCgqIoiaRBSeGCsJ4dujeg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1567097428; 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=xXZZccE5Eb2rPf5eFiRo/1jo8tL6rXWAvLjqjdijulg=; b=lrW5mnplw/7IiFpaSExUHRhBbRGY6UnxTKyVeWa9tM6KbSDjYBrAoJIemI+TU9/hNqZhm1VcVPpiRBInF5N2zdkFrYNGKEeIfxW1WrL1IUfaOVJ1I5lLG1lTKS5avB24qTlblepLqBRmFo1hF9iDTLLqeosuyTOaKvQEivdpIAs= 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 1567097428878145.60659512408847; Thu, 29 Aug 2019 09:50:28 -0700 (PDT) Received: from localhost ([::1]:52028 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i3Ncx-0008At-7y for importer@patchew.org; Thu, 29 Aug 2019 12:50:27 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:46328) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i3Naq-0006Bp-Ix for qemu-devel@nongnu.org; Thu, 29 Aug 2019 12:48:17 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1i3Nap-00068w-5c for qemu-devel@nongnu.org; Thu, 29 Aug 2019 12:48:16 -0400 Received: from mail-qt1-x842.google.com ([2607:f8b0:4864:20::842]:40960) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1i3Nap-00068n-1R for qemu-devel@nongnu.org; Thu, 29 Aug 2019 12:48:15 -0400 Received: by mail-qt1-x842.google.com with SMTP id i4so4400615qtj.8 for ; Thu, 29 Aug 2019 09:48:15 -0700 (PDT) Received: from vanderson-lmcad.gw.lmcad.ic.unicamp.br (gw.lmcad.ic.unicamp.br. [143.106.73.166]) by smtp.googlemail.com with ESMTPSA id g25sm1441024qkk.87.2019.08.29.09.48.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 29 Aug 2019 09:48:13 -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=xXZZccE5Eb2rPf5eFiRo/1jo8tL6rXWAvLjqjdijulg=; b=DmOR8gCpnYDXCorkNupG8bxDZkuyPtWkoQ4Cu6K0PdqwGG9hcHM5XF5GDOqZlkst/E vfDKQoXUAIXD71Cfeexb/hxZaQIqIeB85rbFgq0Mq0ol8ZaLRREq2btatZGSc38y1No8 9sB5Kr8jOW/GB2dYIuzHkj15dHL1y54w57qLtADuJaR8k0RO4LepleX3YLeVpXuv3tkM CAglrCK5YBhmcdnVaFZm16dA4GOnIbn09R9pnIHCzneAEPWxTsjslBgjgWIYj9rz+t6Z e0ddVbO8wBlbROqxwusnGbMXSAHADikLTqw1y2Eemjpo/Zo8aySGyog+dHHSvl/gQHqI nXKg== 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=xXZZccE5Eb2rPf5eFiRo/1jo8tL6rXWAvLjqjdijulg=; b=NPTfYdiNsh6xj6dbo5jAFP6Wld8OLKUXmfS6SU+tIyTUxyW8swQ0xIMyduxuqexZYE IUFJ83SiGLP5Iwz8cSUuPPwHYO0D8as8OK+HZY/YpfXqHW4dF3Fidt67B3QVcPT25P7l p41UiECkHpB0D4KA5kgdgBs6IYid/53b3K8fZ7Ptpk1SHhUSPAjgxlV+J8g5mwAp7sdR RL+Bzm1PW08IQohfRuRe41QJNel0WnE4uTIsFuNzmwSC4lDSqSW4rFoQaQufx/hPcgFJ Rcc8yR/IraBB1IMxAom59VVOTQmqm3CLmwLu6exyeiaQLRtBniLwV3ssY6aBd1/TZHEQ MxqA== X-Gm-Message-State: APjAAAVIxm8ib/pyJcAFjVFdGlEGKwbIbhrQtbldvdnLW1nNh/DcyBSD fMg1W2CWLDEAmbvwc466dcIsrg80Ev9hMg== X-Google-Smtp-Source: APXvYqwCVKz7eBSugUeQxve+ah6p0lzGvFv/U/4Npx4PV9b50B3smbI2PtLN6zeZwf/unG5AMT0QUw== X-Received: by 2002:ac8:4117:: with SMTP id q23mr10915005qtl.305.1567097294200; Thu, 29 Aug 2019 09:48:14 -0700 (PDT) From: vandersonmr To: qemu-devel@nongnu.org Date: Thu, 29 Aug 2019 13:47:45 -0300 Message-Id: <20190829164754.3906-2-vandersonmr2@gmail.com> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190829164754.3906-1-vandersonmr2@gmail.com> References: <20190829164754.3906-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 v7 01/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 48272c781b..9b2b7bff80 100644 --- a/accel/tcg/cpu-exec.c +++ b/accel/tcg/cpu-exec.c @@ -251,6 +251,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 948b107e68..1db81d83e7 100644 --- a/accel/tcg/tb-stats.c +++ b/accel/tcg/tb-stats.c @@ -61,3 +61,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..e72aeba682 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); + + if (qemu_log_in_addr_range(tb->pc)) { + uint32_t flag =3D get_default_tbstats_flag(); + 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 70c66c538c..ec6bd829a0 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 822c43cfd3..be006383b9 100644 --- a/include/exec/gen-icount.h +++ b/include/exec/gen-icount.h @@ -32,6 +32,15 @@ static inline void gen_io_end(void) tcg_temp_free_i32(tmp); } =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 898e05a36f..c4a8715400 100644 --- a/include/exec/tb-stats.h +++ b/include/exec/tb-stats.h @@ -30,6 +30,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 /* @@ -46,6 +49,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; }; @@ -56,7 +68,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 (1 << 0) +#define TB_EXEC_STATS (1 << 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); @@ -64,4 +81,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 Sat May 4 22:40:56 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=1567097582; cv=none; d=zoho.com; s=zohoarc; b=Q9Tn57m1+ZwhavDR5uQSoZCASzVaWNEwMYzPnCJ1FKYsMgWmSseyudzbxMk3kQiOVBH28tZ5aaC+vzdvnk6XINW+OG2EmjMc5qz/6CYlD++pPZQOTCD+FKxOmiKvyCixR+88+F12qrKzKO5VHcxNSbQgvb3goq1VCOTkIZd89TM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1567097582; h=Content-Type: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=fBs5joRr2GmQQ30d+sA4UaECTV9lNrfGzlG2K0u8w34=; b=NUUKR9AoasfHA8xb/Vy+dH91CmYCU/Lcgy/vEQF3+QLtO5LiG4wOZA/MDwz0aZXAP5Tq3nNqh2GpVwchXQO2aig7vXG+SYetZNKO6W6ZsxrDRvBsmYuHz3gBwV3mmy0NPtVUx4Nw7VICjd4LhQdssBWJfL6kjpThfPBbNMU+rpo= 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 1567097582789210.78130610976712; Thu, 29 Aug 2019 09:53:02 -0700 (PDT) Received: from localhost ([::1]:52064 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i3NfP-00036s-2K for importer@patchew.org; Thu, 29 Aug 2019 12:52:59 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:46364) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i3Nas-0006Dp-GT for qemu-devel@nongnu.org; Thu, 29 Aug 2019 12:48:20 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1i3Nar-0006AR-4B for qemu-devel@nongnu.org; Thu, 29 Aug 2019 12:48:18 -0400 Received: from mail-qt1-x843.google.com ([2607:f8b0:4864:20::843]:46788) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1i3Naq-0006AJ-WE for qemu-devel@nongnu.org; Thu, 29 Aug 2019 12:48:17 -0400 Received: by mail-qt1-x843.google.com with SMTP id j15so4354007qtl.13 for ; Thu, 29 Aug 2019 09:48:16 -0700 (PDT) Received: from vanderson-lmcad.gw.lmcad.ic.unicamp.br (gw.lmcad.ic.unicamp.br. [143.106.73.166]) by smtp.googlemail.com with ESMTPSA id g25sm1441024qkk.87.2019.08.29.09.48.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 29 Aug 2019 09:48:15 -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=fBs5joRr2GmQQ30d+sA4UaECTV9lNrfGzlG2K0u8w34=; b=JtxvI4TcUuH0qZM9o1DL6MPTGd+q/u2d4GSDBInCYwgGLDUODIRzVL2fDwukX/jma7 r6SpkD3oyhxxv1pLIuGy8LhAuMJxh+er0Yp/iYYyuaWVvhCd9Hu1F0krn2fEGpUs9+71 MeMMFwLqUV4vC1IWkjmDbWpXcw1RVZCLBXJPMtja3mCVaq6E1sDYs32jXpQmGsdsVUZ9 8SNUXPXZt0AJx3KRzlyCnUqtHck+KL4AELFvk6J6cQ0vXDoFnoEzZGAbItSURb4Zya+W nOZJ9W2poeMSMw3PCr23EpGIMzpqw4KT8IaBFIh9ai6yJa5EwNzN0AWmgt+8Bo1K9JD1 iKKA== 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=fBs5joRr2GmQQ30d+sA4UaECTV9lNrfGzlG2K0u8w34=; b=MrrxQjtcMfX3IU9aRuW+ISejYsH5PNksHhbJ4FGC6wLCcXfwc3WfU/ECaDZrmagxP/ rubDObGsBTPuMk4Y/IFobDXYkPsobM1oJRoXIHoo/VZIOoIdvMcHcYGfOoCGIAfgDjJq ++zqs4rUvjN96aKJNGGvscn6hVFbJl/uNEf6IBbtlvu3HSmfWZUs+VLuV8Tgn1RlBL7O XdfKicD6Omx7MoE6HhLqNPKz1U8YwtY9TZHwei3qhfojENsl024u1BBqKEDkq7vHKw/k u4dYJhsa2xTxALC2zwKh8q1AyQw5sDoKXfMN5i3xz3pwLXxDUZq6YeVz/Ukrcq1DZymY 0+AA== X-Gm-Message-State: APjAAAVPbHDEBNuELYVuh5N9Nx8Lp6y6D5xgljjwlMoE+13DAVCgorxn VxygKtpiHxKVBW9qwO5F/RerwXnlA0T05w== X-Google-Smtp-Source: APXvYqzJr5OrE3sTv/7s+iLrOGRXgc0Ko7/6KPtwTLi4xOHThdvAvhTjzOhOVbR7fElmzUY111/PMQ== X-Received: by 2002:ac8:1419:: with SMTP id k25mr10560141qtj.339.1567097296194; Thu, 29 Aug 2019 09:48:16 -0700 (PDT) From: vandersonmr To: qemu-devel@nongnu.org Date: Thu, 29 Aug 2019 13:47:46 -0300 Message-Id: <20190829164754.3906-3-vandersonmr2@gmail.com> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190829164754.3906-1-vandersonmr2@gmail.com> References: <20190829164754.3906-1-vandersonmr2@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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 v7 02/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: =?UTF-8?q?Alex=20Benn=C3=A9e?= , 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) 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. Reviewed-by: Alex Benn=C3=A9e Signed-off-by: Vanderson M. do Rosario --- accel/tcg/translate-all.c | 15 ++++++++++++++- accel/tcg/translator.c | 4 ++++ include/exec/tb-stats.h | 15 +++++++++++++++ tcg/tcg.c | 23 +++++++++++++++++++++++ tcg/tcg.h | 2 ++ 5 files changed, 58 insertions(+), 1 deletion(-) diff --git a/accel/tcg/translate-all.c b/accel/tcg/translate-all.c index e72aeba682..fb2fe0fa1f 100644 --- a/accel/tcg/translate-all.c +++ b/accel/tcg/translate-all.c @@ -1705,6 +1705,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; @@ -1785,13 +1786,18 @@ 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(); =20 if (qemu_log_in_addr_range(tb->pc)) { - uint32_t flag =3D get_default_tbstats_flag(); if (flag & TB_EXEC_STATS) { 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 +1875,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 +1936,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 ec6bd829a0..9b2e248b09 100644 --- a/accel/tcg/translator.c +++ b/accel/tcg/translator.c @@ -116,6 +116,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 c4a8715400..b68edd5d24 100644 --- a/include/exec/tb-stats.h +++ b/include/exec/tb-stats.h @@ -58,6 +58,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; }; @@ -71,6 +85,7 @@ enum TBStatsStatus { TB_STATS_RUNNING, TB_STATS_PAUSED, T= B_STATS_STOPPED }; =20 #define TB_NOTHING (1 << 0) #define TB_EXEC_STATS (1 << 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 0458eaec57..ae3e7a2217 100644 --- a/tcg/tcg.c +++ b/tcg/tcg.c @@ -3125,6 +3125,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: @@ -3996,6 +4001,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; @@ -4027,6 +4034,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. */ { @@ -4093,6 +4108,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 529acb2ed8..b4601162f8 100644 --- a/tcg/tcg.h +++ b/tcg/tcg.h @@ -740,6 +740,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 Sat May 4 22:40:56 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=1567097589; cv=none; d=zoho.com; s=zohoarc; b=AWyjLw8/RZtwvT0A4/FW7BGnUPRC3Ke4XLIteu2U4R6pWTkxf+BOlxUgxR/7UrBRGJoDYRkZgUqOgvMmCOCWWR5ESLc/4tlGZkWD2rv6fWSYESmJxwSaxIjc/tMDWa94SVT1UYFBjfFTWWmNYCBovid13GjN+iy/aWK6lP/+CM0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1567097589; h=Content-Type: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=0tyi9RV7v4NGuPxExoPiL2GQVSfMRvF20u4F8hRW0Eg=; b=NH83zP45bQW3tD+SJOGiYYVAqda8D31fieB2wEPZiKxNOyVcNQ/NtwjCiCawJyLwf/8KOztt2oB4HS6ty5M4oLuOriKiq0Sr96ghne0Rqknp0m9VKlhhxWfLozNlrpTzF3iGNZyyERYY4KYJxnMI6leFnqzwG4UkVZVGD6ds9qU= 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 1567097589949238.59378062401595; Thu, 29 Aug 2019 09:53:09 -0700 (PDT) Received: from localhost ([::1]:52066 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i3NfY-0003O9-Ce for importer@patchew.org; Thu, 29 Aug 2019 12:53:08 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:46416) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i3Naw-0006HT-KS for qemu-devel@nongnu.org; Thu, 29 Aug 2019 12:48:24 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1i3Nau-0006DC-Gi for qemu-devel@nongnu.org; Thu, 29 Aug 2019 12:48:22 -0400 Received: from mail-qk1-x741.google.com ([2607:f8b0:4864:20::741]:39325) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1i3Nau-0006Cf-9s for qemu-devel@nongnu.org; Thu, 29 Aug 2019 12:48:20 -0400 Received: by mail-qk1-x741.google.com with SMTP id 4so3544135qki.6 for ; Thu, 29 Aug 2019 09:48:19 -0700 (PDT) Received: from vanderson-lmcad.gw.lmcad.ic.unicamp.br (gw.lmcad.ic.unicamp.br. [143.106.73.166]) by smtp.googlemail.com with ESMTPSA id g25sm1441024qkk.87.2019.08.29.09.48.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 29 Aug 2019 09:48:18 -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=0tyi9RV7v4NGuPxExoPiL2GQVSfMRvF20u4F8hRW0Eg=; b=bHIkUcK34JTh19m1E5IOtE2LyvRK+/QJCnDRcDMQzSxsNA9ShxW1oKElrJtJOVWgkv d6u8RzIH7QR1PNK2BcGO2Qjr+1lv3bgGXv1RnmHQxTrcQAenlM7Pr5U7N565070Bp3hI htjsnZbi75uSxH/chlommC5av8nVPvCSY3r9pbGKCwom30hojJmrTYT+kf/9fYj5H963 1alMT2Tk5IihMLk8WHlQ3hhxzl1qNUY4HP0l92OW41VbyNOGS+2gikeXDgLUDTxVbydr xwIOzKqGlDgxkf05YcTtBRQO8Qv1tO9j1sLaF4NXXNs1ZMxEf7Pb9q+oSt5MjZciYZvi QmIg== 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=0tyi9RV7v4NGuPxExoPiL2GQVSfMRvF20u4F8hRW0Eg=; b=gFNXbIIbcoN9TOhbjXSzPzW4FYDOLL8gxlAK8+9nlVwi30lzSf5P7rTRVRmK1isXg6 6LLvH7r4hYfqXNTj/Cmzwb1zivrAgmkXyydCYxok3CYQosbOQt+uVGS7XrACqpoqYCPa CyXHt8bbaOUSJmBrs77czD3c3xvUBd20xNhOAkPEyYg5fjO3na37f8o+q4OO+rCtVHwg FkROLq2GSyoboX4blq9vnxsbwTackd6zSN16uNzOO8AbyXxuGPzia1GhuxxtnvvGBLiP nFyufkQid0BvoRjsQ8xNThH1iyC8z+fQsJI9KFM8Uu2zaiGpqSRxct+2DsjoGzHKs8xR ClbQ== X-Gm-Message-State: APjAAAVJEDQvJ1b0riO/+ia+YBE8C3EWzGa0q6OBQ4huD+xIapRZcHP/ hJVY6nnWQPapXNCun2Z/78MdxR3CnWJJfg== X-Google-Smtp-Source: APXvYqweDc0gkopYX8h2OgsKcCZCEzF0+X6ZchM+xy3Qioct7CN6ldomValWNXl9JQxPvnW2B1Xy6Q== X-Received: by 2002:a37:ad06:: with SMTP id f6mr3622087qkm.384.1567097299025; Thu, 29 Aug 2019 09:48:19 -0700 (PDT) From: vandersonmr To: qemu-devel@nongnu.org Date: Thu, 29 Aug 2019 13:47:47 -0300 Message-Id: <20190829164754.3906-4-vandersonmr2@gmail.com> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190829164754.3906-1-vandersonmr2@gmail.com> References: <20190829164754.3906-1-vandersonmr2@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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 v7 03/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: =?UTF-8?q?Alex=20Benn=C3=A9e?= , 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) 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. Reviewed-by: Alex Benn=C3=A9e Signed-off-by: Vanderson M. do Rosario --- accel/tcg/tb-stats.c | 96 +++++++++++++++++++++++++++++++++++++++ accel/tcg/translate-all.c | 8 +--- include/exec/tb-stats.h | 11 +++++ tcg/tcg.c | 93 ++++--------------------------------- tcg/tcg.h | 10 ---- 5 files changed, 119 insertions(+), 99 deletions(-) diff --git a/accel/tcg/tb-stats.c b/accel/tcg/tb-stats.c index 1db81d83e7..176da60e13 100644 --- a/accel/tcg/tb-stats.c +++ b/accel/tcg/tb-stats.c @@ -25,9 +25,105 @@ #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); + } + } + g_free(jpi); +} + + 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 fb2fe0fa1f..fe890f0782 100644 --- a/accel/tcg/translate-all.c +++ b/accel/tcg/translate-all.c @@ -1774,8 +1774,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 @@ -1823,7 +1821,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 @@ -1870,13 +1867,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 b68edd5d24..b9d5a343be 100644 --- a/include/exec/tb-stats.h +++ b/include/exec/tb-stats.h @@ -33,6 +33,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 /* @@ -63,7 +66,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 { @@ -80,6 +89,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 ae3e7a2217..03b11495aa 100644 --- a/tcg/tcg.c +++ b/tcg/tcg.c @@ -2294,9 +2294,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) @@ -3913,16 +3913,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); @@ -4002,26 +3992,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) @@ -4228,70 +4209,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 b4601162f8..a8d779f7e6 100644 --- a/tcg/tcg.h +++ b/tcg/tcg.h @@ -646,16 +646,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 Sat May 4 22:40:56 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=1567097445; cv=none; d=zoho.com; s=zohoarc; b=Y6AzOl9LwtOsj13yWm+q4mta0hsf+PEXg3Gny4W9HuC3N0YedLQ+kNbxTz5oGn7ATUnAK1HiOyF6Ftf5XC3daCDOYXgGDwXDQ8km82bpXg2gcW50JFAjVGRni9GIor3JlYFErcB4gG4U/Z1v55a8xn9DJ2n4/jRN8Sw73LoBIfI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1567097445; 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=ErbjO9DzMldhU3oh3AJ9Vm50vGT86OM30IcOuEpHSvQ=; b=NyzQzl9a9SWY1qdzfXY8KFp+Ft+5zuokh7ABIWHsNmtAsYHwz08KGLBiroAXWT8GQAYiTZxgmss9rhb2ysSMwmpKzOIAGwhbxDqWSwgH2vFNBNrwD1z4H2Uvr0pIvLIPECIPLJyw34RFxMNn5U1STYLsZoJzqOeVKeWMZZsYBMw= 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 1567097445798901.4855081341371; Thu, 29 Aug 2019 09:50:45 -0700 (PDT) Received: from localhost ([::1]:52030 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i3Nd7-0008ML-1c for importer@patchew.org; Thu, 29 Aug 2019 12:50:37 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:46462) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i3Naz-0006K6-5K for qemu-devel@nongnu.org; Thu, 29 Aug 2019 12:48:27 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1i3Naw-0006FW-KV for qemu-devel@nongnu.org; Thu, 29 Aug 2019 12:48:24 -0400 Received: from mail-qt1-x844.google.com ([2607:f8b0:4864:20::844]:38665) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1i3Naw-0006EZ-EQ for qemu-devel@nongnu.org; Thu, 29 Aug 2019 12:48:22 -0400 Received: by mail-qt1-x844.google.com with SMTP id b2so933149qtq.5 for ; Thu, 29 Aug 2019 09:48:22 -0700 (PDT) Received: from vanderson-lmcad.gw.lmcad.ic.unicamp.br (gw.lmcad.ic.unicamp.br. [143.106.73.166]) by smtp.googlemail.com with ESMTPSA id g25sm1441024qkk.87.2019.08.29.09.48.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 29 Aug 2019 09:48:21 -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=ErbjO9DzMldhU3oh3AJ9Vm50vGT86OM30IcOuEpHSvQ=; b=npRtL14CoL+dKKtXOc7x8DMLq2g5f28dPFCI2J2HFL7gNPOAmbhSTBQOY5+rl+d8Am Us/2SlmTp1mj5o3AyWUngfq3VjpYD+1oa3ADxAEH0xTe3O2sraMqPqc7qMiHa90SIbse yf04jX/03oUXtX5bkJekrczrcyWQDNWBFW+hzppe4U8/t3bfZSg5aDOVQyFh2UEqb5aL X6VuI+FAqpvGbed8QbBQPcAY3FDgMBtGsXXWJwRt+10paduuGgKxDYf/W8Z13ink0FWP cLvNdl9eWdif6yy/pNoJj6/h4bdCZzyw9VnOrCCozw89EX+O6qzwgCE3uH7FV/5oJC5N 3/TQ== 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=ErbjO9DzMldhU3oh3AJ9Vm50vGT86OM30IcOuEpHSvQ=; b=cdbOK4aV02Ki4c/ldjaU3v++UfQzn66VcGVmLwyg448cAWBwbK+QFYJUWLSFNafefV BVrOP8mr5fF2LXKjzPq1m2MeN3axRxVa1MOxHfvAdXh0vgXSd5kS5IOWCvhavtK0dxyk Sc8hhUoFis+byoZMU5mOvqXDGZoQ65Yp/GE109XDlFv37yRAwAT77JSwQJUKfUAbZJRd Z4xDRMJHGqUKyCjSawxbzdgIxelBXcqyC45y0BXwyK6mPXBUzBFfMsKZ7ulU87ltQ7i8 /5eXMNCASrGXeXr8r/LIvXY8ZH30kdkHZ+2JUYs8N+OV4njN/msaASCw885CJlMyI1dU n/Rw== X-Gm-Message-State: APjAAAVL0hDvAAayw4p/Z0T54XICRqTZGv5dq0H054Q+qR4y92lnG2sN HDaJmmZtLQXKVBvXAUML/m8ykBxFV+RC8Q== X-Google-Smtp-Source: APXvYqzqE8QSFX6vHcsnK92m2/Oe795tp6YJvMKpjidTQXrXqu2drEBqhUJE9zYmXfKYyKDh6pUF+A== X-Received: by 2002:ac8:281c:: with SMTP id 28mr10755308qtq.102.1567097301468; Thu, 29 Aug 2019 09:48:21 -0700 (PDT) From: vandersonmr To: qemu-devel@nongnu.org Date: Thu, 29 Aug 2019 13:47:48 -0300 Message-Id: <20190829164754.3906-5-vandersonmr2@gmail.com> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190829164754.3906-1-vandersonmr2@gmail.com> References: <20190829164754.3906-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 v7 04/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 , "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" 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 | 91 +++++++++++++++++++--------- accel/tcg/translate-all.c | 47 ++++++++------- configure | 3 - cpus.c | 14 ++--- include/exec/tb-stats.h | 19 +++++- include/qemu/timer.h | 5 +- monitor/misc.c | 28 ++------- tcg/tcg.c | 124 +++++++++++--------------------------- tcg/tcg.h | 10 +-- vl.c | 8 +-- 10 files changed, 156 insertions(+), 193 deletions(-) diff --git a/accel/tcg/tb-stats.c b/accel/tcg/tb-stats.c index 176da60e13..66abc97ad4 100644 --- a/accel/tcg/tb-stats.c +++ b/accel/tcg/tb-stats.c @@ -32,6 +32,8 @@ =20 #include "exec/tb-stats.h" =20 +uint64_t dev_time; + struct jit_profile_info { uint64_t translations; uint64_t aborted; @@ -43,6 +45,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 */ @@ -64,6 +73,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 */ @@ -90,34 +122,39 @@ 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_coun= t); + 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); diff --git a/accel/tcg/translate-all.c b/accel/tcg/translate-all.c index fe890f0782..a2e65bb85c 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 @@ -1724,10 +1725,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); @@ -1773,9 +1772,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 @@ -1796,6 +1792,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; } @@ -1820,10 +1821,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)) { @@ -1865,9 +1866,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 e44e454c43..af8ff2e6dc 100755 --- a/configure +++ b/configure @@ -6611,9 +6611,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 "$want_tools" =3D "yes" ; then echo "CONFIG_TOOLS=3Dy" >> $config_host_mak fi diff --git a/cpus.c b/cpus.c index 85cd451a86..c1844a412b 100644 --- a/cpus.c +++ b/cpus.c @@ -1433,21 +1433,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 b9d5a343be..0b9a6e2f72 100644 --- a/include/exec/tb-stats.h +++ b/include/exec/tb-stats.h @@ -81,22 +81,39 @@ struct TBStatistics { unsigned long spanning; } translations; =20 + struct { + int64_t restore; + uint64_t restore_count; + int64_t interm; + int64_t code; + int64_t opt; + int64_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 (1 << 0) #define TB_EXEC_STATS (1 << 1) #define TB_JIT_STATS (1 << 2) +#define TB_JIT_TIME (1 << 3) =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 85bc6eb00b..641ca3ddd0 100644 --- a/include/qemu/timer.h +++ b/include/qemu/timer.h @@ -1006,13 +1006,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 aef16f6cfb..ac4ff58d96 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 03b11495aa..4986ff3984 100644 --- a/tcg/tcg.c +++ b/tcg/tcg.c @@ -3884,82 +3884,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]); @@ -3969,25 +3921,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 @@ -4040,18 +3976,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); @@ -4074,9 +4010,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_add(&tb->tb_stats->time.la, profile_getclock()); + } =20 #ifdef DEBUG_DISAS if (unlikely(qemu_loglevel_mask(CPU_LOG_TB_OP_OPT) @@ -4109,14 +4045,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: @@ -4209,14 +4148,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 a8d779f7e6..3550d22873 100644 --- a/tcg/tcg.h +++ b/tcg/tcg.h @@ -646,12 +646,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 @@ -679,9 +673,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; @@ -1013,7 +1005,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 630f5c5e9c..4203cc728c 100644 --- a/vl.c +++ b/vl.c @@ -1796,17 +1796,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 Sat May 4 22:40:56 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=1567097554; cv=none; d=zoho.com; s=zohoarc; b=PNMwuu9bxtR/X/dF9upaOtnHs5V2+lrYn3zWMKQJSjsUD/ZQB5fTgV0i7latnWRTy4n+qa+il4aMvdXFsGNEf67rBP300lz2wtOC2Pz5u81fao2lW6y1yR0JKerDsEqY7KsuMEgDxqUDbXwBEYDnoAE7hbCCjfjS7p9pwd/2Vno= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1567097554; 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=Ype+RhMQ6yuP+PwkChrUABRIauIUwsULdkVXVz2HWbA=; b=PAvHGzLsOs4rOJa9Ccvtpxo0pqSV4bJUN26LK1hVBmVdybgRGwEsC8L7MPK35lY+x3lNJdNSKV0QJGPvKUuOGe0eQYYvjQ3VpNKqugu8nEfpnI/1FtTRfbKAsjD/9Z+xHzb8jpXUGir3opDDYx7ceLSa+XNeSiO1yJf0N8JzPKE= 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 1567097554587747.8712556679818; Thu, 29 Aug 2019 09:52:34 -0700 (PDT) Received: from localhost ([::1]:52062 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i3Ney-0002Xm-Ni for importer@patchew.org; Thu, 29 Aug 2019 12:52:32 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:46471) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i3Naz-0006KX-Jq for qemu-devel@nongnu.org; Thu, 29 Aug 2019 12:48:27 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1i3Nay-0006Gq-0S for qemu-devel@nongnu.org; Thu, 29 Aug 2019 12:48:25 -0400 Received: from mail-qt1-x843.google.com ([2607:f8b0:4864:20::843]:39018) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1i3Nax-0006GI-SJ for qemu-devel@nongnu.org; Thu, 29 Aug 2019 12:48:23 -0400 Received: by mail-qt1-x843.google.com with SMTP id n7so4411679qtb.6 for ; Thu, 29 Aug 2019 09:48:23 -0700 (PDT) Received: from vanderson-lmcad.gw.lmcad.ic.unicamp.br (gw.lmcad.ic.unicamp.br. [143.106.73.166]) by smtp.googlemail.com with ESMTPSA id g25sm1441024qkk.87.2019.08.29.09.48.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 29 Aug 2019 09:48:22 -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=Ype+RhMQ6yuP+PwkChrUABRIauIUwsULdkVXVz2HWbA=; b=HNhm4SoVmjnHxdjw6QxYKlFzH0pkT/tD0t6uHxmswbEZ1dApTArSaXc3bfdtYbXopw /QJsA+XzcoZmUCTgx5+9d3aQmYEVm4Npmzyelsuaugcs/Tqo0dDW+D+sBRRny3P4RgB9 KvcInx7MH1j8KHk7gkQ6ivChn8wyPFmckMgsQ5WX1Xyk9P2t2Ti4RNM9CDKdsV7mlqV5 0I6oTcXpxxaYLV8k5ui20Xd98I6E2f6ysArsgr4BM0/3TbpiOQyAXhKTMfObBadyiN+i XlFxhSyJfoG4WFFddHuU13VtG19QVFQGCUDupI1c/RoHeWUuI2IFxYl0crR5zTDNGKOf 4I/w== 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=Ype+RhMQ6yuP+PwkChrUABRIauIUwsULdkVXVz2HWbA=; b=cq1Ad8ljrdIvdmTBwwQCiq4OZnld/iOON50XdZiQabpQcA7qibHLWWdN3p44i7audD 0cawR8z4eQrYY6cR6Igt3sQyUJf2lMb5Rq81Rll156wA9LvJrHuiXeQ/iTb0AuTclpZN Gsl1ZWbbjKh98m0shGtPYCnKyvYLXrBPyAKRvxc6LEN/61T0veVaU4+O51vg2kxQvaW4 Vp+QmcQPpcVN4fkd70GCpc/d71wfaMT9NLm3J4AVLZt0zRc48pBV6xhMqScPQsHbfT+f vBacxuu1R4MEJ3Haar18c1EdoUlUWQZoC4VLpVSDo+rpa9LCBP5hm7Tpcv3ZFBtfEfjf EvGg== X-Gm-Message-State: APjAAAV9RC6s/W7Y0X6GHY8wXrTub1c1TT1OhQVzdhaR13Sha60xteey h2w21cO67kfHpPAwgnGaNltmMwNnwFx9lg== X-Google-Smtp-Source: APXvYqyiZJ00XnTEfmc9gAEpMdyKFnsamy8uXAgAx1GIOgqpPHsVGB1IfcOvc9NWvAWUqhxSuVPFDA== X-Received: by 2002:ad4:496b:: with SMTP id p11mr3433868qvy.29.1567097302936; Thu, 29 Aug 2019 09:48:22 -0700 (PDT) From: vandersonmr To: qemu-devel@nongnu.org Date: Thu, 29 Aug 2019 13:47:49 -0300 Message-Id: <20190829164754.3906-6-vandersonmr2@gmail.com> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190829164754.3906-1-vandersonmr2@gmail.com> References: <20190829164754.3906-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 v7 05/10] Adding -d tb_stats to control TBStatistics collection: 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: vandersonmr 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" -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 --- include/exec/gen-icount.h | 1 + include/exec/tb-stats-flags.h | 42 +++++++++++++++++++++++++++++++++++ include/exec/tb-stats.h | 18 +++------------ include/qemu/log.h | 1 + util/log.c | 35 +++++++++++++++++++++++++++++ 5 files changed, 82 insertions(+), 15 deletions(-) create mode 100644 include/exec/tb-stats-flags.h diff --git a/include/exec/gen-icount.h b/include/exec/gen-icount.h index be006383b9..3987adfb0e 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 "tb-stats-flags.h" =20 /* Helpers for instruction counting code generation. */ =20 diff --git a/include/exec/tb-stats-flags.h b/include/exec/tb-stats-flags.h new file mode 100644 index 0000000000..c936ac1084 --- /dev/null +++ b/include/exec/tb-stats-flags.h @@ -0,0 +1,42 @@ +/* + * QEMU System Emulator, Code Quality Monitor System + * + * Copyright (c) 2019 Vanderson M. do Rosario + * + * Permission is hereby granted, free of charge, to any person obtaining a= copy + * of this software and associated documentation files (the "Software"), t= o deal + * in the Software without restriction, including without limitation the r= ights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or se= ll + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included= in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS= OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OT= HER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING= FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS = IN + * THE SOFTWARE. + */ +#ifndef TB_STATS_FLAGS +#define TB_STATS_FLAGS + +enum TBStatsStatus { + TB_STATS_DISABLED =3D 0, + TB_STATS_RUNNING, + TB_STATS_PAUSED, + TB_STATS_STOPPED +}; + +#define TB_NOTHING (1 << 0) +#define TB_EXEC_STATS (1 << 1) +#define TB_JIT_STATS (1 << 2) +#define TB_JIT_TIME (1 << 3) + +extern int tcg_collect_tb_stats; +extern uint32_t default_tbstats_flag; + +#endif diff --git a/include/exec/tb-stats.h b/include/exec/tb-stats.h index 0b9a6e2f72..6a53bef31b 100644 --- a/include/exec/tb-stats.h +++ b/include/exec/tb-stats.h @@ -30,6 +30,8 @@ #include "exec/tb-context.h" #include "tcg.h" =20 +#include "exec/tb-stats-flags.h" + #define tb_stats_enabled(tb, JIT_STATS) \ (tb && tb->tb_stats && (tb->tb_stats->stats_enabled & JIT_STATS)) =20 @@ -98,26 +100,12 @@ 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 /* TBStatistic collection controls */ -enum TBStatsStatus { - TB_STATS_DISABLED =3D 0, - TB_STATS_RUNNING, - TB_STATS_PAUSED, - TB_STATS_STOPPED -}; - -#define TB_NOTHING (1 << 0) -#define TB_EXEC_STATS (1 << 1) -#define TB_JIT_STATS (1 << 2) -#define TB_JIT_TIME (1 << 3) - -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/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/util/log.c b/util/log.c index 29021a4584..c3805b331b 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 "exec/tb-stats-flags.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 Sat May 4 22:40:56 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=1567097809; cv=none; d=zoho.com; s=zohoarc; b=bLPIZ6nFp+m1zuf+6TAIPK0KOV2qbodBaMYe/qmj9hEYjlHPJygBEtUXwSi4V9HJK+VFnePLl8hoI303X/g9jto0LYF8kfVUZjyI6bil8xnM4qEdRdi/ZlOeWXelKsdMB6oGCjn96569NYbqc2xejYemkZfALgr58FQvSSwjGXM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1567097809; 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=vD3H1azDT1nF0aF1U/15SXskrW4/Xq3TLViAuCH6Ixk=; b=cYSi62oMYL0ThMkd9v44RpWzQqEwGj1GdUUTyAUxfC8Cl2DXm5ejeFkYhk7h/Q7jfcqAOZNNB/Jkzig6IXusP9VW8G6w8Gf74kgqd317GezJZRqRwdYXjgo6e5QO+vcb5B48XgD/Gp3C970Mf5KLbYg8v28RWK6lozGhQuuxLF0= 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 1567097809187856.5901762260286; Thu, 29 Aug 2019 09:56:49 -0700 (PDT) Received: from localhost ([::1]:52108 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i3Nj5-0007C0-Mw for importer@patchew.org; Thu, 29 Aug 2019 12:56:47 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:46519) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i3Nb2-0006NR-37 for qemu-devel@nongnu.org; Thu, 29 Aug 2019 12:48:29 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1i3Nb0-0006Iw-9U for qemu-devel@nongnu.org; Thu, 29 Aug 2019 12:48:27 -0400 Received: from mail-qk1-x742.google.com ([2607:f8b0:4864:20::742]:45384) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1i3Nb0-0006IX-45 for qemu-devel@nongnu.org; Thu, 29 Aug 2019 12:48:26 -0400 Received: by mail-qk1-x742.google.com with SMTP id m2so3502543qki.12 for ; Thu, 29 Aug 2019 09:48:26 -0700 (PDT) Received: from vanderson-lmcad.gw.lmcad.ic.unicamp.br (gw.lmcad.ic.unicamp.br. [143.106.73.166]) by smtp.googlemail.com with ESMTPSA id g25sm1441024qkk.87.2019.08.29.09.48.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 29 Aug 2019 09:48:24 -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=vD3H1azDT1nF0aF1U/15SXskrW4/Xq3TLViAuCH6Ixk=; b=ceyoz3RihwxTF+WEpbj55CHtOwKO+0EKtd4rgQO9HZ+6SoCXCt46IHxqiQTRhQwUbm xNzfghsY3fLid0DebqFIX1Jn7J9uVth9ddNiGt59rfaNDakFvGu1o3kH+SUNz6j0qQ3g rD6dpZZbI5XZS4yD8FqPLMCkdzn79jwxPuQb57UQYdXH7l5Pjc5Yjyk0REW55PP8OLpx 7dQO6oETEoOBY3miAecAj9xHofaO76xLrp/KcHhsD1U0LwPrvfBaNKP4BMWBFc0xMyvQ OlTG8kR1ArY3Hs2vD6BUDm/Qbyu+BOAJBZwgI10RqgNEHhOxijAXSxL2XJGtKUrNCSLo XHAw== 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=vD3H1azDT1nF0aF1U/15SXskrW4/Xq3TLViAuCH6Ixk=; b=kl1ZpxNoKEnEawEx4thqVaw8RYhZBvNDN04iT+2LBbO978VmPuHy2Ri29FrsI1jsjr GqhLDu093XoHZkMeQUhNDUG9ZK3UErfvWHinBxbcmOnj/lS89Xm+OtjjFknC+ZC9DY1L pzvlyCd/OXJ6nrTVcpCPv/1FYb7L8BgCOEO/qvOOWmd40npnBgGUtNNiBRDByEnabEW1 +Zp5o7VvGzkErce4aJtLSIUbsYq1OHKszuVMM1fU74meHOIFYGT5NrnkqW1nEFzUsfgu nE3uIUjtQDlNVkhs+1FVaTuaQ31m0opaAt9AihM94hnZEox/qROvRvLXBaEch94bpeYG aRhg== X-Gm-Message-State: APjAAAUUyF+1dwIR2dXDOkkS93iK2d4MuNlOFFefsyzyA7PiB39kcdY2 r9iPtKsJ9spBd/u67zT/s0XKjUnqPRbsNA== X-Google-Smtp-Source: APXvYqxcUOxnStcdsaFRHAQn9AOA6cPncBc3xRIRGTHj7KPGLZlad7QsPq/sRQC42/LL9PE7fO9/og== X-Received: by 2002:a37:8381:: with SMTP id f123mr10076741qkd.316.1567097305234; Thu, 29 Aug 2019 09:48:25 -0700 (PDT) From: vandersonmr To: qemu-devel@nongnu.org Date: Thu, 29 Aug 2019 13:47:50 -0300 Message-Id: <20190829164754.3906-7-vandersonmr2@gmail.com> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190829164754.3906-1-vandersonmr2@gmail.com> References: <20190829164754.3906-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 v7 06/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. Acked-by: Dr. David Alan Gilbert Signed-off-by: Vanderson M. do Rosario --- accel/tcg/tb-stats.c | 110 ++++++++++++++++++++++++++++++++++ hmp-commands.hx | 17 ++++++ include/exec/tb-stats-flags.h | 1 + include/exec/tb-stats.h | 11 ++++ monitor/misc.c | 47 +++++++++++++++ vl.c | 6 ++ 6 files changed, 192 insertions(+) diff --git a/accel/tcg/tb-stats.c b/accel/tcg/tb-stats.c index 66abc97ad4..9959477fbb 100644 --- a/accel/tcg/tb-stats.c +++ b/accel/tcg/tb-stats.c @@ -32,6 +32,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 { @@ -160,6 +163,95 @@ 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) { @@ -195,6 +287,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 cfcc044ce4..6cd2800378 100644 --- a/hmp-commands.hx +++ b/hmp-commands.hx @@ -1886,6 +1886,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-flags.h b/include/exec/tb-stats-flags.h index c936ac1084..16b563f858 100644 --- a/include/exec/tb-stats-flags.h +++ b/include/exec/tb-stats-flags.h @@ -35,6 +35,7 @@ enum TBStatsStatus { #define TB_EXEC_STATS (1 << 1) #define TB_JIT_STATS (1 << 2) #define TB_JIT_TIME (1 << 3) +#define TB_PAUSED (1 << 4) =20 extern int tcg_collect_tb_stats; extern uint32_t default_tbstats_flag; diff --git a/include/exec/tb-stats.h b/include/exec/tb-stats.h index 6a53bef31b..65063c52d7 100644 --- a/include/exec/tb-stats.h +++ b/include/exec/tb-stats.h @@ -32,6 +32,9 @@ =20 #include "exec/tb-stats-flags.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 @@ -105,6 +108,13 @@ 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); @@ -112,6 +122,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/monitor/misc.c b/monitor/misc.c index ac4ff58d96..b389ca09a1 100644 --- a/monitor/misc.c +++ b/monitor/misc.c @@ -459,6 +459,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 +1132,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 4203cc728c..dcb30eea8a 100644 --- a/vl.c +++ b/vl.c @@ -1796,11 +1796,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 Sat May 4 22:40:56 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=1567097601; cv=none; d=zoho.com; s=zohoarc; b=aCOiNLsYJOVceLO1quqfBKI2P65tDqGyShtnnvBpOvr+ZipFfXROC/Sujli0CFwufShHywXm1FMRQqysyy8DTrRzHv/x2uXX1NG1MFrr5oW6ywF7b8zLxHOx3G3NuFP13a6HWCUANiaj8bN/Py5ZyW7eog/0JYt6dzBc3K//Ejs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1567097601; 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=trBE4Pt415G810pTzI+AXLcczqBsJRYpVn3faZnlzM8=; b=Kg2UVvtegf9wW6PYS2v/HdyDx8Mtw6+4B5jWPuptwp2Ci3TZngxSRhZz5X0WEdBeELrcxBCzVd/ZFTYqDiZ1hT/bvtOjjr8vUap3RGMS5fezkIuvzLgYGMR3hciJv4GnO+E7hTLYCN62PyqJTW/ETjomx9VYfwPf/b6/jAcbv1I= 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 1567097601646662.7528475014752; Thu, 29 Aug 2019 09:53:21 -0700 (PDT) Received: from localhost ([::1]:52068 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i3Nfk-0003br-1Z for importer@patchew.org; Thu, 29 Aug 2019 12:53:20 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:46544) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i3Nb3-0006P8-EH for qemu-devel@nongnu.org; Thu, 29 Aug 2019 12:48:30 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1i3Nb2-0006LB-2R for qemu-devel@nongnu.org; Thu, 29 Aug 2019 12:48:29 -0400 Received: from mail-qk1-x743.google.com ([2607:f8b0:4864:20::743]:40618) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1i3Nb1-0006Kt-Ul for qemu-devel@nongnu.org; Thu, 29 Aug 2019 12:48:28 -0400 Received: by mail-qk1-x743.google.com with SMTP id f10so3549724qkg.7 for ; Thu, 29 Aug 2019 09:48:27 -0700 (PDT) Received: from vanderson-lmcad.gw.lmcad.ic.unicamp.br (gw.lmcad.ic.unicamp.br. [143.106.73.166]) by smtp.googlemail.com with ESMTPSA id g25sm1441024qkk.87.2019.08.29.09.48.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 29 Aug 2019 09:48: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=trBE4Pt415G810pTzI+AXLcczqBsJRYpVn3faZnlzM8=; b=GCSO46mq6c15ABLizl3xQsHquZ5Ga1dApzRydZweXqbbKxhRQ0Az5n1IvRTWwse8yC gzRYq43ltBJbbd1XLcmTj5YYpXZedVy+dZiERtbzjtuYPZO6gvGNTaOUDpTGNxTvj2OH ERnbkKIHpKYOsCnCb6SyJvCg+tSJBv3wA8KNDoj5Jymg+52CFQ7KBMHX9slkplwSUYH1 0Wtt6LpNat2L5P8umU1Bq3DAF2IOz+equgMOOXEhKqGt59ADkzbvnNEQYjo6muZLsmX9 R7W4M9L9nCwb/KoJejIMYUQZzwDyju4QMtbCChIpbFAUIPbgiRVoSLQVfBRuJSHwuRUh /MKQ== 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=trBE4Pt415G810pTzI+AXLcczqBsJRYpVn3faZnlzM8=; b=WmLByhZHh76Jj9PnqUTJHNYbxcqRnCOaYqG9dR7/yuo3qBnRBv5t5l1LzueZyI0zcV q7DqtkTBSLxYAXkRHBEC/WeK5yqod5ypEt0XKVw7GpbtyLo2I/WL4Rb3R0TNQQ+79JeG Qq0GmOWZWcm+Ih1R+PYOno6BoI0LFP2lDlKx4idS61BFFT1abkjzfguToVXDOUbuIK2L TeH6F/5efrSXzzEvON1uYqCyv3kNybGTelllOwsM7v2Kfus4BkHbvqnz7j20vjcANDwQ s5tl9qw0BGJl+9Fni3bTbV014yWfUQ2gD8pu31AtZRN1I7I1+3a0L4XY2NuSsrnYrmGa iM5g== X-Gm-Message-State: APjAAAXNWWDY1udJ+U9TZryHGIEAGB8RjbB4xrpP6CrwSiGsmJBRPsHE 9N8mgssSpPqn3zDeiUZwX75NB5151bV1/A== X-Google-Smtp-Source: APXvYqy3MXTB1DoDAbzh3Fl0KWrzDlda0jzcoPivskf6UlkUaem1EpWsOQoYutsLbYOjcvEOX9A8hg== X-Received: by 2002:a37:98f:: with SMTP id 137mr10623316qkj.188.1567097307093; Thu, 29 Aug 2019 09:48:27 -0700 (PDT) From: vandersonmr To: qemu-devel@nongnu.org Date: Thu, 29 Aug 2019 13:47:51 -0300 Message-Id: <20190829164754.3906-8-vandersonmr2@gmail.com> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190829164754.3906-1-vandersonmr2@gmail.com> References: <20190829164754.3906-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 v7 07/10] Adding tb_stats [start|pause|stop|filter] command to hmp. 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: vandersonmr , "Dr . David Alan Gilbert" , Markus Armbruster 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" 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. Acked-by: Dr. David Alan Gilbert Signed-off-by: Vanderson M. do Rosario --- monitor/misc.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/monitor/misc.c b/monitor/misc.c index b389ca09a1..218263d29a 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" --=20 2.22.0 From nobody Sat May 4 22:40:56 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=1567098029; cv=none; d=zoho.com; s=zohoarc; b=LrlN462VP+bq605fVpU8ulNs4XKS1zxiWrQ9HZG4/GVCNt1JfjOnij8Wor9LI98zADgsmeRSLVIp0ZjJmjyP7UDDvWAVGJvBbxx17cWUcUpr5L9MxOFC0KXNs8BywKKXNYaT8IPScWSJgxB2iGN53vhzltXqBbXMPYHvYhqpadg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1567098029; 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=gldjjNeOXXLP+VPk84ZaCQqNJXol7qudw4JE7i3j1aU=; b=H5cuMhZnljxsz9fwEKVD4JJWerZfRa6QPrwxOIKkcfb0vbAhSZGWPYTANokZerh938ZeP6VglGpNkjU6mAmQSjq+Q6Ft233cpqLIXp+BBdSq48iZlMu+HfWrYklTo3tsy5TMJH3MewFdzb/liG/RztjyO2Q6SGfyZd7vZzDrV2s= 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 1567098029543406.41279097408915; Thu, 29 Aug 2019 10:00:29 -0700 (PDT) Received: from localhost ([::1]:52146 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i3Nmd-00028O-SS for importer@patchew.org; Thu, 29 Aug 2019 13:00:27 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:46636) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i3Nb9-0006XL-Nb for qemu-devel@nongnu.org; Thu, 29 Aug 2019 12:48:42 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1i3Nb5-0006Q8-Vz for qemu-devel@nongnu.org; Thu, 29 Aug 2019 12:48:35 -0400 Received: from mail-qk1-x744.google.com ([2607:f8b0:4864:20::744]:37981) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1i3Nb5-0006P6-Pp for qemu-devel@nongnu.org; Thu, 29 Aug 2019 12:48:31 -0400 Received: by mail-qk1-x744.google.com with SMTP id u190so3561982qkh.5 for ; Thu, 29 Aug 2019 09:48:30 -0700 (PDT) Received: from vanderson-lmcad.gw.lmcad.ic.unicamp.br (gw.lmcad.ic.unicamp.br. [143.106.73.166]) by smtp.googlemail.com with ESMTPSA id g25sm1441024qkk.87.2019.08.29.09.48.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 29 Aug 2019 09:48:29 -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=gldjjNeOXXLP+VPk84ZaCQqNJXol7qudw4JE7i3j1aU=; b=IKocd4H2EJSbqlWsRnpPLI5Akly6A9K4i3pjsThzrKKpYVDbLYFBueCJ7ujacziqLt VW1rmqgLEiGXfkEJXqSiQmXuDcz/IQi7Uzlz686ZioOVP38ITPYDU1Or9AyBWExQYqEF S5lo/9OZujzPHgKzs3MzGsGahG1IhgbJwz4WOfOGN/GDmId+kzKoxdP/f1llisD5+HTB Vq/iPeqlU+b9QueZ6Xi6H47fElT26Yzqb1TL6kAEFFMwLKrk+zY/ms4g5jQx6kvqhgKE RykRVgSA+jYU2+IuzE17UO4T+nLXEm6j+LH7XY0GnlU6J42kvFQiuoh0MipKMqOnU7rp ajxg== 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=gldjjNeOXXLP+VPk84ZaCQqNJXol7qudw4JE7i3j1aU=; b=Nk101FcXd9P5lpLbBMTUehc7OAHFRGQnvrh6vzZiXZsJ2nS7U+sdtj94TxKnQRJCGj iz3MelzFtrm9LKDQODMzFEDcPEsq4fshY9vH55eoxfWCp6lhtEOTvSh4l+A+VRFNr0YI Xo8cYL6nzjsWNl5TzC3if4DjSvPKsDGk1gRH3Vx1XRZHv4Axtrwrbh1MHULFS4ZbpM8a FQaBElx54qT/RAI1qp71RiucOX1liiM4N20dgoTReZlirzZ479wHOjvjB+vCvEcEOWEp GR4Q+hO8HU7xgFCVRPqtnWAHhxZHZf3i+/KHvkAAOuOyApzgNQTpYH1S5xYqKYe9J360 RaNw== X-Gm-Message-State: APjAAAXVX/hVr1wquZfSqvEVGMlOvvLje+frSjmH89ULArVskeJbKj1q Usw+JJDqJu+ToXbPWfjtzdTx0V8WnGhFVA== X-Google-Smtp-Source: APXvYqyMn2VuBcWXEX2KIqhLf+cMGdVscyf4nlFQ/3DragFBBrAIzHyPlN0tYpwlUp8+quWAQ/5OaA== X-Received: by 2002:a05:620a:691:: with SMTP id f17mr10639334qkh.470.1567097309679; Thu, 29 Aug 2019 09:48:29 -0700 (PDT) From: vandersonmr To: qemu-devel@nongnu.org Date: Thu, 29 Aug 2019 13:47:52 -0300 Message-Id: <20190829164754.3906-9-vandersonmr2@gmail.com> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190829164754.3906-1-vandersonmr2@gmail.com> References: <20190829164754.3906-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::744 Subject: [Qemu-devel] [PATCH v7 08/10] Adding info [tb-list|tb|coverset] commands to HMP. 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" 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. The goal of this command is to allow the dynamic exploration of TCG behavior and code quality. Therefore, for now, a corresponding QMP command is not worthwhile. Example of output: TB id:1 | phys:0x34d54 virt:0x0000000000034d54 flags:0x0000f0 | exec:4828932/0 guest inst cov:16.38% | trans:1 ints: g:3 op:82 op_opt:34 spills:3 | h/g (host bytes / guest insts): 90.666664 | time to gen at 2.4GHz =3D> code:3150.83(ns) IR:712.08(ns) | targets: 0x0000000000034d5e (id:11), 0x0000000000034d0d (id:2) TB id:2 | phys:0x34d0d virt:0x0000000000034d0d flags:0x0000f0 | exec:4825842/0 guest inst cov:21.82% | trans:1 ints: g:4 op:80 op_opt:38 spills:2 | h/g (host bytes / guest insts): 84.000000 | time to gen at 2.4GHz =3D> code:3362.92(ns) IR:793.75(ns) | targets: 0x0000000000034d19 (id:12), 0x0000000000034d54 (id:1) TB id:2 | phys:0x34d0d virt:0x0000000000034d0d flags:0x0000f0 | exec:6956495/0 guest inst cov:21.82% | trans:2 ints: g:2 op:40 op_opt:19 spills:1 | h/g (host bytes / guest insts): 84.000000 | time to gen at 2.4GHz =3D> code:3130.83(ns) IR:722.50(ns) | targets: 0x0000000000034d19 (id:12), 0x0000000000034d54 (id:1) Acked-by: Dr. David Alan Gilbert ---------------- IN: 0x00034d0d: 89 de movl %ebx, %esi 0x00034d0f: 26 8b 0e movl %es:(%esi), %ecx 0x00034d12: 26 f6 46 08 80 testb $0x80, %es:8(%esi) 0x00034d17: 75 3b jne 0x34d54 ------------------------------ TB id:1 | phys:0x34d54 virt:0x0000000000034d54 flags:0x0000f0 | exec:5202686/0 guest inst cov:11.28% | trans:1 ints: g:3 op:82 op_opt:34 spills:3 | h/g (host bytes / guest insts): 90.666664 | time to gen at 2.4GHz =3D> code:2793.75(ns) IR:614.58(ns) | targets: 0x0000000000034d5e (id:3), 0x0000000000034d0d (id:2) TB id:2 | phys:0x34d0d virt:0x0000000000034d0d flags:0x0000f0 | exec:5199468/0 guest inst cov:15.03% | trans:1 ints: g:4 op:80 op_opt:38 spills:2 | h/g (host bytes / guest insts): 84.000000 | time to gen at 2.4GHz =3D> code:2958.75(ns) IR:719.58(ns) | targets: 0x0000000000034d19 (id:4), 0x0000000000034d54 (id:1) ------------------------------ 2 TBs to reach 25% of guest inst exec coverage Total of guest insts exec: 138346727 ------------------------------ Acked-by: Dr. David Alan Gilbert Signed-off-by: Vanderson M. do Rosario --- accel/tcg/tb-stats.c | 421 ++++++++++++++++++++++++++++++++++- accel/tcg/translate-all.c | 2 +- disas.c | 31 ++- hmp-commands-info.hx | 24 ++ include/exec/tb-stats.h | 45 +++- include/qemu/log-for-trace.h | 4 + include/qemu/log.h | 2 + monitor/misc.c | 74 ++++++ util/log.c | 52 ++++- 9 files changed, 634 insertions(+), 21 deletions(-) diff --git a/accel/tcg/tb-stats.c b/accel/tcg/tb-stats.c index 9959477fbb..d588c551c9 100644 --- a/accel/tcg/tb-stats.c +++ b/accel/tcg/tb-stats.c @@ -34,9 +34,35 @@ =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; + } + } + return NULL; +} + struct jit_profile_info { uint64_t translations; uint64_t aborted; @@ -175,6 +201,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; @@ -261,6 +288,398 @@ 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) { + TBStatistics *valid_target_tbstats[2] =3D {NULL, NULL}; + + /* + * Check and ensure that targets' tbstats have a valid display_id = and + * are in last_search list + */ + for (int jmp_id =3D 0; jmp_id < 2; jmp_id++) { + qemu_spin_lock(&tbs->tb->jmp_lock); + TranslationBlock *tb_dst =3D + (TranslationBlock *) (atomic_read(&tbs->tb->jmp_dest[jmp_i= d]) & ~1); + qemu_spin_unlock(&tbs->tb->jmp_lock); + + if (tb_dst) { + target_ulong pc =3D tb_dst ? tb_dst->pc : 0; + + /* Check if tb_dst is on the last_search list */ + TBStatistics *tbstats_pc =3D get_tbstats_by_addr(pc); + + /* if not in the last_search list, then insert it */ + if (!tbstats_pc) { + last_search =3D g_list_append(last_search, tb_dst->tb_= stats); + } + + /* if the tb_stats does not have a valid display_id, then = set one. */ + if (tb_dst->tb_stats && tb_dst->tb_stats->display_id =3D= =3D 0) { + tb_dst->tb_stats->display_id =3D id++; + valid_target_tbstats[jmp_id] =3D tb_dst->tb_stats; + } + } + } + + if (valid_target_tbstats[0] && !valid_target_tbstats[1]) { + qemu_log("\t| targets: 0x"TARGET_FMT_lx" (id:%d)\n", + valid_target_tbstats[0]->pc, valid_target_tbstats[0]->= display_id); + } else if (!valid_target_tbstats[0] && valid_target_tbstats[1]) { + qemu_log("\t| targets: 0x"TARGET_FMT_lx" (id:%d)\n", + valid_target_tbstats[1]->pc, valid_target_tbstats[1]->= display_id); + } else if (valid_target_tbstats[0] && valid_target_tbstats[1]) { + qemu_log("\t| targets: 0x"TARGET_FMT_lx" (id:%d), " + "0x"TARGET_FMT_lx" (id:%d)\n", + valid_target_tbstats[0]->pc, valid_target_tbstats[0]->= display_id, + valid_target_tbstats[1]->pc, valid_target_tbstats[1]->= display_id); + } 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 guest inst cov:%.2f%%\n", tbs->executio= ns.normal, + tbs->executions.atomic, tbs->executions.coverage / 100.0f); + } + + 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 *l =3D last_search; + while (l !=3D NULL && count--) { + TBStatistics *tbs =3D (TBStatistics *) l->data; + GList *next =3D l->next; + dump_tb_header(tbs); + l =3D next; + } +} + +static uint64_t calculate_last_search_coverages(void) +{ + uint64_t total_exec_count =3D 0; + GList *i; + + /* 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.atomic + tbs->executions.normal) * tbs->code.= num_guest_inst; + } + + for (i =3D last_search; i; i =3D i->next) { + TBStatistics *tbs =3D (TBStatistics *) i->data; + uint64_t tb_total_execs =3D + (tbs->executions.atomic + tbs->executions.normal) * tbs->code.= num_guest_inst; + tbs->executions.coverage =3D (10000 * tb_total_execs) / (total_exe= c_count + 1); + } + + return total_exec_count; +} + +static void do_dump_coverset_info(int percentage) +{ + mmap_lock(); + uint16_t total_coverage =3D 0; + unsigned coverset_size =3D 0; + percentage *=3D 100; + 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; + } + + uint64_t total_exec_count =3D calculate_last_search_coverages(); + + /* Iterate and tbs display_id until reach the coverage percentage coun= t */ + for (i =3D last_search; i && total_coverage < percentage; i =3D i->nex= t) { + TBStatistics *tbs =3D (TBStatistics *) i->data; + tbs->display_id =3D id++; + coverset_size++; + total_coverage +=3D tbs->executions.coverage; + } + + /* 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); + mmap_unlock(); + + qemu_log("------------------------------\n"); + qemu_log("%u TBs to reach %d%% of guest inst exec coverage\n", + coverset_size, percentage / 100); + qemu_log("Total of guest insts exec: %lu", total_exec_count); + qemu_log("\n------------------------------\n"); +} + +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; + } + + calculate_last_search_coverages(); + + 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 a2e65bb85c..fa163440dc 100644 --- a/accel/tcg/translate-all.c +++ b/accel/tcg/translate-all.c @@ -1778,7 +1778,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..f415479011 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 "tb-list", + .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_tblist, + }, + { + .name =3D "tb", + .args_type =3D "id:i,flags:s?", + .params =3D "id [flag1,flag2,...]", + .help =3D "show information about one translated block by id= ." + "dump flags 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 65063c52d7..51d73e1c5f 100644 --- a/include/exec/tb-stats.h +++ b/include/exec/tb-stats.h @@ -35,8 +35,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) @@ -64,6 +67,8 @@ struct TBStatistics { struct { unsigned long normal; unsigned long atomic; + /* filled only when dumping x% cover set */ + uint16_t coverage; } executions; =20 struct { @@ -82,7 +87,6 @@ struct TBStatistics { =20 struct { unsigned long total; - unsigned long uncached; unsigned long spanning; } translations; =20 @@ -95,6 +99,9 @@ struct TBStatistics { int64_t la; } time; =20 + /* HMP information - used for referring to previous search */ + int display_id; + /* current TB linked to this TBStatistics */ TranslationBlock *tb; }; @@ -115,6 +122,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 218263d29a..b99c018124 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_tblist(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 c3805b331b..698b48d083 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 Sat May 4 22:40:56 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=1567097784; cv=none; d=zoho.com; s=zohoarc; b=VPbTM6hMcAm6o1yTXgVFHn8EBXJN9OmasKa2kllHgW5OKHbLWEB98I3CTmaJXPIUgpdvoJ7to3VpuHIurFGnF7l3EgJtfYAbfGsK97tZMtAhfYnCs5C7eUq2sgYTddFH5klgQuMoLagx2uuh3SZzpILMLBkiMP+Es1E2q3Qj/+M= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1567097784; 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=uA3SYtnZA83HptN0mbb2qEQqLyGVSp6IpiQrNn1J314=; b=a1WkL6AqKusDmTy7WWcms+fgC4mmV1L6tKt3DhCvVtm66hjjEt6IGbdMDXKT9ODT4yLJ7OaD9vlYw6IX67v8fgvHGkoAuDjv0H9w3voFLTpcMPYYrbBm/MbY7xsODNo/X3dKpbKBa2eU73QCrovgVOs/QV4wX7I5XxjOU2PpqpY= 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 (209.51.188.17 [209.51.188.17]) by mx.zohomail.com with SMTPS id 1567097784188655.2072152309293; Thu, 29 Aug 2019 09:56:24 -0700 (PDT) Received: from localhost ([::1]:52102 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i3Nib-0006u0-JQ for importer@patchew.org; Thu, 29 Aug 2019 12:56:17 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:46639) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i3Nb9-0006XM-Na for qemu-devel@nongnu.org; Thu, 29 Aug 2019 12:48:37 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1i3Nb6-0006Qm-Ro for qemu-devel@nongnu.org; Thu, 29 Aug 2019 12:48:35 -0400 Received: from mail-qk1-x742.google.com ([2607:f8b0:4864:20::742]:43373) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1i3Nb6-0006QY-Mu for qemu-devel@nongnu.org; Thu, 29 Aug 2019 12:48:32 -0400 Received: by mail-qk1-x742.google.com with SMTP id m2so3512592qkd.10 for ; Thu, 29 Aug 2019 09:48:32 -0700 (PDT) Received: from vanderson-lmcad.gw.lmcad.ic.unicamp.br (gw.lmcad.ic.unicamp.br. [143.106.73.166]) by smtp.googlemail.com with ESMTPSA id g25sm1441024qkk.87.2019.08.29.09.48.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 29 Aug 2019 09:48:31 -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=uA3SYtnZA83HptN0mbb2qEQqLyGVSp6IpiQrNn1J314=; b=qoQEZucSxutuLNJ7BHXHaKQ4o05+KDGgfGGBuY1AYNntXDudAXEdX36Q8fHEUEy3Mm c7BQruBPeAQ2hL/SkNNjjXnHmOhTdCTCx0nzdna9hJJFd+0DfSlq/PypUVi2Oc+NgXE1 Jl2V5fPs+Oltxp9IRMacsFfT7LEcwA7y1PY3w5UGmkL5wXHCATCdmzz7V+lwVSoV2jQM zzr1qCAxHae9hU5u+NJrliMWdkt8762BvqnxBdiSeL+QM61BsMRIWz9CmY6hYnl2au/D G9iXwh6biBHtUzEpBmQJDuTZPBSFPjh85iTd0NGhwrWbA1KABnmJn5506OVJBgmLJ7XR 01BQ== 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=uA3SYtnZA83HptN0mbb2qEQqLyGVSp6IpiQrNn1J314=; b=moiLYnt03ivjNLaV4j8PIZu4F/xO7OsB6qRtSFV+Hta9s1RC/6hVv/MqyHRmgiqD2G dkLi1S2FaxQ0w3OvM4eE4A+SpJ1dRVJs2rpYykdPNiBr4JnQ4VeRmdLh7ST3iOVpTWLY Zn5jtkp3A7C2DCk0O9oST1nNDcbjTFczNpcgdafmrglHn5CBACj7Z9rHuwdEseW3ukNI GnmdPwM0GFlcVgBTZzK1q29oTnv5+bKGKnvryAK2510Ebyzo0Rz9LXL3RoHXe8zTB/Fz rKsa0nQEzaXjmCzQoKfQ76xnswcfrpiPiajyC7rgxv0YYpJYTLyV+5igJIprJVgoL5Fm cLdQ== X-Gm-Message-State: APjAAAW1FrXZ98RzE9KfmXtikYPor7WXS8Hbt9v3cmZ/cLmRMDLuVTl9 LwUJXahThgtht57OTjyBcQplORoIw8Uzhg== X-Google-Smtp-Source: APXvYqy+21fV7Ks2ENGvGDwSCxK72XE/nEnBv0bSKSsH8PCpgcPbdkF91L6SQjIqe4YB2DCHEG+FmQ== X-Received: by 2002:ae9:e313:: with SMTP id v19mr10560378qkf.22.1567097311852; Thu, 29 Aug 2019 09:48:31 -0700 (PDT) From: vandersonmr To: qemu-devel@nongnu.org Date: Thu, 29 Aug 2019 13:47:53 -0300 Message-Id: <20190829164754.3906-10-vandersonmr2@gmail.com> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190829164754.3906-1-vandersonmr2@gmail.com> References: <20190829164754.3906-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 v7 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 | 164 ++++++++++++++++++++++++++++++++++++++++ hmp-commands-info.hx | 7 ++ include/exec/tb-stats.h | 1 + monitor/misc.c | 22 ++++++ 4 files changed, 194 insertions(+) diff --git a/accel/tcg/tb-stats.c b/accel/tcg/tb-stats.c index d588c551c9..fd2344c5d1 100644 --- a/accel/tcg/tb-stats.c +++ b/accel/tcg/tb-stats.c @@ -679,6 +679,170 @@ 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; + } + + fprintf(dot, " node_%d -> node_%d;\n", *from_id, *to_id); +} + +/* Hotness colors used in the CFG */ +#define HOT_RED1 0xFF000 /* RGB(255,0,0) */ +#define HOT_RED2 0xFF333 /* RGB(255,51,48) */ +#define MILD_RED 0xFF666 /* RGB(255,102,96) */ +#define WEAK_RED1 0xFF999 /* RGB(255,153,144) */ +#define WEAK_RED2 0xFFCCC /* RGB(255,204,192) */ + +static void fputs_tbstats(TBStatistics *tbs, FILE *dot, int log_flags) +{ + if (!tbs) { + return; + } + + uint32_t color =3D MILD_RED; + uint64_t count =3D tbs->executions.normal; + if (count > 1.6 * root_count) { + color =3D HOT_RED1; + } else if (count > 1.2 * root_count) { + color =3D HOT_RED2; + } else if (count < 0.4 * root_count) { + color =3D WEAK_RED2; + } else if (count < 0.8 * root_count) { + color =3D WEAK_RED1; + } + + 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; + } + } + + fprintf(dot, + " 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); + + 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(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); + + 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) { diff --git a/hmp-commands-info.hx b/hmp-commands-info.hx index f415479011..8c96924c0b 100644 --- a/hmp-commands-info.hx +++ b/hmp-commands-info.hx @@ -305,6 +305,13 @@ ETEXI "dump flags 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 51d73e1c5f..4515db106a 100644 --- a/include/exec/tb-stats.h +++ b/include/exec/tb-stats.h @@ -155,6 +155,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 b99c018124..b3b31d7035 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 Sat May 4 22:40:56 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=1567098133; cv=none; d=zoho.com; s=zohoarc; b=LRfPVurPx0Gr/rCReYua1agy8Cd+6MNFYPoq/cODXzB1eGQxcV1hTeJqYfRV30bNBit6njVx02jL+/h/2iX2e5Di27GeyRp2gYphYDqdqwDD3ZIbjrGr7RE1v+MUYYTROpZ+gmR42/H2XOyytwhgHdiS4NwpxmOUOmjXfx9S5+0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1567098133; 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=eIyOQ+zPZUw8zXyJxqloCxuHMSH9TDYN6ZH48z46XB8=; b=XHL9rvlbZcfh+rrrbOMwHvmsRC9oAfLFqdHOH6RS34Ddsv94jBLzdznppizGKm8MESBsBUC9+cMKisySOMbLGOGRW8l1NZ27GreRiPV+hD/plPvB9jOYIvlMSm6qkhdKlgwUxh7Iz+AyZI1ZaFjYRNrYTc5uo6W/ZBfBT/vT64Q= 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 1567098133444595.422858235954; Thu, 29 Aug 2019 10:02:13 -0700 (PDT) Received: from localhost ([::1]:52170 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i3NoG-0003v4-Le for importer@patchew.org; Thu, 29 Aug 2019 13:02:08 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:46668) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i3NbA-0006Yt-UK for qemu-devel@nongnu.org; Thu, 29 Aug 2019 12:48:37 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1i3Nb9-0006U0-S2 for qemu-devel@nongnu.org; Thu, 29 Aug 2019 12:48:36 -0400 Received: from mail-qk1-x741.google.com ([2607:f8b0:4864:20::741]:42319) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1i3Nb9-0006SK-N8 for qemu-devel@nongnu.org; Thu, 29 Aug 2019 12:48:35 -0400 Received: by mail-qk1-x741.google.com with SMTP id f13so3478335qkm.9 for ; Thu, 29 Aug 2019 09:48:35 -0700 (PDT) Received: from vanderson-lmcad.gw.lmcad.ic.unicamp.br (gw.lmcad.ic.unicamp.br. [143.106.73.166]) by smtp.googlemail.com with ESMTPSA id g25sm1441024qkk.87.2019.08.29.09.48.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 29 Aug 2019 09:48: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=eIyOQ+zPZUw8zXyJxqloCxuHMSH9TDYN6ZH48z46XB8=; b=inmkQyMx73qSOv+Rs2r1RyzHITGmva3wn6EO9qZ6wMHYwu1Ok0Z1b6g7ZxW7RF58Ig G348yf1BePgQKirsPd6F4TtCk8xDm0QSohZzUuU2ziprgv1AbCIPReaj4JXVCOARZC9f DGo7pNHNCminY0hF+R/VsOxtuwKeR/DSuFTr5OmN/4yins6hT0E92NJNRTfOc+Ew5CfB edh5xwBaiiH/Mq2j/UjzW3uBuLMXP8vt8/xNHEEPO+GnpSWoQpIazXK1l8uJ/8DoTpbq /W6Ir8v4twCcmXAApP9YZb0hSSHdccuwaNnybG2woP0pXOAzLZEAsEgUdWEHySsfQRNj whKg== 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=eIyOQ+zPZUw8zXyJxqloCxuHMSH9TDYN6ZH48z46XB8=; b=gwi5+fZjcSKStAULj4XPNS5zI59Bj70pQtZwa3pxGuV1snI8+Rae/4UhpbTG3Ozu9P Gcxd0LiPZ5Hjxa1YCxqIYuOIPiu85qAkXcWqDdmHzjBZO6HguvQwQ6JH12vLeWo3fy9q Z9U6mIX0BDmMVZO/ibGPzUG+AOmItcNBUkXYjStctV3auahcpvWB9IzFVF+S+Yb8aqoL K22uaGBePr/By2s8wueQJIUb8BEj4k/I5JZprIYiDCgCLBSALFnZIyQnh6QxP6blCw38 8XG5ivHY5hr1L63l+1s/TFGZGTsZg68VD7TUgHYOZOOshns1gcLWmZxljutD3NPu6lQJ QrAQ== X-Gm-Message-State: APjAAAVOU22ZLpLj0eNWDaZzejLYoUoUZsGjueDiFG7mqtjoxlSzO06L 2lvXeD9ZzoyRgkVE2q91nf/V46K5v2JSpA== X-Google-Smtp-Source: APXvYqzEsMAAoqtYc4JkxrBCp6zUMOLiOXygyvD8ZssExeCX98XJDioVrQOa4qj2g1lQVERylHxf5w== X-Received: by 2002:a37:92c6:: with SMTP id u189mr10028790qkd.69.1567097313685; Thu, 29 Aug 2019 09:48:33 -0700 (PDT) From: vandersonmr To: qemu-devel@nongnu.org Date: Thu, 29 Aug 2019 13:47:54 -0300 Message-Id: <20190829164754.3906-11-vandersonmr2@gmail.com> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190829164754.3906-1-vandersonmr2@gmail.com> References: <20190829164754.3906-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 v7 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. Example of output for the 3 hottest TBs: TB id:1 | phys:0x34d54 virt:0x0000000000034d54 flags:0x0000f0 | exec:4828932/0 guest inst cov:16.38% | trans:1 ints: g:3 op:82 op_opt:34 spills:3 | h/g (host bytes / guest insts): 90.666664 | time to gen at 2.4GHz =3D> code:3150.83(ns) IR:712.08(ns) | targets: 0x0000000000034d5e (id:11), 0x0000000000034d0d (id:2) TB id:2 | phys:0x34d0d virt:0x0000000000034d0d flags:0x0000f0 | exec:4825842/0 guest inst cov:21.82% | trans:1 ints: g:4 op:80 op_opt:38 spills:2 | h/g (host bytes / guest insts): 84.000000 | time to gen at 2.4GHz =3D> code:3362.92(ns) IR:793.75(ns) | targets: 0x0000000000034d19 (id:12), 0x0000000000034d54 (id:1) TB id:3 | phys:0xec1c1 virt:0x00000000000ec1c1 flags:0x0000b0 | exec:872032/0 guest inst cov:1.97% | trans:1 ints: g:2 op:56 op_opt:26 spills:1 | h/g (host bytes / guest insts): 68.000000 | time to gen at 2.4GHz =3D> code:1692.08(ns) IR:473.75(ns) | targets: 0x00000000000ec1c5 (id:4), 0x00000000000ec1cb (id:13) 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