Received: by 2002:ac0:98c7:0:0:0:0:0 with SMTP id g7-v6csp316343imd; Wed, 31 Oct 2018 20:00:09 -0700 (PDT) X-Google-Smtp-Source: AJdET5cO8c+rK9CZrRboAhxt5dDlluO1KzFnrS9UjE2QpUQKqBMiWmT00WTObs3lP8SgcimRu0F/ X-Received: by 2002:a62:2c16:: with SMTP id s22-v6mr5959520pfs.6.1541041209221; Wed, 31 Oct 2018 20:00:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1541041209; cv=none; d=google.com; s=arc-20160816; b=wMOUh87d65+bJo4sgiXQ59As4dKBXOYFl+t+3kXI4sJnZYYKUxQZTgfS7PyhqUwcV6 o8MbSGxINHNcjQGo8auzXELsBpnZ9aI5p7PoSZeBl2c3XvYZHdTWUepcVOsrZdAYvmtT MqHuX3H/wsTw4FOnThobZp0Y1d02Z2LIrtfCR3vraqNYlBo4zYGw+G3Qn/4p4Pr9wQjA iF9qe32PuBAiLDt5ni3vxZY/VV74iFnnpN5eA7R7ut59RCVUmWog+6MKdLxCjC0VNNtZ iPqdN3DkviK5MxWpdFGhAeZVu1XN5M/EFBO1yFV3QnwIH7xwe6I7BUAf3Kd15nv5KUxO vuxA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=QOSxRggcjUksRsOCf6mfNAeYLRROOH7cdOzQ/0UZTUk=; b=YUfl3BNaS07epUGMOE+9hhmw3xCFnrIHrcOeEKAS6NiZoQZmTbPGiiOzt5fs2ltwh/ 8L9WVgNK6pV6Vyuq+ILTHMIw7rrN2XFhMM3SfZI+U72vyYiTJkqhWhDfwe7+Tnu+1esB VPlUC5YUKOjP6Kf5IRyBRDYaTG2x5l31TLlfa8LniXKODKNEfIglNGg6bmOE8eGSqaca AqlDkLmzyrIzEEyqpGgBAqZWY8e5sht/hs7ttAczbFbT6JWjAmq+JSO70JJk3mDPQwo+ t8hQj25D2lhQ1grXhm75iswQdAoOmFxp4l5ysmR7w0Mmzb94RjBT8YNfgl00pPak6UaX 8Nhg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=HJVMfI+j; 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=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id i13-v6si28628430pgo.128.2018.10.31.19.59.53; Wed, 31 Oct 2018 20:00:09 -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; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=HJVMfI+j; 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=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727643AbeKAL7o (ORCPT + 99 others); Thu, 1 Nov 2018 07:59:44 -0400 Received: from mail-io1-f65.google.com ([209.85.166.65]:37990 "EHLO mail-io1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726419AbeKAL7n (ORCPT ); Thu, 1 Nov 2018 07:59:43 -0400 Received: by mail-io1-f65.google.com with SMTP id q18-v6so11263088iod.5 for ; Wed, 31 Oct 2018 19:58:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=QOSxRggcjUksRsOCf6mfNAeYLRROOH7cdOzQ/0UZTUk=; b=HJVMfI+jP8qwJ+T5gXrMmsDmI+ofJOL1Zc7zim6jzTGGjBzvvmdaAUYNxAcOCyoCZy l2BbePFTLM8Xe7YOYDtJVOQBYIZquZv0DLCEil4aRxYlAUlkJQ9UBUU4/DZysgJ5+GCR pRUeNr2la3NA+fWqclBbCtByJkyXS7UBZ8WCE= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=QOSxRggcjUksRsOCf6mfNAeYLRROOH7cdOzQ/0UZTUk=; b=mFrlTeOAOaB3C2XRK3WQcwkiUDOakEbSez4IqAwsAix/I/CdUToAbLf3hU1U4K8HIQ XVz8+YWzJSfwbV5iGmA2/vQICI5T/TwelzQVs1dWLoJzkWKrwNg+yKn/Om7Q6Am8oPiZ Vc0wL4ufVXd0Gr2GMbHg5uD+hLgKQe6jelnbz9hgti8RIDTJtLO23w3dTAnYtHVzKd5+ CiD2PWK2+r0yoLT53Xp+/BRXV9MF0010nNjpCk3NgKpRuOUL474Y/UJrs5gMB7HNq1aJ 4fn7qOZFKVPsnygzNp2pTBrL4FbdBDOwI0STDYdLWc5UG7VFPDOBFkurYFz5xfCzrZBX qZZw== X-Gm-Message-State: AGRZ1gKU57fte9YI543hMwy6xvDW8gvQDyRKoWyGfzGAHi4ILq6JWGnt 1E17hhIq03AfFtmXmKZWXh0famMJzC3UlQ82qOZOS8zj1HXY5A== X-Received: by 2002:a6b:acc5:: with SMTP id v188-v6mr4363558ioe.66.1541041122644; Wed, 31 Oct 2018 19:58:42 -0700 (PDT) MIME-Version: 1.0 References: <20181024013132.115907-1-dbasehore@chromium.org> <20181024013132.115907-3-dbasehore@chromium.org> In-Reply-To: <20181024013132.115907-3-dbasehore@chromium.org> From: "dbasehore ." Date: Wed, 31 Oct 2018 19:58:31 -0700 Message-ID: Subject: Re: [PATCH 2/6] clk: fix clk_calc_subtree compute duplications To: linux-kernel Cc: linux-clk@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-rockchip@lists.infradead.org, linux-doc@vger.kernel.org, sboyd@kernel.org, Michael Turquette , =?UTF-8?Q?Heiko_St=C3=BCbner?= , aisheng.dong@nxp.com, mchehab+samsung@kernel.org, Jonathan Corbet Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Oct 23, 2018 at 6:31 PM Derek Basehore wrote: > > 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 | 30 ++++++++++++++++++++---------- > 1 file changed, 20 insertions(+), 10 deletions(-) > > diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c > index 95d818f5edb2..61de8ad3e4cf 100644 > --- a/drivers/clk/clk.c > +++ b/drivers/clk/clk.c > @@ -1717,11 +1717,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; > @@ -1729,11 +1737,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); > - } > } > > /* > @@ -1744,7 +1747,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; > @@ -1791,6 +1794,8 @@ 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) > + child->new_rate = clk_recalc(child, new_rate); > goto out; > } > > @@ -1813,11 +1818,14 @@ 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) > + child->new_rate = clk_recalc(child, parent->new_rate); > + } > > out: > - clk_calc_subtree(core, new_rate, parent, p_index); > + clk_set_change(core, new_rate, parent, p_index); > > return top; > } > @@ -2018,6 +2026,8 @@ static int clk_core_set_rate_nolock(struct clk_core *core, > if (ret) > return ret; > > + clk_calc_subtree(core); This should be: hlist_for_each_entry(child, core->new_parent? core->new_parent : core->parent, child_node) clk_calc_subtree(child); > + > /* notify that we are about to change rates */ > fail_clk = clk_propagate_rate_change(top, PRE_RATE_CHANGE); > if (fail_clk) { > -- > 2.19.1.568.g152ad8e336-goog >