qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH] cpus: reset throttle_thread_scheduled after sleep
@ 2017-05-19 21:29 Felipe Franciosi
  2017-05-22 13:01 ` Jason J. Herne
                   ` (2 more replies)
  0 siblings, 3 replies; 10+ messages in thread
From: Felipe Franciosi @ 2017-05-19 21:29 UTC (permalink / raw)
  To: Paolo Bonzini, Jason J. Herne, Malcolm Crossley
  Cc: qemu-devel@nongnu.org, Felipe Franciosi

Currently, the throttle_thread_scheduled flag is reset back to 0 before
sleeping (as part of the throttling logic). Given that throttle_timer
(well, any timer) may tick with a slight delay, it so happens that under
heavy throttling (ie. close or on CPU_THROTTLE_PCT_MAX) the tick may
schedule a further cpu_throttle_thread() work item after the flag reset,
but before the previous sleep completed. This results on the vCPU thread
sleeping continuously for potentially several seconds in a row.

The chances of that happening can be drastically minimised by resetting
the flag after the sleep.

Signed-off-by: Felipe Franciosi <felipe@nutanix.com>
Signed-off-by: Malcolm Crossley <malcolm@nutanix.com>
---
 cpus.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/cpus.c b/cpus.c
index 516e5cb..f42eebd 100644
--- a/cpus.c
+++ b/cpus.c
@@ -677,9 +677,9 @@ static void cpu_throttle_thread(CPUState *cpu, run_on_cpu_data opaque)
     sleeptime_ns = (long)(throttle_ratio * CPU_THROTTLE_TIMESLICE_NS);
 
     qemu_mutex_unlock_iothread();
-    atomic_set(&cpu->throttle_thread_scheduled, 0);
     g_usleep(sleeptime_ns / 1000); /* Convert ns to us for usleep call */
     qemu_mutex_lock_iothread();
+    atomic_set(&cpu->throttle_thread_scheduled, 0);
 }
 
 static void cpu_throttle_timer_tick(void *opaque)
-- 
1.9.5

^ permalink raw reply related	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2017-06-07 16:58 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-05-19 21:29 [Qemu-devel] [PATCH] cpus: reset throttle_thread_scheduled after sleep Felipe Franciosi
2017-05-22 13:01 ` Jason J. Herne
2017-06-01 14:36   ` Dr. David Alan Gilbert
2017-06-01 15:02     ` Felipe Franciosi
2017-06-01 15:08       ` Dr. David Alan Gilbert
2017-05-25 15:52 ` Paolo Bonzini
2017-05-25 16:25   ` Felipe Franciosi
2017-05-25 16:34     ` Paolo Bonzini
2017-06-07 16:26 ` Juan Quintela
2017-06-07 16:58   ` Paolo Bonzini

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).