public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: George Anzinger <george@mvista.com>
To: Roman Zippel <zippel@linux-m68k.org>
Cc: john stultz <johnstul@us.ibm.com>,
	lkml <linux-kernel@vger.kernel.org>,
	frank@tuxrocks.com, Anton Blanchard <anton@samba.org>,
	benh@kernel.crashing.org, Nishanth Aravamudan <nacc@us.ibm.com>,
	Ulrich Windl <ulrich.windl@rz.uni-regensburg.de>
Subject: Re: [RFC - 0/9] Generic timekeeping subsystem  (v. B5)
Date: Wed, 17 Aug 2005 12:03:47 -0700	[thread overview]
Message-ID: <43038A13.8010008@mvista.com> (raw)
In-Reply-To: <Pine.LNX.4.61.0508162337130.3728@scrub.home>

Roman Zippel wrote:


~

The thing that worries me about this function is that it does every 
thing in usec.  We are using nsec in xtime now and I wonder if it would 
not be more accurate to do the math in nsecs.  Even tick size 
(tick_nsec) does not translate well to usec, it currently being 999849 
nsecs.

George
> ---
> 
>  kernel/time.c  |    3 ++-
>  kernel/timer.c |   53 +++++++++++++++++++++++++++++++++++++++++++++++++++++
>  2 files changed, 55 insertions(+), 1 deletion(-)
> 
> Index: linux-2.6/kernel/time.c
> ===================================================================
> --- linux-2.6.orig/kernel/time.c	2005-07-13 03:18:04.000000000 +0200
> +++ linux-2.6/kernel/time.c	2005-08-16 01:37:20.000000000 +0200
> @@ -366,8 +366,9 @@ int do_adjtimex(struct timex *txc)
>  	    } /* txc->modes & ADJ_OFFSET */
>  	    if (txc->modes & ADJ_TICK) {
>  		tick_usec = txc->tick;
> -		tick_nsec = TICK_USEC_TO_NSEC(tick_usec);
>  	    }
> +	    if (txc->modes & (ADJ_FREQUENCY|ADJ_OFFSET|ADJ_TICK))
> +		    time_recalc();
>  	} /* txc->modes */
>  leave:	if ((time_status & (STA_UNSYNC|STA_CLOCKERR)) != 0
>  	    || ((time_status & (STA_PPSFREQ|STA_PPSTIME)) != 0
> Index: linux-2.6/kernel/timer.c
> ===================================================================
> --- linux-2.6.orig/kernel/timer.c	2005-07-13 03:18:04.000000000 +0200
> +++ linux-2.6/kernel/timer.c	2005-08-16 23:10:53.000000000 +0200
> @@ -559,6 +559,7 @@ found:
>   */
>  unsigned long tick_usec = TICK_USEC; 		/* USER_HZ period (usec) */
>  unsigned long tick_nsec = TICK_NSEC;		/* ACTHZ period (nsec) */
> +unsigned long tick_nsec2 = TICK_NSEC;
>  
>  /* 
>   * The current time 
> @@ -569,6 +570,7 @@ unsigned long tick_nsec = TICK_NSEC;		/*
>   * the usual normalization.
>   */
>  struct timespec xtime __attribute__ ((aligned (16)));
> +struct timespec xtime2 __attribute__ ((aligned (16)));
>  struct timespec wall_to_monotonic __attribute__ ((aligned (16)));
>  
>  EXPORT_SYMBOL(xtime);
> @@ -596,6 +598,33 @@ static long time_adj;			/* tick adjust (
>  long time_reftime;			/* time at last adjustment (s)	*/
>  long time_adjust;
>  long time_next_adjust;
> +static long time_adj2, time_adj2_cur, time_freq_adj2, time_freq_phase2, time_phase2;
> +
> +void time_recalc(void)
> +{
> +	long f, t;
> +	tick_nsec = TICK_USEC_TO_NSEC(tick_usec);

This leaves bits on the floor.  Is it not possible to do this whole 
calculation in nano seconds?  Currently, for example, tick_nsec is 999849...
> +
> +	t = time_freq >> (SHIFT_USEC + 8);
> +	if (t) {
> +		time_freq -= t << (SHIFT_USEC + 8);
> +		t *= 1000 << 8;
> +	}
> +	f = time_freq * 125;
> +	t += tick_usec * USER_HZ * 1000 + (f >> (SHIFT_USEC - 3));
> +	f &= (1 << (SHIFT_USEC - 3)) - 1;
> +	tick_nsec2 = t / HZ;
> +	f += (t % HZ) << (SHIFT_USEC - 3);
> +	f <<= 5;
> +	time_adj2 = f / HZ;
> +	time_freq_adj2 = f % HZ;
> +
> +	printk("tr: %ld.%09ld(%ld,%ld,%ld,%ld) - %ld.%09ld(%ld,%ld,%ld)\n",
> +		xtime.tv_sec, xtime.tv_sec,
> +		tick_nsec, time_freq, time_offset, time_next_adjust,
> +		xtime2.tv_sec, xtime2.tv_nsec,
> +		tick_nsec2, time_adj2, time_freq_adj2);
> +}
>  
>  /*
>   * this routine handles the overflow of the microsecond field
> @@ -739,6 +768,16 @@ static void second_overflow(void)
>  #endif
>  }
>  
> +static void second_overflow2(void)
> +{
> +	time_adj2_cur = time_adj2;
> +	time_freq_phase2 += time_freq_adj2;
> +	if (time_freq_phase2 > HZ) {
> +		time_freq_phase2 -= HZ;
> +		time_adj2_cur++;
> +	}
> +}
> +
>  /* in the NTP reference this is called "hardclock()" */
>  static void update_wall_time_one_tick(void)
>  {
> @@ -786,6 +825,20 @@ static void update_wall_time_one_tick(vo
>  		time_adjust = time_next_adjust;
>  		time_next_adjust = 0;
>  	}
> +
> +	delta_nsec = tick_nsec2;
> +	time_phase2 += time_adj2_cur;
> +	if (time_phase2 >= (1 << (SHIFT_USEC + 2))) {
> +		long ltemp = time_phase2 >> (SHIFT_USEC + 2);
> +		time_phase2 -= ltemp << (SHIFT_USEC + 2);
> +		delta_nsec += ltemp;
> +	}
> +	xtime2.tv_nsec += delta_nsec;
> +	if (xtime2.tv_nsec >= NSEC_PER_SEC) {
> +		xtime2.tv_nsec -= NSEC_PER_SEC;
> +		xtime2.tv_sec++;
> +		second_overflow2();
> +	}
>  }
>  
>  /*
> -
> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at  http://www.tux.org/lkml/
> 

-- 
George Anzinger   george@mvista.com
HRT (High-res-timers):  http://sourceforge.net/projects/high-res-timers/

  parent reply	other threads:[~2005-08-17 19:04 UTC|newest]

Thread overview: 71+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-08-11  1:21 [RFC - 0/13] NTP cleanup work (v. B5) john stultz
2005-08-11  1:23 ` [RFC][PATCH - 1/13] NTP cleanup: Move NTP code into ntp.c john stultz
2005-08-11  1:25   ` [RFC][PATCH - 2/13] NTP cleanup: Move arches to new ntp interfaces john stultz
2005-08-11  1:26     ` [RFC][PATCH - 3/13] NTP cleanup: Remove unused NTP PPS code john stultz
2005-08-11  1:27       ` [RFC][PATCH - 4/13] NTP cleanup: Breakup ntp_adjtimex() john stultz
2005-08-11  1:28         ` [RFC][PATCH - 5/13] NTP cleanup: Break out leapsecond processing john stultz
2005-08-11  1:28           ` [RFC][PATCH - 6/13] NTP cleanup: Clean up ntp_adjtimex() arguement checking john stultz
2005-08-11  1:31             ` [RFC][PATCH - 7/13] NTP cleanup: Cleanup signed shifting logic john stultz
2005-08-11  1:31               ` [RFC][PATCH - 8/13] NTP cleanup: Integrate second_overflow() logic john stultz
2005-08-11  1:33                 ` [RFC][PATCH - 9/13] NTP cleanup: Improve NTP variable names john stultz
2005-08-11  1:33                   ` [RFC][PATCH - 10/13] NTP cleanup: Use ntp_lock instead of xtime_lock john stultz
2005-08-11  1:35                     ` [RFC][PATCH - 11/13] NTP cleanup: Introduce PPM adjustment variables john stultz
2005-08-11  1:36                       ` [RFC][PATCH - 12/13] NTP cleanup: cleanup ntp_advance() adjtime code john stultz
2005-08-11  1:38                         ` [RFC][PATCH - 13/13] NTP cleanup: drop time_phase and time_adj add copyright john stultz
2005-08-16  2:08         ` [RFC][PATCH - 4/13] NTP cleanup: Breakup ntp_adjtimex() john stultz
2005-08-11  2:13 ` [RFC - 0/9] Generic timekeeping subsystem (v. B5) john stultz
2005-08-11  2:14   ` [PATCH 1/9] Timesource management code john stultz
2005-08-11  2:16     ` [PATCH 2/9] Generic timekeeping core subsystem john stultz
2005-08-11  2:18       ` [PATCH 3/9] Generic timekeeping i386 arch specific changes, part 1 john stultz
2005-08-11  2:19         ` [PATCH 4/9] generic timekeeping i386 arch specific changes, part 2 john stultz
2005-08-11  2:20           ` [PATCH 5/9] generic timekeeping i386 arch specific changes, part 3 john stultz
2005-08-11  2:21             ` [PATCH 6/9] generic timekeeping i386 arch specific changes, part 4 john stultz
2005-08-11  2:23               ` [PATCH 7/9] generic timekeeping i386 arch specific changes, part 5 john stultz
2005-08-11  2:24                 ` [PATCH 8/9] generic timekeeping i386 arch specific changes, part 6 john stultz
2005-08-11  2:25                   ` [PATCH 9/9] generic timekeeping i386 specific timesources john stultz
2005-08-11  2:32   ` [RFC - 0/9] Generic timekeeping subsystem (v. B5) Lee Revell
2005-08-11  2:39     ` john stultz
2005-08-11  2:44       ` Lee Revell
2005-08-11  6:17     ` Ulrich Windl
2005-08-11  2:37   ` [RFC] Cumulative NTP cleanujp and generic timekeeping patch (v B5) john stultz
2005-08-15 22:14   ` [RFC - 0/9] Generic timekeeping subsystem (v. B5) Roman Zippel
2005-08-16  0:10     ` john stultz
2005-08-16 18:25       ` Christoph Lameter
2005-08-16 23:48         ` john stultz
2005-08-17  0:14           ` Christoph Lameter
2005-08-17  0:17             ` john stultz
2005-08-17  0:21               ` Christoph Lameter
2005-08-17  6:08         ` Ulrich Windl
2005-08-17 14:07           ` Christoph Lameter
2005-08-17  0:28       ` Roman Zippel
2005-08-17  1:17         ` john stultz
2005-08-17  7:40           ` Ulrich Windl
2005-08-19  0:27           ` Roman Zippel
2005-08-20  2:32             ` john stultz
2005-08-21 23:19               ` Roman Zippel
2005-08-22 18:57                 ` john stultz
2005-08-23 11:30                   ` Roman Zippel
2005-08-23 18:52                     ` john stultz
2005-08-23 20:51                     ` john stultz
2005-08-23 21:34                       ` Roman Zippel
2005-08-23 23:14                         ` john stultz
2005-08-23 23:54                           ` Roman Zippel
2005-08-24  0:29                             ` George Anzinger
2005-08-24 20:36                               ` john stultz
2005-08-24 23:46                                 ` George Anzinger
2005-08-25  0:42                                   ` john stultz
2005-08-25  1:44                                     ` George Anzinger
2005-08-25  2:13                                       ` john stultz
2005-08-24  6:34                             ` Ulrich Windl
2005-08-24  9:47                               ` Roman Zippel
2005-08-24 18:00                             ` john stultz
2005-08-24 18:48                               ` Roman Zippel
2005-08-24 19:15                                 ` john stultz
2005-08-24 19:49                                   ` Roman Zippel
2005-08-24 22:40                                     ` john stultz
2005-08-25  0:45                                       ` Roman Zippel
2005-08-25 18:08                                         ` john stultz
2005-08-17 19:03         ` George Anzinger [this message]
2005-08-15 22:12 ` [RFC - 0/13] NTP cleanup work " Roman Zippel
2005-08-15 22:46   ` john stultz
2005-08-17  0:10     ` Roman Zippel

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=43038A13.8010008@mvista.com \
    --to=george@mvista.com \
    --cc=anton@samba.org \
    --cc=benh@kernel.crashing.org \
    --cc=frank@tuxrocks.com \
    --cc=johnstul@us.ibm.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=nacc@us.ibm.com \
    --cc=ulrich.windl@rz.uni-regensburg.de \
    --cc=zippel@linux-m68k.org \
    /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