Received: by 2002:a05:6a10:d5a5:0:0:0:0 with SMTP id gn37csp1339286pxb; Thu, 7 Oct 2021 05:58:13 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz7D3/7bU5pxj2lmGilnewr/kukY3LhychTi5gOVc80iJ1bpzZhgiI661eiP6fohVd+QIeV X-Received: by 2002:a17:906:f2cd:: with SMTP id gz13mr5543636ejb.278.1633611493718; Thu, 07 Oct 2021 05:58:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1633611493; cv=none; d=google.com; s=arc-20160816; b=Jy+doi+mpLD40ipZQx9iAYxCaUyNHzdCPUFUOHzG1hhp6w1GjsF2bUFLLhimZ2uikU 7k/5koD+ioBI9xboY/Pk2AZ5FmZIQNSt1resdi5sYVlj8psRiVyt8nf5qnxXpSBKT6Sh MdBLGNFuBxXHnEwAV8yjxBFeGMGtH4N31avJGRD3lSv4w9xRaoN48qIoe4ewSZbn6yx4 TFQObXVcdMyFxKL3dT3rT+VFBCiFi7y0HFArVWYW24tukbKmlfBCXAV2WOCYqdkkXY2s n9SEAt1hAUAeTjj/ikhhE1OBNPwmF532WjYczCXmS5E93xeh/c3d8CeoJYPJqX2J/nQ0 CVCQ== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=Eh9LuTlDkpTPqTny36Xjff8x9vwoQYh0H6br1oICLUY=; b=FBaTPd0ZLp6s2mOLJJ/9LdVbx5mQkD0xZAznvixkkuIH61w+drTKxYHr5FiHGSHPqB QeaKsjyEFsvmWzuQLoboO+c0kwoiWRlKGz+w+JH42C/3a7tODm/w8gJR2p24Pt3vH1Wg snUSB4v3OHmOwBQq1mk6lBT3by7R+/Ru8pjWu+Pdyuq88mY5yIZ37QpvmBzRQOErguCD X5E/Dc2hL6Gr3S+gid+1Ue7tM8FvSGfUqrHjCPmDq6dn6hs5yhu5wExuWmvPxA3Ce/U4 j+OigcihdgyzJ088fQodT5sbfKaYNiZKPRcj1H+2wQPyJBKVT/ONE4TXioMYxF8AA+dQ z99A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=f2VWXTLc; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id x16si17372764edd.401.2021.10.07.05.57.50; Thu, 07 Oct 2021 05:58:13 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=f2VWXTLc; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241253AbhJGMKS (ORCPT + 99 others); Thu, 7 Oct 2021 08:10:18 -0400 Received: from mail.kernel.org ([198.145.29.99]:49866 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241194AbhJGMKA (ORCPT ); Thu, 7 Oct 2021 08:10:00 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id B020260F90; Thu, 7 Oct 2021 12:08:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1633608485; bh=uyhVJBEbisAuVsjetSktVzFw9MpbNh+Rd6PTR+/pxCA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=f2VWXTLcitiYQ7aTjjtcFsMX9gAcZkmYMVuq21sOx/JA1VlEZBll9bSEEAQxCkPl9 EqinqhLQ9JIC83uzsFgMwJKokpqn1R6puEjDtZG7ZvsOGCumCUvKP8fnEUyLyRX5+Y Qag/SbNVZ8HOTmBrQV+kPkdGCIbbhn9HoujXIJ4f/mi6zqxPnSPwVVxuekXzaXpPkv OyHprTQtRlj0vdE7KAB4x7KCl1vK6gOYOeT7nwmB7pc+deK85OKEWSkz2x45ZxOcvh SPHoJ9ouRdn1uIcQY4fX+YTkUGaV5kXGAcyXykXrr6hHDp3o9eOxa7nnvw14rCEMgR PJOvG1OpqJ1mg== Received: by mail.kernel.org with local (Exim 4.94.2) (envelope-from ) id 1mYSBv-005QTV-KN; Thu, 07 Oct 2021 14:08:03 +0200 From: Mauro Carvalho Chehab To: Michael Turquette , Stephen Boyd Cc: linuxarm@huawei.com, mauro.chehab@huawei.com, Mauro Carvalho Chehab , Manivannan Sadhasivam , linux-clk@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 1/2] clk: wait for extra time before disabling unused clocks Date: Thu, 7 Oct 2021 14:06:54 +0200 Message-Id: <884bf18a34b76208f80284de3a6ff8fa48cec178.1633607765.git.mchehab+huawei@kernel.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: Mauro Carvalho Chehab Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On some tests with HiKey970, with several drivers compiled as modules, clk_disable_unused() has been called too early, before the init code from the drivers built as module to be called. If the system is left to disable unused clocks, those are the last messages at the console: [ 22.348592] initcall acpi_gpio_handle_deferred_request_irqs+0x0/0xa8 returned 0 after 1 usecs, irqs_disabled() 0 [ 22.366973] calling fb_logo_late_init+0x0/0x20 @ 1 irqs_disabled() 0 [ 22.373432] initcall fb_logo_late_init+0x0/0x20 returned 0 after 1 usecs, irqs_disabled() 0 [ 22.381800] calling clk_disable_unused+0x0/0xe8 @ 1 irqs_disabled() 0 ================== Preventing clk_disable_unused to be called, there are several other initcall logs after it: [ 22.340305] calling acpi_gpio_handle_deferred_request_irqs+0x0/0xa8 @ 1 irqs_disabled() 0 [ 22.348594] dwmmc_k3 fc183000.dwmmc2: card claims to support voltages below defined range [ 22.348592] initcall acpi_gpio_handle_deferred_request_irqs+0x0/0xa8 returned 0 after 1 usecs, irqs_disabled() 0 [ 22.366973] calling fb_logo_late_init+0x0/0x20 @ 1 irqs_disabled() 0 [ 22.373432] initcall fb_logo_late_init+0x0/0x20 returned 0 after 1 usecs, irqs_disabled() 0 [ 22.356984] initcall clk_disable_unused+0x0/0xe8 returned 0 after 117 usecs, irqs_disabled() 0 ================== [ 22.372335] initcall imx_clk_disable_uart+0x0/0x88 returned 0 after 1 usecs, irqs_disabled() 0 [ 22.387946] initcall regulator_init_complete+0x0/0x58 returned 0 after 2 usecs, irqs_disabled() 0 [ 22.404163] initcall of_platform_sync_state_init+0x0/0x20 returned 0 after 1 usecs, irqs_disabled() 0 [ 22.426508] initcall alsa_sound_last_init+0x0/0x90 returned 0 after 6239 usecs, irqs_disabled() 0 [ 22.703071] initcall inet6_init+0x0/0x358 [ipv6] returned 0 after 13341 usecs, irqs_disabled() 0 [ 22.723861] initcall xt_init+0x0/0x1000 [x_tables] returned 0 after 8 usecs, irqs_disabled() 0 [ 22.744405] initcall ip_tables_init+0x0/0x1000 [ip_tables] returned 0 after 23 usecs, irqs_disabled() 0 [ 23.467003] initcall fuse_init+0x0/0x154 [fuse] returned 0 after 392 usecs, irqs_disabled() 0 [ 23.537742] initcall drm_core_init+0x0/0x1000 [drm] returned 0 after 122 usecs, irqs_disabled() 0 [ 24.519076] initcall rfkill_init+0x0/0x12c [rfkill] returned 0 after 15654 usecs, irqs_disabled() 0 [ 24.622168] initcall hi3670_pcie_phy_driver_init+0x0/0x1000 [phy_hi3670_pcie] returned 0 after 836 usecs, irqs_disabled() 0 [ 24.665100] initcall hi3670_phy_driver_init+0x0/0x1000 [phy_hi3670_usb3] returned 0 after 1888 usecs, irqs_disabled() 0 [ 24.694668] initcall typec_init+0x0/0x1000 [typec] returned 0 after 89 usecs, irqs_disabled() 0 [ 24.732557] initcall cpu_feature_match_ASIMD_init+0x0/0x1000 [crct10dif_ce] returned 0 after 8838 usecs, irqs_disabled() 0 [ 24.746636] initcall tcpci_i2c_driver_init+0x0/0x1000 [tcpci] returned 0 after 8607 usecs, irqs_disabled() 0 [ 24.774541] initcall hisi_hikey_usb_driver_init+0x0/0x1000 [hisi_hikey_usb] returned 0 after 35860 usecs, irqs_disabled() 0 [ 24.892957] initcall rt1711h_i2c_driver_init+0x0/0x1000 [tcpci_rt1711h] returned 0 after 21500 usecs, irqs_disabled() 0 [ 24.956528] initcall wl1271_init+0x0/0x1000 [wlcore_sdio] returned 0 after 83582 usecs, irqs_disabled() 0 [ 25.039853] initcall cfg80211_init+0x0/0xdc [cfg80211] returned 0 after 26291 usecs, irqs_disabled() 0 [ 25.118288] initcall ieee80211_init+0x0/0x40 [mac80211] returned 0 after 15 usecs, irqs_disabled() 0 [ 25.335203] initcall wl18xx_driver_init+0x0/0x1000 [wl18xx] returned 0 after 134423 usecs, irqs_disabled() 0 [ 26.277300] initcall ecdh_init+0x0/0xd0 [ecdh_generic] returned 0 after 302 usecs, irqs_disabled() 0 [ 26.435409] initcall bt_init+0x0/0xcc [bluetooth] returned 0 after 63051 usecs, irqs_disabled() 0 [ 26.508033] initcall btusb_driver_init+0x0/0x1000 [btusb] returned 0 after 305 usecs, irqs_disabled() 0 [ 27.333049] initcall kirin_pcie_driver_init+0x0/0x1000 [pcie_kirin] returned 0 after 805983 usecs, irqs_disabled() 0 So, just like regulator_init_complete code at drivers/regulator/core.c does, we need to also delay the call to the actual logic which disables the unused clocks. Signed-off-by: Mauro Carvalho Chehab --- To mailbombing on a large number of people, only mailing lists were C/C on the cover. See [PATCH 0/2] at: https://lore.kernel.org/all/cover.1633607765.git.mchehab+huawei@kernel.org/ drivers/clk/clk.c | 51 +++++++++++++++++++++++++++++------------------ 1 file changed, 32 insertions(+), 19 deletions(-) diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c index 65508eb89ec9..d2e192e243b2 100644 --- a/drivers/clk/clk.c +++ b/drivers/clk/clk.c @@ -21,6 +21,7 @@ #include #include #include +#include #include "clk.h" @@ -1206,7 +1207,7 @@ static void clk_core_disable_unprepare(struct clk_core *core) clk_core_unprepare_lock(core); } -static void __init clk_unprepare_unused_subtree(struct clk_core *core) +static void clk_unprepare_unused_subtree(struct clk_core *core) { struct clk_core *child; @@ -1236,7 +1237,7 @@ static void __init clk_unprepare_unused_subtree(struct clk_core *core) clk_pm_runtime_put(core); } -static void __init clk_disable_unused_subtree(struct clk_core *core) +static void clk_disable_unused_subtree(struct clk_core *core) { struct clk_core *child; unsigned long flags; @@ -1290,30 +1291,42 @@ static int __init clk_ignore_unused_setup(char *__unused) } __setup("clk_ignore_unused", clk_ignore_unused_setup); +static void __clk_disable_unused(struct work_struct *w) +{ + struct clk_core *core; + + clk_prepare_lock(); + + hlist_for_each_entry(core, &clk_root_list, child_node) + clk_disable_unused_subtree(core); + + hlist_for_each_entry(core, &clk_orphan_list, child_node) + clk_disable_unused_subtree(core); + + hlist_for_each_entry(core, &clk_root_list, child_node) + clk_unprepare_unused_subtree(core); + + hlist_for_each_entry(core, &clk_orphan_list, child_node) + clk_unprepare_unused_subtree(core); + + clk_prepare_unlock(); +} +DECLARE_DELAYED_WORK(disable_unused, __clk_disable_unused); + static int __init clk_disable_unused(void) { - struct clk_core *core; - if (clk_ignore_unused) { pr_warn("clk: Not disabling unused clocks\n"); return 0; } - clk_prepare_lock(); - - hlist_for_each_entry(core, &clk_root_list, child_node) - clk_disable_unused_subtree(core); - - hlist_for_each_entry(core, &clk_orphan_list, child_node) - clk_disable_unused_subtree(core); - - hlist_for_each_entry(core, &clk_root_list, child_node) - clk_unprepare_unused_subtree(core); - - hlist_for_each_entry(core, &clk_orphan_list, child_node) - clk_unprepare_unused_subtree(core); - - clk_prepare_unlock(); + /* + * We punt completion for an arbitrary amount of time since + * systems with enable clocks during module load are initialized + * after late_initcall_sync(), as module drivers will be probed + * and initialized afterwards. + */ + schedule_delayed_work(&disable_unused, msecs_to_jiffies(15000)); return 0; } -- 2.31.1