From patchwork Thu Aug 6 15:32:06 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Lezcano X-Patchwork-Id: 52011 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-la0-f71.google.com (mail-la0-f71.google.com [209.85.215.71]) by patches.linaro.org (Postfix) with ESMTPS id 2AB6622A15 for ; Thu, 6 Aug 2015 15:32:53 +0000 (UTC) Received: by lagz9 with SMTP id z9sf9829629lag.3 for ; Thu, 06 Aug 2015 08:32:52 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:in-reply-to:references:sender:precedence:list-id :x-original-sender:x-original-authentication-results:mailing-list :list-post:list-help:list-archive:list-unsubscribe; bh=k12I2G1R10s0+dIdnSb2S9iDOUdGF/iyOrt7A7fWHXI=; b=UJrNx5J+2dOeMv4nSgtZOugQm0YQBJYFRfkJIGtvjn+kSFJulRn8rMPcdzRMgcrQ1B 1fwyLEi/ET26h6WhZQdw4ADRQl9vNJ3uj2bHYTSEvY8b6wh80WFJSPyK8ExNkGfoONV5 ZYsdMLnDWjQXRzRgKZ4EThKSWYpuEtFavunso9XWN4N9DgXA+0/NPMROP3TnHcHfVE4W ULoSJkabAtKjO2hDdLaGTpPvCTDMOgNXCRKZzDisz9QR5ZOX2ZBxSOFWSdkhSV5GMTWf 7bVlKIPB+bPnGoyUmlQ9X8qxjxizWqZDa3odzZUi+NA26AAA0/6c0A9A+bXMd2/qIQTo PCqw== X-Gm-Message-State: ALoCoQns43iKVEeYG0rvfUOPrYhHfYQQI1B5VViJW0cCjbL9rMU5bms2RNYxngc0ML8WYo8Kklqz X-Received: by 10.180.106.10 with SMTP id gq10mr1141717wib.0.1438875172114; Thu, 06 Aug 2015 08:32:52 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.37.196 with SMTP id a4ls313162lak.27.gmail; Thu, 06 Aug 2015 08:32:51 -0700 (PDT) X-Received: by 10.152.2.2 with SMTP id 2mr2735192laq.58.1438875171920; Thu, 06 Aug 2015 08:32:51 -0700 (PDT) Received: from mail-la0-f52.google.com (mail-la0-f52.google.com. [209.85.215.52]) by mx.google.com with ESMTPS id ai9si5131317lbc.98.2015.08.06.08.32.51 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 06 Aug 2015 08:32:51 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.52 as permitted sender) client-ip=209.85.215.52; Received: by labow3 with SMTP id ow3so51615286lab.1 for ; Thu, 06 Aug 2015 08:32:51 -0700 (PDT) X-Received: by 10.112.133.72 with SMTP id pa8mr2605179lbb.117.1438875171447; Thu, 06 Aug 2015 08:32:51 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.7.198 with SMTP id l6csp1018178lba; Thu, 6 Aug 2015 08:32:50 -0700 (PDT) X-Received: by 10.67.15.67 with SMTP id fm3mr4436412pad.114.1438875169497; Thu, 06 Aug 2015 08:32:49 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id jm1si12169335pbb.85.2015.08.06.08.32.48; Thu, 06 Aug 2015 08:32:49 -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; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932261AbbHFPcr (ORCPT + 28 others); Thu, 6 Aug 2015 11:32:47 -0400 Received: from mail-wi0-f172.google.com ([209.85.212.172]:34909 "EHLO mail-wi0-f172.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932235AbbHFPco (ORCPT ); Thu, 6 Aug 2015 11:32:44 -0400 Received: by wibxm9 with SMTP id xm9so27582241wib.0 for ; Thu, 06 Aug 2015 08:32:43 -0700 (PDT) X-Received: by 10.194.200.42 with SMTP id jp10mr4841571wjc.66.1438875163832; Thu, 06 Aug 2015 08:32:43 -0700 (PDT) Received: from mai.telefonica.net (185.Red-213-96-199.staticIP.rima-tde.net. [213.96.199.185]) by smtp.gmail.com with ESMTPSA id ej5sm10057510wjd.22.2015.08.06.08.32.42 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 06 Aug 2015 08:32:43 -0700 (PDT) From: Daniel Lezcano To: mingo@kernel.org, tglx@linutronix.de Cc: linux-kernel@vger.kernel.org, Geert Uytterhoeven , Laurent Pinchart Subject: [PATCH 2/2] clockevents/drivers/sh_cmt: Only perform clocksource suspend/resume if enabled Date: Thu, 6 Aug 2015 17:32:06 +0200 Message-Id: <1438875126-12596-2-git-send-email-daniel.lezcano@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1438875126-12596-1-git-send-email-daniel.lezcano@linaro.org> References: <55C37D4A.6000302@linaro.org> <1438875126-12596-1-git-send-email-daniel.lezcano@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: daniel.lezcano@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.52 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , From: Geert Uytterhoeven Currently the sh_cmt clocksource timer is disabled or enabled unconditionally on clocksource suspend resp. resume, even if a better clocksource is present (e.g. arch_sys_counter) and the sh_cmt clocksource is not enabled. As sh_cmt is a syscore device when its timer is enabled, this may lead to a genpd.prepared_count imbalance in the presence of PM Domains, which may cause a lock-up during reboot after s2ram. During suspend: - pm_genpd_prepare() is called for all non-syscore devices (incl. sh_cmt), increasing genpd.prepared_count for each device, - clocksource.suspend() is called for all clocksource devices, - sh_cmt_clocksource_suspend() calls sh_cmt_stop(), which is a no-op as the clocksource was not enabled. During resume: - clocksource.resume() is called for all clocksource devices, - sh_cmt_clocksource_resume() calls sh_cmt_start(), which enables the clocksource timer, and turns sh_cmt into a syscore device, - pm_genpd_complete() is called for all non-syscore devices (excl. sh_cmt now!), decreasing genpd.prepared_count for each device but sh_cmt. Now genpd.prepared_count of the PM Domain containing sh_cmt is still 1 instead of zero. On subsequent suspend/resume cycles, sh_cmt is still a syscore device, hence it's skipped for pm_genpd_{prepare,complete}(), keeping the imbalance of genpd.prepared_count at 1. During reboot: - platform_drv_shutdown() is called for any platform device that has a driver with a .shutdown() method (only rcar-dmac on R-Car Gen2), - platform_drv_shutdown() calls dev_pm_domain_detach(), which calls genpd_dev_pm_detach(), - genpd_dev_pm_detach() keeps calling pm_genpd_remove_device() until it doesn't return -EAGAIN[*], - If the device is part of the same PM Domain as sh_cmt, pm_genpd_remove_device() always fails with -EAGAIN due to genpd.prepared_count > 0. - Infinite loop in genpd_dev_pm_detach()[*]. [*] Commit 93af5e9354432828 ("PM / Domains: Avoid infinite loops in attach/detach code") already limited the number of loop iterations, avoiding the lock-up. To fix this, only disable or enable the clocksource timer on clocksource suspend resp. resume if the clocksource was enabled. This was tested on r8a7791/koelsch with the CPG Clock Domain: - using arch_sys_counter as the clocksource, which is the default, and which showed the problem, - using sh_cmt as a clocksource ("echo ffca0000.timer > \ /sys/devices/system/clocksource/clocksource0/current_clocksource"), which behaves the same as before. Signed-off-by: Geert Uytterhoeven Acked-by: Laurent Pinchart Signed-off-by: Daniel Lezcano --- drivers/clocksource/sh_cmt.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/drivers/clocksource/sh_cmt.c b/drivers/clocksource/sh_cmt.c index b8ff3c6..c96de14 100644 --- a/drivers/clocksource/sh_cmt.c +++ b/drivers/clocksource/sh_cmt.c @@ -661,6 +661,9 @@ static void sh_cmt_clocksource_suspend(struct clocksource *cs) { struct sh_cmt_channel *ch = cs_to_sh_cmt(cs); + if (!ch->cs_enabled) + return; + sh_cmt_stop(ch, FLAG_CLOCKSOURCE); pm_genpd_syscore_poweroff(&ch->cmt->pdev->dev); } @@ -669,6 +672,9 @@ static void sh_cmt_clocksource_resume(struct clocksource *cs) { struct sh_cmt_channel *ch = cs_to_sh_cmt(cs); + if (!ch->cs_enabled) + return; + pm_genpd_syscore_poweron(&ch->cmt->pdev->dev); sh_cmt_start(ch, FLAG_CLOCKSOURCE); }