From patchwork Mon Jan 3 10:03:50 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Kiszka X-Patchwork-Id: 77242 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id EA250B708B for ; Mon, 3 Jan 2011 21:05:04 +1100 (EST) Received: from localhost ([127.0.0.1]:38948 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PZhHi-00033J-9A for incoming@patchwork.ozlabs.org; Mon, 03 Jan 2011 05:05:02 -0500 Received: from [140.186.70.92] (port=51924 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PZhGb-0002vp-Py for qemu-devel@nongnu.org; Mon, 03 Jan 2011 05:03:54 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PZhGa-0006zv-IT for qemu-devel@nongnu.org; Mon, 03 Jan 2011 05:03:53 -0500 Received: from fmmailgate03.web.de ([217.72.192.234]:37871) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1PZhGa-0006zn-4S for qemu-devel@nongnu.org; Mon, 03 Jan 2011 05:03:52 -0500 Received: from smtp07.web.de ( [172.20.5.215]) by fmmailgate03.web.de (Postfix) with ESMTP id E016F18394602; Mon, 3 Jan 2011 11:03:50 +0100 (CET) Received: from [88.64.22.98] (helo=mchn199C.mchp.siemens.de) by smtp07.web.de with asmtp (TLSv1:AES256-SHA:256) (WEB.DE 4.110 #2) id 1PZhGY-0007V9-00; Mon, 03 Jan 2011 11:03:50 +0100 Message-ID: <4D219F06.7040305@web.de> Date: Mon, 03 Jan 2011 11:03:50 +0100 From: Jan Kiszka User-Agent: Mozilla/5.0 (X11; U; Linux i686 (x86_64); de; rv:1.8.1.12) Gecko/20080226 SUSE/2.0.0.12-1.1 Thunderbird/2.0.0.12 Mnenhy/0.7.5.666 MIME-Version: 1.0 To: Avi Kivity References: <4D219AF5.2030204@web.de> <4D219E6D.8060902@redhat.com> In-Reply-To: <4D219E6D.8060902@redhat.com> X-Enigmail-Version: 1.1.2 X-Sender: jan.kiszka@web.de X-Provags-ID: V01U2FsdGVkX1/2coDs4705DP+FsEdZpvHiNY0VFX1MCBvkNgoj FKFHH3M+zHTWh8CS9hIP7NAkRjaSQrd1mtpoGssvCnn9lIG6Hk IdUc9357g= X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4-2.6 Cc: Marcelo Tosatti , qemu-devel , kvm Subject: [Qemu-devel] Re: Role of qemu_fair_mutex X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Am 03.01.2011 11:01, Avi Kivity wrote: > On 01/03/2011 11:46 AM, Jan Kiszka wrote: >> Hi, >> >> at least in kvm mode, the qemu_fair_mutex seems to have lost its >> function of balancing qemu_global_mutex access between the io-thread and >> vcpus. It's now only taken by the latter, isn't it? >> >> This and the fact that qemu-kvm does not use this kind of lock made me >> wonder what its role is and if it is still relevant in practice. I'd >> like to unify the execution models of qemu-kvm and qemu, and this lock >> is the most obvious difference (there are surely more subtle ones as >> well...). >> > > IIRC it was used for tcg, which has a problem that kvm doesn't have: a > tcg vcpu needs to hold qemu_mutex when it runs, which means there will > always be contention on qemu_mutex. In the absence of fairness, the tcg > thread could dominate qemu_mutex and starve the iothread. > > This doesn't happen with kvm since kvm vcpus drop qemu_mutex when running. > I see. Then I guess we should do this: Jan diff --git a/cpus.c b/cpus.c index 9bf5224..0de8552 100644 --- a/cpus.c +++ b/cpus.c @@ -734,9 +734,7 @@ static sigset_t block_io_signals(void) void qemu_mutex_lock_iothread(void) { if (kvm_enabled()) { - qemu_mutex_lock(&qemu_fair_mutex); qemu_mutex_lock(&qemu_global_mutex); - qemu_mutex_unlock(&qemu_fair_mutex); } else { qemu_mutex_lock(&qemu_fair_mutex); if (qemu_mutex_trylock(&qemu_global_mutex)) {