From patchwork Sun Oct 13 22:25:44 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 176101 Delivered-To: patch@linaro.org Received: by 2002:a92:7e96:0:0:0:0:0 with SMTP id q22csp3797033ill; Sun, 13 Oct 2019 15:49:11 -0700 (PDT) X-Google-Smtp-Source: APXvYqxZvwf+vGz5YfyWlihqIpW+V00CFG9njkjI9M19GqV/89WuZ9Kbcv3Mk/Ee+E6KwPcg9t45 X-Received: by 2002:a0c:94af:: with SMTP id j44mr27995543qvj.230.1571006951538; Sun, 13 Oct 2019 15:49:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1571006951; cv=none; d=google.com; s=arc-20160816; b=hp1q8YPATj2l+r33sZOv3jQw79JlAxBNeCfRf+7XKSmIuABZPq6Olmid4GptFrokEB rvsXDSgkdOLXDOyCJH0Vsi4rUeBSMVZPHploNE9+LjKRHz+ArEAXRiveam0NKLLVPcOU FjqiqK+npf1F8+nId+1O6msFqw9Z/kyjZvvw6JC2mrjkGuM3y8TFnJYSUyx07D0Z/mjP QSBrei4KuZhlMn9vjAmVsJzOhyFKt1ozfY5fIJ8ePP91aVEao92Ck6G4h/qz4hyXCQ0D iU9Kv4i7eRh8ZHtm9cBEK0HYDf0Fn4uE+qYtQh/eWhkxXO2DcWXoUTJ2wHDSk0nE42j9 EY+Q== 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:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=mbGjA7d6AQiFvZB5+xEjn3eOcLNF0/a+vXYuP56z9BY=; b=qMOYZN+ht8AzE2jcZDzMefshxn9ppDblvkLj5Y2LEnOAww3f7VFcfT7aNTFapn19eS UV0R9NwVXb1YQRrOlnbI94Za6MEB8w5TvoUIzzjOZtpbtHi+lWkQTksl3UhXDd0pSb8Q Ys1Mbvvh9uP7fRlSotTig5CWCPC3uQ6vwzJQIMwqaS/dz3FhYEzIn0KdYXOvDR+rp8Wd FFM+gUMPga2yf61MSzkjiHwsGUe0D4EWrZHU0DT08LNpOUrO/aVKFiVghJGi63eWHnT8 0w97SctfCQbG5tacsZtwOP9JAvD41G2dSlWlN1704A/yDigMk1Zrodbot9n7elxIm1Io ySvA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=nZP+Xcmw; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id o35si16450926qvc.115.2019.10.13.15.49.11 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sun, 13 Oct 2019 15:49:11 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=nZP+Xcmw; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:43414 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iJmfn-0005e3-3S for patch@linaro.org; Sun, 13 Oct 2019 18:49:11 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:51404) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iJmJk-00076A-Bm for qemu-devel@nongnu.org; Sun, 13 Oct 2019 18:26:27 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iJmJj-00018x-8z for qemu-devel@nongnu.org; Sun, 13 Oct 2019 18:26:24 -0400 Received: from mail-pg1-x543.google.com ([2607:f8b0:4864:20::543]:40448) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1iJmJf-00015C-F4 for qemu-devel@nongnu.org; Sun, 13 Oct 2019 18:26:22 -0400 Received: by mail-pg1-x543.google.com with SMTP id e13so725763pga.7 for ; Sun, 13 Oct 2019 15:26:17 -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=mbGjA7d6AQiFvZB5+xEjn3eOcLNF0/a+vXYuP56z9BY=; b=nZP+XcmwTKiIjP+VQdUQS35Akek47LhX0vjgUdvW9MBW8veUyAwEYWWyEtVBfTpTVz KYtFL/+amHtfr0PHG0WD12tF4E9ojPviuGwNGeBJQlJDQZkdNAFXGHXUhEXjzP9mt4lw 1nEtGGcVM7w4s6gzXNr46b+pSFmNueNRB9evbUTXb4jiltB2Ak3jbER4aR1GZqQO3Wzf ir3KVN4o1hBC7miFEC6B5hQ8apPEaW9V5CSAn39J5Uqv8de6PAS9XTpLp4hvWRAK7T5z uPMe4g494P5q6CVfxcrSZ4EK2lnZUJ8XMTRYnRV9trvoFQ+ba+/M0S08H3JrPct5ZW0C PjCg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=mbGjA7d6AQiFvZB5+xEjn3eOcLNF0/a+vXYuP56z9BY=; b=Ppa2EMDuNe0t6xkAcSgduBUmp6bjtj7w/DWhtN6iFr8CdhvJF4UBuT2SZKlsVQt2no m+A90i2rDD1dc1+v7jk5iTtMJEIbIHjh03Okooho92JYEHsstQPDGH4OS0DW7/on0Owa rK8eb+gU79zvV39jXiUr8aw1hQwCNZS/bGKVr64mYjbp0zcNkpZH2iz/VX99qiVpkEwM ystlC4lGjxRk7Ww3S8aFrpG+L625gBePKA5H4ATsMp2TL/uX3ftuRix/+tLRTA+qNukY 040SR8bMRDzVaHoeownntIKmBRAtEgv3tBGo5EPEo9Q2RqpDVudakUKCZonqLmk/dPVF z8bw== X-Gm-Message-State: APjAAAWJ6zLmQCeqV/rhSiNUgNS97MEJejlzIpe4O1Vs95tN6oPC2VZb lSWq64PYQQWrR7r7k/LP/+m8hFRRY/4= X-Received: by 2002:aa7:9157:: with SMTP id 23mr30094311pfi.61.1571005576666; Sun, 13 Oct 2019 15:26:16 -0700 (PDT) Received: from localhost.localdomain (97-113-7-119.tukw.qwest.net. [97.113.7.119]) by smtp.gmail.com with ESMTPSA id d76sm15940571pfd.185.2019.10.13.15.26.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 13 Oct 2019 15:26:15 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PULL 23/23] cpus: kick all vCPUs when running thread=single Date: Sun, 13 Oct 2019 15:25:44 -0700 Message-Id: <20191013222544.3679-24-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191013222544.3679-1-richard.henderson@linaro.org> References: <20191013222544.3679-1-richard.henderson@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::543 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org, =?utf-8?q?Alex_Benn=C3=A9e?= Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: Alex Bennée qemu_cpu_kick is used for a number of reasons including to indicate there is work to be done. However when thread=single the old qemu_cpu_kick_rr_cpu only advanced the vCPU to the next executing one which can lead to a hang in the case that: a) the kick is from outside the vCPUs (e.g. iothread) b) the timers are paused (i.e. iothread calling run_on_cpu) To avoid this lets split qemu_cpu_kick_rr into two functions. One for the timer which continues to advance to the next timeslice and another for all other kicks. Message-Id: <20191001160426.26644-1-alex.bennee@linaro.org> Reviewed-by: Paolo Bonzini Reviewed-by: Richard Henderson Signed-off-by: Alex Bennée Signed-off-by: Richard Henderson --- cpus.c | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) -- 2.17.1 diff --git a/cpus.c b/cpus.c index d2c61ff155..bee7209134 100644 --- a/cpus.c +++ b/cpus.c @@ -949,8 +949,8 @@ static inline int64_t qemu_tcg_next_kick(void) return qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) + TCG_KICK_PERIOD; } -/* Kick the currently round-robin scheduled vCPU */ -static void qemu_cpu_kick_rr_cpu(void) +/* Kick the currently round-robin scheduled vCPU to next */ +static void qemu_cpu_kick_rr_next_cpu(void) { CPUState *cpu; do { @@ -961,6 +961,16 @@ static void qemu_cpu_kick_rr_cpu(void) } while (cpu != atomic_mb_read(&tcg_current_rr_cpu)); } +/* Kick all RR vCPUs */ +static void qemu_cpu_kick_rr_cpus(void) +{ + CPUState *cpu; + + CPU_FOREACH(cpu) { + cpu_exit(cpu); + }; +} + static void do_nothing(CPUState *cpu, run_on_cpu_data unused) { } @@ -993,7 +1003,7 @@ void qemu_timer_notify_cb(void *opaque, QEMUClockType type) static void kick_tcg_thread(void *opaque) { timer_mod(tcg_kick_vcpu_timer, qemu_tcg_next_kick()); - qemu_cpu_kick_rr_cpu(); + qemu_cpu_kick_rr_next_cpu(); } static void start_tcg_kick_timer(void) @@ -1828,9 +1838,11 @@ void qemu_cpu_kick(CPUState *cpu) { qemu_cond_broadcast(cpu->halt_cond); if (tcg_enabled()) { - cpu_exit(cpu); - /* NOP unless doing single-thread RR */ - qemu_cpu_kick_rr_cpu(); + if (qemu_tcg_mttcg_enabled()) { + cpu_exit(cpu); + } else { + qemu_cpu_kick_rr_cpus(); + } } else { if (hax_enabled()) { /*