From patchwork Mon Jun 24 05:54:39 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: vandersonmr X-Patchwork-Id: 11012329 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 432D0112C for ; Mon, 24 Jun 2019 05:56:41 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3374E28B01 for ; Mon, 24 Jun 2019 05:56:41 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2766D28B1E; Mon, 24 Jun 2019 05:56:41 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.0 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id A73E428B01 for ; Mon, 24 Jun 2019 05:56:40 +0000 (UTC) Received: from localhost ([::1]:48106 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hfHy3-0001g2-RZ for patchwork-qemu-devel@patchwork.kernel.org; Mon, 24 Jun 2019 01:56:39 -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) 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) 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) 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 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+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP 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) } } +static gint statistics_cmp(gconstpointer p1, gconstpointer p2) +{ + const TBStatistics *a = (TBStatistics *) p1; + const TBStatistics *b = (TBStatistics *) p2; + + return (a->pc == b->pc && + a->cs_base == b->cs_base && + a->flags == b->flags && + a->page_addr[0] == b->page_addr[0] && + a->page_addr[1] == b->page_addr[1]) ? 0 : 1; +} + static bool tb_cmp(const void *ap, const void *bp) { const TranslationBlock *a = ap; @@ -1586,6 +1598,29 @@ static inline void tb_page_add(PageDesc *p, TranslationBlock *tb, #endif } +static void tb_insert_statistics_structure(TranslationBlock *tb) { + TBStatistics *new_stats = g_new0(TBStatistics, 1); + new_stats->pc = tb->pc; + new_stats->cs_base = tb->cs_base; + new_stats->flags = tb->flags; + new_stats->page_addr[0] = tb->page_addr[0]; + new_stats->page_addr[1] = tb->page_addr[1]; + + GList *lookup_result = g_list_find_custom(tb_ctx.tb_statistics, new_stats, 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 = lookup_result->data; + } else { + /* If not, then points to the new tb_statistics and add it to the hash */ + tb->tb_stats = new_stats; + tb_ctx.tb_statistics = g_list_prepend(tb_ctx.tb_statistics, new_stats); + } +} + /* 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 phys_pc, void *existing_tb = NULL; uint32_t h; + 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 = tb_hash_func(phys_pc, tb->pc, tb->flags, tb->cflags & CF_HASH_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 +typedef struct TBStatistics TBStatistics; + +/* + * This struct stores statistics such as execution count of the TranslationBlocks. + * Each TB has its own TBStatistics. TBStatistics is suppose to live even after + * flushes. + */ +struct TBStatistics { + target_ulong pc; + target_ulong cs_base; + uint32_t flags; + tb_page_addr_t page_addr[2]; + + // total number of times that the related TB have being executed + uint32_t exec_count; + uint32_t exec_count_overflows; +}; + /* * Translation Cache-related fields of a TB. * This struct exists just for convenience; we keep track of TB's in a binary @@ -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; }; 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 { /* statistics */ unsigned tb_flush_count; + GList *tb_statistics; }; 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) /* 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 From patchwork Mon Jun 24 05:54:40 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: vandersonmr X-Patchwork-Id: 11012331 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 2D23A13AF for ; Mon, 24 Jun 2019 05:58:09 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1B17528B01 for ; Mon, 24 Jun 2019 05:58:09 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0E9DB28B1E; Mon, 24 Jun 2019 05:58:09 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.0 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id A824A28B01 for ; Mon, 24 Jun 2019 05:58:08 +0000 (UTC) Received: from localhost ([::1]:48116 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hfHzT-0003OQ-Rv for patchwork-qemu-devel@patchwork.kernel.org; Mon, 24 Jun 2019 01:58:07 -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) 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) 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) 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 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+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP 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 = (TranslationBlock*) ptr; + // if overflows, then reset the execution counter and increment the overflow counter + if (atomic_cmpxchg(&tb->tb_stats->exec_count, 0xFFFFFFFF, 0) == 0xFFFFFFFF) { + 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) DEF_HELPER_FLAGS_1(exit_atomic, TCG_CALL_NO_WG, noreturn, env) +DEF_HELPER_FLAGS_1(inc_exec_freq, TCG_CALL_NO_RWG, void, ptr) + #ifdef CONFIG_SOFTMMU 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, DisasContextBase *db, gen_tb_start(db->tb); ops->tb_start(db, cpu); tcg_debug_assert(db->is_jmp == DISAS_NEXT); /* no early exit */ + gen_tb_exec_count(tb); 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 @@ static TCGOp *icount_start_insn; +static inline void gen_tb_exec_count(TranslationBlock *tb) +{ + if (qemu_loglevel_mask(CPU_LOG_HOT_TBS)) { + TCGv_ptr tb_ptr = 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; From patchwork Mon Jun 24 05:54:41 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: vandersonmr X-Patchwork-Id: 11012333 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 80D8B112C for ; Mon, 24 Jun 2019 05:58:21 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7133C28B01 for ; Mon, 24 Jun 2019 05:58:21 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 64BE328B1E; Mon, 24 Jun 2019 05:58:21 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.0 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 026BE28B01 for ; Mon, 24 Jun 2019 05:58:21 +0000 (UTC) Received: from localhost ([::1]:48118 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hfHzg-0003Rh-9D for patchwork-qemu-devel@patchwork.kernel.org; Mon, 24 Jun 2019 01:58:20 -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) 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) 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) 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 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+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP 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, gpointer value, gpointer data) return false; } +static void tb_dump_statistics(TBStatistics *tbs) +{ + uint32_t cflags = curr_cflags() | CF_NOCACHE; + int old_log_flags = 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 + tbs->exec_count_overflows*0xFFFFFFFF)); + + mmap_lock(); + TranslationBlock *tb = tb_gen_code(current_cpu, tbs->pc, tbs->cs_base, 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(); } +static gint inverse_sort_tbs(gconstpointer p1, gconstpointer p2) +{ + const TBStatistics *tbs1 = (TBStatistics *) p1; + const TBStatistics *tbs2 = (TBStatistics *) p2; + uint64_t p1_count = (uint64_t) (tbs1->exec_count + tbs1->exec_count_overflows*0xFFFFFFFF); + uint64_t p2_count = (uint64_t) (tbs2->exec_count + tbs2->exec_count_overflows*0xFFFFFFFF); + + return p1_count < p2_count ? 1 : p1_count == p2_count ? 0 : -1; +} + +void tb_dump_exec_freq(uint32_t max_tbs_to_print) +{ + tb_ctx.tb_statistics = g_list_sort(tb_ctx.tb_statistics, inverse_sort_tbs); + + uint32_t tbs_printed = 0; + for (GList *i = tb_ctx.tb_statistics; i != NULL; i = i->next) { + tbs_printed++; + tb_dump_statistics((TBStatistics *) i->data); + if (max_tbs_to_print != 0 && tbs_printed >= 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; +void tb_dump_exec_freq(uint32_t); + #endif From patchwork Mon Jun 24 05:54:42 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: vandersonmr X-Patchwork-Id: 11012337 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 4EF4C76 for ; Mon, 24 Jun 2019 06:01:28 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3B12628B0A for ; Mon, 24 Jun 2019 06:01:28 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2A0B928B1E; Mon, 24 Jun 2019 06:01:28 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.0 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id C057028B0A for ; Mon, 24 Jun 2019 06:01:27 +0000 (UTC) Received: from localhost ([::1]:48142 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hfI2h-0005yV-3i for patchwork-qemu-devel@patchwork.kernel.org; Mon, 24 Jun 2019 02:01:27 -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) 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) 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) 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 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+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP 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; +extern int32_t max_num_hot_tbs_to_dump; + #define LOG_TRACE (1 << 15) /* 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); 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 = 0; static GArray *debug_regions; +int32_t max_num_hot_tbs_to_dump; /* Return the number of characters emitted. */ int qemu_log(const char *fmt, ...) @@ -273,6 +274,9 @@ const QEMULogItem qemu_log_items[] = { { 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 }, }; @@ -294,6 +298,11 @@ int qemu_str_to_log_mask(const char *str) trace_enable_events((*tmp) + 6); mask |= LOG_TRACE; #endif + } else if (g_str_has_prefix(*tmp, "hot_tbs")) { + if (g_str_has_prefix(*tmp, "hot_tbs:") && (*tmp)[8] != '\0') { + max_num_hot_tbs_to_dump = atoi((*tmp) + 8); + } + mask |= CPU_LOG_HOT_TBS; } else { for (item = qemu_log_items; item->mask != 0; item++) { if (g_str_equal(*tmp, item->name)) {