From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 68C16CD128A for ; Mon, 8 Apr 2024 04:39:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Date:To:Cc:From:Subject:References: In-Reply-To:MIME-Version:Message-ID:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=dLlibpU34SN2fxv4koU2qU9CHbLP0rNdCtzUsFL78lw=; b=cC62/Wgr+vSoe6 QYC4jHMIYeiMuxOB4HiVugZROeKjXgZ2QjxQKEcz/Hi7xrtZ5dtXHJG4j3WIZpiFqnUvOsNXOTbTs n6dHHr6oa07P9gEKthyiCHxcjIiLl2GaNnkkjL8XSmTBYq++nD5uVkNStJd68nmMTqJPBj3Tm8r0y OsI4ZUEJc8QB1awRLtrGCKBgIzQ0UK3TdCtzbCusEiHtwb9Tv85VkVHnfP19HPzpyWSvi13RHOr5g +ezlGM9FWYp0ZkW1zMCLjNZyYNXiT/M2AnQiB8qdfTU5OLzhd7AxUzNm0h6mfP1rNZsT3R4IozbbF xSpuz22C7d+DZO0HWa3g==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rtgmZ-0000000EKRi-0fJm; Mon, 08 Apr 2024 04:38:59 +0000 Received: from sin.source.kernel.org ([145.40.73.55]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rtgmU-0000000EKQT-1qZ7 for linux-arm-kernel@lists.infradead.org; Mon, 08 Apr 2024 04:38:56 +0000 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by sin.source.kernel.org (Postfix) with ESMTP id 9E4A1CE0AE6; Mon, 8 Apr 2024 04:38:49 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C2D03C433F1; Mon, 8 Apr 2024 04:38:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1712551128; bh=jW0HOzZx0chmSo4CS4bYPAqUuVJL9YFJVxgudK72DAk=; h=In-Reply-To:References:Subject:From:Cc:To:Date:From; b=t57GBb195OPD/sUJ2TG40eUgBFGHeRKNJpB7nX/Rhb/5ZhlKQwQe6PoqSVCqoe3jj Akusy1fvhtQUzSgWXCl9ToFI6NyHJYz2JL0Gw0I3xn1LeggAIk5dKS3DMb8W9FkgQP ZDCSGY5zUHXgb0tJlaPXjrobfjr4NuTuQVcRY7hm3yBoDd4rRWIzLNocsbnkSZP0an ukZmRSPbB4yx6aF3vB/p7kN3zzhD4qzI8P5MdKXtyCXEqbMjoGeEvWD7K8IK7zCFFB 0KA8RqLjpNnqgMhUb++WlZfkC0n0cMTD6VKla/lvpgnC1jJxPF14pmCOqSUbb1LwzD i2yTElggYFz5Q== Message-ID: <7027a28723d2597d9f620f4e0e1da97e.sboyd@kernel.org> MIME-Version: 1.0 In-Reply-To: <20240325210025.1448717-2-cristian.marussi@arm.com> References: <20240325210025.1448717-1-cristian.marussi@arm.com> <20240325210025.1448717-2-cristian.marussi@arm.com> Subject: Re: [PATCH v2 1/5] clk: scmi: Allocate CLK operations dynamically From: Stephen Boyd Cc: sudeep.holla@arm.com, james.quinlan@broadcom.com, f.fainelli@gmail.com, vincent.guittot@linaro.org, peng.fan@oss.nxp.com, michal.simek@amd.com, quic_sibis@quicinc.com, quic_nkela@quicinc.com, souvik.chakravarty@arm.com, mturquette@baylibre.com, Cristian Marussi To: Cristian Marussi , linux-arm-kernel@lists.infradead.org, linux-clk@vger.kernel.org, linux-kernel@vger.kernel.org Date: Sun, 07 Apr 2024 21:38:46 -0700 User-Agent: alot/0.10 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240407_213855_117881_FF3438ED X-CRM114-Status: GOOD ( 28.90 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Quoting Cristian Marussi (2024-03-25 14:00:21) > diff --git a/drivers/clk/clk-scmi.c b/drivers/clk/clk-scmi.c > index 8cbe24789c24..d5d369b052bd 100644 > --- a/drivers/clk/clk-scmi.c > +++ b/drivers/clk/clk-scmi.c > @@ -16,6 +16,14 @@ > #define NOT_ATOMIC false > #define ATOMIC true > > +enum scmi_clk_feats { > + SCMI_CLK_ATOMIC_SUPPORTED, > + SCMI_CLK_MAX_FEATS > +}; > + > +#define SCMI_MAX_CLK_OPS (1 << SCMI_CLK_MAX_FEATS) > + > +static const struct clk_ops *clk_ops_db[SCMI_MAX_CLK_OPS]; Can it be 'scmi_clk_ops_db' for some name spacing? > static const struct scmi_clk_proto_ops *scmi_proto_clk_ops; > > struct scmi_clk { > @@ -230,6 +202,106 @@ static int scmi_clk_ops_init(struct device *dev, struct scmi_clk *sclk, > return ret; > } > > +/** > + * scmi_clk_ops_alloc() - Alloc and configure clock operations > + * @dev: A device reference for devres > + * @feats_key: A bitmap representing the desired clk_ops capabilities. Drop the period please because it's not consistent with the previous argument descriptor. > + * > + * Allocate and configure a proper set of clock operations depending on the > + * specifically required SCMI clock features. > + * > + * Return: A pointer to the allocated and configured clk_ops on Success, Lowercase 'Success'. > + > +/** > + * scmi_clk_ops_select() - Select a proper set of clock operations > + * @sclk: A reference to an SCMI clock descriptor > + * @atomic_capable: A flag to indicate if atomic mode is supported by the > + * transport > + * @atomic_threshold: Platform atomic threshold value Is this in nanoseconds, microseconds, or ??? Maybe a better description is "clk_ops are atomic when clk enable_latency is less than X [time unit]" > + * > + * After having built a bitmap descriptor to represent the set of features > + * needed by this SCMI clock, at first use it to lookup into the set of > + * previously allocated clk_ops to check if a suitable combination of clock > + * operations was already created; when no match is found allocate a brand new > + * set of clk_ops satisfying the required combination of features and save it > + * for future references. > + * > + * In this way only one set of clk_ops is ever created for each different > + * combination that is effectively needed. > + * > + * Return: A pointer to the allocated and configured clk_ops on Success, or Lowercase 'Success'. > + * NULL otherwise. > + */ > +static const struct clk_ops * > +scmi_clk_ops_select(struct scmi_clk *sclk, bool atomic_capable, > + unsigned int atomic_threshold) > +{ > + const struct scmi_clock_info *ci = sclk->info; > + unsigned int feats_key = 0; > + const struct clk_ops *ops; > + > + /* > + * Note that when transport is atomic but SCMI protocol did not > + * specify (or support) an enable_latency associated with a > + * clock, we default to use atomic operations mode. > + */ > + if (atomic_capable && ci->enable_latency <= atomic_threshold) > + feats_key |= BIT(SCMI_CLK_ATOMIC_SUPPORTED); > + Can we have a static_assert() here that makes sure 'feats_key' isn't larger than the size of clk_ops_db? static_assert(ARRAY_SIZE(clk_ops_db) >= feats_key); > + /* Lookup previously allocated ops */ > + ops = clk_ops_db[feats_key]; > + if (!ops) { > + ops = scmi_clk_ops_alloc(sclk->dev, feats_key); > + if (!ops) > + return NULL; This could be less nested if the first lookup is put in scmi_clk_ops_alloc() and the store below is folded in. Or an early return if found. ops = clk_ops_db[feats_key]; if (ops) return ops; /* Didn't find one */ ops = scmi_clk_ops_alloc(...) if (!ops) return NULL; clk_ops_db[feats_key] = ops; return ops; > + > + /* Store new ops combinations */ > + clk_ops_db[feats_key] = ops; > + } > + > + return ops; > +} > + > static int scmi_clocks_probe(struct scmi_device *sdev) > { > int idx, count, err; > @@ -285,16 +357,10 @@ static int scmi_clocks_probe(struct scmi_device *sdev) > sclk->ph = ph; > sclk->dev = dev; > > - /* > - * Note that when transport is atomic but SCMI protocol did not > - * specify (or support) an enable_latency associated with a > - * clock, we default to use atomic operations mode. > - */ > - if (is_atomic && > - sclk->info->enable_latency <= atomic_threshold) > - scmi_ops = &scmi_atomic_clk_ops; > - else > - scmi_ops = &scmi_clk_ops; > + scmi_ops = scmi_clk_ops_select(sclk, is_atomic, 'is_atomic' should probably be 'transport_is_atomic' so this reads easier. > + atomic_threshold); > + if (!scmi_ops) > + return -ENOMEM; > > /* Initialize clock parent data. */ > if (sclk->info->num_parents > 0) { _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel