migration: Dynamic cpu throttling for auto-converge
cover migration: Dynamic cpu throttling for auto-converge
This patch set provides a new method for throttling a vcpu and makes use of said method to dynamically increase cpu throttling during an autoconverge migration until the migration completes. This method ensures that all migrations will eventually converge.
The method used here for throttling vcpus is likely not the best. However, I believe that it is preferable to what is used for autoconverge today.
This work is related to the following discussion:
https://lists.gnu.org/archive/html/qemu-devel/2015-03/msg00287.html
Jason J. Herne (2):
cpu: Provide vcpu throttling interface
migration: Dynamic cpu throttling for auto-converge
arch_init.c | 95 +++++++++++++++++---------------------------------- cpus.c | 62 +++++++++++++++++++++++++++++++++ include/qom/cpu.h | 46 +++++++++++++++++++++++++ migration/migration.c | 9 +++++ 4 files changed, 149 insertions(+), 63 deletions(-)
Signature · 1 line
1.9.1
PATCH 1/2 cpu: Provide vcpu throttling interface
Provide a method to throttle guest cpu execution. CPUState is augmented with timeout controls and throttle start/stop functions. To throttle the guest cpu the caller simply has to call the throttle start function and provide a ratio of sleep time to normal execution time.
--- cpus.c | 62 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ include/qom/cpu.h | 46 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 108 insertions(+)
cpus.c +62 -0
@@ -64,6 +64,9 @@#endif /* CONFIG_LINUX */ +/* Number of ms between cpu throttle operations */ +#define CPU_THROTTLE_TIMESLICE 10 +static CPUState *next_cpu;int64_t max_delay;int64_t max_advance;
@@ -919,6 +922,65 @@ static void qemu_kvm_wait_io_event(CPUState *cpu)qemu_wait_io_event_common (cpu); } +static void cpu_throttle_thread (void *opq) +{ +CPUState *cpu = (CPUState *)opq; +long sleeptime_ms = (long )(cpu->throttle_ratio *CPU_THROTTLE_TIMESLICE ); + +/* Stop the timer if needed */ +if (cpu->throttle_timer_stop) { +timer_del (cpu->throttle_timer); +timer_free (cpu->throttle_timer); + cpu->throttle_timer =NULL ; +return ; + } + +qemu_mutex_unlock_iothread (); +g_usleep (sleeptime_ms *1000 );/* Convert ms to us for usleep call */ +qemu_mutex_lock_iothread (); + +timer_mod (cpu->throttle_timer,qemu_clock_get_ms (QEMU_CLOCK_REALTIME ) + +CPU_THROTTLE_TIMESLICE ); +} + +static void cpu_throttle_timer_pop (void *opq) +{ +CPUState *cpu = (CPUState *)opq; + +async_run_on_cpu (cpu, cpu_throttle_thread, cpu); +} + +void cpu_throttle_start (CPUState *cpu,float throttle_ratio) +{ +assert (throttle_ratio >0 ); + cpu->throttle_ratio = throttle_ratio; + +if (!cpu_throttle_active (cpu)) { + cpu->throttle_timer =timer_new_ms (QEMU_CLOCK_REALTIME , + cpu_throttle_timer_pop, cpu); +timer_mod (cpu->throttle_timer,qemu_clock_get_ms (QEMU_CLOCK_REALTIME ) + +CPU_THROTTLE_TIMESLICE ); + cpu->throttle_timer_stop = false; + } +} + +void cpu_throttle_stop (CPUState *cpu) +{ +assert (cpu_throttle_active (cpu)); + cpu->throttle_timer_stop = true; +} + +bool cpu_throttle_active (CPUState *cpu) +{ +return (cpu->throttle_timer !=NULL ); +} + +float cpu_throttle_get_ratio (CPUState *cpu) +{ +assert (cpu_throttle_active (cpu)); +return cpu->throttle_ratio; +} +static void *qemu_kvm_cpu_thread_fn (void *arg) {CPUState *cpu = arg;
include/qom/cpu.h +46 -0
58 lines not on this page · raw message
Signature · 1 line
1.9.1
Re: [Qemu-devel] [PATCH 1/2] cpu: Provide vcpu throttling interface
Quoted 157 lines · Jason J. Herne
Provide a method to throttle guest cpu execution. CPUState is augmented with timeout controls and throttle start/stop functions. To throttle the guest cpu the caller simply has to call the throttle start function and provide a ratio of sleep time to normal execution time.
Signed-off-by Jason J. Herne <[email protected]>Reviewed-by Matthew Rosato <[email protected]>--- cpus.c | 62 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ include/qom/cpu.h | 46 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 108 insertions(+)cpus.c +62
-0@@ -64,6 +64,9 @@#endif /* CONFIG_LINUX */ +/* Number of ms between cpu throttle operations */ +#define CPU_THROTTLE_TIMESLICE 10 +static CPUState *next_cpu;int64_t max_delay;int64_t max_advance;@@ -919,6 +922,65 @@ static void qemu_kvm_wait_io_event(CPUState *cpu)qemu_wait_io_event_common (cpu); } +static void cpu_throttle_thread (void *opq) +{ +CPUState *cpu = (CPUState *)opq; +long sleeptime_ms = (long )(cpu->throttle_ratio *CPU_THROTTLE_TIMESLICE ); + +/* Stop the timer if needed */ +if (cpu->throttle_timer_stop) { +timer_del (cpu->throttle_timer); +timer_free (cpu->throttle_timer); + cpu->throttle_timer =NULL ; +return ; + } + +qemu_mutex_unlock_iothread (); +g_usleep (sleeptime_ms *1000 );/* Convert ms to us for usleep call */ +qemu_mutex_lock_iothread (); + +timer_mod (cpu->throttle_timer,qemu_clock_get_ms (QEMU_CLOCK_REALTIME ) + +CPU_THROTTLE_TIMESLICE ); +} + +static void cpu_throttle_timer_pop (void *opq) +{ +CPUState *cpu = (CPUState *)opq; + +async_run_on_cpu (cpu, cpu_throttle_thread, cpu); +} + +void cpu_throttle_start (CPUState *cpu,float throttle_ratio) +{ +assert (throttle_ratio >0 ); + cpu->throttle_ratio = throttle_ratio; + +if (!cpu_throttle_active (cpu)) { + cpu->throttle_timer =timer_new_ms (QEMU_CLOCK_REALTIME , + cpu_throttle_timer_pop, cpu); +timer_mod (cpu->throttle_timer,qemu_clock_get_ms (QEMU_CLOCK_REALTIME ) + +CPU_THROTTLE_TIMESLICE ); + cpu->throttle_timer_stop = false; + } +} + +void cpu_throttle_stop (CPUState *cpu) +{ +assert (cpu_throttle_active (cpu)); + cpu->throttle_timer_stop = true; +} + +bool cpu_throttle_active (CPUState *cpu) +{ +return (cpu->throttle_timer !=NULL ); +} + +float cpu_throttle_get_ratio (CPUState *cpu) +{ +assert (cpu_throttle_active (cpu)); +return cpu->throttle_ratio; +} +static void *qemu_kvm_cpu_thread_fn (void *arg) {CPUState *cpu = arg;include/qom/cpu.h +46
-1@@ -310,6 +310,11 @@ struct CPUState {uint32_t can_do_io;int32_t exception_index;/* used by m68k TCG */ +/* vcpu throttling controls */ +QEMUTimer *throttle_timer; +bool throttle_timer_stop; +float throttle_ratio; +/* Note that this is accessed at the start of every TB via a negative offset from AREG0. Leave this field at the end so as to make the (absolute value) offset as small as possible. This reduces code @@ -553,6 +558,47 @@ CPUState *qemu_get_cpu(int index);*/ bool cpu_exists (int64_t id); +/** +* cpu_throttle_start: +* @cpu: The vcpu to throttle +* +* Throttles a vcpu by forcing it to sleep. The duration of the sleep is a +* ratio of sleep time to running time. A ratio of 1.0 corresponds to a 50% +* duty cycle (example: 10ms sleep for every 10ms awake). +* +* cpu_throttle_start can be called as needed to adjust the throttle ratio. +* Once the throttling starts, it will remain in effect until cpu_throttle_stop +* is called. +*/ +void cpu_throttle_start (CPUState *cpu,float throttle_ratio); + +/** +* cpu_throttle_stop: +* @cpu: The vcpu to stop throttling +* +* Stops the vcpu throttling started by cpu_throttle_start. +*/ +void cpu_throttle_stop (CPUState *cpu); + +/** +* cpu_throttle_active: +* @cpu: The vcpu to check +* +* Returns %true if this vcpu is currently being throttled, %false otherwise. +*/ +bool cpu_throttle_active (CPUState *cpu); + +/** +* cpu_throttle_get_ratio: +* @cpu: The vcpu whose throttle ratio to return. +* +* Returns the ratio being used to throttle this vcpu. See cpu_throttle_start +* for details. +* +* Returns The ratio being used to throttle this vcpu. +*/ +float cpu_throttle_get_ratio (CPUState *cpu); +#ifndef CONFIG_USER_ONLY typedef void (*CPUInterruptHandler )(CPUState *,int ); --
Quoted 3 lines
1.9.1
Thanks Jason, this patch would be quite interesting as it eliminates slight overhead from scheduler when cgroups are actively used for same task (~5% for per-vcpu cgroup layout simular to libvirt`s one for guest perf numa bench). Are you planning to add wakeup frequency throttler as well to same interface?
Re: [Qemu-devel] [PATCH 1/2] cpu: Provide vcpu throttling interface
Quoted 157 lines · Andrey Korolyov
Quoted 155 lines · Jason J. Herne
Provide a method to throttle guest cpu execution. CPUState is augmented with timeout controls and throttle start/stop functions. To throttle the guest cpu the caller simply has to call the throttle start function and provide a ratio of sleep time to normal execution time.
Signed-off-by Jason J. Herne <[email protected]>Reviewed-by Matthew Rosato <[email protected]>--- cpus.c | 62 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ include/qom/cpu.h | 46 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 108 insertions(+)cpus.c +62
-0@@ -64,6 +64,9 @@#endif /* CONFIG_LINUX */ +/* Number of ms between cpu throttle operations */ +#define CPU_THROTTLE_TIMESLICE 10 +static CPUState *next_cpu;int64_t max_delay;int64_t max_advance;@@ -919,6 +922,65 @@ static void qemu_kvm_wait_io_event(CPUState *cpu)qemu_wait_io_event_common (cpu); } +static void cpu_throttle_thread (void *opq) +{ +CPUState *cpu = (CPUState *)opq; +long sleeptime_ms = (long )(cpu->throttle_ratio *CPU_THROTTLE_TIMESLICE ); + +/* Stop the timer if needed */ +if (cpu->throttle_timer_stop) { +timer_del (cpu->throttle_timer); +timer_free (cpu->throttle_timer); + cpu->throttle_timer =NULL ; +return ; + } + +qemu_mutex_unlock_iothread (); +g_usleep (sleeptime_ms *1000 );/* Convert ms to us for usleep call */ +qemu_mutex_lock_iothread (); + +timer_mod (cpu->throttle_timer,qemu_clock_get_ms (QEMU_CLOCK_REALTIME ) + +CPU_THROTTLE_TIMESLICE ); +} + +static void cpu_throttle_timer_pop (void *opq) +{ +CPUState *cpu = (CPUState *)opq; + +async_run_on_cpu (cpu, cpu_throttle_thread, cpu); +} + +void cpu_throttle_start (CPUState *cpu,float throttle_ratio) +{ +assert (throttle_ratio >0 ); + cpu->throttle_ratio = throttle_ratio; + +if (!cpu_throttle_active (cpu)) { + cpu->throttle_timer =timer_new_ms (QEMU_CLOCK_REALTIME , + cpu_throttle_timer_pop, cpu); +timer_mod (cpu->throttle_timer,qemu_clock_get_ms (QEMU_CLOCK_REALTIME ) + +CPU_THROTTLE_TIMESLICE ); + cpu->throttle_timer_stop = false; + } +} + +void cpu_throttle_stop (CPUState *cpu) +{ +assert (cpu_throttle_active (cpu)); + cpu->throttle_timer_stop = true; +} + +bool cpu_throttle_active (CPUState *cpu) +{ +return (cpu->throttle_timer !=NULL ); +} + +float cpu_throttle_get_ratio (CPUState *cpu) +{ +assert (cpu_throttle_active (cpu)); +return cpu->throttle_ratio; +} +static void *qemu_kvm_cpu_thread_fn (void *arg) {CPUState *cpu = arg;include/qom/cpu.h +46
-0@@ -310,6 +310,11 @@ struct CPUState {uint32_t can_do_io;int32_t exception_index;/* used by m68k TCG */ +/* vcpu throttling controls */ +QEMUTimer *throttle_timer; +bool throttle_timer_stop; +float throttle_ratio; +/* Note that this is accessed at the start of every TB via a negative offset from AREG0. Leave this field at the end so as to make the (absolute value) offset as small as possible. This reduces code @@ -553,6 +558,47 @@ CPUState *qemu_get_cpu(int index);*/ bool cpu_exists (int64_t id); +/** +* cpu_throttle_start: +* @cpu: The vcpu to throttle +* +* Throttles a vcpu by forcing it to sleep. The duration of the sleep is a +* ratio of sleep time to running time. A ratio of 1.0 corresponds to a 50% +* duty cycle (example: 10ms sleep for every 10ms awake). +* +* cpu_throttle_start can be called as needed to adjust the throttle ratio. +* Once the throttling starts, it will remain in effect until cpu_throttle_stop +* is called. +*/ +void cpu_throttle_start (CPUState *cpu,float throttle_ratio); + +/** +* cpu_throttle_stop: +* @cpu: The vcpu to stop throttling +* +* Stops the vcpu throttling started by cpu_throttle_start. +*/ +void cpu_throttle_stop (CPUState *cpu); + +/** +* cpu_throttle_active: +* @cpu: The vcpu to check +* +* Returns %true if this vcpu is currently being throttled, %false otherwise. +*/ +bool cpu_throttle_active (CPUState *cpu); + +/** +* cpu_throttle_get_ratio: +* @cpu: The vcpu whose throttle ratio to return. +* +* Returns the ratio being used to throttle this vcpu. See cpu_throttle_start +* for details. +* +* Returns The ratio being used to throttle this vcpu. +*/ +float cpu_throttle_get_ratio (CPUState *cpu); +#ifndef CONFIG_USER_ONLY
Quoted 12 lines
Quoted 5 lines
include/qom/cpu.h +0
-1typedef void (*CPUInterruptHandler )(CPUState *,int ); --1.9.1
Thanks Jason, this patch would be quite interesting as it eliminates slight overhead from scheduler when cgroups are actively used for same task (~5% for per-vcpu cgroup layout simular to libvirt`s one for guest perf numa bench). Are you planning to add wakeup frequency throttler as well to same interface?
No, I was not planning on adding anything. I recognise that the controls this patch provides are not an ideal throttling mechanism. But it seems better than what we have today for auto-converge. That said, if people like the interface and the mechanism it certainly can be enhanced.
Signature · 1 line
-- Jason J. Herne ([email protected])
Re: [Qemu-devel] [PATCH 1/2] cpu: Provide vcpu throttling interface
In reply to Jason J. HerneQuoted 27 lines · Jason J. Herne
Provide a method to throttle guest cpu execution. CPUState is augmented with timeout controls and throttle start/stop functions. To throttle the guest cpu the caller simply has to call the throttle start function and provide a ratio of sleep time to normal execution time.
Signed-off-by Jason J. Herne <[email protected]>Reviewed-by Matthew Rosato <[email protected]>--- cpus.c | 62 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ include/qom/cpu.h | 46 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 108 insertions(+)cpus.c +3
-0@@ -64,6 +64,9 @@#endif /* CONFIG_LINUX */ +/* Number of ms between cpu throttle operations */ +#define CPU_THROTTLE_TIMESLICE 10 +static CPUState *next_cpu;int64_t max_delay;int64_t max_advance;
cpus.c static void qemu_kvm_wait_io_event(CPUState *cpu) · line 927
Quoted 6 lines
cpus.c +3
-0@@ -919,6 +922,65 @@ static void qemu_kvm_wait_io_event(CPUState *cpu)qemu_wait_io_event_common (cpu); } +static void cpu_throttle_thread (void *opq) +{ +CPUState *cpu = (CPUState *)opq;
Cast not neeeded. Same in rest of functions.
cpus.c static void qemu_kvm_wait_io_event(CPUState *cpu) · line 938
Quoted 11 lines
cpus.c +11
-0+long sleeptime_ms = (long )(cpu->throttle_ratio *CPU_THROTTLE_TIMESLICE ); + +/* Stop the timer if needed */ +if (cpu->throttle_timer_stop) { +timer_del (cpu->throttle_timer); +timer_free (cpu->throttle_timer); + cpu->throttle_timer =NULL ; +return ; + } + +qemu_mutex_unlock_iothread ();
We are creating a thread for each cpu, but just for waiting? That is exactly what the iothread does, no?
Quoted 53 lines
cpus.c +45
-0+g_usleep (sleeptime_ms *1000 );/* Convert ms to us for usleep call */ +qemu_mutex_lock_iothread (); + +timer_mod (cpu->throttle_timer,qemu_clock_get_ms (QEMU_CLOCK_REALTIME ) + +CPU_THROTTLE_TIMESLICE ); +} + +static void cpu_throttle_timer_pop (void *opq) +{ +CPUState *cpu = (CPUState *)opq; + +async_run_on_cpu (cpu, cpu_throttle_thread, cpu); +} + +void cpu_throttle_start (CPUState *cpu,float throttle_ratio) +{ +assert (throttle_ratio >0 ); + cpu->throttle_ratio = throttle_ratio; + +if (!cpu_throttle_active (cpu)) { + cpu->throttle_timer =timer_new_ms (QEMU_CLOCK_REALTIME , + cpu_throttle_timer_pop, cpu); +timer_mod (cpu->throttle_timer,qemu_clock_get_ms (QEMU_CLOCK_REALTIME ) + +CPU_THROTTLE_TIMESLICE ); + cpu->throttle_timer_stop = false; + } +} + +void cpu_throttle_stop (CPUState *cpu) +{ +assert (cpu_throttle_active (cpu)); + cpu->throttle_timer_stop = true; +} + +bool cpu_throttle_active (CPUState *cpu) +{ +return (cpu->throttle_timer !=NULL ); +} + +float cpu_throttle_get_ratio (CPUState *cpu) +{ +assert (cpu_throttle_active (cpu)); +return cpu->throttle_ratio; +} +static void *qemu_kvm_cpu_thread_fn (void *arg) {CPUState *cpu = arg;include/qom/cpu.h +0
-0
include/qom/cpu.h struct CPUState { · line 317
Quoted 8 lines
include/qom/cpu.h +5
-0@@ -310,6 +310,11 @@ struct CPUState {uint32_t can_do_io;int32_t exception_index;/* used by m68k TCG */ +/* vcpu throttling controls */ +QEMUTimer *throttle_timer; +bool throttle_timer_stop; +float throttle_ratio; +
I think that if we go this way, we can have a single throotling thread that do a for loop for each vcpu. As a bonus, we got a single timer, and single bool and a single throotle_ratio (i.e. it don't need to be on the cpu struct). Being a global will don't matter because we are requiring the iothread anyways.
Quoted 51 lines
include/qom/cpu.h +41
-0/* Note that this is accessed at the start of every TB via a negative offset from AREG0. Leave this field at the end so as to make the (absolute value) offset as small as possible. This reduces code @@ -553,6 +558,47 @@ CPUState *qemu_get_cpu(int index);*/ bool cpu_exists (int64_t id); +/** +* cpu_throttle_start: +* @cpu: The vcpu to throttle +* +* Throttles a vcpu by forcing it to sleep. The duration of the sleep is a +* ratio of sleep time to running time. A ratio of 1.0 corresponds to a 50% +* duty cycle (example: 10ms sleep for every 10ms awake). +* +* cpu_throttle_start can be called as needed to adjust the throttle ratio. +* Once the throttling starts, it will remain in effect until cpu_throttle_stop +* is called. +*/ +void cpu_throttle_start (CPUState *cpu,float throttle_ratio); + +/** +* cpu_throttle_stop: +* @cpu: The vcpu to stop throttling +* +* Stops the vcpu throttling started by cpu_throttle_start. +*/ +void cpu_throttle_stop (CPUState *cpu); + +/** +* cpu_throttle_active: +* @cpu: The vcpu to check +* +* Returns %true if this vcpu is currently being throttled, %false otherwise. +*/ +bool cpu_throttle_active (CPUState *cpu); + +/** +* cpu_throttle_get_ratio: +* @cpu: The vcpu whose throttle ratio to return. +* +* Returns the ratio being used to throttle this vcpu. See cpu_throttle_start +* for details. +* +* Returns The ratio being used to throttle this vcpu. +*/ +float cpu_throttle_get_ratio (CPUState *cpu); +#ifndef CONFIG_USER_ONLY typedef void (*CPUInterruptHandler )(CPUState *,int );
Re: [Qemu-devel] [PATCH 1/2] cpu: Provide vcpu throttling interface
Quoted 8 lines · Juan Quintela
Quoted 8 lines
include/qom/cpu.h +0
-0Quoted 7 lines
index 39f0f19..9d16e6a 100644
include/qom/cpu.h +0
-0@@ -310,6 +310,11 @@ struct CPUState {uint32_t can_do_io;int32_t exception_index;/* used by m68k TCG */
Quoted 11 lines
Quoted 5 lines
include/qom/cpu.h struct CPUState { · line 317
Quoted 5 lines
include/qom/cpu.h +5
-0+/* vcpu throttling controls */ +QEMUTimer *throttle_timer; +bool throttle_timer_stop; +float throttle_ratio; +I think that if we go this way, we can have a single throotling thread that do a for loop for each vcpu. As a bonus, we got a single timer, and single bool and a single
throotle_ratio(i.e. it don't need to be on the cpu struct). Being a global will don't matter because we are requiring the iothread anyways.
Juan,
I like this idea. I'll work up another patch set :).
Signature · 1 line
-- Jason J. Herne ([email protected])
PATCH 2/2 migration: Dynamic cpu throttling for auto-converge
In reply to Jason J. HerneRemove traditional auto-converge static 30ms throttling code and replace it with a dynamic throttling algorithm.
Additionally, be more aggressive when deciding when to start throttling. Previously we waited until four unproductive memory passes. Now we begin throttling after only two unproductive memory passes. Four seemed quite arbitrary and only waiting for two passes allows us to complete the migration faster.
--- arch_init.c | 95 +++++++++++++++++---------------------------------- migration/migration.c | 9 +++++ 2 files changed, 41 insertions(+), 63 deletions(-)
arch_init.c +32 -63
@@ -111,9 +111,7 @@ int graphic_depth = 32;#endif const uint32_t arch_type =QEMU_ARCH ; -static bool mig_throttle_on;static int dirty_rate_high_cnt; -static void check_guest_throttling (void );static uint64_t bitmap_sync_count;
@@ -487,6 +485,31 @@ static size_t save_page_header(QEMUFile *f, RAMBlock *block, ram_addr_t offset)return size; } +/* Reduce amount of guest cpu execution to hopefully slow down memory writes. +* If guest dirty memory rate is reduced below the rate at which we can +* transfer pages to the destination then we should be able to complete +* migration. Some workloads dirty memory way too fast and will not effectively +* converge, even with auto-converge. For these workloads we will continue to +* increase throttling until the guest is paused long enough to complete the +* migration. This essentially becomes a non-live migration. +*/ +static void mig_throttle_guest_down (void ) +{ +CPUState *cpu; + +CPU_FOREACH (cpu) { +/* We have not started throttling yet. Lets start it.*/ +if (!cpu_throttle_active (cpu)) { +cpu_throttle_start (cpu,0.2 ); + } + +/* Throttling is already in place. Just increase the throttling rate */ +else { +cpu_throttle_start (cpu,cpu_throttle_get_ratio (cpu) *2 ); + } + } +} +/* Update the xbzrle cache to reflect a page that's been sent as all 0. * The important thing is that a stale (not-yet-0'd) page be replaced * by the new data.
@@ -714,21 +737,21 @@ static void migration_bitmap_sync(void)/* The following detection logic can be refined later. For now: Check to see if the dirtied bytes is 50% more than the approx. amount of bytes that just got transferred since the last time we -were in this routine. If that happens >N times (for now N==4) -we turn on the throttle down logic */ +were in this routine. If that happens twice, start or increase +throttling */ bytes_xfer_now =ram_bytes_transferred (); +if (s->dirty_pages_rate && (num_dirty_pages_period *TARGET_PAGE_SIZE > (bytes_xfer_now - bytes_xfer_prev)/2 ) && - (dirty_rate_high_cnt++ >4 )) { + (dirty_rate_high_cnt++ >=2 )) {trace_migration_throttle (); - mig_throttle_on = true; dirty_rate_high_cnt =0 ; +mig_throttle_guest_down (); } bytes_xfer_prev = bytes_xfer_now; - }else { - mig_throttle_on = false; } +if (migrate_use_xbzrle ()) {if (iterations_prev != acct_info.iterations) { acct_info.xbzrle_cache_miss_rate =
@@ -1197,7 +1220,6 @@ static int ram_save_setup(QEMUFile *f, void *opaque)RAMBlock *block;int64_t ram_bitmap_pages;/* Size of bitmap in pages, including gaps */ - mig_throttle_on = false; dirty_rate_high_cnt =0 ; bitmap_sync_count =0 ;migration_bitmap_sync_init ();
@@ -1301,12 +1323,7 @@ static int ram_save_iterate(QEMUFile *f, void *opaque) } pages_sent += pages; acct_info.iterations++; -check_guest_throttling (); -/* we want to check in the 1st loop, just in case it was the 1st time -and we had to sync the dirty bitmap. -qemu_get_clock_ns() is a bit expensive, so we only check each some -iterations -*/ +if ((i &63 ) ==0 ) {uint64_t t1 = (qemu_clock_get_ns (QEMU_CLOCK_REALTIME ) - t0) /1000000 ;if (t1 >MAX_WAIT ) {
@@ -1913,51 +1930,3 @@ TargetInfo *qmp_query_target(Error **errp)return info; } -/* Stub function that's gets run on the vcpu when its brought out of the -VM to run inside qemu via async_run_on_cpu()*/ -static void mig_sleep_cpu (void *opq) -{ -qemu_mutex_unlock_iothread (); -g_usleep (30 *1000 ); -qemu_mutex_lock_iothread (); -} - -/* To reduce the dirty rate explicitly disallow the VCPUs from spending -much time in the VM. The migration thread will try to catchup. -Workload will experience a performance drop. -*/ -static void mig_throttle_guest_down (void ) -{ -CPUState *cpu; - -qemu_mutex_lock_iothread (); -CPU_FOREACH (cpu) { -async_run_on_cpu (cpu, mig_sleep_cpu,NULL ); - } -qemu_mutex_unlock_iothread (); -} - -static void check_guest_throttling (void ) -{ -static int64_t t0; -int64_t t1; - -if (!mig_throttle_on) { -return ; - } - -if (!t0) { - t0 =qemu_clock_get_ns (QEMU_CLOCK_REALTIME ); -return ; - } - - t1 =qemu_clock_get_ns (QEMU_CLOCK_REALTIME ); - -/* If it has been more than 40 ms since the last time the guest -* was throttled then do it again. -*/ -if (40 < (t1-t0)/1000000 ) { -mig_throttle_guest_down (); - t0 = t1; - } -}
migration/migration.c +9 -0
@@ -25,6 +25,7 @@#include "qemu/thread.h" #include "qmp-commands.h" #include "trace.h" +#include "qom/cpu.h" #define MAX_THROTTLE (32 << 20)/* Migration speed throttling */
@@ -731,6 +732,7 @@ int64_t migrate_xbzrle_cache_size(void)static void *migration_thread (void *opaque) {MigrationState *s = opaque; +CPUState *cpu;int64_t initial_time =qemu_clock_get_ms (QEMU_CLOCK_REALTIME );int64_t setup_start =qemu_clock_get_ms (QEMU_CLOCK_HOST );int64_t initial_bytes =0 ;
@@ -814,6 +816,13 @@ static void *migration_thread(void *opaque) } } +/* If we enabled cpu throttling for auto-converge, turn it off. */ +CPU_FOREACH (cpu) { +if (cpu_throttle_active (cpu)) { +cpu_throttle_stop (cpu); + } + } +qemu_mutex_lock_iothread ();if (s->state ==MIGRATION_STATUS_COMPLETED ) {int64_t end_time =qemu_clock_get_ms (QEMU_CLOCK_REALTIME );
Signature · 1 line
1.9.1
Quoted 46 lines · * Jason J. Herne ([email protected]) wrote:
Remove traditional auto-converge static 30ms throttling code and replace it with a dynamic throttling algorithm.
Additionally, be more aggressive when deciding when to start throttling. Previously we waited until four unproductive memory passes. Now we begin throttling after only two unproductive memory passes. Four seemed quite arbitrary and only waiting for two passes allows us to complete the migration faster.
Signed-off-by Jason J. Herne <[email protected]>Reviewed-by Matthew Rosato <[email protected]>--- arch_init.c | 95 +++++++++++++++++---------------------------------- migration/migration.c | 9 +++++ 2 files changed, 41 insertions(+), 63 deletions(-)arch_init.c +12
-2@@ -111,9 +111,7 @@ int graphic_depth = 32;#endif const uint32_t arch_type =QEMU_ARCH ; -static bool mig_throttle_on;static int dirty_rate_high_cnt; -static void check_guest_throttling (void );static uint64_t bitmap_sync_count;@@ -487,6 +485,31 @@ static size_t save_page_header(QEMUFile *f, RAMBlock *block, ram_addr_t offset)return size; } +/* Reduce amount of guest cpu execution to hopefully slow down memory writes. +* If guest dirty memory rate is reduced below the rate at which we can +* transfer pages to the destination then we should be able to complete +* migration. Some workloads dirty memory way too fast and will not effectively +* converge, even with auto-converge. For these workloads we will continue to +* increase throttling until the guest is paused long enough to complete the +* migration. This essentially becomes a non-live migration. +*/ +static void mig_throttle_guest_down (void ) +{ +CPUState *cpu; +
arch_init.c static size_t save_page_header(QEMUFile *f, RAMBlock *block, ram_addr_t offset) · line 509
Quoted 10 lines
arch_init.c +10
-0+CPU_FOREACH (cpu) { +/* We have not started throttling yet. Lets start it.*/ +if (!cpu_throttle_active (cpu)) { +cpu_throttle_start (cpu,0.2 ); + } + +/* Throttling is already in place. Just increase the throttling rate */ +else { +cpu_throttle_start (cpu,cpu_throttle_get_ratio (cpu) *2 ); + }
Now that migration has migrate_parameters, it would be best to replace the magic numbers (the 0.2, the *2 - anything else?) by parameters that can change the starting throttling and increase rate. It would probably also be good to make the current throttling rate visible in info somewhere; maybe info migrate?
Quoted 98 lines
arch_init.c +10
-51+ } +} +/* Update the xbzrle cache to reflect a page that's been sent as all 0. * The important thing is that a stale (not-yet-0'd) page be replaced * by the new data. @@ -714,21 +737,21 @@ static void migration_bitmap_sync(void)/* The following detection logic can be refined later. For now: Check to see if the dirtied bytes is 50% more than the approx. amount of bytes that just got transferred since the last time we -were in this routine. If that happens >N times (for now N==4) -we turn on the throttle down logic */ +were in this routine. If that happens twice, start or increase +throttling */ bytes_xfer_now =ram_bytes_transferred (); +if (s->dirty_pages_rate && (num_dirty_pages_period *TARGET_PAGE_SIZE > (bytes_xfer_now - bytes_xfer_prev)/2 ) && - (dirty_rate_high_cnt++ >4 )) { + (dirty_rate_high_cnt++ >=2 )) {trace_migration_throttle (); - mig_throttle_on = true; dirty_rate_high_cnt =0 ; +mig_throttle_guest_down (); } bytes_xfer_prev = bytes_xfer_now; - }else { - mig_throttle_on = false; } +if (migrate_use_xbzrle ()) {if (iterations_prev != acct_info.iterations) { acct_info.xbzrle_cache_miss_rate =@@ -1197,7 +1220,6 @@ static int ram_save_setup(QEMUFile *f, void *opaque)RAMBlock *block;int64_t ram_bitmap_pages;/* Size of bitmap in pages, including gaps */ - mig_throttle_on = false; dirty_rate_high_cnt =0 ; bitmap_sync_count =0 ;migration_bitmap_sync_init ();@@ -1301,12 +1323,7 @@ static int ram_save_iterate(QEMUFile *f, void *opaque) } pages_sent += pages; acct_info.iterations++; -check_guest_throttling (); -/* we want to check in the 1st loop, just in case it was the 1st time -and we had to sync the dirty bitmap. -qemu_get_clock_ns() is a bit expensive, so we only check each some -iterations -*/ +if ((i &63 ) ==0 ) {uint64_t t1 = (qemu_clock_get_ns (QEMU_CLOCK_REALTIME ) - t0) /1000000 ;if (t1 >MAX_WAIT ) {@@ -1913,51 +1930,3 @@ TargetInfo *qmp_query_target(Error **errp)return info; } -/* Stub function that's gets run on the vcpu when its brought out of the -VM to run inside qemu via async_run_on_cpu()*/ -static void mig_sleep_cpu (void *opq) -{ -qemu_mutex_unlock_iothread (); -g_usleep (30 *1000 ); -qemu_mutex_lock_iothread (); -} - -/* To reduce the dirty rate explicitly disallow the VCPUs from spending -much time in the VM. The migration thread will try to catchup. -Workload will experience a performance drop. -*/ -static void mig_throttle_guest_down (void ) -{ -CPUState *cpu; - -qemu_mutex_lock_iothread (); -CPU_FOREACH (cpu) { -async_run_on_cpu (cpu, mig_sleep_cpu,NULL ); - } -qemu_mutex_unlock_iothread (); -} - -static void check_guest_throttling (void ) -{ -static int64_t t0; -int64_t t1; - -if (!mig_throttle_on) { -return ; - } - -if (!t0) { - t0 =qemu_clock_get_ns (QEMU_CLOCK_REALTIME ); -return ; - } -
arch_init.c TargetInfo *qmp_query_target(Error **errp) · line 1963
Quoted 10 lines
arch_init.c +0
-10- t1 =qemu_clock_get_ns (QEMU_CLOCK_REALTIME ); - -/* If it has been more than 40 ms since the last time the guest -* was throttled then do it again. -*/ -if (40 < (t1-t0)/1000000 ) { -mig_throttle_guest_down (); - t0 = t1; - } -}
Lots of deleted code; that's got to be good.
Quoted 37 lines
migration/migration.c +9
-0@@ -25,6 +25,7 @@#include "qemu/thread.h" #include "qmp-commands.h" #include "trace.h" +#include "qom/cpu.h" #define MAX_THROTTLE (32 << 20)/* Migration speed throttling */ @@ -731,6 +732,7 @@ int64_t migrate_xbzrle_cache_size(void)static void *migration_thread (void *opaque) {MigrationState *s = opaque; +CPUState *cpu;int64_t initial_time =qemu_clock_get_ms (QEMU_CLOCK_REALTIME );int64_t setup_start =qemu_clock_get_ms (QEMU_CLOCK_HOST );int64_t initial_bytes =0 ;@@ -814,6 +816,13 @@ static void *migration_thread(void *opaque) } } +/* If we enabled cpu throttling for auto-converge, turn it off. */ +CPU_FOREACH (cpu) { +if (cpu_throttle_active (cpu)) { +cpu_throttle_stop (cpu); + } + } +qemu_mutex_lock_iothread ();if (s->state ==MIGRATION_STATUS_COMPLETED ) {int64_t end_time =qemu_clock_get_ms (QEMU_CLOCK_REALTIME );Signature · 1 line
1.9.1
Dave
--
Dr. David Alan Gilbert / [email protected] / Manchester, UK
Quoted 55 lines · Dr. David Alan Gilbert
Quoted 54 lines · * Jason J. Herne ([email protected]) wrote:
Remove traditional auto-converge static 30ms throttling code and replace it with a dynamic throttling algorithm.
Additionally, be more aggressive when deciding when to start throttling. Previously we waited until four unproductive memory passes. Now we begin throttling after only two unproductive memory passes. Four seemed quite arbitrary and only waiting for two passes allows us to complete the migration faster.
Signed-off-by Jason J. Herne <[email protected]>Reviewed-by Matthew Rosato <[email protected]>--- arch_init.c | 95 +++++++++++++++++---------------------------------- migration/migration.c | 9 +++++ 2 files changed, 41 insertions(+), 63 deletions(-)arch_init.c +20
-2@@ -111,9 +111,7 @@ int graphic_depth = 32;#endif const uint32_t arch_type =QEMU_ARCH ; -static bool mig_throttle_on;static int dirty_rate_high_cnt; -static void check_guest_throttling (void );static uint64_t bitmap_sync_count;@@ -487,6 +485,31 @@ static size_t save_page_header(QEMUFile *f, RAMBlock *block, ram_addr_t offset)return size; } +/* Reduce amount of guest cpu execution to hopefully slow down memory writes. +* If guest dirty memory rate is reduced below the rate at which we can +* transfer pages to the destination then we should be able to complete +* migration. Some workloads dirty memory way too fast and will not effectively +* converge, even with auto-converge. For these workloads we will continue to +* increase throttling until the guest is paused long enough to complete the +* migration. This essentially becomes a non-live migration. +*/ +static void mig_throttle_guest_down (void ) +{ +CPUState *cpu; + +CPU_FOREACH (cpu) { +/* We have not started throttling yet. Lets start it.*/ +if (!cpu_throttle_active (cpu)) { +cpu_throttle_start (cpu,0.2 ); + } + +/* Throttling is already in place. Just increase the throttling rate */ +else {
Quoted 9 lines
arch_init.c static size_t save_page_header(QEMUFile *f, RAMBlock *block, ram_addr_t offset) · line 509
Quoted 2 lines
arch_init.c +2
-0+cpu_throttle_start (cpu,cpu_throttle_get_ratio (cpu) *2 ); + }Now that migration has
migrate_parameters, it would be best to replace the magic numbers (the 0.2, the *2 - anything else?) by parameters that can change the starting throttling and increase rate. It would probably also be good to make the current throttling rate visible in info somewhere; maybe info migrate?
I did consider all of this. However, I don't think that the controls this patch provides are an ideal throttling mechanism. I suspect someone with vcpu/scheduling experience could whip up something more user friendly and cleaner. I merely propose this because it seems better than what we have today for auto-converge.
Also, I'm not sure how useful the information really is to the user. The fact that it is a ratio instead of a percentage might be confusing. Also, I suspect it is not truly very accurate. Again, I was going for "make it better", not "make it perfect".
Lastly, if we define this external interface we are kind of stuck with it, yes? In this regard we should be sure that this is how we want cpu throttling to work. Alternatively, I propose to accept this patch set as-is and then work on a real vcpu Throttling mechanism that can be used for auto-converge as well as a user controllable guest throttling/limiting mechanism. Once that is in place we can migrate (no pun intended) the auto-converge code to the new way and remove this stuff.
With all of that said, I'm willing to provide the requested controls if we really feel the pros outweigh the cons. Thanks for your review :).
...
Signature · 1 line
-- Jason J. Herne ([email protected])
Quoted 74 lines · * Jason J. Herne ([email protected]) wrote:
Quoted 55 lines · Dr. David Alan Gilbert
Quoted 54 lines · * Jason J. Herne ([email protected]) wrote:
Remove traditional auto-converge static 30ms throttling code and replace it with a dynamic throttling algorithm.
Additionally, be more aggressive when deciding when to start throttling. Previously we waited until four unproductive memory passes. Now we begin throttling after only two unproductive memory passes. Four seemed quite arbitrary and only waiting for two passes allows us to complete the migration faster.
Signed-off-by Jason J. Herne <[email protected]>Reviewed-by Matthew Rosato <[email protected]>--- arch_init.c | 95 +++++++++++++++++---------------------------------- migration/migration.c | 9 +++++ 2 files changed, 41 insertions(+), 63 deletions(-)arch_init.c +20
-2@@ -111,9 +111,7 @@ int graphic_depth = 32;#endif const uint32_t arch_type =QEMU_ARCH ; -static bool mig_throttle_on;static int dirty_rate_high_cnt; -static void check_guest_throttling (void );static uint64_t bitmap_sync_count;@@ -487,6 +485,31 @@ static size_t save_page_header(QEMUFile *f, RAMBlock *block, ram_addr_t offset)return size; } +/* Reduce amount of guest cpu execution to hopefully slow down memory writes. +* If guest dirty memory rate is reduced below the rate at which we can +* transfer pages to the destination then we should be able to complete +* migration. Some workloads dirty memory way too fast and will not effectively +* converge, even with auto-converge. For these workloads we will continue to +* increase throttling until the guest is paused long enough to complete the +* migration. This essentially becomes a non-live migration. +*/ +static void mig_throttle_guest_down (void ) +{ +CPUState *cpu; + +CPU_FOREACH (cpu) { +/* We have not started throttling yet. Lets start it.*/ +if (!cpu_throttle_active (cpu)) { +cpu_throttle_start (cpu,0.2 ); + } + +/* Throttling is already in place. Just increase the throttling rate */ +else {Quoted 9 lines
arch_init.c static size_t save_page_header(QEMUFile *f, RAMBlock *block, ram_addr_t offset) · line 509
Quoted 2 lines
arch_init.c +2
-0+cpu_throttle_start (cpu,cpu_throttle_get_ratio (cpu) *2 ); + }Now that migration has
migrate_parameters, it would be best to replace the magic numbers (the 0.2, the *2 - anything else?) by parameters that can change the starting throttling and increase rate. It would probably also be good to make the current throttling rate visible in info somewhere; maybe info migrate?I did consider all of this. However, I don't think that the controls this patch provides are an ideal throttling mechanism. I suspect someone with
vcpu/scheduling experience could whip up something more user friendly and cleaner.
I merely propose this because it seems better than what we have today for auto-converge.
Quoted 8 lines
Also, I'm not sure how useful the information really is to the user. The fact that it is a ratio instead of a percentage might be confusing. Also, I suspect it is not
truly very accurate. Again, I was going for "make it better", not "make it perfect".Lastly, if we define this external interface we are kind of stuck with it, yes?
Well, one thing you can do is add a parameter with a name starting with x- which means it's not a fixed interface (so things like libvirt wont use it). And the reason I was interested in seeing the information was otherwise we don't really have any way of knowing how well the code is working; is it already throttling down more and more?
Quoted 7 lines
In
this regard we should be sure that this is how we want cpu throttling to work. Alternatively, I propose to accept this patch set as-is and then work on a real vcpu Throttling mechanism that can be used for auto-converge as well as a user controllable guest throttling/limiting mechanism. Once that is in place we can migrate (no pun intended) the auto-converge code to the new way and remove this stuff.
Yes, it's probably still better than what we already have.
Dave
Quoted 10 lines
With all of that said, I'm willing to provide the requested controls if we really
feel the pros outweigh the cons. Thanks for your review :)....
Signature · 1 line
-- Jason J. Herne ([email protected])
--
Dr. David Alan Gilbert / [email protected] / Manchester, UK
Quoted 81 lines · Dr. David Alan Gilbert
Quoted 80 lines · * Jason J. Herne ([email protected]) wrote:
Quoted 55 lines · Dr. David Alan Gilbert
Quoted 54 lines · * Jason J. Herne ([email protected]) wrote:
Remove traditional auto-converge static 30ms throttling code and replace it with a dynamic throttling algorithm.
Additionally, be more aggressive when deciding when to start throttling. Previously we waited until four unproductive memory passes. Now we begin throttling after only two unproductive memory passes. Four seemed quite arbitrary and only waiting for two passes allows us to complete the migration faster.
Signed-off-by Jason J. Herne <[email protected]>Reviewed-by Matthew Rosato <[email protected]>--- arch_init.c | 95 +++++++++++++++++---------------------------------- migration/migration.c | 9 +++++ 2 files changed, 41 insertions(+), 63 deletions(-)arch_init.c +20
-2@@ -111,9 +111,7 @@ int graphic_depth = 32;#endif const uint32_t arch_type =QEMU_ARCH ; -static bool mig_throttle_on;static int dirty_rate_high_cnt; -static void check_guest_throttling (void );static uint64_t bitmap_sync_count;@@ -487,6 +485,31 @@ static size_t save_page_header(QEMUFile *f, RAMBlock *block, ram_addr_t offset)return size; } +/* Reduce amount of guest cpu execution to hopefully slow down memory writes. +* If guest dirty memory rate is reduced below the rate at which we can +* transfer pages to the destination then we should be able to complete +* migration. Some workloads dirty memory way too fast and will not effectively +* converge, even with auto-converge. For these workloads we will continue to +* increase throttling until the guest is paused long enough to complete the +* migration. This essentially becomes a non-live migration. +*/ +static void mig_throttle_guest_down (void ) +{ +CPUState *cpu; + +CPU_FOREACH (cpu) { +/* We have not started throttling yet. Lets start it.*/ +if (!cpu_throttle_active (cpu)) { +cpu_throttle_start (cpu,0.2 ); + } + +/* Throttling is already in place. Just increase the throttling rate */ +else {Quoted 9 lines
arch_init.c static size_t save_page_header(QEMUFile *f, RAMBlock *block, ram_addr_t offset) · line 509
Quoted 2 lines
arch_init.c +2
-0+cpu_throttle_start (cpu,cpu_throttle_get_ratio (cpu) *2 ); + }Now that migration has
migrate_parameters, it would be best to replace the magic numbers (the 0.2, the *2 - anything else?) by parameters that can change the starting throttling and increase rate. It would probably also be good to make the current throttling rate visible in info somewhere; maybe info migrate?I did consider all of this. However, I don't think that the controls this patch provides are an ideal throttling mechanism. I suspect someone with
vcpu/scheduling experience could whip up something more user friendly and cleaner.
I merely propose this because it seems better than what we have today for auto-converge.Also, I'm not sure how useful the information really is to the user. The fact that it is a ratio instead of a percentage might be confusing. Also, I suspect it is not
truly very accurate. Again, I was going for "make it better", not "make it perfect".
Quoted 9 lines
Quoted 2 lines
Lastly, if we define this external interface we are kind of stuck with it, yes?
Well, one thing you can do is add a parameter with a name starting with x- which means it's not a fixed interface (so things like libvirt wont use it). And the reason I was interested in seeing the information was otherwise we don't really have any way of knowing how well the code is working; is it already throttling down more and more?
Fair point. Can we add a qmp/hmp command like "info x-cpu-throttle"? Or a new line in "info migrate" output, "x-throttle-ration: 1.0" perhaps? Would this mess up libvirt's parsing of the hmp/qmp data?
Signature · 1 line
-- Jason J. Herne ([email protected])
Quoted 92 lines · * Jason J. Herne ([email protected]) wrote:
Quoted 81 lines · Dr. David Alan Gilbert
Quoted 80 lines · * Jason J. Herne ([email protected]) wrote:
Quoted 55 lines · Dr. David Alan Gilbert
Quoted 54 lines · * Jason J. Herne ([email protected]) wrote:
Remove traditional auto-converge static 30ms throttling code and replace it with a dynamic throttling algorithm.
Additionally, be more aggressive when deciding when to start throttling. Previously we waited until four unproductive memory passes. Now we begin throttling after only two unproductive memory passes. Four seemed quite arbitrary and only waiting for two passes allows us to complete the migration faster.
Signed-off-by Jason J. Herne <[email protected]>Reviewed-by Matthew Rosato <[email protected]>--- arch_init.c | 95 +++++++++++++++++---------------------------------- migration/migration.c | 9 +++++ 2 files changed, 41 insertions(+), 63 deletions(-)arch_init.c +20
-2@@ -111,9 +111,7 @@ int graphic_depth = 32;#endif const uint32_t arch_type =QEMU_ARCH ; -static bool mig_throttle_on;static int dirty_rate_high_cnt; -static void check_guest_throttling (void );static uint64_t bitmap_sync_count;@@ -487,6 +485,31 @@ static size_t save_page_header(QEMUFile *f, RAMBlock *block, ram_addr_t offset)return size; } +/* Reduce amount of guest cpu execution to hopefully slow down memory writes. +* If guest dirty memory rate is reduced below the rate at which we can +* transfer pages to the destination then we should be able to complete +* migration. Some workloads dirty memory way too fast and will not effectively +* converge, even with auto-converge. For these workloads we will continue to +* increase throttling until the guest is paused long enough to complete the +* migration. This essentially becomes a non-live migration. +*/ +static void mig_throttle_guest_down (void ) +{ +CPUState *cpu; + +CPU_FOREACH (cpu) { +/* We have not started throttling yet. Lets start it.*/ +if (!cpu_throttle_active (cpu)) { +cpu_throttle_start (cpu,0.2 ); + } + +/* Throttling is already in place. Just increase the throttling rate */ +else {Quoted 9 lines
arch_init.c static size_t save_page_header(QEMUFile *f, RAMBlock *block, ram_addr_t offset) · line 509
Quoted 2 lines
arch_init.c +2
-0+cpu_throttle_start (cpu,cpu_throttle_get_ratio (cpu) *2 ); + }Now that migration has
migrate_parameters, it would be best to replace the magic numbers (the 0.2, the *2 - anything else?) by parameters that can change the starting throttling and increase rate. It would probably also be good to make the current throttling rate visible in info somewhere; maybe info migrate?I did consider all of this. However, I don't think that the controls this patch provides are an ideal throttling mechanism. I suspect someone with
vcpu/scheduling experience could whip up something more user friendly and cleaner.
I merely propose this because it seems better than what we have today for auto-converge.Also, I'm not sure how useful the information really is to the user. The fact that it is a ratio instead of a percentage might be confusing. Also, I suspect it is not
truly very accurate. Again, I was going for "make it better", not "make it perfect".Quoted 9 lines
Quoted 2 lines
Lastly, if we define this external interface we are kind of stuck with it, yes?
Well, one thing you can do is add a parameter with a name starting with x- which means it's not a fixed interface (so things like libvirt wont use it). And the reason I was interested in seeing the information was otherwise we don't really have any way of knowing how well the code is working; is it already throttling down more and more?
Quoted 3 lines
Fair point. Can we add a qmp/hmp command like "info x-cpu-throttle"? Or a new line in "info migrate" output, "x-throttle-ration: 1.0" perhaps? Would this mess up libvirt's parsing of the hmp/qmp data?
A friendly libvirt person said that it will ignore extra data (and if it doesn't it's a bug).
Dave
Quoted 3 lines
Signature · 1 line
-- Jason J. Herne ([email protected])
--
Dr. David Alan Gilbert / [email protected] / Manchester, UK
Quoted 10 lines · Jason J. Herne
Quoted 9 lines
Well, one thing you can do is add a parameter with a name starting with x-
which means it's not a fixed interface (so things like libvirt wont use it).
And the reason I was interested in seeing the information was otherwise we don't really have any way of knowing how well the code is working; is it already throttling down more and more?
Quoted 3 lines
Fair point. Can we add a qmp/hmp command like "info x-cpu-throttle"? Or a new line in "info migrate" output, "x-throttle-ration: 1.0" perhaps? Would this mess up libvirt's parsing of the hmp/qmp data?
Libvirt doesn't parse HMP data, and when parsing QMP data it gracefully ignores any fields it doesn't recognize (especially fields beginning with 'x-') (and if not, that's a bug to be fixed in libvirt). The QMP protocol even documents that clients MUST be prepared for new keys to appear in output. So this proposal should not cause any grief.
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
Quoted 92 lines · Jason J. Herne
Quoted 81 lines · Dr. David Alan Gilbert
Quoted 80 lines · * Jason J. Herne ([email protected]) wrote:
Quoted 55 lines · Dr. David Alan Gilbert
Quoted 54 lines · * Jason J. Herne ([email protected]) wrote:
Remove traditional auto-converge static 30ms throttling code and replace it with a dynamic throttling algorithm.
Additionally, be more aggressive when deciding when to start throttling. Previously we waited until four unproductive memory passes. Now we begin throttling after only two unproductive memory passes. Four seemed quite arbitrary and only waiting for two passes allows us to complete the migration faster.
Signed-off-by Jason J. Herne <[email protected]>Reviewed-by Matthew Rosato <[email protected]>--- arch_init.c | 95 +++++++++++++++++---------------------------------- migration/migration.c | 9 +++++ 2 files changed, 41 insertions(+), 63 deletions(-)arch_init.c +20
-2@@ -111,9 +111,7 @@ int graphic_depth = 32;#endif const uint32_t arch_type =QEMU_ARCH ; -static bool mig_throttle_on;static int dirty_rate_high_cnt; -static void check_guest_throttling (void );static uint64_t bitmap_sync_count;@@ -487,6 +485,31 @@ static size_t save_page_header(QEMUFile *f, RAMBlock *block, ram_addr_t offset)return size; } +/* Reduce amount of guest cpu execution to hopefully slow down memory writes. +* If guest dirty memory rate is reduced below the rate at which we can +* transfer pages to the destination then we should be able to complete +* migration. Some workloads dirty memory way too fast and will not effectively +* converge, even with auto-converge. For these workloads we will continue to +* increase throttling until the guest is paused long enough to complete the +* migration. This essentially becomes a non-live migration. +*/ +static void mig_throttle_guest_down (void ) +{ +CPUState *cpu; + +CPU_FOREACH (cpu) { +/* We have not started throttling yet. Lets start it.*/ +if (!cpu_throttle_active (cpu)) { +cpu_throttle_start (cpu,0.2 ); + } + +/* Throttling is already in place. Just increase the throttling rate */ +else {Quoted 9 lines
arch_init.c static size_t save_page_header(QEMUFile *f, RAMBlock *block, ram_addr_t offset) · line 509
Quoted 2 lines
arch_init.c +2
-0+cpu_throttle_start (cpu,cpu_throttle_get_ratio (cpu) *2 ); + }Now that migration has
migrate_parameters, it would be best to replace the magic numbers (the 0.2, the *2 - anything else?) by parameters that can change the starting throttling and increase rate. It would probably also be good to make the current throttling rate visible in info somewhere; maybe info migrate?I did consider all of this. However, I don't think that the controls this patch provides are an ideal throttling mechanism. I suspect someone with
vcpu/scheduling experience could whip up something more user friendly and cleaner.
I merely propose this because it seems better than what we have today for auto-converge.Also, I'm not sure how useful the information really is to the user. The fact that it is a ratio instead of a percentage might be confusing. Also, I suspect it is not
truly very accurate. Again, I was going for "make it better", not "make it perfect".Quoted 9 lines
Quoted 2 lines
Lastly, if we define this external interface we are kind of stuck with it, yes?
Well, one thing you can do is add a parameter with a name starting with x- which means it's not a fixed interface (so things like libvirt wont use it). And the reason I was interested in seeing the information was otherwise we don't really have any way of knowing how well the code is working; is it already throttling down more and more?
Quoted 3 lines
Fair point. Can we add a qmp/hmp command like "info x-cpu-throttle"? Or a new line in "info migrate" output, "x-throttle-ration: 1.0" perhaps? Would this mess up libvirt's parsing of the hmp/qmp data?
info migrate with extra field, please. Name it with x-throotle-ratio or whatever.
I would also preffer to ha a percentage (or per thousand) that is an integer, but that is just a prefference and I don't really care too much.
Later, Juan.
Quoted 46 lines · Jason J. Herne
Remove traditional auto-converge static 30ms throttling code and replace it with a dynamic throttling algorithm.
Additionally, be more aggressive when deciding when to start throttling. Previously we waited until four unproductive memory passes. Now we begin throttling after only two unproductive memory passes. Four seemed quite arbitrary and only waiting for two passes allows us to complete the migration faster.
Signed-off-by Jason J. Herne <[email protected]>Reviewed-by Matthew Rosato <[email protected]>--- arch_init.c | 95 +++++++++++++++++---------------------------------- migration/migration.c | 9 +++++ 2 files changed, 41 insertions(+), 63 deletions(-)arch_init.c +12
-2@@ -111,9 +111,7 @@ int graphic_depth = 32;#endif const uint32_t arch_type =QEMU_ARCH ; -static bool mig_throttle_on;static int dirty_rate_high_cnt; -static void check_guest_throttling (void );static uint64_t bitmap_sync_count;@@ -487,6 +485,31 @@ static size_t save_page_header(QEMUFile *f, RAMBlock *block, ram_addr_t offset)return size; } +/* Reduce amount of guest cpu execution to hopefully slow down memory writes. +* If guest dirty memory rate is reduced below the rate at which we can +* transfer pages to the destination then we should be able to complete +* migration. Some workloads dirty memory way too fast and will not effectively +* converge, even with auto-converge. For these workloads we will continue to +* increase throttling until the guest is paused long enough to complete the +* migration. This essentially becomes a non-live migration. +*/ +static void mig_throttle_guest_down (void ) +{ +CPUState *cpu; +
arch_init.c static size_t save_page_header(QEMUFile *f, RAMBlock *block, ram_addr_t offset) · line 509
Quoted 10 lines
arch_init.c +10
-0+CPU_FOREACH (cpu) { +/* We have not started throttling yet. Lets start it.*/ +if (!cpu_throttle_active (cpu)) { +cpu_throttle_start (cpu,0.2 ); + } + +/* Throttling is already in place. Just increase the throttling rate */ +else { +cpu_throttle_start (cpu,cpu_throttle_get_ratio (cpu) *2 ); + }
If we go this design (I think I preffer the old one), can we rename
cpu_throottle_start() to cpu_throotle_increase(), that just do this? As an added bonus, we don't have to export cpu_throttle_get_ratio() and cpu_throotle_active().
Quoted 11 lines
arch_init.c +3
-1+ } +} +/* Update the xbzrle cache to reflect a page that's been sent as all 0. * The important thing is that a stale (not-yet-0'd) page be replaced * by the new data. @@ -714,21 +737,21 @@ static void migration_bitmap_sync(void)/* The following detection logic can be refined later. For now: Check to see if the dirtied bytes is 50% more than the approx. amount of bytes that just got transferred since the last time we -were in this routine. If that happens >N times (for now N==4)
arch_init.c static void migration_bitmap_sync(void) · line 747
Quoted 10 lines
arch_init.c +4
-2-we turn on the throttle down logic */ +were in this routine. If that happens twice, start or increase +throttling */ bytes_xfer_now =ram_bytes_transferred (); +if (s->dirty_pages_rate && (num_dirty_pages_period *TARGET_PAGE_SIZE > (bytes_xfer_now - bytes_xfer_prev)/2 ) && - (dirty_rate_high_cnt++ >4 )) { + (dirty_rate_high_cnt++ >=2 )) {
Once we are here, cahnging this to a parameter is a good idea. The same for the 0.2 increase.
Quoted 22 lines
arch_init.c +2
-4trace_migration_throttle (); - mig_throttle_on = true; dirty_rate_high_cnt =0 ; +mig_throttle_guest_down (); } bytes_xfer_prev = bytes_xfer_now; - }else { - mig_throttle_on = false; } +if (migrate_use_xbzrle ()) {if (iterations_prev != acct_info.iterations) { acct_info.xbzrle_cache_miss_rate =@@ -1197,7 +1220,6 @@ static int ram_save_setup(QEMUFile *f, void *opaque)RAMBlock *block;int64_t ram_bitmap_pages;/* Size of bitmap in pages, including gaps */ - mig_throttle_on = false; dirty_rate_high_cnt =0 ; bitmap_sync_count =0 ;migration_bitmap_sync_init ();
arch_init.c static int ram_save_iterate(QEMUFile *f, void *opaque) · line 1304
Quoted 4 lines
arch_init.c +0
-1@@ -1301,12 +1323,7 @@ static int ram_save_iterate(QEMUFile *f, void *opaque) } pages_sent += pages; acct_info.iterations++; -check_guest_throttling ();
Notice, ond old code, we check for throotling each time that we do an iteration through ram, reason of doing it here is that it avoids us to have to had additional threads to control it.
Quoted 82 lines
arch_init.c +1
-53-/* we want to check in the 1st loop, just in case it was the 1st time -and we had to sync the dirty bitmap. -qemu_get_clock_ns() is a bit expensive, so we only check each some -iterations -*/ +if ((i &63 ) ==0 ) {uint64_t t1 = (qemu_clock_get_ns (QEMU_CLOCK_REALTIME ) - t0) /1000000 ;if (t1 >MAX_WAIT ) {@@ -1913,51 +1930,3 @@ TargetInfo *qmp_query_target(Error **errp)return info; } -/* Stub function that's gets run on the vcpu when its brought out of the -VM to run inside qemu via async_run_on_cpu()*/ -static void mig_sleep_cpu (void *opq) -{ -qemu_mutex_unlock_iothread (); -g_usleep (30 *1000 ); -qemu_mutex_lock_iothread (); -} - -/* To reduce the dirty rate explicitly disallow the VCPUs from spending -much time in the VM. The migration thread will try to catchup. -Workload will experience a performance drop. -*/ -static void mig_throttle_guest_down (void ) -{ -CPUState *cpu; - -qemu_mutex_lock_iothread (); -CPU_FOREACH (cpu) { -async_run_on_cpu (cpu, mig_sleep_cpu,NULL ); - } -qemu_mutex_unlock_iothread (); -} - -static void check_guest_throttling (void ) -{ -static int64_t t0; -int64_t t1; - -if (!mig_throttle_on) { -return ; - } - -if (!t0) { - t0 =qemu_clock_get_ns (QEMU_CLOCK_REALTIME ); -return ; - } - - t1 =qemu_clock_get_ns (QEMU_CLOCK_REALTIME ); - -/* If it has been more than 40 ms since the last time the guest -* was throttled then do it again. -*/ -if (40 < (t1-t0)/1000000 ) { -mig_throttle_guest_down (); - t0 = t1; - } -}migration/migration.c +2
-0@@ -25,6 +25,7 @@#include "qemu/thread.h" #include "qmp-commands.h" #include "trace.h" +#include "qom/cpu.h" #define MAX_THROTTLE (32 << 20)/* Migration speed throttling */ @@ -731,6 +732,7 @@ int64_t migrate_xbzrle_cache_size(void)static void *migration_thread (void *opaque) {MigrationState *s = opaque; +CPUState *cpu;int64_t initial_time =qemu_clock_get_ms (QEMU_CLOCK_REALTIME );int64_t setup_start =qemu_clock_get_ms (QEMU_CLOCK_HOST );int64_t initial_bytes =0 ;
migration/migration.c static void *migration_thread(void *opaque) · line 823
Quoted 8 lines
migration/migration.c +5
-0@@ -814,6 +816,13 @@ static void *migration_thread(void *opaque) } } +/* If we enabled cpu throttling for auto-converge, turn it off. */ +CPU_FOREACH (cpu) { +if (cpu_throttle_active (cpu)) { +cpu_throttle_stop (cpu); + }
It is a question of style, but I will do the other way, put the test for cpu_throttle_active() inside cpu_throttle_stop().
And if you move to having a single thread, you get a simpler cleanup, or using the migration_thread for this, you get the cleanup for free.
migration/migration.c static void *migration_thread(void *opaque) · line 828
Quoted 5 lines
migration/migration.c +2
-0+ } +qemu_mutex_lock_iothread ();if (s->state ==MIGRATION_STATUS_COMPLETED ) {int64_t end_time =qemu_clock_get_ms (QEMU_CLOCK_REALTIME );
Thanks, Juan.