From patchwork Mon Jan 22 14:56:10 2024 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: 13525619 Received: from mail-wm1-f52.google.com (mail-wm1-f52.google.com [209.85.128.52]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 989A645C1D for ; Mon, 22 Jan 2024 15:01:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.52 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705935692; cv=none; b=R84kVX9rrz/+J+cmD5Bk0EI7gK43Jr0xV4JGCBMJ+qoB6G1nrIjgEEB/qutcg8YkIAJi1UqnAACwuGZ+C89agHOOIlrUIyyvvmc5R5ACJhk3nXBR+AK9I+Ds/pnhwb/uqysFk8nzaO7SwVyXAGuLX+gpasFLuE+LsZWr03NDSws= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705935692; c=relaxed/simple; bh=I9heYG1ZCRndjP2m4FuccJ3EDDRfFtvTj6b9pH35Gms=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=bnM+CstrD3BnsWTfEL12mj5AfomSrFo0IqdmyyBP3kIp5hZszroMe1/vGFEwDYlmV6fY3E1CL6gan5YV2QwKU2fJofJRgQmG1uIQaQAYzXCUQ7pR+jyzcGAmxQMLmf3j/os5Eig8eaz7GuJNZcFJZofnA/zh9k02qzdjntJQtQc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=Lgzn3/+2; arc=none smtp.client-ip=209.85.128.52 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="Lgzn3/+2" Received: by mail-wm1-f52.google.com with SMTP id 5b1f17b1804b1-40e8fec0968so42340005e9.1 for ; Mon, 22 Jan 2024 07:01:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1705935689; x=1706540489; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=zMZ+pFdg1P4n/cHnfp4DZXoxUsYEnk+lXnRUtGdShK8=; b=Lgzn3/+2RL+/jTMGBHmPCLf9rxPQaKOlBFhLjSidaJJMxKhs70CH/qlfXPTI+E5yvE 5K7STa64T9Cuos0iRCt13kX25XkEDZhGy092qUre/kGR6xTXlT0UI18euhO2gUlRwoFA MqppjeF9VgOqbdckjYmoGz8EGviNmWnLSMJxO1x6w5oTHEqqgkMmGBns8zm53hOSYNG7 nszsvs296EUiOCDDykRkfS/wwC8AspkDJWIArVHziMdyZ8TN3vmX01KBYc72r+s9IfwV 8VrMKcV6R+o+9E/xjwsTeBgbd5FjF33pbkztYTdqdc3nvDPox+3vikWIRWfX/br9AwZz 21NQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1705935689; x=1706540489; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=zMZ+pFdg1P4n/cHnfp4DZXoxUsYEnk+lXnRUtGdShK8=; b=h2/h7jjj0/mzUoo5UDQxCG8s9WaVb9tI3huJXUgOx53ThIu5hxp8m+jfHItPHuDy2h 7oSj0RFRzqBiQHXw97BAWltu9CC6X9DmMzeqXW+PLmOb6QPkm94hdI78A9TGiRkxVweI 1On9kzWVbbd8rdxMVp/qEuGCA6aR3ucx/3na3fXpgZuMXeNIg+UxiU+TEspgMbdrm8q9 yhC5qxSDMExn1jHpcD6T1OypIOy/4sZ+kj77O92DENkfVTqCgDsvaDcu3xAWNaxuwsKB CUp+vKNcAVOJ5vbeRR0b2oN3iNTlJCVLuFB4aRL3kde3AhjWNDz7amFxJzDGgJpiguhE KGjg== X-Gm-Message-State: AOJu0YwL11I9+3ktKW4UTGU6ak8vvHXOn4DQRE6u6xknfuAp4Iq6Nrd2 TBEvHBWIjfHLkzTo4X/v1pIa1hs2w10EB4vjbfa0b3pj1s65a6aYfzfmYAxwIbk= X-Google-Smtp-Source: AGHT+IFPIr2Ee0y73303g5cCda6EprIxJ9AwU9+gItZXvCJzsVuJi+g6jnLnWq7qRPmBEAJUswV1Ew== X-Received: by 2002:a05:600c:4f10:b0:40e:b0ec:e98c with SMTP id l16-20020a05600c4f1000b0040eb0ece98cmr456950wmq.139.1705935688372; Mon, 22 Jan 2024 07:01:28 -0800 (PST) Received: from draig.lan ([85.9.250.243]) by smtp.gmail.com with ESMTPSA id t18-20020a05600c199200b0040e5951f199sm39123604wmq.34.2024.01.22.07.01.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Jan 2024 07:01:27 -0800 (PST) Received: from draig.lan (localhost [IPv6:::1]) by draig.lan (Postfix) with ESMTP id 3642F5F9D5; Mon, 22 Jan 2024 14:56:13 +0000 (GMT) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: Marcel Apfelbaum , "Edgar E. Iglesias" , =?utf-8?q?Philippe_Mathieu-?= =?utf-8?q?Daud=C3=A9?= , Michael Rolnik , =?utf-8?q?Marc-Andr=C3=A9_Lureau?= , Laurent Vivier , kvm@vger.kernel.org, Yoshinori Sato , Pierrick Bouvier , Palmer Dabbelt , Liu Zhiwei , Laurent Vivier , Yanan Wang , qemu-ppc@nongnu.org, Weiwei Li , qemu-s390x@nongnu.org, =?utf-8?q?Alex_Benn=C3=A9e?= , =?utf-8?q?C=C3=A9dri?= =?utf-8?q?c_Le_Goater?= , Peter Maydell , Alexandre Iooss , John Snow , Mahmoud Mandour , Wainer dos Santos Moschetta , Richard Henderson , Ilya Leoshkevich , Alistair Francis , David Woodhouse , Cleber Rosa , Beraldo Leal , Bin Meng , Nicholas Piggin , Aurelien Jarno , Daniel Henrique Barboza , Daniel Henrique Barboza , Thomas Huth , David Hildenbrand , qemu-riscv@nongnu.org, qemu-arm@nongnu.org, Paolo Bonzini , Song Gao , Eduardo Habkost , Brian Cain , Paul Durrant Subject: [PATCH v3 21/21] docs/devel: document some plugin assumptions Date: Mon, 22 Jan 2024 14:56:10 +0000 Message-Id: <20240122145610.413836-22-alex.bennee@linaro.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240122145610.413836-1-alex.bennee@linaro.org> References: <20240122145610.413836-1-alex.bennee@linaro.org> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 While we attempt to hide implementation details from the plugin we shouldn't be totally obtuse. Let the user know what they can and can't expect with the various instrumentation options. Message-Id: <20240103173349.398526-44-alex.bennee@linaro.org> Reviewed-by: Pierrick Bouvier Signed-off-by: Alex Bennée --- docs/devel/tcg-plugins.rst | 49 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/docs/devel/tcg-plugins.rst b/docs/devel/tcg-plugins.rst index 535a74684c5..9cc09d8c3da 100644 --- a/docs/devel/tcg-plugins.rst +++ b/docs/devel/tcg-plugins.rst @@ -112,6 +112,55 @@ details are opaque to plugins. The plugin is able to query select details of instructions and system configuration only through the exported *qemu_plugin* functions. +However the following assumptions can be made: + +Translation Blocks +++++++++++++++++++ + +All code will go through a translation phase although not all +translations will be necessarily be executed. You need to instrument +actual executions to track what is happening. + +It is quite normal to see the same address translated multiple times. +If you want to track the code in system emulation you should examine +the underlying physical address (``qemu_plugin_insn_haddr``) to take +into account the effects of virtual memory although if the system does +paging this will change too. + +Not all instructions in a block will always execute so if its +important to track individual instruction execution you need to +instrument them directly. However asynchronous interrupts will not +change control flow mid-block. + +Instructions +++++++++++++ + +Instruction instrumentation runs before the instruction executes. You +can be can be sure the instruction will be dispatched, but you can't +be sure it will complete. Generally this will be because of a +synchronous exception (e.g. SIGILL) triggered by the instruction +attempting to execute. If you want to be sure you will need to +instrument the next instruction as well. See the ``execlog.c`` plugin +for examples of how to track this and finalise details after execution. + +Memory Accesses ++++++++++++++++ + +Memory callbacks are called after a successful load or store. +Unsuccessful operations (i.e. faults) will not be visible to memory +instrumentation although the execution side effects can be observed +(e.g. entering a exception handler). + +System Idle and Resume States ++++++++++++++++++++++++++++++ + +The ``qemu_plugin_register_vcpu_idle_cb`` and +``qemu_plugin_register_vcpu_resume_cb`` functions can be used to track +when CPUs go into and return from sleep states when waiting for +external I/O. Be aware though that these may occur less frequently +than in real HW due to the inefficiencies of emulation giving less +chance for the CPU to idle. + Internals ---------