Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp820054imm; Fri, 31 Aug 2018 14:21:34 -0700 (PDT) X-Google-Smtp-Source: ANB0VdY94easz1ElN//jtuMpAEk9C8HOCv0trFkNHwpAgRDPCJDwxzRLwQie8BqTdYCJhrXDCqMr X-Received: by 2002:a17:902:bf0b:: with SMTP id bi11-v6mr17409374plb.76.1535750494122; Fri, 31 Aug 2018 14:21:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1535750494; cv=none; d=google.com; s=arc-20160816; b=fembd4xDdeg+mmF85bv7L2sgKcLGMfhw0Av8/xx4hK6w8FkE+aPG78J+Yjjup5YZlv YnpiptQcSKQuWYk5eudL9GQrvNhBTc7XclkkflLvuVgok2orhJ0GaOQDjYP7AZd+CJ7x xuKycxnRt5+4cGb5mG3eNHFA20GTPwpQtZLHqWw+X9AkLXeviPzimAtE5XeoA7YmRhEc kh5lzXatqNCigmEvVrQ0XrT8CPBt7XHAONytVlJMgplieHPFFiGYVeeH4WribNPk+SsP a2F4PXY2Xk1hFfuGCEGRnlLyUjlJUWy2iZX501GI7EjdTTsk04yJn68qhVSz3JlQzWG6 HOLw== 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 :message-id:date:subject:cc:to:from:dkim-signature :arc-authentication-results; bh=Cj7JgX+iXT4uVtzoZVFieuPOGdIccPYkThtUySHDX3o=; b=b8yokNeKyGO7koP+BoqB5JMJXPe+i0eWp5aYM6vR1TChP+s7mWpEiyD767nAtzyCnJ tqOM5b3Mda6jsm9udpx4Grd7XhxDP9CsitCKllQV3pW2WdDKPZtQF0SIK/b9DljhpNcQ DTI9Qf+/skTwgtarjHYD3C1ZoY++PjSnXTlBTXVBzytQbnU0NdeAQEc2SBWGRsZPrhDi 9ZNfnER2JgeYae/DCtTQj6e1EyriFPDdawBYfKHGJ4BE9tKfgm2P8IOWSQkE3OE+impC NQE9iU3qK3r6QcF+zPYtp9JwfVzLCzGCaHbcxuS2ctojrk7KoVU3O3ZxVDVUV7bmEgYG 1ogQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=OguqJ3jm; 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 f15-v6si10980406pli.194.2018.08.31.14.21.19; Fri, 31 Aug 2018 14:21:34 -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=OguqJ3jm; 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 S1727338AbeIAB3b (ORCPT + 99 others); Fri, 31 Aug 2018 21:29:31 -0400 Received: from mail-pf1-f194.google.com ([209.85.210.194]:37577 "EHLO mail-pf1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727248AbeIAB3a (ORCPT ); Fri, 31 Aug 2018 21:29:30 -0400 Received: by mail-pf1-f194.google.com with SMTP id h69-v6so6061973pfd.4 for ; Fri, 31 Aug 2018 14:20:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=Cj7JgX+iXT4uVtzoZVFieuPOGdIccPYkThtUySHDX3o=; b=OguqJ3jmuSSpbIQ20CGUxnTlM/NbIUSJ/4qvAX8dD8WOyfGvZNj23XRFdUZ+Rdz4Km E0xxTBxMC98+BIioFZjj4JkL+KPwF+RzGk6UIJX3ayzZGua0aNT4K99BlkPa6aXZPZ7+ sRfl6B+s+OY10SK1udN+PHe0YKIbseHx57q8w= 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:mime-version :content-transfer-encoding; bh=Cj7JgX+iXT4uVtzoZVFieuPOGdIccPYkThtUySHDX3o=; b=oqWUdvFAHZ1tS50+9HdNy+6nMGl3jd/8MuQiLjebTSexGPN0jnxJ1RsiVP4FIPZaUP 95Wj3RrCKlojvnxG/D8+IzgVZ/Ms2U5UZrRZvfJK3yvd6faonzbgggMCCB52eDPxzWnK n4rf9IO1iGOw6RIcTUBPwykyqvWs6TBxcKMWg71hY9UQ5IDOqEa0DbtkJ3qTe1Ck4F8d DMcpn/1K+VOhjpCEWkLvQQeFHvL77qda22ewJd5lkZPvSbs+CFdfJGAuE44R7lJAJOFO aCLqkl1xcgEUhzNmugvmYb4d2CxjAW+dGMHr4FSBrW21J+RVglCXzxoRB6+sqeIlcFmw xfgw== X-Gm-Message-State: APzg51A1eKT+i0WLnbVIGVcVRcY3nLrQF2GdUZKvBFiksUa/NSG0LVa0 EejmtQU+rB3EWL4QeVuDHT5Guw== X-Received: by 2002:a62:3001:: with SMTP id w1-v6mr17731669pfw.19.1535750412330; Fri, 31 Aug 2018 14:20:12 -0700 (PDT) Received: from exogeni.mtv.corp.google.com ([2620:15c:202:1:5e2b:39df:72ed:4968]) by smtp.gmail.com with ESMTPSA id d24-v6sm11838607pgv.23.2018.08.31.14.20.10 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 31 Aug 2018 14:20:11 -0700 (PDT) From: Derek Basehore To: sboyd@kernel.org Cc: mturquette@baylibre.com, linux-clk@vger.kernel.org, linux-kernel@vger.kernel.org, Derek Basehore Subject: [PATCH] clk: fix clk_calc_subtree compute duplications Date: Fri, 31 Aug 2018 14:20:07 -0700 Message-Id: <20180831212007.247186-1-dbasehore@chromium.org> X-Mailer: git-send-email 2.19.0.rc1.350.ge57e33dbd1-goog MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 is fixed by adding a non-recursive function called at every step in clk_calc_new_rates that fills in new_rate, new_parent, etc. Since the clks not called directly for clk_calc_new_rates can only change their rate, we only set new_rate in clk_calc_subtree. clk_calc_subtree is also only called on the top clk after it's found via clk_calc_new_rates to remove the duplicate recursive calls. Signed-off-by: Derek Basehore --- drivers/clk/clk.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c index d31055ae6ec6..52032fb1a8a2 100644 --- a/drivers/clk/clk.c +++ b/drivers/clk/clk.c @@ -1609,11 +1609,18 @@ 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, unsigned long new_rate) { struct clk_core *child; + core->new_rate = new_rate; + hlist_for_each_entry(child, &core->children, child_node) + clk_calc_subtree(child, clk_recalc(child, new_rate)); +} + +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; @@ -1621,11 +1628,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); - } } /* @@ -1709,7 +1711,7 @@ static struct clk_core *clk_calc_new_rates(struct clk_core *core, top = clk_calc_new_rates(parent, best_parent_rate); out: - clk_calc_subtree(core, new_rate, parent, p_index); + clk_set_change(core, new_rate, parent, p_index); return top; } @@ -1910,6 +1912,8 @@ static int clk_core_set_rate_nolock(struct clk_core *core, if (ret) return ret; + clk_calc_subtree(top, top->new_rate); + /* notify that we are about to change rates */ fail_clk = clk_propagate_rate_change(top, PRE_RATE_CHANGE); if (fail_clk) { -- 2.19.0.rc1.350.ge57e33dbd1-goog