From patchwork Wed Jul 31 16:07:07 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: 170158 Delivered-To: patch@linaro.org Received: by 2002:a92:512:0:0:0:0:0 with SMTP id q18csp4224808ile; Wed, 31 Jul 2019 09:18:26 -0700 (PDT) X-Google-Smtp-Source: APXvYqyFxTjwJcdqj7tDv0f6+BkHtwZuXmRnPDr9utiMUKM8w3bFNYGt/9QI/5XW4KJLwjoGHpRu X-Received: by 2002:a05:620a:1006:: with SMTP id z6mr48540558qkj.312.1564589906383; Wed, 31 Jul 2019 09:18:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564589906; cv=none; d=google.com; s=arc-20160816; b=PdPtDpQ2dPPbi4VPKtHGEqj5gFEsiaE1Qkwfl1pU2b/abWEOC3beTSp7wLfsuLkoM9 F0HDxy07AHhQXIYisbRcLDrPg95agFEwc004E6+zEqfp2najyRHPRPj67ufmhkFAK5Z9 B+52/yrJdfcwwRY61Vdvg/vc+rGKEkT9nmJ9yRZTaA7AQYqGNcMqeEh52+pt5aEtriG3 BNHSMOCxRPj3FlhrvXeNpBN1fnswwHUMATHZIMhA323GlGuyzAAMDqTjCvCSRzyKdgLN WSfn09f51/GgBPPABr3qN6xohAXD8BlhCuHXqzdUflq8KHB82C83SWuA5bVB5KRac1gc qfuw== 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:subject :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:to:from:dkim-signature; bh=NeBjS48hgLPnN+/FAA6/R9TYKzQRsPV0AVfEZ4tlPs0=; b=iO5M0RIZvdvbHivzwQtrGrw2xlQmVjgD0wKaf9+vBxwY5QoRaFWdiyEAl6jsAkbY12 pC7YD3zt7ktmRAOZ/h0ogdcicWoGdvob7AoHlewqvUgyQsQJ9N4MFokeRkE+zzL4ysVE juf2xxe3ZnVrECUbrD7q5Ko5zjHnucgvEvngnst3S/OLT9hHaFm9xB9+wL+i8xTZuMUt MCDDQ/FsOkRczKLLCdwupssAi/MS/pA6TlzGNt6qi2EWFDlSAhD3vNtTB3GHjUxAlBdg 541FjmdmBbc+N9Q4MKc2ywQdDxQIxPc+YOCaIZwhISCx5bpLy3VFpxCNyZ+PXUpilyEK bkuw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=awe2Z7+U; 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 h67si39247187qke.108.2019.07.31.09.18.26 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 31 Jul 2019 09:18:26 -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=awe2Z7+U; 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]:42476 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hsrJ3-0003aY-T4 for patch@linaro.org; Wed, 31 Jul 2019 12:18:25 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:42328) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hsrG5-0005pP-OK for qemu-devel@nongnu.org; Wed, 31 Jul 2019 12:15:22 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hsrG3-00048O-Od for qemu-devel@nongnu.org; Wed, 31 Jul 2019 12:15:21 -0400 Received: from mail-wr1-x442.google.com ([2a00:1450:4864:20::442]:36708) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hsrG1-00046M-Mj for qemu-devel@nongnu.org; Wed, 31 Jul 2019 12:15:17 -0400 Received: by mail-wr1-x442.google.com with SMTP id n4so70412820wrs.3 for ; Wed, 31 Jul 2019 09:15:16 -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=NeBjS48hgLPnN+/FAA6/R9TYKzQRsPV0AVfEZ4tlPs0=; b=awe2Z7+UteZ1OleIoymnp2TEcFmXxOeCtR8TTDIqq3AsphDj/P1onA61KvN9yMF7Sc qAsURm5ljRnRGJmUorKK3GksZ2rOSvkUFREGrg1G5a8hUDSyX7Hqu4MWJ3C/5vRifr1g vAN2X8rNbVYxGooWneSnVlR5d8YUNV0xq1qGRe9SdBm9r2CEgJNHbzl+DPkkGlvJvnA3 Qw747TQcSDd+wp7rk25MdhzuYQqLArUaT0URpXn1LIebxTvasytbyL50Lxsu+CcYVLHq R5VLliTFFiuGsA84SVOcHX8ixhhjU8NSUneqfcHiVu1ldVnfpROHW2FQdhA2IipWTWn8 EitQ== 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=NeBjS48hgLPnN+/FAA6/R9TYKzQRsPV0AVfEZ4tlPs0=; b=gw/yo1bApCfMtQTDFWZXs8eINRKG/qBHsFqS7QL2ImGeRdwN52U2ovKmlKKISSIjKT 2aOYrIHwBWagSHqBxpR+vTDedWZFHQTiyiWWFA5V35z2TAraIEuIWyDfEQxkSPt3Mjgl hWf5Rfj8S6YYUs7HIMPFvMb24aSX6m77aJOR006KnQ1O6j0+qiWHCe07mYYPTKyjpScK e6f8Gdnr5v7MxU9FmqkXyU2Bav/Dwr6sPLpVSk3v4TXEmNdIJhMv/Kx8sSvk9x9QESYu rwP8R5w6eI8UkKH1R+FsPnWsDRXMn+UGVGdQhUIuZan/K7eQx6NKG1px8wLJaZIICNnx H43Q== X-Gm-Message-State: APjAAAUtTpSHElD0go5uMEitePTxy8GgPmn5GCPYosLFrZTuJWJz0Aw/ bV2WVTPFlBhmscO76EX3dnBDug== X-Received: by 2002:a5d:50d1:: with SMTP id f17mr4932906wrt.124.1564589715274; Wed, 31 Jul 2019 09:15:15 -0700 (PDT) Received: from zen.linaroharston ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id x6sm71886710wrt.63.2019.07.31.09.15.12 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Wed, 31 Jul 2019 09:15:13 -0700 (PDT) Received: from zen.linaroharston. (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id 5D2141FFC0; Wed, 31 Jul 2019 17:07:23 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Date: Wed, 31 Jul 2019 17:07:07 +0100 Message-Id: <20190731160719.11396-43-alex.bennee@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190731160719.11396-1-alex.bennee@linaro.org> References: <20190731160719.11396-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::442 Subject: [Qemu-devel] [PATCH v4 42/54] translator: inject instrumentation from plugins 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: aaron@os.amperecomputing.com, cota@braap.org, Paolo Bonzini , bobby.prani@gmail.com, =?utf-8?q?Alex_Benn?= =?utf-8?b?w6ll?= , 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 --- v4 - note we can't inject instrumentation if ! DISAS_NEXT --- accel/tcg/translator.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) -- 2.20.1 Reviewed-by: Richard Henderson diff --git a/accel/tcg/translator.c b/accel/tcg/translator.c index 9226a348a39..4e30772f8cb 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))) { @@ -100,6 +108,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) { @@ -112,6 +128,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;