devfreq: event: Add new devfreq_event class to provide basic data for devfreq governor
Hi Chanwoo,
I love the idea and I now have a little mechanical issues in your code.
Quoted 33 lines
--- drivers/devfreq/Kconfig | 2 + drivers/devfreq/Makefile | 5 +- drivers/devfreq/devfreq-event.c | 449 ++++++++++++++++++++++++++++++++++++++++ drivers/devfreq/event/Makefile | 1 + include/linux/devfreq.h | 160 ++++++++++++++ 5 files changed, 616 insertions(+), 1 deletion(-) create mode 100644 drivers/devfreq/devfreq-event.c create mode 100644 drivers/devfreq/event/Makefiledrivers/devfreq/Kconfig +2
-0@@ -87,4 +87,6 @@ config ARM_EXYNOS5_BUS_DEVFREQ It reads PPMU counters of memory controllers and adjusts the operating frequencies and voltages with OPP support. +comment "DEVFREQ Event Drivers" + endif # PM_DEVFREQdrivers/devfreq/Makefile +1
-1@@ -1,4 +1,4 @@ -obj-$(CONFIG_PM_DEVFREQ) += devfreq.o +obj-$(CONFIG_PM_DEVFREQ) += devfreq.o devfreq-event.o obj-$(CONFIG_DEVFREQ_GOV_SIMPLE_ONDEMAND) += governor_simpleondemand.o obj-$(CONFIG_DEVFREQ_GOV_PERFORMANCE) += governor_performance.o obj-$(CONFIG_DEVFREQ_GOV_POWERSAVE) += governor_powersave.o
drivers/devfreq/Makefile obj-$(CONFIG_DEVFREQ_GOV_USERSPACE) += governor_userspace.o · line 12
Quoted 6 lines
drivers/devfreq/Makefile +3
-0@@ -7,3 +7,6 @@ obj-$(CONFIG_DEVFREQ_GOV_USERSPACE) += governor_userspace.o # DEVFREQ Drivers obj-$(CONFIG_ARM_EXYNOS4_BUS_DEVFREQ) += exynos/ obj-$(CONFIG_ARM_EXYNOS5_BUS_DEVFREQ) += exynos/ + +# DEVFREQ Event Drivers +obj-$(CONFIG_PM_DEVFREQ) += event/
It looks getting mature fast.
However, I would like to suggest you to
allow not to compile devfreq-event.c and not include its compiled object
if devfreq.c is required but devfreq-event.c is not required. (e.g., add CONFIG_PM_DEVFREQ_EVENT and let it be enabled when needed) just a little concern for lightweight devices.
(this change might require a bit more work on the header as well)
- Or do you think devfreq-event.c will become almost mandatory for most devfreq drivers?
[snip]
drivers/devfreq/devfreq-event.c line 2
Quoted 8 lines
drivers/devfreq/devfreq-event.c new file +2
-0@@ -0,0 +1,449 @@ +/* +* devfreq-event: Generic DEVFREQ Event class driver
DEVFREQ is a generic DVFS mechanism (or subsystem).
Plus, I thought devfreq-event is considered to be a "framework" for devfreq event class drivers. Am I mistaken?
[snip]
Quoted 11 lines
drivers/devfreq/devfreq-event.c new file +11
-0+struct devfreq_event_dev *devfreq_event_add_edev (struct device *dev, +struct devfreq_event_desc *desc) +{ +struct devfreq_event_dev *edev; +static atomic_t event_no =ATOMIC_INIT (0 ); +int ret; + +if (!dev || !desc) +return ERR_PTR (-EINVAL ); + +if (!desc->name || !desc->ops)
drivers/devfreq/devfreq-event.c line 23
Quoted 10 lines
drivers/devfreq/devfreq-event.c new file +10
-0+return ERR_PTR (-EINVAL ); + +if (!desc->ops->set_event || !desc->ops->get_event) +return ERR_PTR (-EINVAL ); + + edev =devm_kzalloc (dev,sizeof (*edev),GFP_KERNEL ); +if (!edev) +return ERR_PTR (-ENOMEM ); + +mutex_lock (&devfreq_event_list_lock);
You seem to lock that global lock too long. That lock is only required while you operate the list. The data to be protected by this mutex is devfreq_event_list. Until the new entry is added to the list, the new entry is free from protection. (may be delayed right before list_add)
Quoted 11 lines
drivers/devfreq/devfreq-event.c new file +11
-0+mutex_init (&edev->lock); + edev->desc = desc; + edev->dev.parent = dev; + edev->dev.class = devfreq_event_class; + edev->dev.release = devfreq_event_release_edev; + +dev_set_name (&edev->dev,"event.%d" ,atomic_inc_return (&event_no) -1 ); + ret =device_register (&edev->dev); +if (ret <0 ) { +put_device (&edev->dev); +mutex_unlock (&devfreq_event_list_lock);
drivers/devfreq/devfreq-event.c line 44
Quoted 10 lines
drivers/devfreq/devfreq-event.c new file +10
-0+return ERR_PTR (ret); + } +dev_set_drvdata (&edev->dev, edev); + +INIT_LIST_HEAD (&edev->node); +list_add (&edev->node, &devfreq_event_list); +mutex_unlock (&devfreq_event_list_lock); + +return edev; +}
[snip / reversed maybe.. sorry]
Quoted 13 lines
drivers/devfreq/devfreq-event.c new file +13
-0+/** +* devfreq_event_is_enabled() - Check whether devfreq-event dev is enabled or +* not. +* @edev : the devfreq-event device +* +* Note that this function check whether devfreq-event dev is enabled or not. +* If return true, the devfreq-event dev is enabeld. If return false, the +* devfreq-event dev is disabled. +*/ +bool devfreq_event_is_enabled (struct devfreq_event_dev *edev) +{ +bool enabled = false; +
drivers/devfreq/devfreq-event.c line 67
Quoted 10 lines
drivers/devfreq/devfreq-event.c new file +10
-0+if (!edev || !edev->desc) +return enabled; + +mutex_lock (&edev->lock); + +if (edev->enable_count >0 ) + enabled = true; + +if (edev->desc->ops && edev->desc->ops->is_enabled) + enabled |= edev->desc->ops->is_enabled (edev);
What does it mean when enabled_count > 0 and ops->is_enabled() is false? or.. What does it mean when enabled_count = 0 and ops->is_enabled() is true?
If you do enable_count in the subsystem, why would we rely on ops->is_enabled()? Are you assuming that a device MAY turn itself off without any kernel control (ops->disable()) and it is still a correct behabior?
drivers/devfreq/devfreq-event.c line 73
Quoted 6 lines
drivers/devfreq/devfreq-event.c new file +6
-0+ +mutex_unlock (&edev->lock); + +return enabled; +} +EXPORT_SYMBOL_GPL (devfreq_event_is_enabled);
Cheers,
MyungJoo
Dear Myungjoo,
Thanks for your review.
Quoted 47 lines · MyungJoo Ham
Hi Chanwoo,
I love the idea and I now have a little mechanical issues in your code.
Quoted 33 lines
--- drivers/devfreq/Kconfig | 2 + drivers/devfreq/Makefile | 5 +- drivers/devfreq/devfreq-event.c | 449 ++++++++++++++++++++++++++++++++++++++++ drivers/devfreq/event/Makefile | 1 + include/linux/devfreq.h | 160 ++++++++++++++ 5 files changed, 616 insertions(+), 1 deletion(-) create mode 100644 drivers/devfreq/devfreq-event.c create mode 100644 drivers/devfreq/event/Makefiledrivers/devfreq/Kconfig +2
-0@@ -87,4 +87,6 @@ config ARM_EXYNOS5_BUS_DEVFREQ It reads PPMU counters of memory controllers and adjusts the operating frequencies and voltages with OPP support. +comment "DEVFREQ Event Drivers" + endif # PM_DEVFREQdrivers/devfreq/Makefile +1
-1@@ -1,4 +1,4 @@ -obj-$(CONFIG_PM_DEVFREQ) += devfreq.o +obj-$(CONFIG_PM_DEVFREQ) += devfreq.o devfreq-event.o obj-$(CONFIG_DEVFREQ_GOV_SIMPLE_ONDEMAND) += governor_simpleondemand.o obj-$(CONFIG_DEVFREQ_GOV_PERFORMANCE) += governor_performance.o obj-$(CONFIG_DEVFREQ_GOV_POWERSAVE) += governor_powersave.odrivers/devfreq/Makefile obj-$(CONFIG_DEVFREQ_GOV_USERSPACE) += governor_userspace.o · line 12
Quoted 6 lines
drivers/devfreq/Makefile +3
-0@@ -7,3 +7,6 @@ obj-$(CONFIG_DEVFREQ_GOV_USERSPACE) += governor_userspace.o # DEVFREQ Drivers obj-$(CONFIG_ARM_EXYNOS4_BUS_DEVFREQ) += exynos/ obj-$(CONFIG_ARM_EXYNOS5_BUS_DEVFREQ) += exynos/ + +# DEVFREQ Event Drivers +obj-$(CONFIG_PM_DEVFREQ) += event/It looks getting mature fast.
However, I would like to suggest you to
Quoted 7 lines
allow not to compile
devfreq-event.cand not include its compiled object
ifdevfreq.cis required butdevfreq-event.cis not required. (e.g., addCONFIG_PM_DEVFREQ_EVENTand let it be enabled when needed) just a little concern for lightweight devices.
(this change might require a bit more work on the header as well)
- Or do you thinkdevfreq-event.cwill become almost mandatory for most devfreq drivers?
I agree your opinion.
I'll add CONFIG_PM_DEVFREQ_EVENT according to your comment.
Quoted 15 lines
[snip]
drivers/devfreq/devfreq-event.c line 2
Quoted 8 lines
drivers/devfreq/devfreq-event.c new file +2
-0@@ -0,0 +1,449 @@ +/* +* devfreq-event: Generic DEVFREQ Event class driver DEVFREQ is a generic DVFS mechanism (or subsystem).
Quoted 2 lines
Plus, I thought devfreq-event is considered to be a "framework" for devfreq event class drivers. Am I mistaken?
You're right. just "class driver" description is not proper. I'll modify the description of devfreq-event.c as following:
or If you have other opinion, would you please let me know about it?
devfreq-event: DEVFREQ-Event Framework to provide raw data of Non-CPU Devices.
Quoted 20 lines
[snip]
Quoted 18 lines
drivers/devfreq/devfreq-event.c new file +18
-0+struct devfreq_event_dev *devfreq_event_add_edev (struct device *dev, +struct devfreq_event_desc *desc) +{ +struct devfreq_event_dev *edev; +static atomic_t event_no =ATOMIC_INIT (0 ); +int ret; + +if (!dev || !desc) +return ERR_PTR (-EINVAL ); + +if (!desc->name || !desc->ops) +return ERR_PTR (-EINVAL ); + +if (!desc->ops->set_event || !desc->ops->get_event) +return ERR_PTR (-EINVAL ); + + edev =devm_kzalloc (dev,sizeof (*edev),GFP_KERNEL ); +if (!edev)
Quoted 8 lines
drivers/devfreq/devfreq-event.c
Quoted 3 lines
drivers/devfreq/devfreq-event.c new file +3
-0+return ERR_PTR (-ENOMEM ); + +mutex_lock (&devfreq_event_list_lock);You seem to lock that global lock too long. That lock is only required while you operate the list. The data to be protected by this mutex is
devfreq_event_list. Until the new entry is added to the list, the new entry is free from protection. (may be delayed right beforelist_add)
OK. I'll move global lock right before calling list_add() on below.
Quoted 54 lines
Quoted 12 lines
drivers/devfreq/devfreq-event.c new file +11
-0+mutex_init (&edev->lock); + edev->desc = desc; + edev->dev.parent = dev; + edev->dev.class = devfreq_event_class; + edev->dev.release = devfreq_event_release_edev; + +dev_set_name (&edev->dev,"event.%d" ,atomic_inc_return (&event_no) -1 ); + ret =device_register (&edev->dev); +if (ret <0 ) { +put_device (&edev->dev); +mutex_unlock (&devfreq_event_list_lock);drivers/devfreq/devfreq-event.c
Quoted 10 lines
drivers/devfreq/devfreq-event.c new file +10
-0+return ERR_PTR (ret); + } +dev_set_drvdata (&edev->dev, edev); + +INIT_LIST_HEAD (&edev->node); +list_add (&edev->node, &devfreq_event_list); +mutex_unlock (&devfreq_event_list_lock); + +return edev; +}[snip / reversed maybe.. sorry]
Quoted 13 lines
drivers/devfreq/devfreq-event.c new file +13
-0+/** +* devfreq_event_is_enabled() - Check whether devfreq-event dev is enabled or +* not. +* @edev : the devfreq-event device +* +* Note that this function check whether devfreq-event dev is enabled or not. +* If return true, the devfreq-event dev is enabeld. If return false, the +* devfreq-event dev is disabled. +*/ +bool devfreq_event_is_enabled (struct devfreq_event_dev *edev) +{ +bool enabled = false; +drivers/devfreq/devfreq-event.c
Quoted 10 lines
drivers/devfreq/devfreq-event.c new file +10
-0+if (!edev || !edev->desc) +return enabled; + +mutex_lock (&edev->lock); + +if (edev->enable_count >0 ) + enabled = true; + +if (edev->desc->ops && edev->desc->ops->is_enabled) + enabled |= edev->desc->ops->is_enabled (edev);What does it mean when
enabled_count> 0 andops->is_enabled()is false? or.. What does it mean whenenabled_count= 0 andops->is_enabled()is true?
Quoted 4 lines
If you do
enable_countin the subsystem, why would we rely onops->is_enabled()? Are you assuming that a device MAY turn itself off without any kernel control (ops->disable()) and it is still a correct behabior?
You're right. devfreq_event_is_enabled() has ambiguous operation according to your comment.
I'll only control the enable_count in the subsystem without ops->is_enabled() and then remove the is_enabled function in the structre devfreq_event_ops.
Best Regards,
Chanwoo Choi