From patchwork Tue Mar 5 04:49:32 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Derek Basehore X-Patchwork-Id: 10838935 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 05FF21869 for ; Tue, 5 Mar 2019 04:50:02 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E12492B74A for ; Tue, 5 Mar 2019 04:50:01 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D11AE2B75F; Tue, 5 Mar 2019 04:50:01 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 5A5942B74A for ; Tue, 5 Mar 2019 04:50:01 +0000 (UTC) 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:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=Xrf8RBkK0P6vYGa+OMZM0SO2K8FFP+TZT+0D6U7eq+U=; b=YEN4S/8W86XQz2 AYGEAdEABPCIQWYL81ddietzyVQWcMytCQOUere3G/gW6TMLMmcFzvwcex1fWMnHpEFd/AoaxaOvN 72wCUebJlm3HZycDgNKtUCoWsI34v7/4gHcXUQLAFhTVMhoEJHlTX7ny3yQXnpuaps8D73aVIQX/J UI/VHZSAb0vbUEU0QfVCIm4mD3UzXKgc2DyZk7NCORs9Cdfjs0VGIVRL2ubPzpu+QIAIiD+70YBGU YyulqCNWghxpJXyFSlwMXwl6KNnWWiUDQXmUI0/+Qps+cjaFyPZ44zgmMf6PiTlr2zZ1MEjNIhRvk 3EFkRSJeXPmxo2Q3yReg==; 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 1h121f-0000CM-DH; Tue, 05 Mar 2019 04:49:59 +0000 Received: from mail-pf1-x441.google.com ([2607:f8b0:4864:20::441]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1h121R-0008PU-I1 for linux-arm-kernel@lists.infradead.org; Tue, 05 Mar 2019 04:49:48 +0000 Received: by mail-pf1-x441.google.com with SMTP id u9so4707641pfn.1 for ; Mon, 04 Mar 2019 20:49:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=XW9u00gqF+VQkOHiAdDCZCu3GFv7vefH7f1kWrnMso4=; b=SN3+Ny9MGa1ekRvQ5YA1Av6352InetdZtx5Ubjat2cT7QlJz/lKGlegpWWgtKD+ZfU 36E2+U/Fz16MYLe/3Do3v7Bll3m4QqyLxDPaboNav+tIl8QkJwRmHXYmDHj4qtmITg58 8PBcO4DYBMYu6jRhNJgNxYIncdvw5il6hyCvg= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=XW9u00gqF+VQkOHiAdDCZCu3GFv7vefH7f1kWrnMso4=; b=JyVYwk7l65n/vG3RkwM5TWFaNnzXY0wY9slAaReETZxw4jyDVy+qRgvypn26ppKTH6 OkpDUlStL41RVKAMbq1eKs6o4eDqW8nm0PAUabezFHGvrY3tvLEnQOpliAUuzLg/HreB FzdMFx0UMiRdPWOC0QEKSLIrUWEC9COBlF9W4BWIbT3mahFziLBTBFZicUv0VCFYOzeH ZAFSXHOCQWVsOo74wlQY4t3aKUyw/MCWbB9W+byrq4x/kJqoSQ9fbnyEjSrIIKaTqEv/ Z7ALSN59ZHEpQGJ+fgG3VE3OmRGXYLELbPH5D0B0MqNbds0lQAMhn28IKYm8jpfPXQ81 YBrQ== X-Gm-Message-State: APjAAAXY/AcYjccsawSri2l7Q0Y3odXfjHs14ylqItXbEmBh1scMi01F 1t7DN9AZL74EIoTK2i+elQ2FCg== X-Google-Smtp-Source: APXvYqwa/kkbZvMxHk+1iiUNJApYCJBUzUfSqzOx9LMXXbQaWNbvZC6nZp9FjO6/QNoYcZXwYu5H8w== X-Received: by 2002:a63:7e0e:: with SMTP id z14mr21987642pgc.436.1551761384745; Mon, 04 Mar 2019 20:49:44 -0800 (PST) Received: from exogeni.mtv.corp.google.com ([2620:15c:202:1:db8d:8e3f:2514:5db8]) by smtp.gmail.com with ESMTPSA id z15sm15893883pgc.25.2019.03.04.20.49.43 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 04 Mar 2019 20:49:44 -0800 (PST) From: Derek Basehore To: linux-kernel@vger.kernel.org Subject: [PATCH v2 2/6] clk: fix clk_calc_subtree compute duplications Date: Mon, 4 Mar 2019 20:49:32 -0800 Message-Id: <20190305044936.22267-3-dbasehore@chromium.org> X-Mailer: git-send-email 2.21.0.352.gf09ad66450-goog In-Reply-To: <20190305044936.22267-1-dbasehore@chromium.org> References: <20190305044936.22267-1-dbasehore@chromium.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190304_204945_589809_A65481E3 X-CRM114-Status: GOOD ( 16.85 ) 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: aisheng.dong@nxp.com, Derek Basehore , heiko@sntech.de, linux-doc@vger.kernel.org, sboyd@kernel.org, mturquette@baylibre.com, corbet@lwn.net, linux-rockchip@lists.infradead.org, mchehab+samsung@kernel.org, linux-clk@vger.kernel.org, linux-arm-kernel@lists.infradead.org, jbrunet@baylibre.com Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP clk_calc_subtree was called at every step up the clk tree in clk_calc_new_rates. Since it recursively calls itself for its children, this means it would be called once on each clk for each step above the top clk is. This fixes this by breaking the subtree calculation into two parts. The first part recalcs the rate for each child of the parent clk in clk_calc_new_rates. This part is not recursive itself. The second part recursively calls a new clk_calc_subtree on the clk_core that was passed into clk_set_rate. Signed-off-by: Derek Basehore --- drivers/clk/clk.c | 49 ++++++++++++++++++++++++++++++++++++----------- 1 file changed, 38 insertions(+), 11 deletions(-) diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c index 94b3ac783d90..e20364812b54 100644 --- a/drivers/clk/clk.c +++ b/drivers/clk/clk.c @@ -1732,11 +1732,19 @@ static int __clk_speculate_rates(struct clk_core *core, return ret; } -static void clk_calc_subtree(struct clk_core *core, unsigned long new_rate, - struct clk_core *new_parent, u8 p_index) +static void clk_calc_subtree(struct clk_core *core) { struct clk_core *child; + hlist_for_each_entry(child, &core->children, child_node) { + child->new_rate = clk_recalc(child, core->new_rate); + clk_calc_subtree(child); + } +} + +static void clk_set_change(struct clk_core *core, unsigned long new_rate, + struct clk_core *new_parent, u8 p_index) +{ core->new_rate = new_rate; core->new_parent = new_parent; core->new_parent_index = p_index; @@ -1744,11 +1752,6 @@ static void clk_calc_subtree(struct clk_core *core, unsigned long new_rate, core->new_child = NULL; if (new_parent && new_parent != core->parent) new_parent->new_child = core; - - hlist_for_each_entry(child, &core->children, child_node) { - child->new_rate = clk_recalc(child, new_rate); - clk_calc_subtree(child, child->new_rate, NULL, 0); - } } /* @@ -1759,7 +1762,7 @@ static struct clk_core *clk_calc_new_rates(struct clk_core *core, unsigned long rate) { struct clk_core *top = core; - struct clk_core *old_parent, *parent; + struct clk_core *old_parent, *parent, *child; unsigned long best_parent_rate = 0; unsigned long new_rate; unsigned long min_rate; @@ -1806,6 +1809,13 @@ static struct clk_core *clk_calc_new_rates(struct clk_core *core, /* pass-through clock with adjustable parent */ top = clk_calc_new_rates(parent, rate); new_rate = parent->new_rate; + hlist_for_each_entry(child, &parent->children, child_node) { + if (child == core) + continue; + + child->new_rate = clk_recalc(child, new_rate); + clk_calc_subtree(child); + } goto out; } @@ -1828,11 +1838,19 @@ static struct clk_core *clk_calc_new_rates(struct clk_core *core, } if ((core->flags & CLK_SET_RATE_PARENT) && parent && - best_parent_rate != parent->rate) + best_parent_rate != parent->rate) { top = clk_calc_new_rates(parent, best_parent_rate); + hlist_for_each_entry(child, &parent->children, child_node) { + if (child == core) + continue; + + child->new_rate = clk_recalc(child, parent->new_rate); + clk_calc_subtree(child); + } + } out: - clk_calc_subtree(core, new_rate, parent, p_index); + clk_set_change(core, new_rate, parent, p_index); return top; } @@ -2007,7 +2025,7 @@ static unsigned long clk_core_req_round_rate_nolock(struct clk_core *core, static int clk_core_set_rate_nolock(struct clk_core *core, unsigned long req_rate) { - struct clk_core *top, *fail_clk; + struct clk_core *top, *fail_clk, *child; unsigned long rate; int ret = 0; @@ -2033,6 +2051,15 @@ static int clk_core_set_rate_nolock(struct clk_core *core, if (ret) return ret; + if (top != core) { + /* new_parent cannot be NULL in this case */ + hlist_for_each_entry(child, &core->new_parent->children, + child_node) + clk_calc_subtree(child); + } else { + clk_calc_subtree(core); + } + /* notify that we are about to change rates */ fail_clk = clk_propagate_rate_change(top, PRE_RATE_CHANGE); if (fail_clk) {