From nobody Mon Feb 9 14:37:58 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=1560522584; cv=none; d=zoho.com; s=zohoarc; b=Wq3V7LqZfvHFUnd7OYTptce8EfHQN+iK7U7bVpijOBc5+mbHwKMRaNmYYtKW0MqWw2iJNihbX6TMBLXZcohS1xXUdm7RtpTJfabwQcfXrRGfKHja3EKyQbe2zOKOsZ8YpSnIBYLx7/xG7HSvTjU5oLSnJMW03tS7uZ1OO2AX1N8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1560522584; 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=PKjJ8WywQMhni5S/aI+GnLf+YqUEj6nxfGowAtVbIiE=; b=E96C4RwliiyDzPUf34VYlwz9VX4lUcgrjyopIVpGeVPXEjQgXyXKwkNMJ0OgXBEJXoHtOpnUoc67Y971Ul3mLbsQkqEv1BqV5g91JT6Y7i8lZkT/yV/MrRojV8IzwJGrwhAi1oWhfjdWa9Tdt4/TlO2n7NVyIK06rRK4urqMsls= 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 1560522584279816.6566329214796; Fri, 14 Jun 2019 07:29:44 -0700 (PDT) Received: from localhost ([::1]:52084 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hbnD5-00038u-BM for importer@patchew.org; Fri, 14 Jun 2019 10:29:43 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:50912) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hbmf0-0003My-5e for qemu-devel@nongnu.org; Fri, 14 Jun 2019 09:54:31 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hbmey-0007zb-P8 for qemu-devel@nongnu.org; Fri, 14 Jun 2019 09:54:30 -0400 Received: from mail-qk1-x742.google.com ([2607:f8b0:4864:20::742]:35369) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hbmey-0007z3-KU for qemu-devel@nongnu.org; Fri, 14 Jun 2019 09:54:28 -0400 Received: by mail-qk1-x742.google.com with SMTP id l128so1707387qke.2 for ; Fri, 14 Jun 2019 06:54:28 -0700 (PDT) Received: from localhost.localdomain ([2804:7f4:548c:f96b:4e5b:86ef:e7bc:c1a0]) by smtp.googlemail.com with ESMTPSA id 77sm1747150qkd.59.2019.06.14.06.54.26 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Fri, 14 Jun 2019 06:54:27 -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=PKjJ8WywQMhni5S/aI+GnLf+YqUEj6nxfGowAtVbIiE=; b=GVcdPK/5lQWaW5q7epnrdARJieE/83qoLH8JFEx57x40wbEgxaq68OxUfmA20B3lRM /3I3AG2v611yzWO4afdpWfejoD6PU80U6V0FWh+F0rg4thOKcuZocvdne+sTP13UkDRY sB/hlJewVDr92CZoNDcpqq74HxWwzAayQhCDctqhB+RdRZkrSybA99m9onvk9VntUN8v EeZ14h9ADI09hIeEE1nA7mZNJwjUmsKvy64ZemdC66isGfIXLB+bdICpMVweiCJnKDBe DRYWOCk4uKU2Ea/GYGSyZQcaKF+nYrVKOeIOuDimFEOPbv5olExLYAM1l5JZyvIfYay8 /buQ== 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=PKjJ8WywQMhni5S/aI+GnLf+YqUEj6nxfGowAtVbIiE=; b=ShIW1RzXq3GMXY+L21pzsE3MzvLvcbg1PRTaqZ6YoZ+F148OrEzIHZl30cDfenpIEf sI+L38tyTr9xXWlbHXLW8nz/jazeD/pMG9Lz8x1iNWCemftNVXrCHF38fVL4LjFugxAz ZsBKhaGZKYo85oUeC6sbXy654gtWGxCRGG2qh8cBqsaQqrntkxbS4jQKjoqQIJVVvCtA A5PIAJ3F69HMcnxv0aPC878bFJBO4wLH/eBs1rhdFCsl3MylKzYA18vso1mFKL6OED27 vGeh0KCP5jayim3g9tijB0jqrUTF+zyIFEzYaJYbwKofkMLoQgIqW7mbcLFNsXkCeLEG ykSw== X-Gm-Message-State: APjAAAWw1wK2aJw7Jal3G2x2eAPZKhQqABlueCYW4eryKQPBvhUmA59w GVasFk7KscUn0gzQeLB9//InHcDDjpQ= X-Google-Smtp-Source: APXvYqwvOWwlyMP9epKbsJfRS+c13T5SDM2ql2jPRaisl1pRLyV6Lb1erMdNtfx+uKVcxFeT/Zy9Ww== X-Received: by 2002:a37:8081:: with SMTP id b123mr6667396qkd.62.1560520467753; Fri, 14 Jun 2019 06:54:27 -0700 (PDT) From: vandersonmr To: qemu-devel@nongnu.org Date: Fri, 14 Jun 2019 10:53:30 -0300 Message-Id: <20190614135332.12777-3-vandersonmr2@gmail.com> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190614135332.12777-1-vandersonmr2@gmail.com> References: <20190614135332.12777-1-vandersonmr2@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::742 Subject: [Qemu-devel] [Qemu-Devel][PATCH 2/3] Saving counters between tb_flush events. 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" A new hash map was added to store the accumulated execution frequency of the TBs even after tb_flush events. A dump function was also added as a way to visualize these frequencies. Signed-off-by: vandersonmr --- accel/tcg/translate-all.c | 59 +++++++++++++++++++++++++++++++++++++++ accel/tcg/translate-all.h | 2 ++ exec.c | 7 +++++ include/exec/exec-all.h | 3 ++ include/exec/tb-context.h | 9 ++++++ include/qom/cpu.h | 2 ++ 6 files changed, 82 insertions(+) diff --git a/accel/tcg/translate-all.c b/accel/tcg/translate-all.c index 5d1e08b169..0bc670ffad 100644 --- a/accel/tcg/translate-all.c +++ b/accel/tcg/translate-all.c @@ -1118,6 +1118,12 @@ static inline void code_gen_alloc(size_t tb_size) } } =20 +static bool statistics_cmp(const void* ap, const void *bp) { + const TBStatistics *a =3D ap; + const TBStatistics *b =3D bp; + return 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 +1143,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); + qht_init(&tb_ctx.tb_statistics, statistics_cmp, CODE_GEN_HTABLE_SIZE, = QHT_MODE_AUTO_RESIZE); } =20 /* Must be called before using the QEMU cpus. 'tb_size' is the size @@ -1228,6 +1235,53 @@ static gboolean tb_host_size_iter(gpointer key, gpoi= nter value, gpointer data) return false; } =20 +static void do_tb_dump_exec_freq(void *p, uint32_t hash, void *userp) +{ +#if TARGET_LONG_SIZE =3D=3D 8 + TBStatistics *tbs =3D p; + printf("%016lx\t%lu\n", tbs->pc, tbs->total_exec_freq); +#elif TARGET_LONG_SIZE =3D=3D 4 + TBStatistics *tbs =3D p; + printf("%016x\t%lu\n", tbs->pc, tbs->total_exec_freq); +#endif +} + +void tb_dump_all_exec_freq(void) +{ + tb_read_exec_freq(); + qht_iter(&tb_ctx.tb_statistics, do_tb_dump_exec_freq, NULL); +} + +static void do_tb_read_exec_freq(void *p, uint32_t hash, void *userp) +{ + TranslationBlock *tb =3D p; + TBStatistics tbscmp; + tbscmp.pc =3D tb->pc; + tbscmp.cs_base =3D tb->cs_base; + tbscmp.flags =3D tb->flags; + + TBStatistics *tbs =3D qht_lookup(userp, &tbscmp, hash); + + uint64_t exec_freq =3D tb_get_and_reset_exec_freq((TranslationBlock*) = p); + + if (tbs) { + tbs->total_exec_freq +=3D exec_freq; + } else { + void *existing; + tbs =3D malloc(sizeof(TBStatistics)); + tbs->total_exec_freq =3D exec_freq; + tbs->pc =3D tb->pc; + tbs->cs_base =3D tb->cs_base; + tbs->flags =3D tb->flags; + qht_insert(userp, tbs, hash, &existing); + } +} + +void tb_read_exec_freq(void) +{ + qht_iter(&tb_ctx.htable, do_tb_read_exec_freq, &tb_ctx.tb_statistics); +} + /* flush all the translation blocks */ static void do_tb_flush(CPUState *cpu, run_on_cpu_data tb_flush_count) { @@ -1252,6 +1306,10 @@ static void do_tb_flush(CPUState *cpu, run_on_cpu_da= ta tb_flush_count) cpu_tb_jmp_cache_clear(cpu); } =20 + if (enable_freq_count) { + tb_read_exec_freq(); + } + qht_reset_size(&tb_ctx.htable, CODE_GEN_HTABLE_SIZE); page_flush_tb(); =20 @@ -1723,6 +1781,7 @@ TranslationBlock *tb_gen_code(CPUState *cpu, tb->flags =3D flags; tb->cflags =3D cflags; tb->trace_vcpu_dstate =3D *cpu->trace_dstate; + tb->exec_freq =3D 0; tcg_ctx->tb_cflags =3D cflags; tb_overflow: =20 diff --git a/accel/tcg/translate-all.h b/accel/tcg/translate-all.h index 64f5fd9a05..e13088c36d 100644 --- a/accel/tcg/translate-all.h +++ b/accel/tcg/translate-all.h @@ -32,6 +32,8 @@ void tb_invalidate_phys_page_range(tb_page_addr_t start, = tb_page_addr_t end, int is_cpu_write_access); void tb_check_watchpoint(CPUState *cpu); =20 +extern bool enable_freq_count; + #ifdef CONFIG_USER_ONLY int page_unprotect(target_ulong address, uintptr_t pc); #endif diff --git a/exec.c b/exec.c index e7622d1956..9b64a012ee 100644 --- a/exec.c +++ b/exec.c @@ -1013,6 +1013,13 @@ const char *parse_cpu_option(const char *cpu_option) return cpu_type; } =20 +uint64_t tb_get_and_reset_exec_freq(TranslationBlock *tb) +{ + uint64_t exec_freq =3D atomic_load_acquire(&tb->exec_freq); + atomic_store_release(&tb->exec_freq, 0); + return exec_freq; +} + #if defined(CONFIG_USER_ONLY) void tb_invalidate_phys_addr(target_ulong addr) { diff --git a/include/exec/exec-all.h b/include/exec/exec-all.h index a80407622e..5d3d829d18 100644 --- a/include/exec/exec-all.h +++ b/include/exec/exec-all.h @@ -513,4 +513,7 @@ hwaddr memory_region_section_get_iotlb(CPUState *cpu, /* vl.c */ extern int singlestep; =20 +void tb_read_exec_freq(void); +void tb_dump_all_exec_freq(void); + #endif diff --git a/include/exec/tb-context.h b/include/exec/tb-context.h index feb585e0a7..ba518d47a0 100644 --- a/include/exec/tb-context.h +++ b/include/exec/tb-context.h @@ -28,6 +28,14 @@ =20 typedef struct TranslationBlock TranslationBlock; typedef struct TBContext TBContext; +typedef struct TBStatistics TBStatistics; + +struct TBStatistics { + target_ulong pc; + target_ulong cs_base; + uint32_t flags; + uint64_t total_exec_freq; +}; =20 struct TBContext { =20 @@ -35,6 +43,7 @@ struct TBContext { =20 /* statistics */ unsigned tb_flush_count; + struct qht tb_statistics; }; =20 extern TBContext tb_ctx; diff --git a/include/qom/cpu.h b/include/qom/cpu.h index 5ee0046b62..593c1f1137 100644 --- a/include/qom/cpu.h +++ b/include/qom/cpu.h @@ -474,6 +474,8 @@ static inline void cpu_tb_jmp_cache_clear(CPUState *cpu) } } =20 +uint64_t tb_get_and_reset_exec_freq(struct TranslationBlock*); + /** * qemu_tcg_mttcg_enabled: * Check whether we are running MultiThread TCG or not. --=20 2.22.0