From nobody Sat May 18 16:18:00 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=1684516059; cv=none; d=zohomail.com; s=zohoarc; b=euJHSabHH9EiE5D0IrQFU5UhZAQip/jjLvto+fQDNM9QEIcV67bNN7gz6nmjtACHxbw1PR85+nWGyyXPLUhcas5KhJGphkV/l31U3WoIahGxr/6ReLvSoK8RFnALXWxT1kppcvdIF/zPbbD5Fh5gDMy3Y54rlwbnCEU9QZbeP/c= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1684516059; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=yg00DZfe+F7dr7y3vEVOv3SJnj/XXqqhg6oEcb/MIUE=; b=hyt0AkHYxLDmYEuLzkN/QWHXz5s7toylniQb0bkBZkTtqhZ8ukRdNtnOzvduCB4yyHOq0PsEzj9o/dbKKO/5gbSw6G3UHxKzEB+s8a6Cww7s/mosW1UAsRsRGZDmMr8dhgeQua4Yh30UqaQwnrebJG3xxFxW65JQUbgwpUn4QGA= 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 1684516059809390.58947065266204; Fri, 19 May 2023 10:07:39 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1q03Xd-0002HT-LO; Fri, 19 May 2023 13:05:21 -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 1q03XO-0002BU-A2 for qemu-devel@nongnu.org; Fri, 19 May 2023 13:05:07 -0400 Received: from mail-wr1-x42e.google.com ([2a00:1450:4864:20::42e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1q03XG-0005Tx-Hi for qemu-devel@nongnu.org; Fri, 19 May 2023 13:05:06 -0400 Received: by mail-wr1-x42e.google.com with SMTP id ffacd0b85a97d-3093a778089so2362732f8f.1 for ; Fri, 19 May 2023 10:04:57 -0700 (PDT) Received: from zen.linaroharston ([85.9.250.243]) by smtp.gmail.com with ESMTPSA id g9-20020adfe409000000b002ceacff44c7sm5776973wrm.83.2023.05.19.10.04.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 19 May 2023 10:04:55 -0700 (PDT) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id C540C1FFBC; Fri, 19 May 2023 18:04:54 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1684515896; x=1687107896; 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=yg00DZfe+F7dr7y3vEVOv3SJnj/XXqqhg6oEcb/MIUE=; b=KcBEl6YGiZuGjt8SqzMhHNVxP8yR/cPVhwv54wsHXjjWabkjD1ptkpKt53l1z2+PNC tXxYuBjMJ9Ql/QkVCOhcMCxxUfCISIJ8HaSv8UyBNbPSdEjexAZwsuI1N2LXHKEc8fIZ ytjTetekfopNnVKK0SQFLOtBk7Qht0l9pzEjqJFGrx5P/9CPmUegmhM+uTXycDtTNkYH DJcQ85rIh8V+E+/8JvkMPbyzTymtRoKcnhhfKUliWurof5NY+6nvgj1m+LDowsUKC9QH 7UvMTLOlNx3PFkkUYdVOiNVZ5HebK/2oS9Y41drPyMwcEQT0McLNF3aifbus0/SWaHR8 L8NA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684515896; x=1687107896; 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=yg00DZfe+F7dr7y3vEVOv3SJnj/XXqqhg6oEcb/MIUE=; b=CZzw8ELFWGpp1drJQsWs3R9CNiuHnwCs2e8yffDVvxd5HHZZP9ULqVlSNFq74MO51S TMkv28OA7XeqqyeiG6YFD6FpN86r2TmHpqMcRbz9VaHRg3QLGPtghfL+f5LgeIdcT+HU BWQAul7pIY4cNVs+OeRMhPsVdBHnwxxxgsN3EPr2TLj2QlGs4DDrCWXdphB6yvW4IclQ E+iuyLgurZ4V1EEgMLth2b1QScFEWQZpG5D1jhiOH+9UDoaXs2dRvf7kGlUQddYnh1K1 /ltmIdUdMc9OHPUlaadddk3SNMXJUEz2EXbyUeMq7bcjzZKzMX6o9GXBoSt5LnmUDwK9 1MwA== X-Gm-Message-State: AC+VfDzhZ9zNGg9LmMmI0KNlBt3wnWq8rU0gve6xbeeeXWNBU9qRlOIb TktaYS53XSN54u34vs8LsQcYRA== X-Google-Smtp-Source: ACHHUZ6oeCT6aVQqMdAZvwKRlGcFv9jiatQTorykaKHwqogxp2Vyn+mlclPbzBaHR5Wt6bZSmw3pAA== X-Received: by 2002:a05:6000:1010:b0:307:834f:7159 with SMTP id a16-20020a056000101000b00307834f7159mr2812482wrx.4.1684515896127; Fri, 19 May 2023 10:04:56 -0700 (PDT) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Alex=20Benn=C3=A9e?= , Yanan Wang , Riku Voipio , Laurent Vivier , Marcel Apfelbaum , Marco Liebel , Mark Burton , Thomas Huth , Peter Maydell , Richard Henderson , Eduardo Habkost , Paolo Bonzini , qemu-arm@nongnu.org, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Alexandre Iooss , Mahmoud Mandour , Robert Henry , Aaron Lindsay Subject: [PATCH 1/8] plugins: force slow path when plugins instrument memory ops Date: Fri, 19 May 2023 18:04:47 +0100 Message-Id: <20230519170454.2353945-2-alex.bennee@linaro.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230519170454.2353945-1-alex.bennee@linaro.org> References: <20230519170454.2353945-1-alex.bennee@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=2a00:1450:4864:20::42e; envelope-from=alex.bennee@linaro.org; helo=mail-wr1-x42e.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=unavailable 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: 1684516060577100001 The lack of SVE memory instrumentation has been an omission in plugin handling since it was introduced. Fortunately we can utilise the probe_* functions to force all all memory access to follow the slow path. We do this by checking the access type and presence of plugin memory callbacks and if set return the TLB_MMIO flag. We have to jump through a few hoops in user mode to re-use the flag but it was the desired effect: ./qemu-system-aarch64 -display none -serial mon:stdio \ -M virt -cpu max -semihosting-config enable=3Don \ -kernel ./tests/tcg/aarch64-softmmu/memory-sve \ -plugin ./contrib/plugins/libexeclog.so,ifilter=3Dst1w,afilter=3D0x40001= 808 -d plugin gives (disas doesn't currently understand st1w): 0, 0x40001808, 0xe54342a0, ".byte 0xa0, 0x42, 0x43, 0xe5", store, 0x40213= 010, RAM, store, 0x40213014, RAM, store, 0x40213018, RAM And for user-mode: ./qemu-aarch64 \ -plugin contrib/plugins/libexeclog.so,afilter=3D0x4007c0 \ -d plugin \ ./tests/tcg/aarch64-linux-user/sha512-sve gives: 1..10 ok 1 - do_test(&tests[i]) 0, 0x4007c0, 0xa4004b80, ".byte 0x80, 0x4b, 0x00, 0xa4", load, 0x55008003= 70, load, 0x5500800371, load, 0x5500800372, load, 0x5500800373, load, 0x550= 0800374, load, 0x5500800375, load, 0x5500800376, load, 0x5500800377, load, = 0x5500800378, load, 0x5500800379, load, 0x550080037a, load, 0x550080037b, l= oad, 0x550080037c, load, 0x550080037d, load, 0x550080037e, load, 0x55008003= 7f, load, 0x5500800380, load, 0x5500800381, load, 0x5500800382, load, 0x550= 0800383, load, 0x5500800384, load, 0x5500800385, load, 0x5500800386, lo ad, 0x5500800387, load, 0x5500800388, load, 0x5500800389, load, 0x5500800= 38a, load, 0x550080038b, load, 0x550080038c, load, 0x550080038d, load, 0x55= 0080038e, load, 0x550080038f, load, 0x5500800390, load, 0x5500800391, load,= 0x5500800392, load, 0x5500800393, load, 0x5500800394, load, 0x5500800395, = load, 0x5500800396, load, 0x5500800397, load, 0x5500800398, load, 0x5500800= 399, load, 0x550080039a, load, 0x550080039b, load, 0x550080039c, load, 0x55= 0080039d, load, 0x550080039e, load, 0x550080039f, load, 0x55008003a0, load,= 0x55008003a1, load, 0x55008003a2, load, 0x55008003a3, load, 0x55008003a4, = load, 0x55008003a5, load, 0x55008003a6, load, 0x55008003a7, load, 0x5500800= 3a8, load, 0x55008003a9, load, 0x55008003aa, load, 0x55008003ab, load, 0x55= 008003ac, load, 0x55008003ad, load, 0x55008003ae, load, 0x55008003af (4007c0 is the ld1b in the sha512-sve) Signed-off-by: Alex Benn=C3=A9e Reviewed-by: Richard Henderson Cc: Robert Henry Cc: Aaron Lindsay --- include/exec/cpu-all.h | 2 +- include/hw/core/cpu.h | 17 +++++++++++++++++ accel/tcg/cputlb.c | 4 +++- accel/tcg/user-exec.c | 6 +++++- target/arm/tcg/sve_helper.c | 4 ---- tests/tcg/aarch64/Makefile.target | 8 ++++++++ 6 files changed, 34 insertions(+), 7 deletions(-) diff --git a/include/exec/cpu-all.h b/include/exec/cpu-all.h index 78d258af44..9ab09cf7c2 100644 --- a/include/exec/cpu-all.h +++ b/include/exec/cpu-all.h @@ -301,7 +301,7 @@ CPUArchState *cpu_copy(CPUArchState *env); * be signaled by probe_access_flags(). */ #define TLB_INVALID_MASK (1 << (TARGET_PAGE_BITS_MIN - 1)) -#define TLB_MMIO 0 +#define TLB_MMIO (1 << (TARGET_PAGE_BITS_MIN - 2)) #define TLB_WATCHPOINT 0 =20 #else diff --git a/include/hw/core/cpu.h b/include/hw/core/cpu.h index 39150cf8f8..26fadf7e62 100644 --- a/include/hw/core/cpu.h +++ b/include/hw/core/cpu.h @@ -983,6 +983,23 @@ void cpu_watchpoint_remove_by_ref(CPUState *cpu, CPUWa= tchpoint *watchpoint); void cpu_watchpoint_remove_all(CPUState *cpu, int mask); #endif =20 +/** + * cpu_plugin_mem_cbs_enabled() - are plugin memory callbacks enabled? + * @cs: CPUState pointer + * + * The memory callbacks are installed if a plugin has instrumented an + * instruction for memory. This can be useful to know if you want to + * force a slow path for a series of memory accesses. + */ +static inline bool cpu_plugin_mem_cbs_enabled(const CPUState *cpu) +{ +#ifdef CONFIG_PLUGIN + return !!cpu->plugin_mem_cbs; +#else + return false; +#endif +} + /** * cpu_get_address_space: * @cpu: CPU to get address space from diff --git a/accel/tcg/cputlb.c b/accel/tcg/cputlb.c index ae0fbcdee2..f117fd8f16 100644 --- a/accel/tcg/cputlb.c +++ b/accel/tcg/cputlb.c @@ -1540,7 +1540,9 @@ static int probe_access_internal(CPUArchState *env, t= arget_ulong addr, *pfull =3D &env_tlb(env)->d[mmu_idx].fulltlb[index]; =20 /* Fold all "mmio-like" bits into TLB_MMIO. This is not RAM. */ - if (unlikely(flags & ~(TLB_WATCHPOINT | TLB_NOTDIRTY))) { + if (unlikely(flags & ~(TLB_WATCHPOINT | TLB_NOTDIRTY)) + || + (access_type !=3D MMU_INST_FETCH && cpu_plugin_mem_cbs_enabled(env= _cpu(env)))) { *phost =3D NULL; return TLB_MMIO; } diff --git a/accel/tcg/user-exec.c b/accel/tcg/user-exec.c index 36ad8284a5..383263cd1d 100644 --- a/accel/tcg/user-exec.c +++ b/accel/tcg/user-exec.c @@ -745,6 +745,10 @@ static int probe_access_internal(CPUArchState *env, ta= rget_ulong addr, if (guest_addr_valid_untagged(addr)) { int page_flags =3D page_get_flags(addr); if (page_flags & acc_flag) { + if ((acc_flag =3D=3D PAGE_READ || acc_flag =3D=3D PAGE_WRITE) + && cpu_plugin_mem_cbs_enabled(env_cpu(env))) { + return TLB_MMIO; + } return 0; /* success */ } maperr =3D !(page_flags & PAGE_VALID); @@ -767,7 +771,7 @@ int probe_access_flags(CPUArchState *env, target_ulong = addr, int size, =20 g_assert(-(addr | TARGET_PAGE_MASK) >=3D size); flags =3D probe_access_internal(env, addr, size, access_type, nonfault= , ra); - *phost =3D flags ? NULL : g2h(env_cpu(env), addr); + *phost =3D (flags & TLB_INVALID_MASK) ? NULL : g2h(env_cpu(env), addr); return flags; } =20 diff --git a/target/arm/tcg/sve_helper.c b/target/arm/tcg/sve_helper.c index 0097522470..7c103fc9f7 100644 --- a/target/arm/tcg/sve_helper.c +++ b/target/arm/tcg/sve_helper.c @@ -5688,9 +5688,6 @@ void sve_ldN_r(CPUARMState *env, uint64_t *vg, const = target_ulong addr, =20 flags =3D info.page[0].flags | info.page[1].flags; if (unlikely(flags !=3D 0)) { -#ifdef CONFIG_USER_ONLY - g_assert_not_reached(); -#else /* * At least one page includes MMIO. * Any bus operation can fail with cpu_transaction_failed, @@ -5727,7 +5724,6 @@ void sve_ldN_r(CPUARMState *env, uint64_t *vg, const = target_ulong addr, memcpy(&env->vfp.zregs[(rd + i) & 31], &scratch[i], reg_max); } return; -#endif } =20 /* The entire operation is in RAM, on valid pages. */ diff --git a/tests/tcg/aarch64/Makefile.target b/tests/tcg/aarch64/Makefile= .target index 0315795487..f83edd8544 100644 --- a/tests/tcg/aarch64/Makefile.target +++ b/tests/tcg/aarch64/Makefile.target @@ -80,6 +80,14 @@ sha512-vector: sha512.c =20 TESTS +=3D sha512-vector =20 +ifneq ($(CROSS_CC_HAS_SVE),) +sha512-sve: CFLAGS=3D-O3 -march=3Darmv8.1-a+sve +sha512-sve: sha512.c + $(CC) $(CFLAGS) $(EXTRA_CFLAGS) $< -o $@ $(LDFLAGS) + +TESTS +=3D sha512-sve +endif + ifeq ($(HOST_GDB_SUPPORTS_ARCH),y) GDB_SCRIPT=3D$(SRC_PATH)/tests/guest-debug/run-test.py =20 --=20 2.39.2 From nobody Sat May 18 16:18:00 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=1684515992; cv=none; d=zohomail.com; s=zohoarc; b=dEAJMMlE6QcwLgmiAeiErmGERiJ8LTd6uff/yfZ9plP/YcLjYtb1McTRGhgCPnxAm/ZGh4E6l8OHL1yQ26ez88zJKpsZudufcYngEJ+YWjaQMt37bhS0Swrta10rnjlmoBus6YiLb73bpHmXElaRoxDRvF6zZxONjq5hTs8+Jfs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1684515992; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=BK8vzqUrJMrBxmrdwxNxw8ipZXv8OO87/QXAs2j6w1U=; b=NYKmDmA+T8LhbS0gM8kVutuAZFc1hjgmdPJlKmb6oIyEgVY1UjOPcoUIRkUVWF2qWzEhPjAbx9DmU8hEziZ3bdPTsnN7/KcmSJtxkD2UFqqULFnhgh4K9bMfSWF9+w5g8rTaT9rZw66DDAx3ZdlQOZIBOgxCHkSkObifDq+Hp5Q= 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 1684515992844277.6528681812773; Fri, 19 May 2023 10:06:32 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1q03XT-0002CU-6c; Fri, 19 May 2023 13:05:11 -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 1q03XL-0002AU-Bx for qemu-devel@nongnu.org; Fri, 19 May 2023 13:05:03 -0400 Received: from mail-wr1-x432.google.com ([2a00:1450:4864:20::432]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1q03XG-0005UD-JQ for qemu-devel@nongnu.org; Fri, 19 May 2023 13:05:03 -0400 Received: by mail-wr1-x432.google.com with SMTP id ffacd0b85a97d-30796c0cbcaso3501932f8f.1 for ; Fri, 19 May 2023 10:04:57 -0700 (PDT) Received: from zen.linaroharston ([85.9.250.243]) by smtp.gmail.com with ESMTPSA id g14-20020a056000118e00b002f22c44e974sm5860820wrx.102.2023.05.19.10.04.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 19 May 2023 10:04:55 -0700 (PDT) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id 082371FFBD; Fri, 19 May 2023 18:04:55 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1684515897; x=1687107897; 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=BK8vzqUrJMrBxmrdwxNxw8ipZXv8OO87/QXAs2j6w1U=; b=Hl5pDHGRZc5GBGHznaYo7jDDA+R9D1AMLJ7qaH24CFjMWSGv6yv0Y/tQrYlwzyNE2a FZqrqWZGpdUDvzuQSLx3rdDvRGOEZlZYKQ8kYExALC5eK0Pkbxfp1I4zzOUni3PnkHYT hEWLlPzbfUGRGslqWBPNvylOG27NN7/Nr48G7NjYrnJ4ZbnXRsSRTamGMfw65IalfW4L weV16U0lccYEnTRDMMWOvBYB7QF8XVrd1c6RmuLtLEZSEoEAuEt9nab7bp4/nf5Vtizw ht/ES3b6yldyOza7ay+Yd17unLkM2ZIt8ZzyrPatGpoYYE6EQMfgPuyQeQsWUbBmCmrO VX9Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684515897; x=1687107897; 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=BK8vzqUrJMrBxmrdwxNxw8ipZXv8OO87/QXAs2j6w1U=; b=U8/LFRxIogLAQdVSga2lyXJYgyna+viMi9nIEJhQki15ATz2495Opi0tLcy+5pUX/w 05HqlB8tp4muREoDW3NRzORXkc3B7dkJaRfsOKmk3fIbXVRmeI3v6oZEn3ynKor3Gikb xTrlpS4Bg9n+AWAJ7BFgI8+bvWEZkUwEAerkhEMrxUhZ5aV890lUksl41NKuRYSNMHiw KQRKYqNlXtsegdjVOjewst8c7U0rITjutnomwpxWWOX/xPfhgWlshgox4U58d2EXKXaZ C5GF9UGmFOe5df8L3smRr9EhQ23VPNYcYdw/U+wDCaBfkChFZmcJUgeR14ypeBd5nhxF 9nGw== X-Gm-Message-State: AC+VfDxKT1JA1SG2MqxascqhNfZ2A1/k4ePJue9liJh/i8tELUgA4BF0 SJQaeIOBcDXWAyVS8aPCocEnBA== X-Google-Smtp-Source: ACHHUZ7LFLHVxkdrw0MVWFizH8zYe15AkKZboPW4rJdv6kaZ7wZIIjn42TqX/grY8TbbFV7bx1TOlg== X-Received: by 2002:adf:e941:0:b0:2ef:eb54:4dc0 with SMTP id m1-20020adfe941000000b002efeb544dc0mr2296060wrn.51.1684515896590; Fri, 19 May 2023 10:04:56 -0700 (PDT) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Alex=20Benn=C3=A9e?= , Yanan Wang , Riku Voipio , Laurent Vivier , Marcel Apfelbaum , Marco Liebel , Mark Burton , Thomas Huth , Peter Maydell , Richard Henderson , Eduardo Habkost , Paolo Bonzini , qemu-arm@nongnu.org, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Alexandre Iooss , Mahmoud Mandour Subject: [PATCH 2/8] plugins: fix memory leak while parsing options Date: Fri, 19 May 2023 18:04:48 +0100 Message-Id: <20230519170454.2353945-3-alex.bennee@linaro.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230519170454.2353945-1-alex.bennee@linaro.org> References: <20230519170454.2353945-1-alex.bennee@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=2a00:1450:4864:20::432; envelope-from=alex.bennee@linaro.org; helo=mail-wr1-x432.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=unavailable 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: 1684515995183100003 It was hard to track down this leak as it was an internal allocation by glib and the backtraces did not give much away. The autofree was freeing the allocation with g_free() but not taking care of the individual strings. They should have been freed with g_strfreev() instead. Searching the glib source code for the correct string free function led to: G_DEFINE_AUTO_CLEANUP_FREE_FUNC(GStrv, g_strfreev, NULL) and indeed if you read to the bottom of the documentation page you will find: typedef gchar** GStrv; A typedef alias for gchar**. This is mostly useful when used together wit= h g_auto(). So fix up all the g_autofree g_strsplit case that smugly thought they had de-allocation covered. Signed-off-by: Alex Benn=C3=A9e Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- contrib/plugins/cache.c | 2 +- contrib/plugins/drcov.c | 2 +- contrib/plugins/execlog.c | 2 +- contrib/plugins/hotblocks.c | 2 +- contrib/plugins/hotpages.c | 2 +- contrib/plugins/howvec.c | 2 +- contrib/plugins/hwprofile.c | 2 +- contrib/plugins/lockstep.c | 2 +- tests/plugin/bb.c | 2 +- tests/plugin/insn.c | 2 +- tests/plugin/mem.c | 2 +- tests/plugin/syscall.c | 2 +- 12 files changed, 12 insertions(+), 12 deletions(-) diff --git a/contrib/plugins/cache.c b/contrib/plugins/cache.c index 2e25184a7f..5036213f1b 100644 --- a/contrib/plugins/cache.c +++ b/contrib/plugins/cache.c @@ -772,7 +772,7 @@ int qemu_plugin_install(qemu_plugin_id_t id, const qemu= _info_t *info, =20 for (i =3D 0; i < argc; i++) { char *opt =3D argv[i]; - g_autofree char **tokens =3D g_strsplit(opt, "=3D", 2); + g_auto(GStrv) tokens =3D g_strsplit(opt, "=3D", 2); =20 if (g_strcmp0(tokens[0], "iblksize") =3D=3D 0) { l1_iblksize =3D STRTOLL(tokens[1]); diff --git a/contrib/plugins/drcov.c b/contrib/plugins/drcov.c index b4a855adaf..686ae0a537 100644 --- a/contrib/plugins/drcov.c +++ b/contrib/plugins/drcov.c @@ -148,7 +148,7 @@ int qemu_plugin_install(qemu_plugin_id_t id, const qemu= _info_t *info, int argc, char **argv) { for (int i =3D 0; i < argc; i++) { - g_autofree char **tokens =3D g_strsplit(argv[i], "=3D", 2); + g_auto(GStrv) tokens =3D g_strsplit(argv[i], "=3D", 2); if (g_strcmp0(tokens[0], "filename") =3D=3D 0) { file_name =3D g_strdup(tokens[1]); } diff --git a/contrib/plugins/execlog.c b/contrib/plugins/execlog.c index e255bd21fd..7129d526f8 100644 --- a/contrib/plugins/execlog.c +++ b/contrib/plugins/execlog.c @@ -227,7 +227,7 @@ QEMU_PLUGIN_EXPORT int qemu_plugin_install(qemu_plugin_= id_t id, =20 for (int i =3D 0; i < argc; i++) { char *opt =3D argv[i]; - g_autofree char **tokens =3D g_strsplit(opt, "=3D", 2); + g_auto(GStrv) tokens =3D g_strsplit(opt, "=3D", 2); if (g_strcmp0(tokens[0], "ifilter") =3D=3D 0) { parse_insn_match(tokens[1]); } else if (g_strcmp0(tokens[0], "afilter") =3D=3D 0) { diff --git a/contrib/plugins/hotblocks.c b/contrib/plugins/hotblocks.c index 062200a7a4..6b74d25fea 100644 --- a/contrib/plugins/hotblocks.c +++ b/contrib/plugins/hotblocks.c @@ -135,7 +135,7 @@ int qemu_plugin_install(qemu_plugin_id_t id, const qemu= _info_t *info, { for (int i =3D 0; i < argc; i++) { char *opt =3D argv[i]; - g_autofree char **tokens =3D g_strsplit(opt, "=3D", 2); + g_auto(GStrv) tokens =3D g_strsplit(opt, "=3D", 2); if (g_strcmp0(tokens[0], "inline") =3D=3D 0) { if (!qemu_plugin_bool_parse(tokens[0], tokens[1], &do_inline))= { fprintf(stderr, "boolean argument parsing failed: %s\n", o= pt); diff --git a/contrib/plugins/hotpages.c b/contrib/plugins/hotpages.c index 0d12910af6..8316ae50c7 100644 --- a/contrib/plugins/hotpages.c +++ b/contrib/plugins/hotpages.c @@ -169,7 +169,7 @@ int qemu_plugin_install(qemu_plugin_id_t id, const qemu= _info_t *info, =20 for (i =3D 0; i < argc; i++) { char *opt =3D argv[i]; - g_autofree char **tokens =3D g_strsplit(opt, "=3D", -1); + g_auto(GStrv) tokens =3D g_strsplit(opt, "=3D", -1); =20 if (g_strcmp0(tokens[0], "sortby") =3D=3D 0) { if (g_strcmp0(tokens[1], "reads") =3D=3D 0) { diff --git a/contrib/plugins/howvec.c b/contrib/plugins/howvec.c index 4a5ec3d936..0ed01ea931 100644 --- a/contrib/plugins/howvec.c +++ b/contrib/plugins/howvec.c @@ -333,7 +333,7 @@ QEMU_PLUGIN_EXPORT int qemu_plugin_install(qemu_plugin_= id_t id, =20 for (i =3D 0; i < argc; i++) { char *p =3D argv[i]; - g_autofree char **tokens =3D g_strsplit(p, "=3D", -1); + g_auto(GStrv) tokens =3D g_strsplit(p, "=3D", -1); if (g_strcmp0(tokens[0], "inline") =3D=3D 0) { if (!qemu_plugin_bool_parse(tokens[0], tokens[1], &do_inline))= { fprintf(stderr, "boolean argument parsing failed: %s\n", p= ); diff --git a/contrib/plugins/hwprofile.c b/contrib/plugins/hwprofile.c index 691d4edb0c..739ac0c66b 100644 --- a/contrib/plugins/hwprofile.c +++ b/contrib/plugins/hwprofile.c @@ -263,7 +263,7 @@ int qemu_plugin_install(qemu_plugin_id_t id, const qemu= _info_t *info, =20 for (i =3D 0; i < argc; i++) { char *opt =3D argv[i]; - g_autofree char **tokens =3D g_strsplit(opt, "=3D", 2); + g_auto(GStrv) tokens =3D g_strsplit(opt, "=3D", 2); =20 if (g_strcmp0(tokens[0], "track") =3D=3D 0) { if (g_strcmp0(tokens[1], "read") =3D=3D 0) { diff --git a/contrib/plugins/lockstep.c b/contrib/plugins/lockstep.c index a41ffe83fa..e36f0b9562 100644 --- a/contrib/plugins/lockstep.c +++ b/contrib/plugins/lockstep.c @@ -323,7 +323,7 @@ QEMU_PLUGIN_EXPORT int qemu_plugin_install(qemu_plugin_= id_t id, =20 for (i =3D 0; i < argc; i++) { char *p =3D argv[i]; - g_autofree char **tokens =3D g_strsplit(p, "=3D", 2); + g_auto(GStrv) tokens =3D g_strsplit(p, "=3D", 2); =20 if (g_strcmp0(tokens[0], "verbose") =3D=3D 0) { if (!qemu_plugin_bool_parse(tokens[0], tokens[1], &verbose)) { diff --git a/tests/plugin/bb.c b/tests/plugin/bb.c index 7d470a1011..df50d1fd3b 100644 --- a/tests/plugin/bb.c +++ b/tests/plugin/bb.c @@ -104,7 +104,7 @@ QEMU_PLUGIN_EXPORT int qemu_plugin_install(qemu_plugin_= id_t id, =20 for (i =3D 0; i < argc; i++) { char *opt =3D argv[i]; - g_autofree char **tokens =3D g_strsplit(opt, "=3D", 2); + g_auto(GStrv) tokens =3D g_strsplit(opt, "=3D", 2); if (g_strcmp0(tokens[0], "inline") =3D=3D 0) { if (!qemu_plugin_bool_parse(tokens[0], tokens[1], &do_inline))= { fprintf(stderr, "boolean argument parsing failed: %s\n", o= pt); diff --git a/tests/plugin/insn.c b/tests/plugin/insn.c index cd5ea5d4ae..e251a84d86 100644 --- a/tests/plugin/insn.c +++ b/tests/plugin/insn.c @@ -196,7 +196,7 @@ QEMU_PLUGIN_EXPORT int qemu_plugin_install(qemu_plugin_= id_t id, { for (int i =3D 0; i < argc; i++) { char *opt =3D argv[i]; - g_autofree char **tokens =3D g_strsplit(opt, "=3D", 2); + g_auto(GStrv) tokens =3D g_strsplit(opt, "=3D", 2); if (g_strcmp0(tokens[0], "inline") =3D=3D 0) { if (!qemu_plugin_bool_parse(tokens[0], tokens[1], &do_inline))= { fprintf(stderr, "boolean argument parsing failed: %s\n", o= pt); diff --git a/tests/plugin/mem.c b/tests/plugin/mem.c index 4570f7d815..f3b9f696a0 100644 --- a/tests/plugin/mem.c +++ b/tests/plugin/mem.c @@ -83,7 +83,7 @@ QEMU_PLUGIN_EXPORT int qemu_plugin_install(qemu_plugin_id= _t id, =20 for (int i =3D 0; i < argc; i++) { char *opt =3D argv[i]; - g_autofree char **tokens =3D g_strsplit(opt, "=3D", 2); + g_auto(GStrv) tokens =3D g_strsplit(opt, "=3D", 2); =20 if (g_strcmp0(tokens[0], "haddr") =3D=3D 0) { if (!qemu_plugin_bool_parse(tokens[0], tokens[1], &do_haddr)) { diff --git a/tests/plugin/syscall.c b/tests/plugin/syscall.c index 96040c578f..72e1a5bf90 100644 --- a/tests/plugin/syscall.c +++ b/tests/plugin/syscall.c @@ -121,7 +121,7 @@ QEMU_PLUGIN_EXPORT int qemu_plugin_install(qemu_plugin_= id_t id, =20 for (int i =3D 0; i < argc; i++) { char *opt =3D argv[i]; - g_autofree char **tokens =3D g_strsplit(opt, "=3D", 2); + g_auto(GStrv) tokens =3D g_strsplit(opt, "=3D", 2); =20 if (g_strcmp0(tokens[0], "print") =3D=3D 0) { if (!qemu_plugin_bool_parse(tokens[0], tokens[1], &do_print)) { --=20 2.39.2 From nobody Sat May 18 16:18:00 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=1684515931; cv=none; d=zohomail.com; s=zohoarc; b=gBt1Ct9wMBVfK7avv0rav/iCcLiPXzmQkvVzRh6FwjKfmDJL/4IM6eHF9opHV1rJ6frJLqWeFzmr5W51iUyeGGlupuKm/HR4unAieShESwxxN62goOhGCUp+uw92lvV4tQqZ/1SNlWF8EBI0wwgJ1uSBQm0dCLFXvFu4qV2+Mbc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1684515931; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=BBI1EKXYVa+WMuYu7l3ZX5976guHRdH5nUfqC+4pCho=; b=JMueq+0r3Acr69Z7j8zFEkBzs3zUlv/ypysD8I3SZxTcEz4cWMbaIwBnsQrxpBilxfQgiTW4wwg6pR7JSfiqzZzKaJJvvlz71klsW/DZCgU3nJ+x2AAX9AWucjD2xrp+dIxBdIiyi8zmPCm9rcmPoWwsLyM16yV/kV6AnWVQ9AA= 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 1684515931286719.7817078250195; Fri, 19 May 2023 10:05:31 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1q03XN-0002Au-Ef; Fri, 19 May 2023 13:05:05 -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 1q03XJ-00029v-7I for qemu-devel@nongnu.org; Fri, 19 May 2023 13:05:01 -0400 Received: from mail-wm1-x32a.google.com ([2a00:1450:4864:20::32a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1q03XG-0005UH-Hp for qemu-devel@nongnu.org; Fri, 19 May 2023 13:05:00 -0400 Received: by mail-wm1-x32a.google.com with SMTP id 5b1f17b1804b1-3f42d937d61so33855725e9.3 for ; Fri, 19 May 2023 10:04:58 -0700 (PDT) Received: from zen.linaroharston ([85.9.250.243]) by smtp.gmail.com with ESMTPSA id h19-20020a05600c28d300b003f427cba193sm2930166wmd.41.2023.05.19.10.04.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 19 May 2023 10:04:55 -0700 (PDT) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id 21BD71FFBE; Fri, 19 May 2023 18:04:55 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1684515897; x=1687107897; 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=BBI1EKXYVa+WMuYu7l3ZX5976guHRdH5nUfqC+4pCho=; b=vSmseuVKS6Pcki9dUs+hDKsDj5LH/PEe50J3O453cteuGX9FwoczU5sb9sAllS+CVy JdZjpW+/FxfM+LoDPc1MOOQSD6rBqcFC7pnG3Dzqyd7gl4pA/C2cGw33uTjhFYr5F8qa klZQP08Z18CMRNTFBmK/3W9aUVqqLm3jmBEb3Pe7tPSAsMXpV/dl9PRTMuImcpoVM/md EW+s8dsX3sOkJuVLlk/b2TgvjI0FM5n0/XpWZlBHGh7xiafdwMi/Z5Dpwr0vCMaeAIfH 148l2CdNleTx+Eis7VWN5wyEyE/IF/KgrVyVCvhd6yLAnetKivz1+NmTDAAIBNi6C0IM 6Jcg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684515897; x=1687107897; 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=BBI1EKXYVa+WMuYu7l3ZX5976guHRdH5nUfqC+4pCho=; b=YfriuakDmig8IrkeZCmchVRUJC9LgB1x3TUxSnOkEs7CoOAgMNeVqcITTsJWWv1gAM wvLz1PpY5Hfa6J+v0nzZYPPQbzj35Y/ANVkC3EliztN7+MXS9yjCaGj73ylqudyxOtJA gefg3PRXZswXW0zwFfVH/l1YJQLB/bTgNqG8FJlSGk5+4/g4Wdb4aXizzhRYlFbijPN0 dfjlG2E272Rp6PFpPxzIOEEz3lkVPJOOIiR8zixvw/EGZqEFAtfHw2o7RiIaUTvLbGWa ZApxpsCchJFd3D9TGFzR4Ysft7VTY3yXG++rWBtRbZf2NwfStfi8jahVCGP072RuwxcH lljg== X-Gm-Message-State: AC+VfDwH5Q0k7/51xHLR7pZCNAXeBW7CA3oKDOkHZeqmh9n6qQ8GcdTQ sNP0Il4CMXcZDobtFt0Uzlb6fw== X-Google-Smtp-Source: ACHHUZ6AZsW9QVuKR3pyOaZXsLrnlVqSTirKilv1SQhyayMtGZt7OgDh1XUuMoMQRvIKfnBMIdZCEA== X-Received: by 2002:a05:600c:ad2:b0:3f4:294d:8529 with SMTP id c18-20020a05600c0ad200b003f4294d8529mr1919989wmr.19.1684515896798; Fri, 19 May 2023 10:04:56 -0700 (PDT) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Alex=20Benn=C3=A9e?= , Yanan Wang , Riku Voipio , Laurent Vivier , Marcel Apfelbaum , Marco Liebel , Mark Burton , Thomas Huth , Peter Maydell , Richard Henderson , Eduardo Habkost , Paolo Bonzini , qemu-arm@nongnu.org, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Alexandre Iooss , Mahmoud Mandour Subject: [PATCH 3/8] plugins: update lockstep to use g_memdup2 Date: Fri, 19 May 2023 18:04:49 +0100 Message-Id: <20230519170454.2353945-4-alex.bennee@linaro.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230519170454.2353945-1-alex.bennee@linaro.org> References: <20230519170454.2353945-1-alex.bennee@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=2a00:1450:4864:20::32a; envelope-from=alex.bennee@linaro.org; helo=mail-wm1-x32a.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: 1684515933339100002 The old g_memdup is deprecated, use the replacement. Signed-off-by: Alex Benn=C3=A9e --- contrib/plugins/lockstep.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contrib/plugins/lockstep.c b/contrib/plugins/lockstep.c index e36f0b9562..3614c3564c 100644 --- a/contrib/plugins/lockstep.c +++ b/contrib/plugins/lockstep.c @@ -130,7 +130,7 @@ static void report_divergance(ExecState *us, ExecState = *them) } } divergence_log =3D g_slist_prepend(divergence_log, - g_memdup(&divrec, sizeof(divrec))); + g_memdup2(&divrec, sizeof(divrec))); =20 /* Output short log entry of going out of sync... */ if (verbose || divrec.distance =3D=3D 1 || diverged) { --=20 2.39.2 From nobody Sat May 18 16:18:00 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=1684516028; cv=none; d=zohomail.com; s=zohoarc; b=UTIokjXcCyECxpshzUKWfC81nvXBcYV9E+txCjDV2x6MjOxFTvCef63JR2Ohex8Z1B/rzrSjnJ5iowxNnxhY+rwaK0YfTwAPWyU2X0ydrKWcsDP1YhzoLlnXMb+cUd0WsppRjV2tOdvFc/q6sRLS8eOKyWSs/cSuyfNUKZ6k7Ik= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1684516028; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=Y4Fc4cXBL03Lk5/gUamd723FCI9OSGD0ICedLkUTlC8=; b=bg0wXIZ1C02Nmu+ttFvvFH52J/qNNIPI4NFebr186RiwGJvLTpSpu6bAVFcC20QWuzDhhFlBhCdhpoZfZV8IyU6istWLyupdS4DTcxWpo+gr9JqpkSUzngU0RLWKPTss0OslovD8qtHRhvADlmyxfbNsYqSmS2C6aSkvpXLyLG4= 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 1684516028717376.56971691734395; Fri, 19 May 2023 10:07:08 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1q03XV-0002DT-5i; Fri, 19 May 2023 13:05:14 -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 1q03XM-0002Ay-8P for qemu-devel@nongnu.org; Fri, 19 May 2023 13:05:05 -0400 Received: from mail-wr1-x435.google.com ([2a00:1450:4864:20::435]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1q03XG-0005UU-JT for qemu-devel@nongnu.org; Fri, 19 May 2023 13:05:03 -0400 Received: by mail-wr1-x435.google.com with SMTP id ffacd0b85a97d-3063891d61aso3336173f8f.0 for ; Fri, 19 May 2023 10:04:58 -0700 (PDT) Received: from zen.linaroharston ([85.9.250.243]) by smtp.gmail.com with ESMTPSA id q18-20020a5d61d2000000b003079c402762sm5839752wrv.19.2023.05.19.10.04.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 19 May 2023 10:04:55 -0700 (PDT) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id 45B7F1FFBF; Fri, 19 May 2023 18:04:55 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1684515897; x=1687107897; 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=Y4Fc4cXBL03Lk5/gUamd723FCI9OSGD0ICedLkUTlC8=; b=VoUv1nLC184dLCFpeVOU/3BGEqI2CEotvOCQcmUYFihVkWGFJCKJaYZYUx9i0roFTf rVoRRMuFj/nqHPNwpKD7b5CuIgC0Z8qaHwTg+4zVv+jQ7mFjLrMUfd1CWHcxRkMGAsYr P8u2lsUmEWbPKlEf1CZayJduKSCTPf27RwQM61/0Z3340vNRAH+ckYatuqBA9lhHUD1k n0P2IzoXhphlA/QTIgsbedCNx6ioryaEDTBDezVVuQCj5iCynTHuGbP9nDRc+edz2nNz K21oUyvCGpwr5jRjDh0JAbZxHlJe0jo0RmJWAA0jU3TyFhTEJ1XjvqvG+PCy7W3mMeID SjiQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684515897; x=1687107897; 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=Y4Fc4cXBL03Lk5/gUamd723FCI9OSGD0ICedLkUTlC8=; b=lhg6Xjb5e5PziRQ0fnmGcszcBGckt+5ogz4n9EYxSjf4Zew1YT7MKCRpK2HfVcv04D 5ev9VUhPaV1E6FR/3S34x+ma0/mZ0W9O9gUFHna0NSo17heF5nZq43Q3S/6mZc7t2sMW aCZBUx/5nGK+1D6sDEVi3XRwOAoN32WcdEK9d3mqxORuYfMrB5wiX2QFEwQJsYPXqY79 Y5UecYxBSDvQcs2IEbaPaM9wD/RgqxkRWY8bwSgACsyTzrZZA9zuK8013M56Jc2J4Vqy IqnE88N56QZeOE7BeA9T5LDxU6ejqsbRJK3TYlyCz2YZCS8MQXCAV9b1ShJNr9qOssC+ NThA== X-Gm-Message-State: AC+VfDwuHp8uIiUi9Kpm8B52B+SDm1MO/v7vwsHq9oV/onmhqdoiud34 1ZtxZ/Flr/ni3rA91dCI6Uvskg== X-Google-Smtp-Source: ACHHUZ7EeK4jwhITIzB5jIITj9Ez4i/5hFOqUHFlzttnGaWFalUmmg2u0ot2O6BpZoV8p+MdfFTWmw== X-Received: by 2002:adf:e689:0:b0:309:38af:d300 with SMTP id r9-20020adfe689000000b0030938afd300mr2008452wrm.33.1684515897196; Fri, 19 May 2023 10:04:57 -0700 (PDT) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Alex=20Benn=C3=A9e?= , Yanan Wang , Riku Voipio , Laurent Vivier , Marcel Apfelbaum , Marco Liebel , Mark Burton , Thomas Huth , Peter Maydell , Richard Henderson , Eduardo Habkost , Paolo Bonzini , qemu-arm@nongnu.org, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Alexandre Iooss , Mahmoud Mandour Subject: [RFC PATCH 4/8] sysemu: add set_virtual_time to accel ops Date: Fri, 19 May 2023 18:04:50 +0100 Message-Id: <20230519170454.2353945-5-alex.bennee@linaro.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230519170454.2353945-1-alex.bennee@linaro.org> References: <20230519170454.2353945-1-alex.bennee@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=2a00:1450:4864:20::435; envelope-from=alex.bennee@linaro.org; helo=mail-wr1-x435.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: 1684516030765100005 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. Signed-off-by: Alex Benn=C3=A9e Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- include/sysemu/accel-ops.h | 18 +++++++++++++++++- include/sysemu/cpu-timers.h | 3 ++- softmmu/cpus.c | 11 +++++++++++ ...et-virtual-clock.c =3D> cpus-virtual-clock.c} | 5 +++++ 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 3c1fab4b1e..224e85a649 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; @@ -43,7 +48,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 2e786fe7fb..c3f4c262f8 100644 --- a/include/sysemu/cpu-timers.h +++ b/include/sysemu/cpu-timers.h @@ -84,8 +84,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 the VIRTUAL clock and VM elapsed ticks via the cpus accel inter= face */ 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/softmmu/cpus.c b/softmmu/cpus.c index 9cbc8172b5..1e4f09553a 100644 --- a/softmmu/cpus.c +++ b/softmmu/cpus.c @@ -221,6 +221,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/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 fd447d53f3..af7c1a1d40 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/stubs/meson.build b/stubs/meson.build index 8412cad15f..c32c66a5c7 100644 --- a/stubs/meson.build +++ b/stubs/meson.build @@ -5,7 +5,7 @@ stub_ss.add(files('blockdev-close-all-bdrv-states.c')) stub_ss.add(files('change-state-handler.c')) stub_ss.add(files('cmos.c')) stub_ss.add(files('cpu-get-clock.c')) -stub_ss.add(files('cpus-get-virtual-clock.c')) +stub_ss.add(files('cpus-virtual-clock.c')) stub_ss.add(files('qemu-timer-notify-cb.c')) stub_ss.add(files('icount.c')) stub_ss.add(files('dump.c')) --=20 2.39.2 From nobody Sat May 18 16:18:00 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=1684516040; cv=none; d=zohomail.com; s=zohoarc; b=mqZQ6vFmD9wS5VA6KPbPWkGLOCSLD0+hS0KceLqob6rnNvG95OAhSr0ag/af6xMQ4KCpdMqB6WzYFQ3cir5vRvcA3LI1dHQRvFKnyOHZDCUYqiJ2sEzy/wZGAefRg7tJtwc7qReQ0RUY/ZjhPCO9xU+wVUm4JBKybtcyzBEuqqA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1684516040; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=CR/oWYkskBmS5+T6RF3T/y2a8OCs1JuDOn7YbNsQaig=; b=ccxRXLhdGhecJ5rWQw7ts/5y/sZbdNVdISuEZPkYQKorFY+PJ49V+yg1Xb0JZvJ4LntN4t33W++J024tQBZybQfMg0AH7XcG75j7fSDZalBD3dW6rziwCJXlTuZb7o5QV1tRVC984Fy/yA8g1KukZJWxKCIkOWTGr/8vDPr3QQk= 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 1684516040676479.4785769846477; Fri, 19 May 2023 10:07:20 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1q03Xe-0002IP-Bb; Fri, 19 May 2023 13:05:22 -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 1q03XR-0002CY-EB for qemu-devel@nongnu.org; Fri, 19 May 2023 13:05:10 -0400 Received: from mail-wm1-x334.google.com ([2a00:1450:4864:20::334]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1q03XI-0005Ur-H1 for qemu-devel@nongnu.org; Fri, 19 May 2023 13:05:09 -0400 Received: by mail-wm1-x334.google.com with SMTP id 5b1f17b1804b1-3f4271185daso34052855e9.2 for ; Fri, 19 May 2023 10:04:59 -0700 (PDT) Received: from zen.linaroharston ([85.9.250.243]) by smtp.gmail.com with ESMTPSA id n11-20020a05600c294b00b003f182a10106sm2979974wmd.8.2023.05.19.10.04.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 19 May 2023 10:04:57 -0700 (PDT) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id 656491FFC0; Fri, 19 May 2023 18:04:55 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1684515898; x=1687107898; 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=CR/oWYkskBmS5+T6RF3T/y2a8OCs1JuDOn7YbNsQaig=; b=Ntkube46iK/SQXofhWnm3aYeLHicpuKXe2wRqdt1L5U2mtNuALzpy3teICPKEoGViV Ugs5l9LUOMQoegfVXA6IDaCW8G687yk32cRkS8r4U3lHif2ZRw2WS0K5DA3Ba5yneZih HtaUq7aQcIO1vjaXiZ+Xe38HedSPIJ77kT5naaOXDV2n98fSjXh5mcOlk1ukrsdTgiIF 0uL+3hPFVOi747xqN9PzSiWbGDQ5quOx9h/8kewbiQqOGpsY9z7HpPFp9C2Uz+62XaQH j1aNCb8houjuqQq2t6Sic+PY+oHsmEZK+YLkVq77JNIgfHd72l6sMfdzIvTS+OwpU/W2 kIfw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684515898; x=1687107898; 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=CR/oWYkskBmS5+T6RF3T/y2a8OCs1JuDOn7YbNsQaig=; b=YYASWQG6xV94oLVpXh9kNDnb/hhLagZzx038RfGDrmC8R81Cd7UKMuj1QMvtFYWbtE 4ZsqvqzjGlh4L1T65np7CFq7k/iyzXV5kduvwCEXefTXXv71Q7EpxOfdFdW8zZY3ngr0 iMBznVcPSpZ0vVPne/64SpSOmpKHcfE+ZE0bg3PNjBvMIS3ZNY++bbuEbF1ejR3j7wvr 9KouzGMSR0VXalpaI1PgnewxhMz7AO1hUN0agd7UIslIWyLzHCZzIJvo3l/Tb5pJ79PB A/51ms6SiS3JUU47ERYcAnZ4y5SX6VAE24cx9y0h3bwGEWqYjZVMI92Dar8MwII5heLy aqVA== X-Gm-Message-State: AC+VfDxSg1ju6wxwrQAi2rg87cqS8SXrLmNKL4+Evp3Ks28MFKEf1BXv uK10o68dQurQcMzaL7yXV+v0aA== X-Google-Smtp-Source: ACHHUZ4iXNgH6avS1EFDStKadWpq4otGGfrS004ap8PuzUPeqYmhs5cmg8Y//xIYnop7Sk8tq8j9gQ== X-Received: by 2002:a05:600c:245:b0:3f5:4e1:2a89 with SMTP id 5-20020a05600c024500b003f504e12a89mr1874830wmj.34.1684515898115; Fri, 19 May 2023 10:04:58 -0700 (PDT) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Alex=20Benn=C3=A9e?= , Yanan Wang , Riku Voipio , Laurent Vivier , Marcel Apfelbaum , Marco Liebel , Mark Burton , Thomas Huth , Peter Maydell , Richard Henderson , Eduardo Habkost , Paolo Bonzini , qemu-arm@nongnu.org, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Alexandre Iooss , Mahmoud Mandour Subject: [RFC PATCH 5/8] qtest: use cpu interface in qtest_clock_warp Date: Fri, 19 May 2023 18:04:51 +0100 Message-Id: <20230519170454.2353945-6-alex.bennee@linaro.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230519170454.2353945-1-alex.bennee@linaro.org> References: <20230519170454.2353945-1-alex.bennee@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=2a00:1450:4864:20::334; envelope-from=alex.bennee@linaro.org; helo=mail-wm1-x334.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=unavailable 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: 1684516041800100003 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. Signed-off-by: Alex Benn=C3=A9e Acked-by: Thomas Huth --- include/sysemu/qtest.h | 1 + accel/qtest/qtest.c | 1 + softmmu/qtest.c | 6 +++--- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/include/sysemu/qtest.h b/include/sysemu/qtest.h index 85f05b0e46..e1f69783d6 100644 --- a/include/sysemu/qtest.h +++ b/include/sysemu/qtest.h @@ -35,5 +35,6 @@ 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); =20 #endif diff --git a/accel/qtest/qtest.c b/accel/qtest/qtest.c index f6056ac836..53182e6c2a 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/softmmu/qtest.c b/softmmu/qtest.c index f8d764b719..34bc9e1f49 100644 --- a/softmmu/qtest.c +++ b/softmmu/qtest.c @@ -331,14 +331,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(); @@ -347,7 +347,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 Sat May 18 16:18:00 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=1684515990; cv=none; d=zohomail.com; s=zohoarc; b=Y6oZq6yIpyp7VDuOcYlNDOQAn6NNNLQZCZAYw67YmW0LKgll41ahjkEf47Y27uW0eJwLwceEXQT4lnWnUur+Nn65WfE4xPtqbpatSSDLlBAZJBEGs16B/XEd6A2eoPSqyox9JGI5bGC/vPOpnQK2CawfHBqETq4xh1eBEaKksFg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1684515990; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=c1Ip0l2uFfVETbP6bR+CKxPn1peac5csfC67WejDHPo=; b=fWcBZXitQ7KrAqLwVs8KoD3Qal3rUXdHWNIU8T6U/uNeAO8Mjfj/uwh+IM44sD4FM3ZU/fYLqSO6uRWK1Tx3zDQlyaAvVcK28bJkpQCDtz1YRsb51U4GWq8irJonytCGUIT8FHgp2v8zfy3IKAh9+RNXlqdnKDJqq18RsOsGxWI= 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 1684515990054633.6564043677495; Fri, 19 May 2023 10:06:30 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1q03Xf-0002Ip-Hn; Fri, 19 May 2023 13:05:23 -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 1q03XQ-0002CV-I4 for qemu-devel@nongnu.org; Fri, 19 May 2023 13:05:10 -0400 Received: from mail-wm1-x32c.google.com ([2a00:1450:4864:20::32c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1q03XI-0005Us-2T for qemu-devel@nongnu.org; Fri, 19 May 2023 13:05:08 -0400 Received: by mail-wm1-x32c.google.com with SMTP id 5b1f17b1804b1-3f41d087a84so7781615e9.1 for ; Fri, 19 May 2023 10:04:59 -0700 (PDT) Received: from zen.linaroharston ([85.9.250.243]) by smtp.gmail.com with ESMTPSA id n7-20020a7bcbc7000000b003f318be9442sm2948436wmi.40.2023.05.19.10.04.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 19 May 2023 10:04:57 -0700 (PDT) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id 876961FFC1; Fri, 19 May 2023 18:04:55 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1684515898; x=1687107898; 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=c1Ip0l2uFfVETbP6bR+CKxPn1peac5csfC67WejDHPo=; b=EuQ57wgtlJ90JbZ1ILULSt5wVq8/gCXRuY1wabUom2lkgbqajWQbhB0ztsk5u8tXQl cW1rMl3Z+rLQRiDwUus7v4kYUbd75xgtj7poLYWYRgbJd5NysHEHjrBp54UpkfSQ9lXF wCoxDZVMqi/7mO6d6iZzIAkfswUMyRPr7DSChGmOxzcCjxd5RAvE7EHlKpM63EGj+3sc RGtLIDP157QJ3owUJj9SqTjV2W0qpH4yh5ocGspIgtsygMJpQLuUn7tJ+ytKE37ysR37 u/BcTRrRBmuSudvTEZzH9HbLtcrbDFJ2zKBLtDhWHsymocmCoP20inGCi52jMhy9o+wT iS1A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684515898; x=1687107898; 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=c1Ip0l2uFfVETbP6bR+CKxPn1peac5csfC67WejDHPo=; b=hISNl2JHZwLo6y5/wte2h1rZiD07nEY4b+6HbwLtItMVz85udFEdztx+VOVmPbenoa yBhJvXZ1tHPu7x8FWpKNvdRYEwRszOvP5WCIJDhrHKI1Pbcldlyl8PW/oI8NBOv6EfX1 YMqlCMzE/9bqUGhekESG9MpRXqJoFfHtJKANobCE8x3gEpg24oq6TxuMsHQmgRdxZ8lr JY+pN2vXJP15Y6kzH5lSl0KxK7HQxU3G3voXDQQDuE8oobUaWEPyWH9UrI7oW9pV0TF0 UqVFcFypG+lIQRB7m65Kdhf0FkfbxHU7yaX3YkHRlVMtMnAlOvt97eiXGJxlnOaYEQVS NC9A== X-Gm-Message-State: AC+VfDz4Ok2eHrGuu/DgZMtwzYUZgBGi+qttYRL25teuSyzaFnkn9OIp uQhHJ2peJurYp8SckZs3J7aGGA== X-Google-Smtp-Source: ACHHUZ7YAD5JtAfszg1Jry2VFBi4ZzVNwZmAWhGwP9KBBsIjRL/QFylt/8xCcv82f4QFWeaGTiff3w== X-Received: by 2002:a05:600c:230e:b0:3f4:2610:5cc5 with SMTP id 14-20020a05600c230e00b003f426105cc5mr1990264wmo.5.1684515898329; Fri, 19 May 2023 10:04:58 -0700 (PDT) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Alex=20Benn=C3=A9e?= , Yanan Wang , Riku Voipio , Laurent Vivier , Marcel Apfelbaum , Marco Liebel , Mark Burton , Thomas Huth , Peter Maydell , Richard Henderson , Eduardo Habkost , Paolo Bonzini , qemu-arm@nongnu.org, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Alexandre Iooss , Mahmoud Mandour Subject: [RFC PATCH 6/8] sysemu: generalise qtest_warp_clock as qemu_clock_advance_virtual_time Date: Fri, 19 May 2023 18:04:52 +0100 Message-Id: <20230519170454.2353945-7-alex.bennee@linaro.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230519170454.2353945-1-alex.bennee@linaro.org> References: <20230519170454.2353945-1-alex.bennee@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=2a00:1450:4864:20::32c; envelope-from=alex.bennee@linaro.org; helo=mail-wm1-x32c.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=unavailable 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: 1684515991066100003 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. Signed-off-by: Alex Benn=C3=A9e --- include/qemu/timer.h | 15 +++++++++++++++ softmmu/qtest.c | 24 ++---------------------- util/qemu-timer.c | 26 ++++++++++++++++++++++++++ 3 files changed, 43 insertions(+), 22 deletions(-) diff --git a/include/qemu/timer.h b/include/qemu/timer.h index ee071e07d1..9a1a42a400 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/softmmu/qtest.c b/softmmu/qtest.c index 34bc9e1f49..3cd6c11f5a 100644 --- a/softmmu/qtest.c +++ b/softmmu/qtest.c @@ -336,26 +336,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)) @@ -732,7 +712,7 @@ 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_VIRTU= AL) + ns); qtest_send_prefix(chr); qtest_sendf(chr, "OK %"PRIi64"\n", (int64_t)qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL)); @@ -758,7 +738,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 6a0de33dd2..213114be68 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 Sat May 18 16:18:00 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=1684516028; cv=none; d=zohomail.com; s=zohoarc; b=AHJficFzynjZln+kn9pGE3ux3XdplBhh0Zv+LtPZiPm5rHPmpgh4iGXiHUGjzCaawgxg2AQx7d1EkUx22pF+LlUhPhMiD0/Lkh4Je4AhwNW6i8FvCMgjP22e6pWsdbwdz+tb7Xt0nkCAOdi4f+37g4KsSzcDz5nAVRFWjVaCPcs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1684516028; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=7F9Gx979+6Hkz/Du+/YB5Ayn8YHTGimM/bWSDeN1tW4=; b=S2YqVnTLJhzsYIw+GcNj39ejjU0+LQxUrq1tWMfqYyDk+3iAejzpbsZMeU/5JKNmkf/HTQ7DRfd4Eg6UQ8AD5/PtobNLbD2ARqV44QwTzrJs9AajxrF/6uasRTfLl92vSCdyy97uSOb3gq7GFcA0rG+vqRRHvLyRO85dX9WF6lg= 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 16845160281651010.4919630940806; Fri, 19 May 2023 10:07:08 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1q03Xd-0002HZ-On; Fri, 19 May 2023 13:05:21 -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 1q03XQ-0002CL-4n for qemu-devel@nongnu.org; Fri, 19 May 2023 13:05:10 -0400 Received: from mail-wr1-x436.google.com ([2a00:1450:4864:20::436]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1q03XI-0005Uv-3j for qemu-devel@nongnu.org; Fri, 19 May 2023 13:05:07 -0400 Received: by mail-wr1-x436.google.com with SMTP id ffacd0b85a97d-3095b1b6e02so245422f8f.2 for ; Fri, 19 May 2023 10:04:59 -0700 (PDT) Received: from zen.linaroharston ([85.9.250.243]) by smtp.gmail.com with ESMTPSA id y18-20020adff152000000b002e61e002943sm5769093wro.116.2023.05.19.10.04.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 19 May 2023 10:04:57 -0700 (PDT) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id A71131FFC2; Fri, 19 May 2023 18:04:55 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1684515898; x=1687107898; 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=7F9Gx979+6Hkz/Du+/YB5Ayn8YHTGimM/bWSDeN1tW4=; b=ErnBAQ9hencXmZIjORoaDWajla1FsfI+TRGcNHaNhE4l9EBGQvdB/LgZjCDCWnENiO iw0awPVnP6hiBUhVxWMs458aztlDI/38uAbrNZt8Ws2s+VjLfcdJlDflOu8Trw3nHFP7 laaED30pJ70HF1Ha0Y/ZEzaVA/ZvInKioR4IbajRPydWKGUC+QKvXbt1jZWXZl4DZVBQ 312lvKabQPeITpegNHSR7eoiVM7Ata3Qg+d5mUq77/1P2vxtxSZebRQIZ4f9TVpObya1 fwYmv3tv7eyaRAsU1YJ9qC/LOmuQSVOFLm8xUjyqwXnDVegSZQkHSJt/6uMPctueKZKQ KdTw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684515898; x=1687107898; 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=7F9Gx979+6Hkz/Du+/YB5Ayn8YHTGimM/bWSDeN1tW4=; b=W5xIg0XpH726R+ZhhmimIHdn+g8Dc8zxX8FstgeoEPlWv14pjNs419ctjD4ylWgR2b aBn8hbfdTKXr0SC8VOPx5euxAxLylS72dixxp48iqmbOsVY7YgG6loWlbsJE5Xc86ipB 5MEwVl1AdVPEvUinq6NFF3BuY2fZQfE8yEzgdnWgexTKnhvm0EnCMbg+YTryqpmE/MNI jkXlJnqhSo/ZeouTVd1YRFioEohCt6ujTbozAtAtrvpAH1X7u4lOrk9Ov12xkwLwJMnW yWKw4MuYF6k6lQRyKxudA+JBeArY16IDfiEQ+L1B29GcZpUPlUlJKJQH3v1v9yV9jCH2 LVoA== X-Gm-Message-State: AC+VfDwQF8bj36ETgLJyEwfMoWdNMA9x8X9Y0nK03pzicDX+ZDhiU5FB amGF/naEuUKpMZ3onyFaKp52lQ== X-Google-Smtp-Source: ACHHUZ7Yyop3MUn44DlcqgrBzUIACE9XGMEo6QLg/TtB+1xVQbLr+RCME1kcBVcNuwgcE0/peCSmsw== X-Received: by 2002:adf:f2d2:0:b0:307:977a:e693 with SMTP id d18-20020adff2d2000000b00307977ae693mr2107267wrp.59.1684515898515; Fri, 19 May 2023 10:04:58 -0700 (PDT) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Alex=20Benn=C3=A9e?= , Yanan Wang , Riku Voipio , Laurent Vivier , Marcel Apfelbaum , Marco Liebel , Mark Burton , Thomas Huth , Peter Maydell , Richard Henderson , Eduardo Habkost , Paolo Bonzini , qemu-arm@nongnu.org, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Alexandre Iooss , Mahmoud Mandour Subject: [RFC PATCH 7/8] plugins: add time control API Date: Fri, 19 May 2023 18:04:53 +0100 Message-Id: <20230519170454.2353945-8-alex.bennee@linaro.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230519170454.2353945-1-alex.bennee@linaro.org> References: <20230519170454.2353945-1-alex.bennee@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=2a00:1450:4864:20::436; envelope-from=alex.bennee@linaro.org; helo=mail-wr1-x436.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: 1684516029754100003 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. Signed-off-by: Alex Benn=C3=A9e --- include/qemu/qemu-plugin.h | 19 +++++++++++++++++++ plugins/api.c | 22 ++++++++++++++++++++++ plugins/qemu-plugins.symbols | 2 ++ 3 files changed, 43 insertions(+) diff --git a/include/qemu/qemu-plugin.h b/include/qemu/qemu-plugin.h index 50a9957279..8385670976 100644 --- a/include/qemu/qemu-plugin.h +++ b/include/qemu/qemu-plugin.h @@ -536,7 +536,26 @@ void qemu_plugin_register_vcpu_mem_inline(struct qemu_= plugin_insn *insn, enum qemu_plugin_op op, void *pt= r, 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); =20 +/** + * 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. + */ +void qemu_plugin_update_ns(const void *handle, int64_t new_time); =20 typedef void (*qemu_plugin_vcpu_syscall_cb_t)(qemu_plugin_id_t id, unsigned int vcpu_in= dex, diff --git a/plugins/api.c b/plugins/api.c index 2078b16edb..8402b3a5f6 100644 --- a/plugins/api.c +++ b/plugins/api.c @@ -37,6 +37,7 @@ #include "qemu/osdep.h" #include "qemu/plugin.h" #include "qemu/log.h" +#include "qemu/timer.h" #include "tcg/tcg.h" #include "exec/exec-all.h" #include "exec/ram_addr.h" @@ -442,3 +443,24 @@ uint64_t qemu_plugin_entry_code(void) #endif return entry; } + +/* + * 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; +} + +void qemu_plugin_update_ns(const void *handle, int64_t new_time) +{ + if (handle =3D=3D &has_control) { + qemu_clock_advance_virtual_time(new_time); + } +} diff --git a/plugins/qemu-plugins.symbols b/plugins/qemu-plugins.symbols index 71f6c90549..91b882fecc 100644 --- a/plugins/qemu-plugins.symbols +++ b/plugins/qemu-plugins.symbols @@ -35,11 +35,13 @@ qemu_plugin_register_vcpu_tb_exec_cb; qemu_plugin_register_vcpu_tb_exec_inline; qemu_plugin_register_vcpu_tb_trans_cb; + qemu_plugin_request_time_control; qemu_plugin_reset; qemu_plugin_start_code; qemu_plugin_tb_get_insn; qemu_plugin_tb_n_insns; qemu_plugin_tb_vaddr; qemu_plugin_uninstall; + qemu_plugin_update_ns; qemu_plugin_vcpu_for_each; }; --=20 2.39.2 From nobody Sat May 18 16:18:00 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=1684516016; cv=none; d=zohomail.com; s=zohoarc; b=J1FKjsEE6yk4EU9pHIGXOdsNtSvp/nSnbvcnHWyJKf0vyEn4I/JRgsSLnQCYYZD4lMx7oSb9RLIFMMNnAtfOtgqDGtHWRStnWZoaknb7efU5rARNeg7kYqW0furU1z7VFfhUsRm1vZeuMPireP+dDTneSAOYV1w3+iN6MWPifoM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1684516016; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=JokzLRHlJbPSM9sdlrouC/BAPg2f8genVSe9n3nO2c8=; b=bnCN72nasy0iq/Ky5yOwpRnpQmyybIFM1BfxDkBATqaPJ6dqwP84DWlftzqJHiqNn3Qg7hc6lQBS+xtS41XNmZsZ/PbWJVgWAT4nszLBW91FiBkyQH27KuXBYdge8J4TlWPeGUj0RNartoQGInflTTlimvrF2gghVs0kuicLTWk= 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 16845160163212.668955383537309; Fri, 19 May 2023 10:06:56 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1q03Xg-0002JS-Sx; Fri, 19 May 2023 13:05: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 1q03XS-0002CZ-B6 for qemu-devel@nongnu.org; Fri, 19 May 2023 13:05:11 -0400 Received: from mail-wr1-x42c.google.com ([2a00:1450:4864:20::42c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1q03XI-0005VP-Tx for qemu-devel@nongnu.org; Fri, 19 May 2023 13:05:10 -0400 Received: by mail-wr1-x42c.google.com with SMTP id ffacd0b85a97d-30626f4d74aso2363947f8f.0 for ; Fri, 19 May 2023 10:05:00 -0700 (PDT) Received: from zen.linaroharston ([85.9.250.243]) by smtp.gmail.com with ESMTPSA id l5-20020a7bc345000000b003f4ebeaa970sm2971265wmj.25.2023.05.19.10.04.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 19 May 2023 10:04:57 -0700 (PDT) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id C77CA1FFBB; Fri, 19 May 2023 18:04:55 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1684515899; x=1687107899; 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=JokzLRHlJbPSM9sdlrouC/BAPg2f8genVSe9n3nO2c8=; b=OaY6zbKQNYuPS8A8ePD8mXN6nyS4huPWLtF1wSwHDaPLcoSAs3HR6PQEFCKl/CJADr eKT3Xa44I/TBi8fwjoi5rxhp4sUv6W2R31JwmP3tAOJPYHD5Tcc9IWB7PXuednvvU4Pa kfC9JmlVjOOekyG3fOyiXwYdCx0zGjKPxfuMn/HpLsiuKixpe6ruFXSaw4CpTXYeZUfD MEJxJPaynRcA4vyLWjRfr0ow4WgAP7qkQ+HBjqS00gy5Qz4p/Dznpc7cX4PN+FfVWWpw 7UEDbdhIh+OrfLa39tqzR/KhdbkkTQAEq7wXIiyR0NT26/mBuEhQHE+/7mlp2W+rrYaL izEg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684515899; x=1687107899; 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=JokzLRHlJbPSM9sdlrouC/BAPg2f8genVSe9n3nO2c8=; b=MKtmpFp/yAloYJH/VWHeIY5MYmG6Tj11bry4w0rzZOxuBrL7Jb7wBTG50CBZEZDzu2 YZBzmnwsGywakLj9TJf+/Jo9U6waSEBbmbIgSpDTtbg1khD8HCzMU0eB1l3gWXCrKXOq wcDEY2e+AF6LSMrLzuZOJMl9/XK+h7kTVDYp8MyZR6Ac6QysJAPXpQAtkXF4vLmFXwgj TfLVCwVqCoETAkdk58BXuZpVn6AxbwcK2k5ZgMylgi51LYHgObprdIOItXqzsZiLKuvN +Ryn5udZ9xwSIj+/WBsJmM0bPsWe3zVRnI05Ycmwq4G/L6feYkknM67FEPDC504exrwR lW1A== X-Gm-Message-State: AC+VfDyvHnR/yVeUaUVtoT8kBV0/Lh0608U2HDHIkwwmcKXV3exl2GWq 3GlTxaOCchrURWzpu+G99bcNlw== X-Google-Smtp-Source: ACHHUZ7z5Tt5iX4V5CBb1XObqXTb/DcxsV/CSnPwkjKVByI2kOWP7AdnIVaRaEQ/+mkSSlfmdYevDA== X-Received: by 2002:a5d:4650:0:b0:307:8e1b:6cc7 with SMTP id j16-20020a5d4650000000b003078e1b6cc7mr2403172wrs.67.1684515899492; Fri, 19 May 2023 10:04:59 -0700 (PDT) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Alex=20Benn=C3=A9e?= , Yanan Wang , Riku Voipio , Laurent Vivier , Marcel Apfelbaum , Marco Liebel , Mark Burton , Thomas Huth , Peter Maydell , Richard Henderson , Eduardo Habkost , Paolo Bonzini , qemu-arm@nongnu.org, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Alexandre Iooss , Mahmoud Mandour Subject: [RFC PATCH 8/8] contrib/plugins: add iops plugin example for cost modelling Date: Fri, 19 May 2023 18:04:54 +0100 Message-Id: <20230519170454.2353945-9-alex.bennee@linaro.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230519170454.2353945-1-alex.bennee@linaro.org> References: <20230519170454.2353945-1-alex.bennee@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=2a00:1450:4864:20::42c; envelope-from=alex.bennee@linaro.org; helo=mail-wr1-x42c.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: 1684516017947100001 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 iops 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 as updated for the emulation as a function of total executed instructions with some adjustments for cores that idle. Signed-off-by: Alex Benn=C3=A9e --- contrib/plugins/iops.c | 260 +++++++++++++++++++++++++++++++++++++++ contrib/plugins/Makefile | 1 + 2 files changed, 261 insertions(+) create mode 100644 contrib/plugins/iops.c diff --git a/contrib/plugins/iops.c b/contrib/plugins/iops.c new file mode 100644 index 0000000000..6eb8f97820 --- /dev/null +++ b/contrib/plugins/iops.c @@ -0,0 +1,260 @@ +/* + * iops rate limiting plugin. + * + * This plugin can be used to restrict the execution of a system to a + * particular number of Instructions Per Second (IOPS). 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; + +#define SLICES 10 /* the number of slices per second we compute delay */ + +static GMutex global_state_lock; + +static uint64_t iops =3D 1000000; /* iops rate, per core, per second */ +static uint64_t current_ticks; /* current global ticks */ +static uint64_t next_check; /* the next checkpoint for time */ +static bool precise_execution; /* count every instruction */ + +static int64_t systime_at_start; /* time we started the first vCPU */ + +static const uint64_t nsec_per_sec =3D 1000000000; +static const void * time_handle; + +/* + * We need to track the number of instructions each vCPU has executed + * as well as what its current state is. We need to account for time + * passing while a vCPU is idle. + */ + +typedef enum { + UNKNOWN =3D 0, + CREATED, + EXECUTING, + IDLE, + FINISHED +} vCPUState; + +typedef struct { + /* pointer to vcpu counter entry */ + uint64_t *counter; + vCPUState state; + /* timestamp when vCPU entered state */ + uint64_t state_time; + /* number of ns vCPU was idle */ + uint64_t total_idle; +} vCPUTime; + +GArray *vcpus; +uint64_t *vcpu_counters; + +/* + * Get the vcpu structure for this vCPU. We don't do any locking here + * as only one vCPU will ever access its own structure. + */ +static vCPUTime *get_vcpu(int cpu_index) +{ + return &g_array_index(vcpus, vCPUTime, cpu_index); +} + +/* + * When emulation is running faster than real time this is the point + * we can throttle the execution of a given vCPU. Either way we can + * now tell the system to move time forward. + */ +static void update_system_time(int64_t vcpu_ticks) +{ + int64_t now =3D g_get_real_time(); + int64_t real_runtime_ns =3D now - systime_at_start; + + g_mutex_lock(&global_state_lock); + /* now we have the lock double check we are fastest */ + if (vcpu_ticks > next_check) { + + int64_t tick_runtime_ns =3D (vcpu_ticks / iops) * nsec_per_sec; + if (tick_runtime_ns > real_runtime_ns) { + int64_t sleep_us =3D (tick_runtime_ns - real_runtime_ns) / 100= 0; + g_usleep(sleep_us); + } + + /* Having slept we can now move the clocks forward */ + qemu_plugin_update_ns(time_handle, vcpu_ticks); + current_ticks =3D vcpu_ticks; + next_check =3D iops/SLICES; + } + g_mutex_unlock(&global_state_lock); +} + +/* + * State tracking + */ +static void vcpu_init(qemu_plugin_id_t id, unsigned int cpu_index) +{ + vCPUTime *vcpu =3D get_vcpu(cpu_index); + vcpu->state =3D CREATED; + vcpu->state_time =3D *vcpu->counter; + + g_mutex_lock(&global_state_lock); + if (!systime_at_start) { + systime_at_start =3D g_get_real_time(); + } + g_mutex_unlock(&global_state_lock); +} + +static void vcpu_idle(qemu_plugin_id_t id, unsigned int cpu_index) +{ + vCPUTime *vcpu =3D get_vcpu(cpu_index); + vcpu->state =3D IDLE; + vcpu->state_time =3D *vcpu->counter; + + /* handle when we are the last vcpu to sleep here */ +} + +static void vcpu_resume(qemu_plugin_id_t id, unsigned int cpu_index) +{ + vCPUTime *vcpu =3D get_vcpu(cpu_index); + + /* + * Now we need to reset counter to something approximating the + * current time, however we only update current_ticks when a block + * exceeds next_check. If the vCPU has been asleep for awhile this + * will probably do, otherwise lets pick somewhere between + * current_ticks and the next_check value. + */ + if (vcpu->state_time < current_ticks) { + *vcpu->counter =3D current_ticks; + } else { + int64_t window =3D next_check - vcpu->state_time; + *vcpu->counter =3D next_check - (window / 2); + } + =20 + vcpu->state =3D EXECUTING; + vcpu->state_time =3D *vcpu->counter; +} + +static void vcpu_exit(qemu_plugin_id_t id, unsigned int cpu_index) +{ + vCPUTime *vcpu =3D get_vcpu(cpu_index); + vcpu->state =3D FINISHED; + vcpu->state_time =3D *vcpu->counter; +} + +/* + * tb exec + */ +static void vcpu_tb_exec(unsigned int cpu_index, void *udata) +{ + vCPUTime *vcpu =3D get_vcpu(cpu_index); + uint64_t count =3D *vcpu->counter; + + count +=3D GPOINTER_TO_UINT(udata); + + if (count >=3D next_check) { + update_system_time(count); + } +} + +/* + * We have two choices at translation time. In imprecise mode we just + * install a tb execution callback with the total number of + * instructions in the block. This ignores any partial execution + * effects but it reasonably fast. In precise mode we increment a + * per-vCPU counter for every execution. + */ + +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_register_vcpu_tb_exec_cb(tb, vcpu_tb_exec, + QEMU_PLUGIN_CB_NO_REGS, + GUINT_TO_POINTER(n_insns)); +} + +/** + * Install the plugin + */ +QEMU_PLUGIN_EXPORT int qemu_plugin_install(qemu_plugin_id_t id, + const qemu_info_t *info, int ar= gc, + char **argv) +{ + /* This plugin only makes sense for system emulation */ + if (!info->system_emulation) { + fprintf(stderr, "iops plugin only works with system emulation\n"); + return -1; + } + + 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], "iops") =3D=3D 0) { + iops =3D g_ascii_strtoull(tokens[1], NULL, 10); + if (!iops && 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_exe= cution)) { + fprintf(stderr, "boolean argument parsing failed: %s\n", o= pt); + return -1; + } + } else { + fprintf(stderr, "option parsing failed: %s\n", opt); + return -1; + } + } + + /* + * Setup the tracking information we need to run. + */ + vcpus =3D g_array_new(true, true, sizeof(vCPUTime)); + g_array_set_size(vcpus, info->system.max_vcpus); + vcpu_counters =3D g_malloc0_n(info->system.max_vcpus, sizeof(uint64_t)= ); + for (int i =3D 0; i < info->system.max_vcpus; i++) { + vCPUTime *vcpu =3D get_vcpu(i); + vcpu->counter =3D &vcpu_counters[i]; + } + + /* + * We are going to check the state of time every slice so set the + * first check at t0 + iops/SLICES + */ + next_check =3D iops/SLICES; + + /* + * Only one plugin can request time control, if we don't get the + * handle there isn't much we can do. + */ + time_handle =3D qemu_plugin_request_time_control(); + if (!time_handle) { + fprintf(stderr, "%s: not given permission to control time\n", __fu= nc__); + return -1; + } + + /* + * To track time we need to measure how many instructions each + * core is executing as well as when each vcpu enters/leaves the + */ + 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); + + return 0; +} diff --git a/contrib/plugins/Makefile b/contrib/plugins/Makefile index b2b9db9f51..f269c18d11 100644 --- a/contrib/plugins/Makefile +++ b/contrib/plugins/Makefile @@ -21,6 +21,7 @@ NAMES +=3D lockstep NAMES +=3D hwprofile NAMES +=3D cache NAMES +=3D drcov +NAMES +=3D iops =20 SONAMES :=3D $(addsuffix .so,$(addprefix lib,$(NAMES))) =20 --=20 2.39.2