From patchwork Sun Apr 7 05:18:00 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Crosthwaite X-Patchwork-Id: 234458 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id C3AE72C00BA for ; Sun, 7 Apr 2013 15:18:49 +1000 (EST) Received: from localhost ([::1]:57242 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UOi07-0005KJ-V4 for incoming@patchwork.ozlabs.org; Sun, 07 Apr 2013 01:18:47 -0400 Received: from eggs.gnu.org ([208.118.235.92]:35622) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UOhzt-0005KB-0y for qemu-devel@nongnu.org; Sun, 07 Apr 2013 01:18:35 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UOhzm-00077K-BP for qemu-devel@nongnu.org; Sun, 07 Apr 2013 01:18:32 -0400 Received: from mail-da0-x230.google.com ([2607:f8b0:400e:c00::230]:55942) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UOhzm-000777-5D for qemu-devel@nongnu.org; Sun, 07 Apr 2013 01:18:26 -0400 Received: by mail-da0-f48.google.com with SMTP id p8so2117609dan.7 for ; Sat, 06 Apr 2013 22:18:25 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-received:sender:from:to:cc:subject:date:message-id:x-mailer :x-gm-message-state; bh=4cvyoisM8M/XA4QX/wxzCVoveYojUukelDnckLdvd7c=; b=OKG9f1kntMuvXvb5x1u25VLMWMRpETzd68GEW07Rb2H2Fs6cFq9o708GgzOE5fGmhs EdVNI+Ky5vld1VNWnLJA2x77qqcFXpp7EPA67D+6ozWsmfp219LhWSofX/UmZqiZg4uT GyZ8tmVk7VOqfqy8SshorqI9wdzDHpqACyNFR/eRIo2IFY97jITc18FGFGq7kep+kRsT Ral1CqDcCKiylzdfFqdNbGRG29wJLbSRHjsG6RvIanv2Qs7BCYclbweFmSdLY/3CzZ2f /mgeXgRQNzWvVtdHCDWP3FD/2aiLQPGJWzEAz+VD72PhFpcLa0FGp9ZtFgtY85tYpL+u qHjg== X-Received: by 10.66.160.225 with SMTP id xn1mr25821995pab.136.1365311905163; Sat, 06 Apr 2013 22:18:25 -0700 (PDT) Received: from localhost ([149.199.62.254]) by mx.google.com with ESMTPS id wl5sm8945175pac.18.2013.04.06.22.18.22 (version=TLSv1.1 cipher=RC4-SHA bits=128/128); Sat, 06 Apr 2013 22:18:24 -0700 (PDT) From: Peter Crosthwaite To: qemu-devel@nongnu.org Date: Sun, 7 Apr 2013 15:18:00 +1000 Message-Id: <1365311880-11800-1-git-send-email-peter.crosthwaite@xilinx.com> X-Mailer: git-send-email 1.7.0.4 X-Gm-Message-State: ALoCoQmm3rD6lS75Z7TZz/zn4TTQ8ZsCN/Dco+k+1PZiJV9MMpjGMbSsMEFNTKdviGF8I9a9L6Q+ X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2607:f8b0:400e:c00::230 Cc: pbonzini@redhat.com, aliguori@us.ibm.com, Peter Crosthwaite Subject: [Qemu-devel] [PATCH] mainloop.c: Keep unlocking BQL during busy-wait spin-out X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Modify Anthony's starvation detection logic to keep the BQL unlocked until the starvation condition goes away. Otherwise the counter has to count up to 1000 for each needed iteration until the busy-wait is lifted. Reset the counter back to zero once glib_pollfds_fill returns with a non-zero timout, (indicating a return to normality). The 1000 iteration wait now only happens once on the transition from normal operation to busy-wait starvation. Anthony's original patch fixed the serial paste bug, but this patch is also needed to restore performance. Signed-off-by: Peter Crosthwaite --- main-loop.c | 20 ++++++++++---------- 1 files changed, 10 insertions(+), 10 deletions(-) diff --git a/main-loop.c b/main-loop.c index f46aece..93d2917 100644 --- a/main-loop.c +++ b/main-loop.c @@ -200,10 +200,13 @@ static int os_host_main_loop_wait(uint32_t timeout) /* If the I/O thread is very busy or we are incorrectly busy waiting in * the I/O thread, this can lead to starvation of the BQL such that the * VCPU threads never run. To make sure we can detect the later case, - * print a message to the screen. If we run into this condition, create - * a fake timeout in order to give the VCPU threads a chance to run. + * print a message to the screen. If we run into this condition, unlock + * the BQL until a non-zero timout is given (indicating the starvation + * issue has gome away). */ - if (spin_counter > MAX_MAIN_LOOP_SPIN) { + if (timeout > 0) { + spin_counter = 0; + } else if (spin_counter > MAX_MAIN_LOOP_SPIN) { static bool notified; if (!notified) { @@ -212,21 +215,18 @@ static int os_host_main_loop_wait(uint32_t timeout) MAX_MAIN_LOOP_SPIN); notified = true; } - - timeout = 1; } - if (timeout > 0) { - spin_counter = 0; + if (timeout > 0 || spin_counter > MAX_MAIN_LOOP_SPIN) { qemu_mutex_unlock_iothread(); - } else { - spin_counter++; } ret = g_poll((GPollFD *)gpollfds->data, gpollfds->len, timeout); - if (timeout > 0) { + if (timeout > 0 || spin_counter > MAX_MAIN_LOOP_SPIN) { qemu_mutex_lock_iothread(); + } else { + spin_counter++; } glib_pollfds_poll();