diff mbox series

[v2] devfreq: Support device update function

Message ID 20221003060201.14833-1-johnliu@nvidia.com
State Superseded
Headers show
Series [v2] devfreq: Support device update function | expand

Commit Message

Johnny Liu Oct. 3, 2022, 6:02 a.m. UTC
To realize interrupt-driven closed-loop governors, governors need to be
able to send data to the underlying devfreq driver to ask for updating
the device settings, such as hardware registers for frequency limits,
which are compared against the device frequency to generate interrupts.

Since governors might export several tunable parameters, users can
enforce different policies for the control logics. Under different
policies, governors need to send different information to inform the
devfreq driver to configure the device accordingly.

The introduced update function improves the flexibility of governors
and acts as a communication interface between governors and devfreq
drivers.

Signed-off-by: Johnny Liu <johnliu@nvidia.com>
---
v2: Correct the function signature of devfreq_update_dev

 drivers/devfreq/governor.h | 8 ++++++++
 include/linux/devfreq.h    | 8 ++++++++
 2 files changed, 16 insertions(+)

Comments

Chanwoo Choi Oct. 12, 2022, 7:44 p.m. UTC | #1
Hi,

Basically, struct devfreq_dev_profile is used to pass the devfreq device data
from devfreq driver to governor. But, This means that it passes
the data from governor to devfreq driver reversely?

On 22. 10. 3. 15:02, Johnny Liu wrote:
> To realize interrupt-driven closed-loop governors, governors need to be

Could you explain the detailed means of 'interrupt-driven closed-loop governors'?

> able to send data to the underlying devfreq driver to ask for updating
> the device settings, such as hardware registers for frequency limits,

I think that governor is not able to get the hardware information direclty
instead of devfreq driver. Usually, the devfreq driver should get the
h/w info and then passed to governor if required.

Lastly, this patch doesn't contain the any use-case of devfreq_update_dev().
I prefer to post the real use-case of this patch. 

> which are compared against the device frequency to generate interrupts
> 
> Since governors might export several tunable parameters, users can
> enforce different policies for the control logics. Under different
> policies, governors need to send different information to inform the
> devfreq driver to configure the device accordingly.
> 
> The introduced update function improves the flexibility of governors
> and acts as a communication interface between governors and devfreq
> drivers.
> 
> Signed-off-by: Johnny Liu <johnliu@nvidia.com>
> ---
> v2: Correct the function signature of devfreq_update_dev
> 
>  drivers/devfreq/governor.h | 8 ++++++++
>  include/linux/devfreq.h    | 8 ++++++++
>  2 files changed, 16 insertions(+)
> 
> diff --git a/drivers/devfreq/governor.h b/drivers/devfreq/governor.h
> index 0adfebc0467a..b5781fa549c7 100644
> --- a/drivers/devfreq/governor.h
> +++ b/drivers/devfreq/governor.h
> @@ -124,4 +124,12 @@ static inline int devfreq_update_stats(struct devfreq *df)
>  
>  	return df->profile->get_dev_status(df->dev.parent, &df->last_status);
>  }
> +
> +static inline int devfreq_update_dev(struct devfreq *df, void *data)
> +{
> +	if (!df->profile->update)
> +		return -EINVAL;
> +
> +	return df->profile->update(df->dev.parent, data);
> +}
>  #endif /* _GOVERNOR_H */
> diff --git a/include/linux/devfreq.h b/include/linux/devfreq.h
> index 34aab4dd336c..91648e8f8d76 100644
> --- a/include/linux/devfreq.h
> +++ b/include/linux/devfreq.h
> @@ -92,6 +92,8 @@ struct devfreq_dev_status {
>   *			devfreq.last_status.
>   * @get_cur_freq:	The device should provide the current frequency
>   *			at which it is operating.
> + * @update:		An optional function to allow governors send data back
> + *			to the devfreq driver to update the device settings.

IMO, 'update' word is too generic. I think that 'update_device_data' is better
to improve the readability.

>   * @exit:		An optional callback that is called when devfreq
>   *			is removing the devfreq object due to error or
>   *			from devfreq_remove_device() call. If the user
> @@ -114,6 +116,7 @@ struct devfreq_dev_profile {
>  	int (*get_dev_status)(struct device *dev,
>  			      struct devfreq_dev_status *stat);
>  	int (*get_cur_freq)(struct device *dev, unsigned long *freq);
> +	int (*update)(struct device *dev, void *data);
>  	void (*exit)(struct device *dev);
>  
>  	unsigned long *freq_table> @@ -451,6 +454,11 @@ static inline int devfreq_update_stats(struct devfreq *df)
>  {
>  	return -EINVAL;
>  }
> +
> +static inline int devfreq_update_dev(struct devfreq *df, void *data)
> +{
> +	return -EINVAL;
> +}
>  #endif /* CONFIG_PM_DEVFREQ */
>  
>  #endif /* __LINUX_DEVFREQ_H__ */
diff mbox series

Patch

diff --git a/drivers/devfreq/governor.h b/drivers/devfreq/governor.h
index 0adfebc0467a..b5781fa549c7 100644
--- a/drivers/devfreq/governor.h
+++ b/drivers/devfreq/governor.h
@@ -124,4 +124,12 @@  static inline int devfreq_update_stats(struct devfreq *df)
 
 	return df->profile->get_dev_status(df->dev.parent, &df->last_status);
 }
+
+static inline int devfreq_update_dev(struct devfreq *df, void *data)
+{
+	if (!df->profile->update)
+		return -EINVAL;
+
+	return df->profile->update(df->dev.parent, data);
+}
 #endif /* _GOVERNOR_H */
diff --git a/include/linux/devfreq.h b/include/linux/devfreq.h
index 34aab4dd336c..91648e8f8d76 100644
--- a/include/linux/devfreq.h
+++ b/include/linux/devfreq.h
@@ -92,6 +92,8 @@  struct devfreq_dev_status {
  *			devfreq.last_status.
  * @get_cur_freq:	The device should provide the current frequency
  *			at which it is operating.
+ * @update:		An optional function to allow governors send data back
+ *			to the devfreq driver to update the device settings.
  * @exit:		An optional callback that is called when devfreq
  *			is removing the devfreq object due to error or
  *			from devfreq_remove_device() call. If the user
@@ -114,6 +116,7 @@  struct devfreq_dev_profile {
 	int (*get_dev_status)(struct device *dev,
 			      struct devfreq_dev_status *stat);
 	int (*get_cur_freq)(struct device *dev, unsigned long *freq);
+	int (*update)(struct device *dev, void *data);
 	void (*exit)(struct device *dev);
 
 	unsigned long *freq_table;
@@ -451,6 +454,11 @@  static inline int devfreq_update_stats(struct devfreq *df)
 {
 	return -EINVAL;
 }
+
+static inline int devfreq_update_dev(struct devfreq *df, void *data)
+{
+	return -EINVAL;
+}
 #endif /* CONFIG_PM_DEVFREQ */
 
 #endif /* __LINUX_DEVFREQ_H__ */