[{"id":1768069,"web_url":"http://patchwork.ozlabs.org/comment/1768069/","msgid":"<418914ee-c8bf-2576-3cea-4a3eb2a9d4f7@linaro.org>","list_archive_url":null,"date":"2017-09-13T18:01:39","subject":"Re: [Qemu-devel] [PATCH 6/7] trace: Add event \"guest_inst_after\"","submitter":{"id":72104,"url":"http://patchwork.ozlabs.org/api/people/72104/","name":"Richard Henderson","email":"richard.henderson@linaro.org"},"content":"On 09/10/2017 09:35 AM, Lluís Vilanova wrote:\n> Signed-off-by: Lluís Vilanova <vilanova@ac.upc.edu>\n> ---\n>  accel/tcg/translator.c |   23 ++++++++++++++++++-----\n>  trace-events           |    8 ++++++++\n>  2 files changed, 26 insertions(+), 5 deletions(-)\n> \n> diff --git a/accel/tcg/translator.c b/accel/tcg/translator.c\n> index d66d601c89..c010aeee45 100644\n> --- a/accel/tcg/translator.c\n> +++ b/accel/tcg/translator.c\n> @@ -35,7 +35,8 @@ void translator_loop_temp_check(DisasContextBase *db)\n>  void translator_loop(const TranslatorOps *ops, DisasContextBase *db,\n>                       CPUState *cpu, TranslationBlock *tb)\n>  {\n> -    target_ulong pc_bbl;\n> +    target_ulong pc_bbl, pc_insn = 0;\n> +    bool translated_insn = false;\n>      int max_insns;\n>  \n>      /* Initialize DisasContext */\n> @@ -75,10 +76,15 @@ void translator_loop(const TranslatorOps *ops, DisasContextBase *db,\n>      tcg_debug_assert(db->is_jmp == DISAS_NEXT);  /* no early exit */\n>  \n>      while (true) {\n> -        target_ulong pc_insn = db->pc_next;\n>          TCGv_i32 insn_size_tcg = 0;\n>          int insn_size_opcode_idx;\n>  \n> +        /* Tracing after (previous instruction) */\n> +        if (db->num_insns > 0) {\n> +            trace_guest_inst_after_tcg(cpu, tcg_ctx.tcg_env, pc_insn);\n> +        }\n\nHow does this differ from \"guest_inst\"?  Why would you need two trace points?\n\nWhy are you placing this at the beginning of the while loop rather than the end?\n\n> @@ -164,6 +172,9 @@ void translator_loop(const TranslatorOps *ops, DisasContextBase *db,\n>  \n>          gen_set_inline_region_begin(tcg_ctx.disas.inline_label);\n>  \n> +        if (TRACE_GUEST_INST_AFTER_ENABLED && translated_insn) {\n> +            trace_guest_inst_after_tcg(cpu, tcg_ctx.tcg_env, pc_insn);\n> +        }\n>          if (TRACE_GUEST_BBL_AFTER_ENABLED) {\n>              trace_guest_bbl_after_tcg(cpu, tcg_ctx.tcg_env, pc_bbl);\n>          }\n\nI think I'm finally beginning to understand what you're after with your\ninlining.  But I still think this should be doable in the appropriate opcode\ngenerating functions.\n\n\nr~","headers":{"Return-Path":"<qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org>","X-Original-To":"incoming@patchwork.ozlabs.org","Delivered-To":"patchwork-incoming@bilbo.ozlabs.org","Authentication-Results":["ozlabs.org;\n\tspf=pass (mailfrom) smtp.mailfrom=nongnu.org\n\t(client-ip=2001:4830:134:3::11; helo=lists.gnu.org;\n\tenvelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org;\n\treceiver=<UNKNOWN>)","ozlabs.org;\n\tdkim=fail reason=\"signature verification failed\" (1024-bit key;\n\tunprotected) header.d=linaro.org header.i=@linaro.org\n\theader.b=\"JqXWQWHD\"; dkim-atps=neutral"],"Received":["from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11])\n\t(using TLSv1 with cipher AES256-SHA (256/256 bits))\n\t(No client certificate requested)\n\tby ozlabs.org (Postfix) with ESMTPS id 3xsqKB4Tw2z9s7v\n\tfor <incoming@patchwork.ozlabs.org>;\n\tThu, 14 Sep 2017 04:03:26 +1000 (AEST)","from localhost ([::1]:43930 helo=lists.gnu.org)\n\tby lists.gnu.org with esmtp (Exim 4.71) (envelope-from\n\t<qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org>)\n\tid 1dsC0S-0006F7-Pc\n\tfor incoming@patchwork.ozlabs.org; Wed, 13 Sep 2017 14:03:24 -0400","from eggs.gnu.org ([2001:4830:134:3::10]:59105)\n\tby lists.gnu.org with esmtp (Exim 4.71)\n\t(envelope-from <richard.henderson@linaro.org>) id 1dsBzs-0006Bc-R9\n\tfor qemu-devel@nongnu.org; Wed, 13 Sep 2017 14:02:49 -0400","from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)\n\t(envelope-from <richard.henderson@linaro.org>) id 1dsBzr-0006NL-TG\n\tfor qemu-devel@nongnu.org; Wed, 13 Sep 2017 14:02:48 -0400","from mail-qt0-x22f.google.com ([2607:f8b0:400d:c0d::22f]:48403)\n\tby eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16)\n\t(Exim 4.71) (envelope-from <richard.henderson@linaro.org>)\n\tid 1dsBzr-0006My-Pc\n\tfor qemu-devel@nongnu.org; Wed, 13 Sep 2017 14:02:47 -0400","by mail-qt0-x22f.google.com with SMTP id q8so2409425qtb.5\n\tfor <qemu-devel@nongnu.org>; Wed, 13 Sep 2017 11:02:47 -0700 (PDT)","from bigtime.twiddle.net (184-217-192-88.pools.spcsdns.net.\n\t[184.217.192.88]) by smtp.gmail.com with ESMTPSA id\n\tm31sm7871572qtf.55.2017.09.13.11.02.44\n\t(version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);\n\tWed, 13 Sep 2017 11:02:46 -0700 (PDT)"],"DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google;\n\th=subject:to:cc:references:from:message-id:date:user-agent\n\t:mime-version:in-reply-to:content-language:content-transfer-encoding; \n\tbh=a9hqkkBRHVnTTVHQWBlsgvPqqy15Na+GFyWqYVyEViY=;\n\tb=JqXWQWHDxd9bNURSgj/mYQCizdVIes7hpZzUwlGO7qqnTYQypsB0rLJ8CBYd0+RS3P\n\tqY2vG2Rfdu0pqi/IIFjuabNb7+0OrKHgXfi5IF94aQUO9QPAkvm9+TYxg3Tjr9LILQm6\n\tHVW/Qw3J/eXjLCTAJOVhdFj7qweJJuc7S7UAs=","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20161025;\n\th=x-gm-message-state:subject:to:cc:references:from:message-id:date\n\t:user-agent:mime-version:in-reply-to:content-language\n\t:content-transfer-encoding;\n\tbh=a9hqkkBRHVnTTVHQWBlsgvPqqy15Na+GFyWqYVyEViY=;\n\tb=Z0zZ1mduI772O4eNbeRujDoDbOLtkphXdi/VySW1T7aO3SBweunsxxouNp2r0OBUYB\n\tT3EmWJS2R5UVUMLjndQ2yFTx/ddQVOMhf5CT1g3hlGaSTLVehSseGp+fNsmE1n5A4wxy\n\tpHPpnzD47lDSR+NIwywWrsyIL9LyY1IVYHIWFclTvm9EC6sVr00y0DUsXAbP+qZ5UbXL\n\tZoxZwuZXli+cfwionJPeTp8/Zqm9wrQy/ioqQ/wSrxGxRBifYwN41LH69JQb1SJYFo59\n\tGaHbVACHcVq8P+ngrvxUK2HK79J8mwK4Y+Z+8Jqz21y7QsHb+9JnnbpJQ3MzaR4b0mZe\n\tJemQ==","X-Gm-Message-State":"AHPjjUhRHB4ore0H6rqDi3jT5lSeSZ+z4e646mRJ48cswJc/olE0pZtD\n\t06ixoVlrER1qFck1","X-Google-Smtp-Source":"AOwi7QB1j86DBYWEe99BhSQIX7cwxlDEWa1Dq1MBLAvW9bEZEB8VJkrDynolR88oVBdViNCkxGzF4A==","X-Received":"by 10.237.53.5 with SMTP id a5mr26870048qte.53.1505325767065;\n\tWed, 13 Sep 2017 11:02:47 -0700 (PDT)","To":"=?utf-8?q?Llu=C3=ADs_Vilanova?= <vilanova@ac.upc.edu>,\n\tqemu-devel@nongnu.org","References":"<150505986682.19604.11937392314067517230.stgit@frigg.lan>\n\t<150506131942.19604.1306593039321280342.stgit@frigg.lan>","From":"Richard Henderson <richard.henderson@linaro.org>","Message-ID":"<418914ee-c8bf-2576-3cea-4a3eb2a9d4f7@linaro.org>","Date":"Wed, 13 Sep 2017 11:01:39 -0700","User-Agent":"Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101\n\tThunderbird/52.3.0","MIME-Version":"1.0","In-Reply-To":"<150506131942.19604.1306593039321280342.stgit@frigg.lan>","Content-Type":"text/plain; charset=utf-8","Content-Language":"en-US","Content-Transfer-Encoding":"8bit","X-detected-operating-system":"by eggs.gnu.org: Genre and OS details not\n\trecognized.","X-Received-From":"2607:f8b0:400d:c0d::22f","Subject":"Re: [Qemu-devel] [PATCH 6/7] trace: Add event \"guest_inst_after\"","X-BeenThere":"qemu-devel@nongnu.org","X-Mailman-Version":"2.1.21","Precedence":"list","List-Id":"<qemu-devel.nongnu.org>","List-Unsubscribe":"<https://lists.nongnu.org/mailman/options/qemu-devel>,\n\t<mailto:qemu-devel-request@nongnu.org?subject=unsubscribe>","List-Archive":"<http://lists.nongnu.org/archive/html/qemu-devel/>","List-Post":"<mailto:qemu-devel@nongnu.org>","List-Help":"<mailto:qemu-devel-request@nongnu.org?subject=help>","List-Subscribe":"<https://lists.nongnu.org/mailman/listinfo/qemu-devel>,\n\t<mailto:qemu-devel-request@nongnu.org?subject=subscribe>","Cc":"Paolo Bonzini <pbonzini@redhat.com>,\n\tPeter Crosthwaite <crosthwaite.peter@gmail.com>,\n\tStefan Hajnoczi <stefanha@redhat.com>,\n\tRichard Henderson <rth@twiddle.net>","Errors-To":"qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org","Sender":"\"Qemu-devel\"\n\t<qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org>"}},{"id":1768718,"web_url":"http://patchwork.ozlabs.org/comment/1768718/","msgid":"<877ex1nta1.fsf@frigg.lan>","list_archive_url":null,"date":"2017-09-14T16:23:34","subject":"Re: [Qemu-devel] [PATCH 6/7] trace: Add event \"guest_inst_after\"","submitter":{"id":9099,"url":"http://patchwork.ozlabs.org/api/people/9099/","name":"Lluís Vilanova","email":"vilanova@ac.upc.edu"},"content":"Richard Henderson writes:\n\n> On 09/10/2017 09:35 AM, Lluís Vilanova wrote:\n>> Signed-off-by: Lluís Vilanova <vilanova@ac.upc.edu>\n>> ---\n>> accel/tcg/translator.c |   23 ++++++++++++++++++-----\n>> trace-events           |    8 ++++++++\n>> 2 files changed, 26 insertions(+), 5 deletions(-)\n>> \n>> diff --git a/accel/tcg/translator.c b/accel/tcg/translator.c\n>> index d66d601c89..c010aeee45 100644\n>> --- a/accel/tcg/translator.c\n>> +++ b/accel/tcg/translator.c\n>> @@ -35,7 +35,8 @@ void translator_loop_temp_check(DisasContextBase *db)\n>> void translator_loop(const TranslatorOps *ops, DisasContextBase *db,\n>> CPUState *cpu, TranslationBlock *tb)\n>> {\n>> -    target_ulong pc_bbl;\n>> +    target_ulong pc_bbl, pc_insn = 0;\n>> +    bool translated_insn = false;\n>> int max_insns;\n>> \n>> /* Initialize DisasContext */\n>> @@ -75,10 +76,15 @@ void translator_loop(const TranslatorOps *ops, DisasContextBase *db,\n>> tcg_debug_assert(db->is_jmp == DISAS_NEXT);  /* no early exit */\n>> \n>> while (true) {\n>> -        target_ulong pc_insn = db->pc_next;\n>> TCGv_i32 insn_size_tcg = 0;\n>> int insn_size_opcode_idx;\n>> \n>> +        /* Tracing after (previous instruction) */\n>> +        if (db->num_insns > 0) {\n>> +            trace_guest_inst_after_tcg(cpu, tcg_ctx.tcg_env, pc_insn);\n>> +        }\n\n> How does this differ from \"guest_inst\"?  Why would you need two trace points?\n\nI assume you mean how it differs from guest_inst_before. The two main ideas are:\n\n* To be able to get a trace an execution-time event only after the instruction\n  or TB have finished executing successfully (i.e., there could be an exception).\n* Some values are only known *after* the instruction is translated (like the\n  instruction size, or other extra information we might add in the future), so\n  an efficient way to collect that is to trace guest_bbl_* and guest_insn_after\n  at translation time (to build a TB \"dictionary\" as some call it), and trace\n  guest_bbl_before at execution time (and use the detailed info above that you\n  got at translation time).\n\n\n> Why are you placing this at the beginning of the while loop rather than the end?\n\nYeah, that'll be much clearer.\n\n\n>> @@ -164,6 +172,9 @@ void translator_loop(const TranslatorOps *ops, DisasContextBase *db,\n>> \n>> gen_set_inline_region_begin(tcg_ctx.disas.inline_label);\n>> \n>> +        if (TRACE_GUEST_INST_AFTER_ENABLED && translated_insn) {\n>> +            trace_guest_inst_after_tcg(cpu, tcg_ctx.tcg_env, pc_insn);\n>> +        }\n>> if (TRACE_GUEST_BBL_AFTER_ENABLED) {\n>> trace_guest_bbl_after_tcg(cpu, tcg_ctx.tcg_env, pc_bbl);\n>> }\n\n> I think I'm finally beginning to understand what you're after with your\n> inlining.  But I still think this should be doable in the appropriate opcode\n> generating functions.\n\nI'm not sure we can if we want to avoid having the duplicate translation-time\nevents I said in a previous response (since TB can have two exit points and\nwe're detecting them through goto_tb).\n\n\nThanks,\n  Lluis","headers":{"Return-Path":"<qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org>","X-Original-To":"incoming@patchwork.ozlabs.org","Delivered-To":"patchwork-incoming@bilbo.ozlabs.org","Authentication-Results":"ozlabs.org;\n\tspf=pass (mailfrom) smtp.mailfrom=nongnu.org\n\t(client-ip=2001:4830:134:3::11; helo=lists.gnu.org;\n\tenvelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org;\n\treceiver=<UNKNOWN>)","Received":["from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11])\n\t(using TLSv1 with cipher AES256-SHA (256/256 bits))\n\t(No client certificate requested)\n\tby ozlabs.org (Postfix) with ESMTPS id 3xtP4C5Q1Wz9sPs\n\tfor <incoming@patchwork.ozlabs.org>;\n\tFri, 15 Sep 2017 02:24:11 +1000 (AEST)","from localhost ([::1]:48832 helo=lists.gnu.org)\n\tby lists.gnu.org with esmtp (Exim 4.71) (envelope-from\n\t<qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org>)\n\tid 1dsWvx-0002Wh-Sz\n\tfor incoming@patchwork.ozlabs.org; Thu, 14 Sep 2017 12:24:09 -0400","from eggs.gnu.org ([2001:4830:134:3::10]:50317)\n\tby lists.gnu.org with esmtp (Exim 4.71)\n\t(envelope-from <vilanova@ac.upc.edu>) id 1dsWve-0002Wa-Bj\n\tfor qemu-devel@nongnu.org; Thu, 14 Sep 2017 12:23:51 -0400","from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)\n\t(envelope-from <vilanova@ac.upc.edu>) id 1dsWvb-0006n9-6K\n\tfor qemu-devel@nongnu.org; Thu, 14 Sep 2017 12:23:50 -0400","from roura.ac.upc.edu ([147.83.33.10]:50510 helo=roura.ac.upc.es)\n\tby eggs.gnu.org with esmtp (Exim 4.71)\n\t(envelope-from <vilanova@ac.upc.edu>) id 1dsWva-0006mB-QQ\n\tfor qemu-devel@nongnu.org; Thu, 14 Sep 2017 12:23:47 -0400","from correu-2.ac.upc.es (correu-2.ac.upc.es [147.83.30.92])\n\tby roura.ac.upc.es (8.13.8/8.13.8) with ESMTP id v8EGNfDL022091;\n\tThu, 14 Sep 2017 18:23:41 +0200","from localhost (unknown [132.68.50.201])\n\tby correu-2.ac.upc.es (Postfix) with ESMTPSA id 1A20A358;\n\tThu, 14 Sep 2017 18:23:35 +0200 (CEST)"],"From":"=?utf-8?q?Llu=C3=ADs_Vilanova?= <vilanova@ac.upc.edu>","To":"Richard Henderson <richard.henderson@linaro.org>","References":"<150505986682.19604.11937392314067517230.stgit@frigg.lan>\n\t<150506131942.19604.1306593039321280342.stgit@frigg.lan>\n\t<418914ee-c8bf-2576-3cea-4a3eb2a9d4f7@linaro.org>","Mail-Followup-To":"Richard Henderson <richard.henderson@linaro.org>,\n\tqemu-devel@nongnu.org, Paolo Bonzini <pbonzini@redhat.com>, Richard\n\tHenderson <rth@twiddle.net>, Stefan Hajnoczi <stefanha@redhat.com>,\n\tPeter Crosthwaite <crosthwaite.peter@gmail.com>","Date":"Thu, 14 Sep 2017 19:23:34 +0300","In-Reply-To":"<418914ee-c8bf-2576-3cea-4a3eb2a9d4f7@linaro.org> (Richard\n\tHenderson's message of \"Wed, 13 Sep 2017 11:01:39 -0700\")","Message-ID":"<877ex1nta1.fsf@frigg.lan>","User-Agent":"Gnus/5.13 (Gnus v5.13) Emacs/25.2 (gnu/linux)","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Transfer-Encoding":"quoted-printable","X-detected-operating-system":"by eggs.gnu.org: GNU/Linux 2.6.x [fuzzy]","X-Received-From":"147.83.33.10","Subject":"Re: [Qemu-devel] [PATCH 6/7] trace: Add event \"guest_inst_after\"","X-BeenThere":"qemu-devel@nongnu.org","X-Mailman-Version":"2.1.21","Precedence":"list","List-Id":"<qemu-devel.nongnu.org>","List-Unsubscribe":"<https://lists.nongnu.org/mailman/options/qemu-devel>,\n\t<mailto:qemu-devel-request@nongnu.org?subject=unsubscribe>","List-Archive":"<http://lists.nongnu.org/archive/html/qemu-devel/>","List-Post":"<mailto:qemu-devel@nongnu.org>","List-Help":"<mailto:qemu-devel-request@nongnu.org?subject=help>","List-Subscribe":"<https://lists.nongnu.org/mailman/listinfo/qemu-devel>,\n\t<mailto:qemu-devel-request@nongnu.org?subject=subscribe>","Cc":"Paolo Bonzini <pbonzini@redhat.com>,\n\tPeter Crosthwaite <crosthwaite.peter@gmail.com>,\n\tqemu-devel@nongnu.org, Stefan Hajnoczi <stefanha@redhat.com>,\n\tRichard Henderson <rth@twiddle.net>","Errors-To":"qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org","Sender":"\"Qemu-devel\"\n\t<qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org>"}}]