From b162fa019439d8442b70d9e002b8ce5d476064c1 Mon Sep 17 00:00:00 2001 From: "David S. Miller" Date: Wed, 19 Nov 2003 01:30:27 -0800 Subject: [PATCH] [SPARC]: Port over cset 1.1459 x86 gettimeofday fix. --- arch/sparc/kernel/pcic.c | 19 ++++++++++++------- arch/sparc/kernel/time.c | 19 ++++++++++++------- arch/sparc64/kernel/time.c | 19 ++++++++++++------- 3 files changed, 36 insertions(+), 21 deletions(-) diff --git a/arch/sparc/kernel/pcic.c b/arch/sparc/kernel/pcic.c index 3bb97b4771bdc..d03654e646468 100644 --- a/arch/sparc/kernel/pcic.c +++ b/arch/sparc/kernel/pcic.c @@ -776,23 +776,28 @@ static void pci_do_gettimeofday(struct timeval *tv) unsigned long flags; unsigned long seq; unsigned long usec, sec; + unsigned long max_ntp_tick = tick_usec - tickadj; do { + unsigned long lost; + seq = read_seqbegin_irqsave(&xtime_lock, flags); usec = do_gettimeoffset(); - { - unsigned long lost = jiffies - wall_jiffies; - if (lost) - usec += lost * (1000000 / HZ); - } + lost = jiffies - wall_jiffies; /* * If time_adjust is negative then NTP is slowing the clock * so make sure not to go into next possible interval. * Better to lose some accuracy than have time go backwards.. */ - if (unlikely(time_adjust < 0) && usec > tickadj) - usec = tickadj; + if (unlikely(time_adjust < 0)) { + usec = min(usec, max_ntp_tick); + + if (lost) + usec += lost * max_ntp_tick; + } + else if (unlikely(lost)) + usec += lost * tick_usec; sec = xtime.tv_sec; usec += (xtime.tv_nsec / 1000); diff --git a/arch/sparc/kernel/time.c b/arch/sparc/kernel/time.c index 5566ad8a751ba..20ba51723a400 100644 --- a/arch/sparc/kernel/time.c +++ b/arch/sparc/kernel/time.c @@ -481,23 +481,28 @@ void do_gettimeofday(struct timeval *tv) unsigned long flags; unsigned long seq; unsigned long usec, sec; + unsigned long max_ntp_tick = tick_usec - tickadj; do { + unsigned long lost; + seq = read_seqbegin_irqsave(&xtime_lock, flags); usec = do_gettimeoffset(); - { - unsigned long lost = jiffies - wall_jiffies; - if (lost) - usec += lost * (1000000 / HZ); - } + lost = jiffies - wall_jiffies; /* * If time_adjust is negative then NTP is slowing the clock * so make sure not to go into next possible interval. * Better to lose some accuracy than have time go backwards.. */ - if (unlikely(time_adjust < 0) && usec > tickadj) - usec = tickadj; + if (unlikely(time_adjust < 0)) { + usec = min(usec, max_ntp_tick); + + if (lost) + usec += lost * max_ntp_tick; + } + else if (unlikely(lost)) + usec += lost * tick_usec; sec = xtime.tv_sec; usec += (xtime.tv_nsec / 1000); diff --git a/arch/sparc64/kernel/time.c b/arch/sparc64/kernel/time.c index d06bcc0562f13..e368409323d9c 100644 --- a/arch/sparc64/kernel/time.c +++ b/arch/sparc64/kernel/time.c @@ -1140,23 +1140,28 @@ void do_gettimeofday(struct timeval *tv) unsigned long flags; unsigned long seq; unsigned long usec, sec; + unsigned long max_ntp_tick = tick_usec - tickadj; do { + unsigned long lost; + seq = read_seqbegin_irqsave(&xtime_lock, flags); usec = do_gettimeoffset(); - { - unsigned long lost = jiffies - wall_jiffies; - if (lost) - usec += lost * (1000000 / HZ); - } + lost = jiffies - wall_jiffies; /* * If time_adjust is negative then NTP is slowing the clock * so make sure not to go into next possible interval. * Better to lose some accuracy than have time go backwards.. */ - if (unlikely(time_adjust < 0) && usec > tickadj) - usec = tickadj; + if (unlikely(time_adjust < 0)) { + usec = min(usec, max_ntp_tick); + + if (lost) + usec += lost * max_ntp_tick; + } + else if (unlikely(lost)) + usec += lost * tick_usec; sec = xtime.tv_sec; usec += (xtime.tv_nsec / 1000); -- 2.53.0