From nobody Wed May 1 22:06:27 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=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1570462971; cv=none; d=zoho.com; s=zohoarc; b=RVkyfZ6CemHpmi0Q9cI+UK4kJAOaMBnkPbEtsx0d3aVx9aUvgKdDxGSmlG/A7dU/OlkLWKhpaSgaLWpNwEQv+RcXykCe2SxxC1v1rfOJSjHMuz101u6vYzJDXSNx4+icv0tweu57DgQB3YkFgFFz8ETPcheJKrflhKU6q3T8EF8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1570462971; 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=iek8Qe/zrNC0/kJNkNMtZvO/A84+ne8Hmh0aHdialcc=; b=HU/QBPqmujjcmTyZ3wfB6c3kUoJlkA6EgV8S3H495YeIrH+P4bWsnsM+YprHsCQCsuD4gsNHbPmXnkadu6ryEMx1qm9Mcqodts2xb1RRI6KFjjfVrDJBpaqQ5BK/fJlmi1sttIS1TLNaxEW17J3kpunb0fQ18cVqO7jDc41w8JQ= 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 1570462970974507.70880274657236; Mon, 7 Oct 2019 08:42:50 -0700 (PDT) Received: from localhost ([::1]:46362 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iHV9t-0005VX-Gs for importer@patchew.org; Mon, 07 Oct 2019 11:42:49 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:48855) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iHUwH-0002Wu-RS for qemu-devel@nongnu.org; Mon, 07 Oct 2019 11:28:48 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iHUwF-00058L-LC for qemu-devel@nongnu.org; Mon, 07 Oct 2019 11:28:45 -0400 Received: from mail-wm1-x343.google.com ([2a00:1450:4864:20::343]:54594) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1iHUwF-00056N-Cs for qemu-devel@nongnu.org; Mon, 07 Oct 2019 11:28:43 -0400 Received: by mail-wm1-x343.google.com with SMTP id p7so13155639wmp.4 for ; Mon, 07 Oct 2019 08:28:43 -0700 (PDT) Received: from zen.linaroharston ([51.148.130.216]) by smtp.gmail.com with ESMTPSA id l9sm15548131wme.45.2019.10.07.08.28.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Oct 2019 08:28:39 -0700 (PDT) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id 43F041FF8C; Mon, 7 Oct 2019 16:28:39 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=iek8Qe/zrNC0/kJNkNMtZvO/A84+ne8Hmh0aHdialcc=; b=AQuUOSgQilvgiisA56Uw+1RSoVBC2Sw2dAG35RlozMv3I1H7KT42nrVlsmTNfsYB9j +nsYKNZYFj+8VNTROD1mXcvrrovutt1qLbV5QWBWl6/IcDNw3QzZHbFh6m6EyJhCEpI4 +sjQHkEQWkKNraARYgBmz5o5MDUSzBk2Kbp4RpT7Sj0JqNiAeSGL3LyBuZ9tFUcc+ij5 Olknguw0P1ys2oNHzDKdfLMgJHVJcEImpoi7p8M7xRCzRuiw4Ov7tt0mNP9INIw+RKbe EHPwArHhmB0N+70N+3N6O0Di/FEzWdjFAekVZox41dePNnPIbUMbvGaO2EmUMSAAecRT L5QQ== 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=iek8Qe/zrNC0/kJNkNMtZvO/A84+ne8Hmh0aHdialcc=; b=cMQ2r5T2d9ykBy1DngWU5sSENm/sMoT5/0Uswo6ev4U7ecwov9h7Oxwd2UmG5nXeom /pTf7Tme4Glb7jaFP4DIfAnobnw/wDOPfBHzOP2VkkuaQHImuzA2LJMcxeNr+MKCku3O OJ/Fk+psPsK9w3DnyS4z2w2btBJPmMkw+hANEhUXV6zuNwY5DvCd2EvnmtnhCAXWs/h8 SkxE/09xLOufWgjQdlPZe+CYDPgcVng7Jarq6/IrGGTTPt0xJSLmHt6B065bA4P4Z40K OJ7Ui5/JLh5oQ3ngCM/JNWEAKVTB06RT8Noso5bRqZ6jEiWRHJZDeYdvuYuYWa4e4KD1 0g2A== X-Gm-Message-State: APjAAAUl/pDx4jnmjmafVYsLpQQGXTQ0kp6LJbRv0ttX7ND4PlfxFEcA K6kkn/Kh4jqExHU8MQ2nAgQhYg== X-Google-Smtp-Source: APXvYqz2nAMnlEWeY97HR1v74wdonmdjAzGCCw1SxzQQIB07GWNBNnbYCIkyu6qMrunSYiMXEV9wNw== X-Received: by 2002:a05:600c:295d:: with SMTP id n29mr19925671wmd.36.1570462122021; Mon, 07 Oct 2019 08:28:42 -0700 (PDT) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: qemu-devel@nongnu.org Subject: [PATCH v9 01/13] accel/tcg: introduce TBStatistics structure Date: Mon, 7 Oct 2019 16:28:27 +0100 Message-Id: <20191007152839.30804-2-alex.bennee@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191007152839.30804-1-alex.bennee@linaro.org> References: <20191007152839.30804-1-alex.bennee@linaro.org> 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: 2a00:1450:4864:20::343 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?= , cota@braap.org, "Vanderson M. do Rosario" , Paolo Bonzini , Richard Henderson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) From: "Vanderson M. do Rosario" To store statistics for each TB, we created a TBStatistics structure which is linked with the TBs. TBStatistics can stay alive after tb_flush and be relinked to a regenerated TB. So the statistics can be accumulated even through flushes. The goal is to have all present and future qemu/tcg statistics and meta-data stored in this new structure. Reviewed-by: Alex Benn=C3=A9e Signed-off-by: Vanderson M. do Rosario Message-Id: <20190829173437.5926-2-vandersonmr2@gmail.com> [AJB: fix git author, review comments] Signed-off-by: Alex Benn=C3=A9e --- AJB - move tcg_collect_tb_stats inside tb-stats.c - add spdx header - drop tb from tbstats and associated functions --- accel/tcg/Makefile.objs | 2 +- accel/tcg/tb-stats.c | 52 +++++++++++++++++++++++++++++++++ accel/tcg/translate-all.c | 60 ++++++++++++++++++++++++++++++++++++++ include/exec/exec-all.h | 15 +++------- include/exec/tb-context.h | 12 ++++++++ include/exec/tb-hash.h | 7 +++++ include/exec/tb-stats.h | 61 +++++++++++++++++++++++++++++++++++++++ 7 files changed, 197 insertions(+), 12 deletions(-) create mode 100644 accel/tcg/tb-stats.c create mode 100644 include/exec/tb-stats.h diff --git a/accel/tcg/Makefile.objs b/accel/tcg/Makefile.objs index d381a02f34..49ffe81b5d 100644 --- a/accel/tcg/Makefile.objs +++ b/accel/tcg/Makefile.objs @@ -2,7 +2,7 @@ obj-$(CONFIG_SOFTMMU) +=3D tcg-all.o obj-$(CONFIG_SOFTMMU) +=3D cputlb.o obj-y +=3D tcg-runtime.o tcg-runtime-gvec.o obj-y +=3D cpu-exec.o cpu-exec-common.o translate-all.o -obj-y +=3D translator.o +obj-y +=3D translator.o tb-stats.o =20 obj-$(CONFIG_USER_ONLY) +=3D user-exec.o obj-$(call lnot,$(CONFIG_SOFTMMU)) +=3D user-exec-stub.o diff --git a/accel/tcg/tb-stats.c b/accel/tcg/tb-stats.c new file mode 100644 index 0000000000..8208f4a0ad --- /dev/null +++ b/accel/tcg/tb-stats.c @@ -0,0 +1,52 @@ +/* + * QEMU System Emulator, Code Quality Monitor System + * + * Copyright (c) 2019 Vanderson M. do Rosario + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#include "qemu/osdep.h" + +#include "disas/disas.h" + +#include "exec/tb-stats.h" + +/* TBStatistic collection controls */ +enum TBStatsStatus { TB_STATS_RUNNING, TB_STATS_PAUSED, TB_STATS_STOPPED }; + +static enum TBStatsStatus tcg_collect_tb_stats; + +void init_tb_stats_htable_if_not(void) +{ + if (tb_stats_collection_enabled() && !tb_ctx.tb_stats.map) { + qht_init(&tb_ctx.tb_stats, tb_stats_cmp, + CODE_GEN_HTABLE_SIZE, QHT_MODE_AUTO_RESIZE); + } +} + +void enable_collect_tb_stats(void) +{ + init_tb_stats_htable_if_not(); + tcg_collect_tb_stats =3D TB_STATS_RUNNING; +} + +void disable_collect_tb_stats(void) +{ + tcg_collect_tb_stats =3D TB_STATS_PAUSED; +} + +void pause_collect_tb_stats(void) +{ + tcg_collect_tb_stats =3D TB_STATS_STOPPED; +} + +bool tb_stats_collection_enabled(void) +{ + return tcg_collect_tb_stats =3D=3D TB_STATS_RUNNING; +} + +bool tb_stats_collection_paused(void) +{ + return tcg_collect_tb_stats =3D=3D TB_STATS_PAUSED; +} diff --git a/accel/tcg/translate-all.c b/accel/tcg/translate-all.c index 66d4bc4341..114ebe48bf 100644 --- a/accel/tcg/translate-all.c +++ b/accel/tcg/translate-all.c @@ -1118,6 +1118,23 @@ static inline void code_gen_alloc(size_t tb_size) } } =20 +/* + * This is the more or less the same compare as tb_cmp(), but the + * data persists over tb_flush. We also aggregate the various + * variations of cflags under one record and ignore the details of + * page overlap (although we can count it). + */ +bool tb_stats_cmp(const void *ap, const void *bp) +{ + const TBStatistics *a =3D ap; + const TBStatistics *b =3D bp; + + return a->phys_pc =3D=3D b->phys_pc && + a->pc =3D=3D b->pc && + a->cs_base =3D=3D b->cs_base && + a->flags =3D=3D b->flags; +} + static bool tb_cmp(const void *ap, const void *bp) { const TranslationBlock *a =3D ap; @@ -1137,6 +1154,7 @@ static void tb_htable_init(void) unsigned int mode =3D QHT_MODE_AUTO_RESIZE; =20 qht_init(&tb_ctx.htable, tb_cmp, CODE_GEN_HTABLE_SIZE, mode); + init_tb_stats_htable_if_not(); } =20 /* Must be called before using the QEMU cpus. 'tb_size' is the size @@ -1666,6 +1684,37 @@ tb_link_page(TranslationBlock *tb, tb_page_addr_t ph= ys_pc, return tb; } =20 +static TBStatistics *tb_get_stats(tb_page_addr_t phys_pc, target_ulong pc, + target_ulong cs_base, uint32_t flags) +{ + TBStatistics *new_stats =3D g_new0(TBStatistics, 1); + uint32_t hash =3D tb_stats_hash_func(phys_pc, pc, flags); + void *existing_stats =3D NULL; + new_stats->phys_pc =3D phys_pc; + new_stats->pc =3D pc; + new_stats->cs_base =3D cs_base; + new_stats->flags =3D flags; + + /* + * All initialisation must be complete before we insert into qht + * table otherwise another thread might get a partially created + * structure. + */ + qht_insert(&tb_ctx.tb_stats, new_stats, hash, &existing_stats); + + if (unlikely(existing_stats)) { + /* + * If there is already a TBStatistic for this TB from a previous f= lush + * then just make the new TB point to the older TBStatistic + */ + g_free(new_stats); + return existing_stats; + } else { + return new_stats; + } +} + + /* Called with mmap_lock held for user mode emulation. */ TranslationBlock *tb_gen_code(CPUState *cpu, target_ulong pc, target_ulong cs_base, @@ -1732,6 +1781,17 @@ TranslationBlock *tb_gen_code(CPUState *cpu, ti =3D profile_getclock(); #endif =20 + /* + * We want to fetch the stats structure before we start code + * generation so we can count interesting things about this + * generation. + */ + if (tb_stats_collection_enabled()) { + tb->tb_stats =3D tb_get_stats(phys_pc, pc, cs_base, flags); + } else { + tb->tb_stats =3D NULL; + } + tcg_func_start(tcg_ctx); =20 tcg_ctx->cpu =3D env_cpu(env); diff --git a/include/exec/exec-all.h b/include/exec/exec-all.h index 49db07ba0b..73b15db7a7 100644 --- a/include/exec/exec-all.h +++ b/include/exec/exec-all.h @@ -23,21 +23,11 @@ #include "cpu.h" #include "exec/tb-context.h" #include "sysemu/cpus.h" +#include "exec/tb-stats.h" =20 /* allow to see translation results - the slowdown should be negligible, s= o we leave it */ #define DEBUG_DISAS =20 -/* Page tracking code uses ram addresses in system mode, and virtual - addresses in userspace mode. Define tb_page_addr_t to be an appropriate - type. */ -#if defined(CONFIG_USER_ONLY) -typedef abi_ulong tb_page_addr_t; -#define TB_PAGE_ADDR_FMT TARGET_ABI_FMT_lx -#else -typedef ram_addr_t tb_page_addr_t; -#define TB_PAGE_ADDR_FMT RAM_ADDR_FMT -#endif - #include "qemu/log.h" =20 void gen_intermediate_code(CPUState *cpu, TranslationBlock *tb, int max_in= sns); @@ -410,6 +400,9 @@ struct TranslationBlock { uintptr_t jmp_list_head; uintptr_t jmp_list_next[2]; uintptr_t jmp_dest[2]; + + /* Pointer to a struct where statistics from the TB is stored */ + TBStatistics *tb_stats; }; =20 extern bool parallel_cpus; diff --git a/include/exec/tb-context.h b/include/exec/tb-context.h index feb585e0a7..3cfb62a338 100644 --- a/include/exec/tb-context.h +++ b/include/exec/tb-context.h @@ -23,6 +23,17 @@ #include "qemu/thread.h" #include "qemu/qht.h" =20 +/* Page tracking code uses ram addresses in system mode, and virtual + addresses in userspace mode. Define tb_page_addr_t to be an appropriate + type. */ +#if defined(CONFIG_USER_ONLY) +typedef abi_ulong tb_page_addr_t; +#define TB_PAGE_ADDR_FMT TARGET_ABI_FMT_lx +#else +typedef ram_addr_t tb_page_addr_t; +#define TB_PAGE_ADDR_FMT RAM_ADDR_FMT +#endif + #define CODE_GEN_HTABLE_BITS 15 #define CODE_GEN_HTABLE_SIZE (1 << CODE_GEN_HTABLE_BITS) =20 @@ -35,6 +46,7 @@ struct TBContext { =20 /* statistics */ unsigned tb_flush_count; + struct qht tb_stats; }; =20 extern TBContext tb_ctx; diff --git a/include/exec/tb-hash.h b/include/exec/tb-hash.h index 805235d321..dd8e8f252a 100644 --- a/include/exec/tb-hash.h +++ b/include/exec/tb-hash.h @@ -66,4 +66,11 @@ uint32_t tb_hash_func(tb_page_addr_t phys_pc, target_ulo= ng pc, uint32_t flags, return qemu_xxhash7(phys_pc, pc, flags, cf_mask, trace_vcpu_dstate); } =20 +static inline +uint32_t tb_stats_hash_func(tb_page_addr_t phys_pc, target_ulong pc, + uint32_t flags) +{ + return qemu_xxhash5(phys_pc, pc, flags); +} + #endif diff --git a/include/exec/tb-stats.h b/include/exec/tb-stats.h new file mode 100644 index 0000000000..4be6522da0 --- /dev/null +++ b/include/exec/tb-stats.h @@ -0,0 +1,61 @@ +/* + * 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_H + +#define TB_STATS_H + +#include "exec/cpu-common.h" +#include "exec/tb-context.h" +#include "tcg.h" + +typedef struct TBStatistics TBStatistics; + +/* + * This struct stores statistics such as execution count of the + * TranslationBlocks. Each sets of TBs for a given phys_pc/pc/flags + * has its own TBStatistics which will persist over tb_flush. + * + * We include additional counters to track number of translations as + * well as variants for compile flags. + */ +struct TBStatistics { + tb_page_addr_t phys_pc; + target_ulong pc; + uint32_t flags; + /* cs_base isn't included in the hash but we do check for matches */ + target_ulong cs_base; +}; + +bool tb_stats_cmp(const void *ap, const void *bp); + +void init_tb_stats_htable_if_not(void); + +void enable_collect_tb_stats(void); +void disable_collect_tb_stats(void); +void pause_collect_tb_stats(void); +bool tb_stats_collection_enabled(void); +bool tb_stats_collection_paused(void); + +#endif --=20 2.20.1 From nobody Wed May 1 22:06:27 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=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1570462642; cv=none; d=zoho.com; s=zohoarc; b=d4cYhtryo2wxeOTJpCV/94D/rS3Al1LuEzMm8NlroEmwhSUltdZ7OvEOMFgbVAAuizERJ6jV6PZ5nw9ScChSL/WiXRV2+mTcaMiWs3ipgXaDinbNDfr1X0tbUbuUCzU1X6CoekDQelLgHPjNbsqko42eiikzd9TKWZBvc/feGZk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1570462642; 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=jiinz3d2F99RIXRll0ualSf17q0g/ADEbP78O4FLO4Y=; b=eNpRYI98RitY+5Lr4TXiOMmUHGPrnpbmv40xhhRKcA/lYGnAen+FRAMuHqHw/tUEY6gEriGKnHwNQvDNqle4pT+JV5K316P0q8Z690FCs+Ubko3J/7Gw28kb399AjpuwjFCL2dpHaRKpkIFyulnYSWnxOwWT7QXVoII2lNDf0zE= 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 1570462642461886.5975334668102; Mon, 7 Oct 2019 08:37:22 -0700 (PDT) Received: from localhost ([::1]:46282 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iHV4Z-0000aS-BF for importer@patchew.org; Mon, 07 Oct 2019 11:37:19 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:48827) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iHUwG-0002Uu-8Q for qemu-devel@nongnu.org; Mon, 07 Oct 2019 11:28:45 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iHUwE-00055l-JQ for qemu-devel@nongnu.org; Mon, 07 Oct 2019 11:28:44 -0400 Received: from mail-wm1-x341.google.com ([2a00:1450:4864:20::341]:39099) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1iHUwE-000545-AI for qemu-devel@nongnu.org; Mon, 07 Oct 2019 11:28:42 -0400 Received: by mail-wm1-x341.google.com with SMTP id v17so12818975wml.4 for ; Mon, 07 Oct 2019 08:28:42 -0700 (PDT) Received: from zen.linaroharston ([51.148.130.216]) by smtp.gmail.com with ESMTPSA id x2sm19782660wrn.81.2019.10.07.08.28.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Oct 2019 08:28:39 -0700 (PDT) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id 62A111FF8F; Mon, 7 Oct 2019 16:28:39 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=jiinz3d2F99RIXRll0ualSf17q0g/ADEbP78O4FLO4Y=; b=R4sJ4dW2NklQ96IyVjLN9AfmmJgowWqJSewdwHBwxGD/rxO6l+LWGQnlgCyIXy/oaV hMyq3hr7K/IsEhBDzTcETIY3+kgxsF3iNOVQfcs0/uLRHcG4mhm6d9CajM/C8lUt6o/r IUfsF/r5/ylJC4z6/SzpjI6KJFH3Sl6/dPK0DK68BhHTS5h90kMPS3l/5PrXcN71HlbA 8T8STcIHG9Q54TBmpj8XwvubhnbNh4f5AUucVhLTSxAxmGRqCTOImpSLRTVBvMNuBpwf sIQfCwmFhs8xEAfqpus9z3YKggJtbJnN6KPV3rYTyE5ZoqgxjXyD5Jqj3RGbSpJhRCEa +uBw== 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=jiinz3d2F99RIXRll0ualSf17q0g/ADEbP78O4FLO4Y=; b=pEDvSbi9aHS3AFnMbrLKlbT9WC1Ybdcv8FBcmHZgIzAcDrXWQJWgPXAC9q8tYXD3Hm 2fUxy6ypKj1xOcxEnQ+swrCtfh42qNnivIr5sVhLUrJHbGwaU7ARoH4RW62DXcZ+bz2o tfVsGJzWKzxCviQoM96cJDsQBYv1O3ROfgn7WdCEHxQNnoMcB5HjDbl9FO6f19H5YIIY NcK6uVi9T8EVNfjyWrHFjbUSzLv4Yzl3hsexvTqWN9DdjrD5IC8+0RMbk5CGDx2Ifekm sswuvTaTy3xNkeJoWs4v8CKjfNMx4TEjsnNUSL2GAXsgdS5mrBN+0y53LBekzboVL9eW TDdQ== X-Gm-Message-State: APjAAAVNDwv2QHraCPlRCgvVFYw0wzxOUPxxzRxej29DPSRRRypWPL+O /JuGSI8/cm/j7ZC7KDc9wW1/Ow== X-Google-Smtp-Source: APXvYqzPPyMmjzt5/eqF/cED2fPcnLnUFJvdQz1LVYQVPsLU7TcwFOgifi2youNgr8vWXCZ1BfEh1Q== X-Received: by 2002:a7b:c258:: with SMTP id b24mr20574835wmj.21.1570462121096; Mon, 07 Oct 2019 08:28:41 -0700 (PDT) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: qemu-devel@nongnu.org Subject: [PATCH v9 02/13] accel: collecting TB execution count Date: Mon, 7 Oct 2019 16:28:28 +0100 Message-Id: <20191007152839.30804-3-alex.bennee@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191007152839.30804-1-alex.bennee@linaro.org> References: <20191007152839.30804-1-alex.bennee@linaro.org> 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: 2a00:1450:4864:20::341 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?= , cota@braap.org, "Vanderson M. do Rosario" , Paolo Bonzini , Richard Henderson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) From: "Vanderson M. do Rosario" 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 Message-Id: <20190829173437.5926-3-vandersonmr2@gmail.com> [AJB: Fix author] Signed-off-by: Alex Benn=C3=A9e --- AJB: - move default_tbstats_flag to tb-stats - hoist dfilter check --- accel/tcg/cpu-exec.c | 4 ++++ accel/tcg/tb-stats.c | 6 ++++++ accel/tcg/tcg-runtime.c | 7 +++++++ accel/tcg/tcg-runtime.h | 2 ++ accel/tcg/translate-all.c | 11 +++++++++-- accel/tcg/translator.c | 1 + include/exec/gen-icount.h | 9 +++++++++ include/exec/tb-stats.h | 18 ++++++++++++++++++ 8 files changed, 56 insertions(+), 2 deletions(-) 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 8208f4a0ad..ee0506bff1 100644 --- a/accel/tcg/tb-stats.c +++ b/accel/tcg/tb-stats.c @@ -16,6 +16,7 @@ enum TBStatsStatus { TB_STATS_RUNNING, TB_STATS_PAUSED, TB_STATS_STOPPED }; =20 static enum TBStatsStatus tcg_collect_tb_stats; +static uint32_t default_tbstats_flag; =20 void init_tb_stats_htable_if_not(void) { @@ -50,3 +51,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 114ebe48bf..b7dd1a78e5 100644 --- a/accel/tcg/translate-all.c +++ b/accel/tcg/translate-all.c @@ -1784,10 +1784,17 @@ TranslationBlock *tb_gen_code(CPUState *cpu, /* * We want to fetch the stats structure before we start code * generation so we can count interesting things about this - * generation. + * generation. If dfilter is in effect we will only collect stats + * for the specified range. */ - if (tb_stats_collection_enabled()) { + if (tb_stats_collection_enabled() && + qemu_log_in_addr_range(tb->pc)) { + uint32_t flag =3D get_default_tbstats_flag(); tb->tb_stats =3D tb_get_stats(phys_pc, pc, cs_base, flags); + + 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 4be6522da0..51aecf65e2 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,16 +49,31 @@ struct TBStatistics { uint32_t flags; /* cs_base isn't included in the hash but we do check for matches */ target_ulong cs_base; + + /* which stats are enabled for this TBStats */ + uint32_t stats_enabled; + + /* Execution stats */ + struct { + unsigned long normal; + unsigned long atomic; + } executions; + }; =20 bool tb_stats_cmp(const void *ap, const void *bp); =20 void init_tb_stats_htable_if_not(void); =20 +#define TB_NOTHING (1 << 0) +#define TB_EXEC_STATS (1 << 1) + void enable_collect_tb_stats(void); void disable_collect_tb_stats(void); void pause_collect_tb_stats(void); bool tb_stats_collection_enabled(void); bool tb_stats_collection_paused(void); =20 +uint32_t get_default_tbstats_flag(void); + #endif --=20 2.20.1 From nobody Wed May 1 22:06:27 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=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1570462715; cv=none; d=zoho.com; s=zohoarc; b=gNBZX2UB3XUE9xa6DhYTl0a19Yihqc6FnzXpdeT//lkjzgY60TfkYJQhXqimxUs3yvLADsH431KWh4N704UjGaPooTZ75qIcQwVxtERIbfKPMu4lnrzUmijmCajPIlg0WHXTmbh0RT13QkCCxdoEgfdgI6tM31pgGSOH6x5KucM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1570462715; 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=ZX61NvfE8BqogvWy9OM6m8VYaWtIBDMGNRtv9Ph9gpM=; b=L+/5u3w37D1PuCNbdAYzic5M+uKtp7+d5HI81qGd40/ZC4LCwAvBKliZE2zw2lAqqMOHx5bsNci8UMg52pPeD/XmcXlFwx5aVMWBkeZX8LdqzCObDwmujeHG9z8s+OfUJ/7dqDCvJVS5sdBdQq+InEElDxByczs+LdvnLCjbNmQ= 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 1570462715256597.7648958303881; Mon, 7 Oct 2019 08:38:35 -0700 (PDT) Received: from localhost ([::1]:46290 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iHV5l-0001dC-Fy for importer@patchew.org; Mon, 07 Oct 2019 11:38:33 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:48858) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iHUwI-0002X4-1k for qemu-devel@nongnu.org; Mon, 07 Oct 2019 11:28:47 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iHUwG-00058q-2u for qemu-devel@nongnu.org; Mon, 07 Oct 2019 11:28:45 -0400 Received: from mail-wr1-x443.google.com ([2a00:1450:4864:20::443]:36827) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1iHUwF-00057f-Rk for qemu-devel@nongnu.org; Mon, 07 Oct 2019 11:28:44 -0400 Received: by mail-wr1-x443.google.com with SMTP id y19so15859060wrd.3 for ; Mon, 07 Oct 2019 08:28:43 -0700 (PDT) Received: from zen.linaroharston ([51.148.130.216]) by smtp.gmail.com with ESMTPSA id a10sm16739122wrm.52.2019.10.07.08.28.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Oct 2019 08:28:40 -0700 (PDT) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id 7F6ED1FF90; Mon, 7 Oct 2019 16:28:39 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=ZX61NvfE8BqogvWy9OM6m8VYaWtIBDMGNRtv9Ph9gpM=; b=rrM7tQa0mFN3QELZQjQIJXyvQi9A3nSFZmwCOVV4sas5/kauY9RdwG6BN4zPPY9P0O N2JYAHZOJJPJIdtWIHEKf5hFmDmiqPSFHiwZCVx1Zr+hSHFKLrdSE1m7RgzWuvCtdvo8 J9is4NSMGayOInsWMuSZoaEaZuKW8PaFjt/qaKPsXJClxYXWpzWtWeB5d7KbXGAchtNr 9/T/kFkZNqUdEifaC1Algu4wmukZ8Raz/8IcbZByIAm2C/Oh/oK1cp4ttRiVuw81LeJz KJ5Q0vpoFDGufr6TcCaY9efUUkduh8PZsgo7+m4HMNbGaGK6jZlvnKvHI8+mGfNG2PvR nBAQ== 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=ZX61NvfE8BqogvWy9OM6m8VYaWtIBDMGNRtv9Ph9gpM=; b=elaRpRp7Z1aMCf07f2INbl8BL1nu8f8ETWJ0hW0/G+vyHLy1/jWZpfwF80lKPsW46n 7V5ccKBsT7MLxZ9wCoJL352Ynyy7RLL1wPGDrLHgs5SKsXPp4OKn8XwyPHbjsp/uOxrE vHHaGqQeefcv+pARHcsWEYMikZwMmOV77kC8R6/hWUgb3tHq9lNlkV5crscGbEevNr9a DV9yuEb+VgNMQzVed/J6HTM9dxhF5A9/shes5sr9dql5gzhr6wef8zhYGr7Zikz8eFnS K8AcYXcLukIMORT2budiFFHy+xJcW+pYUOi9pROMbkq2AiA1/eQAz9NZh4YZ8e/7qiqr Ntvw== X-Gm-Message-State: APjAAAWUoArulBqdxOM98MqDSEAcIJwvuG3VvDc9M1xsg5SCbL3uWKya t+knRoxeJRdroOn95uRudclMTA== X-Google-Smtp-Source: APXvYqxfrpdAh6cQL9BfqbMRdP/legsmBckQ4HAaZWiH6uHQpcaCn8nsPqS9aFoN+4t7ILBxF0hecw== X-Received: by 2002:a5d:664b:: with SMTP id f11mr23865013wrw.285.1570462122573; Mon, 07 Oct 2019 08:28:42 -0700 (PDT) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: qemu-devel@nongnu.org Subject: [PATCH v9 03/13] accel: collecting JIT statistics Date: Mon, 7 Oct 2019 16:28:29 +0100 Message-Id: <20191007152839.30804-4-alex.bennee@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191007152839.30804-1-alex.bennee@linaro.org> References: <20191007152839.30804-1-alex.bennee@linaro.org> 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: 2a00:1450:4864:20::443 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?= , cota@braap.org, "Vanderson M. do Rosario" , Paolo Bonzini , Richard Henderson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) From: "Vanderson M. do Rosario" If a TB has a TBS (TBStatistics) with the TB_JIT_STATS enabled then we collect statistics of its translation processes and code translation. To help with collection we include the TCGProfile structure unconditionally. It will have further alterations in future commits. Collecting the number of host instructions seems to be not simple as it would imply in having to modify several target source files. So, for now, we are only collecting the size of the host gen code. Signed-off-by: Vanderson M. do Rosario Message-Id: <20190829173437.5926-4-vandersonmr2@gmail.com> Signed-off-by: Alex Benn=C3=A9e --- AJB: - replace tb tracking with proper array. - stash tcg counts in tcg_ctx.prof until we can update later - update jit stats under a lock instead of lots of atomics - don't re-count nb_ops --- accel/tcg/translate-all.c | 35 ++++++++++++++++++++++++++++++++++- accel/tcg/translator.c | 3 +++ include/exec/tb-stats.h | 23 +++++++++++++++++++++++ tcg/tcg.c | 9 +++++++-- tcg/tcg.h | 23 +++++++++++++++++++++-- 5 files changed, 88 insertions(+), 5 deletions(-) diff --git a/accel/tcg/translate-all.c b/accel/tcg/translate-all.c index b7dd1a78e5..6fa9850a3a 100644 --- a/accel/tcg/translate-all.c +++ b/accel/tcg/translate-all.c @@ -1690,10 +1690,13 @@ static TBStatistics *tb_get_stats(tb_page_addr_t ph= ys_pc, target_ulong pc, TBStatistics *new_stats =3D g_new0(TBStatistics, 1); uint32_t hash =3D tb_stats_hash_func(phys_pc, pc, flags); void *existing_stats =3D NULL; + new_stats->phys_pc =3D phys_pc; new_stats->pc =3D pc; new_stats->cs_base =3D cs_base; new_stats->flags =3D flags; + new_stats->tbs =3D g_ptr_array_sized_new(4); + qemu_mutex_init(&new_stats->jit_stats_lock); =20 /* * All initialisation must be complete before we insert into qht @@ -1707,6 +1710,7 @@ static TBStatistics *tb_get_stats(tb_page_addr_t phys= _pc, target_ulong pc, * If there is already a TBStatistic for this TB from a previous f= lush * then just make the new TB point to the older TBStatistic */ + g_ptr_array_free(new_stats->tbs, true); g_free(new_stats); return existing_stats; } else { @@ -1726,8 +1730,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; +#ifdef CONFIG_PROFILER int64_t ti; #endif assert_memory_lock(); @@ -1795,6 +1799,10 @@ TranslationBlock *tb_gen_code(CPUState *cpu, 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; + } } else { tb->tb_stats =3D NULL; } @@ -1930,6 +1938,31 @@ TranslationBlock *tb_gen_code(CPUState *cpu, if ((pc & TARGET_PAGE_MASK) !=3D virt_page2) { phys_page2 =3D get_page_addr_code(env, virt_page2); } + + /* + * Collect JIT stats when enabled. We batch them all up here to + * avoid spamming the cache with atomic accesses + */ + if (tb_stats_enabled(tb, TB_JIT_STATS)) { + TBStatistics *ts =3D tb->tb_stats; + qemu_mutex_lock(&ts->jit_stats_lock); + + ts->code.num_guest_inst +=3D prof->translation.nb_guest_insns; + ts->code.num_tcg_ops +=3D prof->translation.nb_ops_pre_opt; + ts->code.num_tcg_ops_opt +=3D tcg_ctx->nb_ops; + ts->code.spills +=3D prof->translation.nb_spills; + ts->code.out_len +=3D tb->tc.size; + + ts->translations.total++; + if (phys_page2 !=3D -1) { + ts->translations.spanning++; + } + + g_ptr_array_add(ts->tbs, tb); + + qemu_mutex_unlock(&ts->jit_stats_lock); + } + /* * No explicit memory barrier is required -- tb_link_page() makes the * TB visible in a consistent state. diff --git a/accel/tcg/translator.c b/accel/tcg/translator.c index ec6bd829a0..114e76db27 100644 --- a/accel/tcg/translator.c +++ b/accel/tcg/translator.c @@ -116,6 +116,9 @@ void translator_loop(const TranslatorOps *ops, DisasCon= textBase *db, db->tb->size =3D db->pc_next - db->pc_first; db->tb->icount =3D db->num_insns; =20 + /* Save number of guest instructions for TB_JIT_STATS */ + tcg_ctx->prof.translation.nb_guest_insns =3D 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 51aecf65e2..566ae0d2be 100644 --- a/include/exec/tb-stats.h +++ b/include/exec/tb-stats.h @@ -59,6 +59,28 @@ struct TBStatistics { unsigned long atomic; } executions; =20 + /* JIT Stats - protected by lock */ + QemuMutex jit_stats_lock; + + 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; + + /* + * All persistent (cached) TranslationBlocks using + * this TBStats structure. Has to be reset on a tb_flush. + */ + GPtrArray *tbs; }; =20 bool tb_stats_cmp(const void *ap, const void *bp); @@ -67,6 +89,7 @@ void init_tb_stats_htable_if_not(void); =20 #define TB_NOTHING (1 << 0) #define TB_EXEC_STATS (1 << 1) +#define TB_JIT_STATS (1 << 2) =20 void enable_collect_tb_stats(void); void disable_collect_tb_stats(void); diff --git a/tcg/tcg.c b/tcg/tcg.c index 16b2d0e0ec..fa2fef9f1a 100644 --- a/tcg/tcg.c +++ b/tcg/tcg.c @@ -1117,6 +1117,7 @@ void tcg_func_start(TCGContext *s) s->nb_labels =3D 0; s->current_frame_offset =3D s->frame_start; =20 + s->prof.translation.nb_spills =3D 0; #ifdef CONFIG_DEBUG_TCG s->goto_tb_issue_mask =3D 0; #endif @@ -3125,6 +3126,7 @@ static void temp_sync(TCGContext *s, TCGTemp *ts, TCG= RegSet allocated_regs, case TEMP_VAL_REG: tcg_out_st(s, ts->type, ts->reg, ts->mem_base->reg, ts->mem_offset); + s->prof.translation.nb_spills++; break; =20 case TEMP_VAL_MEM: @@ -3990,12 +3992,12 @@ int64_t tcg_cpu_exec_time(void) =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 + s->current_tb =3D tb; + #ifdef CONFIG_PROFILER { int n =3D 0; @@ -4027,6 +4029,9 @@ int tcg_gen_code(TCGContext *s, TranslationBlock *tb) } #endif =20 + /* save pre-optimisation op count */ + prof->translation.nb_ops_pre_opt =3D s->nb_ops; + #ifdef CONFIG_DEBUG_TCG /* Ensure all labels referenced have been emitted. */ { diff --git a/tcg/tcg.h b/tcg/tcg.h index a37181c899..31571289cf 100644 --- a/tcg/tcg.h +++ b/tcg/tcg.h @@ -555,7 +555,26 @@ typedef struct TCGOp { /* Make sure operands fit in the bitfields above. */ QEMU_BUILD_BUG_ON(NB_OPS > (1 << 8)); =20 +/* + * The TCGProfile structure holds data for analysing the quality of + * the code generation. The data is split between stuff that is valid + * for the lifetime of a single translation and things that are valid + * for the lifetime of the translator. As the former is reset for each + * new translation so it should be copied elsewhere if you want to + * keep it. + * + * The structure is safe to access within the context of translation + * but accessing the data from elsewhere should be done with safe + * work. + */ typedef struct TCGProfile { + + struct { + int nb_guest_insns; + int nb_spills; + int nb_ops_pre_opt; + } translation; + int64_t cpu_exec_time; int64_t tb_count1; int64_t tb_count; @@ -600,9 +619,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; @@ -651,6 +668,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.20.1 From nobody Wed May 1 22:06:27 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=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1570462745; cv=none; d=zoho.com; s=zohoarc; b=Cz0r0S7K971uUb2p/uYnBtdha1+uyF/CmQpf9LFRdMfvmWuZh8AMzKSEkBEDF1bvzV4kzhe6h6Fwt070KCyeEXh15d1PQds4JxisRuwVc9SxPVcfxzzk7qE9zQUhcrEaUnE4Ymt9DCqG1wkVgm6fqPpmql/lQn5MOoSsqoTD5/w= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1570462745; 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=WKb/0Q1Y5QzQgdMwznbijSAIlWY98BZFsAtX/2aCdlc=; b=OxTjF2zgdbxXlXwLU7mWhtiGHiDt6YYF2+bekJIcR4EaMk/GCwO/ZJm2z0AVCLLjJku+8YEAjQVJDz+G91wx3I9g5F6KxNJsB3Lnu6S+q/KbtBnqbz29iwlwsDxJvEkmJ/gxUDWDS6ZFap9WkevYD0JzZUP6i656tjffz5WYRwM= 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 1570462745610358.0500806479349; Mon, 7 Oct 2019 08:39:05 -0700 (PDT) Received: from localhost ([::1]:46298 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iHV6G-00022U-1v for importer@patchew.org; Mon, 07 Oct 2019 11:39:04 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:48890) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iHUwK-0002a1-AC for qemu-devel@nongnu.org; Mon, 07 Oct 2019 11:28:51 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iHUwH-00059r-EL for qemu-devel@nongnu.org; Mon, 07 Oct 2019 11:28:48 -0400 Received: from mail-wr1-x441.google.com ([2a00:1450:4864:20::441]:34719) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1iHUwH-00059F-5z for qemu-devel@nongnu.org; Mon, 07 Oct 2019 11:28:45 -0400 Received: by mail-wr1-x441.google.com with SMTP id j11so10060489wrp.1 for ; Mon, 07 Oct 2019 08:28:45 -0700 (PDT) Received: from zen.linaroharston ([51.148.130.216]) by smtp.gmail.com with ESMTPSA id f143sm31722083wme.40.2019.10.07.08.28.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Oct 2019 08:28:42 -0700 (PDT) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id 9BE9B1FF91; Mon, 7 Oct 2019 16:28:39 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=WKb/0Q1Y5QzQgdMwznbijSAIlWY98BZFsAtX/2aCdlc=; b=XvqgXoNYo+0uQDsuX9JYCGjh7Jvz9u9WK3VWwNqjE+ZDkNT0Aol2a8e/Morlr/Uexw lMIT2wKY1RCGFOe8uwBhAWFJUjAGLucx0/DxRguGo+dcqXjn6SbtZMNOw9ihZ3wQY+hO /58GRpv6TVcisMVxJ7aSyFoQc4zAWM4eYJBChk1FYsoE4jPX39xFpMrS2AmtSHbNNVvU f/GOWADAbWvWcFTCcHQh8ZsxXdJ5izp5jmJJ3/6LukFyr8gFbqULa4nISikfLYDrLt6c n8u0sMuzIy9vwX3Xos0Sc8lYZhNjPFq+MqwVDOXmZIOLHf60t3/Q1sTj8D1FlpJC7Ozd 4/hw== 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=WKb/0Q1Y5QzQgdMwznbijSAIlWY98BZFsAtX/2aCdlc=; b=OZA9lgB1xNDpqw8FPNz3F/ThaCYCYIayrwzb0B8msnfiDOOE36VE/S4fcIzplATbpr ZLhiiJ1wB6L3Qdt+D7KoJk6r871TVFVrEfN4+U4O3iuRBC7/mIDKMbXoNRHN2cSrnqmL gMNjGKq6rchLQ8gdH8NHmbT14nbJ8WMI4yfdcqjNuV3XSA+8mxsoDpA9bYzemPLKzKJh 38VySwmWqj0IMUzMRMh8Tvzt3GEq52ZKi4Re20xZsb9JjZRpKXtAUIhvH/09xo3WMKCD a2CSuScf2Ta1o+4E7LyASz3IcrxkMPJCZj+oDXikiT3aMCaQ5CO3iSs7ybmh7JskjSya pFsw== X-Gm-Message-State: APjAAAWPVEk546Jnm7HvDNvzuEjRVj0ITYXwSWGgWSJZLnGQ3k+Rm5Ka 7eZSyUlopgK1cBztUc6AwK6SZQ== X-Google-Smtp-Source: APXvYqx2YXb8QzxbhQyVQEUqV7e7ZPpHZpXP11Cqx8Wu36Wq/DenE1kqdZEjw6eKO8Y9eVQxPTbkTQ== X-Received: by 2002:adf:ecc6:: with SMTP id s6mr17854287wro.174.1570462123881; Mon, 07 Oct 2019 08:28:43 -0700 (PDT) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: qemu-devel@nongnu.org Subject: [PATCH v9 04/13] accel: replacing part of CONFIG_PROFILER with TBStats Date: Mon, 7 Oct 2019 16:28:30 +0100 Message-Id: <20191007152839.30804-5-alex.bennee@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191007152839.30804-1-alex.bennee@linaro.org> References: <20191007152839.30804-1-alex.bennee@linaro.org> 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: 2a00:1450:4864:20::441 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?= , cota@braap.org, "Vanderson M. do Rosario" , Paolo Bonzini , Richard Henderson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) From: "Vanderson M. do Rosario" 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 Message-Id: <20190829173437.5926-5-vandersonmr2@gmail.com> [AJB: fix authorship, use prof structure] Signed-off-by: Alex Benn=C3=A9e --- AJB: - moving profiler stuff under jit_stats lock - keep TCGProf as per-ctx staging post for values - delete max counters as can be interfered. --- accel/tcg/tb-stats.c | 95 ++++++++++++++++++++++++++++++++++ accel/tcg/translate-all.c | 11 ++-- include/exec/tb-stats.h | 11 ++++ tcg/tcg.c | 105 ++++---------------------------------- tcg/tcg.h | 9 ++-- 5 files changed, 125 insertions(+), 106 deletions(-) diff --git a/accel/tcg/tb-stats.c b/accel/tcg/tb-stats.c index ee0506bff1..0e64c176b3 100644 --- a/accel/tcg/tb-stats.c +++ b/accel/tcg/tb-stats.c @@ -9,6 +9,10 @@ #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 @@ -18,6 +22,97 @@ enum TBStatsStatus { TB_STATS_RUNNING, TB_STATS_PAUSED, = TB_STATS_STOPPED }; static enum TBStatsStatus tcg_collect_tb_stats; static uint32_t default_tbstats_flag; =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 6fa9850a3a..84f759a829 100644 --- a/accel/tcg/translate-all.c +++ b/accel/tcg/translate-all.c @@ -1780,8 +1780,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 @@ -1807,6 +1805,7 @@ TranslationBlock *tb_gen_code(CPUState *cpu, tb->tb_stats =3D NULL; } =20 + tcg_func_start(tcg_ctx); =20 tcg_ctx->cpu =3D env_cpu(env); @@ -1828,7 +1827,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 @@ -1875,9 +1873,6 @@ 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 #ifdef DEBUG_DISAS @@ -1951,7 +1946,11 @@ TranslationBlock *tb_gen_code(CPUState *cpu, ts->code.num_tcg_ops +=3D prof->translation.nb_ops_pre_opt; ts->code.num_tcg_ops_opt +=3D tcg_ctx->nb_ops; ts->code.spills +=3D prof->translation.nb_spills; + ts->code.temps +=3D prof->translation.temp_count; + ts->code.deleted_ops +=3D prof->translation.del_op_count; + ts->code.in_len +=3D tb->size; ts->code.out_len +=3D tb->tc.size; + ts->code.search_out_len +=3D search_size; =20 ts->translations.total++; if (phys_page2 !=3D -1) { diff --git a/include/exec/tb-stats.h b/include/exec/tb-stats.h index 566ae0d2be..c779d6a183 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 /* @@ -67,7 +70,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 { @@ -87,6 +96,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); + #define TB_NOTHING (1 << 0) #define TB_EXEC_STATS (1 << 1) #define TB_JIT_STATS (1 << 2) diff --git a/tcg/tcg.c b/tcg/tcg.c index fa2fef9f1a..9c199c8a40 100644 --- a/tcg/tcg.c +++ b/tcg/tcg.c @@ -1118,6 +1118,8 @@ void tcg_func_start(TCGContext *s) s->current_frame_offset =3D s->frame_start; =20 s->prof.translation.nb_spills =3D 0; + s->prof.translation.del_op_count =3D 0; + s->prof.translation.temp_count =3D 0; #ifdef CONFIG_DEBUG_TCG s->goto_tb_issue_mask =3D 0; #endif @@ -2294,10 +2296,8 @@ void tcg_op_remove(TCGContext *s, TCGOp *op) QTAILQ_REMOVE(&s->ops, op, link); QTAILQ_INSERT_TAIL(&s->free_ops, op, link); s->nb_ops--; - -#ifdef CONFIG_PROFILER - atomic_set(&s->prof.del_op_count, s->prof.del_op_count + 1); -#endif + /* ? won't this end up op_opt - op =3D del_op_count ? */ + s->prof.translation.del_op_count++; } =20 static TCGOp *tcg_op_alloc(TCGOpcode opc) @@ -3910,16 +3910,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); @@ -3997,26 +3987,9 @@ int tcg_gen_code(TCGContext *s, TranslationBlock *tb) TCGOp *op; =20 s->current_tb =3D tb; - -#ifdef CONFIG_PROFILER - { - int n =3D 0; - - 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); - } - - 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); - } - } -#endif + /* save pre-optimisation op count */ + prof->translation.nb_ops_pre_opt =3D s->nb_ops; + prof->translation.temp_count =3D s->nb_temps; =20 #ifdef DEBUG_DISAS if (unlikely(qemu_loglevel_mask(CPU_LOG_TB_OP) @@ -4029,8 +4002,6 @@ int tcg_gen_code(TCGContext *s, TranslationBlock *tb) } #endif =20 - /* save pre-optimisation op count */ - prof->translation.nb_ops_pre_opt =3D s->nb_ops; =20 #ifdef CONFIG_DEBUG_TCG /* Ensure all labels referenced have been emitted. */ @@ -4210,70 +4181,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 31571289cf..5296f7c075 100644 --- a/tcg/tcg.h +++ b/tcg/tcg.h @@ -573,16 +573,13 @@ typedef struct TCGProfile { int nb_guest_insns; int nb_spills; int nb_ops_pre_opt; + + int del_op_count; + int temp_count; } translation; =20 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; --=20 2.20.1 From nobody Wed May 1 22:06:27 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=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1570463049; cv=none; d=zoho.com; s=zohoarc; b=GvjUGylkUds7ksaJAjOVy3VuGGaF7+Fkzn6jksXTDcontXKF2sZglwmKTpw/+0erSBZYUbrzHvmF88xVUlmApMPu5DzyEJYaCrLwMRPdLo97Vol7Y99KqkRm+kANMxIM2KGFcRB95tZgTTeCOx/ZwIPpcjIEHkz2hrlVbguLsN0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1570463049; 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=gaR/h6vIzeFfWXFxJELxenHTc8qDjXB7qS1QURQMS9g=; b=d4krD9wCQPgkzs0o3NY8x7Z+TzSlA5yvR9kAxgOOSidevbapdSciZmPPw5FUs2C7QFtusekxY1/9jjM9hNFJwXeRiFYaMgwWQJ7RDTobhCsUGCFNTfJhk9xgE+qI+KgBsahfV+q1SJImt1xbHwK12+uFZy9ghIvTDyJZKqJBcgg= 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 157046304927789.06916411345287; Mon, 7 Oct 2019 08:44:09 -0700 (PDT) Received: from localhost ([::1]:46372 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iHVB6-00064d-Fd for importer@patchew.org; Mon, 07 Oct 2019 11:44:04 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:48917) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iHUwL-0002bm-LQ for qemu-devel@nongnu.org; Mon, 07 Oct 2019 11:28:52 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iHUwI-0005Ab-Ki for qemu-devel@nongnu.org; Mon, 07 Oct 2019 11:28:49 -0400 Received: from mail-wm1-x334.google.com ([2a00:1450:4864:20::334]:36530) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1iHUwI-0005A1-7s for qemu-devel@nongnu.org; Mon, 07 Oct 2019 11:28:46 -0400 Received: by mail-wm1-x334.google.com with SMTP id m18so12837900wmc.1 for ; Mon, 07 Oct 2019 08:28:46 -0700 (PDT) Received: from zen.linaroharston ([51.148.130.216]) by smtp.gmail.com with ESMTPSA id a3sm14933460wmj.35.2019.10.07.08.28.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Oct 2019 08:28:42 -0700 (PDT) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id C0A841FF92; Mon, 7 Oct 2019 16:28:39 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=gaR/h6vIzeFfWXFxJELxenHTc8qDjXB7qS1QURQMS9g=; b=zGeKDGF87oX94Q4F1Nvcjm9AQBpQAyxDHor9hKtjIClfKXLZ9WQOBCPOE0v/RQW5YU +f9USzEqwFqQooGAgnoTpSwyGctijxQEVfDgY7MxTp6p2wA5PmxYZQA6gGDQtVPePebb Cp1TWPA4LjEcco+b457SpSU3m/qzpx9LejVDui5nM7ukvqW3WTLddhIy5hUMJyJ6r/VY 3AuX1WIz7aGMkRq8MBFzFm5/7TTj0C2F61gAwc7SXd6gr4NFn1XH7AunO4l8gJTxwqIr Zig5vWvNpLwkw9Ar5UZh8QCEW0UsmmYgixb1tG7b80up3cvGuSdEq+vcdbeUrKCUy0uq 2mng== 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=gaR/h6vIzeFfWXFxJELxenHTc8qDjXB7qS1QURQMS9g=; b=md0uSpSTJdWbuH4eYz+80cIPM5USFTnMQ2B2JB0e4UmHCO2MnSrEQHCTBhiiVKEXtI V+zV6jRp/MnjawFrFiCisnc625BUbVhTxAwgFm04NPRzmE3qdmB9KpqBCPg/zAI1+kSl QDG7f234RDmlE0hvCMdRVc+UA7uR1m60UyCKc8/5gfJ7smfmuvhCBeogPiB8A3ZJ3ABY KzDxQJMSF2Iq2dYHry3SuSkOKDCHN8GMs09oVEdkKhndfBJCVTETvpUf46NFGupZK5vv O9/eeQ7jFDsb5QTHatgv0rS/C6B6gA7KnN5kGzB5Zg63WEgKpWpdDSw4e5SmYyOr0wxQ KYBQ== X-Gm-Message-State: APjAAAXOD69rBX4hzDqGxzuFEfx0jU4SRV8AUtQ+rUUqkKE+hQg8xSNN unef8cOWNxtf3fdhF9YYCAvAvQ== X-Google-Smtp-Source: APXvYqwVN70WupAJluwKHY8iZvUkmZmSrxe/Hvt/mNtJi+UEE4iniz0PCu2M4AJ8nnyKjsVrBfUZCA== X-Received: by 2002:a1c:7ec4:: with SMTP id z187mr20292409wmc.94.1570462124857; Mon, 07 Oct 2019 08:28:44 -0700 (PDT) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: qemu-devel@nongnu.org Subject: [PATCH v9 05/13] accel: adding TB_JIT_TIME and full replacing CONFIG_PROFILER Date: Mon, 7 Oct 2019 16:28:31 +0100 Message-Id: <20191007152839.30804-6-alex.bennee@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191007152839.30804-1-alex.bennee@linaro.org> References: <20191007152839.30804-1-alex.bennee@linaro.org> 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: 2a00:1450:4864:20::334 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: "Vanderson M. do Rosario" , "Dr. David Alan Gilbert" , Markus Armbruster , cota@braap.org, Paolo Bonzini , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Richard Henderson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) From: "Vanderson M. do Rosario" 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 Message-Id: <20190829173437.5926-6-vandersonmr2@gmail.com> [AJB: fix authorship] Signed-off-by: Alex Benn=C3=A9e --- accel/tcg/tb-stats.c | 98 +++++++++++++++++++++--------- accel/tcg/translate-all.c | 46 ++++++++------- configure | 3 - cpus.c | 14 ++--- include/exec/tb-stats.h | 15 +++++ include/qemu/timer.h | 5 +- monitor/misc.c | 28 ++------- tcg/tcg.c | 121 ++++++++++++-------------------------- tcg/tcg.h | 2 +- vl.c | 8 +-- 10 files changed, 159 insertions(+), 181 deletions(-) diff --git a/accel/tcg/tb-stats.c b/accel/tcg/tb-stats.c index 0e64c176b3..f431159fd2 100644 --- a/accel/tcg/tb-stats.c +++ b/accel/tcg/tb-stats.c @@ -17,11 +17,18 @@ #include "exec/tb-stats.h" =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 static enum TBStatsStatus tcg_collect_tb_stats; static uint32_t default_tbstats_flag; =20 +uint64_t dev_time; + struct jit_profile_info { uint64_t translations; uint64_t aborted; @@ -33,6 +40,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 */ @@ -54,6 +68,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 */ @@ -80,34 +117,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 84f759a829..396e63c3e7 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 @@ -1731,9 +1732,8 @@ TranslationBlock *tb_gen_code(CPUState *cpu, tcg_insn_unit *gen_code_buf; int gen_code_size, search_size, max_insns; TCGProfile *prof =3D &tcg_ctx->prof; -#ifdef CONFIG_PROFILER - int64_t ti; -#endif + uint64_t ti =3D 0; + assert_memory_lock(); =20 phys_pc =3D get_page_addr_code(env, pc); @@ -1779,9 +1779,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 @@ -1801,6 +1798,11 @@ TranslationBlock *tb_gen_code(CPUState *cpu, if (flag & TB_JIT_STATS) { tb->tb_stats->stats_enabled |=3D TB_JIT_STATS; } + + if (flag & TB_JIT_TIME) { + tb->tb_stats->stats_enabled |=3D TB_JIT_TIME; + ti =3D profile_getclock(); + } } else { tb->tb_stats =3D NULL; } @@ -1826,10 +1828,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)) { @@ -1871,9 +1873,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 #ifdef DEBUG_DISAS if (qemu_loglevel_mask(CPU_LOG_TB_OUT_ASM) && diff --git a/configure b/configure index 8f8446f52b..eedeb9016e 100755 --- a/configure +++ b/configure @@ -6566,9 +6566,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 d2c61ff155..3c4bce0e56 100644 --- a/cpus.c +++ b/cpus.c @@ -1442,21 +1442,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 c779d6a183..a142972960 100644 --- a/include/exec/tb-stats.h +++ b/include/exec/tb-stats.h @@ -90,10 +90,24 @@ struct TBStatistics { * this TBStats structure. Has to be reset on a tb_flush. */ GPtrArray *tbs; + + /* end of jit_stats_lock */ + + /* These are accessed with atomic operations */ + struct { + int64_t restore; + uint64_t restore_count; + int64_t interm; + int64_t code; + int64_t opt; + int64_t la; + } time; }; =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); @@ -101,6 +115,7 @@ void dump_jit_profile_info(TCGProfile *s); #define TB_NOTHING (1 << 0) #define TB_EXEC_STATS (1 << 1) #define TB_JIT_STATS (1 << 2) +#define TB_JIT_TIME (1 << 3) =20 void enable_collect_tb_stats(void); void disable_collect_tb_stats(void); 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 9c199c8a40..e1438fa0d9 100644 --- a/tcg/tcg.c +++ b/tcg/tcg.c @@ -3881,82 +3881,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]); @@ -3966,19 +3918,6 @@ 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) { @@ -4020,18 +3959,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); @@ -4054,9 +3993,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) @@ -4081,14 +4020,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: @@ -4181,14 +4123,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 5296f7c075..6dcbbf79e7 100644 --- a/tcg/tcg.h +++ b/tcg/tcg.h @@ -948,7 +948,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 002bf4919e..f91bc6fb4c 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.20.1 From nobody Wed May 1 22:06:27 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=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1570463343; cv=none; d=zoho.com; s=zohoarc; b=cfrGCj1bs6BdbS+mWxMEtKbuGSZv2HGZzoVoqmfuZ0X+bFfgbWXhNBuuYen5iRGixG35NkpCvY41nddLSAjzswg7bNifjJeRgpNG1HCv6dN6oMcKyXvfVdYKL7yXy7/NPNiX1XG8LYYwCImhavPmYjdIkOSu7++rXvfplK/mlns= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1570463343; 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=mxx40Q+nCYSDb7wZipkn3exesX1aGd6/ZVPDy+DAdhc=; b=UHmH6FO7n33e+PEBn/VzMOGvwsh6AEpLPsAAL+xPW5zGGKfFUGUpv89RXU5xZnDw0ZwjnDWvwJrihJ2rLPvtOJ9jN0Gbwl6dcIw26jjMK53doluaJ1z35CgixUo6LsOvoeSc4wI9N2BaLZqxqOlb6dxyObwL08gnp8SA9EWUFEk= 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 1570463342951323.66609707964665; Mon, 7 Oct 2019 08:49:02 -0700 (PDT) Received: from localhost ([::1]:46434 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iHVFm-00013g-Ul for importer@patchew.org; Mon, 07 Oct 2019 11:48:54 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:48887) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iHUwJ-0002ZL-UV for qemu-devel@nongnu.org; Mon, 07 Oct 2019 11:28:50 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iHUwH-0005AD-QT for qemu-devel@nongnu.org; Mon, 07 Oct 2019 11:28:47 -0400 Received: from mail-wr1-x441.google.com ([2a00:1450:4864:20::441]:36826) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1iHUwH-00059b-G9 for qemu-devel@nongnu.org; Mon, 07 Oct 2019 11:28:45 -0400 Received: by mail-wr1-x441.google.com with SMTP id y19so15859169wrd.3 for ; Mon, 07 Oct 2019 08:28:45 -0700 (PDT) Received: from zen.linaroharston ([51.148.130.216]) by smtp.gmail.com with ESMTPSA id g3sm31784713wro.14.2019.10.07.08.28.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Oct 2019 08:28:42 -0700 (PDT) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id E14831FF93; Mon, 7 Oct 2019 16:28:39 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=mxx40Q+nCYSDb7wZipkn3exesX1aGd6/ZVPDy+DAdhc=; b=UIL9b2NL23s2SNI+9tz9L7GbgG8Tf57fUBIlyg9q8/sN1e17PYGIFRXU3Am+8vdaVA dzI+THAdNO1PQT3m3kbgUcirkxrW4oP6gddgGAPDkAGmQMHxUbgZc+u97YI+mOjRJayY EHpDJd7tvzcN52b2bwLGOKmZAJf54vq4QLMPAkZFRpIqlOK9DmIbdjA7xZdwToGIGG2P 1ZeRyyp2PyeyNCMA65MF3xypgpnbdxfcpTbGBMrrKk2xBI7v1XWotmGXiTBmch+K3/2Q kVh0EsfH3Y41lXI8LvDw+7ocmX+1bCNl+pDsF/pMcjgECHFT+pui+j4SF6+WnK0ihM85 H33w== 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=mxx40Q+nCYSDb7wZipkn3exesX1aGd6/ZVPDy+DAdhc=; b=tmI3RthN4UYrRuFlkXA75yUvs24xoJ9CT/TuxDbLx9WVok7mKSXqKWtRCR50v2SgJS /Nq/4z3+vH8MZip56FCS8VcZhvKKft7POXrVUBbshPwtb8HT+8G1ej1zZy3Jga5vhvj9 L578JsBs3LoApNAJtcOSbo8P7vHi9yDJ2n+YAxfCv2hjvmHIw5C8jMN2HryEeN3wt5Nm IXrGBkEhOKLzVSiRnySKsCNV8OWCwZviEMvLqv6Ao6c/ATIoKZd5c0BZ1nPaOvVdJgY0 IB2iADvATzMaSEmzjVW++PU81bs0fyuvV8VqwYAZFjml0XB0tgTrdO/VlG0gS4UGpRsy +OKw== X-Gm-Message-State: APjAAAXB58xOKli9+XD8JuaudFlDAlHSreT8Hz5gn59wEL+46DlkyPji FyrfuSD3RLSf5q+QS4nb4Kx34g== X-Google-Smtp-Source: APXvYqzzaGvaMvbqwwj5Em+RQAET0e/tscyC7haADc1Xef+KnexOaAHF8N6qHTZaOv/m/ONk3idE6A== X-Received: by 2002:adf:f7c3:: with SMTP id a3mr10423057wrq.275.1570462124367; Mon, 07 Oct 2019 08:28:44 -0700 (PDT) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: qemu-devel@nongnu.org Subject: [PATCH v9 06/13] debug: add -d tb_stats to control TBStatistics collection: Date: Mon, 7 Oct 2019 16:28:32 +0100 Message-Id: <20191007152839.30804-7-alex.bennee@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191007152839.30804-1-alex.bennee@linaro.org> References: <20191007152839.30804-1-alex.bennee@linaro.org> 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: 2a00:1450:4864:20::441 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?= , cota@braap.org, "Vanderson M. do Rosario" , Paolo Bonzini , Richard Henderson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) From: "Vanderson M. do Rosario" -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 Message-Id: <20190829173437.5926-7-vandersonmr2@gmail.com> [AJB: fix authorship, reword title] Signed-off-by: Alex Benn=C3=A9e --- AJB: - reword title - add stubs for enabling - move things across to tb-stats-flags.h --- accel/tcg/tb-stats.c | 5 +++++ include/exec/gen-icount.h | 1 + include/exec/tb-stats-flags.h | 29 +++++++++++++++++++++++++++++ include/exec/tb-stats.h | 16 +++------------- include/qemu/log.h | 1 + stubs/Makefile.objs | 1 + stubs/tb-stats.c | 27 +++++++++++++++++++++++++++ util/log.c | 35 +++++++++++++++++++++++++++++++++++ 8 files changed, 102 insertions(+), 13 deletions(-) create mode 100644 include/exec/tb-stats-flags.h create mode 100644 stubs/tb-stats.c diff --git a/accel/tcg/tb-stats.c b/accel/tcg/tb-stats.c index f431159fd2..1c66e03979 100644 --- a/accel/tcg/tb-stats.c +++ b/accel/tcg/tb-stats.c @@ -193,3 +193,8 @@ uint32_t get_default_tbstats_flag(void) { return default_tbstats_flag; } + +void set_default_tbstats_flag(uint32_t flags) +{ + default_tbstats_flag =3D flags; +} 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..8455073048 --- /dev/null +++ b/include/exec/tb-stats-flags.h @@ -0,0 +1,29 @@ +/* + * QEMU System Emulator, Code Quality Monitor System + * + * We define the flags and control bits here to avoid complications of + * including TCG/CPU information in common code. + * + * Copyright (c) 2019 Vanderson M. do Rosario + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ +#ifndef TB_STATS_FLAGS +#define TB_STATS_FLAGS + +#define TB_NOTHING (1 << 0) +#define TB_EXEC_STATS (1 << 1) +#define TB_JIT_STATS (1 << 2) +#define TB_JIT_TIME (1 << 3) + +/* TBStatistic collection controls */ +void enable_collect_tb_stats(void); +void disable_collect_tb_stats(void); +void pause_collect_tb_stats(void); +bool tb_stats_collection_enabled(void); +bool tb_stats_collection_paused(void); + +uint32_t get_default_tbstats_flag(void); +void set_default_tbstats_flag(uint32_t); + +#endif diff --git a/include/exec/tb-stats.h b/include/exec/tb-stats.h index a142972960..019d316f5c 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 @@ -108,21 +110,9 @@ 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 -#define TB_NOTHING (1 << 0) -#define TB_EXEC_STATS (1 << 1) -#define TB_JIT_STATS (1 << 2) -#define TB_JIT_TIME (1 << 3) - -void enable_collect_tb_stats(void); -void disable_collect_tb_stats(void); -void pause_collect_tb_stats(void); -bool tb_stats_collection_enabled(void); -bool tb_stats_collection_paused(void); - -uint32_t get_default_tbstats_flag(void); - #endif diff --git a/include/qemu/log.h b/include/qemu/log.h index b097a6cae1..a8d1997cde 100644 --- a/include/qemu/log.h +++ b/include/qemu/log.h @@ -45,6 +45,7 @@ static inline bool qemu_log_separate(void) /* LOG_TRACE (1 << 15) is defined in log-for-trace.h */ #define CPU_LOG_TB_OP_IND (1 << 16) #define CPU_LOG_TB_FPU (1 << 17) +#define CPU_LOG_TB_STATS (1 << 18) =20 /* Lock output for a series of related logs. Since this is not needed * for a single qemu_log / qemu_log_mask / qemu_log_mask_and_addr, we diff --git a/stubs/Makefile.objs b/stubs/Makefile.objs index 9c7393b08c..1c5cd05147 100644 --- a/stubs/Makefile.objs +++ b/stubs/Makefile.objs @@ -41,3 +41,4 @@ stub-obj-y +=3D ram-block.o stub-obj-y +=3D ramfb.o stub-obj-y +=3D fw_cfg.o stub-obj-$(CONFIG_SOFTMMU) +=3D semihost.o +stub-obj-$(CONFIG_TCG) +=3D tb-stats.o diff --git a/stubs/tb-stats.c b/stubs/tb-stats.c new file mode 100644 index 0000000000..d212c2a1fa --- /dev/null +++ b/stubs/tb-stats.c @@ -0,0 +1,27 @@ +/* + * TB Stats Stubs + * + * Copyright (c) 2019 + * Written by Alex Benn=C3=A9e + * + * This code is licensed under the GNU GPL v2, or later. + */ + + +#include "qemu/osdep.h" +#include "exec/tb-stats-flags.h" + +void enable_collect_tb_stats(void) +{ + return; +} + +bool tb_stats_collection_enabled(void) +{ + return false; +} + +void set_default_tbstats_flag(uint32_t flags) +{ + return; +} diff --git a/util/log.c b/util/log.c index 1d1b33f7d9..86bd691967 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 /* Return the number of characters emitted. */ int qemu_log(const char *fmt, ...) @@ -273,6 +276,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 @@ -294,6 +300,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; + set_default_tbstats_flag(TB_JIT_STATS | TB_EXEC_STATS | TB_JIT= _TIME); + enable_collect_tb_stats(); + } else if (tb_stats_collection_enabled() && + g_str_has_prefix(*tmp, "dump_limit=3D")) { + max_num_hot_tbs_to_dump =3D atoi((*tmp) + 11); + } else if (tb_stats_collection_enabled() && + g_str_has_prefix(*tmp, "level=3D")) { + uint32_t flags =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")) { + flags |=3D TB_JIT_STATS; + } else if (g_str_equal(*level_tmp, "exec")) { + flags |=3D TB_EXEC_STATS; + } else if (g_str_equal(*level_tmp, "time")) { + flags |=3D TB_JIT_TIME; + } else if (g_str_equal(*level_tmp, "all")) { + flags |=3D TB_JIT_STATS | TB_EXEC_STATS | TB_JIT_TIME; + } else { + /* FIXME: set errp */ + fprintf(stderr, "no option level=3D%s, valid options a= re:" + "all, jit, exec or/and time\n", *level_tmp); + exit(1); + } + set_default_tbstats_flag(flags); + } } else { for (item =3D qemu_log_items; item->mask !=3D 0; item++) { if (g_str_equal(*tmp, item->name)) { --=20 2.20.1 From nobody Wed May 1 22:06:27 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=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1570462899; cv=none; d=zoho.com; s=zohoarc; b=VmWDmd3Vkog1wHrc+BOx5S09Adh55TIwl424V6nolJYErZH5SXaCLCpq+eXDtiAlnE92ytQoXUqz4KqiBTOwIDRBUncLR/3RJCTF0PvgjnZOeN49YtInn19EQmKjhXlNYf7/8p1XzCAAaf3rgE/LGagdgflb3RowOiffhL6zNY0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1570462899; 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=CZflwldCN50YlIobs9aZPRkYZvox2aKMETtZiJDlL04=; b=XFFkeFpDxaA7H6x98Yz9whn5JLBJjtlC/QCB966pln5hpou75lj+WRPwWT5t41Cz54SJ/eNOb7zx5RBBO8a/es65N/ETkM2CTNxyLp28nJT3m2KP+VvLSESfkdWAdziTW1ZQg6uk8abW3pU8gMQ1myeelkJ5H0y97gRXsTD86XE= 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 1570462899326317.80992959031937; Mon, 7 Oct 2019 08:41:39 -0700 (PDT) Received: from localhost ([::1]:46340 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iHV8f-0004Mg-Uo for importer@patchew.org; Mon, 07 Oct 2019 11:41:33 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:48914) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iHUwL-0002bb-IE for qemu-devel@nongnu.org; Mon, 07 Oct 2019 11:28:51 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iHUwJ-0005Ax-9h for qemu-devel@nongnu.org; Mon, 07 Oct 2019 11:28:49 -0400 Received: from mail-wr1-x441.google.com ([2a00:1450:4864:20::441]:46902) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1iHUwJ-0005AX-26 for qemu-devel@nongnu.org; Mon, 07 Oct 2019 11:28:47 -0400 Received: by mail-wr1-x441.google.com with SMTP id o18so15792748wrv.13 for ; Mon, 07 Oct 2019 08:28:46 -0700 (PDT) Received: from zen.linaroharston ([51.148.130.216]) by smtp.gmail.com with ESMTPSA id a14sm15301444wmm.44.2019.10.07.08.28.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Oct 2019 08:28:42 -0700 (PDT) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id 0CA6C1FF96; Mon, 7 Oct 2019 16:28:40 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=CZflwldCN50YlIobs9aZPRkYZvox2aKMETtZiJDlL04=; b=Jh6uQSbPiW9SkfOV7aWHBCqRVLBjouaO2LvT2ceUjv8vNEhYteiEwrPaUJepb+3iYV qcm4UAl6I3xVRDO8dArXqvvlL5jXbpmJQFd46BbVKin6RkKXHwn+/4BQbwwEuJjq/Jf0 QiLpVy4o7c3a72/anHsM9aoP2rADBcFtwkIQctnndm15OoIhE3i8kxMTziMeF6MDiqOZ P429D8MP5ydXqPHPKm3AVeICIkJ9oI2zSTXHzKqBrbfpq+0279SArQ4u0Ffnmmd988lD uFkrvbaGzIKhn0GvHI/c2ZnuNQngMDT6EgH/mQqYu4xNU/xA8iLhizNFmw7z4S6KV3wM 5YSQ== 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=CZflwldCN50YlIobs9aZPRkYZvox2aKMETtZiJDlL04=; b=Qsz98eO57OhOEsjASGXJYa6vds9lVCnlpgWQEaOCe/1Ib5u+1MypfSv73gNORbsuvf b5sbQg9yzR62o0aWhKlkSpGRtYk6rWmqF+mFHUqdddfW4sInX0vnTpKDuT9dlMDoZvDs TBGoYjO4uigEw3zgURCFO4alOSCVgR2mdf9RqTERsLhYGlQffd97yHv4ToCtbcVdb2GD wX7ZFqie5uPYc2c4kmNp0E1/CKn8rS2z2gUt11zXDvqcDqmn8CCzuYWC5w8BFATPlir+ 1/MCHcdAJ3uHzOKPEpw+/9sSIgGvum1uxhoBeYB7i9NHbfOYKQDCjlYvKEH/UOtv97Sr pYQA== X-Gm-Message-State: APjAAAWKnKX0Tpq88J6ONRlnU55PRF75sCmAVJ3B5kQZQeJfvj0fsi4F Ja6mmz7ccF+dB5avcNEOHhNebA== X-Google-Smtp-Source: APXvYqxNY/xuntEy/GM7jl7DphQPBsJisAWe5L9KBc66XLwP7QQHCSvLhdCZs9PSJPnJuSkBxBzCvQ== X-Received: by 2002:adf:e588:: with SMTP id l8mr8571883wrm.290.1570462125933; Mon, 07 Oct 2019 08:28:45 -0700 (PDT) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: qemu-devel@nongnu.org Subject: [PATCH v9 07/13] monitor: adding tb_stats hmp command Date: Mon, 7 Oct 2019 16:28:33 +0100 Message-Id: <20191007152839.30804-8-alex.bennee@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191007152839.30804-1-alex.bennee@linaro.org> References: <20191007152839.30804-1-alex.bennee@linaro.org> 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: 2a00:1450:4864:20::441 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: "Vanderson M. do Rosario" , "Dr . David Alan Gilbert" , Markus Armbruster , cota@braap.org, Paolo Bonzini , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Richard Henderson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) From: "Vanderson M. do Rosario" 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 Message-Id: <20190829173437.5926-8-vandersonmr2@gmail.com> [AJB: fix authorship] Signed-off-by: Alex Benn=C3=A9e monitor: add 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 Message-Id: <20190829173437.5926-9-vandersonmr2@gmail.com> [AJB: fix authorship] Signed-off-by: Alex Benn=C3=A9e --- accel/tcg/tb-stats.c | 105 ++++++++++++++++++++++++++++++++++ hmp-commands.hx | 17 ++++++ include/exec/tb-stats-flags.h | 1 + include/exec/tb-stats.h | 10 ++++ monitor/misc.c | 49 ++++++++++++++++ vl.c | 6 ++ 6 files changed, 188 insertions(+) diff --git a/accel/tcg/tb-stats.c b/accel/tcg/tb-stats.c index 1c66e03979..dabc5150f9 100644 --- a/accel/tcg/tb-stats.c +++ b/accel/tcg/tb-stats.c @@ -26,6 +26,8 @@ enum TBStatsStatus { =20 static enum TBStatsStatus tcg_collect_tb_stats; static uint32_t default_tbstats_flag; +/* only accessed in safe work */ +static GList *last_search; =20 uint64_t dev_time; =20 @@ -155,6 +157,96 @@ void dump_jit_profile_info(TCGProfile *s) g_free(jpi); } =20 +static void free_tbstats(void *p, uint32_t hash, void *userp) +{ + g_free(p); +} + +static void clean_tbstats(void) +{ + /* remove all tb_stats */ + qht_iter(&tb_ctx.tb_stats, free_tbstats, NULL); + qht_destroy(&tb_ctx.tb_stats); +} + +void do_hmp_tbstats_safe(CPUState *cpu, run_on_cpu_data icmd) +{ + struct TbstatsCommand *cmdinfo =3D icmd.host_ptr; + int cmd =3D cmdinfo->cmd; + uint32_t level =3D cmdinfo->level; + + switch (cmd) { + case START: + if (tb_stats_collection_paused()) { + set_tbstats_flags(level); + } else { + if (tb_stats_collection_enabled()) { + qemu_printf("TB information already being recorded"); + return; + } + qht_init(&tb_ctx.tb_stats, tb_stats_cmp, CODE_GEN_HTABLE_SIZE, + QHT_MODE_AUTO_RESIZE); + } + + set_default_tbstats_flag(level); + enable_collect_tb_stats(); + tb_flush(cpu); + break; + case PAUSE: + if (!tb_stats_collection_enabled()) { + qemu_printf("TB information not being recorded"); + return; + } + + /* Continue to create TBStatistic structures but stop collecting s= tatistics */ + pause_collect_tb_stats(); + set_default_tbstats_flag(TB_NOTHING); + set_tbstats_flags(TB_PAUSED); + tb_flush(cpu); + break; + case STOP: + if (!tb_stats_collection_enabled()) { + qemu_printf("TB information not being recorded"); + return; + } + + /* Dissalloc all TBStatistics structures and stop creating new one= s */ + disable_collect_tb_stats(); + clean_tbstats(); + tb_flush(cpu); + break; + case FILTER: + if (!tb_stats_collection_enabled()) { + qemu_printf("TB information not being recorded"); + return; + } + if (!last_search) { + qemu_printf("no search on record! execute info tbs before filt= ering!"); + return; + } + + set_default_tbstats_flag(TB_NOTHING); + + /* Set all tbstats as paused, then return only the ones from last_= search */ + pause_collect_tb_stats(); + set_tbstats_flags(TB_PAUSED); + + for (GList *iter =3D last_search; iter; iter =3D g_list_next(iter)= ) { + TBStatistics *tbs =3D iter->data; + tbs->stats_enabled =3D level; + } + + tb_flush(cpu); + + break; + default: /* INVALID */ + g_assert_not_reached(); + break; + } + + g_free(cmdinfo); +} + void init_tb_stats_htable_if_not(void) { if (tb_stats_collection_enabled() && !tb_ctx.tb_stats.map) { @@ -189,6 +281,19 @@ 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_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 8455073048..252304d685 100644 --- a/include/exec/tb-stats-flags.h +++ b/include/exec/tb-stats-flags.h @@ -15,6 +15,7 @@ #define TB_EXEC_STATS (1 << 1) #define TB_JIT_STATS (1 << 2) #define TB_JIT_TIME (1 << 3) +#define TB_PAUSED (1 << 4) =20 /* TBStatistic collection controls */ void enable_collect_tb_stats(void); diff --git a/include/exec/tb-stats.h b/include/exec/tb-stats.h index 019d316f5c..921da38c97 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 @@ -115,4 +118,11 @@ 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); + #endif diff --git a/monitor/misc.c b/monitor/misc.c index ac4ff58d96..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" @@ -459,6 +461,49 @@ static void hmp_info_registers(Monitor *mon, const QDi= ct *qdict) } =20 #ifdef CONFIG_TCG +static void hmp_tbstats(Monitor *mon, const QDict *qdict) +{ + if (!tcg_enabled()) { + error_report("TB information is only available with accel=3Dtcg"); + return; + } + + char *cmd =3D (char *) qdict_get_try_str(qdict, "command"); + enum TbstatsCmd icmd =3D -1; + + if (strcmp(cmd, "start") =3D=3D 0) { + icmd =3D START; + } else if (strcmp(cmd, "pause") =3D=3D 0) { + icmd =3D PAUSE; + } else if (strcmp(cmd, "stop") =3D=3D 0) { + icmd =3D STOP; + } else if (strcmp(cmd, "filter") =3D=3D 0) { + icmd =3D FILTER; + } else { + error_report("invalid command!"); + return; + } + + char *slevel =3D (char *) qdict_get_try_str(qdict, "level"); + uint32_t level =3D TB_EXEC_STATS | TB_JIT_STATS | TB_JIT_TIME; + if (slevel) { + if (strcmp(slevel, "jit") =3D=3D 0) { + level =3D TB_JIT_STATS; + } else if (strcmp(slevel, "exec") =3D=3D 0) { + level =3D TB_EXEC_STATS; + } else if (strcmp(slevel, "time") =3D=3D 0) { + level =3D TB_JIT_TIME; + } + } + + struct TbstatsCommand *tbscommand =3D g_new0(struct TbstatsCommand, 1); + tbscommand->cmd =3D icmd; + tbscommand->level =3D level; + async_safe_run_on_cpu(first_cpu, do_hmp_tbstats_safe, + RUN_ON_CPU_HOST_PTR(tbscommand)); + +} + static void hmp_info_jit(Monitor *mon, const QDict *qdict) { if (!tcg_enabled()) { @@ -1089,8 +1134,12 @@ static void hmp_info_mtree(Monitor *mon, const QDict= *qdict) =20 static void hmp_info_profile(Monitor *mon, const QDict *qdict) { +#ifdef CONFIG_TCG dump_jit_exec_time_info(dev_time); dev_time =3D 0; +#else + error_report("TCG should be enabled!"); +#endif } =20 /* Capture support */ diff --git a/vl.c b/vl.c index f91bc6fb4c..781fddaf18 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.20.1 From nobody Wed May 1 22:06:27 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=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1570463527; cv=none; d=zoho.com; s=zohoarc; b=Rj3jBgDMPCrUzbppyBicjzvs/M2GZsHCEA+8c6TDn+jAIjQhNAGtCv3A1vEUBMwD/5TlCu6uIxaWznu/bJyPZqHhg+3oIzCi7PsXFjYNyYOGBo5ltRB8NfL061/HngNIGvQ16+CwefiLibdfS46KtasfrEO4pBRBwXqIqeWdc+0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1570463527; 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=hggjK8Ae7uaAUz2uVJWEK720XDx0HS+iysTy3zwJ5bU=; b=V0hKL1Yd7kSjhi9WwbLz6+29nwZpvcad+/mvCSSnG1D6K68HvsiIQdLowO2lS3vDNrAewKOQVNYqQucd450XVC9UVwNS4+gsy+CylLJN93OzSREArpiUdhsA/QE9xAOTp9+ObcLSm1FoFYaqF17FwSqcKeyUkvIkl+5/FngzGv0= 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 1570463527502534.9838606484743; Mon, 7 Oct 2019 08:52:07 -0700 (PDT) Received: from localhost ([::1]:46508 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iHVIs-0004Yc-1N for importer@patchew.org; Mon, 07 Oct 2019 11:52:06 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:48913) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iHUwL-0002bT-G8 for qemu-devel@nongnu.org; Mon, 07 Oct 2019 11:28:50 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iHUwJ-0005BF-QH for qemu-devel@nongnu.org; Mon, 07 Oct 2019 11:28:49 -0400 Received: from mail-wm1-x341.google.com ([2a00:1450:4864:20::341]:39100) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1iHUwJ-0005An-IS for qemu-devel@nongnu.org; Mon, 07 Oct 2019 11:28:47 -0400 Received: by mail-wm1-x341.google.com with SMTP id v17so12819265wml.4 for ; Mon, 07 Oct 2019 08:28:47 -0700 (PDT) Received: from zen.linaroharston ([51.148.130.216]) by smtp.gmail.com with ESMTPSA id y13sm21402104wrg.8.2019.10.07.08.28.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Oct 2019 08:28:42 -0700 (PDT) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id 23B8E1FF98; Mon, 7 Oct 2019 16:28:40 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=hggjK8Ae7uaAUz2uVJWEK720XDx0HS+iysTy3zwJ5bU=; b=MWLw29C5a2/tlUtOGDP/AnatDJmaxu0PByRmZLHFIsv+fah23hB3Q2g8z4cbTD/LpR BftdHZtbtz0OvC+5HOdflMFx5fn8Va8EgNyFEkiot5GoQdnbh8oKYTEbrwGB9lIfW7wl g0mOQerJ/niZ585wyebpDqijrjySlMafW/wsv9iruG8kpIyHV7tYD16RnUkTSRJbYFb2 CBcJ9t+4+QSM91Pr+Z42ztrGeOVGirFNyk5WtK9wIpgasjTVUKbiLPkdwSSF3+3+B11b UZqxQaZGKtJv9HtIazpiKLkoMiMBnrQX1DD1kcRAvDoCE2rwYmbucOSNqwSN0FdbTd4w 5N9A== 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=hggjK8Ae7uaAUz2uVJWEK720XDx0HS+iysTy3zwJ5bU=; b=JO8eJPixliPUkg05AWCmWZHgOzEpVmvR7JgVUBt4j4Iy83Uh3XMHPKrYG74mySmhq7 jyPJ+VQ4DuAYAIlzecNRQHA71S48lo6IY7k3Tz04IFSFvpQiaU+8OR83jnYYPhKv9nQR yNFg1KXceOU3el+6gWbR3rHROeKhcGKcCugMvNPx3pCfTsspREPqmDLrul7Q/EZEhON4 3riBfHllr8oOrq2zoNS8srwBJq/9HeJvX20PPKL7nmG3a4/fmA9ssnAqpB21o631Vp90 4CAdZco1U/vjVlRlw6MQ+4Gy5i9fvDB+HeFJ595JYe7L2AhbYhQaa5MaVATFxvheAxi1 iLdg== X-Gm-Message-State: APjAAAUX1+zLSQNlE5qJjYmnfweCPX74lYdOljyhp2AI6x0gUuNWu+UZ 5gjtM3XGb4AdTcJm14h+RgpgGQ== X-Google-Smtp-Source: APXvYqz4zPDjbhCqy5hBdXcWCGhQ9m9CvQOX8K050s4Gh2Eyw2G+jazsFdpmxZpuT/UinBaR68omwA== X-Received: by 2002:a1c:a404:: with SMTP id n4mr17163987wme.137.1570462126494; Mon, 07 Oct 2019 08:28:46 -0700 (PDT) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: qemu-devel@nongnu.org Subject: [PATCH v9 08/13] tb-stats: reset the tracked TBs on a tb_flush Date: Mon, 7 Oct 2019 16:28:34 +0100 Message-Id: <20191007152839.30804-9-alex.bennee@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191007152839.30804-1-alex.bennee@linaro.org> References: <20191007152839.30804-1-alex.bennee@linaro.org> 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: 2a00:1450:4864:20::341 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 , cota@braap.org, =?UTF-8?q?Alex=20Benn=C3=A9e?= , 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 keep track of translations but can only do so up until the translation cache is flushed. At that point we really have no idea if we can re-create a translation because all the active tracking information has been reset. Signed-off-by: Alex Benn=C3=A9e Reviewed-by: Richard Henderson --- accel/tcg/tb-stats.c | 19 +++++++++++++++++++ accel/tcg/translate-all.c | 2 +- include/exec/tb-stats.h | 8 ++++++++ 3 files changed, 28 insertions(+), 1 deletion(-) diff --git a/accel/tcg/tb-stats.c b/accel/tcg/tb-stats.c index dabc5150f9..f08e5f2540 100644 --- a/accel/tcg/tb-stats.c +++ b/accel/tcg/tb-stats.c @@ -247,6 +247,25 @@ void do_hmp_tbstats_safe(CPUState *cpu, run_on_cpu_dat= a icmd) g_free(cmdinfo); } =20 +/* + * We have to reset the tbs array on a tb_flush as those + * TranslationBlocks no longer exist and we no loner know if the + * current mapping is still valid. + */ + +static void reset_tbs_array(void *p, uint32_t hash, void *userp) +{ + TBStatistics *tbs =3D p; + g_ptr_array_set_size(tbs->tbs, 0); +} + +void tbstats_reset_tbs(void) +{ + if (tb_ctx.tb_stats.map) { + qht_iter(&tb_ctx.tb_stats, reset_tbs_array, NULL); + } +} + 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 396e63c3e7..871d91d559 100644 --- a/accel/tcg/translate-all.c +++ b/accel/tcg/translate-all.c @@ -1273,7 +1273,7 @@ static void do_tb_flush(CPUState *cpu, run_on_cpu_dat= a tb_flush_count) =20 qht_reset_size(&tb_ctx.htable, CODE_GEN_HTABLE_SIZE); page_flush_tb(); - + tbstats_reset_tbs(); tcg_region_reset_all(); /* XXX: flush processor icache at this point if cache flush is expensive */ diff --git a/include/exec/tb-stats.h b/include/exec/tb-stats.h index 921da38c97..c20a3e6439 100644 --- a/include/exec/tb-stats.h +++ b/include/exec/tb-stats.h @@ -125,4 +125,12 @@ struct TbstatsCommand { =20 void do_hmp_tbstats_safe(CPUState *cpu, run_on_cpu_data icmd); =20 +/** + * tbstats_reset_tbs: reset the linked array of TBs + * + * Reset the list of tbs for a given array. Should be called from + * safe work during tb_flush. + */ +void tbstats_reset_tbs(void); + #endif --=20 2.20.1 From nobody Wed May 1 22:06:27 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=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1570463240; cv=none; d=zoho.com; s=zohoarc; b=belge9up8GA1dXLFyB+99ozboQmBWmJk+/Ollb5roXUXfvJKMN/5JxLxoFDTZeQas+iPfU4sc8H8AgZD14MaaLKn3hB7oLtg4I3Qzl/cZpx01LMeyC1lQsZtlKpQ5RrmZllyeqYTDeO/rWGQNYuRyMQcHJtb/awirU9FbukaBiI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1570463240; 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=/O/UgEaGYt9Y+FF6QjgMS4U3ASkLFc3mv9nkgvjFUmw=; b=Kg9Mcb2FYW+GKjI7bmeFmAmcS5ORKJlA3wsGhM6xCEWU7jZinubbOuvYgeVjfsC3KFpYrVe5wKB++P6QPWClJRS8f/ptaor//koHXAvXP0l9g8ITFuyzTJIN3U5PGxOR+//ZJ647i7IVeagOR23fS3fad9Q7TSbml1j7tcSp4pk= 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 1570463240179226.63176951931484; Mon, 7 Oct 2019 08:47:20 -0700 (PDT) Received: from localhost ([::1]:46424 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iHVED-0000C5-Hc for importer@patchew.org; Mon, 07 Oct 2019 11:47:17 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:48959) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iHUwO-0002fb-L9 for qemu-devel@nongnu.org; Mon, 07 Oct 2019 11:28:55 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iHUwK-0005Bu-W9 for qemu-devel@nongnu.org; Mon, 07 Oct 2019 11:28:52 -0400 Received: from mail-wr1-x442.google.com ([2a00:1450:4864:20::442]:41834) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1iHUwK-0005BR-Kx for qemu-devel@nongnu.org; Mon, 07 Oct 2019 11:28:48 -0400 Received: by mail-wr1-x442.google.com with SMTP id q9so15849282wrm.8 for ; Mon, 07 Oct 2019 08:28:48 -0700 (PDT) Received: from zen.linaroharston ([51.148.130.216]) by smtp.gmail.com with ESMTPSA id h7sm15903821wrs.15.2019.10.07.08.28.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Oct 2019 08:28:42 -0700 (PDT) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id 446851FF99; Mon, 7 Oct 2019 16:28:40 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=/O/UgEaGYt9Y+FF6QjgMS4U3ASkLFc3mv9nkgvjFUmw=; b=y4V6Nh2dh9EpjX9c0cOKA47/Aq3gSleHgua35/dIfu1Fi0pctZdZqFnDjpM7YtE7Tz KZ1LoUZfEZ1buhLxfpZa10ZYGcr0xEjEQTMm71DjOg88V9G/R/5X8Q01EGZ6/ZDfXKoS lNXdyNd7xcEeAAr/91XtP6gJ0E0mYn10Y2Q59L7QQPr5cQBEK2ata0LmIJFNTUjE1Eg9 mn1p4lJ688G1oqjZmeBV8ipNluK/Jg5Y1picBK0M5ifN5jVcvOWYE/OYzZ9c+F3BXWxi 0mk92cggqkOBCVwHcZP4ZY6T9Cm8yig5II3ve1t633SRQgzTfTNm/J+SJF4yvIX2aGH4 Xgkw== 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=/O/UgEaGYt9Y+FF6QjgMS4U3ASkLFc3mv9nkgvjFUmw=; b=dzdA6/9CnttPfARw/fyQNBQks5Ac2HcmRM76lij7hS0RHZhsnLqSKKIMDcyCs3cncu BTonyCbuuj7oDTscv/BuzEgqpI6eZL7WuNFv5ifyRbzSD7P+Wxz39nptllyIrirgo+UD t4kMuhbraiy35+O0/CMnnbKVO9sxlaljdVceQJpGZvjIqFVG523myh5dxqJ1XxppdBIp pTMmcWf8CBk7yOy69QC0fWnga2etxvQDNxq2/0uA8aEXAgE36tUdOtF1oWl+LDh/fMDA WtU43TDNENTMap+cUFkyHnkjJlIthkIKQlvP/vqKCHSSN2L7/xb4f1PdSCbkGiAaTNTQ pIEA== X-Gm-Message-State: APjAAAWIiJJweQQVsnm3ydqusX/NkfZ39Gw70AvAreX4Bt+7mKGFkaIW bLwMuemGK3Xeb68z8fwsEMXxfQ== X-Google-Smtp-Source: APXvYqzgTqpxdRILjFSJKmJJv6+1bTCyKA696snsS0YUCzwGe4rEPVh8hPSR07yTtejwV852aaehyg== X-Received: by 2002:a05:6000:108c:: with SMTP id y12mr21928439wrw.238.1570462127138; Mon, 07 Oct 2019 08:28:47 -0700 (PDT) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: qemu-devel@nongnu.org Subject: [PATCH v9 09/13] Adding info [tb-list|tb] commands to HMP (WIP) Date: Mon, 7 Oct 2019 16:28:35 +0100 Message-Id: <20191007152839.30804-10-alex.bennee@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191007152839.30804-1-alex.bennee@linaro.org> References: <20191007152839.30804-1-alex.bennee@linaro.org> 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: 2a00:1450:4864:20::442 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: "Vanderson M. do Rosario" , "Dr . David Alan Gilbert" , Markus Armbruster , cota@braap.org, Paolo Bonzini , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Richard Henderson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) From: "Vanderson M. do Rosario" These commands allow the exploration of TBs generated by the TCG. Understand which one hotter, with more guest/host instructions... and examine 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. [AJB: WIP - we still can't be safely sure a translation will succeed] 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 Message-Id: <20190829173437.5926-10-vandersonmr2@gmail.com> [AJB: fix authorship, dropped coverset] Signed-off-by: Alex Benn=C3=A9e --- AJB - dropped coverset for now - check tbs list for valid translations - document the valid but unreachable TLB case --- accel/tcg/tb-stats.c | 319 ++++++++++++++++++++++++++++++++++- disas.c | 31 +++- hmp-commands-info.hx | 16 ++ include/exec/tb-stats.h | 33 +++- include/qemu/log-for-trace.h | 4 + include/qemu/log.h | 2 + monitor/misc.c | 52 ++++++ util/log.c | 54 ++++-- 8 files changed, 491 insertions(+), 20 deletions(-) diff --git a/accel/tcg/tb-stats.c b/accel/tcg/tb-stats.c index f08e5f2540..3c1cc8cd06 100644 --- a/accel/tcg/tb-stats.c +++ b/accel/tcg/tb-stats.c @@ -28,9 +28,23 @@ static enum TBStatsStatus tcg_collect_tb_stats; static uint32_t default_tbstats_flag; /* only accessed in safe work */ static GList *last_search; - +static 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; +} + struct jit_profile_info { uint64_t translations; uint64_t aborted; @@ -274,6 +288,309 @@ 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 count_invalid_tbs(gpointer data, gpointer user_data) +{ + TranslationBlock *tb =3D (TranslationBlock *) data; + unsigned *counter =3D (unsigned *) user_data; + if (tb->cflags & CF_INVALID) { + *counter =3D *counter + 1; + } +} + +static int 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); + unsigned act =3D tbs->tbs->len; + unsigned invalid =3D 0; + + float guest_host_prop =3D g ? ((float) h / g) : 0; + + g_ptr_array_foreach(tbs->tbs, &count_invalid_tbs, &invalid); + + qemu_log("TB id:%d | phys:0x"TB_PAGE_ADDR_FMT" virt:0x"TARGET_FMT_lx + " flags:%#08x %d inv/%d\n", + tbs->display_id, tbs->phys_pc, tbs->pc, tbs->flags, + invalid, act); + + 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); + } + + qemu_log("\n"); + + return act - invalid; +} + +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_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); +} + +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_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); + } +} + +/* + * We cannot always re-generate the code even if we know there are + * valid translations still in the cache. The reason being the guest + * may have un-mapped the page code. In real life this would be + * un-reachable as the jump cache is cleared and the following QHT + * lookup will do a get_page_addr_code() and fault. + * + * TODO: can we do this safely? We need to + * a) somehow recover the mmu_idx for this translation + * b) probe MMU_INST_FETCH to know it will succeed + */ +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. + */ + qemu_log("\ncould not gen code for this TB (no longer mapped?)\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) +{ + g_autoptr(GString) code_s =3D NULL; + + qemu_log("\n------------------------------\n\n"); + + if (dump_tb_header(tbs) > 0) { + code_s =3D get_code_string(tbs, log_flags); + } else { + code_s =3D g_string_new("cannot re-translate non-active translatio= n"); + } + qemu_log("%s", code_s->str); + 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/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 257ee7d7a3..c8418211d9 100644 --- a/hmp-commands-info.hx +++ b/hmp-commands-info.hx @@ -289,6 +289,22 @@ 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, + }, #endif =20 STEXI diff --git a/include/exec/tb-stats.h b/include/exec/tb-stats.h index c20a3e6439..b5e9c54b33 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) @@ -65,6 +68,8 @@ struct TBStatistics { struct { unsigned long normal; unsigned long atomic; + /* filled only when dumping x% cover set */ + uint16_t coverage; } executions; =20 /* JIT Stats - protected by lock */ @@ -86,7 +91,6 @@ struct TBStatistics { =20 struct { unsigned long total; - unsigned long uncached; unsigned long spanning; } translations; =20 @@ -107,6 +111,9 @@ struct TBStatistics { int64_t opt; int64_t la; } time; + + /* HMP information - used for referring to previous search */ + int display_id; }; =20 bool tb_stats_cmp(const void *ap, const void *bp); @@ -133,4 +140,26 @@ void do_hmp_tbstats_safe(CPUState *cpu, run_on_cpu_dat= a icmd); */ void tbstats_reset_tbs(void); =20 +/** + * 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); + #endif 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..af09a97085 100644 --- a/monitor/misc.c +++ b/monitor/misc.c @@ -504,6 +504,58 @@ 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_jit(Monitor *mon, const QDict *qdict) { if (!tcg_enabled()) { diff --git a/util/log.c b/util/log.c index 86bd691967..fa78e2bca9 100644 --- a/util/log.c +++ b/util/log.c @@ -33,25 +33,55 @@ 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 -/* 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 */ @@ -300,6 +330,7 @@ int qemu_str_to_log_mask(const char *str) trace_enable_events((*tmp) + 6); mask |=3D LOG_TRACE; #endif +#ifdef CONFIG_TCG } else if (g_str_has_prefix(*tmp, "tb_stats")) { mask |=3D CPU_LOG_TB_STATS; set_default_tbstats_flag(TB_JIT_STATS | TB_EXEC_STATS | TB_JIT= _TIME); @@ -329,6 +360,7 @@ int qemu_str_to_log_mask(const char *str) } set_default_tbstats_flag(flags); } +#endif } else { for (item =3D qemu_log_items; item->mask !=3D 0; item++) { if (g_str_equal(*tmp, item->name)) { --=20 2.20.1 From nobody Wed May 1 22:06:27 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=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1570462627; cv=none; d=zoho.com; s=zohoarc; b=R7Imyocd7jxqvgnBut3cwwHeX54DMREfjhpUIOXW9ED+6+Q9UkrI8FGH78CyAi35+uhsvb+ibIwZyawhMLbAJ3QkDAwEjYtWKwxUkbD7M8H8iHkx1QDIAId7rkIDTYxUlxwBKEPpk2AJzFNe/90oOaFhZDId/K/TKzNBiYPUHyc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1570462627; 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=7gCV4zFcfwB/MqyFrxlDjzbDS1zMRutLLkzPj4QW9Yk=; b=eBffCRDGScR0KhfgJsnXn6JQItnfXn4txHDUsVAYCPtfqdDF1s7fJdpRJYj8qIf22MF2+GACwfsNO+KPdwTbDxhYfCv9LlXNzB5ygKTbKGCZdmgz/DbssgyMvaDsy4Mn6aRBQJX4ebgHFPUYysdaGLQTi7Q8MFjZJ3y9Kt0+r30= 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 1570462627617911.9178353230944; Mon, 7 Oct 2019 08:37:07 -0700 (PDT) Received: from localhost ([::1]:46278 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iHV4L-0000IM-Oa for importer@patchew.org; Mon, 07 Oct 2019 11:37:05 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:48939) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iHUwN-0002dd-Id for qemu-devel@nongnu.org; Mon, 07 Oct 2019 11:28:53 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iHUwL-0005CA-8b for qemu-devel@nongnu.org; Mon, 07 Oct 2019 11:28:51 -0400 Received: from mail-wr1-x443.google.com ([2a00:1450:4864:20::443]:41996) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1iHUwK-0005Bc-VM for qemu-devel@nongnu.org; Mon, 07 Oct 2019 11:28:49 -0400 Received: by mail-wr1-x443.google.com with SMTP id n14so15801927wrw.9 for ; Mon, 07 Oct 2019 08:28:48 -0700 (PDT) Received: from zen.linaroharston ([51.148.130.216]) by smtp.gmail.com with ESMTPSA id 207sm21693651wme.17.2019.10.07.08.28.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Oct 2019 08:28:42 -0700 (PDT) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id 64F731FF9A; Mon, 7 Oct 2019 16:28:40 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=7gCV4zFcfwB/MqyFrxlDjzbDS1zMRutLLkzPj4QW9Yk=; b=IeovF85JWo8oxbPzCVzRpSEbLanGm4HKDdhNpt0WT4SqJtnnEVhnx28G+vo6fto/T+ 3yCJxBM6VcRPMa2M2zu1GMDqbm/l31qkQYgVujlZyaUtwSXw1M/vXaagriucXfin2TS7 FInyMJUXKTO6f2rTfmaJXFTPrPuEyiL+Y28tUcRg4Q9BBActsHDZXVFfEWYrA889ncoM 7TTsD4G7S8VYpnVGpz/43Gpw1Fhe/y90p8EwVAh3pr/lcGECZe2oIkMMnzuuevbwPgZw xm9iiLVVWD4+jTQ4GQRKvuE/EoAf1FXNdblmLsAyOpo9V/BaHgT6c7K5pNZO7cPaAD03 VOaw== 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=7gCV4zFcfwB/MqyFrxlDjzbDS1zMRutLLkzPj4QW9Yk=; b=tGvF+ZZ+Xzx1gdsgYmtuysUP3pRR0TMafw+P3K2077N8stezm1kZpZwH8e2JdR1qgW TXIj3J4C76Iy2ceC7OCwjEkl8/3WDjUjxEgy9+fDX76kR9JfIrodXi0qw55kL1wIdJp9 5jW7MdK8X+Bmy5+3gM39Ag4Ips4Mvtqr8I1CSktPzDEh+Uxv6Km8HTwhC7KnwYzvnApP n5xftYBqYMeddOyD1Rzr73HUdds3QC+2vvqf1OAc+Rz6uy18O4yiqW2yNiZAREDB9zlf rMY2F8hPAAB1zT+55Kald3lXg44h/XPibE0S/kWOfXK4DnTglqP7c8LHoYGJ56Nplp40 RSnA== X-Gm-Message-State: APjAAAXZOus+s3JuLTJzzQc0e5CwqQX/hFXveb8d4FHHG+opwQHa60Nc T9bCBekUecInjCP4EC7QwaNzyA== X-Google-Smtp-Source: APXvYqyTLkdYcHSmztmzAOfAANnuxIAAt+AnxDeFfBzFrVrBhJSb41bUTDwVSi65hh9gMMLQFGszIA== X-Received: by 2002:adf:f950:: with SMTP id q16mr8124174wrr.225.1570462127811; Mon, 07 Oct 2019 08:28:47 -0700 (PDT) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: qemu-devel@nongnu.org Subject: [PATCH v9 10/13] tb-stats: dump hot TBs at the end of the execution Date: Mon, 7 Oct 2019 16:28:36 +0100 Message-Id: <20191007152839.30804-11-alex.bennee@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191007152839.30804-1-alex.bennee@linaro.org> References: <20191007152839.30804-1-alex.bennee@linaro.org> 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: 2a00:1450:4864:20::443 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: "Vanderson M. do Rosario" , Riku Voipio , Laurent Vivier , cota@braap.org, Paolo Bonzini , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Richard Henderson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) From: "Vanderson M. do Rosario" Dump the hottest TBs if -d tb_stats,dump_limit=3DN 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 Message-Id: <20190829173437.5926-12-vandersonmr2@gmail.com> [AJB: fix authorship, ad softmmu support] Signed-off-by: Alex Benn=C3=A9e --- AJB: - move vars into tb_stats.c - support softmmu as well --- accel/tcg/tb-stats.c | 21 +++++++++++++++++++++ include/exec/tb-stats-dump.h | 21 +++++++++++++++++++++ include/exec/tb-stats-flags.h | 1 + linux-user/exit.c | 2 ++ stubs/tb-stats.c | 5 +++++ util/log.c | 4 ++-- vl.c | 2 ++ 7 files changed, 54 insertions(+), 2 deletions(-) create mode 100644 include/exec/tb-stats-dump.h diff --git a/accel/tcg/tb-stats.c b/accel/tcg/tb-stats.c index 3c1cc8cd06..60a9ee4b9c 100644 --- a/accel/tcg/tb-stats.c +++ b/accel/tcg/tb-stats.c @@ -15,6 +15,7 @@ #include "qemu/qemu-print.h" =20 #include "exec/tb-stats.h" +#include "exec/tb-stats-dump.h" =20 /* TBStatistic collection controls */ enum TBStatsStatus { @@ -26,6 +27,7 @@ enum TBStatsStatus { =20 static enum TBStatsStatus tcg_collect_tb_stats; static uint32_t default_tbstats_flag; +static int max_dump_tbs; /* only accessed in safe work */ static GList *last_search; static int id =3D 1; /* display_id increment counter */ @@ -591,6 +593,20 @@ void dump_tb_info(int id, int log_mask, bool use_monit= or) } =20 =20 +/* + * Dump the final stats + */ +void tb_stats_dump(void) +{ + if (!tb_stats_collection_enabled()) { + return; + } + + dump_tbs_info(max_dump_tbs, SORT_BY_HOTNESS, false); +} + +/* TBStatistic collection controls */ + void enable_collect_tb_stats(void) { init_tb_stats_htable_if_not(); @@ -639,3 +655,8 @@ void set_default_tbstats_flag(uint32_t flags) { default_tbstats_flag =3D flags; } + +void set_tbstats_max_tbs(int max) +{ + max_dump_tbs =3D max; +} diff --git a/include/exec/tb-stats-dump.h b/include/exec/tb-stats-dump.h new file mode 100644 index 0000000000..197c6148e9 --- /dev/null +++ b/include/exec/tb-stats-dump.h @@ -0,0 +1,21 @@ +/* + * TB Stats common dump functions across sysemu/linux-user + * + * Copyright (c) 2019 Linaro + * + * SPDX-License-Identifier: GPL-3.0-or-later + */ + +#ifndef _TB_STATS_DUMP_H_ +#define _TB_STATS_DUMP_H_ + +/** + * tb_stats_dump: dump final tb_stats at end of execution + */ +#ifdef CONFIG_TCG +void tb_stats_dump(void); +#else +static inline void tb_stats_dump(void) { /* do nothing */ }; +#endif + +#endif /* _TB_STATS_DUMP_H_ */ diff --git a/include/exec/tb-stats-flags.h b/include/exec/tb-stats-flags.h index 252304d685..a5bf44f824 100644 --- a/include/exec/tb-stats-flags.h +++ b/include/exec/tb-stats-flags.h @@ -24,6 +24,7 @@ void pause_collect_tb_stats(void); bool tb_stats_collection_enabled(void); bool tb_stats_collection_paused(void); =20 +void set_tbstats_max_tbs(int max); uint32_t get_default_tbstats_flag(void); void set_default_tbstats_flag(uint32_t); =20 diff --git a/linux-user/exit.c b/linux-user/exit.c index bdda720553..c00700bb96 100644 --- a/linux-user/exit.c +++ b/linux-user/exit.c @@ -21,6 +21,7 @@ #ifdef TARGET_GPROF #include #endif +#include "exec/tb-stats-dump.h" =20 #ifdef CONFIG_GCOV extern void __gcov_dump(void); @@ -35,4 +36,5 @@ void preexit_cleanup(CPUArchState *env, int code) __gcov_dump(); #endif gdb_exit(env, code); + tb_stats_dump(); } diff --git a/stubs/tb-stats.c b/stubs/tb-stats.c index d212c2a1fa..a3e1406b88 100644 --- a/stubs/tb-stats.c +++ b/stubs/tb-stats.c @@ -21,6 +21,11 @@ bool tb_stats_collection_enabled(void) return false; } =20 +void set_tbstats_max_tbs(int max) +{ + return; +} + void set_default_tbstats_flag(uint32_t flags) { return; diff --git a/util/log.c b/util/log.c index fa78e2bca9..b6e4f71c1f 100644 --- a/util/log.c +++ b/util/log.c @@ -32,7 +32,6 @@ FILE *qemu_logfile; 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 @@ -337,7 +336,8 @@ int qemu_str_to_log_mask(const char *str) enable_collect_tb_stats(); } else if (tb_stats_collection_enabled() && g_str_has_prefix(*tmp, "dump_limit=3D")) { - max_num_hot_tbs_to_dump =3D atoi((*tmp) + 11); + int hot_tbs =3D atoi((*tmp) + 11); + set_tbstats_max_tbs(hot_tbs); } else if (tb_stats_collection_enabled() && g_str_has_prefix(*tmp, "level=3D")) { uint32_t flags =3D 0; diff --git a/vl.c b/vl.c index 781fddaf18..9ceb401007 100644 --- a/vl.c +++ b/vl.c @@ -35,6 +35,7 @@ #include "sysemu/runstate.h" #include "sysemu/seccomp.h" #include "sysemu/tcg.h" +#include "exec/tb-stats-dump.h" =20 #ifdef CONFIG_SDL #if defined(__APPLE__) || defined(main) @@ -4514,6 +4515,7 @@ int main(int argc, char **argv, char **envp) /* No more vcpu or device emulation activity beyond this point */ vm_shutdown(); =20 + tb_stats_dump(); job_cancel_sync_all(); bdrv_close_all(); =20 --=20 2.20.1 From nobody Wed May 1 22:06:27 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=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1570463226; cv=none; d=zoho.com; s=zohoarc; b=ojF7Kqa1vPyHlnpnIt/MD/NVOMcMQCUTRsRvrHi80MXK3iBSxS62MX4wkGu1p8FCg+R28Z7D6JCmwb92uT6KluFKHiJYTCDpxR0+4DgWeGO3cKSWNyKDyDQchcxg4YTP7a8R6/cztSCiHIq60836t8hIs377lAPd0ZyhM4QDqTA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1570463226; 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=T4HMZgJ1Rxlmg8Ern4sSS2h2E1T91khiCacVECvr12c=; b=JImipvhFW/ItTjkY6iIKGYovuy6kjWGTGg+m5wFfv8rvN0xQf6uubmYwnMccnqtS4n9wNm26M/PgwBB1VrSYoZXGh+wcQ9olNJoiOEMmI3pWOeZF5fzhcjx9z6jVZdcHP5WtjDrUtT6XRXjXzYGCJ/h69hPlGU1Yip0iYK7/j6o= 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 1570463226004592.0519303173716; Mon, 7 Oct 2019 08:47:06 -0700 (PDT) Received: from localhost ([::1]:46416 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iHVDw-0008CW-Sa for importer@patchew.org; Mon, 07 Oct 2019 11:47:00 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:48979) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iHUwP-0002hB-UW for qemu-devel@nongnu.org; Mon, 07 Oct 2019 11:28:56 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iHUwN-0005D5-AN for qemu-devel@nongnu.org; Mon, 07 Oct 2019 11:28:53 -0400 Received: from mail-wr1-x442.google.com ([2a00:1450:4864:20::442]:40499) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1iHUwN-0005Cf-0m for qemu-devel@nongnu.org; Mon, 07 Oct 2019 11:28:51 -0400 Received: by mail-wr1-x442.google.com with SMTP id h4so7115109wrv.7 for ; Mon, 07 Oct 2019 08:28:50 -0700 (PDT) Received: from zen.linaroharston ([51.148.130.216]) by smtp.gmail.com with ESMTPSA id t123sm25635432wma.40.2019.10.07.08.28.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Oct 2019 08:28:47 -0700 (PDT) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id 8AA471FF9B; Mon, 7 Oct 2019 16:28:40 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=T4HMZgJ1Rxlmg8Ern4sSS2h2E1T91khiCacVECvr12c=; b=l5wKWy4Ar2iH1p7q8hEe+nyy9Fnlm9r/RPgMLb+BDLiQwJ243rN/rSUWL8sOtyN3eb j4izBQsb2O3YBQq2BI6LeuPJgkaZnKb/ttSD9otLKAerni16RiEJNvWBKCM84bG5uA01 Kt1ZAU/lHtvJ05NwXPxLo+AYo165YWX/O3VlxiOa7E41l529+LHGbW6iHKQWvOrJQVw6 DCefmfBcQw5K+5PZ0NLTVfi3aGJdW8Owk91rdTq8H+Wz3dVmqAD+v89Df+vQAqE/O/zi d84ar9ZNw72LGgCf851XF/Ea6A38ekIZ/ek3Pb3fd2r02LHxmLXtfMtJMJ6BFtghiRKt p/mg== 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=T4HMZgJ1Rxlmg8Ern4sSS2h2E1T91khiCacVECvr12c=; b=WgFJrHfd0HZNdcz2Z55Z/pzUAUL4126pFqLX5EZb71ZKFbvF5wwNNcx8a01AA+j/cY 0OMGiV8TT9uRXSGlEJ2qOATD0EmWD+buGiH5ri0LO1hAeGhBKouKSHkC1SIMqw/ZxQdV TR8tprAIirgzbKzPc03Mi/c9+5RuWFzALgTrn4RGimtxZ7kyJ3ysKStpydm6ofur4wIp lqSfovl7zHJX7P77P+lcAlPrRvq3fLwQaQTqNHMkBS9Zz50v7B3tAkoTUHj7qCA6K+vn xx954pIDyUJvJV8+ShUYPunjKPDFWGkl42Z3Kr0RMMH2jNEXLL2tg55qZc1sdJAVOP+r lqLQ== X-Gm-Message-State: APjAAAV8SasEzBryp3mANkSYf/Cv+FzK+XmcuIvYAvZ9rUyF5mCiU7ut eBAJNk7XAJ9my6SOYWDcVPcO0g== X-Google-Smtp-Source: APXvYqyFDaNCuIQMYkXvBgHoVRzBFjcVeIVJqAMQPv1/EnjNx8xLvc7NDsmW4Mxcm/AO7YeP/p3KzA== X-Received: by 2002:a5d:4f0b:: with SMTP id c11mr22923034wru.63.1570462129758; Mon, 07 Oct 2019 08:28:49 -0700 (PDT) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: qemu-devel@nongnu.org Subject: [PATCH v9 11/13] accel/tcg: adding integration with linux perf Date: Mon, 7 Oct 2019 16:28:37 +0100 Message-Id: <20191007152839.30804-12-alex.bennee@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191007152839.30804-1-alex.bennee@linaro.org> References: <20191007152839.30804-1-alex.bennee@linaro.org> 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: 2a00:1450:4864:20::442 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: "Vanderson M. do Rosario" , Riku Voipio , Laurent Vivier , cota@braap.org, Paolo Bonzini , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Richard Henderson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) From: "Vanderson M. do Rosario" This commit adds support to Linux Perf in order to be able to analyze qemu jitted code and also to able to see the TBs PC in it. When using "-perf" qemu creates a jitdump file in the current working directory. You then integrate the file using perf inject. Example of use: perf record -k 1 qemu-x86_64 -perf ./a.out perf inject -j -i perf.data -o perf.data.jitted perf report -i perf.data.jitted Signed-off-by: Vanderson M. do Rosario Message-Id: <20190830121903.17585-2-vandersonmr2@gmail.com> [AJB: rebase and various fixes] Signed-off-by: Alex Benn=C3=A9e --- AJB: - use get_clock instead of repeating ourselves - add lock for writing to file - use canonical kernel.org links - g_autoptr/g_autofree strings --- accel/tcg/Makefile.objs | 2 +- accel/tcg/perf/Makefile.objs | 1 + accel/tcg/perf/jitdump.c | 194 +++++++++++++++++++++++++++++++++++ accel/tcg/perf/jitdump.h | 36 +++++++ accel/tcg/translate-all.c | 14 +++ docs/devel/tcg.rst | 15 +++ include/qemu-common.h | 3 + linux-user/main.c | 7 ++ os-posix.c | 5 + qemu-options.hx | 11 ++ 10 files changed, 287 insertions(+), 1 deletion(-) create mode 100644 accel/tcg/perf/Makefile.objs create mode 100644 accel/tcg/perf/jitdump.c create mode 100644 accel/tcg/perf/jitdump.h diff --git a/accel/tcg/Makefile.objs b/accel/tcg/Makefile.objs index 49ffe81b5d..6a1ad59199 100644 --- a/accel/tcg/Makefile.objs +++ b/accel/tcg/Makefile.objs @@ -3,6 +3,6 @@ obj-$(CONFIG_SOFTMMU) +=3D cputlb.o obj-y +=3D tcg-runtime.o tcg-runtime-gvec.o obj-y +=3D cpu-exec.o cpu-exec-common.o translate-all.o obj-y +=3D translator.o tb-stats.o - +obj-y +=3D perf/ obj-$(CONFIG_USER_ONLY) +=3D user-exec.o obj-$(call lnot,$(CONFIG_SOFTMMU)) +=3D user-exec-stub.o diff --git a/accel/tcg/perf/Makefile.objs b/accel/tcg/perf/Makefile.objs new file mode 100644 index 0000000000..ca9abb4f48 --- /dev/null +++ b/accel/tcg/perf/Makefile.objs @@ -0,0 +1 @@ +obj-$(CONFIG_LINUX) +=3D jitdump.o diff --git a/accel/tcg/perf/jitdump.c b/accel/tcg/perf/jitdump.c new file mode 100644 index 0000000000..e1d6f2214e --- /dev/null +++ b/accel/tcg/perf/jitdump.c @@ -0,0 +1,194 @@ +/* + * This code implements an interface to create and fill jitdump files. The= se files + * store information used by Linux Perf to enhance the presentation of jit= ted + * code and to allow the disassembly of jitted code. + * + * The jitdump file specification can be found in the Linux Kernel Source = tree: + * tools/perf/Documentation/jitdump-specification.txt + * + * https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/plai= n/tools/perf/Documentation/jitdump-specification.txt + * + * Copyright (c) 2019 Vanderson M. do Rosario + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#include "qemu/osdep.h" + +#include +#include +#include +#include +#include +#include + +#include "disas/disas.h" +#include "jitdump.h" +#include "qemu-common.h" +#include "qemu/timer.h" +#include "exec/tb-stats.h" + +struct jitheader { + uint32_t magic; /* characters "jItD" */ + uint32_t version; /* header version */ + uint32_t total_size;/* total size of header */ + uint32_t elf_mach; /* elf mach target */ + uint32_t pad1; /* reserved */ + uint32_t pid; /* JIT process id */ + uint64_t timestamp; /* timestamp */ + uint64_t flags; /* flags */ +}; + +enum jit_record_type { + JIT_CODE_LOAD =3D 0, + JIT_CODE_MOVE =3D 1, + JIT_CODE_DEBUG_INFO =3D 2, + JIT_CODE_CLOSE =3D 3, + + JIT_CODE_MAX, +}; + +/* record prefix (mandatory in each record) */ +struct jr_prefix { + uint32_t id; + uint32_t total_size; + uint64_t timestamp; +}; + +struct jr_code_load { + struct jr_prefix p; + + uint32_t pid; + uint32_t tid; + uint64_t vma; + uint64_t code_addr; + uint64_t code_size; + uint64_t code_index; +}; + +struct jr_code_close { + struct jr_prefix p; +}; + +struct jr_code_move { + struct jr_prefix p; + + uint32_t pid; + uint32_t tid; + uint64_t vma; + uint64_t old_code_addr; + uint64_t new_code_addr; + uint64_t code_size; + uint64_t code_index; +}; + +FILE *dumpfile; +QemuMutex dumpfile_lock; +void *perf_marker; + +static uint32_t get_e_machine(void) +{ + uint32_t e_machine =3D EM_NONE; + Elf64_Ehdr elf_header; + FILE *exe =3D fopen("/proc/self/exe", "r"); + + if (exe =3D=3D NULL) { + return e_machine; + } + + if (fread(&elf_header, sizeof(Elf64_Ehdr), 1, exe) !=3D 1) { + goto end; + } + + e_machine =3D elf_header.e_machine; + +end: + fclose(exe); + return e_machine; +} + +void start_jitdump_file(void) +{ + g_autofree gchar *dumpfile_name =3D g_strdup_printf("./jit-%d.dump", g= etpid()); + dumpfile =3D fopen(dumpfile_name, "w+"); + + /* 'Perf record' saves mmaped files during the execution of a program = and + * 'perf inject' iterate over them to reconstruct all used/executed bi= nary. + * So, we create a mmap with the path of our jitdump that is processed + * and used by 'perf inject' to reconstruct jitted binaries. + */ + perf_marker =3D mmap(NULL, sysconf(_SC_PAGESIZE), + PROT_READ | PROT_EXEC, + MAP_PRIVATE, + fileno(dumpfile), 0); + + if (perf_marker =3D=3D MAP_FAILED) { + printf("Failed to create mmap marker file for perf %d\n", fileno(d= umpfile)); + fclose(dumpfile); + return; + } + + struct jitheader header; + header.magic =3D 0x4A695444; + header.version =3D 1; + header.elf_mach =3D get_e_machine(); + header.total_size =3D sizeof(struct jitheader); + header.pid =3D getpid(); + header.timestamp =3D get_clock(); + header.flags =3D 0; + + fwrite(&header, header.total_size, 1, dumpfile); + + fflush(dumpfile); + + qemu_mutex_init(&dumpfile_lock); +} + +void append_load_in_jitdump_file(TranslationBlock *tb) +{ + gchar *func_name =3D g_strdup_printf("TB virt:0x"TARGET_FMT_lx, tb->pc= ); + + /* Serialise the writing of the dump file */ + qemu_mutex_lock(&dumpfile_lock); + + struct jr_code_load load_event; + load_event.p.id =3D JIT_CODE_LOAD; + load_event.p.total_size =3D + sizeof(struct jr_code_load) + func_name->len + 1 + tb->tc.size; + load_event.p.timestamp =3D get_clock(); + load_event.pid =3D getpid(); + load_event.tid =3D syscall(SYS_gettid); + load_event.vma =3D tb->pc; + load_event.code_addr =3D (uint64_t) tb->tc.ptr; + load_event.code_size =3D tb->tc.size; + load_event.code_index =3D tb->pc; + + fwrite(&load_event, sizeof(struct jr_code_load), 1, dumpfile); + fwrite(func_name->str, func_name->len + 1, 1, dumpfile); + fwrite(tb->tc.ptr, tb->tc.size, 1, dumpfile); + + g_free(func_name); + fflush(dumpfile); + + qemu_mutex_unlock(&dumpfile_lock); +} + +void close_jitdump_file(void) +{ + fclose(dumpfile); + if (perf_marker !=3D MAP_FAILED) { + munmap(perf_marker, sysconf(_SC_PAGESIZE)); + } +} + +bool is_jitdump_enabled; + +void enable_jitdump(void) +{ + is_jitdump_enabled =3D true; +} + +bool jitdump_enabled(void) +{ + return is_jitdump_enabled; +} diff --git a/accel/tcg/perf/jitdump.h b/accel/tcg/perf/jitdump.h new file mode 100644 index 0000000000..5d6df3ec91 --- /dev/null +++ b/accel/tcg/perf/jitdump.h @@ -0,0 +1,36 @@ +/* + * QEMU Linux Perf Support + * + * Copyright (c) 2019 Vanderson M. do Rosario (vandersonmr2@gmail.com) + * + * 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 JITDUMP_H +#define JITDUMP_H + +#include "exec/exec-all.h" + +void start_jitdump_file(void); + +void append_load_in_jitdump_file(TranslationBlock *tb); +void append_move_in_jitdump_file(TranslationBlock *tb); + +void close_jitdump_file(void); + +#endif diff --git a/accel/tcg/translate-all.c b/accel/tcg/translate-all.c index 871d91d559..3fafb656e7 100644 --- a/accel/tcg/translate-all.c +++ b/accel/tcg/translate-all.c @@ -58,6 +58,10 @@ #include "sysemu/cpus.h" #include "sysemu/tcg.h" =20 +#ifdef __linux__ +#include "perf/jitdump.h" +#endif + /* #define DEBUG_TB_INVALIDATE */ /* #define DEBUG_TB_FLUSH */ /* make various TB consistency checks */ @@ -1167,6 +1171,11 @@ void tcg_exec_init(unsigned long tb_size) cpu_gen_init(); page_init(); tb_htable_init(); +#ifdef __linux__ + if (jitdump_enabled()) { + start_jitdump_file(); + } +#endif code_gen_alloc(tb_size); #if defined(CONFIG_SOFTMMU) /* There's no guest base to take into account, so go ahead and @@ -1978,6 +1987,11 @@ TranslationBlock *tb_gen_code(CPUState *cpu, return existing_tb; } tcg_tb_insert(tb); +#ifdef __linux__ + if (jitdump_enabled()) { + append_load_in_jitdump_file(tb); + } +#endif return tb; } =20 diff --git a/docs/devel/tcg.rst b/docs/devel/tcg.rst index 4956a30a4e..ab5639cf67 100644 --- a/docs/devel/tcg.rst +++ b/docs/devel/tcg.rst @@ -109,3 +109,18 @@ memory areas instead calls out to C code for device em= ulation. Finally, the MMU helps tracking dirty pages and pages pointed to by translation blocks. =20 +Profiling JITted code +--------------------- + +The Linux `perf` tool will treat all JITed code as a single block as +unlike the main code it can't use debug information to link individual +program counter samples with larger functions. To overcome this +limitation you can use the `--perf` option to generate a map file. +This needs to be integrated with the `perf.data` file before the final +report can be viewed. + +.. code:: + + perf record -k 1 $QEMU --perf $REMAINING_ARGS + perf inject -i perf.data -j -o perf.data.jitted + perf report -i perf.data.jitted diff --git a/include/qemu-common.h b/include/qemu-common.h index 8d84db90b0..a16e0e7eb6 100644 --- a/include/qemu-common.h +++ b/include/qemu-common.h @@ -129,4 +129,7 @@ void page_size_init(void); * returned. */ bool dump_in_progress(void); =20 +void enable_jitdump(void); +bool jitdump_enabled(void); + #endif diff --git a/linux-user/main.c b/linux-user/main.c index 560d053f72..18f771c0be 100644 --- a/linux-user/main.c +++ b/linux-user/main.c @@ -377,6 +377,11 @@ static void handle_arg_strace(const char *arg) do_strace =3D 1; } =20 +static void handle_arg_perf(const char *arg) +{ + enable_jitdump(); +} + static void handle_arg_version(const char *arg) { printf("qemu-" TARGET_NAME " version " QEMU_FULL_VERSION @@ -449,6 +454,8 @@ static const struct qemu_argument arg_table[] =3D { "", "Seed for pseudo-random number generator"}, {"trace", "QEMU_TRACE", true, handle_arg_trace, "", "[[enable=3D]][,events=3D][,file=3D]"}, + {"perf", "QEMU_PERF", false, handle_arg_perf, + "", "dump jitdump files to help linux perf JIT code visuali= zation"}, {"version", "QEMU_VERSION", false, handle_arg_version, "", "display version information and exit"}, #if defined(TARGET_XTENSA) diff --git a/os-posix.c b/os-posix.c index 86cffd2c7d..36ea3a08ca 100644 --- a/os-posix.c +++ b/os-posix.c @@ -191,6 +191,11 @@ int os_parse_cmd_args(int index, const char *optarg) case QEMU_OPTION_enablefips: fips_set_state(true); break; +#if defined(CONFIG_TCG) && defined (CLOCK_MONOTONIC) + case QEMU_OPTION_perf: + enable_jitdump(); + break; +#endif #endif default: return -1; diff --git a/qemu-options.hx b/qemu-options.hx index 2a04ca6ac5..2924032c3b 100644 --- a/qemu-options.hx +++ b/qemu-options.hx @@ -4160,6 +4160,17 @@ STEXI Enable FIPS 140-2 compliance mode. ETEXI =20 +#ifdef __linux__ +DEF("perf", 0, QEMU_OPTION_perf, + "-perf dump jitdump files to help linux perf JIT code visualization\n= ", + QEMU_ARCH_ALL) +#endif +STEXI +@item -perf +@findex -perf +Dumps jitdump files to help linux perf JIT code visualization +ETEXI + HXCOMM Deprecated by -accel tcg DEF("no-kvm", 0, QEMU_OPTION_no_kvm, "", QEMU_ARCH_I386) =20 --=20 2.20.1 From nobody Wed May 1 22:06:27 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=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1570462870; cv=none; d=zoho.com; s=zohoarc; b=MeY9hN3h8RfrsJiipwgY0NCPUMmNeUiy8+Gg0fXSeDOuT/xNFrBiDOE/arduE80atsOQ77tZuvfL2xRTXljPP3x0bxNOTS8RIzrZE+EltKeZK7tn04ZwDNJtuYoV5NGo8ZqPrhHfblVx2l95uz2q+oNihuH9MHgg1mo9Ma3mCr0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1570462870; 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=YDBJO83fFMPFHsguCkuLARuLU3nbWbIEfUOqbeuNP6c=; b=giPDT/IWSySny09jGpzwvA1p9eXDJcD+gELoSbrtZMeXEhK73k0k7+nAK3iTMY3wMoC63LwGDVPlzJLSJJfpB27izf6hYcjSXMdbaofiC0l5jONsmSKEV3v5YIDZKfgTAF3Vk/LN39KslCtKOoAjmZR8lRsjk+wTDMo6iEERWRw= 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 157046287010590.69185546820006; Mon, 7 Oct 2019 08:41:10 -0700 (PDT) Received: from localhost ([::1]:46332 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iHV8G-0003vi-9G for importer@patchew.org; Mon, 07 Oct 2019 11:41:08 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:48964) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iHUwP-0002g8-0J for qemu-devel@nongnu.org; Mon, 07 Oct 2019 11:28:54 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iHUwN-0005DJ-Lk for qemu-devel@nongnu.org; Mon, 07 Oct 2019 11:28:52 -0400 Received: from mail-wm1-x331.google.com ([2a00:1450:4864:20::331]:50904) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1iHUwN-0005Cq-EV for qemu-devel@nongnu.org; Mon, 07 Oct 2019 11:28:51 -0400 Received: by mail-wm1-x331.google.com with SMTP id 5so13176013wmg.0 for ; Mon, 07 Oct 2019 08:28:51 -0700 (PDT) Received: from zen.linaroharston ([51.148.130.216]) by smtp.gmail.com with ESMTPSA id r140sm14661979wme.47.2019.10.07.08.28.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Oct 2019 08:28:47 -0700 (PDT) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id 9EEC71FF87; Mon, 7 Oct 2019 16:28:40 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=YDBJO83fFMPFHsguCkuLARuLU3nbWbIEfUOqbeuNP6c=; b=TIGMGrUW9sr9ncmhU4HLzl6a0/7ts2oEV5UuyE2MWL+4XtI7gv7vJcHCcuGtExwHvg lvmXv5G4Gl4XRg+PbNhu5NN7kBGnsEEbBKVMg1+LNnwPZkLK9kR7DDD0ORiZaAQxq7Me R2ERPOsSCb7A6hoslnhWyxlxa+4Ar3Nq54INfJxMcePPvzUGcDWktSxKELdHBdefCvdX Rj/C72DM+nNnlXH0pIUXzWHoHYHjHbl6d1CRskHiXi+Sbi+6e0f3X/qbVAzMsSXMkkK0 EYDBKnzApZ6zcgTH5yXWIIcvxR5L7xj83A7Rgkslv3sDuFcAoKeBkSEGhNTM8wtwMkju j0eA== 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=YDBJO83fFMPFHsguCkuLARuLU3nbWbIEfUOqbeuNP6c=; b=LifjM8YsxkWrEOGczdIBbFfLiXohAmPus8K0kIFbLyWM25mX5rgqAWvBuBnpD5YwaB Scou2J5uIpXFcDQd77CRsUAkaX20MJ7dO79tAObiOceW5St3jBGKHAbq7NuSLWXqvocm 2QGQb+AkjrZc5pt7nCkyOqpoQOQR4fiVf2hpDaPQmygAtJgxEGZYfbcQi3k6NdJwfrjZ GPbZlkWU02gy9JsksWQ0zYKayKeIDiUMvdAxWdbgFIM9aoqPVQ8aH1e0r60Oh/HMIXyh 1rHq/xGWt1qcnalsnGeASX5LqmsbDuwm4QBj1aNqmCiU4KBTYAeAlw3Ma6DxGvPS6vmX Jovg== X-Gm-Message-State: APjAAAWYj+Vg1oon/gd8+4x9mfBCC5v/Cc7fs8zrgA6yWxHRfuzVjYmc vCPe9xCBvCOAq1zLQOW65rcpeQ== X-Google-Smtp-Source: APXvYqyC4tfwDE522+pyTvwHuqGfFMgYbV7fX3Knr53kAlSyKPKsPoXdBl0m+qKza6/OV6EMtJIK4w== X-Received: by 2002:a1c:5fd6:: with SMTP id t205mr20768288wmb.124.1570462130265; Mon, 07 Oct 2019 08:28:50 -0700 (PDT) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: qemu-devel@nongnu.org Subject: [PATCH v9 12/13] tb-stats: adding TBStatistics info into perf dump Date: Mon, 7 Oct 2019 16:28:38 +0100 Message-Id: <20191007152839.30804-13-alex.bennee@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191007152839.30804-1-alex.bennee@linaro.org> References: <20191007152839.30804-1-alex.bennee@linaro.org> 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: 2a00:1450:4864:20::331 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?= , cota@braap.org, "Vanderson M. do Rosario" , Paolo Bonzini , Richard Henderson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) From: "Vanderson M. do Rosario" Adding TBStatistics information to linux perf TB's symbol names. Signed-off-by: Vanderson M. do Rosario Message-Id: <20190830121903.17585-3-vandersonmr2@gmail.com> [AJB: fix authorship, auto-strings] Signed-off-by: Alex Benn=C3=A9e --- AJB: - use g_string and auto free --- accel/tcg/perf/jitdump.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/accel/tcg/perf/jitdump.c b/accel/tcg/perf/jitdump.c index e1d6f2214e..e7b86173e0 100644 --- a/accel/tcg/perf/jitdump.c +++ b/accel/tcg/perf/jitdump.c @@ -146,7 +146,20 @@ void start_jitdump_file(void) =20 void append_load_in_jitdump_file(TranslationBlock *tb) { - gchar *func_name =3D g_strdup_printf("TB virt:0x"TARGET_FMT_lx, tb->pc= ); + g_autoptr(GString) func_name =3D g_string_new("TB virt:"); + + g_string_append_printf(func_name, "0x"TARGET_FMT_lx, tb->pc); + + if (tb->tb_stats) { + TBStatistics *tbs =3D tb->tb_stats; + 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_op= t); + unsigned spills =3D stat_per_translation(tbs, code.spills); + + g_string_append_printf(func_name, " (g:%u op:%u opt:%u spills:%d)", + g, ops, ops_opt, spills); + } =20 /* Serialise the writing of the dump file */ qemu_mutex_lock(&dumpfile_lock); @@ -167,7 +180,6 @@ void append_load_in_jitdump_file(TranslationBlock *tb) fwrite(func_name->str, func_name->len + 1, 1, dumpfile); fwrite(tb->tc.ptr, tb->tc.size, 1, dumpfile); =20 - g_free(func_name); fflush(dumpfile); =20 qemu_mutex_unlock(&dumpfile_lock); --=20 2.20.1 From nobody Wed May 1 22:06:27 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=pass; 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=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1570463404; cv=none; d=zoho.com; s=zohoarc; b=LiHfwmvfb0H+Qcobbn+jc4Pejtzl4foDDgyiPdCVBc0G2lzU4989q80Hs3zAsQBvvMAyhaVlcdiONRkiZSeLFfS7wo5LVWnQzDxLb+wSvN2Cy7t3C2R5bIPvX4fCX/KqeORRO3QIf/gqDWhbZbpofA+wqu74GVsMZPdkMr3T64A= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1570463404; 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=lS//Prbb20uTZPpM5BoU1FCIVJv7TIfQwriRsFwYsbE=; b=IeMidHkuX3YeJBAHvPqykD6d0DgE3b2OytPWfF1QJCB/ywDDoAeYG4nccmgScwVh53H7fJOgAuElN8FRUE5KtibTZ3fZy68CSflQT2euKhTRcY8gGSgqebmBDClt1xz9X70IsZSybdpwDDa7zXacxn4WdHU3acqLwetRHgvOC8w= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=pass; 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=pass 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 1570463404791516.7160380936227; Mon, 7 Oct 2019 08:50:04 -0700 (PDT) Received: from localhost ([::1]:46442 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iHVGn-0001kZ-PO for importer@patchew.org; Mon, 07 Oct 2019 11:49:57 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:48982) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iHUwQ-0002hX-DG for qemu-devel@nongnu.org; Mon, 07 Oct 2019 11:28:55 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iHUwO-0005Dg-It for qemu-devel@nongnu.org; Mon, 07 Oct 2019 11:28:54 -0400 Received: from mail-wr1-x442.google.com ([2a00:1450:4864:20::442]:45038) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1iHUwO-0005DN-CW for qemu-devel@nongnu.org; Mon, 07 Oct 2019 11:28:52 -0400 Received: by mail-wr1-x442.google.com with SMTP id z9so15800534wrl.11 for ; Mon, 07 Oct 2019 08:28:52 -0700 (PDT) Received: from zen.linaroharston ([51.148.130.216]) by smtp.gmail.com with ESMTPSA id w5sm16461634wrs.34.2019.10.07.08.28.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Oct 2019 08:28:48 -0700 (PDT) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id B197A1FF9C; Mon, 7 Oct 2019 16:28:40 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=lS//Prbb20uTZPpM5BoU1FCIVJv7TIfQwriRsFwYsbE=; b=q0q31hCko5BcR1wSoNcIg+oEK5ZdP4by+oAwyhQ1opGwPP+tRPHA/bp50prwOF+XzA LxxzrhX/oscbPobeYONsmDfx0x4jjaDeR2eeL6khvsX5o0ji+/VQomBPbU/NTpiXTdES MmHlPIm9R5bG6oJU3Qp42NAoo+wOBYTJuiZcm8qiM1KjwJLcaIkMlMi/FjzDPl1ZjI48 vBjWI9S/l9F7FwO9a8Dof9lPNbJz1P/kdfUIgeGUIiciq0ZaQpe8LW/pomSMwvXliRxt URFM9Z25VVP4g+6nX503jgVuA28slLaSVHV/ckv7d0n2nH1V0HrD4AJzoDWm7dd4JXXb PKLg== 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=lS//Prbb20uTZPpM5BoU1FCIVJv7TIfQwriRsFwYsbE=; b=LU35IoZKPeSwJDs6rGitLir2U0zW3POasSfCc42I8fkzCUWAjJRqOnM3KT1lhEygRa kYrpgAPSwwCVMVdfS7BqsmZrdvcGyt2pJPIMgPf+2CwlzRRYMG+R0u7UKMgBQeHvxf3E z/LIhNTjxrqvjP3rSaJMp8L2ZjoMvxqfFkjbuLIaVJZLqASfaj9pUv5GZptFP67Ug1yF 1f15gDaCO7yyLQpuA+aSzt+cytz8bocoJ9Fqe2edFx0TCCgxAALLr9KjlzD4CH4puUon PvYA4kOSHsfW230QjUUwf4VLkd2pPSZ9IcOlCtRZUkoqJknakMfA24ShBBBnv6wWdrP0 EG8A== X-Gm-Message-State: APjAAAW/rMXS779+jdAC54GwQF/wz7VNk3435wr4p/1uYI9caBc2PQgN 59wxQL0NUn43S9LGYZMdtlFvmA== X-Google-Smtp-Source: APXvYqwCeLYyFo3D5ZihBHqxy6O+9wto4CWEVlEZrRBLnzNCuwttcRzXAg9sw2gj9PHJ42QbWXKPuw== X-Received: by 2002:a5d:5111:: with SMTP id s17mr21137961wrt.59.1570462131347; Mon, 07 Oct 2019 08:28:51 -0700 (PDT) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: qemu-devel@nongnu.org Subject: [PATCH v9 13/13] configure: remove the final bits of --profiler support Date: Mon, 7 Oct 2019 16:28:39 +0100 Message-Id: <20191007152839.30804-14-alex.bennee@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191007152839.30804-1-alex.bennee@linaro.org> References: <20191007152839.30804-1-alex.bennee@linaro.org> 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: 2a00:1450:4864:20::442 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: cota@braap.org, =?UTF-8?q?Alex=20Benn=C3=A9e?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @linaro.org) Signed-off-by: Alex Benn=C3=A9e --- configure | 5 ----- 1 file changed, 5 deletions(-) diff --git a/configure b/configure index eedeb9016e..dfd0f67170 100755 --- a/configure +++ b/configure @@ -419,7 +419,6 @@ oss_lib=3D"" bsd=3D"no" linux=3D"no" solaris=3D"no" -profiler=3D"no" cocoa=3D"no" softmmu=3D"yes" linux_user=3D"no" @@ -1192,8 +1191,6 @@ for opt do ;; --enable-libnfs) libnfs=3D"yes" ;; - --enable-profiler) profiler=3D"yes" - ;; --disable-cocoa) cocoa=3D"no" ;; --enable-cocoa) @@ -1702,7 +1699,6 @@ Advanced options (experts only): --with-win-sdk=3DSDK-path path to Windows Platform SDK (to build VSS .t= lb) --tls-priority default TLS protocol/cipher priority string --enable-gprof QEMU profiling with gprof - --enable-profiler profiler support --enable-debug-stack-usage track the maximum stack usage of stacks created= by qemu_alloc_stack =20 @@ -6307,7 +6303,6 @@ echo "target list $target_list" echo "gprof enabled $gprof" echo "sparse enabled $sparse" echo "strip binaries $strip_opt" -echo "profiler $profiler" echo "static build $static" if test "$darwin" =3D "yes" ; then echo "Cocoa support $cocoa" --=20 2.20.1