From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.5 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_PASS, URIBL_BLOCKED,USER_AGENT_MUTT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1882CC43381 for ; Fri, 1 Mar 2019 09:24:43 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id DA5A3218AE for ; Fri, 1 Mar 2019 09:24:42 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="EQb4V1jX"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=kernel.org header.i=@kernel.org header.b="vbmJZX7e" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org DA5A3218AE Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+infradead-linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References: Message-ID:Subject:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=7ISItTimuUiLXGOnWftRTaL14qr76VAXouHKHJlRw20=; b=EQb4V1jXSPMqAT kWrARu91Ewq5bmYO1JtsyzOzRcydxbYdcCqknVGv2ckvWeyLVat3Q8cOuH7bv4qQ0h7ZthqL5/PxE F9wZGi/vKP1XYKfBPQ1mLCMDmk9XZ9X781I4vyTAktJsdGpBk51LiLIwNw2JQk56jDaYmKDg7VjK8 qstUVMuwzvZzkutUjxlWb2xnzSiKzjgrUfpapWTcJ4G458fy5oYFkYFdFnwovRrsgKNdAkQK+v690 scLimkgr1hxswkmIUNSdOfFPq5Laqtk156ysIHihqoWOm3zfzrdQwLBfe4A21kbtPChd2p3t58i/t /UP4W0yQZ5K0xirg1OiQ==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1gzePJ-0005Yh-2R; Fri, 01 Mar 2019 09:24:41 +0000 Received: from mail.kernel.org ([198.145.29.99]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1gzePE-0005YM-Qw for linux-arm-kernel@lists.infradead.org; Fri, 01 Mar 2019 09:24:38 +0000 Received: from dragon (61-216-91-114.HINET-IP.hinet.net [61.216.91.114]) (using TLSv1.2 with cipher DHE-RSA-AES128-SHA (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 4D9D02085A; Fri, 1 Mar 2019 09:24:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1551432276; bh=0O8z6GoCtmbSSLuQOHvzW6zcqwtzzo3D871lm2cY27o=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=vbmJZX7ebZ98VwtKcpP7cVW6uejzXVaHvTy83L3f9TBxos+o/w2A+9ncSDORAP1fW OOCXTvjLjPLz2ga/HU8pgW00Mb9CqcUW/Ne1gOsN5QXz7oogquq93rcbJ6mbCLUJD0 ZF2Bnoj6ZKJClPOE2SXTTP4x+LhnFEimJ9XxBZrQ= Date: Fri, 1 Mar 2019 17:23:42 +0800 From: Shawn Guo To: Kohji Okuno Subject: Re: [PATCH v3] ARM: imx6q: cpuidle: fix bug that CPU might not wake up at expected time Message-ID: <20190301092341.GP26041@dragon> References: <20190222.174953.431124434951497467.okuno.kohji@jp.panasonic.com> <20190226023413.19531-1-okuno.kohji@jp.panasonic.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20190226023413.19531-1-okuno.kohji@jp.panasonic.com> User-Agent: Mutt/1.5.21 (2010-09-15) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190301_012436_916695_FF4B0783 X-CRM114-Status: GOOD ( 22.47 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Fabio Estevam , Sascha Hauer , Pengutronix Kernel Team , linux-arm-kernel@lists.infradead.org, NXP Linux Team Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+infradead-linux-arm-kernel=archiver.kernel.org@lists.infradead.org Hi Kohji, On Tue, Feb 26, 2019 at 11:34:13AM +0900, Kohji Okuno wrote: > 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 tiemr) > > So, this fix changes CPU to return to 'WAIT_CLOCKED'. Just out of curiosity, how did you observe the bug? I'm trying to understand the impact of the bug. Shawn > > Signed-off-by: Kohji Okuno > --- > > Changes for v3: > - remove the braces for a single statement inside the if block. > > Changes for v2: > - change "master" variable name. > > arch/arm/mach-imx/cpuidle-imx6q.c | 27 ++++++++++----------------- > 1 file changed, 10 insertions(+), 17 deletions(-) > > diff --git a/arch/arm/mach-imx/cpuidle-imx6q.c b/arch/arm/mach-imx/cpuidle-imx6q.c > index bfeb25aaf9a2..326e870d7123 100644 > --- 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; > } > -- > 2.17.1 > _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel