Skip to content

Commit

Permalink
Merge git://git.kernel.org/pub/scm/linux/kernel/git/tglx/linux-2.6-hrt
Browse files Browse the repository at this point in the history
* git://git.kernel.org/pub/scm/linux/kernel/git/tglx/linux-2.6-hrt:
  time: remove obsolete CLOCK_TICK_ADJUST
  time: don't touch an offlined CPU's ts->tick_stopped in tick_cancel_sched_timer()
  time: prevent the loop in timespec_add_ns() from being optimised away
  ntp: use unsigned input for do_div()
  • Loading branch information
Linus Torvalds committed Mar 9, 2008
2 parents 83f7a2c + 10a398d commit bf5a25e
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 19 deletions.
4 changes: 4 additions & 0 deletions include/linux/time.h
Expand Up @@ -174,6 +174,10 @@ static inline void timespec_add_ns(struct timespec *a, u64 ns)
{
ns += a->tv_nsec;
while(unlikely(ns >= NSEC_PER_SEC)) {
/* The following asm() prevents the compiler from
* optimising this loop into a modulo operation. */
asm("" : "+r"(ns));

ns -= NSEC_PER_SEC;
a->tv_sec++;
}
Expand Down
9 changes: 1 addition & 8 deletions include/linux/timex.h
Expand Up @@ -232,14 +232,7 @@ static inline int ntp_synced(void)
#else
#define NTP_INTERVAL_FREQ (HZ)
#endif

#define CLOCK_TICK_OVERFLOW (LATCH * HZ - CLOCK_TICK_RATE)
#define CLOCK_TICK_ADJUST (((s64)CLOCK_TICK_OVERFLOW * NSEC_PER_SEC) / \
(s64)CLOCK_TICK_RATE)

/* Because using NSEC_PER_SEC would be too easy */
#define NTP_INTERVAL_LENGTH ((((s64)TICK_USEC * NSEC_PER_USEC * USER_HZ) + \
CLOCK_TICK_ADJUST) / NTP_INTERVAL_FREQ)
#define NTP_INTERVAL_LENGTH (NSEC_PER_SEC/NTP_INTERVAL_FREQ)

/* Returns how long ticks are at present, in ns / 2^(SHIFT_SCALE-10). */
extern u64 current_tick_length(void);
Expand Down
23 changes: 17 additions & 6 deletions kernel/time/ntp.c
Expand Up @@ -42,12 +42,13 @@ long time_esterror = NTP_PHASE_LIMIT; /* estimated error (us) */
long time_freq; /* frequency offset (scaled ppm)*/
static long time_reftime; /* time at last adjustment (s) */
long time_adjust;
static long ntp_tick_adj;

static void ntp_update_frequency(void)
{
u64 second_length = (u64)(tick_usec * NSEC_PER_USEC * USER_HZ)
<< TICK_LENGTH_SHIFT;
second_length += (s64)CLOCK_TICK_ADJUST << TICK_LENGTH_SHIFT;
second_length += (s64)ntp_tick_adj << TICK_LENGTH_SHIFT;
second_length += (s64)time_freq << (TICK_LENGTH_SHIFT - SHIFT_NSEC);

tick_length_base = second_length;
Expand Down Expand Up @@ -342,14 +343,16 @@ int do_adjtimex(struct timex *txc)
freq_adj = shift_right(freq_adj, time_constant * 2 +
(SHIFT_PLL + 2) * 2 - SHIFT_NSEC);
if (mtemp >= MINSEC && (time_status & STA_FLL || mtemp > MAXSEC)) {
u64 utemp64;
temp64 = time_offset << (SHIFT_NSEC - SHIFT_FLL);
if (time_offset < 0) {
temp64 = -temp64;
do_div(temp64, mtemp);
freq_adj -= temp64;
utemp64 = -temp64;
do_div(utemp64, mtemp);
freq_adj -= utemp64;
} else {
do_div(temp64, mtemp);
freq_adj += temp64;
utemp64 = temp64;
do_div(utemp64, mtemp);
freq_adj += utemp64;
}
}
freq_adj += time_freq;
Expand Down Expand Up @@ -400,3 +403,11 @@ leave: if ((time_status & (STA_UNSYNC|STA_CLOCKERR)) != 0)
notify_cmos_timer();
return(result);
}

static int __init ntp_tick_adj_setup(char *str)
{
ntp_tick_adj = simple_strtol(str, NULL, 0);
return 1;
}

__setup("ntp_tick_adj=", ntp_tick_adj_setup);
2 changes: 1 addition & 1 deletion kernel/time/tick-sched.c
Expand Up @@ -640,7 +640,7 @@ void tick_cancel_sched_timer(int cpu)

if (ts->sched_timer.base)
hrtimer_cancel(&ts->sched_timer);
ts->tick_stopped = 0;

ts->nohz_mode = NOHZ_MODE_INACTIVE;
}
#endif /* HIGH_RES_TIMERS */
Expand Down
6 changes: 2 additions & 4 deletions kernel/time/timekeeping.c
Expand Up @@ -187,8 +187,7 @@ static void change_clocksource(void)

clock->error = 0;
clock->xtime_nsec = 0;
clocksource_calculate_interval(clock,
(unsigned long)(current_tick_length()>>TICK_LENGTH_SHIFT));
clocksource_calculate_interval(clock, NTP_INTERVAL_LENGTH);

tick_clock_notify();

Expand Down Expand Up @@ -245,8 +244,7 @@ void __init timekeeping_init(void)
ntp_clear();

clock = clocksource_get_next();
clocksource_calculate_interval(clock,
(unsigned long)(current_tick_length()>>TICK_LENGTH_SHIFT));
clocksource_calculate_interval(clock, NTP_INTERVAL_LENGTH);
clock->cycle_last = clocksource_read(clock);

xtime.tv_sec = sec;
Expand Down

0 comments on commit bf5a25e

Please sign in to comment.