Received: by 2002:ab2:3350:0:b0:1f4:6588:b3a7 with SMTP id o16csp1527437lqe; Mon, 8 Apr 2024 11:24:31 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVnVGcdnu63xhKOjOAUSJqu1dqSfobIhhKtPPXRakq9jIVSqRV43eI946NCX+FoK+U9+/cr22GfsXnwcMZFko/XYKcsZ/VtdmSjN6N3Cg== X-Google-Smtp-Source: AGHT+IElWV8hip4zWRycsfdNssYi5VsXFTNksLtpbgIBY9SBUbytcjf8ZRXVYOyh3wJE3tTx1iBp X-Received: by 2002:ac2:47f3:0:b0:516:d187:8e3a with SMTP id b19-20020ac247f3000000b00516d1878e3amr5765092lfp.55.1712600671826; Mon, 08 Apr 2024 11:24:31 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712600671; cv=pass; d=google.com; s=arc-20160816; b=Nke5HN4n0zApEg6vvTuqLB6MeNQ4nmjyEtNPn99Uc0fJnCumqPqT7g12N8FqEWRuEn oK06Hy2mXi/RhNFQQUrAwWADT+ygvnc3dN1SZBUi4uo7xESmKd1IyjwSegYyF1H3pvV8 L+9jpkncVY6IMuBviXc71MgSuikEO6CFw2vdqk/AGKua1T7s5sJ7Ait5ai00JT2cFpqZ 5y6IH7r/pcjjiu2FvaGm4rbnN8CfLV46g/t3bKN4VLG65DiP2gibc5lYKhQojzaa45dQ DJNyKLJAvAsHWaLe/es6M90C/0bZYFJK2rQrj+up+WaOUZtBloa+JNWyxJRQjDqyJs6O FGBw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date; bh=UuIRt76uBfzR+/KBjC3rmrJPDv8bQycwN77aAcNnZqQ=; fh=Ura8NKIPa/a+D1DDZH8HqO/MHkng+8onb8d4rItYvkg=; b=zMKMXMmu9aFETSeStHIECy2zwB46d3AlCUt6XTx+dCsWsxiLuvr6COz73S7fehUH0T ZxdJPzM1yFNQY1/pRvOGRQoH2MGAx2MuCzTTkaFA5QLM93gvXXVct7GbTqM6WbkG9dQv 2A8xGq4ubUCKj0wuDsHOs3rZQvSGM4RmLFGjhzkKfhWSrjf6BYGAUcIOPhpys8DzvLqQ e+GCPoAoDZvMEeQnS5XaITgxojKqTTEYndXY6sNdrqf5n2iFX5IiwaYMz4X7dVUXloDn N83untve7O8zTAnb8Z5ui6zhdj8aLKe2gHQGltUpOax0qSDj3fR5sxcE+Q3u0k7M+rir BAzA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=arm.com dmarc=pass fromdomain=arm.com); spf=pass (google.com: domain of linux-kernel+bounces-135810-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-135810-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id dr2-20020a170907720200b00a474f747ee9si3897286ejc.740.2024.04.08.11.24.31 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Apr 2024 11:24:31 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-135810-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=arm.com dmarc=pass fromdomain=arm.com); spf=pass (google.com: domain of linux-kernel+bounces-135810-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-135810-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com 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 am.mirrors.kernel.org (Postfix) with ESMTPS id 224D51F26861 for ; Mon, 8 Apr 2024 18:24:11 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 18BC01448E8; Mon, 8 Apr 2024 18:24:04 +0000 (UTC) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 5DFA91448C4; Mon, 8 Apr 2024 18:24:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712600643; cv=none; b=qxd6orPogHn5tkid+QJ2vTkwsLqs8SV8o8lGt86qZC0TWTCCHxov57Me68+JDEXzwIbKsmXqyXoEyVYbgpqbhzD6+uQiR1MYH3hZ7Ab3WRnGC89JYrYV/UjCiCd4GwO1T5OG9k/PJCGg1xXp8HDCixVdJwQlh5vC3HtEydTpXZ8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712600643; c=relaxed/simple; bh=4SE1XiIqPsJ1L/kqgo8ct8w8uCtcg5bu7UGU+uxZsoo=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=Ac5AzEHz884t47engb5D3k32HR4aCWmjXKFXcHYuPXwU+XhLKomEhgMK+/mu42SBm3AjnurduQnPIA6EEx5zp1NQkGX8X7hl+ylITUp2zYjOhbqwug8KV1ffx6EOpnLYMHXs3+5f64DBk1BNtUrNqYqZQVyqVjrj3gGQkHCxAm0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; arc=none smtp.client-ip=217.140.110.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 1391CDA7; Mon, 8 Apr 2024 11:24:31 -0700 (PDT) Received: from pluto (unknown [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id A25423F766; Mon, 8 Apr 2024 11:23:58 -0700 (PDT) Date: Mon, 8 Apr 2024 19:23:55 +0100 From: Cristian Marussi To: Stephen Boyd Cc: linux-arm-kernel@lists.infradead.org, linux-clk@vger.kernel.org, linux-kernel@vger.kernel.org, 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 Subject: Re: [PATCH v2 1/5] clk: scmi: Allocate CLK operations dynamically Message-ID: References: <20240325210025.1448717-1-cristian.marussi@arm.com> <20240325210025.1448717-2-cristian.marussi@arm.com> <7027a28723d2597d9f620f4e0e1da97e.sboyd@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <7027a28723d2597d9f620f4e0e1da97e.sboyd@kernel.org> On Sun, Apr 07, 2024 at 09:38:46PM -0700, Stephen Boyd wrote: > 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 > > Hi, thanks for the review. > > +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? > Yes. > > 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. > Ok. > > + * > > + * 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'. > Ok. > > + > > +/** > > + * 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]" > It is micro, I will comment better. > > + * > > + * 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'. > Ok. > > + * 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); > Ok. > > + /* 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; > ok. > > + > > + /* 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. > Ok. Thanks, Cristian