From patchwork Thu May 30 17:49:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Pierrick Bouvier X-Patchwork-Id: 800199 Delivered-To: patch@linaro.org Received: by 2002:a5d:65c4:0:b0:35b:5a80:51b4 with SMTP id e4csp358938wrw; Thu, 30 May 2024 10:51:36 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCWJpfzvpx9YtLJZxp+DqxPlCvh3iXjXb5k2j0+dlNKSyw8Nv+46KcBBymUZHN4ZldeYqXAVV5w0+25Bh3VwUub3 X-Google-Smtp-Source: AGHT+IF9FMVTrAz+T0TYnaKe80QpESubZ2FBFWPe27xDgb7IxXerGu6jLBbW9ts/De4eSFh4l736 X-Received: by 2002:a05:620a:254b:b0:792:a252:befe with SMTP id af79cd13be357-794eb05d237mr505009385a.38.1717091496339; Thu, 30 May 2024 10:51:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1717091496; cv=none; d=google.com; s=arc-20160816; b=KE4sD2ppcugks+CvCInMUjsvyqQJbEDq5/Yw6R2PPA4xLS/9OFTozj0N4hV+mzLrpE 9ckwmtc/hm41D9CnbDkPwxnfLSvC8UEn9jJBOw+TFaOrmQ3Wm18949OTjBIH/8OYbD9D bBvF0kgk0G02L+WuKueKBxbIAahMLqjvzMcmisSOCLXEjzPVlYyKdd6RIjEXAnHJzXdy UoT+CSHjEvilpVoRLdIzenR5j5wbZuIpH0uIIKnCwXRWfhCQjoUORlRkS8z0S2tIGNi0 zmHRX3wlQdnFJCm8lhuv/a+2yNNyMvJ0JG1ZXDZCMElVIznc5fDuWwWZkUXbVpHObSVA 99Iw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:message-id:date:subject:cc:to:from:dkim-signature; bh=a4MeqareKGtE2HuqvJKUzQo7r7KOKpQtZ4BHRcp8E9o=; fh=cf3Q/5dJyAanhqpbGSZv6kxpEC/hZ4CRqZ3z5yvqhQw=; b=HGt9+XDONXxfHRRz1EWGYBlgJCgcUpkOElbmPTS9adubq6MZlvz9iAZa/Vt/aXizW+ tXbuzCjkF2p8Jw/7seu2kFQJOPTU4n7XKj7xphU4C3LWy6QGFGdz/7PC5BhhqcGDpfGk 0+EEwx2sx0uYlflhihgxYFG2K2sPPTIWla73RxOrtWwz6718hQB/ZoC7zVQhknjb4iIN mzDBrBAUSKObGXDFwF1wTxWBa6ViW4Wdz5IZB+tMvdPbo78LlsnyZz+3hr9uru8wYgpu Y37Z6x9zk6LSLnhWe/fVyJpHywl5InDuO77pK97l/gT3OH3Mfdak5s3VLumZwmXsye8E UwlA==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=hD7zCwFl; 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=pass (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 af79cd13be357-794f3064f32si6493385a.230.2024.05.30.10.51.36 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 30 May 2024 10:51:36 -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=pass header.i=@linaro.org header.s=google header.b=hD7zCwFl; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sCjuY-0003s4-8j; Thu, 30 May 2024 13:49:58 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sCjuW-0003r2-KP for qemu-devel@nongnu.org; Thu, 30 May 2024 13:49:56 -0400 Received: from mail-pl1-x630.google.com ([2607:f8b0:4864:20::630]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sCjuR-0002S0-Tu for qemu-devel@nongnu.org; Thu, 30 May 2024 13:49:55 -0400 Received: by mail-pl1-x630.google.com with SMTP id d9443c01a7336-1f48e9414e9so11138215ad.0 for ; Thu, 30 May 2024 10:49:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1717091389; x=1717696189; darn=nongnu.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=a4MeqareKGtE2HuqvJKUzQo7r7KOKpQtZ4BHRcp8E9o=; b=hD7zCwFlRe3noZjfBJnnSyM4ezot0RWDPA3raA+6q2B/sYq6ehh3UfCtw2+TjlZO7J M9QTisENX/lPriGjC3uOGDcVhlXsTJ5uX0MIIlwdNwohanYz6remozY9wI8bXot8eF1m lDUjltBAYDaIu+Qh7xwkN85540DYFvQtj9cIpjzXT87HkPPIxgfHPt5tA8bR1wIfnUzK fe/bBPiadXx+tIITGC6bv0oCPp6BQdgrjHT43YLaUiWw+090Q19wVHdR/T7bLHhzc0Pz CWiyrS80LSvgxA/lsOviXxvPk7mf6PBXkke7vogE7XSX0sJft7tkq0K27KG+/DguyG2H mprA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717091389; x=1717696189; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=a4MeqareKGtE2HuqvJKUzQo7r7KOKpQtZ4BHRcp8E9o=; b=F6cO1s08ZAIH+ZhXBJ1ueR6ndo1kZixSi4tDh3j85vnQL6JTRS8U97aR59i8ul5DBT 7srp+8MA9W3Asu2J7SG9GlJasWg1Iq8ujCwivzGR19dinmFTdqEV4Ukll6x/BillNcmQ ChPLFA4ldOkMMNXZeg9ay/Dp4i89jQ6tNiTFk9bUCtG0tLMgLSlKSoY7DWI9q5CPd4eu FTMjET+dNgGRhmIXpxHqf1j1O8wd6JV7ICTBMJCrLc/f7eXWfdjlI1FcTdCGYwohxMxe X5WaKTsp/r23y3zWSbbXb0YxbH1ABp5giAHOgoXU2VfM/h/b4L1nQJtG/1FMhO61fTek J7XQ== X-Gm-Message-State: AOJu0YydTkk2YgacVKD2FuJVd/S9s/25diVKMVsrTFEVVc26cNu10WhO BL2JtPKdUgoJzd0cD23lrDbW+ynyBh/LgJrT1CNUbmUI4fvHygCOnnTzwdFYcwEiU7XC7v7rh+S m0Nk= X-Received: by 2002:a17:902:cccb:b0:1f4:75ec:9968 with SMTP id d9443c01a7336-1f61be6be90mr40380465ad.16.1717091388788; Thu, 30 May 2024 10:49:48 -0700 (PDT) Received: from linaro.vn.shawcable.net ([2604:3d08:9384:1d00::e697]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1f6323deb38sm590405ad.124.2024.05.30.10.49.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 May 2024 10:49:48 -0700 (PDT) From: Pierrick Bouvier To: qemu-devel@nongnu.org Cc: Richard Henderson , Laurent Vivier , =?utf-8?q?Alex_Benn=C3=A9e?= , Thomas Huth , Alexandre Iooss , Mahmoud Mandour , Paolo Bonzini , Pierrick Bouvier Subject: [PATCH v2 0/6] Implement icount=auto using TCG Plugins Date: Thu, 30 May 2024 10:49:33 -0700 Message-Id: <20240530174939.749163-1-pierrick.bouvier@linaro.org> X-Mailer: git-send-email 2.39.2 MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::630; envelope-from=pierrick.bouvier@linaro.org; helo=mail-pl1-x630.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org The goal here is to be able to scale temporally execution of qemu-user/system, using a given number of instructions per second. We define a virtual clock, that can be late or in advance compared to real time. When we are in advance, we slow execution (by sleeping) until catching real time. Finally, we should be able to cleanup icount=auto mode completely, and keep icount usage for determistic purposes only. It is built upon new TCG Plugins inline ops (store + conditional callbacks), now merged on master. Example in user-mode: - Retrieve number of instructions to execute /bin/true $ ./build/qemu-x86_64 -plugin ./build/tests/plugin/libinsn.so -d plugin /bin/true cpu 0 insns: 120546 total insns: 120546 - Slow execution to match 5 seconds $ time ./build/qemu-x86_64 -plugin ./build/contrib/plugins/libips,ips=$((120546/5)) /bin/true real 0m4.985s v2 --- - Added missing personal Signed-off-by for commits from Alex - Fix bad rebase in stubs/meson.build - move qtest_{get,set}_virtual_clock to accel/qtest/qtest.c - A race condition was identified for plugins init/idle/resume, but is not related to this series, and will be fixed in another one: https://lore.kernel.org/qemu-devel/20240529152219.825680-1-alex.bennee@linaro.org/ Alex Bennée (4): sysemu: add set_virtual_time to accel ops qtest: use cpu interface in qtest_clock_warp sysemu: generalise qtest_warp_clock as qemu_clock_advance_virtual_time plugins: add time control API Pierrick Bouvier (2): qtest: move qtest_{get,set}_virtual_clock to accel/qtest/qtest.c contrib/plugins: add ips plugin example for cost modeling include/qemu/qemu-plugin.h | 23 ++ include/qemu/timer.h | 15 ++ include/sysemu/accel-ops.h | 18 +- include/sysemu/cpu-timers.h | 3 +- include/sysemu/qtest.h | 2 - accel/qtest/qtest.c | 13 + contrib/plugins/ips.c | 239 ++++++++++++++++++ plugins/api.c | 31 +++ ...t-virtual-clock.c => cpus-virtual-clock.c} | 5 + system/cpus.c | 11 + system/qtest.c | 37 +-- util/qemu-timer.c | 26 ++ contrib/plugins/Makefile | 1 + plugins/qemu-plugins.symbols | 2 + stubs/meson.build | 2 +- 15 files changed, 389 insertions(+), 39 deletions(-) create mode 100644 contrib/plugins/ips.c rename stubs/{cpus-get-virtual-clock.c => cpus-virtual-clock.c} (68%)