From patchwork Fri May 19 17:04:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 683914 Delivered-To: patch@linaro.org Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp1053361wrt; Fri, 19 May 2023 10:07:39 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4ByPkyWthbakk2P0fI6OkpIse05E8SRjW/HiKynVm04osWxNmq4f+eDtiUjUkc/OMwTLbo X-Received: by 2002:a05:6214:e8e:b0:61d:be1e:7c4e with SMTP id hf14-20020a0562140e8e00b0061dbe1e7c4emr5964182qvb.12.1684516059496; Fri, 19 May 2023 10:07:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684516059; cv=none; d=google.com; s=arc-20160816; b=AGZUUb8N89E6y8jmrBxjpfOC6RGEwc1aU63PBwQDuuskPFV8bCY1WYPlSWtSrqj0qI KJXq6Jmt3yJMXShH0/95ROENZwOS7Rbi0COJMBvRaL8W/uuMNA/ptp7pcsuyDjoJwINM 5vYsidnYUlHZvxoqI1grm2Cjv0D7Y7Z3RW1InIiL1hqfEegUPXOb2JmCPYsHXnjqAfc6 JmmyJjqciRDd8UcVzLQXnC2EtPUSdnZJGhyPRYyVorNUMNENVm8i9d5HgZCR2V+ci/10 mBHqonszg3Tczz80gDXXTXRxjkeTCM9kiz2TaX7NvfYpXw59EFrI/IJHocKzFIlFPT2i zfyg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=yg00DZfe+F7dr7y3vEVOv3SJnj/XXqqhg6oEcb/MIUE=; b=mjhc2awD/xtXkSkZ1XfWF9SfpP9SqM/+2JtJSBn0CryF9xAncwg9Z18xS6543jW92+ OOmlXk4VTsx+5b8oK97Smc2wW/PfQccGwmMgiGoz+S/ULIQ5Jiv5O+cPXDjvPYYN9u5Y 1m5BquOZtwwzg8oObyuZ1xjGfdo0LY2Oyi+j5zsdIq8vagqMjrHRWaXX7dMOquxlFTy0 L15rJM+CFx2SRl3QtH62YuhD0UyQ+owEx8exX24J6BRiQaPiiBdJthkk4n6sgxDZx0IM heaXnxYS1rc5AxAJhs9u+Sk06fkxzQd3dYaSL3roxyxeA3fMCBc7xSgzyeNUWfiZxUOX Bt9w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=KcBEl6YG; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id u7-20020ae9c007000000b007596780d546si2814549qkk.372.2023.05.19.10.07.39 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 19 May 2023 10:07:39 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=KcBEl6YG; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 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) 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-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) 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) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: =?utf-8?q?Alex_Benn=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_Mathieu-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 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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org 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=on \ -kernel ./tests/tcg/aarch64-softmmu/memory-sve \ -plugin ./contrib/plugins/libexeclog.so,ifilter=st1w,afilter=0x40001808 -d plugin gives (disas doesn't currently understand st1w): 0, 0x40001808, 0xe54342a0, ".byte 0xa0, 0x42, 0x43, 0xe5", store, 0x40213010, RAM, store, 0x40213014, RAM, store, 0x40213018, RAM And for user-mode: ./qemu-aarch64 \ -plugin contrib/plugins/libexeclog.so,afilter=0x4007c0 \ -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, 0x5500800370, load, 0x5500800371, load, 0x5500800372, load, 0x5500800373, load, 0x5500800374, load, 0x5500800375, load, 0x5500800376, load, 0x5500800377, load, 0x5500800378, load, 0x5500800379, load, 0x550080037a, load, 0x550080037b, load, 0x550080037c, load, 0x550080037d, load, 0x550080037e, load, 0x550080037f, load, 0x5500800380, load, 0x5500800381, load, 0x5500800382, load, 0x5500800383, load, 0x5500800384, load, 0x5500800385, load, 0x5500800386, lo ad, 0x5500800387, load, 0x5500800388, load, 0x5500800389, load, 0x550080038a, load, 0x550080038b, load, 0x550080038c, load, 0x550080038d, load, 0x550080038e, load, 0x550080038f, load, 0x5500800390, load, 0x5500800391, load, 0x5500800392, load, 0x5500800393, load, 0x5500800394, load, 0x5500800395, load, 0x5500800396, load, 0x5500800397, load, 0x5500800398, load, 0x5500800399, load, 0x550080039a, load, 0x550080039b, load, 0x550080039c, load, 0x550080039d, load, 0x550080039e, load, 0x550080039f, load, 0x55008003a0, load, 0x55008003a1, load, 0x55008003a2, load, 0x55008003a3, load, 0x55008003a4, load, 0x55008003a5, load, 0x55008003a6, load, 0x55008003a7, load, 0x55008003a8, load, 0x55008003a9, load, 0x55008003aa, load, 0x55008003ab, load, 0x55008003ac, load, 0x55008003ad, load, 0x55008003ae, load, 0x55008003af (4007c0 is the ld1b in the sha512-sve) Signed-off-by: Alex Bennée 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 #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, CPUWatchpoint *watchpoint); void cpu_watchpoint_remove_all(CPUState *cpu, int mask); #endif +/** + * 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, target_ulong addr, *pfull = &env_tlb(env)->d[mmu_idx].fulltlb[index]; /* 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 != MMU_INST_FETCH && cpu_plugin_mem_cbs_enabled(env_cpu(env)))) { *phost = 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, target_ulong addr, if (guest_addr_valid_untagged(addr)) { int page_flags = page_get_flags(addr); if (page_flags & acc_flag) { + if ((acc_flag == PAGE_READ || acc_flag == PAGE_WRITE) + && cpu_plugin_mem_cbs_enabled(env_cpu(env))) { + return TLB_MMIO; + } return 0; /* success */ } maperr = !(page_flags & PAGE_VALID); @@ -767,7 +771,7 @@ int probe_access_flags(CPUArchState *env, target_ulong addr, int size, g_assert(-(addr | TARGET_PAGE_MASK) >= size); flags = probe_access_internal(env, addr, size, access_type, nonfault, ra); - *phost = flags ? NULL : g2h(env_cpu(env), addr); + *phost = (flags & TLB_INVALID_MASK) ? NULL : g2h(env_cpu(env), addr); return flags; } 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, flags = info.page[0].flags | info.page[1].flags; if (unlikely(flags != 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 } /* 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 TESTS += sha512-vector +ifneq ($(CROSS_CC_HAS_SVE),) +sha512-sve: CFLAGS=-O3 -march=armv8.1-a+sve +sha512-sve: sha512.c + $(CC) $(CFLAGS) $(EXTRA_CFLAGS) $< -o $@ $(LDFLAGS) + +TESTS += sha512-sve +endif + ifeq ($(HOST_GDB_SUPPORTS_ARCH),y) GDB_SCRIPT=$(SRC_PATH)/tests/guest-debug/run-test.py From patchwork Fri May 19 17:04:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 683908 Delivered-To: patch@linaro.org Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp1052703wrt; Fri, 19 May 2023 10:06:32 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ64XAWE6CdTEMQG5D68LCL6tSHwXlEkaabAghT7gaZbXTYwh35H8oJ9oAttIe9iDClmD4p9 X-Received: by 2002:a05:7500:e4a7:b0:108:4e1a:8838 with SMTP id ra39-20020a057500e4a700b001084e1a8838mr272909gab.39.1684515992367; Fri, 19 May 2023 10:06:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684515992; cv=none; d=google.com; s=arc-20160816; b=N5kLvGXdKxshR/5tES/ntJZiWu+YhF4Vwus22kVxeonlzYZg4OT+IYhPSrEipC8+zK 7Dk8Jyl2lp5CENK/IBRzQgtbi5tXJx0OuCQWPKhS3dIS2BNCbVCfvHBXO6xNb6KwddaN IUq/VE+zjRyWA3jUw6sI22xCukZIxLRls22XZqpYd06nfaWpwzKvr4Mkuv892fmxEKQO mxgNlKPEu/rP/e2cgpKlelWFx+R6Ahzfq1j9DBV8MxvuHFR2uS4e/VPMNpAwTxQMBgxX yfFIVN6Syw2K+FPgrb1wocpqk/lowAWVUmOJ8mLuQPVUOBjf0y0Gr9iRuK2euUdACvPZ Mb0g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=BK8vzqUrJMrBxmrdwxNxw8ipZXv8OO87/QXAs2j6w1U=; b=T6Cwd5DsqsVz2LJ87H+k/8CzPSOhM0VeNF0sEbjObh8e0rQLX5Zdny81JfAYtZNbHr gB5yf9uPkXOnSWXFS74U7rcVzSAqGrzUixL335V3lcx0csBkAv56WvtxvgcwI6uez9jA OAoIjPecEfbiDt8w6RSi5qdcUHP4/zyhfv2d2u2yYDRyWr8yQm4hhOxwKUzREi+SvtS5 V4fc3m4RQjON4NYuwjiNx8kO2nEV6ZXlMpXwmlOzU/B+fj2dLydZyVjsdcYa3SoidaeB rEStgcVsci0ZZSArvwOgqUOpTMNB6XdgjjtlQ2YfAK/m4z56ayK6aFnTOE6lylAVLBkE hz9A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Hl5pDHGR; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id m12-20020a05620a13ac00b007576eba19ebsi2856246qki.195.2023.05.19.10.06.32 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 19 May 2023 10:06:32 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Hl5pDHGR; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 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) 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-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) 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) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: =?utf-8?q?Alex_Benn=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_Mathieu-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 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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org 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 with 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ée Reviewed-by: Philippe Mathieu-Daudé --- 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, for (i = 0; i < argc; i++) { char *opt = argv[i]; - g_autofree char **tokens = g_strsplit(opt, "=", 2); + g_auto(GStrv) tokens = g_strsplit(opt, "=", 2); if (g_strcmp0(tokens[0], "iblksize") == 0) { l1_iblksize = 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 = 0; i < argc; i++) { - g_autofree char **tokens = g_strsplit(argv[i], "=", 2); + g_auto(GStrv) tokens = g_strsplit(argv[i], "=", 2); if (g_strcmp0(tokens[0], "filename") == 0) { file_name = 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, for (int i = 0; i < argc; i++) { char *opt = argv[i]; - g_autofree char **tokens = g_strsplit(opt, "=", 2); + g_auto(GStrv) tokens = g_strsplit(opt, "=", 2); if (g_strcmp0(tokens[0], "ifilter") == 0) { parse_insn_match(tokens[1]); } else if (g_strcmp0(tokens[0], "afilter") == 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 = 0; i < argc; i++) { char *opt = argv[i]; - g_autofree char **tokens = g_strsplit(opt, "=", 2); + g_auto(GStrv) tokens = g_strsplit(opt, "=", 2); if (g_strcmp0(tokens[0], "inline") == 0) { if (!qemu_plugin_bool_parse(tokens[0], tokens[1], &do_inline)) { fprintf(stderr, "boolean argument parsing failed: %s\n", opt); 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, for (i = 0; i < argc; i++) { char *opt = argv[i]; - g_autofree char **tokens = g_strsplit(opt, "=", -1); + g_auto(GStrv) tokens = g_strsplit(opt, "=", -1); if (g_strcmp0(tokens[0], "sortby") == 0) { if (g_strcmp0(tokens[1], "reads") == 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, for (i = 0; i < argc; i++) { char *p = argv[i]; - g_autofree char **tokens = g_strsplit(p, "=", -1); + g_auto(GStrv) tokens = g_strsplit(p, "=", -1); if (g_strcmp0(tokens[0], "inline") == 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, for (i = 0; i < argc; i++) { char *opt = argv[i]; - g_autofree char **tokens = g_strsplit(opt, "=", 2); + g_auto(GStrv) tokens = g_strsplit(opt, "=", 2); if (g_strcmp0(tokens[0], "track") == 0) { if (g_strcmp0(tokens[1], "read") == 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, for (i = 0; i < argc; i++) { char *p = argv[i]; - g_autofree char **tokens = g_strsplit(p, "=", 2); + g_auto(GStrv) tokens = g_strsplit(p, "=", 2); if (g_strcmp0(tokens[0], "verbose") == 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, for (i = 0; i < argc; i++) { char *opt = argv[i]; - g_autofree char **tokens = g_strsplit(opt, "=", 2); + g_auto(GStrv) tokens = g_strsplit(opt, "=", 2); if (g_strcmp0(tokens[0], "inline") == 0) { if (!qemu_plugin_bool_parse(tokens[0], tokens[1], &do_inline)) { fprintf(stderr, "boolean argument parsing failed: %s\n", opt); 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 = 0; i < argc; i++) { char *opt = argv[i]; - g_autofree char **tokens = g_strsplit(opt, "=", 2); + g_auto(GStrv) tokens = g_strsplit(opt, "=", 2); if (g_strcmp0(tokens[0], "inline") == 0) { if (!qemu_plugin_bool_parse(tokens[0], tokens[1], &do_inline)) { fprintf(stderr, "boolean argument parsing failed: %s\n", opt); 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, for (int i = 0; i < argc; i++) { char *opt = argv[i]; - g_autofree char **tokens = g_strsplit(opt, "=", 2); + g_auto(GStrv) tokens = g_strsplit(opt, "=", 2); if (g_strcmp0(tokens[0], "haddr") == 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, for (int i = 0; i < argc; i++) { char *opt = argv[i]; - g_autofree char **tokens = g_strsplit(opt, "=", 2); + g_auto(GStrv) tokens = g_strsplit(opt, "=", 2); if (g_strcmp0(tokens[0], "print") == 0) { if (!qemu_plugin_bool_parse(tokens[0], tokens[1], &do_print)) { From patchwork Fri May 19 17:04:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 683906 Delivered-To: patch@linaro.org Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp1052085wrt; Fri, 19 May 2023 10:05:31 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7AwMcr/cKFNfEnFJgejxAfspod8nUlRiMHZli8XZwD6S0BNKOIJxP3mas0M8vfdmQHniRv X-Received: by 2002:ad4:5de3:0:b0:61b:5faf:9a72 with SMTP id jn3-20020ad45de3000000b0061b5faf9a72mr7046076qvb.3.1684515930904; Fri, 19 May 2023 10:05:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684515930; cv=none; d=google.com; s=arc-20160816; b=qF+27t+23QBLfEEi8MOQelNBP0d3CqhITxlS/t5TKNMcmKKeMZIjxMBHcjjL8/HaSm KZjd8Fj2reIUyDRSCxhcD7jXjUO869vfXWeI0IGpQEnOfE9blksoLniclcT9n9zhvm5r HXxbEgTXrOT2jzvXPSXZLtf9ojQxro9sDCceTUtB5xJ0ifjDccYgz0br4lLKhEfvamFT ZuDj6haRdq6WWtHUi1/dVG32nLPh0kLBWPB5keugTtlt0nFfyeGi5+ZVeFdkDehMS900 Ub5R7b9qTEJROb+QKnzjMWi5gQwBT6rjoXCCd/mJn6QwBGK11TWc5yKGRiEAl9un/ZkA ju3w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=BBI1EKXYVa+WMuYu7l3ZX5976guHRdH5nUfqC+4pCho=; b=AXsdzEsTxlTKArJbWTT7ERPkNLpn/W6juUZ77pWivHTWH5qHUBdL1ZOWPApc/TyKBL gshGLrwaKYeRVkfY67/OWRUSltRGfcDqu0F1LTZegYl9YKOZDPWw/rU0NdSQijgImeZK 3BYFlLm9GzlvXZUznKbPRcin3DO4vSkT1vYKtho1s/7WefgVI9uxHqK+Rtu2ts4M0BAQ 6zgs9vU5t6BdK4ugG5UABEaSji1y/XpCRu6o0R0tDw7Kw7sQuwWHGkYfLyVTO4SVwTM7 GYzUZFhDD/lLdK3z3F96f8xPD33bAy1lXDLjRAHzsz3TCXj5LlOUP+PRfJ6Aa3eu7tak nhYA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=vSmseuVK; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id jz10-20020a0562140e6a00b006218ca62ae3si2938998qvb.553.2023.05.19.10.05.30 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 19 May 2023 10:05:30 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=vSmseuVK; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 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) 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-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) 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) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: =?utf-8?q?Alex_Benn=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_Mathieu-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 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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org The old g_memdup is deprecated, use the replacement. Signed-off-by: Alex Bennée --- 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 = g_slist_prepend(divergence_log, - g_memdup(&divrec, sizeof(divrec))); + g_memdup2(&divrec, sizeof(divrec))); /* Output short log entry of going out of sync... */ if (verbose || divrec.distance == 1 || diverged) { From patchwork Fri May 19 17:04:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 683911 Delivered-To: patch@linaro.org Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp1053070wrt; Fri, 19 May 2023 10:07:08 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7qh+SdCrNlVuu81rmNaZ4+U89rEUhcr9xxz3o7gCwj12yU7V+P2i3wlZ5XV2hnLt/bN+23 X-Received: by 2002:ac8:7f92:0:b0:3e6:40f9:cf6c with SMTP id z18-20020ac87f92000000b003e640f9cf6cmr3951699qtj.28.1684516028315; Fri, 19 May 2023 10:07:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684516028; cv=none; d=google.com; s=arc-20160816; b=NJZjrNN8Kyt1RaPdFiqFM+SHeitScuVKQHfrKZ4bA00AKK7sbWCpWodA1tQCCt5kKq 9vJnJp+ez/xfuzqKR8egnhVz1HZMzlqk4JO+4loysweVX+BvtAqJAIZqV8He+VRzDmOP onrhyMYqVtwzZHfoE+8ffeg6lquYVJokt2ULj8JFarusBM7gWb1ylc5MJ5CyXXkcSat+ L52OY77FO5CuDkV+kQ6DAG07cEklPS9H50Lae/U2RRKVc74kmE9B3aNKCyQQwc3PyIqp 05YhOKnGAJceSS7hQHwoxcBkAX8wteZFVDPBIGiaKMQvEiw5SiiBNk+cSUKIbpEaUabZ kCTw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=Y4Fc4cXBL03Lk5/gUamd723FCI9OSGD0ICedLkUTlC8=; b=XByGwsXkivyegGofs4LT9QbTvq/xsvnBi8oiEToD6a2CdPtIQbeT9365GyXZrSBkqO e6w+8mwIQTaPTktnvjv2wpo6G6W8HwhDxG+hpGHmtGanYWx6ZJmRLfhT8eH3KkSELCLN knS2BsMdFxoTm1zH33ZuDyriXizWGn/vdsAX/qQkG9X2UPzIYeV/j8tYidir8bFOb+zL YVPn0+LIzm1bwNPbnqXY2slpN0+lLXuGjWaTkx3EdY4GW5sx6FX7BrZPHxA+e40RAnFX Pbb2mdTrctT9qEWvMtR9+K4/eaB7++aW4xf3Kn8IAcgkkevxiFNlRH59OYc509DKigM2 3hmw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=VoUv1nLC; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id z11-20020a056214040b00b0062387bfd1d1si2980852qvx.392.2023.05.19.10.07.08 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 19 May 2023 10:07:08 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=VoUv1nLC; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 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) 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-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) 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) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: =?utf-8?q?Alex_Benn=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_Mathieu-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 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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org 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ée Reviewed-by: Philippe Mathieu-Daudé --- include/sysemu/accel-ops.h | 18 +++++++++++++++++- include/sysemu/cpu-timers.h | 3 ++- softmmu/cpus.c | 11 +++++++++++ ...et-virtual-clock.c => cpus-virtual-clock.c} | 5 +++++ stubs/meson.build | 2 +- 5 files changed, 36 insertions(+), 3 deletions(-) rename stubs/{cpus-get-virtual-clock.c => 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) -/* 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 { void (*handle_interrupt)(CPUState *cpu, int mask); + /** + * @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); /* 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); void qemu_timer_notify_cb(void *opaque, QEMUClockType type); -/* 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 interface */ int64_t cpus_get_virtual_clock(void); +void cpus_set_virtual_clock(int64_t new_time); int64_t cpus_get_elapsed_ticks(void); #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(); } +/* + * 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 cycle 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')) From patchwork Fri May 19 17:04:51 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 683912 Delivered-To: patch@linaro.org Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp1053190wrt; Fri, 19 May 2023 10:07:20 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4lWhgU6X/lKc3aRwW1qu7eJ9FbJgDwXkQuUH9AffUhdD/E1+VnThQiwlVzXFcY6vZBUNW5 X-Received: by 2002:a05:622a:189e:b0:3f4:cfed:96bd with SMTP id v30-20020a05622a189e00b003f4cfed96bdmr4863075qtc.21.1684516040326; Fri, 19 May 2023 10:07:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684516040; cv=none; d=google.com; s=arc-20160816; b=Fj+4g6qBDxNNmtWXiF4Qbd69hTs2AfUQfiLb7hyFDjRXFA4DUZ4+0IKASMjSMPJ2sA B4G0bBr8JP/gOlw4pJr2Qjaqs1uu0UV7s/6hZWgOLOUDGFhdXYyI/oxJFp6kp6taHvzw WzHj6SlmlDQlDBPmVtndN8griP6drbV9B0WsGYhx0teJqHctSsDG8T5uf5h2ivNkZa6x J4gOxpIEzkYS+3gHrmLAROxSHYOPIvEbs+i2WyF2u9w0LNZBncB6JEFsLRPkR13/h8gG s3VKUwDOIWG0o29Yy3qCCU/cN/Rbhy3QPNVULe5XeeOdAE7wzR0/uVpCpdww0RnEn79w YBYA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=CR/oWYkskBmS5+T6RF3T/y2a8OCs1JuDOn7YbNsQaig=; b=fyMB5gA7WHntzzRw6iXdaQNA3vKu5amPGayERm5qEcL/00ZGAeTP6b31+lWetlz8+h e0sK0XrLWG7cMqePOCiVk5NkIrtNVSi5Fz9y61btyPACmqZ2m1ynm3RaIrSR1FJZ3Xyh Ipwl0LRImDj1+jOHqLJWaDnvx9KiS7hL9syIU4sl8lPqdi736Sr/wxcInUiZPsJgqrul 7Pfl8kfzQdYXRoxLJBgy9Zi8jC9gyit/Px6lKGGryfGC4uDfe7wcRB6Ym52Mik8WRoed SszzQS2/ruydzlSfhSO1DSP0k3t1UaXkkOMZP2bE8uvKdADPNjxzwIF8C21MZV/oVWh2 6VVA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Ntkube46; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id f9-20020a05620a15a900b0074e264d7ff1si2865638qkk.318.2023.05.19.10.07.20 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 19 May 2023 10:07:20 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Ntkube46; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 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) 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-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) 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) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: =?utf-8?q?Alex_Benn=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_Mathieu-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 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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org 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ée 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 *, const char *), 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 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, void *data) ops->create_vcpu_thread = dummy_start_vcpu_thread; ops->get_virtual_clock = qtest_get_virtual_clock; + ops->set_virtual_clock = qtest_set_virtual_clock; }; static const TypeInfo qtest_accel_ops_type = { 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); } -static void qtest_set_virtual_clock(int64_t count) +void qtest_set_virtual_clock(int64_t count) { qatomic_set_i64(&qtest_clock_counter, count); } static void qtest_clock_warp(int64_t dest) { - int64_t clock = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL); + int64_t clock = cpus_get_virtual_clock(); AioContext *aio_context; assert(qtest_enabled()); aio_context = qemu_get_aio_context(); @@ -347,7 +347,7 @@ static void qtest_clock_warp(int64_t dest) QEMU_TIMER_ATTR_ALL); int64_t warp = qemu_soonest_timeout(dest - clock, deadline); - qtest_set_virtual_clock(qtest_get_virtual_clock() + warp); + 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]); From patchwork Fri May 19 17:04:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 683907 Delivered-To: patch@linaro.org Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp1052683wrt; Fri, 19 May 2023 10:06:29 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4nhmzaT31ZTHP3KdlmO+K4mrbfyN4OiaixA0DSnbffKJMijAo988WxopvJooyG6m3ADa0u X-Received: by 2002:a05:7500:e3a3:b0:108:7016:58f0 with SMTP id qs35-20020a057500e3a300b00108701658f0mr185369gab.35.1684515989674; Fri, 19 May 2023 10:06:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684515989; cv=none; d=google.com; s=arc-20160816; b=iqwGCMh912QvGkTYlj95T11D3s1BWfy3B+N7K+V3mm3/vpCuKpBlGqAJHH2nxsSk1K X3FZ+rDbFsxqHN0lumoXk87Jr5aCstG/XiDnymB0oT+AAVWJOJRbBN9JEG7llX07evXA zue+alds6KdI7WBUn0eFPkZf1PT2W9KYa3AbgduDHyxK2v37824IZhkn2GlqSu978EKH BuRIudjokjW9gcxZS4oQ/1ye58NGyopgz2Ipd8wcf0T68t2Q0WX2rKBQxU0kaDJ9PFsj +zX28MRamegTEPuKgG6jgE6eWckCWYTJ611RVvbqfNcIT+vatVzvpbKkNYb1q1ogNZTp M0Ng== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=c1Ip0l2uFfVETbP6bR+CKxPn1peac5csfC67WejDHPo=; b=JFrHUECH6Z8Yj8ANK93BsFY6L4spzVwMLYv+3KcJA9Wn0h6TdiI4Cf7Ipx//urnRDL RgCapvv/9fYNqc76jBKO1ZMF0iWCue6oqzB/AOkhjffb/altmTFf1df5IlhQbaJ9I3qw iHjp3l9Ha6n1QFJHCXz2VEKzFauY9iPFZPPU+esfYYRDz4RIXP2/P1m41qNmbTKy5PLl MmmRDHWdXwL/+QYImlxwnd9HHUCddJA7xELmWx8AmFWMXIRJQJlzZFTWbYtcQxDLGIPm tPf4XpJ/bvfsjJCTte2IA9Webrn3Yuun1chRn5Jlm3oqxTzedm6JtkghzrmbX1qUFa9W mrwQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=EuQ57wgt; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id oo16-20020a05620a531000b007577c70d297si2809098qkn.479.2023.05.19.10.06.29 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 19 May 2023 10:06:29 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=EuQ57wgt; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 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) 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-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) 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) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: =?utf-8?q?Alex_Benn=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_Mathieu-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 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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org 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ée --- 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); +/** + * 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); /* * 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); } -static void qtest_clock_warp(int64_t dest) -{ - int64_t clock = cpus_get_virtual_clock(); - AioContext *aio_context; - assert(qtest_enabled()); - aio_context = qemu_get_aio_context(); - while (clock < dest) { - int64_t deadline = qemu_clock_deadline_ns_all(QEMU_CLOCK_VIRTUAL, - QEMU_TIMER_ATTR_ALL); - int64_t warp = 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 = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL); - } - qemu_clock_notify(QEMU_CLOCK_VIRTUAL); -} - static bool (*process_command_cb)(CharBackend *chr, gchar **words); void qtest_set_command_cb(bool (*pc_cb)(CharBackend *chr, gchar **words)) @@ -732,7 +712,7 @@ static void qtest_process_command(CharBackend *chr, gchar **words) ns = 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)); @@ -758,7 +738,7 @@ static void qtest_process_command(CharBackend *chr, gchar **words) g_assert(words[1]); ret = qemu_strtoi64(words[1], NULL, 0, &ns); g_assert(ret == 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) } } +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) return progress; } + +int64_t qemu_clock_advance_virtual_time(int64_t dest) +{ + int64_t clock = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL); + AioContext *aio_context; + aio_context = qemu_get_aio_context(); + while (clock < dest) { + int64_t deadline = qemu_clock_deadline_ns_all(QEMU_CLOCK_VIRTUAL, + QEMU_TIMER_ATTR_ALL); + int64_t warp = 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 = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL); + } + qemu_clock_notify(QEMU_CLOCK_VIRTUAL); + + return clock; +} From patchwork Fri May 19 17:04:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 683910 Delivered-To: patch@linaro.org Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp1053063wrt; Fri, 19 May 2023 10:07:08 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6pjmWshkh7MbkDjZ2vPnt5HVFczuHs8wUj9wmo82bRawTGM+ec9Sq4wdlo/8ck0/BGVB33 X-Received: by 2002:a05:6214:20a9:b0:5f7:8b31:4522 with SMTP id 9-20020a05621420a900b005f78b314522mr5468276qvd.5.1684516027762; Fri, 19 May 2023 10:07:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684516027; cv=none; d=google.com; s=arc-20160816; b=NaUDxsCW2AgvgZm3Gh80Xoprzer7JQbswwZYBVUfCRMIqGhwyhkSQGUCOFAIC2j7GK sxsC8CmleNat7eS3zdpUMGgnzWAJtFrIvpQJdr11rDr5elPu0312d85MKYWnN9hpWHxf BWlJh8e7Fgl7aqzByGgug3TV1l/YX4G7mIWlxOBjwNzzaV+ezkcR3ecURPUBpevLTeHT jy53StSr73TM3cyg0fClCJKGDVbcAdgq3sZRk09qOCSP184a/yTOKvhLaAxr315jMwol rDkGOodzKB8ylTzVugm7yJ9FO5RiN6wTCV1GHbf9SEnvgKUCGY/A4DiduXNqveP1W/od xc3w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=7F9Gx979+6Hkz/Du+/YB5Ayn8YHTGimM/bWSDeN1tW4=; b=TRQ4pg8ZSvwb1s2hT0giER/gOHhgORtcG8hA8LsOvX7e9DAbFHGatVdHoo5fwrH1qf Rag9669LVPIQEkSA4q9i09P5E1p6qKjPRJgAA+Cv94aqqVxuqlFIO1OheMi7RLZZX7lO oaaKrkeXwEYh8lFk/SbTfVdZv/XPsWW5y4dyryb3LE4zT5aWK7j09Knru7sHoMcMvaGO fFx+c9kCusNt15tD09RjqN2I1ItixrXjqlen2PgOppqppiNZpFDtzhnzitGs5XzT7gCb DWZbkKuz3dpzfPVkD6EQXQKK+5/vhLx9Au3iiQL4/S+4+0TOTJ0W4M9BfdqSQ80lfQAX SOGQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ErnBAQ9h; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id e16-20020ac84e50000000b003f38925148esi2893971qtw.328.2023.05.19.10.07.07 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 19 May 2023 10:07:07 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ErnBAQ9h; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 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) 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-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) 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) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: =?utf-8?q?Alex_Benn=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_Mathieu-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 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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org 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ée --- 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 *ptr, uint64_t imm); +/** + * 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. + */ +void qemu_plugin_update_ns(const void *handle, int64_t new_time); typedef void (*qemu_plugin_vcpu_syscall_cb_t)(qemu_plugin_id_t id, unsigned int vcpu_index, 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 = true; + return &has_control; + } + return NULL; +} + +void qemu_plugin_update_ns(const void *handle, int64_t new_time) +{ + if (handle == &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; }; From patchwork Fri May 19 17:04:54 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 683909 Delivered-To: patch@linaro.org Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp1052943wrt; Fri, 19 May 2023 10:06:56 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6/+yBDAeJI38nSb+UGI/reI2lUornaSAW32OFFWstJznOeECoMH+e3qyL33DwYvZajjZPC X-Received: by 2002:a1f:bf90:0:b0:456:d3e1:92d4 with SMTP id p138-20020a1fbf90000000b00456d3e192d4mr1044730vkf.12.1684516015834; Fri, 19 May 2023 10:06:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684516015; cv=none; d=google.com; s=arc-20160816; b=CEuQHUWiPQxvdfCWQhBTi72rVZSmCOXcMUJ+PJf99OtkqJXMd5hldHzL0dByswqa8n cXCSt2uVRgu0mdTIrpIl+djEFJ5Hg/73ifU+PKvV5NxzvZlnwRAvMcFy+dQ/k7ZQ2G+T FU05wkglQ8YiKKmFd1j/vhQv1Bzjx8uv1rty2BIFGQ02p2exqjLMosE+GqqacLhf7cEq 5ARrlQECv6Rwerkx/NS+xFgxF4ufr+krJbrZC0yLWc0bpe2+t78yU43u48QoWjpOx5P5 AxzSndKoNZb7wSFR0leSi7mkFzz/jL688A/vpZzHoXizOfgMR49a+mSaCl6Z6M8BWLlu 372w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=JokzLRHlJbPSM9sdlrouC/BAPg2f8genVSe9n3nO2c8=; b=0zyREV3rnft/CUY6RfX9lryQZprGdODT6WuSpCGYKHF8gV0lt7SY9prBBRC/xSTqGs eYOltjBhJyl0hYVjetjLY3c+g18fBguLsnApTVe34fjN3UNpfjtyARF5q2o9JmSL+iGi DpZ2daJEITqggl61jJfMXrOlz4JmIZDL6+wiRBJgUQgBxLZefe57UQau/+fTmlv7U9ne 1L6SNkgkDCPcretxJYoOodYRDvAcumrqCWVkTcJrbho4QKzFL/Ie246ZobIQ3jYA6JD0 JOL3VVWX22XAoxXRhJz7n9hJA5z7lLa+mDUvx0lrUjBIFWAPTCkf2PcVnIiVpZylqfts MuuA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=OaY6zbKQ; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id z19-20020a05620a101300b0074fb2b87c68si2775783qkj.693.2023.05.19.10.06.55 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 19 May 2023 10:06:55 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=OaY6zbKQ; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 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) 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-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) 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) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: =?utf-8?q?Alex_Benn=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_Mathieu-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 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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org 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ée --- 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 = QEMU_PLUGIN_VERSION; + +#define SLICES 10 /* the number of slices per second we compute delay */ + +static GMutex global_state_lock; + +static uint64_t iops = 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 = 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 = 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 = g_get_real_time(); + int64_t real_runtime_ns = 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 = (vcpu_ticks / iops) * nsec_per_sec; + if (tick_runtime_ns > real_runtime_ns) { + int64_t sleep_us = (tick_runtime_ns - real_runtime_ns) / 1000; + g_usleep(sleep_us); + } + + /* Having slept we can now move the clocks forward */ + qemu_plugin_update_ns(time_handle, vcpu_ticks); + current_ticks = vcpu_ticks; + next_check = 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 = get_vcpu(cpu_index); + vcpu->state = CREATED; + vcpu->state_time = *vcpu->counter; + + g_mutex_lock(&global_state_lock); + if (!systime_at_start) { + systime_at_start = 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 = get_vcpu(cpu_index); + vcpu->state = IDLE; + vcpu->state_time = *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 = 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 = current_ticks; + } else { + int64_t window = next_check - vcpu->state_time; + *vcpu->counter = next_check - (window / 2); + } + + vcpu->state = EXECUTING; + vcpu->state_time = *vcpu->counter; +} + +static void vcpu_exit(qemu_plugin_id_t id, unsigned int cpu_index) +{ + vCPUTime *vcpu = get_vcpu(cpu_index); + vcpu->state = FINISHED; + vcpu->state_time = *vcpu->counter; +} + +/* + * tb exec + */ +static void vcpu_tb_exec(unsigned int cpu_index, void *udata) +{ + vCPUTime *vcpu = get_vcpu(cpu_index); + uint64_t count = *vcpu->counter; + + count += GPOINTER_TO_UINT(udata); + + if (count >= 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 = 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 argc, + 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 = 0; i < argc; i++) { + char *opt = argv[i]; + g_auto(GStrv) tokens = g_strsplit(opt, "=", 2); + if (g_strcmp0(tokens[0], "iops") == 0) { + iops = 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") == 0) { + if (!qemu_plugin_bool_parse(tokens[0], tokens[1], &precise_execution)) { + fprintf(stderr, "boolean argument parsing failed: %s\n", opt); + return -1; + } + } else { + fprintf(stderr, "option parsing failed: %s\n", opt); + return -1; + } + } + + /* + * Setup the tracking information we need to run. + */ + vcpus = g_array_new(true, true, sizeof(vCPUTime)); + g_array_set_size(vcpus, info->system.max_vcpus); + vcpu_counters = g_malloc0_n(info->system.max_vcpus, sizeof(uint64_t)); + for (int i = 0; i < info->system.max_vcpus; i++) { + vCPUTime *vcpu = get_vcpu(i); + vcpu->counter = &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 = 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 = qemu_plugin_request_time_control(); + if (!time_handle) { + fprintf(stderr, "%s: not given permission to control time\n", __func__); + 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 += lockstep NAMES += hwprofile NAMES += cache NAMES += drcov +NAMES += iops SONAMES := $(addsuffix .so,$(addprefix lib,$(NAMES)))