Received: by 10.223.176.46 with SMTP id f43csp1503906wra; Wed, 24 Jan 2018 18:21:35 -0800 (PST) X-Google-Smtp-Source: AH8x227uywWMXvkVYdZ5ovEfCdcavKKUJiT3YxT88Zv6DePEBO0rtpLIi1AA6ehkS83PzybEJA31 X-Received: by 10.98.17.21 with SMTP id z21mr14422217pfi.86.1516846895117; Wed, 24 Jan 2018 18:21:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1516846895; cv=none; d=google.com; s=arc-20160816; b=XZiahXLEGH3QsNuCZFVaKE7eXsSuwTfvrJDAolVds29pw1KGnuzNNtCHzVv8bej6lw Q3ZnBxy3WkffdymRbqI5DyPf3V8ok7e22zn4KittTHtxZeth36LmsvNqOt8rzcJBAgq1 bRNEhBaSvjXLaSa1bozQys42CKezhNW6g7iClwwEYhBNprLKkxVEsRXKMLdBiymqkF3i tES3haKZYGLAuWdAU0unoyrm33ftLZMugwfxOy8sW3QBv6pslwUhYB9YTuLmj8uxTxr7 Q1xApq6uK75XxZRtWDpP2TSLTPXpsELPCp1lyn+YkQrRzBYOQbYfxWCong5S7pjR5FUU YCuA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature:arc-authentication-results; bh=W5CjH/CB2JMBwjbLqLFXFt87zCZ5mVLMp6Al/Xkkk4c=; b=sZZaIgKJHQtx4NjrYy92fHIQ6V32J3P+XDjdvTka4UF8Se7CpoQp4lEEo8YY+906z0 5JakFNpsXOHQ0/pkPXs5/X68mqyGXDocjyW1xhSLygJ/rDL9xlnRfqpDaYwFYqzVGZOo yZRaBqApGYl4eYRfzNZPvi2Kjm2de5FqMXsfkG0EL/W7QvFyqYDwesEpUs9fsL5cOBEo WsxeJiJvk6LuNRMhqL/WpIqiDBlNgtRrNWLmCdcWwEvk2ro3qjByijbBrfIRsNIlH+cq nWK+cUGfZtcFvFOxgXJAGvr5AkK2TPRcnpzKQeYhk41qg9th4WJt4pHnzNm3w4BlI8QD qAPQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=TBlwZgew; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a190si879580pgc.708.2018.01.24.18.21.20; Wed, 24 Jan 2018 18:21:35 -0800 (PST) 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=@gmail.com header.s=20161025 header.b=TBlwZgew; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752708AbeAYCU4 (ORCPT + 99 others); Wed, 24 Jan 2018 21:20:56 -0500 Received: from mail-pg0-f66.google.com ([74.125.83.66]:34475 "EHLO mail-pg0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752605AbeAYCUz (ORCPT ); Wed, 24 Jan 2018 21:20:55 -0500 Received: by mail-pg0-f66.google.com with SMTP id r19so4102310pgn.1 for ; Wed, 24 Jan 2018 18:20:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=W5CjH/CB2JMBwjbLqLFXFt87zCZ5mVLMp6Al/Xkkk4c=; b=TBlwZgewcHSwRXbfz6HpK/yuEa5cyBR6+3IEXNUFLpHSjGhFeQT/0PC4sDJjbOkmEZ bDU72Gz/5BtN7vYvQnczfFSTxXvFKnTx2RuB16nf9BD9Y9l2CLkSXj7NfbcgHTCXMqFo kxZMn2SiwWCDMbvNx5kCenadZKIPfl05eLJRe5CRT2FxOkZThwO+nAX1jECU0ZTVC5Mh ehsMkJp4seUk4qX1zhJWA1Qq2lN93HM0B8lntujCeR0RiN0ohYqzGnLPjXqhXTqMIZKF s0V/nStfrG2Azu3D2Kv4jHdb/tu9tvfE32lJbzUUA1/+eSZTw0IRXRgYGLEfQfnaakLd Z7Mw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=W5CjH/CB2JMBwjbLqLFXFt87zCZ5mVLMp6Al/Xkkk4c=; b=JQMjZ+e2LYeyghB31g10eavZ/6Xs1lLsMCdqi3tlUNLHjEVsNZQNKBwRO0ADBrtCad XZmczk7KH7U1nwvy5UgbX8Bs9RcLOF3k62hbVoVJWa4qgWFHwVeqZuAZ8pFl5Jt1NZgF lWTdqjWNknc2m3ES0irUB+USMNHWoGuTwakTUxg1NvyRvXCNiYTuZQgEHSiaxP+ABIXg TlmznI6v+f4OL3J8TrAWLoOilIyBNKukrUO/jTf+6nhoFjgivl3HP2c84qtiLMOUfJku iIdeV4ZFd8y7fz3aBFlvu7qkMKY7UMaDaVYRnnkYKxlqZgH5mUpaIsr0j7gvi3NiLrCI PB2w== X-Gm-Message-State: AKwxyteWVdMTIPgHSvI1v0V2Qsp16TdvVVmMLXjNexEwi3aT/zuuRI2F McRzM4sMCaIKC/PDgyAOsEs= X-Received: by 2002:a17:902:a24:: with SMTP id 33-v6mr9494120plo.141.1516846854307; Wed, 24 Jan 2018 18:20:54 -0800 (PST) Received: from shlinux2 (gate-zmy3.freescale.com. [192.88.167.1]) by smtp.googlemail.com with ESMTPSA id r30sm14592867pff.16.2018.01.24.18.20.50 (version=TLS1_2 cipher=AES128-SHA bits=128/128); Wed, 24 Jan 2018 18:20:53 -0800 (PST) Date: Thu, 25 Jan 2018 10:19:57 +0800 From: Peng Fan To: Lucas Stach Cc: Peng Fan , shawnguo@kernel.org, kernel@pengutronix.de, fabio.estevam@nxp.com, aisheng.dong@nxp.com, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Subject: Re: [PATCH 2/2] ARM: imx: cpuidle-imx6q: configure CCM to RUN mode when CPU is active Message-ID: <20180125021957.GA19344@shlinux2> References: <1514641999-20521-1-git-send-email-peng.fan@nxp.com> <1514641999-20521-2-git-send-email-peng.fan@nxp.com> <1516792585.6411.2.camel@pengutronix.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1516792585.6411.2.camel@pengutronix.de> User-Agent: Mutt/1.5.21 (2010-09-15) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Lucas, On Wed, Jan 24, 2018 at 12:16:25PM +0100, Lucas Stach wrote: >Hi Peng, > >Am Samstag, den 30.12.2017, 21:53 +0800 schrieb Peng Fan: >> There are two states in i.MX6Q cpuidle driver. >> state[1]: ARM WFI mode >> state[2]: i.MX6Q WAIT mode >> >> Take i.MX6DL as example, think out such a case: >> 1. CPU0/1 both run at normal mode >> 2. On CPU0, `sleep 1` is executed. And there are no workload on CPU1. >> 3. CPU0 first runs into state[2] and 'wfi' instruction. Switched to >> use >> ??????GPT broadcast. >> 4. CPU1 runs into state[2] and configure CCM to WAIT MODE, >> ??????then 'wfi' instruction. Now arm_clk and local timer clock are >> ??????shutdown. Switched to use GPT broadcast >> 5. GPT broadcast timer interrupt comes to GPC/GIC, then CPU0 wakes >> up. >> ??????CPU0 switched to use arm local timer. CPU1 is still sleeping. >> 6. No workload on CPU0, CPU0 runs into state[1]. But CCM register >> ??????is still not restored to Normal RUN mode. 'wfi' + CCM WAIT will >> ??????cause arm_clk and arm core clk. >> ??????Now CPU0 stops, which is not correct. >> >> So, need to make sure CCM configured to RUN mode when any cpu exit >> state[2]. >> >> In this patch, >> When CPU exits state[2], it configures CCM to RUN mode. >> When all CPUs enters state[2], the last CPU needs to check >> whether it's ok to configure CCM to WAIT mode or not. > >To me this patch seems like we are adding duct tape to fix the issue.?? > >It seems the whole master_lock thing doesn't properly work when the CPU >that is woken up by the timer broadcast isn't the last CPU going to >sleep. We should probably try to come up with a way to simplify this >whole master dance, instead of adding yet more complexity. The master_lock is used to protect multiple CPUS runs into State[1]. It could not be used to protect the CPU runs into State[0]. The patch is to make sure that before arm clk turned off, need to check whether all the cpus are in State[1]. And the cpu who first wake up from State[1], need to configure CCM to RUN mode. This patch has been integrated into vendor kernel and fixed customer's issue. I could not think out of a better solution to restructure the master lock, and this may introduce new issues. Thanks, Peng. > >Regards, >Lucas > >> Signed-off-by: Peng Fan >> --- >> >> V1: >> ??This is to upstream patch: >> ??http://git.freescale.com/git/cgit.cgi/imx/linux-imx.git/commit/?h=im >> x_4.9.11_1.0.0_ga&id=0d980646ee068b92db71fd5e4e4efcbc33749cbd >> >> ??arch/arm/mach-imx/cpuidle-imx6q.c | 3 +++ >> ??1 file changed, 3 insertions(+) >> >> diff --git a/arch/arm/mach-imx/cpuidle-imx6q.c b/arch/arm/mach- >> imx/cpuidle-imx6q.c >> index bfeb25aaf9a2..4d342e2fdfe6 100644 >> --- a/arch/arm/mach-imx/cpuidle-imx6q.c >> +++ b/arch/arm/mach-imx/cpuidle-imx6q.c >> @@ -30,6 +30,8 @@ static int imx6q_enter_wait(struct cpuidle_device >> *dev, >> ?? if (!spin_trylock(&master_lock)) >> ?? goto idle; >> ?? imx6_set_lpm(WAIT_UNCLOCKED); >> + if (atomic_read(&master) != num_online_cpus()) >> + imx6_set_lpm(WAIT_CLOCKED); >> ?? cpu_do_idle(); >> ?? imx6_set_lpm(WAIT_CLOCKED); >> ?? spin_unlock(&master_lock); >> @@ -41,6 +43,7 @@ static int imx6q_enter_wait(struct cpuidle_device >> *dev, >> ??done: >> ?? atomic_dec(&master); >> ?? >> + imx6_set_lpm(WAIT_CLOCKED); >> ?? return index; >> ??} >> ?? --