From nobody Fri May 3 16:26:49 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1569948512; cv=none; d=zoho.com; s=zohoarc; b=DSuQ7gnKEm8ZSadACXBaSn/0LjsYHA58X84AyUgOptjVsRyvrgpJtDq3rAMGPkRtY2FLR+ERG1dUd58+UhiFTBddsf5odU7V6CYkSjyeU2TncI8SC3wlwYY3c4m52MwnFiae0ymefmVbXIYhTlIsk8DBDHNY9b12a35PKyliqMs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1569948512; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To:ARC-Authentication-Results; bh=wc5z3pSXo6Lrt9lS3SIZHRF6PDH8oo6qYuLp22beZMA=; b=PD9q91gCyeuIUTQEzN3puemFJAlRpwj1HYfd+18yBGBwEPrCTCxRQUCD6a2yECE9+gKwwsfsgMYugK0zFEr9ofmzEpeo0D5ar1CoIRVwz6SmxWnagPU2rmOpIic6nDjc6UMxxbihO7w+t3L6Fs9B4CPS7jIxe7CxnM0JedVhZ+Q= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1569948512196488.908671411823; Tue, 1 Oct 2019 09:48:32 -0700 (PDT) Received: from localhost ([::1]:44882 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iFLKA-0005Bj-EU for importer@patchew.org; Tue, 01 Oct 2019 12:48:30 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:52058) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iFKdj-0003Te-Tq for qemu-devel@nongnu.org; Tue, 01 Oct 2019 12:04:41 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iFKdi-0004ws-JC for qemu-devel@nongnu.org; Tue, 01 Oct 2019 12:04:39 -0400 Received: from mail-wm1-x342.google.com ([2a00:1450:4864:20::342]:39093) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1iFKdi-0004vv-C3 for qemu-devel@nongnu.org; Tue, 01 Oct 2019 12:04:38 -0400 Received: by mail-wm1-x342.google.com with SMTP id v17so3851915wml.4 for ; Tue, 01 Oct 2019 09:04:38 -0700 (PDT) Received: from zen.linaroharston ([51.148.130.216]) by smtp.gmail.com with ESMTPSA id q22sm3824211wmj.5.2019.10.01.09.04.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 01 Oct 2019 09:04:36 -0700 (PDT) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id 3AEC21FF87; Tue, 1 Oct 2019 17:04:35 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=wc5z3pSXo6Lrt9lS3SIZHRF6PDH8oo6qYuLp22beZMA=; b=fuxXBH2DNcPm8uAZiiuSCbtNXzZ0rD3T1UOqPrLwrE2ptU9u37CMhIGvae7NnKkxEd 6L5G9yn+QDX1PwzvY9+lyj0K2lqknssdIW71HUWN2dMUpoJ45AELOZF2k4gz05sXlkxt BiJSujq9FHjOOHzOppOQBxaxITDQu+BktTJL7UgBh+BWYDp0+gQt7ZjTaooVrFCwm8nF 5v37ge5NNejh9b8NKD0xDJvKSzhV3M5JFDIh+ny51OMQGUH5+MHNj8QECPNDCLV1g5Ra RGzfLihl2edzo6uZVxNOz7PhVVFlmSxlJT67MMLV/+/A+LPlHqpo+fYg5BFTxEXv0asN GdSQ== 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:mime-version :content-transfer-encoding; bh=wc5z3pSXo6Lrt9lS3SIZHRF6PDH8oo6qYuLp22beZMA=; b=A1+Bik8px8P2cDtY94ZPJvo5+W/BHKR71YEaIyizUd0K6NqkXgPExNLx0bZIgTv+MK YoY24pVrqoejObZjIonLp3vfwuG1kO49Ci4a3hJqik26FbugwH4U9Py311UEk2NnBRT2 UIhUF42hR74rvzxtXCchqbRVaLcDaodsudS92k05ucWU4IXa5u5zmJmrUWV2itciipS5 1OsfdODgxz6pJ/Dw85no02EFbXWPuC28kIBnGshYgJaKCoXLmLcFxXLUjnqJSzsObi81 brxnNo1Js3uygg6y/4EUFswRXTCcxx3Cp2mpn9OhAmjsx/YRSKVTTGiLLcOKVbtdgTH/ lKZg== X-Gm-Message-State: APjAAAWa+r9TH6W6Ol0QU8BJi0EQRv8rzDSJLFeNpst6VaqsMeUXjJBh tzvkzRfVEkLyM2gl2N/pWG52EQ== X-Google-Smtp-Source: APXvYqy1wKzgSYqX9NOM9aUc0HrLKbx6AfQUFcGbVEPt8DQ1CtIgooevm1YJdgQ7VVECXnx/QHonTA== X-Received: by 2002:a1c:cf8c:: with SMTP id f134mr4581453wmg.174.1569945876915; Tue, 01 Oct 2019 09:04:36 -0700 (PDT) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: qemu-devel@nongnu.org Subject: [PATCH] cpus: kick all vCPUs when running thread=single Date: Tue, 1 Oct 2019 17:04:26 +0100 Message-Id: <20191001160426.26644-1-alex.bennee@linaro.org> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::342 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: Paolo Bonzini , Richard Henderson , Doug Gale , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Peter Maydell Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) qemu_cpu_kick is used for a number of reasons including to indicate there is work to be done. However when thread=3Dsingle 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. Signed-off-by: Alex Benn=C3=A9e Cc: Doug Gale Cc: Paolo Bonzini Cc: Peter Maydell Reviewed-by: Paolo Bonzini --- cpus.c | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) 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; } =20 -/* 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 !=3D atomic_mb_read(&tcg_current_rr_cpu)); } =20 +/* 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(); } =20 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()) { /* --=20 2.20.1