Received: by 2002:a05:7208:13ce:b0:7f:395a:35b6 with SMTP id r14csp203863rbe; Wed, 28 Feb 2024 17:58:30 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXmsZLea4Jo8NbiHlqxl9VSLnYl+N9MrESk43ZafMFj//5LdEA8xcs3YQvq+9f8MA5wz0XcyJevM8Lqj5wPWJL03Eo0LEAX315OYNvmcg== X-Google-Smtp-Source: AGHT+IF7vEfCaBUPiasb9V36QMnDEPbskCWqrpOn26eRpbqC5MQdzuX8BzNuKDUCPhFc2Tg8IzcQ X-Received: by 2002:a05:620a:22c:b0:787:ec28:9c12 with SMTP id u12-20020a05620a022c00b00787ec289c12mr867529qkm.56.1709171909770; Wed, 28 Feb 2024 17:58:29 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709171909; cv=pass; d=google.com; s=arc-20160816; b=vH+XHGXUOpObOFFbJu9Rz0F6EUlrTR/tNGctGbWaEGcvkyWq/rjAqCSuVP4aGTH91a QUAlOyelicx6b0cVtoigyDbWdj9czrdnaokriUyLUExavbpg1jIKFEu1ev+qB1rI8lGy WGSnTx3R4u/CTSQFZ6Fd/+cSWVeM8dG2bgq9lLPdZJULDXyxyE4qszZ9aAPLx1z0cUb8 IOuqoQBeGH85JWmstHaavzsh3FmSC9LsiaFZGyXFM1uT0Ea+RAvhD35HO4Ax/l3PjDVZ hqC54KJNS8LpEDze8Plk0TMSsGk/oLkyZF2r6YhadU6LstpTiiU4Uk234SDoMKc+i6wY Z4aQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=user-agent:date:to:cc:from:subject:references:in-reply-to :content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:dkim-signature; bh=/FumXTNWkQ8TT8ed6HvFzQJ1YEPms0nSep58NKIc2Ew=; fh=s8vFBcVsgXVNsa75KcdSg8e2fRAGeVEuxT8TT0bUwB8=; b=wLlribweMHm3SGVSXNMZDCHOYdDJbc7q6RL0MgO/b7PP8JSG80Y2P9oSq1bylTcyoK aPHKVBK3EmDy6FjMezXLsIBBgPbwkAAV+OtgEmSaF0H7vJ0Z2USP4grOk6ra43zkRC4S s3qrwp6NDEGIbYqw9LmG1Z4YqeeeYE+eLorboJW4kMysL/oJWKqoiopmeOuLe7aE9/zh PH7yoiZDLVtK3TTgUYCYOTueRD/8ZROQRYbf6AsvJURzwr6BQnYBFawjb1su0633Yk9S 8C+uSCBuzX3EnMRXOhc+zkQkHHna0PkH8Wfr7Bb8alaIx5m6xhcB7Onm5pKA/SFX+5kd 6k+A==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=ppqXCoRE; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-86021-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-86021-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id j18-20020a05620a0a5200b00787236cdb49si450797qka.649.2024.02.28.17.58.29 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Feb 2024 17:58:29 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-86021-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=ppqXCoRE; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-86021-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-86021-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 864451C21CA9 for ; Thu, 29 Feb 2024 01:58:29 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 481AA364D9; Thu, 29 Feb 2024 01:58:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="ppqXCoRE" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6EDAE22F13; Thu, 29 Feb 2024 01:58:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709171901; cv=none; b=Nzwn9DQccp2zTIfSUGPvlYLa9LhSNdtZPEqzcakfhMXkhW8y/EAtlamB1ZryIiBd3Rhy8b1Pzfxs+FsXr6Y1/yI+hOY/0EnmOkOsGGenRTgxBvheUcMw7fSFrYpR+zpJHsmtbZOveCYnMp/NFpRI0dctnFTuUrvkcVSjn8anSKk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709171901; c=relaxed/simple; bh=J41cmZC7bQsegjax8yQD7VpQyLCqWbWDH7KNEl/+hnA=; h=Message-ID:Content-Type:MIME-Version:In-Reply-To:References: Subject:From:Cc:To:Date; b=fJcPiULOL6XtkqMIZYuliMpJLnoZBM68KYSEmWVt4oanbEx2tHgURsqltv9sw5pIqD3v7kV/0rl0llffcB4O+WL8PtD0v4mypy/GjGdmuFzQx0/aa3SP8VBz6u/mlotndiJu1kr36iNb4LNKisjaL7I3atHSBtGvNaQY1HSAlJ0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=ppqXCoRE; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id CEE00C433F1; Thu, 29 Feb 2024 01:58:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1709171900; bh=J41cmZC7bQsegjax8yQD7VpQyLCqWbWDH7KNEl/+hnA=; h=In-Reply-To:References:Subject:From:Cc:To:Date:From; b=ppqXCoRECb8qXQoHJV/NedfjPoAvUrCzaLZWrdv36y63x9YACBjE83Eip0svG9PBf lngFZh81/sv5eDP0xqh+DP9e55gJN9nUSINtJ7SDCGddGHywnAG9VF9O9sfnwpDvc2 0DApIgUKBUF6iPHDCAtlJ1DK0gKip1voMF7pZ86nP9sOb7kjkWPfHqhxj77yh/sBOa 2q3EsdbMQVAEfZwDuQMVAuuZpDuJzOJC7kxaTC+BIP9+j/2B1z4PTHwh0CN0xmeuIJ TCfGVBP7w7kadNgohRjctolPlhaclQhNnuqOvYyBZN1Hfa5EWDb+GWJwCmuxqzHi7B 1OW1E2HfMn97A== Message-ID: <0db752d31016823ccd3799925255a74a.sboyd@kernel.org> Content-Type: text/plain; charset="utf-8" Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable In-Reply-To: <20240224-mux-v1-1-608cc704ef43@outlook.com> References: <20240224-mux-v1-1-608cc704ef43@outlook.com> Subject: Re: [PATCH RESEND] clk: set initial best mux parent to current parent when determining rate From: Stephen Boyd Cc: linux-clk@vger.kernel.org, linux-kernel@vger.kernel.org, Yang Xiwen To: Michael Turquette , Yang Xiwen via B4 Relay , forbidden405@outlook.com Date: Wed, 28 Feb 2024 17:58:18 -0800 User-Agent: alot/0.10 Quoting Yang Xiwen via B4 Relay (2024-02-23 09:18:52) > From: Yang Xiwen >=20 > Originally, the initial clock rate is hardcoded to 0, this can lead to > some problem when setting a very small rate with CLK_MUX_ROUND_NEAREST. Did you mean CLK_MUX_ROUND_CLOSEST? >=20 > For example, if the lowest possible rate privided by the mux is 1000Hz, s/privided/provided/ > setting a rate below 500Hz will fail, because no clock can provide a > better rate than the non-existant 0. But it should succeed with 1000Hz > being set. >=20 > Setting the initial best parent to current parent could solve this bug > very well. >=20 > Signed-off-by: Yang Xiwen > --- > This is actually a v2 of [1], but seems too simple to have a unittest. > It's tested in a mmc host driver. It's not too simple for a unittest. >=20 > [1]: https://lore.kernel.org/linux-clk/20230421-clk-v3-1-9ff79e7e7fed@out= look.com/ In that thread I asked you to please Cc Maxime. Please do that. > --- > drivers/clk/clk.c | 4 ++++ > 1 file changed, 4 insertions(+) >=20 > diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c > index 2253c154a824..d98cebd7ff03 100644 > --- a/drivers/clk/clk.c > +++ b/drivers/clk/clk.c > @@ -649,6 +649,10 @@ int clk_mux_determine_rate_flags(struct clk_hw *hw, > =20 > /* find the parent that can provide the fastest rate <=3D rate */ > num_parents =3D core->num_parents; > + if (core->parent) { > + best_parent =3D core->parent; > + best =3D clk_core_get_rate_nolock(best_parent); > + } Is the problem that we're not using abs_diff()? ----8<---- diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c index a3bc7fb90d0f..91023345595f 100644 --- a/drivers/clk/clk.c +++ b/drivers/clk/clk.c @@ -542,7 +542,7 @@ static bool mux_is_better_rate(unsigned long rate, unsi= gned long now, unsigned long best, unsigned long flags) { if (flags & CLK_MUX_ROUND_CLOSEST) - return abs(now - rate) < abs(best - rate); + return abs_diff(now, rate) < abs_diff(best, rate); =20 return now <=3D rate && now > best; }