* shift and clocksource
@ 2011-06-19 16:18 Carlo Caione
2011-06-20 6:25 ` Sascha Hauer
0 siblings, 1 reply; 6+ messages in thread
From: Carlo Caione @ 2011-06-19 16:18 UTC (permalink / raw)
To: barebox
Hi,
I was looking in the sources for time keeping. Why the shift field of the clocksource structure is always set to 10?
Also using the clocks_calc_mult_shift() in kernel sources I obtain different values for the shift variable.
Best regards,
--
Carlo Caione
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: shift and clocksource
2011-06-19 16:18 shift and clocksource Carlo Caione
@ 2011-06-20 6:25 ` Sascha Hauer
2011-06-20 22:08 ` [PATCH] " Carlo Caione
0 siblings, 1 reply; 6+ messages in thread
From: Sascha Hauer @ 2011-06-20 6:25 UTC (permalink / raw)
To: Carlo Caione; +Cc: barebox
Hi Carlo,
On Sun, Jun 19, 2011 at 06:18:44PM +0200, Carlo Caione wrote:
> Hi,
> I was looking in the sources for time keeping. Why the shift field of
> the clocksource structure is always set to 10? Also using the
> clocks_calc_mult_shift() in kernel sources I obtain different values
> for the shift variable.
The value 10 is copied from the initial clocksource. We should add
clocks_calc_mult_shift() to barebox and use it there also.
Sascha
--
Pengutronix e.K. | |
Industrial Linux Solutions | http://www.pengutronix.de/ |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH] shift and clocksource
2011-06-20 6:25 ` Sascha Hauer
@ 2011-06-20 22:08 ` Carlo Caione
2011-06-21 11:53 ` Sascha Hauer
0 siblings, 1 reply; 6+ messages in thread
From: Carlo Caione @ 2011-06-20 22:08 UTC (permalink / raw)
To: Sascha Hauer; +Cc: barebox
Added clocks_calc_mult_shift()
Signed-off-by: Carlo Caione <carlo.caione@gmail.com>
---
common/clock.c | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 55 insertions(+), 0 deletions(-)
diff --git a/common/clock.c b/common/clock.c
index 15df0ab..79c06c8 100644
--- a/common/clock.c
+++ b/common/clock.c
@@ -57,6 +57,61 @@ uint64_t get_time_ns(void)
EXPORT_SYMBOL(get_time_ns);
/**
+ * clocks_calc_mult_shift - calculate mult/shift factors for scaled math of clocks
+ * @mult: pointer to mult variable
+ * @shift: pointer to shift variable
+ * @from: frequency to convert from
+ * @to: frequency to convert to
+ * @maxsec: guaranteed runtime conversion range in seconds
+ *
+ * The function evaluates the shift/mult pair for the scaled math
+ * operations of clocksources and clockevents.
+ *
+ * @to and @from are frequency values in HZ. For clock sources @to is
+ * NSEC_PER_SEC == 1GHz and @from is the counter frequency. For clock
+ * event @to is the counter frequency and @from is NSEC_PER_SEC.
+ *
+ * The @maxsec conversion range argument controls the time frame in
+ * seconds which must be covered by the runtime conversion with the
+ * calculated mult and shift factors. This guarantees that no 64bit
+ * overflow happens when the input value of the conversion is
+ * multiplied with the calculated mult factor. Larger ranges may
+ * reduce the conversion accuracy by chosing smaller mult and shift
+ * factors.
+ */
+
+void clocks_calc_mult_shift(uint32_t *mult, uint32_t *shift, uint32_t from, uint32_t to, uint32_t maxsec)
+{
+ uint64_t tmp;
+ uint32_t sft, sftacc = 32;
+
+ /*
+ * Calculate the shift factor which is limiting the conversion
+ * range:
+ */
+ tmp = ((uint64_t)maxsec * from) >> 32;
+ while (tmp) {
+ tmp >>=1;
+ sftacc--;
+ }
+
+ /*
+ * Find the conversion shift/mult pair which has the best
+ * accuracy and fits the maxsec conversion range:
+ */
+ for (sft = 32; sft > 0; sft--) {
+ tmp = (uint64_t) to << sft;
+ tmp += from / 2;
+ do_div(tmp, from);
+ if ((tmp >> sftacc) == 0)
+ break;
+ }
+ *mult = tmp;
+ *shift = sft;
+}
+
+
+/**
* clocksource_hz2mult - calculates mult from hz and shift
* @hz: Clocksource frequency in Hz
* @shift_constant: Clocksource shift factor
--
1.7.5.2
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] shift and clocksource
2011-06-20 22:08 ` [PATCH] " Carlo Caione
@ 2011-06-21 11:53 ` Sascha Hauer
2011-06-21 18:56 ` Carlo Caione
0 siblings, 1 reply; 6+ messages in thread
From: Sascha Hauer @ 2011-06-21 11:53 UTC (permalink / raw)
To: Carlo Caione; +Cc: barebox
On Tue, Jun 21, 2011 at 12:08:00AM +0200, Carlo Caione wrote:
> Added clocks_calc_mult_shift()
>
> Signed-off-by: Carlo Caione <carlo.caione@gmail.com>
> ---
> common/clock.c | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
You should also add this to include/clock.h. Otherwise the patch looks
good.
Sascha
> 1 files changed, 55 insertions(+), 0 deletions(-)
>
> diff --git a/common/clock.c b/common/clock.c
> index 15df0ab..79c06c8 100644
> --- a/common/clock.c
> +++ b/common/clock.c
> @@ -57,6 +57,61 @@ uint64_t get_time_ns(void)
> EXPORT_SYMBOL(get_time_ns);
>
> /**
> + * clocks_calc_mult_shift - calculate mult/shift factors for scaled math of clocks
> + * @mult: pointer to mult variable
> + * @shift: pointer to shift variable
> + * @from: frequency to convert from
> + * @to: frequency to convert to
> + * @maxsec: guaranteed runtime conversion range in seconds
> + *
> + * The function evaluates the shift/mult pair for the scaled math
> + * operations of clocksources and clockevents.
> + *
> + * @to and @from are frequency values in HZ. For clock sources @to is
> + * NSEC_PER_SEC == 1GHz and @from is the counter frequency. For clock
> + * event @to is the counter frequency and @from is NSEC_PER_SEC.
> + *
> + * The @maxsec conversion range argument controls the time frame in
> + * seconds which must be covered by the runtime conversion with the
> + * calculated mult and shift factors. This guarantees that no 64bit
> + * overflow happens when the input value of the conversion is
> + * multiplied with the calculated mult factor. Larger ranges may
> + * reduce the conversion accuracy by chosing smaller mult and shift
> + * factors.
> + */
> +
> +void clocks_calc_mult_shift(uint32_t *mult, uint32_t *shift, uint32_t from, uint32_t to, uint32_t maxsec)
> +{
> + uint64_t tmp;
> + uint32_t sft, sftacc = 32;
> +
> + /*
> + * Calculate the shift factor which is limiting the conversion
> + * range:
> + */
> + tmp = ((uint64_t)maxsec * from) >> 32;
> + while (tmp) {
> + tmp >>=1;
> + sftacc--;
> + }
> +
> + /*
> + * Find the conversion shift/mult pair which has the best
> + * accuracy and fits the maxsec conversion range:
> + */
> + for (sft = 32; sft > 0; sft--) {
> + tmp = (uint64_t) to << sft;
> + tmp += from / 2;
> + do_div(tmp, from);
> + if ((tmp >> sftacc) == 0)
> + break;
> + }
> + *mult = tmp;
> + *shift = sft;
> +}
> +
> +
> +/**
> * clocksource_hz2mult - calculates mult from hz and shift
> * @hz: Clocksource frequency in Hz
> * @shift_constant: Clocksource shift factor
> --
> 1.7.5.2
>
>
--
Pengutronix e.K. | |
Industrial Linux Solutions | http://www.pengutronix.de/ |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] shift and clocksource
2011-06-21 11:53 ` Sascha Hauer
@ 2011-06-21 18:56 ` Carlo Caione
2011-06-21 22:18 ` Sascha Hauer
0 siblings, 1 reply; 6+ messages in thread
From: Carlo Caione @ 2011-06-21 18:56 UTC (permalink / raw)
To: Sascha Hauer; +Cc: barebox
Added clocks_calc_mult_shift()
Signed-off-by: Carlo Caione <carlo.caione@gmail.com>
---
common/clock.c | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
include/clock.h | 2 ++
2 files changed, 57 insertions(+), 0 deletions(-)
diff --git a/common/clock.c b/common/clock.c
index 15df0ab..79c06c8 100644
--- a/common/clock.c
+++ b/common/clock.c
@@ -57,6 +57,61 @@ uint64_t get_time_ns(void)
EXPORT_SYMBOL(get_time_ns);
/**
+ * clocks_calc_mult_shift - calculate mult/shift factors for scaled math of clocks
+ * @mult: pointer to mult variable
+ * @shift: pointer to shift variable
+ * @from: frequency to convert from
+ * @to: frequency to convert to
+ * @maxsec: guaranteed runtime conversion range in seconds
+ *
+ * The function evaluates the shift/mult pair for the scaled math
+ * operations of clocksources and clockevents.
+ *
+ * @to and @from are frequency values in HZ. For clock sources @to is
+ * NSEC_PER_SEC == 1GHz and @from is the counter frequency. For clock
+ * event @to is the counter frequency and @from is NSEC_PER_SEC.
+ *
+ * The @maxsec conversion range argument controls the time frame in
+ * seconds which must be covered by the runtime conversion with the
+ * calculated mult and shift factors. This guarantees that no 64bit
+ * overflow happens when the input value of the conversion is
+ * multiplied with the calculated mult factor. Larger ranges may
+ * reduce the conversion accuracy by chosing smaller mult and shift
+ * factors.
+ */
+
+void clocks_calc_mult_shift(uint32_t *mult, uint32_t *shift, uint32_t from, uint32_t to, uint32_t maxsec)
+{
+ uint64_t tmp;
+ uint32_t sft, sftacc = 32;
+
+ /*
+ * Calculate the shift factor which is limiting the conversion
+ * range:
+ */
+ tmp = ((uint64_t)maxsec * from) >> 32;
+ while (tmp) {
+ tmp >>=1;
+ sftacc--;
+ }
+
+ /*
+ * Find the conversion shift/mult pair which has the best
+ * accuracy and fits the maxsec conversion range:
+ */
+ for (sft = 32; sft > 0; sft--) {
+ tmp = (uint64_t) to << sft;
+ tmp += from / 2;
+ do_div(tmp, from);
+ if ((tmp >> sftacc) == 0)
+ break;
+ }
+ *mult = tmp;
+ *shift = sft;
+}
+
+
+/**
* clocksource_hz2mult - calculates mult from hz and shift
* @hz: Clocksource frequency in Hz
* @shift_constant: Clocksource shift factor
diff --git a/include/clock.h b/include/clock.h
index b9acdb9..af5b939 100644
--- a/include/clock.h
+++ b/include/clock.h
@@ -25,6 +25,8 @@ int init_clock(struct clocksource *);
uint64_t get_time_ns(void);
+void clocks_calc_mult_shift(uint32_t *mult, uint32_t *shift, uint32_t from, uint32_t to, uint32_t maxsec);
+
uint32_t clocksource_hz2mult(uint32_t hz, uint32_t shift_constant);
int is_timeout(uint64_t start_ns, uint64_t time_offset_ns);
--
1.7.5.2
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] shift and clocksource
2011-06-21 18:56 ` Carlo Caione
@ 2011-06-21 22:18 ` Sascha Hauer
0 siblings, 0 replies; 6+ messages in thread
From: Sascha Hauer @ 2011-06-21 22:18 UTC (permalink / raw)
To: Carlo Caione; +Cc: barebox
On Tue, Jun 21, 2011 at 08:56:53PM +0200, Carlo Caione wrote:
> Added clocks_calc_mult_shift()
>
> Signed-off-by: Carlo Caione <carlo.caione@gmail.com>
Applied to -next
Sascha
> ---
> common/clock.c | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
> include/clock.h | 2 ++
> 2 files changed, 57 insertions(+), 0 deletions(-)
>
> diff --git a/common/clock.c b/common/clock.c
> index 15df0ab..79c06c8 100644
> --- a/common/clock.c
> +++ b/common/clock.c
> @@ -57,6 +57,61 @@ uint64_t get_time_ns(void)
> EXPORT_SYMBOL(get_time_ns);
>
> /**
> + * clocks_calc_mult_shift - calculate mult/shift factors for scaled math of clocks
> + * @mult: pointer to mult variable
> + * @shift: pointer to shift variable
> + * @from: frequency to convert from
> + * @to: frequency to convert to
> + * @maxsec: guaranteed runtime conversion range in seconds
> + *
> + * The function evaluates the shift/mult pair for the scaled math
> + * operations of clocksources and clockevents.
> + *
> + * @to and @from are frequency values in HZ. For clock sources @to is
> + * NSEC_PER_SEC == 1GHz and @from is the counter frequency. For clock
> + * event @to is the counter frequency and @from is NSEC_PER_SEC.
> + *
> + * The @maxsec conversion range argument controls the time frame in
> + * seconds which must be covered by the runtime conversion with the
> + * calculated mult and shift factors. This guarantees that no 64bit
> + * overflow happens when the input value of the conversion is
> + * multiplied with the calculated mult factor. Larger ranges may
> + * reduce the conversion accuracy by chosing smaller mult and shift
> + * factors.
> + */
> +
> +void clocks_calc_mult_shift(uint32_t *mult, uint32_t *shift, uint32_t from, uint32_t to, uint32_t maxsec)
> +{
> + uint64_t tmp;
> + uint32_t sft, sftacc = 32;
> +
> + /*
> + * Calculate the shift factor which is limiting the conversion
> + * range:
> + */
> + tmp = ((uint64_t)maxsec * from) >> 32;
> + while (tmp) {
> + tmp >>=1;
> + sftacc--;
> + }
> +
> + /*
> + * Find the conversion shift/mult pair which has the best
> + * accuracy and fits the maxsec conversion range:
> + */
> + for (sft = 32; sft > 0; sft--) {
> + tmp = (uint64_t) to << sft;
> + tmp += from / 2;
> + do_div(tmp, from);
> + if ((tmp >> sftacc) == 0)
> + break;
> + }
> + *mult = tmp;
> + *shift = sft;
> +}
> +
> +
> +/**
> * clocksource_hz2mult - calculates mult from hz and shift
> * @hz: Clocksource frequency in Hz
> * @shift_constant: Clocksource shift factor
> diff --git a/include/clock.h b/include/clock.h
> index b9acdb9..af5b939 100644
> --- a/include/clock.h
> +++ b/include/clock.h
> @@ -25,6 +25,8 @@ int init_clock(struct clocksource *);
>
> uint64_t get_time_ns(void);
>
> +void clocks_calc_mult_shift(uint32_t *mult, uint32_t *shift, uint32_t from, uint32_t to, uint32_t maxsec);
> +
> uint32_t clocksource_hz2mult(uint32_t hz, uint32_t shift_constant);
>
> int is_timeout(uint64_t start_ns, uint64_t time_offset_ns);
> --
> 1.7.5.2
>
>
>
>
>
>
--
Pengutronix e.K. | |
Industrial Linux Solutions | http://www.pengutronix.de/ |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2011-06-21 22:18 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-06-19 16:18 shift and clocksource Carlo Caione
2011-06-20 6:25 ` Sascha Hauer
2011-06-20 22:08 ` [PATCH] " Carlo Caione
2011-06-21 11:53 ` Sascha Hauer
2011-06-21 18:56 ` Carlo Caione
2011-06-21 22:18 ` Sascha Hauer
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox