* [PATCH v2 0/4] Consolidate DIV_ROUND_CLOSEST_ULL()
@ 2015-03-24 14:03 Javi Merino
2015-03-24 14:03 ` [PATCH v2 1/4] kernel.h: Implement DIV_ROUND_CLOSEST_ULL Javi Merino
` (3 more replies)
0 siblings, 4 replies; 9+ messages in thread
From: Javi Merino @ 2015-03-24 14:03 UTC (permalink / raw)
To: akpm
Cc: intel-gfx, dri-devel, linux-kernel, emil.l.velikov, jepler,
daniel, Javi Merino
The kernel has grown a number of different implementations of
DIV_ROUND_CLOSEST_ULL(). That is, a macro that does the same as
DIV_ROUND_CLOSEST() but with the first operand being an unsigned long
long. That means that you have to do the division using do_div()
instead of using the C division operator '/'.
This series move the implementation in
drivers/gpu/drm/i915/intel_drv.h to linux/kernel.h and then removes
the other similar implementations of the same code in
drivers/clk/bcm/clk-kona.h, drivers/cpuidle/governors/menu.c and
drivers/media/dvb-frontends/cxd2820r_priv.h in favor of the one in
kernel.h
Changes since v1:
- inlcude linux/kernel.h in drivers/gpu/drm/i915/intel_panel.c
instead of drivers/gpu/drm/i915/intel_drv.h as Emil Velikov
suggests
- Avoid evaluating 'divisor' twice
Javi Merino (4):
kernel.h: Implement DIV_ROUND_CLOSEST_ULL
clk: bcm/kona: use DIV_ROUND_CLOSEST_ULL()
cpuidle: menu: use DIV_ROUND_CLOSEST_ULL()
media: cxd2820r: use DIV_ROUND_CLOSEST_ULL()
drivers/clk/bcm/clk-kona.c | 28 +++++++---------------------
drivers/clk/bcm/clk-kona.h | 1 -
drivers/cpuidle/governors/menu.c | 8 +-------
drivers/gpu/drm/i915/intel_drv.h | 3 ---
drivers/gpu/drm/i915/intel_panel.c | 1 +
drivers/media/dvb-frontends/cxd2820r_c.c | 2 +-
drivers/media/dvb-frontends/cxd2820r_core.c | 6 ------
drivers/media/dvb-frontends/cxd2820r_priv.h | 2 --
drivers/media/dvb-frontends/cxd2820r_t.c | 2 +-
drivers/media/dvb-frontends/cxd2820r_t2.c | 2 +-
include/linux/kernel.h | 12 ++++++++++++
11 files changed, 24 insertions(+), 43 deletions(-)
--
1.9.1
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH v2 1/4] kernel.h: Implement DIV_ROUND_CLOSEST_ULL
2015-03-24 14:03 [PATCH v2 0/4] Consolidate DIV_ROUND_CLOSEST_ULL() Javi Merino
@ 2015-03-24 14:03 ` Javi Merino
2015-03-24 14:29 ` Jeff Epler
2015-03-24 14:03 ` [PATCH v2 2/4] clk: bcm/kona: use DIV_ROUND_CLOSEST_ULL() Javi Merino
` (2 subsequent siblings)
3 siblings, 1 reply; 9+ messages in thread
From: Javi Merino @ 2015-03-24 14:03 UTC (permalink / raw)
To: akpm
Cc: intel-gfx, dri-devel, linux-kernel, emil.l.velikov, jepler,
daniel, Javi Merino, Jani Nikula, David Airlie, Guenter Roeck
We have grown a number of different implementations of
DIV_ROUND_CLOSEST_ULL throughout the kernel. Move the i915 one to
kernel.h so that it can be reused.
Cc: Jani Nikula <jani.nikula@linux.intel.com>
Cc: David Airlie <airlied@linux.ie>
Cc: Guenter Roeck <linux@roeck-us.net>
Cc: Andrew Morton <akpm@linux-foundation.org>
Acked-by: Daniel Vetter <daniel.vetter@ffwll.ch>
Signed-off-by: Javi Merino <javi.merino@arm.com>
---
drivers/gpu/drm/i915/intel_drv.h | 3 ---
drivers/gpu/drm/i915/intel_panel.c | 1 +
include/linux/kernel.h | 12 ++++++++++++
3 files changed, 13 insertions(+), 3 deletions(-)
diff --git a/drivers/gpu/drm/i915/intel_drv.h b/drivers/gpu/drm/i915/intel_drv.h
index eef79ccd0b7c..ba243db35840 100644
--- a/drivers/gpu/drm/i915/intel_drv.h
+++ b/drivers/gpu/drm/i915/intel_drv.h
@@ -36,9 +36,6 @@
#include <drm/drm_dp_mst_helper.h>
#include <drm/drm_rect.h>
-#define DIV_ROUND_CLOSEST_ULL(ll, d) \
-({ unsigned long long _tmp = (ll)+(d)/2; do_div(_tmp, d); _tmp; })
-
/**
* _wait_for - magic (register) wait macro
*
diff --git a/drivers/gpu/drm/i915/intel_panel.c b/drivers/gpu/drm/i915/intel_panel.c
index d8686ce89160..08532d4ffe0a 100644
--- a/drivers/gpu/drm/i915/intel_panel.c
+++ b/drivers/gpu/drm/i915/intel_panel.c
@@ -30,6 +30,7 @@
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
+#include <linux/kernel.h>
#include <linux/moduleparam.h>
#include "intel_drv.h"
diff --git a/include/linux/kernel.h b/include/linux/kernel.h
index d6d630d31ef3..3a5b48e52a9e 100644
--- a/include/linux/kernel.h
+++ b/include/linux/kernel.h
@@ -103,6 +103,18 @@
(((__x) - ((__d) / 2)) / (__d)); \
} \
)
+/*
+ * Same as above but for u64 dividends. divisor must be a 32-bit
+ * number.
+ */
+#define DIV_ROUND_CLOSEST_ULL(x, divisor)( \
+{ \
+ typeof(divisor) __d = divisor; \
+ unsigned long long _tmp = (x) + (__d) / 2; \
+ do_div(_tmp, __d); \
+ _tmp; \
+} \
+)
/*
* Multiplies an integer by a fraction, while avoiding unnecessary
--
1.9.1
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH v2 2/4] clk: bcm/kona: use DIV_ROUND_CLOSEST_ULL()
2015-03-24 14:03 [PATCH v2 0/4] Consolidate DIV_ROUND_CLOSEST_ULL() Javi Merino
2015-03-24 14:03 ` [PATCH v2 1/4] kernel.h: Implement DIV_ROUND_CLOSEST_ULL Javi Merino
@ 2015-03-24 14:03 ` Javi Merino
2015-03-24 18:03 ` Alex Elder
2015-03-24 14:03 ` [PATCH v2 3/4] cpuidle: menu: " Javi Merino
2015-03-24 14:03 ` [PATCH v2 4/4] media: cxd2820r: " Javi Merino
3 siblings, 1 reply; 9+ messages in thread
From: Javi Merino @ 2015-03-24 14:03 UTC (permalink / raw)
To: akpm
Cc: intel-gfx, dri-devel, linux-kernel, emil.l.velikov, jepler,
daniel, Javi Merino, Mike Turquette, Stephen Boyd, Alex Elder
Now that the kernel provides DIV_ROUND_CLOSEST_ULL(), drop the internal
implementation and use the kernel one.
Cc: Mike Turquette <mturquette@linaro.org>
Cc: Stephen Boyd <sboyd@codeaurora.org>
Cc: Alex Elder <elder@linaro.org>
Signed-off-by: Javi Merino <javi.merino@arm.com>
---
drivers/clk/bcm/clk-kona.c | 28 +++++++---------------------
drivers/clk/bcm/clk-kona.h | 1 -
2 files changed, 7 insertions(+), 22 deletions(-)
diff --git a/drivers/clk/bcm/clk-kona.c b/drivers/clk/bcm/clk-kona.c
index 05abae89262e..a0ef4f75d457 100644
--- a/drivers/clk/bcm/clk-kona.c
+++ b/drivers/clk/bcm/clk-kona.c
@@ -15,6 +15,7 @@
#include "clk-kona.h"
#include <linux/delay.h>
+#include <linux/kernel.h>
/*
* "Policies" affect the frequencies of bus clocks provided by a
@@ -51,21 +52,6 @@ static inline u32 bitfield_replace(u32 reg_val, u32 shift, u32 width, u32 val)
/* Divider and scaling helpers */
-/*
- * Implement DIV_ROUND_CLOSEST() for 64-bit dividend and both values
- * unsigned. Note that unlike do_div(), the remainder is discarded
- * and the return value is the quotient (not the remainder).
- */
-u64 do_div_round_closest(u64 dividend, unsigned long divisor)
-{
- u64 result;
-
- result = dividend + ((u64)divisor >> 1);
- (void)do_div(result, divisor);
-
- return result;
-}
-
/* Convert a divider into the scaled divisor value it represents. */
static inline u64 scaled_div_value(struct bcm_clk_div *div, u32 reg_div)
{
@@ -87,7 +73,7 @@ u64 scaled_div_build(struct bcm_clk_div *div, u32 div_value, u32 billionths)
combined = (u64)div_value * BILLION + billionths;
combined <<= div->u.s.frac_width;
- return do_div_round_closest(combined, BILLION);
+ return DIV_ROUND_CLOSEST_ULL(combined, BILLION);
}
/* The scaled minimum divisor representable by a divider */
@@ -731,7 +717,7 @@ static unsigned long clk_recalc_rate(struct ccu_data *ccu,
scaled_rate = scale_rate(pre_div, parent_rate);
scaled_rate = scale_rate(div, scaled_rate);
scaled_div = divider_read_scaled(ccu, pre_div);
- scaled_parent_rate = do_div_round_closest(scaled_rate,
+ scaled_parent_rate = DIV_ROUND_CLOSEST_ULL(scaled_rate,
scaled_div);
} else {
scaled_parent_rate = scale_rate(div, parent_rate);
@@ -743,7 +729,7 @@ static unsigned long clk_recalc_rate(struct ccu_data *ccu,
* rate.
*/
scaled_div = divider_read_scaled(ccu, div);
- result = do_div_round_closest(scaled_parent_rate, scaled_div);
+ result = DIV_ROUND_CLOSEST_ULL(scaled_parent_rate, scaled_div);
return (unsigned long)result;
}
@@ -790,7 +776,7 @@ static long round_rate(struct ccu_data *ccu, struct bcm_clk_div *div,
scaled_rate = scale_rate(pre_div, parent_rate);
scaled_rate = scale_rate(div, scaled_rate);
scaled_pre_div = divider_read_scaled(ccu, pre_div);
- scaled_parent_rate = do_div_round_closest(scaled_rate,
+ scaled_parent_rate = DIV_ROUND_CLOSEST_ULL(scaled_rate,
scaled_pre_div);
} else {
scaled_parent_rate = scale_rate(div, parent_rate);
@@ -802,7 +788,7 @@ static long round_rate(struct ccu_data *ccu, struct bcm_clk_div *div,
* the best we can do.
*/
if (!divider_is_fixed(div)) {
- best_scaled_div = do_div_round_closest(scaled_parent_rate,
+ best_scaled_div = DIV_ROUND_CLOSEST_ULL(scaled_parent_rate,
rate);
min_scaled_div = scaled_div_min(div);
max_scaled_div = scaled_div_max(div);
@@ -815,7 +801,7 @@ static long round_rate(struct ccu_data *ccu, struct bcm_clk_div *div,
}
/* OK, figure out the resulting rate */
- result = do_div_round_closest(scaled_parent_rate, best_scaled_div);
+ result = DIV_ROUND_CLOSEST_ULL(scaled_parent_rate, best_scaled_div);
if (scaled_div)
*scaled_div = best_scaled_div;
diff --git a/drivers/clk/bcm/clk-kona.h b/drivers/clk/bcm/clk-kona.h
index 2537b3072910..6849a64baf6d 100644
--- a/drivers/clk/bcm/clk-kona.h
+++ b/drivers/clk/bcm/clk-kona.h
@@ -503,7 +503,6 @@ extern struct clk_ops kona_peri_clk_ops;
/* Externally visible functions */
-extern u64 do_div_round_closest(u64 dividend, unsigned long divisor);
extern u64 scaled_div_max(struct bcm_clk_div *div);
extern u64 scaled_div_build(struct bcm_clk_div *div, u32 div_value,
u32 billionths);
--
1.9.1
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH v2 3/4] cpuidle: menu: use DIV_ROUND_CLOSEST_ULL()
2015-03-24 14:03 [PATCH v2 0/4] Consolidate DIV_ROUND_CLOSEST_ULL() Javi Merino
2015-03-24 14:03 ` [PATCH v2 1/4] kernel.h: Implement DIV_ROUND_CLOSEST_ULL Javi Merino
2015-03-24 14:03 ` [PATCH v2 2/4] clk: bcm/kona: use DIV_ROUND_CLOSEST_ULL() Javi Merino
@ 2015-03-24 14:03 ` Javi Merino
2015-03-24 20:22 ` Rafael J. Wysocki
2015-03-25 11:40 ` Rafael J. Wysocki
2015-03-24 14:03 ` [PATCH v2 4/4] media: cxd2820r: " Javi Merino
3 siblings, 2 replies; 9+ messages in thread
From: Javi Merino @ 2015-03-24 14:03 UTC (permalink / raw)
To: akpm
Cc: intel-gfx, dri-devel, linux-kernel, emil.l.velikov, jepler,
daniel, Javi Merino, Rafael J. Wysocki, Mel Gorman,
Stephen Hemminger
Now that the kernel provides DIV_ROUND_CLOSEST_ULL(), drop the internal
implementation and use the kernel one.
Cc: "Rafael J. Wysocki" <rafael.j.wysocki@intel.com>
Cc: Mel Gorman <mgorman@suse.de>
Cc: Stephen Hemminger <shemminger@linux-foundation.org>
Signed-off-by: Javi Merino <javi.merino@arm.com>
---
| 8 +-------
1 file changed, 1 insertion(+), 7 deletions(-)
--git a/drivers/cpuidle/governors/menu.c b/drivers/cpuidle/governors/menu.c
index 40580794e23d..b8a5fa15ca24 100644
--- a/drivers/cpuidle/governors/menu.c
+++ b/drivers/cpuidle/governors/menu.c
@@ -190,12 +190,6 @@ static DEFINE_PER_CPU(struct menu_device, menu_devices);
static void menu_update(struct cpuidle_driver *drv, struct cpuidle_device *dev);
-/* This implements DIV_ROUND_CLOSEST but avoids 64 bit division */
-static u64 div_round64(u64 dividend, u32 divisor)
-{
- return div_u64(dividend + (divisor / 2), divisor);
-}
-
/*
* Try detecting repeating patterns by keeping track of the last 8
* intervals, and checking if the standard deviation of that set
@@ -317,7 +311,7 @@ static int menu_select(struct cpuidle_driver *drv, struct cpuidle_device *dev)
* operands are 32 bits.
* Make sure to round up for half microseconds.
*/
- data->predicted_us = div_round64((uint64_t)data->next_timer_us *
+ data->predicted_us = DIV_ROUND_CLOSEST_ULL((uint64_t)data->next_timer_us *
data->correction_factor[data->bucket],
RESOLUTION * DECAY);
--
1.9.1
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH v2 4/4] media: cxd2820r: use DIV_ROUND_CLOSEST_ULL()
2015-03-24 14:03 [PATCH v2 0/4] Consolidate DIV_ROUND_CLOSEST_ULL() Javi Merino
` (2 preceding siblings ...)
2015-03-24 14:03 ` [PATCH v2 3/4] cpuidle: menu: " Javi Merino
@ 2015-03-24 14:03 ` Javi Merino
3 siblings, 0 replies; 9+ messages in thread
From: Javi Merino @ 2015-03-24 14:03 UTC (permalink / raw)
To: akpm
Cc: intel-gfx, dri-devel, linux-kernel, emil.l.velikov, jepler,
daniel, Javi Merino, Mauro Carvalho Chehab
Now that the kernel provides DIV_ROUND_CLOSEST_ULL(), drop the internal
implementation and use the kernel one.
Cc: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
Acked-by: Antti Palosaari <crope@iki.fi>
Reviewed-by: Antti Palosaari <crope@iki.fi>
Signed-off-by: Javi Merino <javi.merino@arm.com>
---
drivers/media/dvb-frontends/cxd2820r_c.c | 2 +-
drivers/media/dvb-frontends/cxd2820r_core.c | 6 ------
drivers/media/dvb-frontends/cxd2820r_priv.h | 2 --
drivers/media/dvb-frontends/cxd2820r_t.c | 2 +-
drivers/media/dvb-frontends/cxd2820r_t2.c | 2 +-
5 files changed, 3 insertions(+), 11 deletions(-)
diff --git a/drivers/media/dvb-frontends/cxd2820r_c.c b/drivers/media/dvb-frontends/cxd2820r_c.c
index 149fdca3fb44..72b0e2db3aab 100644
--- a/drivers/media/dvb-frontends/cxd2820r_c.c
+++ b/drivers/media/dvb-frontends/cxd2820r_c.c
@@ -79,7 +79,7 @@ int cxd2820r_set_frontend_c(struct dvb_frontend *fe)
num = if_freq / 1000; /* Hz => kHz */
num *= 0x4000;
- if_ctl = 0x4000 - cxd2820r_div_u64_round_closest(num, 41000);
+ if_ctl = 0x4000 - DIV_ROUND_CLOSEST_ULL(num, 41000);
buf[0] = (if_ctl >> 8) & 0x3f;
buf[1] = (if_ctl >> 0) & 0xff;
diff --git a/drivers/media/dvb-frontends/cxd2820r_core.c b/drivers/media/dvb-frontends/cxd2820r_core.c
index 422e84bbb008..490e090048ef 100644
--- a/drivers/media/dvb-frontends/cxd2820r_core.c
+++ b/drivers/media/dvb-frontends/cxd2820r_core.c
@@ -244,12 +244,6 @@ error:
return ret;
}
-/* 64 bit div with round closest, like DIV_ROUND_CLOSEST but 64 bit */
-u32 cxd2820r_div_u64_round_closest(u64 dividend, u32 divisor)
-{
- return div_u64(dividend + (divisor / 2), divisor);
-}
-
static int cxd2820r_set_frontend(struct dvb_frontend *fe)
{
struct cxd2820r_priv *priv = fe->demodulator_priv;
diff --git a/drivers/media/dvb-frontends/cxd2820r_priv.h b/drivers/media/dvb-frontends/cxd2820r_priv.h
index 7ff5f60c83e1..4b428959b16e 100644
--- a/drivers/media/dvb-frontends/cxd2820r_priv.h
+++ b/drivers/media/dvb-frontends/cxd2820r_priv.h
@@ -64,8 +64,6 @@ int cxd2820r_wr_reg_mask(struct cxd2820r_priv *priv, u32 reg, u8 val,
int cxd2820r_wr_regs(struct cxd2820r_priv *priv, u32 reginfo, u8 *val,
int len);
-u32 cxd2820r_div_u64_round_closest(u64 dividend, u32 divisor);
-
int cxd2820r_wr_regs(struct cxd2820r_priv *priv, u32 reginfo, u8 *val,
int len);
diff --git a/drivers/media/dvb-frontends/cxd2820r_t.c b/drivers/media/dvb-frontends/cxd2820r_t.c
index 51401d036530..008cb2ac8480 100644
--- a/drivers/media/dvb-frontends/cxd2820r_t.c
+++ b/drivers/media/dvb-frontends/cxd2820r_t.c
@@ -103,7 +103,7 @@ int cxd2820r_set_frontend_t(struct dvb_frontend *fe)
num = if_freq / 1000; /* Hz => kHz */
num *= 0x1000000;
- if_ctl = cxd2820r_div_u64_round_closest(num, 41000);
+ if_ctl = DIV_ROUND_CLOSEST_ULL(num, 41000);
buf[0] = ((if_ctl >> 16) & 0xff);
buf[1] = ((if_ctl >> 8) & 0xff);
buf[2] = ((if_ctl >> 0) & 0xff);
diff --git a/drivers/media/dvb-frontends/cxd2820r_t2.c b/drivers/media/dvb-frontends/cxd2820r_t2.c
index 9c0c4f42175c..35fe364c7182 100644
--- a/drivers/media/dvb-frontends/cxd2820r_t2.c
+++ b/drivers/media/dvb-frontends/cxd2820r_t2.c
@@ -120,7 +120,7 @@ int cxd2820r_set_frontend_t2(struct dvb_frontend *fe)
num = if_freq / 1000; /* Hz => kHz */
num *= 0x1000000;
- if_ctl = cxd2820r_div_u64_round_closest(num, 41000);
+ if_ctl = DIV_ROUND_CLOSEST_ULL(num, 41000);
buf[0] = ((if_ctl >> 16) & 0xff);
buf[1] = ((if_ctl >> 8) & 0xff);
buf[2] = ((if_ctl >> 0) & 0xff);
--
1.9.1
^ permalink raw reply related [flat|nested] 9+ messages in thread
* Re: [PATCH v2 1/4] kernel.h: Implement DIV_ROUND_CLOSEST_ULL
2015-03-24 14:03 ` [PATCH v2 1/4] kernel.h: Implement DIV_ROUND_CLOSEST_ULL Javi Merino
@ 2015-03-24 14:29 ` Jeff Epler
0 siblings, 0 replies; 9+ messages in thread
From: Jeff Epler @ 2015-03-24 14:29 UTC (permalink / raw)
To: Javi Merino
Cc: akpm, intel-gfx, dri-devel, linux-kernel, emil.l.velikov, daniel,
Jani Nikula, David Airlie, Guenter Roeck
[for just patch 1/4; I didn't look as closely at the others]
Reviewed-by: Jeff Epler <jepler@unpythonic.net>
...with one half of a caveat (rounded up?): Like most or all of the
originals, and like DIV_ROUND_CLOSEST just above it in kernel.h, the new
code gives an incorrect answer if the temporary overflows at
+ unsigned long long _tmp = (x) + (__d) / 2;
As a doc improvement a remark could be added to a number of these
functions, but there's little reason for that to be part of this series.
Jeff
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH v2 2/4] clk: bcm/kona: use DIV_ROUND_CLOSEST_ULL()
2015-03-24 14:03 ` [PATCH v2 2/4] clk: bcm/kona: use DIV_ROUND_CLOSEST_ULL() Javi Merino
@ 2015-03-24 18:03 ` Alex Elder
0 siblings, 0 replies; 9+ messages in thread
From: Alex Elder @ 2015-03-24 18:03 UTC (permalink / raw)
To: Javi Merino, akpm
Cc: intel-gfx, dri-devel, linux-kernel, emil.l.velikov, jepler,
daniel, Mike Turquette, Stephen Boyd, Alex Elder
On 03/24/2015 09:03 AM, Javi Merino wrote:
> Now that the kernel provides DIV_ROUND_CLOSEST_ULL(), drop the internal
> implementation and use the kernel one.
>
> Cc: Mike Turquette <mturquette@linaro.org>
> Cc: Stephen Boyd <sboyd@codeaurora.org>
> Cc: Alex Elder <elder@linaro.org>
Acked-by: Alex Elder <elder@linaro.org>
> Signed-off-by: Javi Merino <javi.merino@arm.com>
> ---
> drivers/clk/bcm/clk-kona.c | 28 +++++++---------------------
> drivers/clk/bcm/clk-kona.h | 1 -
> 2 files changed, 7 insertions(+), 22 deletions(-)
>
> diff --git a/drivers/clk/bcm/clk-kona.c b/drivers/clk/bcm/clk-kona.c
> index 05abae89262e..a0ef4f75d457 100644
> --- a/drivers/clk/bcm/clk-kona.c
> +++ b/drivers/clk/bcm/clk-kona.c
> @@ -15,6 +15,7 @@
> #include "clk-kona.h"
>
> #include <linux/delay.h>
> +#include <linux/kernel.h>
>
> /*
> * "Policies" affect the frequencies of bus clocks provided by a
> @@ -51,21 +52,6 @@ static inline u32 bitfield_replace(u32 reg_val, u32 shift, u32 width, u32 val)
>
> /* Divider and scaling helpers */
>
> -/*
> - * Implement DIV_ROUND_CLOSEST() for 64-bit dividend and both values
> - * unsigned. Note that unlike do_div(), the remainder is discarded
> - * and the return value is the quotient (not the remainder).
> - */
> -u64 do_div_round_closest(u64 dividend, unsigned long divisor)
> -{
> - u64 result;
> -
> - result = dividend + ((u64)divisor >> 1);
> - (void)do_div(result, divisor);
> -
> - return result;
> -}
> -
> /* Convert a divider into the scaled divisor value it represents. */
> static inline u64 scaled_div_value(struct bcm_clk_div *div, u32 reg_div)
> {
> @@ -87,7 +73,7 @@ u64 scaled_div_build(struct bcm_clk_div *div, u32 div_value, u32 billionths)
> combined = (u64)div_value * BILLION + billionths;
> combined <<= div->u.s.frac_width;
>
> - return do_div_round_closest(combined, BILLION);
> + return DIV_ROUND_CLOSEST_ULL(combined, BILLION);
> }
>
> /* The scaled minimum divisor representable by a divider */
> @@ -731,7 +717,7 @@ static unsigned long clk_recalc_rate(struct ccu_data *ccu,
> scaled_rate = scale_rate(pre_div, parent_rate);
> scaled_rate = scale_rate(div, scaled_rate);
> scaled_div = divider_read_scaled(ccu, pre_div);
> - scaled_parent_rate = do_div_round_closest(scaled_rate,
> + scaled_parent_rate = DIV_ROUND_CLOSEST_ULL(scaled_rate,
> scaled_div);
> } else {
> scaled_parent_rate = scale_rate(div, parent_rate);
> @@ -743,7 +729,7 @@ static unsigned long clk_recalc_rate(struct ccu_data *ccu,
> * rate.
> */
> scaled_div = divider_read_scaled(ccu, div);
> - result = do_div_round_closest(scaled_parent_rate, scaled_div);
> + result = DIV_ROUND_CLOSEST_ULL(scaled_parent_rate, scaled_div);
>
> return (unsigned long)result;
> }
> @@ -790,7 +776,7 @@ static long round_rate(struct ccu_data *ccu, struct bcm_clk_div *div,
> scaled_rate = scale_rate(pre_div, parent_rate);
> scaled_rate = scale_rate(div, scaled_rate);
> scaled_pre_div = divider_read_scaled(ccu, pre_div);
> - scaled_parent_rate = do_div_round_closest(scaled_rate,
> + scaled_parent_rate = DIV_ROUND_CLOSEST_ULL(scaled_rate,
> scaled_pre_div);
> } else {
> scaled_parent_rate = scale_rate(div, parent_rate);
> @@ -802,7 +788,7 @@ static long round_rate(struct ccu_data *ccu, struct bcm_clk_div *div,
> * the best we can do.
> */
> if (!divider_is_fixed(div)) {
> - best_scaled_div = do_div_round_closest(scaled_parent_rate,
> + best_scaled_div = DIV_ROUND_CLOSEST_ULL(scaled_parent_rate,
> rate);
> min_scaled_div = scaled_div_min(div);
> max_scaled_div = scaled_div_max(div);
> @@ -815,7 +801,7 @@ static long round_rate(struct ccu_data *ccu, struct bcm_clk_div *div,
> }
>
> /* OK, figure out the resulting rate */
> - result = do_div_round_closest(scaled_parent_rate, best_scaled_div);
> + result = DIV_ROUND_CLOSEST_ULL(scaled_parent_rate, best_scaled_div);
>
> if (scaled_div)
> *scaled_div = best_scaled_div;
> diff --git a/drivers/clk/bcm/clk-kona.h b/drivers/clk/bcm/clk-kona.h
> index 2537b3072910..6849a64baf6d 100644
> --- a/drivers/clk/bcm/clk-kona.h
> +++ b/drivers/clk/bcm/clk-kona.h
> @@ -503,7 +503,6 @@ extern struct clk_ops kona_peri_clk_ops;
>
> /* Externally visible functions */
>
> -extern u64 do_div_round_closest(u64 dividend, unsigned long divisor);
> extern u64 scaled_div_max(struct bcm_clk_div *div);
> extern u64 scaled_div_build(struct bcm_clk_div *div, u32 div_value,
> u32 billionths);
>
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH v2 3/4] cpuidle: menu: use DIV_ROUND_CLOSEST_ULL()
2015-03-24 14:03 ` [PATCH v2 3/4] cpuidle: menu: " Javi Merino
@ 2015-03-24 20:22 ` Rafael J. Wysocki
2015-03-25 11:40 ` Rafael J. Wysocki
1 sibling, 0 replies; 9+ messages in thread
From: Rafael J. Wysocki @ 2015-03-24 20:22 UTC (permalink / raw)
To: Javi Merino
Cc: akpm, intel-gfx, dri-devel, linux-kernel, emil.l.velikov, jepler,
daniel, Rafael J. Wysocki, Mel Gorman, Stephen Hemminger
On Tuesday, March 24, 2015 02:03:44 PM Javi Merino wrote:
> Now that the kernel provides DIV_ROUND_CLOSEST_ULL(), drop the internal
> implementation and use the kernel one.
Can you please CC patch [1/4] to me too at least, so I can see how the new
macro is defined without digging it up from the entire firehose of messages
which is the LKML today?
> Cc: "Rafael J. Wysocki" <rafael.j.wysocki@intel.com>
> Cc: Mel Gorman <mgorman@suse.de>
> Cc: Stephen Hemminger <shemminger@linux-foundation.org>
> Signed-off-by: Javi Merino <javi.merino@arm.com>
> ---
> drivers/cpuidle/governors/menu.c | 8 +-------
> 1 file changed, 1 insertion(+), 7 deletions(-)
>
> diff --git a/drivers/cpuidle/governors/menu.c b/drivers/cpuidle/governors/menu.c
> index 40580794e23d..b8a5fa15ca24 100644
> --- a/drivers/cpuidle/governors/menu.c
> +++ b/drivers/cpuidle/governors/menu.c
> @@ -190,12 +190,6 @@ static DEFINE_PER_CPU(struct menu_device, menu_devices);
>
> static void menu_update(struct cpuidle_driver *drv, struct cpuidle_device *dev);
>
> -/* This implements DIV_ROUND_CLOSEST but avoids 64 bit division */
> -static u64 div_round64(u64 dividend, u32 divisor)
> -{
> - return div_u64(dividend + (divisor / 2), divisor);
> -}
> -
> /*
> * Try detecting repeating patterns by keeping track of the last 8
> * intervals, and checking if the standard deviation of that set
> @@ -317,7 +311,7 @@ static int menu_select(struct cpuidle_driver *drv, struct cpuidle_device *dev)
> * operands are 32 bits.
> * Make sure to round up for half microseconds.
> */
> - data->predicted_us = div_round64((uint64_t)data->next_timer_us *
> + data->predicted_us = DIV_ROUND_CLOSEST_ULL((uint64_t)data->next_timer_us *
> data->correction_factor[data->bucket],
> RESOLUTION * DECAY);
>
>
--
I speak only for myself.
Rafael J. Wysocki, Intel Open Source Technology Center.
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH v2 3/4] cpuidle: menu: use DIV_ROUND_CLOSEST_ULL()
2015-03-24 14:03 ` [PATCH v2 3/4] cpuidle: menu: " Javi Merino
2015-03-24 20:22 ` Rafael J. Wysocki
@ 2015-03-25 11:40 ` Rafael J. Wysocki
1 sibling, 0 replies; 9+ messages in thread
From: Rafael J. Wysocki @ 2015-03-25 11:40 UTC (permalink / raw)
To: Javi Merino
Cc: akpm, intel-gfx, dri-devel, linux-kernel, emil.l.velikov, jepler,
daniel, Rafael J. Wysocki, Mel Gorman, Stephen Hemminger
On Tuesday, March 24, 2015 02:03:44 PM Javi Merino wrote:
> Now that the kernel provides DIV_ROUND_CLOSEST_ULL(), drop the internal
> implementation and use the kernel one.
>
> Cc: "Rafael J. Wysocki" <rafael.j.wysocki@intel.com>
> Cc: Mel Gorman <mgorman@suse.de>
> Cc: Stephen Hemminger <shemminger@linux-foundation.org>
> Signed-off-by: Javi Merino <javi.merino@arm.com>
Acked-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
> ---
> drivers/cpuidle/governors/menu.c | 8 +-------
> 1 file changed, 1 insertion(+), 7 deletions(-)
>
> diff --git a/drivers/cpuidle/governors/menu.c b/drivers/cpuidle/governors/menu.c
> index 40580794e23d..b8a5fa15ca24 100644
> --- a/drivers/cpuidle/governors/menu.c
> +++ b/drivers/cpuidle/governors/menu.c
> @@ -190,12 +190,6 @@ static DEFINE_PER_CPU(struct menu_device, menu_devices);
>
> static void menu_update(struct cpuidle_driver *drv, struct cpuidle_device *dev);
>
> -/* This implements DIV_ROUND_CLOSEST but avoids 64 bit division */
> -static u64 div_round64(u64 dividend, u32 divisor)
> -{
> - return div_u64(dividend + (divisor / 2), divisor);
> -}
> -
> /*
> * Try detecting repeating patterns by keeping track of the last 8
> * intervals, and checking if the standard deviation of that set
> @@ -317,7 +311,7 @@ static int menu_select(struct cpuidle_driver *drv, struct cpuidle_device *dev)
> * operands are 32 bits.
> * Make sure to round up for half microseconds.
> */
> - data->predicted_us = div_round64((uint64_t)data->next_timer_us *
> + data->predicted_us = DIV_ROUND_CLOSEST_ULL((uint64_t)data->next_timer_us *
> data->correction_factor[data->bucket],
> RESOLUTION * DECAY);
>
>
--
I speak only for myself.
Rafael J. Wysocki, Intel Open Source Technology Center.
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2015-03-25 11:16 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-03-24 14:03 [PATCH v2 0/4] Consolidate DIV_ROUND_CLOSEST_ULL() Javi Merino
2015-03-24 14:03 ` [PATCH v2 1/4] kernel.h: Implement DIV_ROUND_CLOSEST_ULL Javi Merino
2015-03-24 14:29 ` Jeff Epler
2015-03-24 14:03 ` [PATCH v2 2/4] clk: bcm/kona: use DIV_ROUND_CLOSEST_ULL() Javi Merino
2015-03-24 18:03 ` Alex Elder
2015-03-24 14:03 ` [PATCH v2 3/4] cpuidle: menu: " Javi Merino
2015-03-24 20:22 ` Rafael J. Wysocki
2015-03-25 11:40 ` Rafael J. Wysocki
2015-03-24 14:03 ` [PATCH v2 4/4] media: cxd2820r: " Javi Merino
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox