[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 14/29] cpus: Fix throttling during vm_stop
From: |
Paolo Bonzini |
Subject: |
[Qemu-devel] [PULL 14/29] cpus: Fix throttling during vm_stop |
Date: |
Mon, 16 Sep 2019 16:41:54 +0200 |
From: Yury Kotov <address@hidden>
Throttling thread sleeps in VCPU thread. For high throttle percentage
this sleep is more than 10ms. E.g. for 60% - 15ms, for 99% - 990ms.
vm_stop() kicks all VCPUs and waits for them. It's called at the end of
migration and because of the long sleep the migration downtime might be
more than 100ms even for downtime-limit 1ms.
Use qemu_cond_timedwait for high percentage to wake up during vm_stop.
Signed-off-by: Yury Kotov <address@hidden>
Reviewed-by: Eric Blake <address@hidden>
Message-Id: <address@hidden>
---
cpus.c | 25 +++++++++++++++++--------
1 file changed, 17 insertions(+), 8 deletions(-)
diff --git a/cpus.c b/cpus.c
index 85cd451..d2c61ff 100644
--- a/cpus.c
+++ b/cpus.c
@@ -77,6 +77,8 @@
#endif /* CONFIG_LINUX */
+static QemuMutex qemu_global_mutex;
+
int64_t max_delay;
int64_t max_advance;
@@ -782,7 +784,7 @@ static void cpu_throttle_thread(CPUState *cpu,
run_on_cpu_data opaque)
{
double pct;
double throttle_ratio;
- long sleeptime_ns;
+ int64_t sleeptime_ns, endtime_ns;
if (!cpu_throttle_get_percentage()) {
return;
@@ -790,11 +792,20 @@ static void cpu_throttle_thread(CPUState *cpu,
run_on_cpu_data opaque)
pct = (double)cpu_throttle_get_percentage()/100;
throttle_ratio = pct / (1 - pct);
- sleeptime_ns = (long)(throttle_ratio * CPU_THROTTLE_TIMESLICE_NS);
-
- qemu_mutex_unlock_iothread();
- g_usleep(sleeptime_ns / 1000); /* Convert ns to us for usleep call */
- qemu_mutex_lock_iothread();
+ /* Add 1ns to fix double's rounding error (like 0.9999999...) */
+ sleeptime_ns = (int64_t)(throttle_ratio * CPU_THROTTLE_TIMESLICE_NS + 1);
+ endtime_ns = qemu_clock_get_ns(QEMU_CLOCK_REALTIME) + sleeptime_ns;
+ while (sleeptime_ns > 0 && !cpu->stop) {
+ if (sleeptime_ns > SCALE_MS) {
+ qemu_cond_timedwait(cpu->halt_cond, &qemu_global_mutex,
+ sleeptime_ns / SCALE_MS);
+ } else {
+ qemu_mutex_unlock_iothread();
+ g_usleep(sleeptime_ns / SCALE_US);
+ qemu_mutex_lock_iothread();
+ }
+ sleeptime_ns = endtime_ns - qemu_clock_get_ns(QEMU_CLOCK_REALTIME);
+ }
atomic_set(&cpu->throttle_thread_scheduled, 0);
}
@@ -1172,8 +1183,6 @@ static void qemu_init_sigbus(void)
}
#endif /* !CONFIG_LINUX */
-static QemuMutex qemu_global_mutex;
-
static QemuThread io_thread;
/* cpu creation */
--
1.8.3.1
- [Qemu-devel] [PULL 04/29] exec.c: subpage->sub_section is already initialized to 0, (continued)
- [Qemu-devel] [PULL 04/29] exec.c: subpage->sub_section is already initialized to 0, Paolo Bonzini, 2019/09/16
- [Qemu-devel] [PULL 06/29] exec.c: add a check between constants to see whether we could skip, Paolo Bonzini, 2019/09/16
- [Qemu-devel] [PULL 05/29] exec.c: correct the maximum skip value during compact, Paolo Bonzini, 2019/09/16
- [Qemu-devel] [PULL 07/29] win32: fix README file in NSIS installer, Paolo Bonzini, 2019/09/16
- [Qemu-devel] [PULL 08/29] test-char: fix AddressSanitizer failure, Paolo Bonzini, 2019/09/16
- [Qemu-devel] [PULL 09/29] hw/i386: Move CONFIG_ACPI_PCI to CONFIG_PC, Paolo Bonzini, 2019/09/16
- [Qemu-devel] [PULL 10/29] elf-ops.h: fix int overflow in load_elf(), Paolo Bonzini, 2019/09/16
- [Qemu-devel] [PULL 12/29] memory: inline and optimize devend_memop, Paolo Bonzini, 2019/09/16
- [Qemu-devel] [PULL 11/29] memory: fetch pmem size in get_file_size(), Paolo Bonzini, 2019/09/16
- [Qemu-devel] [PULL 15/29] hw/i386/pc: Use e820_get_num_entries() to access e820_entries, Paolo Bonzini, 2019/09/16
- [Qemu-devel] [PULL 14/29] cpus: Fix throttling during vm_stop,
Paolo Bonzini <=
- [Qemu-devel] [PULL 16/29] hw/i386/pc: Extract e820 memory layout code, Paolo Bonzini, 2019/09/16
- [Qemu-devel] [PULL 20/29] hw/i386/pc: Pass the apic_id_limit value by argument, Paolo Bonzini, 2019/09/16
- [Qemu-devel] [PULL 13/29] qemu-thread: Add qemu_cond_timedwait, Paolo Bonzini, 2019/09/16
- [Qemu-devel] [PULL 21/29] hw/i386/pc: Pass the CPUArchIdList array by argument, Paolo Bonzini, 2019/09/16
- [Qemu-devel] [PULL 22/29] hw/i386/pc: Replace PCMachineState argument with MachineState in fw_cfg_arch_create, Paolo Bonzini, 2019/09/16
- [Qemu-devel] [PULL 23/29] hw/i386/pc: Let pc_build_smbios() take a FWCfgState argument, Paolo Bonzini, 2019/09/16
- [Qemu-devel] [PULL 25/29] hw/i386/pc: Rename pc_build_smbios() as generic fw_cfg_build_smbios(), Paolo Bonzini, 2019/09/16
- [Qemu-devel] [PULL 24/29] hw/i386/pc: Let pc_build_smbios() take a generic MachineState argument, Paolo Bonzini, 2019/09/16
- [Qemu-devel] [PULL 28/29] hw/i386/pc: Rename pc_build_feature_control() as generic fw_cfg_build_*, Paolo Bonzini, 2019/09/16
- [Qemu-devel] [PULL 17/29] hw/i386/pc: Use address_space_memory in place, Paolo Bonzini, 2019/09/16