From patchwork Fri Mar 18 16:18:49 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 64078 Delivered-To: patch@linaro.org Received: by 10.112.199.169 with SMTP id jl9csp54312lbc; Fri, 18 Mar 2016 09:23:23 -0700 (PDT) X-Received: by 10.55.72.85 with SMTP id v82mr20622905qka.105.1458318203846; Fri, 18 Mar 2016 09:23:23 -0700 (PDT) Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id d193si12784103qka.54.2016.03.18.09.23.23 for (version=TLS1 cipher=AES128-SHA bits=128/128); Fri, 18 Mar 2016 09:23:23 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Authentication-Results: mx.google.com; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom=qemu-devel-bounces+patch=linaro.org@nongnu.org; dkim=fail header.i=@linaro.org Received: from localhost ([::1]:44825 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1agxBL-0008Py-7X for patch@linaro.org; Fri, 18 Mar 2016 12:23:23 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:56920) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1agx7B-0000RT-9K for qemu-devel@nongnu.org; Fri, 18 Mar 2016 12:19:06 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1agx79-0002xN-VV for qemu-devel@nongnu.org; Fri, 18 Mar 2016 12:19:05 -0400 Received: from mail-wm0-x22a.google.com ([2a00:1450:400c:c09::22a]:37504) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1agx79-0002wt-P5 for qemu-devel@nongnu.org; Fri, 18 Mar 2016 12:19:03 -0400 Received: by mail-wm0-x22a.google.com with SMTP id p65so44379901wmp.0 for ; Fri, 18 Mar 2016 09:19:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=8ObDwfZDtpID2FtivLsgYNjbxcVdgJJ4GHTZQyagGRM=; b=aNdkZkH9LnKZu1NGGVq2wUqywnmzeUqXXRbkkLQCTeTPlta8rET9nPNTd94UuudxOx 6xoiJj1kRRJ3w8IPPc8iRUDr2ybCA7V/+nMHzRKo0Y1Eko574ocfKqLi8/KPurfF8PuK 2w0i7AgoZpm6moLSnQyPvIR7qoGRYJcH3LIXU= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=8ObDwfZDtpID2FtivLsgYNjbxcVdgJJ4GHTZQyagGRM=; b=jarrdIk4ea0BmVIVhOQF2NiAvZb/LZvUNzVQjQL/q4FUKstnz0QIw4lCdaQvMh6djO j121SnzfYd3QZm4Y2VkapbUkurlPEhwSjcFW+Xfd/y4Pbyf2teVKWfaSSMfxJ/SZzsdQ pHvKBYumY8Z7ZTrtxiuAvwkeIWbzF5w42kqGJgiToi/hUwPxkj8UzSo/hRIN64fB8yqP ctIz1eMUtwIHNZ/tEomavcqmyT15eKfsNx8cJgogPZ/Hx37lCTEYgUL6YeWn0jtr5V3A rFm3h4NMqqCZkVQyRwviR3j8XJhbRnsD/HbMwkj6ieboe8bERYyaDNoEx3q4boz3UhI6 Dv6g== X-Gm-Message-State: AD7BkJKn9WYGFf3wUPpX7j6/GFy7muN3tmyYXTTgx+34r01tLk/saNpGD7A30Zp8lBFtQfwQ X-Received: by 10.28.63.13 with SMTP id m13mr199939wma.55.1458317943222; Fri, 18 Mar 2016 09:19:03 -0700 (PDT) Received: from zen.linaro.local ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id hq2sm12877241wjb.3.2016.03.18.09.18.58 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 18 Mar 2016 09:19:00 -0700 (PDT) Received: from zen.linaroharston (localhost [127.0.0.1]) by zen.linaro.local (Postfix) with ESMTP id 4A2CD3E0533; Fri, 18 Mar 2016 16:18:56 +0000 (GMT) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: mttcg@listserver.greensocs.com, fred.konrad@greensocs.com, a.rigo@virtualopensystems.com, serge.fdrv@gmail.com, cota@braap.org Date: Fri, 18 Mar 2016 16:18:49 +0000 Message-Id: <1458317932-1875-9-git-send-email-alex.bennee@linaro.org> X-Mailer: git-send-email 2.7.3 In-Reply-To: <1458317932-1875-1-git-send-email-alex.bennee@linaro.org> References: <1458317932-1875-1-git-send-email-alex.bennee@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2a00:1450:400c:c09::22a Cc: Peter Crosthwaite , mark.burton@greensocs.com, qemu-devel@nongnu.org, pbonzini@redhat.com, =?UTF-8?q?Alex=20Benn=C3=A9e?= , Richard Henderson Subject: [Qemu-devel] [RFC v1 08/11] tcg: add kick timer for single-threaded vCPU emulation 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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org Currently we rely on the side effect of the main loop grabbing the iothread_mutex to give any long running basic block chains a kick to ensure the next vCPU is scheduled. As this code is being re-factored and rationalised we now do it explicitly here. Signed-off-by: Alex Bennée --- cpus.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) -- 2.7.3 diff --git a/cpus.c b/cpus.c index 76bd321..a87fbf9 100644 --- a/cpus.c +++ b/cpus.c @@ -1145,11 +1145,30 @@ static void *qemu_dummy_cpu_thread_fn(void *arg) #endif } +/* Single-threaded TCG + * + * In the single-threaded case each vCPU is simulated in turn. If + * there is more than a single vCPU we create a simple timer to kick + * the vCPU and ensure we don't get stuck in a tight loop in one vCPU. + * This is done explicitly rather than relying on side-effects + * elsewhere. + */ static int tcg_cpu_exec(CPUState *cpu); +static void qemu_cpu_kick_no_halt(void); + +static void kick_tcg_thread(void *opaque) +{ + QEMUTimer *self = *(QEMUTimer **) opaque; + timer_mod(self, + qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) + + get_ticks_per_sec() / 10); + qemu_cpu_kick_no_halt(); +} static void *qemu_tcg_cpu_thread_fn(void *arg) { CPUState *cpu = arg; + QEMUTimer *kick_timer; rcu_register_thread(); @@ -1173,6 +1192,14 @@ static void *qemu_tcg_cpu_thread_fn(void *arg) } } + /* Set to kick if we have to do more than one vCPU */ + if (CPU_NEXT(first_cpu)) { + kick_timer = timer_new_ns(QEMU_CLOCK_VIRTUAL, kick_tcg_thread, &kick_timer); + timer_mod(kick_timer, + qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) + + get_ticks_per_sec() / 10); + } + /* process any pending work */ atomic_mb_set(&exit_request, 1);