From nobody Mon Feb 9 07:05:37 2026 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