linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: Stephen Boyd <sboyd@kernel.org>
To: Cristian Marussi <cristian.marussi@arm.com>,
	linux-arm-kernel@lists.infradead.org, linux-clk@vger.kernel.org,
	linux-kernel@vger.kernel.org
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 <cristian.marussi@arm.com>
Subject: Re: [PATCH v2 1/5] clk: scmi: Allocate CLK operations dynamically
Date: Sun, 07 Apr 2024 21:38:46 -0700	[thread overview]
Message-ID: <7027a28723d2597d9f620f4e0e1da97e.sboyd@kernel.org> (raw)
In-Reply-To: <20240325210025.1448717-2-cristian.marussi@arm.com>

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

  parent reply	other threads:[~2024-04-08  4:39 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-25 21:00 [PATCH v2 0/5] Rework SCMI Clock driver clk_ops setup procedure Cristian Marussi
2024-03-25 21:00 ` [PATCH v2 1/5] clk: scmi: Allocate CLK operations dynamically Cristian Marussi
2024-03-30  3:42   ` Florian Fainelli
2024-04-08  4:38   ` Stephen Boyd [this message]
2024-04-08 18:23     ` Cristian Marussi
2024-03-25 21:00 ` [PATCH v2 2/5] clk: scmi: Add support for state control restricted clocks Cristian Marussi
2024-03-30  3:43   ` Florian Fainelli
2024-04-08  4:48   ` Stephen Boyd
2024-04-08 18:26     ` Cristian Marussi
2024-03-25 21:00 ` [PATCH v2 3/5] clk: scmi: Add support for rate change " Cristian Marussi
2024-03-30  3:43   ` Florian Fainelli
2024-03-25 21:00 ` [PATCH v2 4/5] clk: scmi: Add support for re-parenting " Cristian Marussi
2024-03-30  3:43   ` Florian Fainelli
2024-03-25 21:00 ` [PATCH v2 5/5] clk: scmi: Add support for get/set duty_cycle operations Cristian Marussi
2024-03-30  3:44   ` Florian Fainelli
2024-04-04 14:25 ` [PATCH v2 0/5] Rework SCMI Clock driver clk_ops setup procedure Sudeep Holla

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=7027a28723d2597d9f620f4e0e1da97e.sboyd@kernel.org \
    --to=sboyd@kernel.org \
    --cc=cristian.marussi@arm.com \
    --cc=f.fainelli@gmail.com \
    --cc=james.quinlan@broadcom.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-clk@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=michal.simek@amd.com \
    --cc=mturquette@baylibre.com \
    --cc=peng.fan@oss.nxp.com \
    --cc=quic_nkela@quicinc.com \
    --cc=quic_sibis@quicinc.com \
    --cc=souvik.chakravarty@arm.com \
    --cc=sudeep.holla@arm.com \
    --cc=vincent.guittot@linaro.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).