units: Add the HZ_PER_KHZ macro
Subsystems (4)
PATCH 1/2 units: Add the HZ_PER_KHZ macro
The macro for the unit conversion for frequency is duplicated in different places.
Provide this macro in the 'units' header, so it can be reused.
--- include/linux/units.h | 4 ++++ 1 file changed, 4 insertions(+)
include/linux/units.h +4 -0
@@ -4,6 +4,10 @@#include <linux/math.h> +#define HZ_PER_KHZ 1000L +#define KHZ_PER_MHZ 1000L +#define HZ_PER_MHZ 1000000L +#define MILLIWATT_PER_WATT 1000L#define MICROWATT_PER_MILLIWATT 1000L#define MICROWATT_PER_WATT 1000000L
Signature · 1 line
2.17.1
PATCH 2/2 units: Use the HZ_PER_KHZ macro
The HZ_PER_KHZ macro definition is duplicated in different subsystems.
The macro now exists in include/linux/units.h, make use of it and remove all the duplicated ones.
--- drivers/devfreq/devfreq.c | 2 +- drivers/iio/light/as73211.c | 3 +-- drivers/thermal/devfreq_cooling.c | 2 +- 3 files changed, 3 insertions(+), 4 deletions(-)
drivers/devfreq/devfreq.c +1 -1
@@ -26,6 +26,7 @@#include <linux/hrtimer.h> #include <linux/of.h> #include <linux/pm_qos.h> +#include <linux/units.h> #include "governor.h" #define CREATE_TRACE_POINTS
@@ -33,7 +34,6 @@#define IS_SUPPORTED_FLAG (f, name) ((f & DEVFREQ_GOV_FLAG_##name) ? true : false)#define IS_SUPPORTED_ATTR (f, name) ((f & DEVFREQ_GOV_ATTR_##name) ? true : false) -#define HZ_PER_KHZ 1000static struct class *devfreq_class;static struct dentry *devfreq_debugfs;
drivers/iio/light/as73211.c +1 -2
@@ -24,8 +24,7 @@#include <linux/module.h> #include <linux/mutex.h> #include <linux/pm.h> - -#define HZ_PER_KHZ 1000 +#include <linux/units.h> #define AS73211_DRV_NAME "as73211"
drivers/thermal/devfreq_cooling.c +1 -1
@@ -19,10 +19,10 @@#include <linux/pm_opp.h> #include <linux/pm_qos.h> #include <linux/thermal.h> +#include <linux/units.h> #include <trace/events/thermal.h> -#define HZ_PER_KHZ 1000#define SCALE_ERROR_MITIGATION 100static DEFINE_IDA (devfreq_ida);
Signature · 1 line
2.17.1
Re: [PATCH 2/2] units: Use the HZ_PER_KHZ macro
Quoted 53 lines · Daniel Lezcano
The
HZ_PER_KHZmacro definition is duplicated in different subsystems.The macro now exists in
include/linux/units.h, make use of it and remove all the duplicated ones.Signed-off-by Daniel Lezcano <[email protected]>--- drivers/devfreq/devfreq.c | 2 +- drivers/iio/light/as73211.c | 3 +-- drivers/thermal/devfreq_cooling.c | 2 +- 3 files changed, 3 insertions(+), 4 deletions(-)drivers/devfreq/devfreq.c +1
-1@@ -26,6 +26,7 @@#include <linux/hrtimer.h> #include <linux/of.h> #include <linux/pm_qos.h> +#include <linux/units.h> #include "governor.h" #define CREATE_TRACE_POINTS @@ -33,7 +34,6 @@#define IS_SUPPORTED_FLAG (f, name) ((f & DEVFREQ_GOV_FLAG_##name) ? true : false)#define IS_SUPPORTED_ATTR (f, name) ((f & DEVFREQ_GOV_ATTR_##name) ? true : false) -#define HZ_PER_KHZ 1000static struct class *devfreq_class;static struct dentry *devfreq_debugfs;drivers/iio/light/as73211.c +1
-2@@ -24,8 +24,7 @@#include <linux/module.h> #include <linux/mutex.h> #include <linux/pm.h> - -#define HZ_PER_KHZ 1000 +#include <linux/units.h> #define AS73211_DRV_NAME "as73211"drivers/thermal/devfreq_cooling.c +0
-0@@ -19,10 +19,10 @@#include <linux/pm_opp.h>
drivers/thermal/devfreq_cooling.c line 28
Quoted 10 lines
drivers/thermal/devfreq_cooling.c +1
-1#include <linux/pm_qos.h> #include <linux/thermal.h> +#include <linux/units.h> #include <trace/events/thermal.h> -#define HZ_PER_KHZ 1000#define SCALE_ERROR_MITIGATION 100static DEFINE_IDA (devfreq_ida);
Re: [PATCH 2/2] units: Use the HZ_PER_KHZ macro
In reply to Daniel LezcanoQuoted 53 lines · Daniel Lezcano
The
HZ_PER_KHZmacro definition is duplicated in different subsystems.The macro now exists in
include/linux/units.h, make use of it and remove all the duplicated ones.Signed-off-by Daniel Lezcano <[email protected]>--- drivers/devfreq/devfreq.c | 2 +- drivers/iio/light/as73211.c | 3 +-- drivers/thermal/devfreq_cooling.c | 2 +- 3 files changed, 3 insertions(+), 4 deletions(-)drivers/devfreq/devfreq.c +1
-1@@ -26,6 +26,7 @@#include <linux/hrtimer.h> #include <linux/of.h> #include <linux/pm_qos.h> +#include <linux/units.h> #include "governor.h" #define CREATE_TRACE_POINTS @@ -33,7 +34,6 @@#define IS_SUPPORTED_FLAG (f, name) ((f & DEVFREQ_GOV_FLAG_##name) ? true : false)#define IS_SUPPORTED_ATTR (f, name) ((f & DEVFREQ_GOV_ATTR_##name) ? true : false) -#define HZ_PER_KHZ 1000static struct class *devfreq_class;static struct dentry *devfreq_debugfs;drivers/iio/light/as73211.c +1
-2@@ -24,8 +24,7 @@#include <linux/module.h> #include <linux/mutex.h> #include <linux/pm.h> - -#define HZ_PER_KHZ 1000 +#include <linux/units.h> #define AS73211_DRV_NAME "as73211"drivers/thermal/devfreq_cooling.c +0
-0@@ -19,10 +19,10 @@#include <linux/pm_opp.h>
drivers/thermal/devfreq_cooling.c line 28
Quoted 10 lines
drivers/thermal/devfreq_cooling.c +1
-1#include <linux/pm_qos.h> #include <linux/thermal.h> +#include <linux/units.h> #include <trace/events/thermal.h> -#define HZ_PER_KHZ 1000#define SCALE_ERROR_MITIGATION 100static DEFINE_IDA (devfreq_ida);
For devfreq part,
Signature · 3 lines
Best Regards, Chanwoo Choi Samsung Electronics
A message that is not in the archive (sent off-list or not yet received): CAHp75VcJwoye5KOYXF3Fs1F-82JPP-7VaU4z5OqBrYDr+AGQ5w@mail.gmail.com
A message that is not in the archive (sent off-list or not yet received): CAHp75Vcqug9qC_ejHE03YguiSy-XpsZV6g36-pe3VOFgTS2-tA@mail.gmail.com
Quoted 22 lines · On Wed, 24 Feb 2021 10:39:36 +0200 Andy Shevchenko <[email protected]>…
Quoted 8 lines · Andy Shevchenko
Quoted 3 lines · Daniel Lezcano
The macro for the unit conversion for frequency is duplicated in different places.
Quoted 10 lines
Quoted 3 lines
Provide this macro in the 'units' header, so it can be reused.
Thanks! That was the idea behind my reviews to add those definitions explicitly in the users. I just want to be sure you covered them all. Also there are few non-standard names for above in some drivers (they can be fixed on per driver basis in separate patches though).
Quoted 3 lines
Seems you introduced a common macro and forget about dropping it elsewhere.
Yes. And HZ_PER_KHZ.
Also, why make them signed types? Negative Hz is physically nonsensical. If that upsets some code somewhere because it was dealing with signed types then, well, that code needed fixing anyway.
Ditto MILLIWATT_PER_WATT and friends, sigh.
Quoted 1 line · Andrew Morton
On Wed, 24 Feb 2021 10:39:36 +0200 Andy Shevchenko <[email protected]> wrote:
...
Quoted 5 lines
Also, why make them signed types? Negative Hz is physically nonsensical. If that upsets some code somewhere because it was dealing with signed types then, well, that code needed fixing anyway.
Ditto
MILLIWATT_PER_WATTand friends, sigh.
And all seconds also. I guess it's historically like this and in any case I don't expect we will have multipliers that don't fit long long.
There might be some subtle integral promotion rules that screw the flow up, but I have not much experience with it to be honest.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Hi Andrew,
Quoted 24 lines · Andrew Morton
Quoted 22 lines · On Wed, 24 Feb 2021 10:39:36 +0200 Andy Shevchenko <[email protected]>…
Quoted 18 lines · Andy Shevchenko
Quoted 6 lines · Daniel Lezcano
The macro for the unit conversion for frequency is duplicated in different places.
Provide this macro in the 'units' header, so it can be reused.
Thanks! That was the idea behind my reviews to add those definitions explicitly in the users. I just want to be sure you covered them all. Also there are few non-standard names for above in some drivers (they can be fixed on per driver basis in separate patches though).
Quoted 5 lines
Quoted 3 lines
Seems you introduced a common macro and forget about dropping it elsewhere.
Yes. And
HZ_PER_KHZ.
Thanks for the review, it is fixed it in the v2.
Quoted 5 lines
Also, why make them signed types? Negative Hz is physically nonsensical. If that upsets some code somewhere because it was dealing with signed types then, well, that code needed fixing anyway.
Ditto
MILLIWATT_PER_WATTand friends, sigh.
At the first glance converting to unsigned long should not hurt the users of this macro.
The current series introduces the macro and its usage but by converting the existing type.
Is it ok if I send a separate series to change the units from L to UL?
Signature · 5 lines
<http://www.linaro.org/> Linaro.org │ Open source software for ARM SoCs Follow Linaro: <http://www.facebook.com/pages/Linaro> Facebook | <http://twitter.com/#!/linaroorg> Twitter | <http://www.linaro.org/linaro-blog/> Blog
Quoted 6 lines · On Thu, 4 Mar 2021 13:41:27 +0100 Daniel Lezcano <[email protected]>…
Quoted 5 lines
Also, why make them signed types? Negative Hz is physically nonsensical. If that upsets some code somewhere because it was dealing with signed types then, well, that code needed fixing anyway.
Ditto
MILLIWATT_PER_WATTand friends, sigh.
Quoted 7 lines
At the first glance converting to unsigned long should not hurt the users of this macro.
The current series introduces the macro and its usage but by converting the existing type.
Is it ok if I send a separate series to change the units from L to UL?
That's the way to do it...