From patchwork Mon Oct 14 10:49:28 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: 176184 Delivered-To: patch@linaro.org Received: by 2002:a92:7e96:0:0:0:0:0 with SMTP id q22csp4386112ill; Mon, 14 Oct 2019 04:33:22 -0700 (PDT) X-Google-Smtp-Source: APXvYqxOWy44aOg6pQVz+RBPc6SaOkfo0BfkA+OtNUCzg2OGvODjweCVI/ERKWAy9IMOP5xdMD2e X-Received: by 2002:ac8:729a:: with SMTP id v26mr31219096qto.18.1571052802199; Mon, 14 Oct 2019 04:33:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1571052802; cv=none; d=google.com; s=arc-20160816; b=DyGrwSD30r0Rvc05B8duNjxMVWXgmBFUez1BWusqow+C9QKdnKaZKisIoVuDl6bgss 39i25Cp88e16xHC9/EcJJbH0gmseYWuNEXgQ/3hFK2lCZYMGc1wTIXvDnlgTzeFYeQNI iQyzmi3FPOEAjtbSn+M3Ot+fVGMdfmoNMHedWx4CfV43zMuPIwSjk8aifBfjZpZmD8Y5 bAbdItM/X8xAv8zb3aEx+JQuDXl4ySb13SIfqyQPQ+tYc9xJWqNdFKbtXd0UN1a2kr9Z HBD5gT63uLnmG+Id8G9lDK3hyvF1VQxGieEXFWYV2e7vOvbFcl4V5is/TmJ7V3VFkITV LnBg== 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=coCttQh1DJ7CtKBy6WU9Qj5nCrM3kKgVRgB552jvYCY=; b=x7tvs4TRNHKgcLeF9oz04pifDsLP8ZaHE8x33GMBEi3vWHhrss5lqAIZnleZ6xcGIf 6ZXo6bRY1ft/B7P3zdGd3BFD8V63fCEdwHUvdrfvMdE69K3yPlqUcqOcnODh5/QaNOhN +BR3/HrryjErjfLNJNmX+mgH4GYFct6QmHQI0lpeiW0HwlhC4Y9f4no5BZ+SOFAnfLjQ UGj4Al/kovKxL99s5FGlYnKt8joiscX8SFlBimwWer7LrXsT15sXf13osyxziJfx8sAJ T7yP0ghhsygtXl8+jld7GqAHW6TzYVDi5sj49HX9WSeLy9e/CqbWixyvvxIluBDQUZsH umDA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=PBsiOf7K; 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 v129si15651762qka.262.2019.10.14.04.33.22 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 14 Oct 2019 04:33:22 -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=PBsiOf7K; 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]:47860 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iJybJ-00039V-E7 for patch@linaro.org; Mon, 14 Oct 2019 07:33:21 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:46751) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iJyBk-0007g2-4X for qemu-devel@nongnu.org; Mon, 14 Oct 2019 07:06:57 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iJyBi-0007An-SU for qemu-devel@nongnu.org; Mon, 14 Oct 2019 07:06:55 -0400 Received: from mail-wm1-x343.google.com ([2a00:1450:4864:20::343]:37661) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1iJyBi-00079d-Lg for qemu-devel@nongnu.org; Mon, 14 Oct 2019 07:06:54 -0400 Received: by mail-wm1-x343.google.com with SMTP id f22so16304920wmc.2 for ; Mon, 14 Oct 2019 04:06:54 -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=coCttQh1DJ7CtKBy6WU9Qj5nCrM3kKgVRgB552jvYCY=; b=PBsiOf7KV3rByI4fr27OGVvzX2cIiiioQ+aj1OCgo/vWt8f7JUhVq195VrAUr3JVkv QyC3rjZn0ckqYVV6ulDMH2hcTBW4K9WCeZ9hj/n1a6ZXZBCmzsXKbJVhHJZLrWjaVpVI Wna6aoYkX1CNrxDAEjkSiLzD7toTorLzZlliokwnkG7Xp6WcAkqx1Xh0ZuNElMz5/kqH soSGGwMmfgW0C1TJXTpymRq+UeOhac0CGJrN22XaFIKjSRWnGwsEvVBUYNak0guAmU02 aG4LuL4DmN4hTdIICNzSHzaZY6FHDWJELFftNkJhhP8f1GMSCW1h/GAZWkq/4Z456EWK xssg== 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=coCttQh1DJ7CtKBy6WU9Qj5nCrM3kKgVRgB552jvYCY=; b=eetowDrgS/Y0IzwFBsaiS5/48d1o+r4hLkVBkrCIH/xigBf2+bf7X3RMGC/aLPRnES PNljE1SrSo76BAtpYhkmQpy4hmgGjg6bnIIBRBliNR7A2iceSGHCVp+WPLkfPkkVOPY0 yJX1aWhRyb1PW0OlozHlhWGvFV8XIf7VcowI9oODbWDh292tQWuT+MF+T2rXh3fFkwcT Hnkbmt2+yxTIMpdHg0LMSJ1Asdici1KJjkrXcUIpA6RRUQ8hdQr6Hbcf4kU90VCCx7pH L05K6sKwLFtXZ21z/b6sSb3cWkW87SbmuahyUXSDTUw1zrrxeDVk8FGnVlWRtMECTnrh dNYQ== X-Gm-Message-State: APjAAAXZK4ZoBVFJfjvcJDCFypXWZd8FwlgxYgYs29u/jwzb9DBKuz+l R8ytUCeY/OrFslv4B6IuGOCFcA== X-Received: by 2002:a1c:7e10:: with SMTP id z16mr14087292wmc.11.1571051213375; Mon, 14 Oct 2019 04:06:53 -0700 (PDT) Received: from zen.linaroharston ([51.148.130.216]) by smtp.gmail.com with ESMTPSA id r3sm4014734wre.29.2019.10.14.04.06.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Oct 2019 04:06:52 -0700 (PDT) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id DBBBA1FFC1; Mon, 14 Oct 2019 11:49:56 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Subject: [PATCH v5 35/55] translator: inject instrumentation from plugins Date: Mon, 14 Oct 2019 11:49:28 +0100 Message-Id: <20191014104948.4291-36-alex.bennee@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191014104948.4291-1-alex.bennee@linaro.org> References: <20191014104948.4291-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::343 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: robert.foley@futurewei.com, Richard Henderson , peter.puhov@futurewei.com, aaron@os.amperecomputing.com, cota@braap.org, 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 --- v4 - note we can't inject instrumentation if ! DISAS_NEXT --- accel/tcg/translator.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) -- 2.20.1 diff --git a/accel/tcg/translator.c b/accel/tcg/translator.c index 70c66c538c..f977682be7 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;