mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-08-30 21:42:06 -06:00
hw/ppc: Fix clock update drift
The clock update logic reads the clock twice to compute the new clock value, with a value derived from the later time subtracted from a value derived from the earlier time. The delta causes time to be lost. This can ultimately result in time becoming unsynchronized between CPUs and that can cause OS lockups, timeouts, watchdogs, etc. This can be seen running a KVM guest (that causes lots of TB updates) on a powernv SMP machine. Fix this by reading the clock once. Cc: qemu-stable@nongnu.org Fixes:dbdd25065e
("Implement time-base start/stop helpers.") Signed-off-by: Nicholas Piggin <npiggin@gmail.com> Reviewed-by: Cédric Le Goater <clg@kaod.org> Reviewed-by: Frederic Barrat <fbarrat@linux.ibm.com> Message-ID: <20230629020713.327745-1-npiggin@gmail.com> Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com> (cherry picked from commit2ad2e113de
) Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
This commit is contained in:
parent
720db12b8b
commit
73d6ac24c8
1 changed files with 17 additions and 16 deletions
33
hw/ppc/ppc.c
33
hw/ppc/ppc.c
|
@ -535,23 +535,24 @@ static inline void cpu_ppc_store_tb(ppc_tb_t *tb_env, uint64_t vmclk,
|
|||
void cpu_ppc_store_tbl (CPUPPCState *env, uint32_t value)
|
||||
{
|
||||
ppc_tb_t *tb_env = env->tb_env;
|
||||
int64_t clock = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL);
|
||||
uint64_t tb;
|
||||
|
||||
tb = cpu_ppc_get_tb(tb_env, qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL), tb_env->tb_offset);
|
||||
tb = cpu_ppc_get_tb(tb_env, clock, tb_env->tb_offset);
|
||||
tb &= 0xFFFFFFFF00000000ULL;
|
||||
cpu_ppc_store_tb(tb_env, qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL),
|
||||
&tb_env->tb_offset, tb | (uint64_t)value);
|
||||
cpu_ppc_store_tb(tb_env, clock, &tb_env->tb_offset, tb | (uint64_t)value);
|
||||
}
|
||||
|
||||
static inline void _cpu_ppc_store_tbu(CPUPPCState *env, uint32_t value)
|
||||
{
|
||||
ppc_tb_t *tb_env = env->tb_env;
|
||||
int64_t clock = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL);
|
||||
uint64_t tb;
|
||||
|
||||
tb = cpu_ppc_get_tb(tb_env, qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL), tb_env->tb_offset);
|
||||
tb = cpu_ppc_get_tb(tb_env, clock, tb_env->tb_offset);
|
||||
tb &= 0x00000000FFFFFFFFULL;
|
||||
cpu_ppc_store_tb(tb_env, qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL),
|
||||
&tb_env->tb_offset, ((uint64_t)value << 32) | tb);
|
||||
cpu_ppc_store_tb(tb_env, clock, &tb_env->tb_offset,
|
||||
((uint64_t)value << 32) | tb);
|
||||
}
|
||||
|
||||
void cpu_ppc_store_tbu (CPUPPCState *env, uint32_t value)
|
||||
|
@ -584,23 +585,24 @@ uint32_t cpu_ppc_load_atbu (CPUPPCState *env)
|
|||
void cpu_ppc_store_atbl (CPUPPCState *env, uint32_t value)
|
||||
{
|
||||
ppc_tb_t *tb_env = env->tb_env;
|
||||
int64_t clock = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL);
|
||||
uint64_t tb;
|
||||
|
||||
tb = cpu_ppc_get_tb(tb_env, qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL), tb_env->atb_offset);
|
||||
tb = cpu_ppc_get_tb(tb_env, clock, tb_env->atb_offset);
|
||||
tb &= 0xFFFFFFFF00000000ULL;
|
||||
cpu_ppc_store_tb(tb_env, qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL),
|
||||
&tb_env->atb_offset, tb | (uint64_t)value);
|
||||
cpu_ppc_store_tb(tb_env, clock, &tb_env->atb_offset, tb | (uint64_t)value);
|
||||
}
|
||||
|
||||
void cpu_ppc_store_atbu (CPUPPCState *env, uint32_t value)
|
||||
{
|
||||
ppc_tb_t *tb_env = env->tb_env;
|
||||
int64_t clock = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL);
|
||||
uint64_t tb;
|
||||
|
||||
tb = cpu_ppc_get_tb(tb_env, qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL), tb_env->atb_offset);
|
||||
tb = cpu_ppc_get_tb(tb_env, clock, tb_env->atb_offset);
|
||||
tb &= 0x00000000FFFFFFFFULL;
|
||||
cpu_ppc_store_tb(tb_env, qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL),
|
||||
&tb_env->atb_offset, ((uint64_t)value << 32) | tb);
|
||||
cpu_ppc_store_tb(tb_env, clock, &tb_env->atb_offset,
|
||||
((uint64_t)value << 32) | tb);
|
||||
}
|
||||
|
||||
uint64_t cpu_ppc_load_vtb(CPUPPCState *env)
|
||||
|
@ -622,14 +624,13 @@ void cpu_ppc_store_vtb(CPUPPCState *env, uint64_t value)
|
|||
void cpu_ppc_store_tbu40(CPUPPCState *env, uint64_t value)
|
||||
{
|
||||
ppc_tb_t *tb_env = env->tb_env;
|
||||
int64_t clock = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL);
|
||||
uint64_t tb;
|
||||
|
||||
tb = cpu_ppc_get_tb(tb_env, qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL),
|
||||
tb_env->tb_offset);
|
||||
tb = cpu_ppc_get_tb(tb_env, clock, tb_env->tb_offset);
|
||||
tb &= 0xFFFFFFUL;
|
||||
tb |= (value & ~0xFFFFFFUL);
|
||||
cpu_ppc_store_tb(tb_env, qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL),
|
||||
&tb_env->tb_offset, tb);
|
||||
cpu_ppc_store_tb(tb_env, clock, &tb_env->tb_offset, tb);
|
||||
}
|
||||
|
||||
static void cpu_ppc_tb_stop (CPUPPCState *env)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue