From patchwork Thu May 19 12:33:16 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Wolf X-Patchwork-Id: 96350 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [140.186.70.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 57152B6F82 for ; Thu, 19 May 2011 22:31:27 +1000 (EST) Received: from localhost ([::1]:41515 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QN2Nw-0002HA-E9 for incoming@patchwork.ozlabs.org; Thu, 19 May 2011 08:31:24 -0400 Received: from eggs.gnu.org ([140.186.70.92]:50186) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QN2NR-0002E5-JW for qemu-devel@nongnu.org; Thu, 19 May 2011 08:30:54 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1QN2NQ-0003si-Ro for qemu-devel@nongnu.org; Thu, 19 May 2011 08:30:53 -0400 Received: from mx1.redhat.com ([209.132.183.28]:4133) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QN2NQ-0003sW-JM for qemu-devel@nongnu.org; Thu, 19 May 2011 08:30:52 -0400 Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id p4JCUp4u008546 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Thu, 19 May 2011 08:30:51 -0400 Received: from dhcp-5-188.str.redhat.com (dhcp-5-175.str.redhat.com [10.32.5.175]) by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id p4JCUleI009371; Thu, 19 May 2011 08:30:50 -0400 From: Kevin Wolf To: anthony@codemonkey.ws Date: Thu, 19 May 2011 14:33:16 +0200 Message-Id: <1305808412-16994-3-git-send-email-kwolf@redhat.com> In-Reply-To: <1305808412-16994-1-git-send-email-kwolf@redhat.com> References: <1305808412-16994-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.12 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 209.132.183.28 Cc: kwolf@redhat.com, qemu-devel@nongnu.org Subject: [Qemu-devel] [PATCH 02/18] posix-aio-compat: Fix idle_threads counter 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 A thread should only be counted as idle when it really is waiting for new requests. Without this patch, sometimes too few threads are started as busy threads are counted as idle. Not sure if it makes a difference in practice outside some artificial qemu-io/qemu-img tests, but I think the change makes sense in any case. Signed-off-by: Kevin Wolf --- posix-aio-compat.c | 6 ++---- 1 files changed, 2 insertions(+), 4 deletions(-) diff --git a/posix-aio-compat.c b/posix-aio-compat.c index 6d4df9d..f3cc868 100644 --- a/posix-aio-compat.c +++ b/posix-aio-compat.c @@ -322,7 +322,9 @@ static void *aio_thread(void *unused) while (QTAILQ_EMPTY(&request_list) && !(ret == ETIMEDOUT)) { + idle_threads++; ret = cond_timedwait(&cond, &lock, &ts); + idle_threads--; } if (QTAILQ_EMPTY(&request_list)) @@ -331,7 +333,6 @@ static void *aio_thread(void *unused) aiocb = QTAILQ_FIRST(&request_list); QTAILQ_REMOVE(&request_list, aiocb, node); aiocb->active = 1; - idle_threads--; mutex_unlock(&lock); switch (aiocb->aio_type & QEMU_AIO_TYPE_MASK) { @@ -353,13 +354,11 @@ static void *aio_thread(void *unused) mutex_lock(&lock); aiocb->ret = ret; - idle_threads++; mutex_unlock(&lock); if (kill(pid, aiocb->ev_signo)) die("kill failed"); } - idle_threads--; cur_threads--; mutex_unlock(&lock); @@ -371,7 +370,6 @@ static void spawn_thread(void) sigset_t set, oldset; cur_threads++; - idle_threads++; /* block all signals */ if (sigfillset(&set)) die("sigfillset");