Re: [RFC PATCH 4/5] clocksource: Enlarge the maxim time intervalwhen configuring the scale and shift

From: Chen Gong
Date: Mon Jan 21 2013 - 02:35:29 EST


On Mon, Jan 21, 2013 at 02:38:44PM +0800, Feng Tang wrote:
> Date: Mon, 21 Jan 2013 14:38:44 +0800
> From: Feng Tang <feng.tang@xxxxxxxxx>
> To: Thomas Gleixner <tglx@xxxxxxxxxxxxx>, John Stultz
> <john.stultz@xxxxxxxxxx>, Ingo Molnar <mingo@xxxxxxx>, "H. Peter Anvin"
> <hpa@xxxxxxxxxxxxxxx>, x86@xxxxxxxxxx, Len Brown <lenb@xxxxxxxxxx>,
> "Rafael J. Wysocki" <rafael.j.wysocki@xxxxxxxxx>,
> linux-kernel@xxxxxxxxxxxxxxx
> Cc: Feng Tang <feng.tang@xxxxxxxxx>
> Subject: [RFC PATCH 4/5] clocksource: Enlarge the maxim time interval when
> configuring the scale and shift
> X-Mailer: git-send-email 1.7.9.5
>
> On our x86 platform, we see a failure case of calling clocksource_cyc2ns(),
> which return a negative value. The reason is the time interval was large
> (more than 1000 seconds), while its TSC frequency is 2GHz, so the following
> fomular overflowed:
> ((u64) cycles * mult) >> shift
>
> So enlarge the time interval from 10 mins to 40 mins to fix the bug.
>
> Another solution may be adding a "max_interval" in struct clocksource, and
> use a default value (like current 10 minutes) when clocksource driver
> doesn't set it.
>
As you said, it looks like it is a littleb it arbitrary from 10m -> 40m, I
think max_interval is a better choice, if timer guys not minding too many
control knobs :-).

> Signed-off-by: Feng Tang <feng.tang@xxxxxxxxx>
> ---
> kernel/time/clocksource.c | 6 +++---
> 1 file changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/kernel/time/clocksource.c b/kernel/time/clocksource.c
> index c958338..48fbfcb 100644
> --- a/kernel/time/clocksource.c
> +++ b/kernel/time/clocksource.c
> @@ -663,7 +663,7 @@ void __clocksource_updatefreq_scale(struct clocksource *cs, u32 scale, u32 freq)
> * Calc the maximum number of seconds which we can run before
> * wrapping around. For clocksources which have a mask > 32bit
> * we need to limit the max sleep time to have a good
> - * conversion precision. 10 minutes is still a reasonable
> + * conversion precision. 40 minutes is still a reasonable
> * amount. That results in a shift value of 24 for a
> * clocksource with mask >= 40bit and f >= 4GHz. That maps to
> * ~ 0.06ppm granularity for NTP. We apply the same 12.5%
> @@ -674,8 +674,8 @@ void __clocksource_updatefreq_scale(struct clocksource *cs, u32 scale, u32 freq)
> do_div(sec, scale);
> if (!sec)
> sec = 1;
> - else if (sec > 600 && cs->mask > UINT_MAX)
> - sec = 600;
> + else if (sec > 2400 && cs->mask > UINT_MAX)
> + sec = 2400;
>
> clocks_calc_mult_shift(&cs->mult, &cs->shift, freq,
> NSEC_PER_SEC / scale, sec * scale);
> --
> 1.7.9.5
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> the body of a message to majordomo@xxxxxxxxxxxxxxx
> More majordomo info at http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at http://www.tux.org/lkml/

Attachment: signature.asc
Description: Digital signature