Linux-ARM-Kernel Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Yaxiong Tian <tianyaxiong@kylinos.cn>
To: Jie Zhan <zhanjie9@hisilicon.com>,
	cwchoi00@gmail.com, cw00.choi@samsung.com,
	myungjoo.ham@samsung.com, kyungmin.park@samsung.com,
	linux-pm@vger.kernel.org, linux-arm-kernel@lists.infradead.org
Cc: linuxarm@huawei.com, zhenglifeng1@huawei.com,
	zhangpengjie2@huawei.com, lihuisong@huawei.com,
	prime.zeng@hisilicon.com
Subject: Re: [PATCH v2 4/6] devfreq: Add module owner to devfreq governor
Date: Thu, 14 May 2026 14:14:52 +0800	[thread overview]
Message-ID: <fdcac90b-b253-45f2-81fa-81c980671f28@kylinos.cn> (raw)
In-Reply-To: <20260513093832.1645890-5-zhanjie9@hisilicon.com>


在 2026/5/13 17:38, Jie Zhan 写道:
> Add an 'owner' member to struct devfreq_governor, such that we can find
> the module that holds the governor code when it's compiled as a kernel
> module.  This allows the devfreq core to properly manage the lifecycle
> of governors.
>
> Update devfreq_add_governor() and devm_devfreq_add_governor() to
> automatically set 'owner' to THIS_MODULE via helper macros.
>
> This is a prerequisite for implementing governor reference counting to
> prevent a governor module from being unloaded (except for force unload)
> while a governor is in use.
>
> Signed-off-by: Jie Zhan <zhanjie9@hisilicon.com>
> ---
>   drivers/devfreq/devfreq.c        | 26 +++++++++-----------------
>   include/linux/devfreq-governor.h | 26 +++++++++++++++++++++++---
>   2 files changed, 32 insertions(+), 20 deletions(-)
>
> diff --git a/drivers/devfreq/devfreq.c b/drivers/devfreq/devfreq.c
> index 9e3e6a7348f8..e1363ab69173 100644
> --- a/drivers/devfreq/devfreq.c
> +++ b/drivers/devfreq/devfreq.c
> @@ -1301,11 +1301,8 @@ void devfreq_resume(void)
>   	mutex_unlock(&devfreq_list_lock);
>   }
>   
> -/**
> - * devfreq_add_governor() - Add devfreq governor
> - * @governor:	the devfreq governor to be added
> - */
> -int devfreq_add_governor(struct devfreq_governor *governor)
> +int __devfreq_add_governor(struct devfreq_governor *governor,
> +			   struct module *mod)
>   {
>   	struct devfreq_governor *g;
>   
> @@ -1322,37 +1319,32 @@ int devfreq_add_governor(struct devfreq_governor *governor)
>   		return -EINVAL;
>   	}
>   
> +	governor->owner = mod;
>   	list_add(&governor->node, &devfreq_governor_list);
>   
>   	return 0;
>   }
> -EXPORT_SYMBOL(devfreq_add_governor);
> +EXPORT_SYMBOL(__devfreq_add_governor);

It's a bit strange to use the __ symbol here. Generally speaking, 
functions exported with EXPORT_SYMBOL are public, while __ indicates 
internal.

The same applies below.

