mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Yong Zhang <yong.zhang0@gmail.com>
To: linux-kernel@vger.kernel.org
Cc: John Stultz <johnstul@us.ibm.com>, Thomas Gleixner <tglx@linutronix.de>
Subject: [PATCH 1/3] clocksource: Also tweak ->maxadj in clocksource_calc_mult_shift()
Date: Thu,  1 Dec 2011 15:20:14 +0800	[thread overview]
Message-ID: <1322724016-9770-2-git-send-email-yong.zhang0@gmail.com> (raw)
In-Reply-To: <1322724016-9770-1-git-send-email-yong.zhang0@gmail.com>

There is still user of clocksource_calc_mult_shift(), and it's
complement to commit d65670a7 [clocksource: Avoid selecting mult
values that might overflow when adjusted]

Signed-off-by: Yong Zhang <yong.zhang0@gmail.com>
Cc: John Stultz <johnstul@us.ibm.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
---
 include/linux/clocksource.h |    8 ++------
 kernel/time/clocksource.c   |   18 ++++++++++++++++++
 2 files changed, 20 insertions(+), 6 deletions(-)

diff --git a/include/linux/clocksource.h b/include/linux/clocksource.h
index c86c940..a02a8d7 100644
--- a/include/linux/clocksource.h
+++ b/include/linux/clocksource.h
@@ -314,12 +314,8 @@ static inline void __clocksource_updatefreq_khz(struct clocksource *cs, u32 khz)
 	__clocksource_updatefreq_scale(cs, 1000, khz);
 }
 
-static inline void
-clocksource_calc_mult_shift(struct clocksource *cs, u32 freq, u32 minsec)
-{
-	return clocks_calc_mult_shift(&cs->mult, &cs->shift, freq,
-				      NSEC_PER_SEC, minsec);
-}
+extern void
+clocksource_calc_mult_shift(struct clocksource *cs, u32 freq, u32 minsec);
 
 #ifdef CONFIG_GENERIC_TIME_VSYSCALL
 extern void
diff --git a/kernel/time/clocksource.c b/kernel/time/clocksource.c
index cfc65e1..5119042 100644
--- a/kernel/time/clocksource.c
+++ b/kernel/time/clocksource.c
@@ -724,6 +724,24 @@ int __clocksource_register_scale(struct clocksource *cs, u32 scale, u32 freq)
 }
 EXPORT_SYMBOL_GPL(__clocksource_register_scale);
 
+void clocksource_calc_mult_shift(struct clocksource *cs, u32 freq, u32 minsec)
+{
+	clocks_calc_mult_shift(&cs->mult, &cs->shift, freq,
+				NSEC_PER_SEC, minsec);
+
+	/*
+	 * for clocksources that have large mults, to avoid overflow.
+	 * Since mult may be adjusted by ntp, add an safety extra margin
+	 *
+	 */
+	cs->maxadj = clocksource_max_adjustment(cs);
+	while ((cs->mult + cs->maxadj < cs->mult)
+		|| (cs->mult - cs->maxadj > cs->mult)) {
+		cs->mult >>= 1;
+		cs->shift--;
+		cs->maxadj = clocksource_max_adjustment(cs);
+	}
+}
 
 /**
  * clocksource_register - Used to install new clocksources
-- 
1.7.5.4


  reply	other threads:[~2011-12-01  7:20 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-12-01  7:20 [PATCH 0/3] Patches focus on clocksource_calc_mult_shift() Yong Zhang
2011-12-01  7:20 ` Yong Zhang [this message]
2011-12-01 23:58   ` [PATCH 1/3] clocksource: Also tweak ->maxadj in clocksource_calc_mult_shift() john stultz
2011-12-02  1:35     ` Yong Zhang
2011-12-01  7:20 ` [PATCH 2/3] clocksource: dbx500: convert to clocksource_register_hz() Yong Zhang
2011-12-01 13:03   ` Linus Walleij
2011-12-01 23:55   ` John Stultz
2011-12-02  8:29     ` Linus Walleij
2011-12-02 19:28       ` John Stultz
2011-12-01  7:20 ` [PATCH 3/3] clocksource: get rid of clocksource_calc_mult_shift() Yong Zhang

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1322724016-9770-2-git-send-email-yong.zhang0@gmail.com \
    --to=yong.zhang0@gmail.com \
    --cc=johnstul@us.ibm.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=tglx@linutronix.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®