From patchwork Thu Oct 17 13:15:55 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: 176654 Delivered-To: patch@linaro.org Received: by 2002:a92:7e96:0:0:0:0:0 with SMTP id q22csp984198ill; Thu, 17 Oct 2019 07:11:08 -0700 (PDT) X-Google-Smtp-Source: APXvYqx5NSiltdHsZezWpq2+m4OhRWufpaEdE5uz0UW82mgTzlL9BiEqYTgccZmV9bBFd8fpwItI X-Received: by 2002:a17:906:46db:: with SMTP id k27mr3664749ejs.308.1571321468093; Thu, 17 Oct 2019 07:11:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1571321468; cv=none; d=google.com; s=arc-20160816; b=rV/ngWLI4Jvd0D9uQbRWrowhuenFVEHe08mKY5mkei9k2Uo3P1Nx4ozeLFgXD/p31Q WcTr3QdxKXxKZkP7mfBHOuNBmQkucKWSX+wBXQoDSOGFp/2rw0IvZTXbn4Mtw+34Av3I Idkk/NreZZq2mvgSJVVJ7rjCQ6fY7adOAWgHFxrquxvvm15PDZrEdwOgrP7Y6B6i1XOW yIZOQUR6LUJ3HDdw2yMW9+NcUqDKQK6LmSbU9CMgwqlOGXrxTSGDK+5xNKV1HkDURJF9 aMHPhy+6+WOVS7wx2uW94oZnUJd8m52/SfxNS9GOyb9rtZuCqNE0DeWkJqveJJALJK3r 0rgg== 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=IPo+YlRUqX+T+H73IM5+P2UqJCMzFGx1cxsdRA9PqCyTwMEhxYm4CtnuP/vVgszsy5 MDKIJfo/OSkCQZJcHX5GBA7vBWyLctul5YkTIp3bsD0Dkc7AP5hrmiyzHFFvuYfv22xy 5KVi6xkqMpAGeSF3P/9zn0jot6ZD5Guq+ikCM9tbbxB6MHPTXss1zOW4UxkJeSe0LjNQ tdcnRH97N1CR7uPvDlXC5Y4Mg1urHHGkZ/c+5U/fMKvsvqp5giBZsC6XMFya/WtXhfxr 3s4igty/ZwLs7ynLeXmZb3A4wjHTM0R65MYWg6IE+zQNXkqXtI3zDYxjETSnzB/tl9Oc Mhsw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b="gTC/wLzq"; 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 p14si1544231edc.227.2019.10.17.07.11.07 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 17 Oct 2019 07:11:08 -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="gTC/wLzq"; 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]:48844 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iL6Uc-000688-JY for patch@linaro.org; Thu, 17 Oct 2019 10:11:06 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:35572) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iL5mV-0002Hv-Jk for qemu-devel@nongnu.org; Thu, 17 Oct 2019 09:25:32 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iL5mU-0001I3-Ck for qemu-devel@nongnu.org; Thu, 17 Oct 2019 09:25:31 -0400 Received: from mail-wr1-x444.google.com ([2a00:1450:4864:20::444]:41611) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1iL5mU-0001HT-6U for qemu-devel@nongnu.org; Thu, 17 Oct 2019 09:25:30 -0400 Received: by mail-wr1-x444.google.com with SMTP id p4so2344300wrm.8 for ; Thu, 17 Oct 2019 06:25:30 -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=gTC/wLzqjCaPyNsmujQWYX6qTv2sonKaQAn7gL9XcAzvz1lb4UtYLF7etsv3JgiYkr 5Y02mFxVwxpIgC/kYuYBgPo4uRBCvSIrvjGW2VDJSH2H5mCHHIRf/1+tSHpF7INqM8z7 vKhEJccpj3ro3y8cn7VfE9sfpsoAgfmDxuhPnnzfm1Mxekr73cYgBfv4d/FKWsn3uQdf BEynaCYg1qNotyx8zUTGgqozuk9WIua0SQwP/NFN+zQCimozZBJ5GBTrpQS8j4WIq2mA hgTjLcFOxeoYph5C31s5NJotxBpveNT8UNzeZ9oTmuPfBMr0/t5kQ4vXLCgVHzHLGVPT RS/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=coCttQh1DJ7CtKBy6WU9Qj5nCrM3kKgVRgB552jvYCY=; b=E8m4AdzFk1HgsfWQ+GUAC4Ed6tHQcb6ujT3yHetroXI9fNf76P6tYOlhn5FBTcZz8u T3HWJ3KzVkKysqoxeOajBr/ljQXoojt9MmpoFXC1f0I/JVQvtYh+iBbutuKp6IX7Us7f JLHj7S/lpawln0YER0qeKwVbzm6g4rzJpa4XaAPQ/StqJUgg8mBWUBe6OtmaVOSmnFw3 6PeacVDw3rBNLhunnMBjyKlu+zvApJGPm3Tf3rq+gNlhb4b9u/FvDHu6CHi4WzbFqvE4 FyfiJEFIULe5yHLbEGSEHlnIcHfd88FhZv1aLInsrOrlYruG46DIR83LA0k7Qenk5We/ VRvA== X-Gm-Message-State: APjAAAXIdFZLJ2u7Rwti/Np8pvKCn7rNZRFM09FD5VraFS0TopfgfvRy TH0zmL96zlAoCZiDNGF13a0NuZo6og4= X-Received: by 2002:a5d:544b:: with SMTP id w11mr1484484wrv.205.1571318729110; Thu, 17 Oct 2019 06:25:29 -0700 (PDT) Received: from zen.linaroharston ([51.148.130.216]) by smtp.gmail.com with ESMTPSA id z1sm2115475wrn.57.2019.10.17.06.25.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Oct 2019 06:25:25 -0700 (PDT) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id 142581FFBA; Thu, 17 Oct 2019 14:16:19 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Subject: [PATCH v6 34/54] translator: inject instrumentation from plugins Date: Thu, 17 Oct 2019 14:15:55 +0100 Message-Id: <20191017131615.19660-35-alex.bennee@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191017131615.19660-1-alex.bennee@linaro.org> References: <20191017131615.19660-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::444 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;