From patchwork Fri May 19 21:29:50 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Felipe Franciosi X-Patchwork-Id: 9738279 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 5C5D56034C for ; Fri, 19 May 2017 21:56:13 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4AF3228563 for ; Fri, 19 May 2017 21:56:13 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3D5A728585; Fri, 19 May 2017 21:56:13 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id D85F028563 for ; Fri, 19 May 2017 21:56:12 +0000 (UTC) Received: from localhost ([::1]:60365 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dBpsY-0001NZ-Ps for patchwork-qemu-devel@patchwork.kernel.org; Fri, 19 May 2017 17:56:10 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:56831) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dBpru-0001NU-HA for qemu-devel@nongnu.org; Fri, 19 May 2017 17:55:31 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dBprp-00022L-Qr for qemu-devel@nongnu.org; Fri, 19 May 2017 17:55:30 -0400 Received: from [62.254.189.133] (port=54277 helo=centos.localdomain) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dBprp-0001qw-5U for qemu-devel@nongnu.org; Fri, 19 May 2017 17:55:25 -0400 Received: by centos.localdomain (Postfix, from userid 500) id BB7FB9FBD4; Fri, 19 May 2017 22:29:58 +0100 (BST) From: Felipe Franciosi To: Paolo Bonzini , "Jason J. Herne" , Malcolm Crossley Date: Fri, 19 May 2017 22:29:50 +0100 Message-Id: <1495229390-18909-1-git-send-email-felipe@nutanix.com> X-Mailer: git-send-email 1.9.5 X-detected-operating-system: by eggs.gnu.org: Mac OS X [generic] [fuzzy] X-Received-From: 62.254.189.133 Subject: [Qemu-devel] [PATCH] cpus: reset throttle_thread_scheduled after sleep X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: "qemu-devel@nongnu.org" , Felipe Franciosi Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP 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 Signed-off-by: Malcolm Crossley Acked-by: Jason J. Herne Reviewed-by: Juan Quintela --- 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)