From patchwork Thu May 30 22:06:04 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Pierrick Bouvier X-Patchwork-Id: 800211 Delivered-To: patch@linaro.org Received: by 2002:a5d:65c4:0:b0:35b:5a80:51b4 with SMTP id e4csp447976wrw; Thu, 30 May 2024 15:07:10 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCXpC1HtMjmKBSgVCpwI3Xmxj9A8DQxSclJdV6cmP6LDicfx0X9SO1Y5OpdSZPbhD+yM1z977UDF9mHB85Qdnjq1 X-Google-Smtp-Source: AGHT+IEMOmSuxupRs0XciccrRELqlTWRQBT/v5XpDQ121fix6MrnCw7tdew0NthenuocbQ2ytAAU X-Received: by 2002:a05:6870:219e:b0:22e:8408:a98f with SMTP id 586e51a60fabf-2508bbd8fa6mr197851fac.36.1717106830518; Thu, 30 May 2024 15:07:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1717106830; cv=none; d=google.com; s=arc-20160816; b=hwifWXr5HdRD2IfB3mqVNIfnavjupbulRjtN9av55JDk6ya/+IZhrnWkSQTP9EvKGX zNDNumKNem+IF7wyx0E/SyMAXp0nSJr69tUHkKwrXZpDXVg2y5UKuP0nWbkIBN9jGgbQ XNP1RyUeXW7ZQNcxLHBoODpGCdnNwUizDUzAkzGq2NDyif5o6VKSQSuvjaeYdfEDMZfd 9OhNlUP4BE+YZp4JdUGdSs3ztss3R2kJMyU3wCSdrwh+8RziSSC4wmRTi/Pz/f9NQn03 fqCXmgsqj4vST17yY4BKI6AgwFLR63SkQoEffaOd6eN0oeWdxBwafXrEnRo5dSz6fv00 H0/g== 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=c+v3Csm26bJrGyWtWGYvNY7l6wOwq0bZJEszW/Rc9OM=; fh=9DrfyMIxQXmVFGXijTr0lAFjSMU1v2ifvPRi5ZRi3rM=; b=cimnW5Np+tjHDrxOhnTmVYeogipmgriCW7U7sdmLdRLZGi4chjY4znF07m8t8OGfZO 7GQr/tbiS4OD9YeIZNblX/Q0dXRbmeiZvHEEQnPRc6Mkek/D2RyQkKIy25LvIEMPh58N VYC3lFDvfBrkdyjgeJqS7X+ApkBhM4NJKnZUo0lELFW62D5SeLWVk926r1EcTvYkj/I/ CsUG1u7K+Aoycjm59uWzYXoVGtjF6UnLwkxdT3RJqXkQ/Gcl3wwG4R7DCeI5YHvzcRcK Do93fiozEAo/ZNw/rNkYg/5pzpHqfGfpooep8REpXOCt/omeS8RKmGb4wb4eykF9eFSk R2Jw==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=HM3dCL2R; 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-794f3064f7dsi53023785a.349.2024.05.30.15.07.10 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 30 May 2024 15:07:10 -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=HM3dCL2R; 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 1sCnui-0007JJ-UB; Thu, 30 May 2024 18:06:24 -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 1sCnuf-0007IM-DJ for qemu-devel@nongnu.org; Thu, 30 May 2024 18:06:21 -0400 Received: from mail-pl1-x62b.google.com ([2607:f8b0:4864:20::62b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sCnud-0005CN-AJ for qemu-devel@nongnu.org; Thu, 30 May 2024 18:06:20 -0400 Received: by mail-pl1-x62b.google.com with SMTP id d9443c01a7336-1f62fae8c3cso4746365ad.3 for ; Thu, 30 May 2024 15:06:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1717106773; x=1717711573; 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=c+v3Csm26bJrGyWtWGYvNY7l6wOwq0bZJEszW/Rc9OM=; b=HM3dCL2RT2MhxxLfziXcVUtAEjLSdqt0PoFpNKQGbQBcGRIOghWo/SqIhrlruoFhVo 3l0/no/JfvqHlVXEtRM9U2Xl5fMuzlemfHKOePWfT2E20YI8WorUzSB6sqIlcnOZom7A l/3wYVmHK+MqMnvK5rcvLK9ajwK5430zgNR1DcSM6HZLbML4MLjMnreirbMAjTUCqOof qMFHaGuDjDK5t51b86jciPl5cRVvIK8Q4bgIcOE8q4nquztiOaIsyVGv2Kw14DPbXl+9 n3VxH1GubYOP0pajZS0/J+1o0wsvpYXA/IveW1nBK0U6vnnh1fhq9QWEHI8U5STrfv1D iikA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717106773; x=1717711573; 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=c+v3Csm26bJrGyWtWGYvNY7l6wOwq0bZJEszW/Rc9OM=; b=iLO55nSYhmaAeoeR3w5dRiK1WK82CQyRmkMlD/E3QvVV1E1wNkXAi1iLxhgewok819 4UPPclKksts+pUgEFOHZOhxbpsdAdyvVQqSKlZjoPj9wYOpFSCiNcXp8mvqwGioZTW80 wEI6qeeydmPzB+9957yzgVAYsububilJa8qS8LJ2HQg2vRSpW5xe8CKYE/RRcn0IYqIm aqYrasM935B7A3+ZxvgOdVf4gy+oKoImUhkx3fJjgyjH/i6adCWIxXZP+88Tmb3fTrF+ 0jPa7sV+yOlvUmJLgFiW2I4UyRRVvlLQzUfBjYmShiIHxQqhzT9e0Bk6zNTVYEs7YJtz mifw== X-Gm-Message-State: AOJu0YyfZAvY+J1KlcL6CdWkWglwQAUpBMCcSzqEOmVRHfa813efo0KR V+9kFsesbH3DWOZB4iuyOLSskfW3fEyiz6XcD8hE8yMCQT4FcQGuTQxzKZGg+ZRFW4SIVjm869D CTAw= X-Received: by 2002:a17:902:ecc5:b0:1f6:35ab:dd55 with SMTP id d9443c01a7336-1f6370c1400mr1039165ad.65.1717106773296; Thu, 30 May 2024 15:06:13 -0700 (PDT) Received: from linaro.vn.shawcable.net ([2604:3d08:9384:1d00::e697]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1f6323dde39sm2732615ad.167.2024.05.30.15.06.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 May 2024 15:06:12 -0700 (PDT) From: Pierrick Bouvier To: qemu-devel@nongnu.org Cc: Thomas Huth , Laurent Vivier , Pierrick Bouvier , Paolo Bonzini , Alexandre Iooss , =?utf-8?q?Alex_Benn=C3=A9e?= , Mahmoud Mandour , Richard Henderson Subject: [PATCH v3 0/6] Implement icount=auto using TCG Plugins Date: Thu, 30 May 2024 15:06:04 -0700 Message-Id: <20240530220610.1245424-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::62b; envelope-from=pierrick.bouvier@linaro.org; helo=mail-pl1-x62b.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 Tested in system mode by booting a full debian system, and using: $ sysbench cpu run Performance decrease linearly with the given number of ips. 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/ v3 -- - remove precise execution (per insn, per tb is enough) - fixed algorithm used. Instead of comparing from start time of the system, we just check on a given quantum of time that we didn't run too fast. It is more simple, there is no need to track idle/resume events, and a vcpu can sleep correctly. - use "sysbench cpu run" in system mode to check execution is slowed as expected. - do not use idle/resume callback 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 | 164 ++++++++++++++++++ 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, 314 insertions(+), 39 deletions(-) create mode 100644 contrib/plugins/ips.c rename stubs/{cpus-get-virtual-clock.c => cpus-virtual-clock.c} (68%)