From patchwork Tue Jun 19 01:42:20 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Michael Roth X-Patchwork-Id: 139069 Delivered-To: patch@linaro.org Received: by 2002:a2e:970d:0:0:0:0:0 with SMTP id r13-v6csp4663602lji; Mon, 18 Jun 2018 19:47:28 -0700 (PDT) X-Google-Smtp-Source: ADUXVKITdahIYm6ZYZQ3vvTSaHIrk8N8KMp4ZE1CSy6dWLKM1q/Jg5iFrwIzpEhZY3BtjNryp/UX X-Received: by 2002:a37:350a:: with SMTP id c10-v6mr12115417qka.388.1529376448536; Mon, 18 Jun 2018 19:47:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1529376448; cv=none; d=google.com; s=arc-20160816; b=Z9QlIp0AMoXLcrdpW6helhhmky9vQ5CDPnpiQj1iLib21MM26dQNiHDDCMzsvCs/h2 7eGL5XG2sx/utobt8pK7fZ9PDldfY+MB0CMnWBTllEV0IFptjoB8Hfp/rw7cxwiSitSx DCFpJ2/phlplT7EOj0gT2ng+g1h9Y8tYZrQgYPKhP+lKYY7ITvuWALx//3z4YAB55aDW 2ulueMsIGYKta3OWa5He2zAEkzaiYCgerC2czhKl1qe/imN2vtcSa+3O3ObDOeWZVh+/ xnfNdYDZ487Zo95pW16vnuhxZT44Iq4YeH129ZZJKIs7mPVM9gaUtZCg/rGXxHn1clEH FnMg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:to:from:dkim-signature:arc-authentication-results; bh=rOuwpNiiE+JdCAHr4P1l3+or/iloZktTvGW4y9eDwtg=; b=qMSZer7b/izYhi1y12hYva/uM2n/uA6K1Fwj1/vmJOUgJXikIrQ7gTlvmIa7XIR1J3 /viKlJ/LiyJVUQc5hiM0fk63Mcs/DaBpgJTTMSVYk87uC8KDceKmM386GjkFygftV4g3 8s1PxRoNqHOYuacxbb+a28XITDxXLjYZ7UvllhiKLAJcrwirPKzbWstII1iOyStaxR7B MSisnYjhJgMhoEWzObWukrsL7NxLIWbTXlSQRLhhQRw5CorLmtjNwp6pRvkpx+u96bSB +mo3tepdFy6BHpId6nSS7L+6siR7glEGkcJkZqvglbFOCIbdGtEnR04dznAJJS9GA+9a GmOg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=dthUBTIP; 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"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=ibm.com Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id f5-v6si625893qve.92.2018.06.18.19.47.28 for (version=TLS1 cipher=AES128-SHA bits=128/128); Mon, 18 Jun 2018 19:47:28 -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; dkim=fail header.i=@gmail.com header.s=20161025 header.b=dthUBTIP; 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"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=ibm.com Received: from localhost ([::1]:38749 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fV6g1-0007vt-VT for patch@linaro.org; Mon, 18 Jun 2018 22:47:26 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46365) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fV5ih-0002Jl-EP for qemu-devel@nongnu.org; Mon, 18 Jun 2018 21:46:08 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fV5if-0000F9-GN for qemu-devel@nongnu.org; Mon, 18 Jun 2018 21:46:07 -0400 Received: from mail-ot0-x231.google.com ([2607:f8b0:4003:c0f::231]:33927) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fV5if-0000F3-Ax; Mon, 18 Jun 2018 21:46:05 -0400 Received: by mail-ot0-x231.google.com with SMTP id r18-v6so20783113otk.1; Mon, 18 Jun 2018 18:46:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=rOuwpNiiE+JdCAHr4P1l3+or/iloZktTvGW4y9eDwtg=; b=dthUBTIPndwHy/1GQitVuYlZEmHmgwvqiZLgobqkDF/fLmLFx6irQ7xry5eg6VO1Jg nCDq1BUnjEakjdNFriBlp2/Od3CCGRY5yX4j9Tg7b+4cYErHQ1L51iT6CD8/lGlVlWyj YNhVJN1tSBBe3eJ5pUMN/67JptHPujf56zppHYJGlG5F/WJ3f8ikHSGvtWj7/Wmz0wRV ih1Q+8fVLyAGJSBfJjGvEV7x/3gMa33ZYUKw0a/uwMv0h8xB6f8UdjJsvKf4NdRtAnSc iMnqmd1xgyEhCHqibUYeWUVHIQmhQEPZOLwZUvphUwkbweHQT94BHS6dy0k/IQtXrpLP 1Ekg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=rOuwpNiiE+JdCAHr4P1l3+or/iloZktTvGW4y9eDwtg=; b=JzCa/4+V1Si00N5EkQ0E8anSew7pa6S0q1U3hOIN9D6u/56fDgPM0hYu2JEusTeein jr6tPhekAnewRQjU2swVy5fGwlPM3nenUaOLElrDxhP3u6xTJ/NKlway/JIT1nOxnfzI Rn9v8ggieQHIGc8EABvf16Fdy4wWFzjsrxTGfDh6JjrL9yUe6OUbjOFdXXwjFHyq5jdb QJOWQ37gLzJoTcidPjdwBxIMfh/Hh+NLfarE34e5N48U+MfL25V8Cxutp6g17p2DbI/G Tm+fQw7k7NA7CKQ2VAWJy2rw+HajvLToaqVdlblv0GGLB4+deW8vistzUKMxWvOJySGj GAog== X-Gm-Message-State: APt69E3mwOiE3Zp3ulOjQNFVpP9dhd8HyWFEbCnawW0YaRjH2oh7b1bD YJQuVa2dne3r0BZNTiKksHEm8Tyb X-Received: by 2002:a9d:440d:: with SMTP id u13-v6mr9919613ote.374.1529372764135; Mon, 18 Jun 2018 18:46:04 -0700 (PDT) Received: from localhost (76-251-165-188.lightspeed.austtx.sbcglobal.net. [76.251.165.188]) by smtp.gmail.com with ESMTPSA id t77-v6sm7294818oie.3.2018.06.18.18.46.02 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 18 Jun 2018 18:46:03 -0700 (PDT) From: Michael Roth To: qemu-devel@nongnu.org Date: Mon, 18 Jun 2018 20:42:20 -0500 Message-Id: <20180619014319.28272-55-mdroth@linux.vnet.ibm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20180619014319.28272-1-mdroth@linux.vnet.ibm.com> References: <20180619014319.28272-1-mdroth@linux.vnet.ibm.com> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4003:c0f::231 Subject: [Qemu-devel] [PATCH 054/113] cpus.c: ensure running CPU recalculates icount deadlines on timer expiry 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: Peter Maydell , qemu-stable@nongnu.org Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: Peter Maydell When we run in TCG icount mode, we calculate the number of instructions to execute using tcg_get_icount_limit(), which ensures that we stop execution at the next timer deadline. However there is a bug where currently we do not recalculate that limit if the guest reprograms a timer so that the next deadline moves closer, and so we will continue execution until the original limit and fire the timer later than we should. Fix this bug in qemu_timer_notify_cb(): if we are currently running a VCPU in icount mode, we simply need to kick it out of the main loop and back to tcg_cpu_exec(), where it will recalculate the icount limit. If we are not currently running a VCPU, then we retain the existing logic for waking up a halted CPU. Cc: qemu-stable@nongnu.org Fixes: https://bugs.launchpad.net/qemu/+bug/1754038 Signed-off-by: Peter Maydell Reviewed-by: Richard Henderson Reviewed-by: Alex Bennée Message-id: 20180406123838.21249-1-peter.maydell@linaro.org (cherry picked from commit c52e7132d7c885841500f5277f7305f62767fe1d) Signed-off-by: Michael Roth --- cpus.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) -- 2.11.0 diff --git a/cpus.c b/cpus.c index 114c29b6a0..96bb688d7b 100644 --- a/cpus.c +++ b/cpus.c @@ -843,11 +843,19 @@ void qemu_timer_notify_cb(void *opaque, QEMUClockType type) return; } - if (!qemu_in_vcpu_thread() && first_cpu) { + if (qemu_in_vcpu_thread()) { + /* A CPU is currently running; kick it back out to the + * tcg_cpu_exec() loop so it will recalculate its + * icount deadline immediately. + */ + qemu_cpu_kick(current_cpu); + } else if (first_cpu) { /* qemu_cpu_kick is not enough to kick a halted CPU out of * qemu_tcg_wait_io_event. async_run_on_cpu, instead, * causes cpu_thread_is_idle to return false. This way, * handle_icount_deadline can run. + * If we have no CPUs at all for some reason, we don't + * need to do anything. */ async_run_on_cpu(first_cpu, do_nothing, RUN_ON_CPU_NULL); }