>   
>   static void devm_devfreq_remove_governor(void *governor)
>   {
>   	WARN_ON(devfreq_remove_governor(governor));
>   }
>   
> -/**
> - * devm_devfreq_add_governor() - Add devfreq governor
> - * @dev:	device which adds devfreq governor
> - * @governor:	the devfreq governor to be added
> - *
> - * This is a resource-managed variant of devfreq_add_governor().
> - */
> -int devm_devfreq_add_governor(struct device *dev,
> -			      struct devfreq_governor *governor)
> +int __devm_devfreq_add_governor(struct device *dev,
> +				struct devfreq_governor *governor,
> +				struct module *mod)
>   {
>   	int err;
>   
> -	err = devfreq_add_governor(governor);
> +	err = __devfreq_add_governor(governor, mod);
>   	if (err)
>   		return err;
>   
>   	return devm_add_action_or_reset(dev, devm_devfreq_remove_governor,
>   					governor);
>   }
> -EXPORT_SYMBOL(devm_devfreq_add_governor);
> +EXPORT_SYMBOL(__devm_devfreq_add_governor);
>   
>   /**
>    * devfreq_remove_governor() - Remove devfreq feature from a device.
> diff --git a/include/linux/devfreq-governor.h b/include/linux/devfreq-governor.h
> index dfdd0160a29f..1c4ff57e24de 100644
> --- a/include/linux/devfreq-governor.h
> +++ b/include/linux/devfreq-governor.h
> @@ -12,6 +12,7 @@
>   #define __LINUX_DEVFREQ_DEVFREQ_H__
>   
>   #include <linux/devfreq.h>
> +struct module;
>   
>   #define DEVFREQ_NAME_LEN			16
>   
> @@ -50,6 +51,7 @@
>   /**
>    * struct devfreq_governor - Devfreq policy governor
>    * @node:		list node - contains registered devfreq governors
> + * @owner:		Module that this governor belongs to
>    * @name:		Governor's name
>    * @attrs:		Governor's sysfs attribute flags
>    * @flags:		Governor's feature flags
> @@ -67,6 +69,7 @@
>   struct devfreq_governor {
>   	struct list_head node;
>   
> +	struct module *owner;
>   	const char name[DEVFREQ_NAME_LEN];
>   	const u64 attrs;
>   	const u64 flags;
> @@ -81,11 +84,28 @@ void devfreq_monitor_suspend(struct devfreq *devfreq);
>   void devfreq_monitor_resume(struct devfreq *devfreq);
>   void devfreq_update_interval(struct devfreq *devfreq, unsigned int *delay);
>   
> -int devfreq_add_governor(struct devfreq_governor *governor);
> +/**
> + * devfreq_add_governor() - Add devfreq governor
> + * @governor:	The devfreq governor to be added
> + */
> +#define devfreq_add_governor(governor) \
> +	__devfreq_add_governor((governor), THIS_MODULE)
> +int __devfreq_add_governor(struct devfreq_governor *governor,
> +			   struct module *mod);
>   int devfreq_remove_governor(struct devfreq_governor *governor);
>   
> -int devm_devfreq_add_governor(struct device *dev,
> -			      struct devfreq_governor *governor);
> +/**
> + * devm_devfreq_add_governor() - Add devfreq governor
> + * @dev:	device which adds devfreq governor
> + * @governor:	the devfreq governor to be added
> + *
> + * This is a resource-managed variant of devfreq_add_governor().
> + */
> +#define devm_devfreq_add_governor(dev, governor) \
> +	__devm_devfreq_add_governor((dev), (governor), THIS_MODULE)
> +int __devm_devfreq_add_governor(struct device *dev,
> +				struct devfreq_governor *governor,
> +				struct module *mod);
>   
>   int devfreq_update_status(struct devfreq *devfreq, unsigned long freq);
>   int devfreq_update_target(struct devfreq *devfreq, unsigned long freq);


  reply	other threads:[~2026-05-14  6:15 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-13  9:38 [PATCH v2 0/6] devfreq: Add refcounts for governor modules Jie Zhan
2026-05-13  9:38 ` [PATCH v2 1/6] devfreq: Use mutex guard in governor_store() Jie Zhan
2026-05-14  6:02   ` Yaxiong Tian
2026-05-13  9:38 ` [PATCH v2 2/6] devfreq: Use mutex guard in devfreq_add/remove_governor() Jie Zhan
2026-05-14  6:02   ` Yaxiong Tian
2026-05-13  9:38 ` [PATCH v2 3/6] devfreq: Factor out devfreq_set_governor() Jie Zhan
2026-05-14  6:09   ` Yaxiong Tian
2026-05-13  9:38 ` [PATCH v2 4/6] devfreq: Add module owner to devfreq governor Jie Zhan
2026-05-14  6:14   ` Yaxiong Tian [this message]
2026-05-13  9:38 ` [PATCH v2 5/6] devfreq: Get and put module refcount when switching governor Jie Zhan
2026-05-14  6:50   ` Yaxiong Tian
2026-05-13  9:38 ` [PATCH v2 6/6] devfreq: Get module refcount in try_then_request_governor() Jie Zhan

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=fdcac90b-b253-45f2-81fa-81c980671f28@kylinos.cn \
    --to=tianyaxiong@kylinos.cn \
    --cc=cw00.choi@samsung.com \
    --cc=cwchoi00@gmail.com \
    --cc=kyungmin.park@samsung.com \
    --cc=lihuisong@huawei.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=linuxarm@huawei.com \
    --cc=myungjoo.ham@samsung.com \
    --cc=prime.zeng@hisilicon.com \
    --cc=zhangpengjie2@huawei.com \
    --cc=zhanjie9@hisilicon.com \
    --cc=zhenglifeng1@huawei.com \
    /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