From nobody Mon Nov 25 05:43:47 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1717091504; cv=none; d=zohomail.com; s=zohoarc; b=OrAXkV/PHzYPsQLvMIYn/AQECHqagw/Rnbor1h+D83zMNDpMfTfjXhCeYhVBtamyfcyoWQB7AQKvi15gH+uqveesvdnXmbNEkl2LJwUheJZUFuQTIaKECouRH1zz92OR0Jakyjm/EcWGubchDpwkyLLSwAicnfbgmh7fW+dcy/M= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1717091504; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=5fTc09zeskly2ZP9LGBon66poI8aZTqjlUXNgpOk+s4=; b=d81BjD4iyKKS+y+ZDWRX8+eZ7muKwORe9dMYiVEwJMwth1kGwt/sDCNslxvoc9Q6NCIhh63SSYMQ875yv/HzIfl8RDu1276dbKhoI4Rw0Zp7Qmrp6YICmOh+cm9hPQYkcZpSzKN5CYMrc8h3JjsM26HGts3VNJfzqHOoZXOVjHk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1717091504477388.09866483647863; Thu, 30 May 2024 10:51:44 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sCjuW-0003r3-8J; Thu, 30 May 2024 13:49:56 -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 1sCjuU-0003qi-2a for qemu-devel@nongnu.org; Thu, 30 May 2024 13:49:54 -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-0002S5-L3 for qemu-devel@nongnu.org; Thu, 30 May 2024 13:49:53 -0400 Received: by mail-pl1-x630.google.com with SMTP id d9443c01a7336-1f4a52b9413so9981955ad.2 for ; Thu, 30 May 2024 10:49:51 -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.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 May 2024 10:49:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1717091390; x=1717696190; darn=nongnu.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=5fTc09zeskly2ZP9LGBon66poI8aZTqjlUXNgpOk+s4=; b=RbDEzbgvE61wO2seG9hmbVbWr0KU02cr9ObQp4S8PW1llg4iWS2t8Zymkr0EG9RvhK tQSLK7//s6lEv8IlpK94eZlz2Mn5jKcKVYaKika3H2ZulevfXbbDFxG72UrKDH3JAbxs iEknsYDVaqu0pE9pha2lHzDjkt0nXQXNqsxzWEo551TwdqwUvbJCG5PGeZcy9mGRqtwV LY3A9VVK/rAepz/xii2zRFlha7wNTBw+L5VlpER3SLEUaFSqXtfD/7wB/VlmDCaUgDKv 0VEFzBKrmPP15im0sr38HRFvnf2pR8+/jmrgFBCF83BUqkYBpgbpuq/L+ik6J8RbSYxT la7w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717091390; x=1717696190; 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=5fTc09zeskly2ZP9LGBon66poI8aZTqjlUXNgpOk+s4=; b=D+Uw0MjeuUB8LlsKPNq6/DYZ8t5BtBhcRUNeQzdFbGxy5+JrzUwDIAVg5M5Mruj7yQ nKfIZwqVXRcylclaFxhQC7ys93qxJjLH7UNmvXVsOtnSD8iHWNWIXXtO3w/0v1+1fAhi R624yTGja84UseY5vDicfHTZIaUmN4FJXKazGADEkcEYAt/B0+mbkdBD2D/6nOF6K302 wB7qGiNiaInOWjonfHUFdeADRzLjltxH5wHfELOV2czgjQywhNKbrNZS0M8+7Neh+5WQ +evd94xOy1LVrdlbATADFvV7UXF+ixb9rxhdZ330aZY2z7XEpP41nxQvLnEsUu8vJ8US ta4w== X-Gm-Message-State: AOJu0YwV2hpsXD/fdQkc69mPUhav62uwLx+LhSsIKGfbDGyg298gQnMX E149+0CqAAKFIwFf1nJLvQzCfzce0QzOlvUzQo/jFehi8l9tU2C2s2kAOnQAcgsFsToTSWmTYo+ ktcA= X-Google-Smtp-Source: AGHT+IHyEjTokvLy9RZdGVePQjy2CFxs2wbvSMHqa6JQJgLgaGr6I5MWbNjOnxtv3DPvpQis8dGiHQ== X-Received: by 2002:a17:902:d4cc:b0:1f4:5f66:895 with SMTP id d9443c01a7336-1f61a2e44a4mr30894645ad.68.1717091389832; Thu, 30 May 2024 10:49:49 -0700 (PDT) From: Pierrick Bouvier To: qemu-devel@nongnu.org Cc: Richard Henderson , Laurent Vivier , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Thomas Huth , Alexandre Iooss , Mahmoud Mandour , Paolo Bonzini , Pierrick Bouvier , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [PATCH v2 1/6] sysemu: add set_virtual_time to accel ops Date: Thu, 30 May 2024 10:49:34 -0700 Message-Id: <20240530174939.749163-2-pierrick.bouvier@linaro.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240530174939.749163-1-pierrick.bouvier@linaro.org> References: <20240530174939.749163-1-pierrick.bouvier@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1717091504753100001 From: Alex Benn=C3=A9e We are about to remove direct calls to individual accelerators for this information and will need a central point for plugins to hook into time changes. From: Alex Benn=C3=A9e Signed-off-by: Alex Benn=C3=A9e Reviewed-by: Philippe Mathieu-Daud=C3=A9 Signed-off-by: Pierrick Bouvier --- include/sysemu/accel-ops.h | 18 +++++++++++++++++- include/sysemu/cpu-timers.h | 3 ++- ...et-virtual-clock.c =3D> cpus-virtual-clock.c} | 5 +++++ system/cpus.c | 11 +++++++++++ stubs/meson.build | 2 +- 5 files changed, 36 insertions(+), 3 deletions(-) rename stubs/{cpus-get-virtual-clock.c =3D> cpus-virtual-clock.c} (68%) diff --git a/include/sysemu/accel-ops.h b/include/sysemu/accel-ops.h index ef91fc28bbd..a0886722305 100644 --- a/include/sysemu/accel-ops.h +++ b/include/sysemu/accel-ops.h @@ -20,7 +20,12 @@ typedef struct AccelOpsClass AccelOpsClass; DECLARE_CLASS_CHECKERS(AccelOpsClass, ACCEL_OPS, TYPE_ACCEL_OPS) =20 -/* cpus.c operations interface */ +/** + * struct AccelOpsClass - accelerator interfaces + * + * This structure is used to abstract accelerator differences from the + * core CPU code. Not all have to be implemented. + */ struct AccelOpsClass { /*< private >*/ ObjectClass parent_class; @@ -44,7 +49,18 @@ struct AccelOpsClass { =20 void (*handle_interrupt)(CPUState *cpu, int mask); =20 + /** + * @get_virtual_clock: fetch virtual clock + * @set_virtual_clock: set virtual clock + * + * These allow the timer subsystem to defer to the accelerator to + * fetch time. The set function is needed if the accelerator wants + * to track the changes to time as the timer is warped through + * various timer events. + */ int64_t (*get_virtual_clock)(void); + void (*set_virtual_clock)(int64_t time); + int64_t (*get_elapsed_ticks)(void); =20 /* gdbstub hooks */ diff --git a/include/sysemu/cpu-timers.h b/include/sysemu/cpu-timers.h index d86738a378d..7bfa960fbd6 100644 --- a/include/sysemu/cpu-timers.h +++ b/include/sysemu/cpu-timers.h @@ -96,8 +96,9 @@ int64_t cpu_get_clock(void); =20 void qemu_timer_notify_cb(void *opaque, QEMUClockType type); =20 -/* get the VIRTUAL clock and VM elapsed ticks via the cpus accel interface= */ +/* get/set VIRTUAL clock and VM elapsed ticks via the cpus accel interface= */ int64_t cpus_get_virtual_clock(void); +void cpus_set_virtual_clock(int64_t new_time); int64_t cpus_get_elapsed_ticks(void); =20 #endif /* SYSEMU_CPU_TIMERS_H */ diff --git a/stubs/cpus-get-virtual-clock.c b/stubs/cpus-virtual-clock.c similarity index 68% rename from stubs/cpus-get-virtual-clock.c rename to stubs/cpus-virtual-clock.c index fd447d53f3c..af7c1a1d403 100644 --- a/stubs/cpus-get-virtual-clock.c +++ b/stubs/cpus-virtual-clock.c @@ -6,3 +6,8 @@ int64_t cpus_get_virtual_clock(void) { return cpu_get_clock(); } + +void cpus_set_virtual_clock(int64_t new_time) +{ + /* do nothing */ +} diff --git a/system/cpus.c b/system/cpus.c index f8fa78f33d4..d3640c95030 100644 --- a/system/cpus.c +++ b/system/cpus.c @@ -229,6 +229,17 @@ int64_t cpus_get_virtual_clock(void) return cpu_get_clock(); } =20 +/* + * Signal the new virtual time to the accelerator. This is only needed + * by accelerators that need to track the changes as we warp time. + */ +void cpus_set_virtual_clock(int64_t new_time) +{ + if (cpus_accel && cpus_accel->set_virtual_clock) { + cpus_accel->set_virtual_clock(new_time); + } +} + /* * return the time elapsed in VM between vm_start and vm_stop. Unless * icount is active, cpus_get_elapsed_ticks() uses units of the host CPU c= ycle diff --git a/stubs/meson.build b/stubs/meson.build index 3b9d42023cb..a1deafde08c 100644 --- a/stubs/meson.build +++ b/stubs/meson.build @@ -28,7 +28,7 @@ endif if have_block or have_ga stub_ss.add(files('replay-tools.c')) # stubs for hooks in util/main-loop.c, util/async.c etc. - stub_ss.add(files('cpus-get-virtual-clock.c')) + stub_ss.add(files('cpus-virtual-clock.c')) stub_ss.add(files('icount.c')) stub_ss.add(files('graph-lock.c')) if linux_io_uring.found() --=20 2.39.2 From nobody Mon Nov 25 05:43:47 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1717091496; cv=none; d=zohomail.com; s=zohoarc; b=aVDAFPrmkZX3hTrFG7WQ1hllkVh//qxsixI3fwO0I7D+nkIiWzW8INNo7o3Y+bevmx/4GOeiw+kVREBI6IK3IJ+U0hGhDCyJCcAmOoJv1oGew4J9p2sVZk3/zmBavOW1WyG3ZV6OMI7Cf9onSNhi9lqG2KCzm9Z1A8R6GRinVXQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1717091496; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=N8fpp15niTkZ3IPMy6ehe10O59rmldsghTOZNCkMcuE=; b=IcMrMbhSmM65RpcPyeAqSg5XtgmAQnIO/sVKyMaJTuNdCgmYmHOEVaqH9rHVJ96aMu5mAsEgEkhLHvGTsmy3rXSImJ8qG2ScD2v3VnNV96/rToa4RTd6BCJc6qmoJz2tOHkT1u6Cd+GcXemRd86f1+OYmzvFjblZHsBRN9I4jkA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1717091496647703.0075821981059; Thu, 30 May 2024 10:51:36 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sCjuX-0003rW-Hc; Thu, 30 May 2024 13:49:57 -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 1sCjuV-0003qu-Gq for qemu-devel@nongnu.org; Thu, 30 May 2024 13:49:55 -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 1sCjuT-0002SG-8h for qemu-devel@nongnu.org; Thu, 30 May 2024 13:49:55 -0400 Received: by mail-pl1-x62b.google.com with SMTP id d9443c01a7336-1f44b45d6abso8042455ad.0 for ; Thu, 30 May 2024 10:49:52 -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.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); 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=1717091391; x=1717696191; darn=nongnu.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=N8fpp15niTkZ3IPMy6ehe10O59rmldsghTOZNCkMcuE=; b=W3reaMr1N9cVY5tN/SJOoavOaYYDvJnVaHFC2zVzsrcmYgJNb/i9psC2CgYYYVgnhj OXCjSDBmjEpEGrBV4DTbFClZJUAmOYWvkL2Gdhxorpv21t6+SVdVgqnsPa+Xg5uPvOuK 5XdFUUj3PH30vQvg7ZJitiW30/SLk4tJEVG7zT0Jc/92PIotwf9WSuCASq1mgttX9BBY KGOu/xYdQ6Es32Tseq3YtSnGP0Ll8k2MGOYbvn6aCbciX92TPAHXCgjOq52NeZolQyeh kjaG64oPyYYVhgkgA6uXX7a2qD9xaDODdFPkn47aitG8KyhNwOIFjUzdRBk43ZEniTj8 rAsw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717091391; x=1717696191; 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=N8fpp15niTkZ3IPMy6ehe10O59rmldsghTOZNCkMcuE=; b=QiUM71OLQ4xjrKS2daEve7ijrvLMnx7jiNHYBDsPUdR7u9V4nSTYM+vZGNqLUqDJXK w343Su0ly7hDZizbcOWg+jiw9HSVmBhmPe/sLx0stRl7KHUYd7zGGC4jiNpNaIoik6YL lMnNqXXd2RBS8nKg2ChK138a8SZVsPOINBEHkgGBeTw0a8aRfFOs+HKf1OlB0TN4G57Q BOyNSXw9BtR2KSwyl8t4zM2ywPwuSyxyLTtLaAyqbmYRtPRanLv8idka2RdmlN84DltX Dp/WaHYgDKWILYFZVd7hpJiAe7F3Yh/7xv2wXYoYh+NqCeoDd9/TP7YNZ2AUW+juJZAp fVFA== X-Gm-Message-State: AOJu0YzUj58oYegDgvKKD0D3x7Nvwdjc3my3S6D+RjHdlbxmMtVTZL5G lDL/65xFY+t4YYeEfQjQGaqUu7tIBXlCA5TDCzngbeX528hyHyz0Juzeb1qe8ubCQ4sp1oA2hsI jhsA= X-Google-Smtp-Source: AGHT+IH5YlzSC8YNw6tasuEuJt2Vl1N1ET8xo6UhJ/3oRfA/i8nZUUG1xfCq8vfFGaeLtfiw2MhbBA== X-Received: by 2002:a17:902:c94b:b0:1f4:89e2:b47b with SMTP id d9443c01a7336-1f61992ee59mr33274415ad.50.1717091390928; Thu, 30 May 2024 10:49:50 -0700 (PDT) From: Pierrick Bouvier To: qemu-devel@nongnu.org Cc: Richard Henderson , Laurent Vivier , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Thomas Huth , Alexandre Iooss , Mahmoud Mandour , Paolo Bonzini , Pierrick Bouvier Subject: [PATCH v2 2/6] qtest: use cpu interface in qtest_clock_warp Date: Thu, 30 May 2024 10:49:35 -0700 Message-Id: <20240530174939.749163-3-pierrick.bouvier@linaro.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240530174939.749163-1-pierrick.bouvier@linaro.org> References: <20240530174939.749163-1-pierrick.bouvier@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1717091498670100010 From: Alex Benn=C3=A9e This generalises the qtest_clock_warp code to use the AccelOps handlers for updating its own sense of time. This will make the next patch which moves the warp code closer to pure code motion. From: Alex Benn=C3=A9e Signed-off-by: Alex Benn=C3=A9e Acked-by: Thomas Huth Signed-off-by: Pierrick Bouvier --- include/sysemu/qtest.h | 1 + accel/qtest/qtest.c | 1 + system/qtest.c | 6 +++--- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/include/sysemu/qtest.h b/include/sysemu/qtest.h index b5d5fd34637..45f3b7e1df5 100644 --- a/include/sysemu/qtest.h +++ b/include/sysemu/qtest.h @@ -36,6 +36,7 @@ void qtest_server_set_send_handler(void (*send)(void *, c= onst char *), void qtest_server_inproc_recv(void *opaque, const char *buf); =20 int64_t qtest_get_virtual_clock(void); +void qtest_set_virtual_clock(int64_t count); #endif =20 #endif diff --git a/accel/qtest/qtest.c b/accel/qtest/qtest.c index f6056ac8361..53182e6c2ae 100644 --- a/accel/qtest/qtest.c +++ b/accel/qtest/qtest.c @@ -52,6 +52,7 @@ static void qtest_accel_ops_class_init(ObjectClass *oc, v= oid *data) =20 ops->create_vcpu_thread =3D dummy_start_vcpu_thread; ops->get_virtual_clock =3D qtest_get_virtual_clock; + ops->set_virtual_clock =3D qtest_set_virtual_clock; }; =20 static const TypeInfo qtest_accel_ops_type =3D { diff --git a/system/qtest.c b/system/qtest.c index 6da58b3874e..ee8b139e982 100644 --- a/system/qtest.c +++ b/system/qtest.c @@ -332,14 +332,14 @@ int64_t qtest_get_virtual_clock(void) return qatomic_read_i64(&qtest_clock_counter); } =20 -static void qtest_set_virtual_clock(int64_t count) +void qtest_set_virtual_clock(int64_t count) { qatomic_set_i64(&qtest_clock_counter, count); } =20 static void qtest_clock_warp(int64_t dest) { - int64_t clock =3D qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL); + int64_t clock =3D cpus_get_virtual_clock(); AioContext *aio_context; assert(qtest_enabled()); aio_context =3D qemu_get_aio_context(); @@ -348,7 +348,7 @@ static void qtest_clock_warp(int64_t dest) QEMU_TIMER_ATTR_ALL); int64_t warp =3D qemu_soonest_timeout(dest - clock, deadline); =20 - qtest_set_virtual_clock(qtest_get_virtual_clock() + warp); + cpus_set_virtual_clock(cpus_get_virtual_clock() + warp); =20 qemu_clock_run_timers(QEMU_CLOCK_VIRTUAL); timerlist_run_timers(aio_context->tlg.tl[QEMU_CLOCK_VIRTUAL]); --=20 2.39.2 From nobody Mon Nov 25 05:43:47 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1717091496; cv=none; d=zohomail.com; s=zohoarc; b=E8y97dK2p7snF/6Dagmxy1m/Krlp9azbrqmfwAzWJlFeZM3QbBIRVM/2W3EXIhHZXtU59ocrt4kpWIp2Xek8Ng3/8jYsTXaTSpKF2GsmegywFugGpJnbPSC++3nAsX7DPgG0qE3JYU4d+nCYbnUlIKt64WA/yZ+/iZ0Lw06tv1A= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1717091496; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=6IWWhHyfIReAoyuKPFTir6WLrARTyk7MyySJZx8v8IY=; b=Nu4SmUUhDildUCXYqA+CAGp7TAKQ/HPoIJD9NV1jy9Oy0XgYqLK7sCAQyK4NbMoRKPAjUZ5VR4WCCYCf2vRKKfIV4PargUpoJaCZDW8qSmLnwvzxuvJn1hdH3hvQ669W03JTns7CEDc1rlyq6pzcyjhyT90HDUI4t1HknPY6K30= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1717091496553948.2553958833291; Thu, 30 May 2024 10:51:36 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sCjuY-0003s3-6C; 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 1sCjuX-0003rU-9u for qemu-devel@nongnu.org; Thu, 30 May 2024 13:49:57 -0400 Received: from mail-pl1-x632.google.com ([2607:f8b0:4864:20::632]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sCjuV-0002SM-D5 for qemu-devel@nongnu.org; Thu, 30 May 2024 13:49:57 -0400 Received: by mail-pl1-x632.google.com with SMTP id d9443c01a7336-1f61f775738so6692565ad.2 for ; Thu, 30 May 2024 10:49:54 -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.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 May 2024 10:49:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1717091392; x=1717696192; darn=nongnu.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=6IWWhHyfIReAoyuKPFTir6WLrARTyk7MyySJZx8v8IY=; b=LbENw2dr/TNmqoHOzpqHovhp2mLDPE4yjqa9r5fE9JPF555xHbHGPNNOqfTlj+xg6R K0UUBd7FkpBkoWbJmlO+yuJSc2OhQnwFASG1v9dO7CytVvbIHvPvMQn2d3AryznPuMMS wHJ+3+k3XEyrB7sdD8dw2GOkidKob2b1+giX1puasnpUaoRtvT6cIF6Z3r+rYf4bMe2E CqS8/Cw6Kg2L8Eu9pHwU4tBp8AGYRHJDII41+20uwhJQo3UM8p0UzBjXOnPZg3mPyEF4 NuJ5EkfYdt+VP7z986JQJoJNNNwX9RGNJUWxO2YMXpunauaABj4Z9Huc9D+T1jTd+Qpw JjwQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717091392; x=1717696192; 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=6IWWhHyfIReAoyuKPFTir6WLrARTyk7MyySJZx8v8IY=; b=lJfZn+UDx3j+yLT8kfU+4jg/emfWcSezuN2/mfnKnpPQBjcNFWkiwhJ/Guh/Z3rt6e wKqSh0Uw3GUnMfzaJVdqfi9VZ9rsLReKwXpUb5d7sSozURt41kn/2SQU7t2DGkCcJXl1 RgtxZFmRJ3SxeX+bvgKMDOPTkJWAkW7hWSLZJ5tjGStIkHfqMkAc2aGGrZdgkTVrNZ3O 94fLA7sPUuB8E1ShNmmtK4bUdyM8WBSXrnKb8mYBvfPN+L+Ty6yHl2ACmiuuhOoKR8sp K+OtvSqPxzetfeOYWSjpKkBPhQ5dyrgywyt8ACJa9HdpiaK+hAi+LwzcqVCqFKtoqOZx RCfA== X-Gm-Message-State: AOJu0YyR7xJvQFrbsZxUYjSBzjEYDeT4fqCQ8+qLwRWVkzfKH7o2FcVU LEjI3XSUBhzx0+MHZHrb6qT27uGZMFO9Unj55UINBLioTRA4QK0zavA9M4xx0JChy5h00Me1W97 ghD8= X-Google-Smtp-Source: AGHT+IFAwF5cR+Jg7SUirFkFs9vWxwXiFldFvhwxAhkaK9VVVOTf6vSHeI8x1+uvDPOEf/Hw07wNTQ== X-Received: by 2002:a17:903:2385:b0:1f6:1144:a112 with SMTP id d9443c01a7336-1f6196087d6mr31883245ad.25.1717091392121; Thu, 30 May 2024 10:49:52 -0700 (PDT) From: Pierrick Bouvier To: qemu-devel@nongnu.org Cc: Richard Henderson , Laurent Vivier , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Thomas Huth , Alexandre Iooss , Mahmoud Mandour , Paolo Bonzini , Pierrick Bouvier Subject: [PATCH v2 3/6] sysemu: generalise qtest_warp_clock as qemu_clock_advance_virtual_time Date: Thu, 30 May 2024 10:49:36 -0700 Message-Id: <20240530174939.749163-4-pierrick.bouvier@linaro.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240530174939.749163-1-pierrick.bouvier@linaro.org> References: <20240530174939.749163-1-pierrick.bouvier@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::632; envelope-from=pierrick.bouvier@linaro.org; helo=mail-pl1-x632.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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1717091498681100012 From: Alex Benn=C3=A9e Move the key functionality of moving time forward into the clock sub-system itself. This will allow us to plumb in time control into plugins. From: Alex Benn=C3=A9e Signed-off-by: Alex Benn=C3=A9e Signed-off-by: Pierrick Bouvier --- include/qemu/timer.h | 15 +++++++++++++++ system/qtest.c | 25 +++---------------------- util/qemu-timer.c | 26 ++++++++++++++++++++++++++ 3 files changed, 44 insertions(+), 22 deletions(-) diff --git a/include/qemu/timer.h b/include/qemu/timer.h index 9a366e551fb..910587d8293 100644 --- a/include/qemu/timer.h +++ b/include/qemu/timer.h @@ -245,6 +245,21 @@ bool qemu_clock_run_timers(QEMUClockType type); */ bool qemu_clock_run_all_timers(void); =20 +/** + * qemu_clock_advance_virtual_time(): advance the virtual time tick + * @target: target time in nanoseconds + * + * This function is used where the control of the flow of time has + * been delegated to outside the clock subsystem (be it qtest, icount + * or some other external source). You can ask the clock system to + * return @early at the first expired timer. + * + * Time can only move forward, attempts to reverse time would lead to + * an error. + * + * Returns: new virtual time. + */ +int64_t qemu_clock_advance_virtual_time(int64_t dest); =20 /* * QEMUTimerList diff --git a/system/qtest.c b/system/qtest.c index ee8b139e982..e6f6b4e62d5 100644 --- a/system/qtest.c +++ b/system/qtest.c @@ -337,26 +337,6 @@ void qtest_set_virtual_clock(int64_t count) qatomic_set_i64(&qtest_clock_counter, count); } =20 -static void qtest_clock_warp(int64_t dest) -{ - int64_t clock =3D cpus_get_virtual_clock(); - AioContext *aio_context; - assert(qtest_enabled()); - aio_context =3D qemu_get_aio_context(); - while (clock < dest) { - int64_t deadline =3D qemu_clock_deadline_ns_all(QEMU_CLOCK_VIRTUAL, - QEMU_TIMER_ATTR_ALL); - int64_t warp =3D qemu_soonest_timeout(dest - clock, deadline); - - cpus_set_virtual_clock(cpus_get_virtual_clock() + warp); - - qemu_clock_run_timers(QEMU_CLOCK_VIRTUAL); - timerlist_run_timers(aio_context->tlg.tl[QEMU_CLOCK_VIRTUAL]); - clock =3D qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL); - } - qemu_clock_notify(QEMU_CLOCK_VIRTUAL); -} - static bool (*process_command_cb)(CharBackend *chr, gchar **words); =20 void qtest_set_command_cb(bool (*pc_cb)(CharBackend *chr, gchar **words)) @@ -755,7 +735,8 @@ static void qtest_process_command(CharBackend *chr, gch= ar **words) ns =3D qemu_clock_deadline_ns_all(QEMU_CLOCK_VIRTUAL, QEMU_TIMER_ATTR_ALL); } - qtest_clock_warp(qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) + ns); + qemu_clock_advance_virtual_time( + qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) + ns); qtest_send_prefix(chr); qtest_sendf(chr, "OK %"PRIi64"\n", (int64_t)qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL)); @@ -781,7 +762,7 @@ static void qtest_process_command(CharBackend *chr, gch= ar **words) g_assert(words[1]); ret =3D qemu_strtoi64(words[1], NULL, 0, &ns); g_assert(ret =3D=3D 0); - qtest_clock_warp(ns); + qemu_clock_advance_virtual_time(ns); qtest_send_prefix(chr); qtest_sendf(chr, "OK %"PRIi64"\n", (int64_t)qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL)); diff --git a/util/qemu-timer.c b/util/qemu-timer.c index 6a0de33dd2b..213114be68c 100644 --- a/util/qemu-timer.c +++ b/util/qemu-timer.c @@ -645,6 +645,11 @@ int64_t qemu_clock_get_ns(QEMUClockType type) } } =20 +static void qemu_virtual_clock_set_ns(int64_t time) +{ + return cpus_set_virtual_clock(time); +} + void init_clocks(QEMUTimerListNotifyCB *notify_cb) { QEMUClockType type; @@ -675,3 +680,24 @@ bool qemu_clock_run_all_timers(void) =20 return progress; } + +int64_t qemu_clock_advance_virtual_time(int64_t dest) +{ + int64_t clock =3D qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL); + AioContext *aio_context; + aio_context =3D qemu_get_aio_context(); + while (clock < dest) { + int64_t deadline =3D qemu_clock_deadline_ns_all(QEMU_CLOCK_VIRTUAL, + QEMU_TIMER_ATTR_ALL); + int64_t warp =3D qemu_soonest_timeout(dest - clock, deadline); + + qemu_virtual_clock_set_ns(qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) + = warp); + + qemu_clock_run_timers(QEMU_CLOCK_VIRTUAL); + timerlist_run_timers(aio_context->tlg.tl[QEMU_CLOCK_VIRTUAL]); + clock =3D qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL); + } + qemu_clock_notify(QEMU_CLOCK_VIRTUAL); + + return clock; +} --=20 2.39.2 From nobody Mon Nov 25 05:43:47 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1717091496504105.55361826275919; Thu, 30 May 2024 10:51:36 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sCjuY-0003sG-UB; 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 1sCjuX-0003rp-N2 for qemu-devel@nongnu.org; Thu, 30 May 2024 13:49:57 -0400 Received: from mail-pl1-x62c.google.com ([2607:f8b0:4864:20::62c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sCjuV-0002SW-Tr for qemu-devel@nongnu.org; Thu, 30 May 2024 13:49:57 -0400 Received: by mail-pl1-x62c.google.com with SMTP id d9443c01a7336-1f630e35a01so1388035ad.1 for ; Thu, 30 May 2024 10:49:55 -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.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 May 2024 10:49:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1717091393; x=1717696193; darn=nongnu.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=ChXWvUNOD02yoYequIGCuEzpK9HfTXZtOpXCWQ0j1Uw=; b=dGG/j/kusF2OC8h8X2M1KRmzvUNk2LUH3LaPIPUWkPcIxzcZ736gaQqYhoEd82Cbz2 9JHDDiPs3xnOK2bukJ33HbAuWQ6wb/QM7CFAej/BehNbnBFxQInDMCQuaWihnXf/l6Mx NB7riwuhfk+C7i5XUo6TqQbYNjQuGLjAgKKEk6f1GGGaWeIV0gXIQ9SX9eOVWT/LCiXs 2PAv2+Tu6KfZQ33ZZfHv3IAN+94cxcxZUVIsGLDHfN1Cg6pp4yWPGbURm+0Lh4mQX094 6VzNFDa6U4yzi8nfghzpQrmq4Kppwi6oemvoVK0nb4A5uzVTU0rdwUUNNtLHp/qSxbx9 lezw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717091393; x=1717696193; 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=ChXWvUNOD02yoYequIGCuEzpK9HfTXZtOpXCWQ0j1Uw=; b=fqF7HfIjrMJh4PtmphHwpWJxPCgcH4eSfl5zHxxuroC1rFdzIvf6SGVkUly+FFjNyp x78RzwkJ5Qxf2Hl5dvgzSJiICt9WlNyRyR01XSwO7KQHBYMwlo7LVjOQcyuZnxUX/F2b JPBNyuDrgePfz5PE/oU5AQbsJtDc2IVW1WjVWum+/cT0qAb7PDBQl/MCsWRN2ZmhqEkJ 1WhaG52ItzJDN3W6bN0YayK/yjWnD9kSNdNRbz7hvmDdteorDFSIPv/Nb8W5uqBeIzjj J/F+FHC3YmCiamKn1Sbtx33ThosILeSPJy/AeR/ih5GDgwwBUgSlai7BI/Wjczem6PeC Tp2A== X-Gm-Message-State: AOJu0YzCu4W2PScJfsWdUhTt/pZxCEslc4LWfPtFK0Hmoxa4yyHEsfJ0 PWyXlNpbwzjW5muP5gWOLwlcqYXYEn3RXkj0xrFYsT57k2/y9Tgh4ysp6sx8MuowJG2LAkbTlaK ro0U= X-Google-Smtp-Source: AGHT+IFK5Nnuv8sp7C8fyM6G/nxuCCjstNBkLTzNiWRXZXNGoygsUhYl2t3uw0gsRhHyxeofu0gyOw== X-Received: by 2002:a17:902:e890:b0:1f6:225e:6769 with SMTP id d9443c01a7336-1f6225e697fmr22279025ad.21.1717091393620; Thu, 30 May 2024 10:49:53 -0700 (PDT) From: Pierrick Bouvier To: qemu-devel@nongnu.org Cc: Richard Henderson , Laurent Vivier , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Thomas Huth , Alexandre Iooss , Mahmoud Mandour , Paolo Bonzini , Pierrick Bouvier Subject: [PATCH v2 4/6] qtest: move qtest_{get, set}_virtual_clock to accel/qtest/qtest.c Date: Thu, 30 May 2024 10:49:37 -0700 Message-Id: <20240530174939.749163-5-pierrick.bouvier@linaro.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240530174939.749163-1-pierrick.bouvier@linaro.org> References: <20240530174939.749163-1-pierrick.bouvier@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::62c; envelope-from=pierrick.bouvier@linaro.org; helo=mail-pl1-x62c.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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1717091498600100009 Content-Type: text/plain; charset="utf-8" Signed-off-by: Pierrick Bouvier --- include/sysemu/qtest.h | 3 --- accel/qtest/qtest.c | 12 ++++++++++++ system/qtest.c | 12 ------------ 3 files changed, 12 insertions(+), 15 deletions(-) diff --git a/include/sysemu/qtest.h b/include/sysemu/qtest.h index 45f3b7e1df5..c161d751650 100644 --- a/include/sysemu/qtest.h +++ b/include/sysemu/qtest.h @@ -34,9 +34,6 @@ void qtest_server_init(const char *qtest_chrdev, const ch= ar *qtest_log, Error ** void qtest_server_set_send_handler(void (*send)(void *, const char *), void *opaque); void qtest_server_inproc_recv(void *opaque, const char *buf); - -int64_t qtest_get_virtual_clock(void); -void qtest_set_virtual_clock(int64_t count); #endif =20 #endif diff --git a/accel/qtest/qtest.c b/accel/qtest/qtest.c index 53182e6c2ae..bf14032d294 100644 --- a/accel/qtest/qtest.c +++ b/accel/qtest/qtest.c @@ -24,6 +24,18 @@ #include "qemu/main-loop.h" #include "hw/core/cpu.h" =20 +static int64_t qtest_clock_counter; + +static int64_t qtest_get_virtual_clock(void) +{ + return qatomic_read_i64(&qtest_clock_counter); +} + +static void qtest_set_virtual_clock(int64_t count) +{ + qatomic_set_i64(&qtest_clock_counter, count); +} + static int qtest_init_accel(MachineState *ms) { return 0; diff --git a/system/qtest.c b/system/qtest.c index e6f6b4e62d5..ba210780ec0 100644 --- a/system/qtest.c +++ b/system/qtest.c @@ -325,18 +325,6 @@ static void qtest_irq_handler(void *opaque, int n, int= level) } } =20 -static int64_t qtest_clock_counter; - -int64_t qtest_get_virtual_clock(void) -{ - return qatomic_read_i64(&qtest_clock_counter); -} - -void qtest_set_virtual_clock(int64_t count) -{ - qatomic_set_i64(&qtest_clock_counter, count); -} - static bool (*process_command_cb)(CharBackend *chr, gchar **words); =20 void qtest_set_command_cb(bool (*pc_cb)(CharBackend *chr, gchar **words)) --=20 2.39.2 From nobody Mon Nov 25 05:43:47 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1717091509; cv=none; d=zohomail.com; s=zohoarc; b=GV68dxiEGlDUGAiJRunrXU3EuOvMhvDAL+6xAYKSBjUWIgiLfS5EybECCmeUtRWlyQNNgVyyi2IpwpX0lkiRq2g8YpBegNcc7c716+Qq53AoYpd5tr3eCH2+dhys7gz13FqXROIS0Tyb63B+iUwNOzlE8/wgLbB+2sz8JuYkrYU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1717091509; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=4pgM/UwM460cpw8hnXWYswA57iFvGhgQxtIaLtYjo7Y=; b=GOGwxYqz/innmgN+gbGNzFsoP2EDrta9s/GsC8WIeb2vy8poNLosK61+ELKY0/Wk5d3jpeDIHTduCyBn6D+85RmWC0xqjD0qWUTmK37OPm6Fb4PWjs7W6jQSK+h/1M0cHHDajVVXdPSnb67Mu4dZaNzrutuc3vi/D/yGsZrMN+o= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1717091509627458.2547007558503; Thu, 30 May 2024 10:51:49 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sCjud-0003ty-PE; Thu, 30 May 2024 13:50:03 -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 1sCjua-0003t6-TM for qemu-devel@nongnu.org; Thu, 30 May 2024 13:50:00 -0400 Received: from mail-pl1-x635.google.com ([2607:f8b0:4864:20::635]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sCjuX-0002Sq-56 for qemu-devel@nongnu.org; Thu, 30 May 2024 13:50:00 -0400 Received: by mail-pl1-x635.google.com with SMTP id d9443c01a7336-1f47728fa4cso7956885ad.3 for ; Thu, 30 May 2024 10:49:56 -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.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 May 2024 10:49:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1717091395; x=1717696195; darn=nongnu.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=4pgM/UwM460cpw8hnXWYswA57iFvGhgQxtIaLtYjo7Y=; b=ebuKLsaLQCTDc+mZwN4t2jFkCK5V9wv6c/nB9zto8xCrx1gCtHtx/rsVoOIFz6qj9N 8axs9mLIOfa9tMXGCh/uEEVY7rPlfc+4BaUzk+Icqo3m5TMjUo0EFtRSPbUmiNPSrws4 NyAEGQyCFVkRO7MuaSNOooa6zyf0cjjhCHby1wGYjyHVJmxq569/+6nDpZLlUySC73gT 7SkO8zfAgDfOByPk4NuSJJ3NRmVWT6gSA2VlRwGtyDqHKBv1M5dfR8TQeCgQFt7+d5Ya isfuxuUeuvTv0T0k7YSYK2acqi0rUv1+2pNq7A0WoEMSKcSTVlLSglUPGKeHn5A0mhL+ toLw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717091395; x=1717696195; 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=4pgM/UwM460cpw8hnXWYswA57iFvGhgQxtIaLtYjo7Y=; b=CJq8bSZS5LjZA63SAoUFUy6GiHEn9MGAm+zPY43tW0AP8GQoBOS7n/3bGoekCt53nM EAYFvoBfZQoWvxSt9J2g1iAqyZ890Rx6DoLgAXdoMNb3hGBXDawoXOgSPaMdqb1L9N1K syYUM79MFxjIYbRAR7l3BScGxMYYvAHq2rzzANcio6aMGNDVf4RqiqCh2EnKhVmoz72O wwZCFCjueRvrHPRtLA3jdSIw/Vd9gTGA0xztSu961Y7qx16k+FFqrGT49sV3IEiPsA14 OWEc4xjq3d5+tcduU+cdVJ3yLNR/kE72YOLIpjHXA+IQ7eqefg6BBwobYDSSuFIHfIC6 f6Pw== X-Gm-Message-State: AOJu0YzOS4NcwwhoMRB+0Dllj1uortwDVKzWL41vsonM23dRkvmxbGuO gfjpY3+3iq0vsNIExdkGxx4lgIpdhiNuRBXC35cDn4LCFnPo8n4IsQTUjoIg60S/naBMjJZtsO2 ND5Y= X-Google-Smtp-Source: AGHT+IHsAPxqa31bqaliiAIFNR3cXkTCQfub9HnhjTzasEzKjrP2x1DqUFPeYlu2vemWyBmRRTKCqQ== X-Received: by 2002:a17:902:ca0c:b0:1f4:867c:dc34 with SMTP id d9443c01a7336-1f6193f8762mr24070025ad.13.1717091395187; Thu, 30 May 2024 10:49:55 -0700 (PDT) From: Pierrick Bouvier To: qemu-devel@nongnu.org Cc: Richard Henderson , Laurent Vivier , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Thomas Huth , Alexandre Iooss , Mahmoud Mandour , Paolo Bonzini , Pierrick Bouvier Subject: [PATCH v2 5/6] plugins: add time control API Date: Thu, 30 May 2024 10:49:38 -0700 Message-Id: <20240530174939.749163-6-pierrick.bouvier@linaro.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240530174939.749163-1-pierrick.bouvier@linaro.org> References: <20240530174939.749163-1-pierrick.bouvier@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::635; envelope-from=pierrick.bouvier@linaro.org; helo=mail-pl1-x635.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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1717091510644100005 From: Alex Benn=C3=A9e Expose the ability to control time through the plugin API. Only one plugin can control time so it has to request control when loaded. There are probably more corner cases to catch here. From: Alex Benn=C3=A9e Signed-off-by: Alex Benn=C3=A9e Signed-off-by: Pierrick Bouvier --- include/qemu/qemu-plugin.h | 23 +++++++++++++++++++++++ plugins/api.c | 31 +++++++++++++++++++++++++++++++ plugins/qemu-plugins.symbols | 2 ++ 3 files changed, 56 insertions(+) diff --git a/include/qemu/qemu-plugin.h b/include/qemu/qemu-plugin.h index 95703d8fec1..80b1637cede 100644 --- a/include/qemu/qemu-plugin.h +++ b/include/qemu/qemu-plugin.h @@ -661,6 +661,29 @@ void qemu_plugin_register_vcpu_mem_inline_per_vcpu( qemu_plugin_u64 entry, uint64_t imm); =20 +/** + * qemu_plugin_request_time_control() - request the ability to control time + * + * This grants the plugin the ability to control system time. Only one + * plugin can control time so if multiple plugins request the ability + * all but the first will fail. + * + * Returns an opaque handle or NULL if fails + */ +const void *qemu_plugin_request_time_control(void); + +/** + * qemu_plugin_update_ns() - update system emulation time + * @handle: opaque handle returned by qemu_plugin_request_time_control() + * @time: time in nanoseconds + * + * This allows an appropriately authorised plugin (i.e. holding the + * time control handle) to move system time forward to @time. + * + * Start time is 0. + */ +void qemu_plugin_update_ns(const void *handle, int64_t time); + typedef void (*qemu_plugin_vcpu_syscall_cb_t)(qemu_plugin_id_t id, unsigned int vcpu_in= dex, int64_t num, uint64_t a1, uint64_t a2, diff --git a/plugins/api.c b/plugins/api.c index 5a0a7f8c712..26822b69ea2 100644 --- a/plugins/api.c +++ b/plugins/api.c @@ -39,6 +39,7 @@ #include "qemu/main-loop.h" #include "qemu/plugin.h" #include "qemu/log.h" +#include "qemu/timer.h" #include "tcg/tcg.h" #include "exec/exec-all.h" #include "exec/gdbstub.h" @@ -583,3 +584,33 @@ uint64_t qemu_plugin_u64_sum(qemu_plugin_u64 entry) } return total; } + +/* + * Time control + */ +static bool has_control; + +const void *qemu_plugin_request_time_control(void) +{ + if (!has_control) { + has_control =3D true; + return &has_control; + } + return NULL; +} + +static void advance_virtual_time__async(CPUState *cpu, run_on_cpu_data dat= a) +{ + int64_t new_time =3D data.host_ulong; + qemu_clock_advance_virtual_time(new_time); +} + +void qemu_plugin_update_ns(const void *handle, int64_t new_time) +{ + if (handle =3D=3D &has_control) { + /* Need to execute out of cpu_exec, so bql can be locked. */ + async_run_on_cpu(current_cpu, + advance_virtual_time__async, + RUN_ON_CPU_HOST_ULONG(new_time)); + } +} diff --git a/plugins/qemu-plugins.symbols b/plugins/qemu-plugins.symbols index aa0a77a319f..ca773d8d9fe 100644 --- a/plugins/qemu-plugins.symbols +++ b/plugins/qemu-plugins.symbols @@ -38,6 +38,7 @@ qemu_plugin_register_vcpu_tb_exec_cond_cb; qemu_plugin_register_vcpu_tb_exec_inline_per_vcpu; qemu_plugin_register_vcpu_tb_trans_cb; + qemu_plugin_request_time_control; qemu_plugin_reset; qemu_plugin_scoreboard_free; qemu_plugin_scoreboard_find; @@ -51,5 +52,6 @@ qemu_plugin_u64_set; qemu_plugin_u64_sum; qemu_plugin_uninstall; + qemu_plugin_update_ns; qemu_plugin_vcpu_for_each; }; --=20 2.39.2 From nobody Mon Nov 25 05:43:47 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1717091509; cv=none; d=zohomail.com; s=zohoarc; b=RiRLvf9SwQIDmx5XwKDlef+5U5wSCh8+alZsuv0czv0d5pBCtcdZVzL3i8QES592Me2iwmJUvHQUajdJRq5m0TJNlPIcqC1szHF1SLzUv7nmfPF+PfkuJBYb+n1oC723pgUsFD3JCAmVGCF7BYwsTn0L0O8GblPvAg6tScLsKXA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1717091509; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=a9mfgVW6aKcKwSz1phkXMBstK1m6Ri0Rr6frZF0Wh5I=; b=ZRd/T6xh87CKhQb127Gxyf7R+pifyS/84zN/z0yX+fCAo3lISGFz6+20z/BISSOAjqz9qohnMj5be8bQYo7WUW7+zRQc4mQukIoyDcMV9cUHWBNKTq40T25EfP/XhAu9Tp5e/AuU0HZl+SbaUTMo2Ib0bB6nAp6Eq4WH8m3Tecw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1717091509375596.9736423023891; Thu, 30 May 2024 10:51:49 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sCjud-0003tS-6b; Thu, 30 May 2024 13:50:03 -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 1sCjua-0003sw-9J for qemu-devel@nongnu.org; Thu, 30 May 2024 13:50:00 -0400 Received: from mail-pl1-x62d.google.com ([2607:f8b0:4864:20::62d]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sCjuY-0002T7-8h for qemu-devel@nongnu.org; Thu, 30 May 2024 13:50:00 -0400 Received: by mail-pl1-x62d.google.com with SMTP id d9443c01a7336-1f62fae8c1aso2114755ad.3 for ; Thu, 30 May 2024 10:49:57 -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.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 May 2024 10:49:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1717091396; x=1717696196; darn=nongnu.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=a9mfgVW6aKcKwSz1phkXMBstK1m6Ri0Rr6frZF0Wh5I=; b=voN+CQJqije/81pB0luWr/2dAU8KrBIB1eEk5qrDk3LkClzbTh/q8iaKAAfiagoT2M EYcAhTcGG8ssaQJsXFtnQne79/GmGjIFwirkfSKl4urykeUcDJ6Whkt9Zr/cisBgooQK uCxS3lJsvTl3YFVsDpFTSBVFVGnJGRXSQVXeMQJ86oF58UwuuzJx5VwUbXz4mpNDbjBf xYaZYAohelHvyuA+NGkyTjke6/tcY5KW47Yt3UYIMEb++QdadDC3ggAdqx/q6/nSWbz+ p/bfud2JbI/pTTleHqzALRqOJttjQeXiomDpLfrtvWt35/977mUlrbP5Hzc0aCrCT9zc V6Jw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717091396; x=1717696196; 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=a9mfgVW6aKcKwSz1phkXMBstK1m6Ri0Rr6frZF0Wh5I=; b=Daifze0QdHxCmOUIbwOBnYXOA8SnN58uGnWJ7MH79mDyWZOqRSH1UwZA2jK+k622Ky VJanc8otdpfz6i/YEVLpdGUp1+Lc13qZII/+SD0Rkz/JUH0x01JjpTXWrcUgcPzCAZnL wWITbo8j/k7ZoRSOiHiMk4Y/ZWLmYQbm5xEF7TdVm+Dwyi+x69jw3iNKA+syOfi915f5 9JEqZyXFDR+r/N9VVr2u9En1fwsUVd4sZU7bA72Z6kGTl0oykzc5B/y3Kkq0OyfIvmA4 5i6WG61BXQq8xA2XxZT38R1SpSoLeey8tTVbrtl+8OgK6n1NDORPfE5+41IL8XvSRY8F NjoQ== X-Gm-Message-State: AOJu0YwoI9tr97FyL45Pi4wC78DrqKD5POYWLcYjcpzWFKvWor6/n+u6 ryX3I9/GoE4BKbRVT8eKhelPfHjYx6NNfv23KCoKj73gkAwW+jG7RI3p7oaVQeqj7yTMdj70DPK RH/U= X-Google-Smtp-Source: AGHT+IHmqD8oKpXGiZ5yfj8l+uqnP81xtf3pC2ybaGHSvKTZqP9/u5cc0JLkGHy1ZjbisYBm30j5eg== X-Received: by 2002:a17:902:e549:b0:1f4:5fe5:74c9 with SMTP id d9443c01a7336-1f61a4e4e8emr38818015ad.69.1717091396339; Thu, 30 May 2024 10:49:56 -0700 (PDT) From: Pierrick Bouvier To: qemu-devel@nongnu.org Cc: Richard Henderson , Laurent Vivier , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Thomas Huth , Alexandre Iooss , Mahmoud Mandour , Paolo Bonzini , Pierrick Bouvier Subject: [PATCH v2 6/6] contrib/plugins: add ips plugin example for cost modeling Date: Thu, 30 May 2024 10:49:39 -0700 Message-Id: <20240530174939.749163-7-pierrick.bouvier@linaro.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240530174939.749163-1-pierrick.bouvier@linaro.org> References: <20240530174939.749163-1-pierrick.bouvier@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::62d; envelope-from=pierrick.bouvier@linaro.org; helo=mail-pl1-x62d.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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1717091510762100006 Content-Type: text/plain; charset="utf-8" This plugin uses the new time control interface to make decisions about the state of time during the emulation. The algorithm is currently very simple. The user specifies an ips rate which applies per core. If the core runs ahead of its allocated execution time the plugin sleeps for a bit to let real time catch up. Either way time is updated for the emulation as a function of total executed instructions with some adjustments for cores that idle. Examples -------- Slow down execution of /bin/true: $ num_insn=3D$(./build/qemu-x86_64 -plugin ./build/tests/plugin/libinsn.so = -d plugin /bin/true |& grep total | sed -e 's/.*: //') $ time ./build/qemu-x86_64 -plugin ./build/contrib/plugins/libips.so,ips=3D= $(($num_insn/4)) /bin/true real 4.000s Boot a Linux kernel simulating a 250MHz cpu: $ /build/qemu-system-x86_64 -kernel /boot/vmlinuz-6.1.0-21-amd64 -append "c= onsole=3DttyS0" -plugin ./build/contrib/plugins/libips.so,ips=3D$((250*1000= *1000)) -smp 1 -m 512 check time until kernel panic on serial0 Signed-off-by: Pierrick Bouvier --- contrib/plugins/ips.c | 239 +++++++++++++++++++++++++++++++++++++++ contrib/plugins/Makefile | 1 + 2 files changed, 240 insertions(+) create mode 100644 contrib/plugins/ips.c diff --git a/contrib/plugins/ips.c b/contrib/plugins/ips.c new file mode 100644 index 00000000000..cf3159df391 --- /dev/null +++ b/contrib/plugins/ips.c @@ -0,0 +1,239 @@ +/* + * ips rate limiting plugin. + * + * This plugin can be used to restrict the execution of a system to a + * particular number of Instructions Per Second (ips). This controls + * time as seen by the guest so while wall-clock time may be longer + * from the guests point of view time will pass at the normal rate. + * + * This uses the new plugin API which allows the plugin to control + * system time. + * + * Copyright (c) 2023 Linaro Ltd + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#include +#include +#include + +QEMU_PLUGIN_EXPORT int qemu_plugin_version =3D QEMU_PLUGIN_VERSION; + +/* how many times do we update time per sec */ +#define NUM_TIME_UPDATE_PER_SEC 10 +#define NSEC_IN_ONE_SEC (1000 * 1000 * 1000) + +static GMutex global_state_lock; + +static uint64_t insn_per_second =3D 1000 * 1000; /* ips per core, per seco= nd */ +static uint64_t insn_quantum; /* trap every N instructions */ +static bool precise_execution; /* count every instruction */ +static int64_t start_time_ns; /* time (ns since epoch) first vCPU started = */ +static int64_t virtual_time_ns; /* last set virtual time */ + +static const void *time_handle; + +typedef enum { + UNKNOWN =3D 0, + EXECUTING, + IDLE, + FINISHED +} vCPUState; + +typedef struct { + uint64_t counter; + uint64_t track_insn; + vCPUState state; + /* timestamp when vCPU entered state */ + int64_t last_state_time; +} vCPUTime; + +struct qemu_plugin_scoreboard *vcpus; + +/* return epoch time in ns */ +static int64_t now_ns(void) +{ + return g_get_real_time() * 1000; +} + +static uint64_t num_insn_during(int64_t elapsed_ns) +{ + double num_secs =3D elapsed_ns / (double) NSEC_IN_ONE_SEC; + return num_secs * (double) insn_per_second; +} + +static int64_t time_for_insn(uint64_t num_insn) +{ + double num_secs =3D (double) num_insn / (double) insn_per_second; + return num_secs * (double) NSEC_IN_ONE_SEC; +} + +static int64_t uptime_ns(void) +{ + int64_t now =3D now_ns(); + g_assert(now >=3D start_time_ns); + return now - start_time_ns; +} + +static void vcpu_set_state(vCPUTime *vcpu, vCPUState new_state) +{ + vcpu->last_state_time =3D now_ns(); + vcpu->state =3D new_state; +} + +static void update_system_time(vCPUTime *vcpu) +{ + /* flush remaining instructions */ + vcpu->counter +=3D vcpu->track_insn; + vcpu->track_insn =3D 0; + + int64_t uptime =3D uptime_ns(); + uint64_t expected_insn =3D num_insn_during(uptime); + + if (vcpu->counter >=3D expected_insn) { + /* this vcpu ran faster than expected, so it has to sleep */ + uint64_t insn_advance =3D vcpu->counter - expected_insn; + uint64_t time_advance_ns =3D time_for_insn(insn_advance); + int64_t sleep_us =3D time_advance_ns / 1000; + g_usleep(sleep_us); + } + + /* based on number of instructions, what should be the new time? */ + int64_t new_virtual_time =3D time_for_insn(vcpu->counter); + + g_mutex_lock(&global_state_lock); + + /* Time only moves forward. Another vcpu might have updated it already= . */ + if (new_virtual_time > virtual_time_ns) { + qemu_plugin_update_ns(time_handle, new_virtual_time); + virtual_time_ns =3D new_virtual_time; + } + + g_mutex_unlock(&global_state_lock); +} + +static void set_start_time() +{ + g_mutex_lock(&global_state_lock); + if (!start_time_ns) { + start_time_ns =3D now_ns(); + } + g_mutex_unlock(&global_state_lock); +} + +static void vcpu_init(qemu_plugin_id_t id, unsigned int cpu_index) +{ + vCPUTime *vcpu =3D qemu_plugin_scoreboard_find(vcpus, cpu_index); + /* ensure start time is set first */ + set_start_time(); + /* start counter from absolute time reference */ + vcpu->counter =3D num_insn_during(uptime_ns()); + vcpu_set_state(vcpu, EXECUTING); +} + +static void vcpu_idle(qemu_plugin_id_t id, unsigned int cpu_index) +{ + vCPUTime *vcpu =3D qemu_plugin_scoreboard_find(vcpus, cpu_index); + vcpu_set_state(vcpu, IDLE); +} + +static void vcpu_resume(qemu_plugin_id_t id, unsigned int cpu_index) +{ + vCPUTime *vcpu =3D qemu_plugin_scoreboard_find(vcpus, cpu_index); + g_assert(vcpu->state =3D=3D IDLE); + int64_t idle_time =3D now_ns() - vcpu->last_state_time; + /* accumulate expected number of instructions */ + vcpu->counter +=3D num_insn_during(idle_time); + vcpu_set_state(vcpu, EXECUTING); +} + +static void vcpu_exit(qemu_plugin_id_t id, unsigned int cpu_index) +{ + vCPUTime *vcpu =3D qemu_plugin_scoreboard_find(vcpus, cpu_index); + vcpu_set_state(vcpu, FINISHED); + update_system_time(vcpu); + vcpu->counter =3D 0; +} + +static void every_insn_quantum(unsigned int cpu_index, void *udata) +{ + vCPUTime *vcpu =3D qemu_plugin_scoreboard_find(vcpus, cpu_index); + g_assert(vcpu->track_insn >=3D insn_quantum); + update_system_time(vcpu); +} + +static void vcpu_tb_trans(qemu_plugin_id_t id, struct qemu_plugin_tb *tb) +{ + size_t n_insns =3D qemu_plugin_tb_n_insns(tb); + qemu_plugin_u64 track_insn =3D + qemu_plugin_scoreboard_u64_in_struct(vcpus, vCPUTime, track_insn); + if (precise_execution) { + /* count (and eventually trap) on every instruction */ + for (int idx =3D 0; idx < qemu_plugin_tb_n_insns(tb); ++idx) { + struct qemu_plugin_insn *insn =3D qemu_plugin_tb_get_insn(tb, = idx); + qemu_plugin_register_vcpu_insn_exec_inline_per_vcpu( + insn, QEMU_PLUGIN_INLINE_ADD_U64, track_insn, 1); + qemu_plugin_register_vcpu_insn_exec_cond_cb( + insn, every_insn_quantum, + QEMU_PLUGIN_CB_NO_REGS, QEMU_PLUGIN_COND_GE, + track_insn, insn_quantum, NULL); + } + } else { + /* count (and eventually trap) once per tb */ + qemu_plugin_register_vcpu_tb_exec_inline_per_vcpu( + tb, QEMU_PLUGIN_INLINE_ADD_U64, track_insn, n_insns); + qemu_plugin_register_vcpu_tb_exec_cond_cb( + tb, every_insn_quantum, + QEMU_PLUGIN_CB_NO_REGS, QEMU_PLUGIN_COND_GE, + track_insn, insn_quantum, NULL); + } +} + +static void plugin_exit(qemu_plugin_id_t id, void *udata) +{ + qemu_plugin_scoreboard_free(vcpus); +} + +QEMU_PLUGIN_EXPORT int qemu_plugin_install(qemu_plugin_id_t id, + const qemu_info_t *info, int ar= gc, + char **argv) +{ + for (int i =3D 0; i < argc; i++) { + char *opt =3D argv[i]; + g_auto(GStrv) tokens =3D g_strsplit(opt, "=3D", 2); + if (g_strcmp0(tokens[0], "ips") =3D=3D 0) { + insn_per_second =3D g_ascii_strtoull(tokens[1], NULL, 10); + if (!insn_per_second && errno) { + fprintf(stderr, "%s: couldn't parse %s (%s)\n", + __func__, tokens[1], g_strerror(errno)); + return -1; + } + + } else if (g_strcmp0(tokens[0], "precise") =3D=3D 0) { + if (!qemu_plugin_bool_parse(tokens[0], tokens[1], + &precise_execution)) { + fprintf(stderr, "boolean argument parsing failed: %s\n", o= pt); + return -1; + } + } else { + fprintf(stderr, "option parsing failed: %s\n", opt); + return -1; + } + } + + vcpus =3D qemu_plugin_scoreboard_new(sizeof(vCPUTime)); + insn_quantum =3D insn_per_second / NUM_TIME_UPDATE_PER_SEC; + + time_handle =3D qemu_plugin_request_time_control(); + g_assert(time_handle); + + qemu_plugin_register_vcpu_tb_trans_cb(id, vcpu_tb_trans); + qemu_plugin_register_vcpu_init_cb(id, vcpu_init); + qemu_plugin_register_vcpu_idle_cb(id, vcpu_idle); + qemu_plugin_register_vcpu_resume_cb(id, vcpu_resume); + qemu_plugin_register_vcpu_exit_cb(id, vcpu_exit); + qemu_plugin_register_atexit_cb(id, plugin_exit, NULL); + + return 0; +} diff --git a/contrib/plugins/Makefile b/contrib/plugins/Makefile index 0b64d2c1e3a..449ead11305 100644 --- a/contrib/plugins/Makefile +++ b/contrib/plugins/Makefile @@ -27,6 +27,7 @@ endif NAMES +=3D hwprofile NAMES +=3D cache NAMES +=3D drcov +NAMES +=3D ips =20 ifeq ($(CONFIG_WIN32),y) SO_SUFFIX :=3D .dll --=20 2.39.2