From nobody Tue May 14 10:03:13 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1561355821; cv=none; d=zoho.com; s=zohoarc; b=CCePuf6+oPpuPFKdDx4jHyZG9Y07MClJgY4XIgzDjzpVkM3pFFLm95flv+pJUxj/ZB5Y/v53ukg1pr23Q+V1nPn6ADeLyphagiJ7H9c5qAx5+kCQ9YM345iZTuqoKFBSwkU9kPag5j8RGXCfS7oX3SiUetdoBvP6uOL6yn+rVto= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1561355821; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=BpTIchYsllR1Ah9JBFFUjXd10Do0JEFP6oFAE0/v72Q=; b=FLbttIHScQcKFxB/4XWxcMxjQuQVXAJJ4xdZW+pPccJ3wHKDddgC39qjJodOE++LP20bWa0HOXJgfwKqmU1Ey60p44Ddq5uqAOlPeP88Oyi4JQihBg/fp4ImXNKr8whSDZq1NcXh9Xhvh2Uvtum9Yvs/2FnSr6VQHGVuRqWjcfs= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (209.51.188.17 [209.51.188.17]) by mx.zohomail.com with SMTPS id 1561355821007535.8208574263008; Sun, 23 Jun 2019 22:57:01 -0700 (PDT) Received: from localhost ([::1]:48106 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hfHyG-0001g2-3H for importer@patchew.org; Mon, 24 Jun 2019 01:56:52 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:35106) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hfHxD-0000ej-2g for qemu-devel@nongnu.org; Mon, 24 Jun 2019 01:55:48 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hfHxB-0003tk-Pd for qemu-devel@nongnu.org; Mon, 24 Jun 2019 01:55:47 -0400 Received: from mail-qt1-x841.google.com ([2607:f8b0:4864:20::841]:39879) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hfHxB-0003sT-KD for qemu-devel@nongnu.org; Mon, 24 Jun 2019 01:55:45 -0400 Received: by mail-qt1-x841.google.com with SMTP id i34so13250574qta.6 for ; Sun, 23 Jun 2019 22:55:45 -0700 (PDT) Received: from localhost.localdomain ([2804:7f4:548d:5237:c368:80a0:cb96:64bf]) by smtp.googlemail.com with ESMTPSA id t80sm5154440qka.87.2019.06.23.22.55.42 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Sun, 23 Jun 2019 22:55:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=BpTIchYsllR1Ah9JBFFUjXd10Do0JEFP6oFAE0/v72Q=; b=CyFi7l09n92itBblOOW3IjYwKnPliTj7euOFeCnmARL9SIfMwSFInIm1zS5dHF1Qow dwr1z0j62KNeNhqw7OULDDjICQDZ6z3L0e/T1q0AFWxi6HdVB3pqocmcwzLCx1G7ADkI zIui6cQqOMzJnrhNlyWP+P1vN3P8i+Dro+MrLPTywxe20eRuia0vjHyikKVbl8x/3Ph+ yg6lAX1F1hhMn5hIoROcDMa/gqW8dt6YWh9kLvpvAIeTdwwRybf/9UHIR6w/IdQxoLiB 6bOmw4X1mZL3RrVuQO1Ja/gfgrgMMnjKAfk69slH/zhj0JSMNKNDu3FBd2Nr4LYdlwH/ E8ZA== 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=BpTIchYsllR1Ah9JBFFUjXd10Do0JEFP6oFAE0/v72Q=; b=mVO7FiJlKxWv2rQAVRCm2ftYKEs9mvZ5p2fNY6JQyj7WGnzVXtRS6oecteH7HwUzS6 X9Rs7tH4V0btUpitkGykakMF2glLn+sDsGAjYT2qQi4KjVI3TydoFpITxQR+u/PIgAHr feNxnZ9FrxdA7Sz6aHr1vwr0LYHihabrkc8mABGFIsFEY2Z9vvRJesSZVo6K1WZqMm5I r8YlEnf/6gqjOX4FUJfSabq24nZgkugw/oJgZs5FxW0MIXQaxeVCXWbzeNdMEcWVe6uF 2KGiwYa7sXPDHRxxRvGEC7JGiA/Evl+Ka73NVVxu3V5Www90tqoQnDE/2sQWI3NRfVE/ /pAw== X-Gm-Message-State: APjAAAXqFqxCDrfpq52rlui4+LtA8dx0zZP/Wn1IQoxcw1cOasecZuLr Gd8OKWXNr1YLhZ6X3NWvOjeYkpKB X-Google-Smtp-Source: APXvYqzszH1VV7JZ4BaH6rJnwlWHtAEpFz7gnTBvW1GNCtNoRdp/lPe4SsAolKcsQejEdLOQrKoLGA== X-Received: by 2002:a0c:92ab:: with SMTP id b40mr54771803qvb.129.1561355744121; Sun, 23 Jun 2019 22:55:44 -0700 (PDT) From: vandersonmr To: qemu-devel@nongnu.org Date: Mon, 24 Jun 2019 02:54:39 -0300 Message-Id: <20190624055442.2973-2-vandersonmr2@gmail.com> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190624055442.2973-1-vandersonmr2@gmail.com> References: <20190624055442.2973-1-vandersonmr2@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::841 Subject: [Qemu-devel] [PATCH v2 1/4] add and link a statistic struct to TBs X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Paolo Bonzini , vandersonmr , Richard Henderson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" We want to store statistics for each TB even after flushes. We do not want to modify or grow the TB struct. So we create a new struct to contain this statistics and link it to each TB while they are created. Signed-off-by: Vanderson M. do Rosario --- accel/tcg/translate-all.c | 40 +++++++++++++++++++++++++++++++++++++++ include/exec/exec-all.h | 21 ++++++++++++++++++++ include/exec/tb-context.h | 1 + include/qemu/log.h | 1 + 4 files changed, 63 insertions(+) diff --git a/accel/tcg/translate-all.c b/accel/tcg/translate-all.c index 5d1e08b169..f7e99f90e0 100644 --- a/accel/tcg/translate-all.c +++ b/accel/tcg/translate-all.c @@ -1118,6 +1118,18 @@ static inline void code_gen_alloc(size_t tb_size) } } =20 +static gint statistics_cmp(gconstpointer p1, gconstpointer p2)=20 +{ + const TBStatistics *a =3D (TBStatistics *) p1; + const TBStatistics *b =3D (TBStatistics *) p2; + + return (a->pc =3D=3D b->pc &&=20 + a->cs_base =3D=3D b->cs_base && + a->flags =3D=3D b->flags &&=20 + a->page_addr[0] =3D=3D b->page_addr[0] && + a->page_addr[1] =3D=3D b->page_addr[1]) ? 0 : 1;=20 +} + static bool tb_cmp(const void *ap, const void *bp) { const TranslationBlock *a =3D ap; @@ -1586,6 +1598,29 @@ static inline void tb_page_add(PageDesc *p, Translat= ionBlock *tb, #endif } =20 +static void tb_insert_statistics_structure(TranslationBlock *tb) { + TBStatistics *new_stats =3D g_new0(TBStatistics, 1); + new_stats->pc =3D tb->pc; + new_stats->cs_base =3D tb->cs_base; + new_stats->flags =3D tb->flags; + new_stats->page_addr[0] =3D tb->page_addr[0]; + new_stats->page_addr[1] =3D tb->page_addr[1]; + + GList *lookup_result =3D g_list_find_custom(tb_ctx.tb_statistics, new_sta= ts, statistics_cmp); + + if (lookup_result) { + /* If there is already a TBStatistic for this TB from a previous flush + * then just make the new TB point to the older TBStatistic + */ + free(new_stats); + tb->tb_stats =3D lookup_result->data; + } else { + /* If not, then points to the new tb_statistics and add it to the hash */ + tb->tb_stats =3D new_stats; + tb_ctx.tb_statistics =3D g_list_prepend(tb_ctx.tb_statistics, new_sta= ts); + } +} + /* add a new TB and link it to the physical page tables. phys_page2 is * (-1) to indicate that only one page contains the TB. * @@ -1636,6 +1671,11 @@ tb_link_page(TranslationBlock *tb, tb_page_addr_t ph= ys_pc, void *existing_tb =3D NULL; uint32_t h; =20 + if (qemu_loglevel_mask(CPU_LOG_HOT_TBS)) { + /* create and link to its TB a structure to store statistics */ + tb_insert_statistics_structure(tb); + } + /* add in the hash table */ h =3D tb_hash_func(phys_pc, tb->pc, tb->flags, tb->cflags & CF_HAS= H_MASK, tb->trace_vcpu_dstate); diff --git a/include/exec/exec-all.h b/include/exec/exec-all.h index 16034ee651..359100ef3b 100644 --- a/include/exec/exec-all.h +++ b/include/exec/exec-all.h @@ -324,6 +324,24 @@ static inline void tlb_flush_by_mmuidx_all_cpus_synced= (CPUState *cpu, #define CODE_GEN_AVG_BLOCK_SIZE 150 #endif =20 +typedef struct TBStatistics TBStatistics; = = =20 + +/*=20 + * This struct stores statistics such as execution count of the Translatio= nBlocks. + * Each TB has its own TBStatistics. TBStatistics is suppose to live even = after=20 + * flushes. + */ +struct TBStatistics { = = =20 + target_ulong pc; = = =20 + target_ulong cs_base; = = =20 + uint32_t flags; = = =20 + tb_page_addr_t page_addr[2]; = = =20 + + // total number of times that the related TB have being executed = = =20 + uint32_t exec_count; = = =20 + uint32_t exec_count_overflows; = = =20 +}; =20 + /* * Translation Cache-related fields of a TB. * This struct exists just for convenience; we keep track of TB's in a bin= ary @@ -403,6 +421,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..a78ce92e60 100644 --- a/include/exec/tb-context.h +++ b/include/exec/tb-context.h @@ -35,6 +35,7 @@ struct TBContext { =20 /* statistics */ unsigned tb_flush_count; + GList *tb_statistics; }; =20 extern TBContext tb_ctx; diff --git a/include/qemu/log.h b/include/qemu/log.h index b097a6cae1..2fca65dd01 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_HOT_TBS (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 --=20 2.22.0 From nobody Tue May 14 10:03:13 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1561355920; cv=none; d=zoho.com; s=zohoarc; b=OyDC7lcFRh0lvq5o+33iPY6k3HJWKTmdXzE7sFadc9lPbw7STtMqcAC/qWp09tgawzOvgbWkU2kWZ6v1f3BT6UKP/SmMwdqlfTFgCOGUh8uaQar8QRF+oHlTRi0wIiDthGxDaX9Hhbn7ZHFGfyzHXAy3pqHM/z5lEoo3zhhruXE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1561355920; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=KKclqfftacWgzlGnFMXl4z4qxP79Se0Ou3Fh9OifT6E=; b=AuXEBOiuCDNeiZ6DXBC10zF7g1NU+4RYYqrzfa9nTiCaAb20LPD6aXmKMEtFu4LSCxzR34+8kPhM83sFny6sfYjgEDNn4SlKnIqGRRLazk+kXIT4sTnDf05two59YpPCYeYAlZahUnNnQQ9MflLSQbgPZKhXdc2vg7vBdlG84es= 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 1561355920805174.75836899828732; Sun, 23 Jun 2019 22:58:40 -0700 (PDT) Received: from localhost ([::1]:48116 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hfHzz-0003OQ-SB for importer@patchew.org; Mon, 24 Jun 2019 01:58:39 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:35117) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hfHxD-0000ep-W4 for qemu-devel@nongnu.org; Mon, 24 Jun 2019 01:55:48 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hfHxC-0003uo-Un for qemu-devel@nongnu.org; Mon, 24 Jun 2019 01:55:47 -0400 Received: from mail-qt1-x841.google.com ([2607:f8b0:4864:20::841]:45061) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hfHxC-0003uK-Q6 for qemu-devel@nongnu.org; Mon, 24 Jun 2019 01:55:46 -0400 Received: by mail-qt1-x841.google.com with SMTP id j19so13236430qtr.12 for ; Sun, 23 Jun 2019 22:55:46 -0700 (PDT) Received: from localhost.localdomain ([2804:7f4:548d:5237:c368:80a0:cb96:64bf]) by smtp.googlemail.com with ESMTPSA id t80sm5154440qka.87.2019.06.23.22.55.44 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Sun, 23 Jun 2019 22:55:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=KKclqfftacWgzlGnFMXl4z4qxP79Se0Ou3Fh9OifT6E=; b=uMWGhT+aE/c+ayJD89UpvD7tgP/QdDqMMmjIQrhdGpSmnUVOcXNg/P8e45GjnOvluC W3ppZ0AahSXOz/B4gKVHMd4e1HR5H83owkrLdPfRjLkA0uL+0Rmmua1GAmlCk7+sUmQr 9/+PNpAbE1vXubIuCNhrpjy3jTRw7XAfAEmwj89hn/ZvJkGFvQJjs8PI/mSOa+BWHmnd CiDa/S8gLvjmJuKuv11OH/xQua/oC9jSwLxXZLVK5fi85Z23J/p5X0IK4KBWnU99Nlxa sPN8FdZe/8E8UTfTQjmhoqvhZZnu5GRo7ogA2QIUlmJg40f/XMKV6H7OmyY1bc/QP/6t 1rTQ== 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=KKclqfftacWgzlGnFMXl4z4qxP79Se0Ou3Fh9OifT6E=; b=dfKP95HVa/0hO3zNjmWpOdDCVUF6MWrjZn1CUsAvNKBqkzFJnaLedRq6xHIn/4J+iq fB8wYxBtTLwerDlWt59NviUOQsLxbewv/fLMelL0BQzkKOMdvgbX7hO4ts6i3cZzY1oH 4ZrsitIe/dewCuWWjJG7upe8UXssSatPPlpQB7oqC8PKaGYlO2wmp1TxPVwksJQfgvrX ulOXB1+zrbT08HgxBqF5bNxmMlJkZreQu7oX6rHoc+p9PfkRM+UUXH/ayrHbShHj9woe AjMSo+ywE7iWoA94/91WLnWEqWR1J/sqFwBODCguBvBNZKGMFHknqZQj4XGsL3XY5DF6 tAqA== X-Gm-Message-State: APjAAAUk33hVhmLrL0N+PoE/zNl+6Ka6cEMp1E40f+KITrBJMM1eT+8V H/UushHDz1wp87EJ4pQGsbCy/vUq X-Google-Smtp-Source: APXvYqyoQ/fg5+U/T8UVZMR/nq/eABRbME0JiYqKfLQh6tjHM7KGw13kGu85HW1hq4wP38FtTADSdQ== X-Received: by 2002:a0c:8181:: with SMTP id 1mr55261001qvd.59.1561355746137; Sun, 23 Jun 2019 22:55:46 -0700 (PDT) From: vandersonmr To: qemu-devel@nongnu.org Date: Mon, 24 Jun 2019 02:54:40 -0300 Message-Id: <20190624055442.2973-3-vandersonmr2@gmail.com> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190624055442.2973-1-vandersonmr2@gmail.com> References: <20190624055442.2973-1-vandersonmr2@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::841 Subject: [Qemu-devel] [PATCH v2 2/4] Adding an optional tb execution counter. X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Paolo Bonzini , vandersonmr , Richard Henderson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" We collect the number of times each TB is executed and store it in the its TBStatistics. We also count the number of times the execution counter overflows. Signed-off-by: Vanderson M. do Rosario --- accel/tcg/tcg-runtime.c | 10 ++++++++++ accel/tcg/tcg-runtime.h | 2 ++ accel/tcg/translator.c | 1 + include/exec/gen-icount.h | 9 +++++++++ 4 files changed, 22 insertions(+) diff --git a/accel/tcg/tcg-runtime.c b/accel/tcg/tcg-runtime.c index 8a1e408e31..9888a7fce8 100644 --- a/accel/tcg/tcg-runtime.c +++ b/accel/tcg/tcg-runtime.c @@ -167,3 +167,13 @@ void HELPER(exit_atomic)(CPUArchState *env) { cpu_loop_exit_atomic(env_cpu(env), GETPC()); } + +void HELPER(inc_exec_freq)(void *ptr) +{ + TranslationBlock *tb =3D (TranslationBlock*) ptr; + // if overflows, then reset the execution counter and increment the ov= erflow counter + if (atomic_cmpxchg(&tb->tb_stats->exec_count, 0xFFFFFFFF, 0) =3D=3D 0x= FFFFFFFF) { + atomic_inc(&tb->tb_stats->exec_count_overflows); + } + atomic_inc(&tb->tb_stats->exec_count); +} 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/translator.c b/accel/tcg/translator.c index 9226a348a3..cc06070e7e 100644 --- a/accel/tcg/translator.c +++ b/accel/tcg/translator.c @@ -54,6 +54,7 @@ void translator_loop(const TranslatorOps *ops, DisasConte= xtBase *db, gen_tb_start(db->tb); ops->tb_start(db, cpu); tcg_debug_assert(db->is_jmp =3D=3D DISAS_NEXT); /* no early exit */ + gen_tb_exec_count(tb); =20 while (true) { db->num_insns++; diff --git a/include/exec/gen-icount.h b/include/exec/gen-icount.h index f7669b6841..6d38b6e1fb 100644 --- a/include/exec/gen-icount.h +++ b/include/exec/gen-icount.h @@ -7,6 +7,15 @@ =20 static TCGOp *icount_start_insn; =20 +static inline void gen_tb_exec_count(TranslationBlock *tb) +{ + if (qemu_loglevel_mask(CPU_LOG_HOT_TBS)) { + TCGv_ptr tb_ptr =3D tcg_const_ptr(tb); + gen_helper_inc_exec_freq(tb_ptr); + tcg_temp_free_ptr(tb_ptr); + } +} + static inline void gen_tb_start(TranslationBlock *tb) { TCGv_i32 count, imm; --=20 2.22.0 From nobody Tue May 14 10:03:13 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1561355937; cv=none; d=zoho.com; s=zohoarc; b=Crg8gmFSh1zf7hR2hxazZxw/A1ZkcTIwTyHAdSp4h/BUj45aalro0eoIhZXENkFcozqvzu5jNxT22bm41C+lEpU81Z42HG8J/OiXS4+MM1LtG1Y5FCGE3dMBVj16F6puxNz0Ec6spFWn0P2vtXfjlKId7vT1nvNnzPyPygw3ZGs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1561355937; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=lj7QrdjZw8J8skBaTRgg83iCd0ZIi47fBBWlzMh6hoo=; b=oXzfN2Ts06/0GZiHRaXOS4Wvf/W7ULsHfZReXgBukIAuAwDAYN+3IYbxuBkAmU+Iz3uMYI9VLSoukGrxls7RtM5NkW0ZAlLOzBA2rygPjBLwzmIKUw4ZwFDbSpujFybAW7xkh21NOiFlISDL9sMDAu+sGZTjnEY4eT40Br72Txg= 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 1561355937085759.6588277239523; Sun, 23 Jun 2019 22:58:57 -0700 (PDT) Received: from localhost ([::1]:48118 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hfI0G-0003Rh-6C for importer@patchew.org; Mon, 24 Jun 2019 01:58:56 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:35129) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hfHxG-0000gN-5h for qemu-devel@nongnu.org; Mon, 24 Jun 2019 01:55:51 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hfHxF-0003xE-5n for qemu-devel@nongnu.org; Mon, 24 Jun 2019 01:55:50 -0400 Received: from mail-qk1-x741.google.com ([2607:f8b0:4864:20::741]:37898) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hfHxF-0003x4-1q for qemu-devel@nongnu.org; Mon, 24 Jun 2019 01:55:49 -0400 Received: by mail-qk1-x741.google.com with SMTP id a27so8864418qkk.5 for ; Sun, 23 Jun 2019 22:55:49 -0700 (PDT) Received: from localhost.localdomain ([2804:7f4:548d:5237:c368:80a0:cb96:64bf]) by smtp.googlemail.com with ESMTPSA id t80sm5154440qka.87.2019.06.23.22.55.46 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Sun, 23 Jun 2019 22:55:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=lj7QrdjZw8J8skBaTRgg83iCd0ZIi47fBBWlzMh6hoo=; b=HqN/g5VSc1Qut9rTZaKZ+q3YOe26cRbwvPHu3+rl6oOrZv92USCePDZQ33IanSpbm0 LLC78mrUF+97lVX4VyPwSmIT1BaLhMpyd0W0Q1+8hmL7YSHVIxZj+82jJLWHVF1HNOtZ 3h0epNWnyHQpKLt8YHH7h70Hn2/goliAFUA6wwjzl9hGwps2e3Jk4ZZNCJ6vTvI+UPFP u+p0rYroo0RiamxMqVxbCjk4kfd5vxwLNFRhUnOhEtvfyZAOf+/zyJdsQfbYquAltCqI 3DlqMAK+GhcohkHDCOa5wARkF4GPnw5DyS8r6W4utIPVMfo8F1lzabfKaoqz6EY+13t/ T+0g== 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=lj7QrdjZw8J8skBaTRgg83iCd0ZIi47fBBWlzMh6hoo=; b=TyKVSp7ZfgEVCnHTaM4ru1AODoJT8RGGZ6xxs2osgV56/f5ekohQ6cC6JZy2TyMpqA fVCenDBAuOG9oEj8I2S9M35eT8NcdfJDtYbZa5XGEhabtzqwdHL+ggIPC+z/fyEzhuWT M1OgR57fcpD48+XEKrW6lRvgPwyPOe241FgVu9CRrplZudSQ8nug3YFdCxXht4WnQC4n mf692aqVSa3CWB+hEWKT88ZVuHR0kvixb7dultlrZc8h1rPF4qxibD16Vj/UzFgZrRvy VZLEffUTgsQLOhaRSrFblTOkf9qa6q3mVX73OWNEgJHsYQnsFRO+vIrX0y6x32mSCeAl Lr+Q== X-Gm-Message-State: APjAAAUKML/Zjiahk3TgUFq9px7KX2OCAaekRIdRPx+4GmwQ4vKFTHfm 1+8S3u0DS56vcHTE1QXF7+ol3wfE X-Google-Smtp-Source: APXvYqz8upaVh3h091fMXQLCDpAyOnTByG05zGw31YLfNriAKNZPj7QeiQD7QxjIL6qSD4tmcBloeA== X-Received: by 2002:a05:620a:15a5:: with SMTP id f5mr81491822qkk.45.1561355748199; Sun, 23 Jun 2019 22:55:48 -0700 (PDT) From: vandersonmr To: qemu-devel@nongnu.org Date: Mon, 24 Jun 2019 02:54:41 -0300 Message-Id: <20190624055442.2973-4-vandersonmr2@gmail.com> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190624055442.2973-1-vandersonmr2@gmail.com> References: <20190624055442.2973-1-vandersonmr2@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::741 Subject: [Qemu-devel] [PATCH v2 3/4] Introduce dump of hot TBs X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Paolo Bonzini , vandersonmr , Richard Henderson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Adding a function to dump the Nth hottest TBs. The block PC, execution count and ops is dump to the log. Signed-off-by: Vanderson M. do Rosario --- accel/tcg/translate-all.c | 45 +++++++++++++++++++++++++++++++++++++++ include/exec/exec-all.h | 2 ++ 2 files changed, 47 insertions(+) diff --git a/accel/tcg/translate-all.c b/accel/tcg/translate-all.c index f7e99f90e0..c3d9ecb2c4 100644 --- a/accel/tcg/translate-all.c +++ b/accel/tcg/translate-all.c @@ -1240,6 +1240,27 @@ static gboolean tb_host_size_iter(gpointer key, gpoi= nter value, gpointer data) return false; } =20 +static void tb_dump_statistics(TBStatistics *tbs) +{ + uint32_t cflags =3D curr_cflags() | CF_NOCACHE; + int old_log_flags =3D qemu_loglevel; + + qemu_set_log(CPU_LOG_TB_OP_OPT); + + qemu_log("\n------------------------------\n"); + qemu_log("Translation Block PC: \t0x"TARGET_FMT_lx "\n", tbs->pc); + qemu_log("Execution Count: \t%lu\n\n", (uint64_t) (tbs->exec_count + t= bs->exec_count_overflows*0xFFFFFFFF)); + + mmap_lock(); + TranslationBlock *tb =3D tb_gen_code(current_cpu, tbs->pc, tbs->cs_bas= e, tbs->flags, cflags); + tb_phys_invalidate(tb, -1); + mmap_unlock(); + + qemu_set_log(old_log_flags); + + tcg_tb_remove(tb); +} + /* flush all the translation blocks */ static void do_tb_flush(CPUState *cpu, run_on_cpu_data tb_flush_count) { @@ -1276,6 +1297,30 @@ done: mmap_unlock(); } =20 +static gint inverse_sort_tbs(gconstpointer p1, gconstpointer p2)=20 +{ + const TBStatistics *tbs1 =3D (TBStatistics *) p1; + const TBStatistics *tbs2 =3D (TBStatistics *) p2; + uint64_t p1_count =3D (uint64_t) (tbs1->exec_count + tbs1->exec_count_= overflows*0xFFFFFFFF); + uint64_t p2_count =3D (uint64_t) (tbs2->exec_count + tbs2->exec_count_= overflows*0xFFFFFFFF); + + return p1_count < p2_count ? 1 : p1_count =3D=3D p2_count ? 0 : -1; +} + +void tb_dump_exec_freq(uint32_t max_tbs_to_print) +{ + tb_ctx.tb_statistics =3D g_list_sort(tb_ctx.tb_statistics, inverse_sor= t_tbs); + + uint32_t tbs_printed =3D 0; + for (GList *i =3D tb_ctx.tb_statistics; i !=3D NULL; i =3D i->next) { + tbs_printed++; + tb_dump_statistics((TBStatistics *) i->data); + if (max_tbs_to_print !=3D 0 && tbs_printed >=3D max_tbs_to_print) { + break; + } + } +} + void tb_flush(CPUState *cpu) { if (tcg_enabled()) { diff --git a/include/exec/exec-all.h b/include/exec/exec-all.h index 359100ef3b..0547db0271 100644 --- a/include/exec/exec-all.h +++ b/include/exec/exec-all.h @@ -533,4 +533,6 @@ hwaddr memory_region_section_get_iotlb(CPUState *cpu, /* vl.c */ extern int singlestep; =20 +void tb_dump_exec_freq(uint32_t); + #endif --=20 2.22.0 From nobody Tue May 14 10:03:13 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1561356160; cv=none; d=zoho.com; s=zohoarc; b=mWob9mp68w2SdAH4lxdCUnoyy4J42WDiwzTKpVSpaHfM961A4y+qGQ9NkqkInoQgXyX+UZUetffALoWwnalavsY7vNjcU4/oYxB8cEcL0xbykpO9KLtdYoFlMWC3zZ4vEBywfd0afJNtI+q9U5MQDQUYoP9fojXuFn1fCeI0Ksg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1561356160; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=sk8uSCdQ3hpnmo3bU04NmJku/FzpWj9gaS0iIIIjZe8=; b=fPZi4wFeN1ZMXEBHHg9ycnJcs+mId9wFla1eu3KxCOHyJWHJ7DiWIV5DOoshPgKTT/icDvcI0QZXH7iHsFTsOOKQB6O2ESQGYkG78wYF/cOGZBy43n3i3+DOd4MZqSky+Na0258pFVtGqWiHqynnGezJ2K1bmv+wgiVgKpak3lA= 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 1561356160047863.6377901176799; Sun, 23 Jun 2019 23:02:40 -0700 (PDT) Received: from localhost ([::1]:48142 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hfI3W-0005yV-Pp for importer@patchew.org; Mon, 24 Jun 2019 02:02:18 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:35140) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hfHxI-0000jh-01 for qemu-devel@nongnu.org; Mon, 24 Jun 2019 01:55:52 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hfHxH-00040M-1F for qemu-devel@nongnu.org; Mon, 24 Jun 2019 01:55:51 -0400 Received: from mail-qt1-x841.google.com ([2607:f8b0:4864:20::841]:41255) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hfHxG-0003zV-TO for qemu-devel@nongnu.org; Mon, 24 Jun 2019 01:55:50 -0400 Received: by mail-qt1-x841.google.com with SMTP id d17so13222051qtj.8 for ; Sun, 23 Jun 2019 22:55:50 -0700 (PDT) Received: from localhost.localdomain ([2804:7f4:548d:5237:c368:80a0:cb96:64bf]) by smtp.googlemail.com with ESMTPSA id t80sm5154440qka.87.2019.06.23.22.55.48 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Sun, 23 Jun 2019 22:55:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=sk8uSCdQ3hpnmo3bU04NmJku/FzpWj9gaS0iIIIjZe8=; b=bgwUEwz+jk2hAR+SpgR14G2rp6yZetZ3n2wHPX7LJKei0CVC2CjGn5YgzstJNtLagu AMdkFigZ/FvWyJI8IJpaM3FMdNcCFu1FOxndDHdgYzRVrhHFcJpoJQzZhjBSnibIGI6j dEnfmfTxoCUJwys2qUUvdbGJ+fhUlg+/gZDv5y/SZhckQZRf9G6SDD0oT8FFjBOLSZEn v4H2PQBv0KdA13WaIcf0Z55qBaqkl8TLXG8hyIie4kVpVwSoCcq6jgsaMyRN/QJ7ACuW 7Fmji7pRCcN0d9deR0WvS8bPd6oFHt0+68IU5v6yY/WPlIeZYxIiloiIZR/7ujm0sfmn RYmw== 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=sk8uSCdQ3hpnmo3bU04NmJku/FzpWj9gaS0iIIIjZe8=; b=QqVEuBUAG4A8QxENfvAoVm8WryYyeLwD0RLV17oGCFiFzWGTPyZUnJzhZBFK0XheQs WXWOjJI/TaO0JLEg66qgqJQwCxRisTALC/tFWaR3zS6mY4qx9doVsjxPnJ2ysrD6DpKD e6TpIaEzrsIjVdUKc9CHnxNFzsAvaZtOuP0mpbPOP5IjKaFr/7f7V7g9rVVoKMV2CtzP sUoXYhVooBfIWhOOHoeSQsi+ST0LJRVNcJgg4cYn+q5mHJRdWdjLyDWDcK/2o5RJPEPh IaO9C86fd/iXmmKL4ZL1quesVhggzy5JKWsXZIcMPgmkRG7ZsEdn3q9N8QpHDgxR5IoG JTtg== X-Gm-Message-State: APjAAAVj5kBVrWXVU2toHiNyYSyGRmhZEzJXhaJUzO4naY795ZVoiF9a xm4lbd8ejQuykN4BUNXTrHbP8AmfUKs= X-Google-Smtp-Source: APXvYqwfn7KY9bzRr/H8RSQIkhLEhALGt1LNPTy29pzS9uW0mbyynqjl8+hF9QWiZ1WDWZyjG9yPGQ== X-Received: by 2002:aed:24d9:: with SMTP id u25mr130587406qtc.111.1561355750187; Sun, 23 Jun 2019 22:55:50 -0700 (PDT) From: vandersonmr To: qemu-devel@nongnu.org Date: Mon, 24 Jun 2019 02:54:42 -0300 Message-Id: <20190624055442.2973-5-vandersonmr2@gmail.com> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190624055442.2973-1-vandersonmr2@gmail.com> References: <20190624055442.2973-1-vandersonmr2@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::841 Subject: [Qemu-devel] [PATCH v2 4/4] adding -d hot_tbs:limit command line option X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Riku Voipio , vandersonmr , Laurent Vivier Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" add option to dump the N most hot TB blocks. -d hot_tbs:N Signed-off-by: vandersonmr --- include/qemu/log-for-trace.h | 2 ++ linux-user/exit.c | 3 +++ util/log.c | 9 +++++++++ 3 files changed, 14 insertions(+) diff --git a/include/qemu/log-for-trace.h b/include/qemu/log-for-trace.h index 2f0a5b080e..d65eb83037 100644 --- a/include/qemu/log-for-trace.h +++ b/include/qemu/log-for-trace.h @@ -21,6 +21,8 @@ /* Private global variable, don't use */ extern int qemu_loglevel; =20 +extern int32_t max_num_hot_tbs_to_dump; + #define LOG_TRACE (1 << 15) =20 /* Returns true if a bit is set in the current loglevel mask */ diff --git a/linux-user/exit.c b/linux-user/exit.c index bdda720553..08b86dfd61 100644 --- a/linux-user/exit.c +++ b/linux-user/exit.c @@ -28,6 +28,9 @@ extern void __gcov_dump(void); =20 void preexit_cleanup(CPUArchState *env, int code) { + if (qemu_loglevel_mask(CPU_LOG_HOT_TBS)) { + tb_dump_exec_freq(max_num_hot_tbs_to_dump); + } #ifdef TARGET_GPROF _mcleanup(); #endif diff --git a/util/log.c b/util/log.c index 1d1b33f7d9..e71c663143 100644 --- a/util/log.c +++ b/util/log.c @@ -30,6 +30,7 @@ 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 +274,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_HOT_TBS, "hot_tbs(:limit)", + "show TBs (until given a limit) ordered by their hotness.\n" + "(if no limit is given, show all)" }, { 0, NULL, NULL }, }; =20 @@ -294,6 +298,11 @@ 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, "hot_tbs")) { + if (g_str_has_prefix(*tmp, "hot_tbs:") && (*tmp)[8] !=3D '\0')= { + max_num_hot_tbs_to_dump =3D atoi((*tmp) + 8); + } + mask |=3D CPU_LOG_HOT_TBS; } else { for (item =3D qemu_log_items; item->mask !=3D 0; item++) { if (g_str_equal(*tmp, item->name)) { --=20 2.22.0