Received: by 2002:ab2:3141:0:b0:1ed:23cc:44d1 with SMTP id i1csp10621lqg; Thu, 29 Feb 2024 17:43:34 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUnVO6jWmCvGK3HnzGS7CZMo7DmZ36A8P4p63kgexELfqfWVb9LJ1/uny37WLzgVDBxguEjOO42dNPEddhFx4THwYQewAMKNErzbF2ciA== X-Google-Smtp-Source: AGHT+IEVpETjmduFb8lzz3xWSRGhZ/R+uVPg4/Xuwq5v0Q1n1dDcDYamYBjv5xaKWA1r2fzR+uUD X-Received: by 2002:a05:620a:4492:b0:787:f1d0:ff80 with SMTP id x18-20020a05620a449200b00787f1d0ff80mr437871qkp.34.1709257414630; Thu, 29 Feb 2024 17:43:34 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709257414; cv=pass; d=google.com; s=arc-20160816; b=FsdIzBfFBaoijaLTULzicNXnxCsWA6yMYGVWvIUf5Au3XJ/EVLqj23Hhx2VAZKTm58 R9b78ifYiKTnV4F0M6uLd4yAID9vNAKfy/dsRW1WvSx7sEkRob4QzL7Lzzri1Xjq8TJL Q0DkPKnq5lwTlYL3CE+GrOcVfw+cXX5hqjSwpphDOfIJYcWYt9DglrmrTzzZXUdS0Bob Z6PsZNkXmHgafXH2ePAzdedadvwE8UF9QJg3lG6QpUMpqkal2g6tbqiDVTieHqQqz7j+ eJqkpcg8XvMeZ/6i8xQmlWd6t4IvzphkjYtNnWgV7a8ZoNq0fDgmq58dq2MRpFTOeJF3 +Fqg== 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=S+yC6sQsk+6z0veTQEN7nWvDQi7/w63JOz/vULpQu3I=; fh=phRFw2PU2aEmaocv8urHP2yu3RJ2i2THhGfI+9dxvQk=; b=rytu6Dxnf2Zz0JKiRWeawJWHENsje9ZeHx7iTg45cgIlecaerYbBDo2NPns/cUP8T3 Kyv3svhKvVKT5RkOiH6U6HhHXnE2Zp/3ClBneenSOCqiKfTvFYc5jNowh7jE5UId9rq1 hWicqziY3mayZf0mJRzAbJz7w27icoSz9UoYSF4aCojzaAhF/gyDd3Krw85SLZjz9w4g 7so8oIiEAEXLmIFQj9QWTzYNChalU4e/j6+LLZ2MxczAawVfUizRLEU9pr+KXYKqiVkH hOkCyyKG5uqgOHb82EPz26oLbb3Zj6tVbVy3ruI46zOOiFYEAtx2530Js4RbnGblH+xC 6OHA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=qIm6aNNy; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-87794-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-87794-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 ya19-20020a05620a5e5300b00787b3743293si2560454qkn.236.2024.02.29.17.43.34 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 29 Feb 2024 17:43:34 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-87794-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=qIm6aNNy; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-87794-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-87794-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 5F1511C2225B for ; Fri, 1 Mar 2024 01:43:34 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 28AB0FC03; Fri, 1 Mar 2024 01:42:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="qIm6aNNy" 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 4CE0A2E40E; Fri, 1 Mar 2024 01:42:28 +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=1709257348; cv=none; b=bncxwX6T8SriFSuqiH8raxMAiAF7Eau79n8Wn3D0Dds5FuEbeT3ZFmog5/ZDCzeeW4YKBkskTs7k7CudttUQjZMei86hQnn/iAeVFYtaxwAL4gqI22EBEG2Csqo4ndLgz1X7n1/nFSAp0Hk2q75r970jelqr5XC6ge11cuF55Wg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709257348; c=relaxed/simple; bh=C6GrbXyKhQ/53cioiYQj+qavhzuh+NWCKiVcOEXlD5U=; h=Message-ID:Content-Type:MIME-Version:In-Reply-To:References: Subject:From:Cc:To:Date; b=MFqA2YPpp2KfRdnF89RY630CA65MXPD3m8vXxI99cdzzgwedDuD+9GxPUVUsY8yM5mBYwDWQ5EYt5kk1F2rw9uzbKLEKwEYvrOjRtgMT20jffmuHgE5v6KrpSc/GvVSiecXGdEhbOuzaZAZN9Z9NfTX+E5Cojfua2Zi0hRfKR7s= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=qIm6aNNy; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id C8F8BC433F1; Fri, 1 Mar 2024 01:42:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1709257347; bh=C6GrbXyKhQ/53cioiYQj+qavhzuh+NWCKiVcOEXlD5U=; h=In-Reply-To:References:Subject:From:Cc:To:Date:From; b=qIm6aNNyAeHcfji1JRmEEOg5KuHDf8RZrQHjguspUvQoaJOV11W7tE3dWgZvVgKZa SUSJHk+W/C5/DP3WKmagAKTrwN0s7DxPiy7Pu8e2H3YheCeogVpBE5AhoioT8QzrF4 Fcm+NpPcUhIrEKochPofbqJpmHWWLVWGnotKXaHM6m5WwoEP79CZ2NObRL1ye+3NUb gvZhMc7hmaI8CrgzdGdhM/yTGKrjQC8YZ4dCYN8QpzJelz51IpwIjDWF6LCfnTHAWr kdJfmhH3GzeZcunSA37EldSUs+7ghuYiJu/h6HwKklN04wkzHWqVfqjYMBg7FWVp86 o/VAjI+RGYURg== Message-ID: <97787cc46d663b08b2e571841fb1bd6b.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: References: <20240224-mux-v1-1-608cc704ef43@outlook.com> <0db752d31016823ccd3799925255a74a.sboyd@kernel.org> 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 To: Michael Turquette , Yang Xiwen , Yang Xiwen via B4 Relay Date: Thu, 29 Feb 2024 17:42:25 -0800 User-Agent: alot/0.10 Quoting Yang Xiwen (2024-02-28 18:33:11) > On 2/29/2024 10:25 AM, Stephen Boyd wrote: > >>> > >>> Is the problem that we're not using abs_diff()? > >> > >> > >> No, i think. It has nothing to do with the code here. It's because of > >> the initial best_parent/best_parent_rate. > >=20 > > Alright. I will have to fix this as well in a different patch. > >=20 > >> > >>> > >>> ----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= , unsigned 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); > >> > >> Without this patch, the initial `best` rate would be always 0. This is > >> wrong for most cases, 0Hz might (usually) be unavailable. We should use > >> a valid rate(i.e. current rate) initially. > >=20 > > Ok. But you set best to the parent rate. So why not use 'core->rate' > > directly as 'best'? >=20 >=20 > I can't remember exactly. I just add this piece of code and found it's > working. Is this field already filled prior to setting rate? Anyway, > your suggestion is very reasonable. Maybe dear clk maintainers can fix > it as i'm not familiar with clk core code. Yes the 'struct clk_rate_request' is pre-filled with many details, including the rate of the clk and the current parent rate and parent hw pointer. I'm pretty sure you're trying to fix this fixme from clk_test.c static const struct clk_ops clk_dummy_single_parent_ops =3D { /* * FIXME: Even though we should probably be able to use * __clk_mux_determine_rate() here, if we use it and call * clk_round_rate() or clk_set_rate() with a rate lower than * what all the parents can provide, it will return -EINVAL. * * This is due to the fact that it has the undocumented * behaviour to always pick up the closest rate higher than the * requested rate. If we get something lower, it thus considers * that it's not acceptable and will return an error. * * It's somewhat inconsistent and creates a weird threshold * between rates above the parent rate which would be rounded to * what the parent can provide, but rates below will simply * return an error. */