qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Paolo Bonzini <pbonzini@redhat.com>
To: qemu-devel@nongnu.org
Cc: Felipe Franciosi <felipe@nutanix.com>,
	Malcolm Crossley <malcolm@nutanix.com>
Subject: [Qemu-devel] [PULL 34/34] cpus: reset throttle_thread_scheduled after sleep
Date: Thu,  1 Jun 2017 19:07:33 +0200	[thread overview]
Message-ID: <20170601170733.13080-3-pbonzini@redhat.com> (raw)
In-Reply-To: <20170601170733.13080-1-pbonzini@redhat.com>

From: Felipe Franciosi <felipe@nutanix.com>

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>
Message-Id: <1495229390-18909-1-git-send-email-felipe@nutanix.com>
Acked-by: Jason J. Herne <jjherne@linux.vnet.ibm.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 cpus.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/cpus.c b/cpus.c
index 516e5cbac1..f42eebda91 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)
-- 
2.13.0

  parent reply	other threads:[~2017-06-01 17:07 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-06-01 17:07 [Qemu-devel] [PULL v2 00/34] Misc patches for 2016-06-01 Paolo Bonzini
2017-06-01 17:07 ` [Qemu-devel] [PULL 06/34] qtest: add rtc periodic timer test Paolo Bonzini
2017-06-01 17:07 ` Paolo Bonzini [this message]
2017-06-01 17:53 ` [Qemu-devel] [PULL v2 00/34] Misc patches for 2016-06-01 Peter Maydell
2017-06-01 17:56   ` Peter Maydell
2017-06-02  8:06     ` Paolo Bonzini
2017-06-02 16:45       ` Peter Maydell
  -- strict thread matches above, loose matches on Subject: below --
2017-06-01 16:03 Paolo Bonzini
2017-06-01 16:03 ` [Qemu-devel] [PULL 34/34] cpus: reset throttle_thread_scheduled after sleep Paolo Bonzini

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170601170733.13080-3-pbonzini@redhat.com \
    --to=pbonzini@redhat.com \
    --cc=felipe@nutanix.com \
    --cc=malcolm@nutanix.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).