Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp519022yba; Mon, 1 Apr 2019 10:56:14 -0700 (PDT) X-Google-Smtp-Source: APXvYqzCsIvh2UfGu8nhjhMT8Sri9cc2hc8fiKvN7hkQIH2i6YIBCN+F1m3yFdBMWXnB3h0Y3IvA X-Received: by 2002:a65:6241:: with SMTP id q1mr34528717pgv.244.1554141374038; Mon, 01 Apr 2019 10:56:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1554141374; cv=none; d=google.com; s=arc-20160816; b=qfW8BgDvzR6FL0Ld2Nk6bnm3M0p5hQJ6h2MsxcpdxscsSSaW2rnTk/4z0PLW32GaTl CR9LEGLaXDNF4KF1WSv+7XFy4K55xkUYwjSSatVRNCeP5xuykGqU1NJ5f5RPxGOppv4T 300CUrDVQzHEE75+66I/Gh+QZj3w+8grcvHy54ify+ecPvm0d8ufCsfnDxcRaV8h7m+K 7M61XfZGMpMVJ8naRTV7AThiKYFaH3oiHVJSuXLtZi5bCfNvEK99qSKbtUh2zVU+lUMd mGeVKaDdYpdBmw/wrIdfqvC52GyGCAf9U6U9my/jTp5QokI1tHR/6RjZ3fV5p5dBXjGl oaMg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=Kp18jzMDrZWoXhaAJw1wX1XScE5HprsHNhHGGCVqiwo=; b=epI/+m1QAxVJ+HxVE0cd3d8rwoPTpkvoBaVN0bwrIp4jq7PWY0ENRoE9bUDxfPsr37 QNghwI5LjuoY6+9EZAJsXlUC1XLbaSAXuwH6OjTmupeGy5u8wtC/i4FLIW857oVGs8wd z63yd3o5qoXJLK5J6zvbuSOp6CzGDIda/NnLCRKqvSAhUyC6Mh2ZIlBecNzZbxeaQsvi wryWLcZ1ldUOEKKtGVVnTT4NzKhRn1Rw6AbwsORddkP5E3Xp8eAF7K1Ew4EPtyS2llqg DaAhgTCQB1yDX5y4Fozerx8YRsNpGb1UESoPB4r4VgQJz970gKTkAgTvnHNeL3FzCYnz fNjA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=CtPwSY41; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id m184si9496124pfb.73.2019.04.01.10.55.58; Mon, 01 Apr 2019 10:56:14 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=CtPwSY41; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732042AbfDARXC (ORCPT + 99 others); Mon, 1 Apr 2019 13:23:02 -0400 Received: from mail.kernel.org ([198.145.29.99]:52568 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731384AbfDARW7 (ORCPT ); Mon, 1 Apr 2019 13:22:59 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 479DD206C0; Mon, 1 Apr 2019 17:22:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1554139378; bh=s71LuXgN/mXiSJaGg8Fmh2iNcvTcaI7KssrafnqDAQY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=CtPwSY41V0ehRE5eRnCYjB5N+BjC6ooJXrdbpz+AriZp7bFf/9mtbsPZsKhHuRRAD cLj+OP7v3c4RNFvJHjQ9pgoPE7B78/FwrrBeOpH5BXGTbPidbG92kecIwNWG1gl0Af EI7/HPClw8T60RgO9B3VhZdtY9FFSCRBg/2EFOhk= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Kohji Okuno , Shawn Guo Subject: [PATCH 4.14 059/107] ARM: imx6q: cpuidle: fix bug that CPU might not wake up at expected time Date: Mon, 1 Apr 2019 19:02:14 +0200 Message-Id: <20190401170051.111973225@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190401170045.246405031@linuxfoundation.org> References: <20190401170045.246405031@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review X-Patchwork-Hint: ignore MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.14-stable review patch. If anyone has any objections, please let me know. ------------------ From: Kohji Okuno commit 91740fc8242b4f260cfa4d4536d8551804777fae upstream. In the current cpuidle implementation for i.MX6q, the CPU that sets 'WAIT_UNCLOCKED' and the CPU that returns to 'WAIT_CLOCKED' are always the same. While the CPU that sets 'WAIT_UNCLOCKED' is in IDLE state of "WAIT", if the other CPU wakes up and enters IDLE state of "WFI" istead of "WAIT", this CPU can not wake up at expired time. Because, in the case of "WFI", the CPU must be waked up by the local timer interrupt. But, while 'WAIT_UNCLOCKED' is set, the local timer is stopped, when all CPUs execute "wfi" instruction. As a result, the local timer interrupt is not fired. In this situation, this CPU will wake up by IRQ different from local timer. (e.g. broacast timer) So, this fix changes CPU to return to 'WAIT_CLOCKED'. Signed-off-by: Kohji Okuno Fixes: e5f9dec8ff5f ("ARM: imx6q: support WAIT mode using cpuidle") Cc: Signed-off-by: Shawn Guo Signed-off-by: Greg Kroah-Hartman --- arch/arm/mach-imx/cpuidle-imx6q.c | 27 ++++++++++----------------- 1 file changed, 10 insertions(+), 17 deletions(-) --- a/arch/arm/mach-imx/cpuidle-imx6q.c +++ b/arch/arm/mach-imx/cpuidle-imx6q.c @@ -16,30 +16,23 @@ #include "cpuidle.h" #include "hardware.h" -static atomic_t master = ATOMIC_INIT(0); -static DEFINE_SPINLOCK(master_lock); +static int num_idle_cpus = 0; +static DEFINE_SPINLOCK(cpuidle_lock); static int imx6q_enter_wait(struct cpuidle_device *dev, struct cpuidle_driver *drv, int index) { - if (atomic_inc_return(&master) == num_online_cpus()) { - /* - * With this lock, we prevent other cpu to exit and enter - * this function again and become the master. - */ - if (!spin_trylock(&master_lock)) - goto idle; + spin_lock(&cpuidle_lock); + if (++num_idle_cpus == num_online_cpus()) imx6_set_lpm(WAIT_UNCLOCKED); - cpu_do_idle(); - imx6_set_lpm(WAIT_CLOCKED); - spin_unlock(&master_lock); - goto done; - } + spin_unlock(&cpuidle_lock); -idle: cpu_do_idle(); -done: - atomic_dec(&master); + + spin_lock(&cpuidle_lock); + if (num_idle_cpus-- == num_online_cpus()) + imx6_set_lpm(WAIT_CLOCKED); + spin_unlock(&cpuidle_lock); return index; }