From patchwork Fri Oct 13 12:56:24 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 733196 Delivered-To: patch@linaro.org Received: by 2002:a5d:54d1:0:b0:31d:da82:a3b4 with SMTP id x17csp1448303wrv; Fri, 13 Oct 2023 05:57:09 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEVfYTnBB6Y+zoR61jfrx+bxZHfFm5RX4J6LBMAZeNfwQcszDLXiLClA4LNoZsE5JQ/iBMK X-Received: by 2002:a05:622a:453:b0:412:6e6:b45b with SMTP id o19-20020a05622a045300b0041206e6b45bmr33127965qtx.38.1697201829504; Fri, 13 Oct 2023 05:57:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697201829; cv=none; d=google.com; s=arc-20160816; b=WSn6zzx4E7sWFoXDBQwQAZ85bVUJWxwgiJVJP4dUzEvBipaP1WRiLzbTqLCq0f3TPU llc1Wt+jdnMEUNEdpyfQjiuQo9o9uOk3PX9eH06HhvH2PsIUQw/RyYyYEofGUZgPYgI9 G+RrojMLYNxlKi6E9PZafbUS82x0+O8SSBk5MBJhPcxQf8Fo5ETZcZih+6wUWg4z0Cix TUpvhj4n8SKeCTQz8bLdAuEcQGW6ZFrUZCHS6Mzipr9pkqfM1++YCdMbMRC+TLdY8uHf 6LTlu1gr7nTo//++iNa1oUlDnyg7voziPpsIOyxs1ICAbXR/o1EIW5aSwpfr5jBI0pgH WArQ== 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=aJG9hKwu+wpRvVwz3i5zPTfZu546zhwzoj0NQVluILM=; fh=VA6j7lkwZBpc1StxpFljCA0aH/klDdhOAPrIIfLw9Rk=; b=cXemx2Ym+iFij2/YpgfONh2WEFqY8pNEpuMgQCxbwNU9Qgp3MXsg0oJMkAUvMtIpWO x2uocfJow2LKa9hiQ4XWsPvbjxrS3uFlvAFF99jtY3Qsx69GGxi99do13GCxWsPdtQD3 YIAyvKNR9wc2cIHqXppy2+viMWxpxsU3q6SbMRXwCv8vjvbAMWJwC1qP0Sh+Kk830ehI Q2Rsjdn9cR6ctFAakyc4NnfjPO1LJzZkaJbsVHKQgFoXPYbT1SGCTFeFLdtKv2Ia1URd OziBxxd3vIKG7Bi8c4o5L/FO2RTpJE/5BjlRyzWxWw0mzCDL6vB+wkl/ufvSVy8zN2fH 2PnQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=kgzeKRoZ; 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 c1-20020ac87dc1000000b004199342839dsi1126649qte.234.2023.10.13.05.57.09 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 13 Oct 2023 05:57:09 -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=kgzeKRoZ; 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 1qrHih-00035E-I5; Fri, 13 Oct 2023 08:56:47 -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 1qrHie-0002rq-Hl for qemu-devel@nongnu.org; Fri, 13 Oct 2023 08:56:44 -0400 Received: from mail-ed1-x532.google.com ([2a00:1450:4864:20::532]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qrHic-0002YQ-AH for qemu-devel@nongnu.org; Fri, 13 Oct 2023 08:56:44 -0400 Received: by mail-ed1-x532.google.com with SMTP id 4fb4d7f45d1cf-53dd752685fso3686898a12.3 for ; Fri, 13 Oct 2023 05:56:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1697201800; x=1697806600; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=aJG9hKwu+wpRvVwz3i5zPTfZu546zhwzoj0NQVluILM=; b=kgzeKRoZ1mvc42qI+U/KAu1/G1eNQwordEIAeW3ChGXYDGAZXGo0akFh6Iu4HTHz8g XYYHtdT4HHhaOYrmRjIMVSNWvT2717cJqi5iyKONvym2pHPkaqUly7YquVZN04Mfpklh LB+JgxzZYviZ/OyouOUcTKRbXowZXXqhQA3tl390p897OTbBhmIY08KBbF8DM5CPEwJT ZXeQhvRcyA/cXE1BzUfm1vVkbB2IvRLHhb2mWQ3yogvQbefeZXFfCkO2QXfFDBAAPB2f MOheE6A07XtDcoPEKLww7i2mxQWpGLEh/dMZ0ZnHsUVGR0UV1xXDcdcDq+AipJDtk8Dy ZD7Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697201800; x=1697806600; 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=aJG9hKwu+wpRvVwz3i5zPTfZu546zhwzoj0NQVluILM=; b=T2PwJowxjYvmwlUpoaoPn4OEg/BYhKn85bp6g0Rp0K8SkdLaslOX8q7WRP7bL6XWbQ Kn/naV4/rkmod3u4MWw4u9N8M+0GtcBjobVlPwBj55dTeENLqXQJbsz4vKVyLkXDI3qN 37zxsndVhDDiPmH0DsTSG0Hs0ImWCDi5P7pD6oGaEN/n/0njGpYZKdT4602e8ElcdyQU lI2tdEqrc1pEQkSoqKl8JLjGRyrU/BeoGVGiYbH/Gpx1B1ryxIFZ8D69yt3Qq6UgvHT4 CVUGMmSusL8AYN2YQQKOLhFsEZMy80/de81oAA1GZAUvcjvokmbCj/ZMZQ4HTZRtRA6p iXxw== X-Gm-Message-State: AOJu0YwtwDTHtLm2x/57cOSKqz4t/h6ABT2ratcyk9p+hF0VxOF97yYQ 9GTQNBYv4OpjFPm0w6UMiSz5rrho8QNSLsEEK48= X-Received: by 2002:a05:6402:150d:b0:523:bfec:4915 with SMTP id f13-20020a056402150d00b00523bfec4915mr25184247edw.0.1697201800089; Fri, 13 Oct 2023 05:56:40 -0700 (PDT) Received: from m1x-phil.lan ([176.172.118.168]) by smtp.gmail.com with ESMTPSA id da6-20020a056402176600b0053dfd3519f4sm2439193edb.22.2023.10.13.05.56.37 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Fri, 13 Oct 2023 05:56:38 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: David Gibson , qemu-ppc@nongnu.org, Nicholas Piggin , Harsh Prateek Bora , =?utf-8?q?C=C3=A9dric_Le_Goater?= , Daniel Henrique Barboza , =?utf-8?q?Philippe_Mathieu?= =?utf-8?q?-Daud=C3=A9?= Subject: [PATCH 1/7] hw/ppc/spapr: Restrict PPCTimebase structure declaration to sPAPR Date: Fri, 13 Oct 2023 14:56:24 +0200 Message-ID: <20231013125630.95116-2-philmd@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231013125630.95116-1-philmd@linaro.org> References: <20231013125630.95116-1-philmd@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::532; envelope-from=philmd@linaro.org; helo=mail-ed1-x532.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 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 PPCTimebase structure is only used by the sPAPR machine. Move its declaration to "hw/ppc/spapr.h". Move vmstate_ppc_timebase and the VMSTATE_PPC_TIMEBASE_V() macro to hw/ppc/spapr.c, along with the timebase_foo() migration helpers. Signed-off-by: Philippe Mathieu-Daudé Reviewed-by: Richard Henderson Reviewed-by: Cédric Le Goater --- include/hw/ppc/spapr.h | 6 +++ target/ppc/cpu-qom.h | 22 -------- hw/ppc/ppc.c | 107 ------------------------------------- hw/ppc/spapr.c | 116 +++++++++++++++++++++++++++++++++++++++++ 4 files changed, 122 insertions(+), 129 deletions(-) diff --git a/include/hw/ppc/spapr.h b/include/hw/ppc/spapr.h index e91791a1a9..3cf9978cba 100644 --- a/include/hw/ppc/spapr.h +++ b/include/hw/ppc/spapr.h @@ -163,6 +163,12 @@ struct SpaprMachineClass { SpaprIrq *irq; }; +typedef struct PPCTimebase { + uint64_t guest_timebase; + int64_t time_of_the_day_ns; + bool runstate_paused; +} PPCTimebase; + #define WDT_MAX_WATCHDOGS 4 /* Maximum number of watchdog devices */ #define TYPE_SPAPR_WDT "spapr-wdt" diff --git a/target/ppc/cpu-qom.h b/target/ppc/cpu-qom.h index be33786bd8..b5deef5ca5 100644 --- a/target/ppc/cpu-qom.h +++ b/target/ppc/cpu-qom.h @@ -197,26 +197,4 @@ struct PowerPCCPUClass { int (*check_pow)(CPUPPCState *env); }; -#ifndef CONFIG_USER_ONLY -typedef struct PPCTimebase { - uint64_t guest_timebase; - int64_t time_of_the_day_ns; - bool runstate_paused; -} PPCTimebase; - -extern const VMStateDescription vmstate_ppc_timebase; - -#define VMSTATE_PPC_TIMEBASE_V(_field, _state, _version) { \ - .name = (stringify(_field)), \ - .version_id = (_version), \ - .size = sizeof(PPCTimebase), \ - .vmsd = &vmstate_ppc_timebase, \ - .flags = VMS_STRUCT, \ - .offset = vmstate_offset_value(_state, _field, PPCTimebase), \ -} - -void cpu_ppc_clock_vm_state_change(void *opaque, bool running, - RunState state); -#endif - #endif diff --git a/hw/ppc/ppc.c b/hw/ppc/ppc.c index be167710a3..340cd6192f 100644 --- a/hw/ppc/ppc.c +++ b/hw/ppc/ppc.c @@ -32,7 +32,6 @@ #include "qemu/main-loop.h" #include "qemu/error-report.h" #include "sysemu/kvm.h" -#include "sysemu/replay.h" #include "sysemu/runstate.h" #include "kvm_ppc.h" #include "migration/vmstate.h" @@ -967,112 +966,6 @@ void cpu_ppc_store_purr(CPUPPCState *env, uint64_t value) _cpu_ppc_store_purr(env, qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL), value); } -static void timebase_save(PPCTimebase *tb) -{ - uint64_t ticks = cpu_get_host_ticks(); - PowerPCCPU *first_ppc_cpu = POWERPC_CPU(first_cpu); - - if (!first_ppc_cpu->env.tb_env) { - error_report("No timebase object"); - return; - } - - if (replay_mode == REPLAY_MODE_NONE) { - /* not used anymore, we keep it for compatibility */ - tb->time_of_the_day_ns = qemu_clock_get_ns(QEMU_CLOCK_HOST); - } else { - /* simpler for record-replay to avoid this event, compat not needed */ - tb->time_of_the_day_ns = 0; - } - - /* - * tb_offset is only expected to be changed by QEMU so - * there is no need to update it from KVM here - */ - tb->guest_timebase = ticks + first_ppc_cpu->env.tb_env->tb_offset; - - tb->runstate_paused = - runstate_check(RUN_STATE_PAUSED) || runstate_check(RUN_STATE_SAVE_VM); -} - -static void timebase_load(PPCTimebase *tb) -{ - CPUState *cpu; - PowerPCCPU *first_ppc_cpu = POWERPC_CPU(first_cpu); - int64_t tb_off_adj, tb_off; - unsigned long freq; - - if (!first_ppc_cpu->env.tb_env) { - error_report("No timebase object"); - return; - } - - freq = first_ppc_cpu->env.tb_env->tb_freq; - - tb_off_adj = tb->guest_timebase - cpu_get_host_ticks(); - - tb_off = first_ppc_cpu->env.tb_env->tb_offset; - trace_ppc_tb_adjust(tb_off, tb_off_adj, tb_off_adj - tb_off, - (tb_off_adj - tb_off) / freq); - - /* Set new offset to all CPUs */ - CPU_FOREACH(cpu) { - PowerPCCPU *pcpu = POWERPC_CPU(cpu); - pcpu->env.tb_env->tb_offset = tb_off_adj; - kvmppc_set_reg_tb_offset(pcpu, pcpu->env.tb_env->tb_offset); - } -} - -void cpu_ppc_clock_vm_state_change(void *opaque, bool running, - RunState state) -{ - PPCTimebase *tb = opaque; - - if (running) { - timebase_load(tb); - } else { - timebase_save(tb); - } -} - -/* - * When migrating a running guest, read the clock just - * before migration, so that the guest clock counts - * during the events between: - * - * * vm_stop() - * * - * * pre_save() - * - * This reduces clock difference on migration from 5s - * to 0.1s (when max_downtime == 5s), because sending the - * final pages of memory (which happens between vm_stop() - * and pre_save()) takes max_downtime. - */ -static int timebase_pre_save(void *opaque) -{ - PPCTimebase *tb = opaque; - - /* guest_timebase won't be overridden in case of paused guest or savevm */ - if (!tb->runstate_paused) { - timebase_save(tb); - } - - return 0; -} - -const VMStateDescription vmstate_ppc_timebase = { - .name = "timebase", - .version_id = 1, - .minimum_version_id = 1, - .pre_save = timebase_pre_save, - .fields = (VMStateField []) { - VMSTATE_UINT64(guest_timebase, PPCTimebase), - VMSTATE_INT64(time_of_the_day_ns, PPCTimebase), - VMSTATE_END_OF_LIST() - }, -}; - /* Set up (once) timebase frequency (in Hz) */ void cpu_ppc_tb_init(CPUPPCState *env, uint32_t freq) { diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c index cb840676d3..fe8b425ffd 100644 --- a/hw/ppc/spapr.c +++ b/hw/ppc/spapr.c @@ -37,6 +37,7 @@ #include "sysemu/numa.h" #include "sysemu/qtest.h" #include "sysemu/reset.h" +#include "sysemu/replay.h" #include "sysemu/runstate.h" #include "qemu/log.h" #include "hw/fw-path-provider.h" @@ -1809,6 +1810,100 @@ static bool spapr_vga_init(PCIBus *pci_bus, Error **errp) } } +static void timebase_save(PPCTimebase *tb) +{ + uint64_t ticks = cpu_get_host_ticks(); + PowerPCCPU *first_ppc_cpu = POWERPC_CPU(first_cpu); + + if (!first_ppc_cpu->env.tb_env) { + error_report("No timebase object"); + return; + } + + if (replay_mode == REPLAY_MODE_NONE) { + /* not used anymore, we keep it for compatibility */ + tb->time_of_the_day_ns = qemu_clock_get_ns(QEMU_CLOCK_HOST); + } else { + /* simpler for record-replay to avoid this event, compat not needed */ + tb->time_of_the_day_ns = 0; + } + + /* + * tb_offset is only expected to be changed by QEMU so + * there is no need to update it from KVM here + */ + tb->guest_timebase = ticks + first_ppc_cpu->env.tb_env->tb_offset; + + tb->runstate_paused = + runstate_check(RUN_STATE_PAUSED) || runstate_check(RUN_STATE_SAVE_VM); +} + +static void timebase_load(PPCTimebase *tb) +{ + CPUState *cpu; + PowerPCCPU *first_ppc_cpu = POWERPC_CPU(first_cpu); + int64_t tb_off_adj, tb_off; + unsigned long freq; + + if (!first_ppc_cpu->env.tb_env) { + error_report("No timebase object"); + return; + } + + freq = first_ppc_cpu->env.tb_env->tb_freq; + + tb_off_adj = tb->guest_timebase - cpu_get_host_ticks(); + + tb_off = first_ppc_cpu->env.tb_env->tb_offset; + trace_ppc_tb_adjust(tb_off, tb_off_adj, tb_off_adj - tb_off, + (tb_off_adj - tb_off) / freq); + + /* Set new offset to all CPUs */ + CPU_FOREACH(cpu) { + PowerPCCPU *pcpu = POWERPC_CPU(cpu); + pcpu->env.tb_env->tb_offset = tb_off_adj; + kvmppc_set_reg_tb_offset(pcpu, pcpu->env.tb_env->tb_offset); + } +} + +static void cpu_ppc_clock_vm_state_change(void *opaque, bool running, + RunState state) +{ + PPCTimebase *tb = opaque; + + if (running) { + timebase_load(tb); + } else { + timebase_save(tb); + } +} + +/* + * When migrating a running guest, read the clock just + * before migration, so that the guest clock counts + * during the events between: + * + * * vm_stop() + * * + * * pre_save() + * + * This reduces clock difference on migration from 5s + * to 0.1s (when max_downtime == 5s), because sending the + * final pages of memory (which happens between vm_stop() + * and pre_save()) takes max_downtime. + */ +static int timebase_pre_save(void *opaque) +{ + PPCTimebase *tb = opaque; + + /* guest_timebase won't be overridden in case of paused guest or savevm */ + if (!tb->runstate_paused) { + timebase_save(tb); + } + + return 0; +} + static int spapr_pre_load(void *opaque) { int rc; @@ -2081,6 +2176,27 @@ static const VMStateDescription vmstate_spapr_fwnmi = { }, }; +static const VMStateDescription vmstate_spapr_timebase = { + .name = "timebase", + .version_id = 1, + .minimum_version_id = 1, + .pre_save = timebase_pre_save, + .fields = (VMStateField []) { + VMSTATE_UINT64(guest_timebase, PPCTimebase), + VMSTATE_INT64(time_of_the_day_ns, PPCTimebase), + VMSTATE_END_OF_LIST() + }, +}; + +#define VMSTATE_PPC_TIMEBASE_V(_field, _state, _version) { \ + .name = (stringify(_field)), \ + .version_id = (_version), \ + .size = sizeof(PPCTimebase), \ + .vmsd = &vmstate_spapr_timebase, \ + .flags = VMS_STRUCT, \ + .offset = vmstate_offset_value(_state, _field, PPCTimebase), \ +} + static const VMStateDescription vmstate_spapr = { .name = "spapr", .version_id = 3,