From nobody Thu May 2 07:28:02 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=1560521381; cv=none; d=zoho.com; s=zohoarc; b=HempRSCP/neYmSkNYNDZcU00MXptslQAOwCDW72suMC7DwZaWZX6eW+I2gHMhrl96LJl2NKR4FO1ii6+Ij/w0THP+4nAd4XR2A5Nc1hc/w/0vfETppIWdSTcwiPrhEiG8W0eTbvNYpd8vt3Rd6ArOU55FfptI3RaSF8GUtIEqSU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1560521381; 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=IkKggjJFmzSiJ4uZvBdZPk5OGuw0OM24o79Ww5vmA0s=; b=WDKYIJh9ZawP7LEiJCP5ngsXjowOjVq1N+MhBp7ZppnyKEYT1RNWIH1pmtjNhqu3S1/SlYsICrsx/cV+sHNZk0gG3z/iLWY9t8hR5eANSWtkyDo/U3Df32dzRvgvvqEgb/f0fkULk8EG7fogFPdiMdcQXyRqqOSYqnJuoyszW/s= 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 1560521381240854.06569804938; Fri, 14 Jun 2019 07:09:41 -0700 (PDT) Received: from localhost ([::1]:51864 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hbmte-0007UQ-AF for importer@patchew.org; Fri, 14 Jun 2019 10:09:38 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:50888) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hbmey-0003Dh-5X for qemu-devel@nongnu.org; Fri, 14 Jun 2019 09:54:29 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hbmew-0007xm-LN for qemu-devel@nongnu.org; Fri, 14 Jun 2019 09:54:28 -0400 Received: from mail-qk1-x741.google.com ([2607:f8b0:4864:20::741]:37539) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hbmew-0007xI-HG for qemu-devel@nongnu.org; Fri, 14 Jun 2019 09:54:26 -0400 Received: by mail-qk1-x741.google.com with SMTP id d15so1703457qkl.4 for ; Fri, 14 Jun 2019 06:54:26 -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.23 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Fri, 14 Jun 2019 06:54:25 -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=IkKggjJFmzSiJ4uZvBdZPk5OGuw0OM24o79Ww5vmA0s=; b=Ilfphwh7W0bSCbz3HEE5Ig/H+sPpb7x2Wg2TAKIKuPmF4xtXimH5yuMYHLi4u9cPF3 ApIm3jpHXDxRUkizDFnpok/EVWoYmVAzpQaAu2zbxnt24KFHxfi9sHb5nC9cdGs3xfpN lstxiTcPG9wxI3WxrY5HXm671Sa50zGYySXvFhKQIBjz3YL/XDa5dTvFqUI+MsdGPnUU Lx4ithhhSznK/wT+VIOQ7T+45BKZESlWsw6x4/RfegBLA/64jW8A8Vqczhb2iF/fJ3wN Px1c1ICSYjSaE8Qgg/FGE+O0foCR6E+wNNG2mYLlj6Pp1r3mS/cSj/wMY/70AmWUSvw8 GS/Q== 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=IkKggjJFmzSiJ4uZvBdZPk5OGuw0OM24o79Ww5vmA0s=; b=h9/qH8+2RAx55ClsMwZHeJuz/CFLxRgQZwvjBWTh7YTpJHkf7YCtDJF1welwOHO9e2 pcAl0Gqh9T3U/dzgwoQ/xG2JPRlv8qcPOtD4wpUKM0gKv8FR1fMuRYVoRgyKaJuZaKIx ya+6IvJhvV1u6xYTZ8eqLoy1yX6HXr9N7RG2fTzUzl9GUHIv1iya1Hzt+1bR7LRKctSs 0JtXNhDdZRdqMErwOoip5giYKjYIB5iv3bjHdoY/0M24QSO70b+l1xx57jlXn0yBu6Ty HbElqWyIXk4IQPflxJtO5J9o7KHQUNCIIPYQtYGc7U2vHqNsYnk8VrnKjKFMmkhYSr0K yKNw== X-Gm-Message-State: APjAAAXkfA2AdWgVSc5mQhuF4H3dX48Zdrm6yXtctMkAhd0DlVngZVJZ VzjKYetcHdsOTZos7TbhOZiRreRvmWU= X-Google-Smtp-Source: APXvYqyIYknesP7N2pux79oTWlaO0jCG3TpBqLi3gVCa1uVDxHqx/XVmN8zDqjeDFR9whNADYAuOeg== X-Received: by 2002:a37:9c50:: with SMTP id f77mr76429450qke.6.1560520465756; Fri, 14 Jun 2019 06:54:25 -0700 (PDT) From: vandersonmr To: qemu-devel@nongnu.org Date: Fri, 14 Jun 2019 10:53:29 -0300 Message-Id: <20190614135332.12777-2-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::741 Subject: [Qemu-devel] [Qemu-Devel][PATCH 1/3] 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 , Riku Voipio , vandersonmr , Laurent Vivier , 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" An uint64_t counter was added in the TranslationBlock struct and it is incremented every time that the TB is executed. Signed-off-by: vandersonmr --- accel/tcg/tcg-runtime.c | 6 ++++++ accel/tcg/tcg-runtime.h | 2 ++ include/exec/exec-all.h | 1 + include/exec/gen-icount.h | 7 +++++++ linux-user/main.c | 1 + vl.c | 1 + 6 files changed, 18 insertions(+) diff --git a/accel/tcg/tcg-runtime.c b/accel/tcg/tcg-runtime.c index 8a1e408e31..d1f4127d31 100644 --- a/accel/tcg/tcg-runtime.c +++ b/accel/tcg/tcg-runtime.c @@ -167,3 +167,9 @@ 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; + atomic_inc(&tb->exec_freq); +} 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/include/exec/exec-all.h b/include/exec/exec-all.h index 16034ee651..a80407622e 100644 --- a/include/exec/exec-all.h +++ b/include/exec/exec-all.h @@ -342,6 +342,7 @@ struct TranslationBlock { uint32_t flags; /* flags defining in which context the code was genera= ted */ uint16_t size; /* size of target code for this block (1 <=3D size <=3D TARGET_PAGE_SIZE) */ + uint64_t exec_freq; uint16_t icount; uint32_t cflags; /* compile flags */ #define CF_COUNT_MASK 0x00007fff diff --git a/include/exec/gen-icount.h b/include/exec/gen-icount.h index f7669b6841..a540d12005 100644 --- a/include/exec/gen-icount.h +++ b/include/exec/gen-icount.h @@ -6,11 +6,18 @@ /* Helpers for instruction counting code generation. */ =20 static TCGOp *icount_start_insn; +extern bool enable_freq_count; =20 static inline void gen_tb_start(TranslationBlock *tb) { TCGv_i32 count, imm; =20 + if (enable_freq_count) { + TCGv_ptr tb_ptr =3D tcg_temp_new_ptr(); + tcg_gen_trunc_i64_ptr(tb_ptr, tcg_const_i64((int64_t) tb)); + gen_helper_inc_exec_freq(tb_ptr); + } + tcg_ctx->exitreq_label =3D gen_new_label(); if (tb_cflags(tb) & CF_USE_ICOUNT) { count =3D tcg_temp_local_new_i32(); diff --git a/linux-user/main.c b/linux-user/main.c index a59ae9439d..1bf7155670 100644 --- a/linux-user/main.c +++ b/linux-user/main.c @@ -58,6 +58,7 @@ static const char *seed_optarg; unsigned long mmap_min_addr; unsigned long guest_base; int have_guest_base; +bool enable_freq_count =3D false; =20 /* * When running 32-on-64 we should make sure we can fit all of the possible diff --git a/vl.c b/vl.c index 005468cbfb..cb6c0ad63d 100644 --- a/vl.c +++ b/vl.c @@ -190,6 +190,7 @@ bool boot_strict; uint8_t *boot_splash_filedata; int only_migratable; /* turn it off unless user states otherwise */ bool wakeup_suspend_enabled; +bool enable_freq_count =3D false; =20 int icount_align_option; =20 --=20 2.22.0 From nobody Thu May 2 07:28:02 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=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 From nobody Thu May 2 07:28:02 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=1560523513; cv=none; d=zoho.com; s=zohoarc; b=I7u/Pjlrx+R+Ve58PtvyzJBIh09wmjTE89Tai5HtNZUN3w1gjul+bno4ssPfIY9lNcnnNaK48o2G01c6nXSwhVmNjPoxbemc8HgxSiK1ahwhU8nkafnEITKJ7Sk4fFMBx/a7gHDT9YegpbsMncC/rKLmWlspS5y/Rl8HDfk2rCk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1560523513; 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=xaXpncAfIlNPzwxbXg13UxwI8EcQoz2212flgvquBy4=; b=AIkmEas5WjSzvCfWl/3tr1yFYkK/MCDLYEQdaZ+YEgYE14uNdQJPYeR3aCQBWQBfcm0TSUY/v5snP5MgcJDsx57iFlOHdBglX7UNpXz5R5g/ATrULIiiwuPg45cwbb+BekTMwMVqOv4KYiEouk1uBcPloWznzKR4Nckmz+Vljog= 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 1560523513002621.452322985627; Fri, 14 Jun 2019 07:45:13 -0700 (PDT) Received: from localhost ([::1]:52220 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hbnRx-0004HW-FE for importer@patchew.org; Fri, 14 Jun 2019 10:45:05 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:50923) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hbmf1-0003TX-Iv for qemu-devel@nongnu.org; Fri, 14 Jun 2019 09:54:32 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hbmf0-00080a-H3 for qemu-devel@nongnu.org; Fri, 14 Jun 2019 09:54:31 -0400 Received: from mail-qt1-x841.google.com ([2607:f8b0:4864:20::841]:44773) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hbmf0-00080P-Cr for qemu-devel@nongnu.org; Fri, 14 Jun 2019 09:54:30 -0400 Received: by mail-qt1-x841.google.com with SMTP id x47so2487206qtk.11 for ; Fri, 14 Jun 2019 06:54:30 -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.28 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Fri, 14 Jun 2019 06:54:29 -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=xaXpncAfIlNPzwxbXg13UxwI8EcQoz2212flgvquBy4=; b=U2s8fQP+ylC+Yyy2Py9pWH7gb9fvnxVSWa0nLxKFa8pBTny91pE53gRQb8yYGyP+T9 ZrZbJzym+reWlh2/9lFXfFNK2cvGa1rJcdRDh3DHeOiBaGnKWucqdRbvY0Pts5Slyieq F8X6R16oW1dpd/Pd+zZwiW4+nQyV1+w23mBfeMWeLufr2wgOmqG729jE5C0ICgNvoJwB Vzy+VuM3JcqJ2aZmYo4QKenRSU8u7pTP7cY6kXBJBp4jScx/Uyv0UokBgYxH4Ijo1Bdc fHg2PccPhbv+COUMBqr4IhDwopRdrKkbTNLYJa6/ukzCTdNcFVU10aRgPBfdiYL1J4q7 A5SA== 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=xaXpncAfIlNPzwxbXg13UxwI8EcQoz2212flgvquBy4=; b=GZ2xjsgIJZasCYjJR0N0zIRt+ulEYX2Tey8RyaTLp2WpIGnDM1sIYwzhScTQu5dufi Uh7Qq9019Sms4OqbWnIYY8P4ShLkV+L/H7BHDA0SJtqAuaF4A62Vv782zQ8lNcZglRh7 O3AG9q909CFH6W5mCXA5evCdPm1ER2rFgLYsngSW/nPqBVXFNy7IizBUYsFQJliPjzZj y0Bjb01djveKYMwHomHTvTq8r6HHeVGj20CW/F6iiPmQ9G59P/j5FQhGIhvmXlcmZabC Z7yDbRIhlAMWJDPmrq2vELQFcfYAOQblc4bFmoP86VY14ehfrIWq5B/HpEdYz4VAWV2W O1nA== X-Gm-Message-State: APjAAAVJPPp4qnbYuhJdYWDzidppXnvjSzB5vQcHzju7QPQ8eBB8uGPD ScvVJ57NYmVictE+QjSbF3x5ZQaRfAE= X-Google-Smtp-Source: APXvYqxKGmFIPPcxRHY8ql4h8QE/EjSCVoKoJhTVZxoAdUawwQr8yJPa7wvrCxFXyzBvYahHzY0wug== X-Received: by 2002:ac8:384c:: with SMTP id r12mr31198945qtb.153.1560520469656; Fri, 14 Jun 2019 06:54:29 -0700 (PDT) From: vandersonmr To: qemu-devel@nongnu.org Date: Fri, 14 Jun 2019 10:53:31 -0300 Message-Id: <20190614135332.12777-4-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::841 Subject: [Qemu-devel] [Qemu-Devel][PATCH 3/3] Adding command line option to linux-user. 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" Added -execfreq to enable execution frequency counting and dump all the TB's addresses and their execution frequency at the end of the execution. Signed-off-by: vandersonmr --- linux-user/exit.c | 5 +++++ linux-user/main.c | 7 +++++++ 2 files changed, 12 insertions(+) diff --git a/linux-user/exit.c b/linux-user/exit.c index bdda720553..0c6a2f2d5b 100644 --- a/linux-user/exit.c +++ b/linux-user/exit.c @@ -26,8 +26,13 @@ extern void __gcov_dump(void); #endif =20 +extern bool enable_freq_count; + void preexit_cleanup(CPUArchState *env, int code) { + if (enable_freq_count) { + tb_dump_all_exec_freq(); + } #ifdef TARGET_GPROF _mcleanup(); #endif diff --git a/linux-user/main.c b/linux-user/main.c index 1bf7155670..ece2d8bd8b 100644 --- a/linux-user/main.c +++ b/linux-user/main.c @@ -388,6 +388,11 @@ static void handle_arg_trace(const char *arg) trace_file =3D trace_opt_parse(arg); } =20 +static void handle_arg_execfreq(const char *arg) +{ + enable_freq_count =3D true; +} + struct qemu_argument { const char *argv; const char *env; @@ -439,6 +444,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]"}, + {"execfreq", "QEMU_EXEC_FREQ", false, handle_arg_execfreq, + "", "enable and dump TB's execution frequency counting"}, {"version", "QEMU_VERSION", false, handle_arg_version, "", "display version information and exit"}, {NULL, NULL, false, NULL, NULL, NULL} --=20 2.22.0