Received: by 2002:a05:7412:a9a2:b0:e2:908c:2ebd with SMTP id o34csp229913rdh; Wed, 25 Oct 2023 23:53:37 -0700 (PDT) X-Google-Smtp-Source: AGHT+IE/3boLtc3Q0M3cj2myueSCKyYcuADMv8jqu8cZVaUroywtY/qVK/u3gQv8Hfdo0o40dHZU X-Received: by 2002:a81:52d8:0:b0:5a8:7cb2:15d1 with SMTP id g207-20020a8152d8000000b005a87cb215d1mr19472108ywb.24.1698303216888; Wed, 25 Oct 2023 23:53:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698303216; cv=none; d=google.com; s=arc-20160816; b=KbAbKo+hK6rbxNzZIOIN+2ExzVhcPx4gF/72g3CXBCKCW0dWtOmk87oOUevincx/E8 V+IoQVsvQK8EyMBZBMXv0UfgT2oZNAQO6c1qC8osE/6wxrTqauWWZEWQvmy6JHyhMOP1 HPeCxx/4NVJvkEiLkdcZUuEVsb0I9Q6szAO3bmOHoqFIRM3mJgPzbLzC4+BO+KaiGJj8 mKYPJcZvcsnvgwVGZI/A5Q34J0VJTiThl6en++u41Lw4mbhmtQPlbxVH/B2mqDtTcCNz /yAXNLx7ad+Eb+w/nRUKyB9z+VX9BvSOQ1Zru8poUtde7hWPYjJLtrSy82nZIenYMyVR h5DA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version; bh=BUPackAG++Bj/EyTqTLNv0AOnpVZbNbMMw6utZtHsR0=; fh=ktlYVeHKDtbJtCpddDa3iVED23+KqjyjEn2jt5JfEWg=; b=RL3LCmBx8Oriu3nCivcOMmOez7fZ1EFJtZLxBXm3z2TmZl7Y0ty5nt4PhdE6oN+eEN g9r2cPyMzN+9oA/EfVTule5dvvJGorNCYu5K735rxGxepk6JJZb5+T23be+KFTcrBC4q 7DJC/IyrL0hw/CzrBcxtNSFRXPef7DOXyk+lQ4TmHebraRpx8s0/pb3vBXvikQGaqgoB nRpISJKyMKx48cgB4oi4Lj0gV80XYmICNXgO+KcMTYltpl4duNj/eTeMnbD1gf5VWc+k /2Czk6h6zllEIY13pJpSL+bhYRNNBGxSMtUF3tmeKLP7f1nhL2fccDAXj3FKDOlD7Zxn YM0w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from agentk.vger.email (agentk.vger.email. [23.128.96.32]) by mx.google.com with ESMTPS id u130-20020a814788000000b005862a7016c4si12287282ywa.475.2023.10.25.23.53.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 25 Oct 2023 23:53:36 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) client-ip=23.128.96.32; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id 347AA8115AA3; Wed, 25 Oct 2023 23:53:34 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233221AbjJZGxW convert rfc822-to-8bit (ORCPT + 99 others); Thu, 26 Oct 2023 02:53:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40746 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229518AbjJZGxV (ORCPT ); Thu, 26 Oct 2023 02:53:21 -0400 Received: from mail-vk1-f169.google.com (mail-vk1-f169.google.com [209.85.221.169]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CFAD9129; Wed, 25 Oct 2023 23:53:18 -0700 (PDT) Received: by mail-vk1-f169.google.com with SMTP id 71dfb90a1353d-4a13374a1e8so266471e0c.1; Wed, 25 Oct 2023 23:53:18 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698303198; x=1698907998; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=G0YdPMIyfnoGVa7CnoW2bpfQIBO0dVpufU1sOTZCxTs=; b=YdA9MgUSkfg1Azp8CZ4zyI68+0Ng5s7/TfZdSDWa+DCiLS1/un9HY4hqg11hz4XaU0 0rJ7RjBNqIy7bHUvs43YthOQg/TOtIXt/qjv9Iqm0640Ab71DyD8bPJwZ1EAiwC5wKHx EGpwzygM4Ha+nwqu4JPrLGY1ctmVQYbOxddalIPPFkXMfRLnQlVdYjEjBQo+o2qyfsNr QTy+H1gUUcPm4cN3RGGDHw5Hl+CvW58xKyICZmf0+RSOt1i5QHUf3pmrdR2khk509Ddn DwE1QER0Ini7wlFk3012ugTjSR7Fvw0nVpo2efsBJhJ+UuW9LKUPY+88m5+KI8D/J75i 5+xA== X-Gm-Message-State: AOJu0YzH+1utk5VN2uC7UJI0ozHGYut5Big96a68PDCkswyFm2PD32m7 yGi3sJl5TqFzI8GBoC6rAw8s8Tc+8Hnkew== X-Received: by 2002:a1f:a217:0:b0:49c:79f3:27a4 with SMTP id l23-20020a1fa217000000b0049c79f327a4mr15934012vke.3.1698303197796; Wed, 25 Oct 2023 23:53:17 -0700 (PDT) Received: from mail-yb1-f182.google.com (mail-yb1-f182.google.com. [209.85.219.182]) by smtp.gmail.com with ESMTPSA id w194-20020a8149cb000000b00586108dd8f5sm5771593ywa.18.2023.10.25.23.53.16 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 25 Oct 2023 23:53:17 -0700 (PDT) Received: by mail-yb1-f182.google.com with SMTP id 3f1490d57ef6-d852b28ec3bso379492276.2; Wed, 25 Oct 2023 23:53:16 -0700 (PDT) X-Received: by 2002:a25:81c6:0:b0:da0:4c63:f648 with SMTP id n6-20020a2581c6000000b00da04c63f648mr6168290ybm.6.1698303196340; Wed, 25 Oct 2023 23:53:16 -0700 (PDT) MIME-Version: 1.0 References: <20231026063941.1882023-1-peng.fan@oss.nxp.com> In-Reply-To: <20231026063941.1882023-1-peng.fan@oss.nxp.com> From: Geert Uytterhoeven Date: Thu, 26 Oct 2023 08:53:03 +0200 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH] clk: clk-conf: bypass setting rate/parent if already same To: "Peng Fan (OSS)" Cc: sboyd@kernel.org, abelvesa@kernel.org, mturquette@baylibre.com, clement.leger@bootlin.com, sudeep.holla@arm.com, cristian.marussi@arm.com, kernel@pengutronix.de, pure.logic@nexus-software.ie, a.fatoum@pengutronix.de, aford173@gmail.com, absahu@codeaurora.org, linux-clk@vger.kernel.org, linux-kernel@vger.kernel.org, Peng Fan Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8BIT X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (agentk.vger.email [0.0.0.0]); Wed, 25 Oct 2023 23:53:34 -0700 (PDT) Hi Peng, On Thu, Oct 26, 2023 at 8:35 AM Peng Fan (OSS) wrote: > From: Peng Fan > > If the original rate and parent is already the same as what users > wanna to configure through assigned clock rate and parent, there > is no need to configure them again which may cause more cpu cycles > or more SCMI RPC calls. > > So check the rate and parent first, and bypass when the original > rate and parent are same as requested by device tree node. > > Signed-off-by: Peng Fan Thanks for your patch! > --- a/drivers/clk/clk-conf.c > +++ b/drivers/clk/clk-conf.c > @@ -65,7 +65,11 @@ static int __set_clk_parents(struct device_node *node, bool clk_supplier) > goto err; > } > > - rc = clk_set_parent(clk, pclk); > + if (__clk_get_hw(pclk) != __clk_get_hw(clk_get_parent(clk))) > + rc = clk_set_parent(clk, pclk); > + else > + rc = 0; The else branch is not needed, as rc already indicates a non-error condition. > + > if (rc < 0) > pr_err("clk: failed to reparent %s to %s: %d\n", > __clk_get_name(clk), __clk_get_name(pclk), rc); > @@ -112,7 +116,10 @@ static int __set_clk_rates(struct device_node *node, bool clk_supplier) > return PTR_ERR(clk); > } > > - rc = clk_set_rate(clk, rate); > + if (clk_get_rate(clk) != rate) > + rc = clk_set_rate(clk, rate); > + else > + rc = 0; Likewise. > if (rc < 0) > pr_err("clk: couldn't set %s clk rate to %u (%d), current rate: %lu\n", > __clk_get_name(clk), rate, rc, However, one can wonder whether this check should be done in clk_set_parent() resp. clk_set_rate() instead, so it would benefit all callers? Also: /** * clk_get_rate - obtain the current clock rate (in Hz) for a clock source. * This is only valid once the clock source has been enabled. * @clk: clock source */ So at least the second part is not guaranteed to work? Gr{oetje,eeting}s, Geert -- Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that. -- Linus Torvalds