From patchwork Fri Oct 25 06:36:51 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 177686 Delivered-To: patch@linaro.org Received: by 2002:a92:409a:0:0:0:0:0 with SMTP id d26csp3292002ill; Fri, 25 Oct 2019 00:40:11 -0700 (PDT) X-Google-Smtp-Source: APXvYqwnUINyk2Ati5f+a3xR4hSi5jiUEe9XUoVWsSoxiYvfP8/Js3z0yLKkXC4rgkCS2kuSC3Do X-Received: by 2002:ac8:22f1:: with SMTP id g46mr1707887qta.12.1571989211453; Fri, 25 Oct 2019 00:40:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1571989211; cv=none; d=google.com; s=arc-20160816; b=YQOh3IoSe2z6o49w6qEIlE2e1B0kvwLMZSE/yLK+rF4ED9V7UneJLlUJHtR+6roEc9 eMHDFzA9PaTVYu7g37FnJINNbMXw4/BvOQN5RB85kC3Rk656ngHunMm3I0xXdPNqJ/XP RA6teqKRhSxePUFpisanQ/QwV3JQ9GK+rJyv/1u6SRYoilPWZiESmFHTtw0M+VRkMhqq dD3Gy4Ll7xv5BldfXN0Yk+qm8k1+wlhx+cBYstfPGJSfKbljcNhNZXbu0nDq022fay2C fQHJDg6ijxqLIRpWKkzpnHY3BlskxiTPDZXO93VWCdnSESgvgOoO3PBBfhN2YngLNChe YV4w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=avDcFa6vNjqfkFm9Eh7Mdg86NxTMA5t/4HoZgIMcBpg=; b=DkhsxsZjBKmixZo0QzAKSIjWmlxPM49tl2YYkupStcGY6Nx/YxLYj31+Y399MCuqMn ehFcH0OZzepxRyUqW6lXNWWbyFTpPmj0sj1bjU7DgPTs0ji9qtRaCWdrXDZiN5CrjA6G wMn8X2YSuSXrQpxmf2u3RqEYt4e/FuWGY5KBd93R1i3QR+906dqPgGisrS7Dav6fprDk FgD/4Dc2nnCR7mxIh1afQxPCtcOniX9On7l0iceJRZ9ycQGh1C5YA2vfPYirkq9bGzkz EgEuGiZW/3rd7ioECo4BbDceE8mlCzYtU5Yx2jh9cSktdQAYOKWI+MQc2gEcMnjcamIf pPbA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=NbHuFF+g; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id g32si766347qta.163.2019.10.25.00.40.11 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 25 Oct 2019 00:40:11 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=NbHuFF+g; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:56986 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iNuCf-00075B-RY for patch@linaro.org; Fri, 25 Oct 2019 03:40:09 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40410) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iNtpx-0004dJ-GL for qemu-devel@nongnu.org; Fri, 25 Oct 2019 03:16:42 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iNtpw-0007Cq-3L for qemu-devel@nongnu.org; Fri, 25 Oct 2019 03:16:41 -0400 Received: from mail-wr1-x42b.google.com ([2a00:1450:4864:20::42b]:39306) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1iNtpv-0007C4-Sx for qemu-devel@nongnu.org; Fri, 25 Oct 2019 03:16:40 -0400 Received: by mail-wr1-x42b.google.com with SMTP id a11so1028015wra.6 for ; Fri, 25 Oct 2019 00:16:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=avDcFa6vNjqfkFm9Eh7Mdg86NxTMA5t/4HoZgIMcBpg=; b=NbHuFF+ghhkCeBnDkW5o4yXAtJTkfu5Mz1Pi6zikfUp6Pq+XwIRNb7T39SbuUQOHi9 W/I94CSKVORkaYaf2oJbKpJ3GHG2EwZzEm7TlxT2EElAfE10cvvHEOGFPGJuqyr/SGSJ +U/BYJPNrPBBGR2iO4MhfoqXbyoXjBGa215puULkSCchjWr53z74o0NG/IZfY8yEwjmF 0hV/RVbRQc+nrDTaXnrk2QlzdDAJWlMaMED2S3qd67GdkdSB8z45bETLCbPduwge0i2W WPUVQ5e88jsRQTVWQhqsncOb/9E4w2JJjHr6qAHN/PmY9yA0OEt+wltjaGkNsospMK0x lvzQ== 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=avDcFa6vNjqfkFm9Eh7Mdg86NxTMA5t/4HoZgIMcBpg=; b=AQiplSpzI7giXeQNdUn5e8UD/aYY+Xobw0gjONkc9kWCFQ7DbatS+WpVyE0CpLIull 6rwVWF3CradWoIXbcXHA37s3WL31o1Kt1IAxYXRFa1b9/mAO1O6lm+Omm6OTbn0ataYO dkgHhOITFmQXDn6TzUh4zALShH1zCuCxTi5O8EnVQxiBkvIK3zVRkZZEt44hzcAFg0dV LOFCxODyWtmAZTJ7sqzNOtf4LOyMTvttQyEZptGcLxNXU2qUSBG3sLanEk7jjCuyfqvW XnUHCquZlJT4gw/FPRUpVbrwPQV1Q/pVmGPqd1uVggSshd/RT7z4TwcmhnX8hfCQl9P4 yJCQ== X-Gm-Message-State: APjAAAW5xhIQ4mHQMajem0YfZiwi/SoWNTKAr+apvq3/gaxD6Gn9m3c7 /CHaVO2Lq7RsXz+8eRD3kc9irXagmlQ= X-Received: by 2002:a5d:69c8:: with SMTP id s8mr1414873wrw.167.1571987798667; Fri, 25 Oct 2019 00:16:38 -0700 (PDT) Received: from zen.linaroharston ([51.148.130.216]) by smtp.gmail.com with ESMTPSA id r15sm1316713wro.20.2019.10.25.00.16.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 25 Oct 2019 00:16:36 -0700 (PDT) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id 7F5401FF90; Fri, 25 Oct 2019 07:37:18 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: peter.maydell@linaro.org Subject: [PULL v2 51/73] translator: inject instrumentation from plugins Date: Fri, 25 Oct 2019 07:36:51 +0100 Message-Id: <20191025063713.23374-52-alex.bennee@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191025063713.23374-1-alex.bennee@linaro.org> References: <20191025063713.23374-1-alex.bennee@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::42b 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: Richard Henderson , qemu-devel@nongnu.org, "Emilio G. Cota" , Paolo Bonzini , =?utf-8?q?Alex_Benn=C3=A9e?= , Richard Henderson Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: "Emilio G. Cota" Signed-off-by: Emilio G. Cota Signed-off-by: Alex Bennée Reviewed-by: Richard Henderson -- 2.20.1 diff --git a/accel/tcg/translator.c b/accel/tcg/translator.c index 70c66c538cf..f977682be79 100644 --- a/accel/tcg/translator.c +++ b/accel/tcg/translator.c @@ -16,6 +16,7 @@ #include "exec/gen-icount.h" #include "exec/log.h" #include "exec/translator.h" +#include "exec/plugin-gen.h" /* Pairs with tcg_clear_temp_count. To be called by #TranslatorOps.{translate_insn,tb_stop} if @@ -34,6 +35,7 @@ void translator_loop(const TranslatorOps *ops, DisasContextBase *db, CPUState *cpu, TranslationBlock *tb, int max_insns) { int bp_insn = 0; + bool plugin_enabled; /* Initialize DisasContext */ db->tb = tb; @@ -55,11 +57,17 @@ void translator_loop(const TranslatorOps *ops, DisasContextBase *db, ops->tb_start(db, cpu); tcg_debug_assert(db->is_jmp == DISAS_NEXT); /* no early exit */ + plugin_enabled = plugin_gen_tb_start(cpu, tb); + while (true) { db->num_insns++; ops->insn_start(db, cpu); tcg_debug_assert(db->is_jmp == DISAS_NEXT); /* no early exit */ + if (plugin_enabled) { + plugin_gen_insn_start(cpu, db); + } + /* Pass breakpoint hits to target for further processing */ if (!db->singlestep_enabled && unlikely(!QTAILQ_EMPTY(&cpu->breakpoints))) { @@ -99,6 +107,14 @@ void translator_loop(const TranslatorOps *ops, DisasContextBase *db, break; } + /* + * We can't instrument after instructions that change control + * flow although this only really affects post-load operations. + */ + if (plugin_enabled) { + plugin_gen_insn_end(); + } + /* Stop translation if the output buffer is full, or we have executed all of the allowed instructions. */ if (tcg_op_buf_full() || db->num_insns >= db->max_insns) { @@ -111,6 +127,10 @@ void translator_loop(const TranslatorOps *ops, DisasContextBase *db, ops->tb_stop(db, cpu); gen_tb_end(db->tb, db->num_insns - bp_insn); + if (plugin_enabled) { + plugin_gen_tb_end(cpu); + } + /* The disas_log hook may use these values rather than recompute. */ db->tb->size = db->pc_next - db->pc_first; db->tb->icount = db->num_insns;