public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: john stultz <johnstul@us.ibm.com>
To: Roman Zippel <zippel@linux-m68k.org>
Cc: Andrew Morton <akpm@osdl.org>, linux-kernel@vger.kernel.org
Subject: Re: clocksource
Date: Fri, 16 Jun 2006 11:48:04 -0700	[thread overview]
Message-ID: <1150483684.5316.56.camel@localhost.localdomain> (raw)
In-Reply-To: <Pine.LNX.4.64.0606161620190.32445@scrub.home>

On Fri, 2006-06-16 at 17:33 +0200, Roman Zippel wrote:
> On Thu, 15 Jun 2006, john stultz wrote:
> > I've also been working on improving the adjustment algorithm. Paul
> > Mckenney enlightened me to the established concepts in control theory, I
> > started reading up on PID control (see:
> > http://en.wikipedia.org/wiki/PID_controller ). While I have understood
> > the basic concept, it was useful to read up on it. I've tried to rework
> > the adjustment code accordingly.
> > 
> > The method I came up with is really just P-D (proportional-derivative)
> > control, but that should be ok since the adjustments are all linear so I
> > don't think the integral control is necessary (control theorists can
> > pipe in here).
> 
> This makes it more complex than necessary. AFAICT this controller 
> calculates the adjustment solely based on the current error, but we have 
> more information than this, which make the current error rather 
> uninteresting.

Indeed it is the current error, but its also taking the change in error
into account as well.

> We know the clock frequency and the NTP frequency so we can easily 
> precalculate, how the error will look like at the next few ticks. Based on 
> this we can calculate how we have to adjust the clock frequency to reduce 
> the error. Overshooting is also not a real problem as long as the absolute 
> error gets smaller.

I'm not sure I agree here. Using your patch series, if I re-enable the
code that drops calls to update_wall_time (simulating lost ticks) the
clock does not appear very stable. Robustness and features like
dynamic/no_idle_hz are going to require that we can handle taking
something close to only one tick per second, so overshoot is a big
concern in my mind. Maybe I'm misunderstanding you?

However, I need to forward port your patchset to the new simulator to
really do a fair comparison as I know there were some issues w/ the
simulator that I addressed in order to get the new features working. If
you have already done this, let me know.

> An important point about the last patch is not just robustness but also 
> speed, it tries to keep the fast path small, which is basically:
> 
> 	interval = clock->cycle_interval;
> 	if (error > interval / 2) {
> 		adj = 1;
> 		if (unlikely(error > interval * 2)) {
> 			...
> 		}
> 	} else if (error < -interval / 2) {
> 		adj = -1
> 		interval = -interval;
> 		offset = -offset;
> 		if (unlikely(error < interval * 2)) {
> 			...
> 		}
> 	} else
> 		return;
> 
> 	clock->mult += adj;
> 	clock->xtime_interval += interval;
> 	clock->xtime_nsec -= offset;
> 	clock->error -= interval - offset;
> 
> You'll need a very good reason to do anything more than this for small 
> errors and I would suggest you start from something like this, as this is 
> the very core of the error adjustment.

I agree that the patch I sent could use some optimizations, and likely
even some tweaking (supposedly I can get rid of the proportional
adjustment limiter by using a gain value, but I need to test this a bit)
to improve it further.  

Now trying to compare it to your code:

Looking at your description of the code above from your documentation
email:
1)	mult_adj = error / cycle_update;
2)	mult += mult_adj;
3)	xtime -= cycle_offset * mult_adj;
4)	error -= (cycle_update - cycle_offset) * mult_adj;

Lines 1 & 2 calculates the proportional error adjustment for the error
at the next interval.

Line 3 is also well understood, as it corrects the base for the new
adjustment value if there is an offset value.

So I see the proportional adjustment, but I don't see how the derivative
is included. I suspect the density of the error adjustment bit is what
makes this so opaque to me. Breaking line 4 apart for a moment:

4a) error += cycle_offset * multadj;
4b) error -= cycle_update * muladj

Line 4a is also clear, since if the base had been changed in line 3, the
error between the base and ntp has changed as well, so it must be
changed by the negative amount the base was changed to stay in sync.

Line 4b is a bit foggy. Just assuming cycle_offset is zero, we can
ignore line 3 and 4a. So we're reducing the error by the change in
length of the next interval. I see how this would in effect dampen the
next adjustment, but I'm not sure how that then maps the error value to
the actual distance from ntp_time.

Abstractly I understand how looking at the next tick is good for when
the NTP adjustment value changes, but I'm not sure I see how looking
ahead makes the clock more stable when the NTP adjustment isn't
changing.

Is there a way you can map the math above to the terms of PID control
(or maybe some other established concept that I can dig deeper on?).

thanks
-john


  reply	other threads:[~2006-06-16 18:48 UTC|newest]

Thread overview: 166+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-06-04 20:50 2.6.18 -mm merge plans Andrew Morton
2006-06-04 21:20 ` 2.6.18 hdrinstall (Re: 2.6.18 -mm merge plans) Bernhard Rosenkraenzer
2006-06-04 21:33 ` header cleanup and install David Woodhouse
2006-06-04 21:43   ` Andrew Morton
2006-06-05 10:52   ` Jens Axboe
2006-06-05 10:54     ` David Woodhouse
2006-06-05 10:59       ` Jens Axboe
2006-06-05 10:57         ` David Woodhouse
2006-06-05 11:03           ` Jens Axboe
2006-06-05 18:09             ` Andrew Morton
2006-06-05 19:19               ` David Woodhouse
2006-06-17 20:35                 ` Alistair John Strachan
2006-06-17 21:20                   ` David Woodhouse
2006-06-04 21:36 ` 2.6.18 -mm merge plans Alan Cox
2006-06-04 21:41 ` kbuild, kconfig and hrdinstall stuff Sam Ravnborg
2006-06-04 21:54   ` David Woodhouse
2006-06-04 23:04 ` klibc (was: 2.6.18 -mm merge plans) H. Peter Anvin
2006-06-05 18:09   ` Roman Zippel
2006-06-06 15:20   ` Pavel Machek
2006-06-06 20:56     ` Rafael J. Wysocki
2006-06-07  3:37       ` H. Peter Anvin
2006-06-07  4:00       ` Nigel Cunningham
2006-06-07  4:10         ` H. Peter Anvin
2006-06-07  4:25           ` Nigel Cunningham
2006-06-07  4:26             ` klibc H. Peter Anvin
2006-06-07  6:22               ` klibc Nigel Cunningham
2006-06-07  6:38                 ` klibc H. Peter Anvin
2006-06-07  6:51             ` klibc (was: 2.6.18 -mm merge plans) Joshua Hudson
2006-06-07 21:12               ` H. Peter Anvin
2006-06-09  8:03                 ` klibc Nix
2006-06-09 18:45                   ` klibc H. Peter Anvin
     [not found]                   ` <bda6d13a0606091050n40fda044v668eef09af3c29a7@mail.gmail.com>
     [not found]                     ` <871wty6rl9.fsf@hades.wkstn.nix>
2006-06-09 22:28                       ` klibc Joshua Hudson
2006-06-09 22:48                         ` klibc H. Peter Anvin
2006-06-09 23:13                           ` klibc Joshua Hudson
2006-06-09 23:44                             ` klibc H. Peter Anvin
2006-06-16  6:02                               ` klibc Joshua Hudson
2006-06-16 19:19                                 ` klibc H. Peter Anvin
2006-06-07  8:44       ` klibc (was: 2.6.18 -mm merge plans) Pavel Machek
2006-06-07  9:44         ` Rafael J. Wysocki
2006-06-04 23:50 ` clocksource Roman Zippel
2006-06-05 20:20   ` clocksource john stultz
2006-06-05 20:53     ` clocksource john stultz
2006-06-05 21:07     ` clocksource Roman Zippel
2006-06-06 19:42       ` clocksource john stultz
2006-06-07  0:41         ` clocksource Roman Zippel
2006-06-08  8:05           ` clocksource john stultz
2006-06-15 11:40             ` clocksource Roman Zippel
2006-06-16  3:21               ` clocksource john stultz
2006-06-16  3:35                 ` clocksource john stultz
2006-06-16 15:33                 ` clocksource Roman Zippel
2006-06-16 18:48                   ` john stultz [this message]
2006-06-17 19:45                     ` clocksource Roman Zippel
2006-06-17 17:04                 ` clocksource Andrew Morton
2006-06-05  0:02 ` utsname/hostname Randy.Dunlap
2006-06-05  1:06   ` utsname/hostname Andrew Morton
2006-06-05  3:10     ` utsname/hostname Randy.Dunlap
     [not found] ` <20060605002807.GA4919@mail.ustc.edu.cn>
2006-06-05  0:28   ` readahead benchmark Fengguang Wu
2006-06-05  1:02     ` Andrew Morton
2006-06-05  0:32 ` new SCSI drivers (was Re: 2.6.18 -mm merge plans) Jeff Garzik
     [not found] ` <20060605010501.GA4931@mail.ustc.edu.cn>
2006-06-05  1:05   ` statistics infrastructure Fengguang Wu
2006-06-05 16:30   ` Greg KH
2006-06-13 23:47     ` statistics infrastructure (in -mm tree) review Greg KH
2006-06-14  0:18       ` Randy.Dunlap
2006-06-14 16:45         ` Greg KH
2006-06-14 22:48         ` Martin Peschke
2006-06-19 22:12           ` Greg KH
2006-06-20 15:40             ` Martin Peschke
2006-06-20 16:50               ` Randy.Dunlap
2006-06-21 18:51                 ` Martin Peschke
2006-06-21 19:38                   ` Matthew Frost
2006-06-22 11:43                     ` Martin Peschke
2006-06-14  5:04       ` Andi Kleen
2006-06-14 22:49         ` Martin Peschke
2006-06-16 20:40           ` Greg KH
2006-06-16 21:34             ` Martin Peschke
2006-06-17  6:51           ` Andi Kleen
2006-06-17 11:03             ` Martin Peschke
2006-06-17 10:30       ` Martin Peschke
2006-06-05  1:06 ` wireless (was Re: 2.6.18 -mm merge plans) Jeff Garzik
2006-06-05  1:15   ` Andrew Morton
2006-06-05  8:33     ` Andreas Mohr
2006-06-05  8:45       ` Arjan van de Ven
2006-06-05 10:26         ` Alan Cox
2006-06-05 10:35           ` Arjan van de Ven
2006-06-05 10:59             ` Alan Cox
2006-06-10  6:58             ` Pavel Machek
2006-06-05  8:54   ` Christoph Hellwig
2006-06-05 12:33     ` Jeff Garzik
2006-06-05 12:48       ` Arjan van de Ven
2006-06-05 12:52         ` Jeff Garzik
2006-06-05 14:02           ` Linux kernel and laws Adrian Bunk
2006-06-05 14:21             ` linux-os (Dick Johnson)
2006-06-06  5:33             ` Evgeniy Polyakov
2006-06-05 13:27     ` wireless (was Re: 2.6.18 -mm merge plans) John W. Linville
2006-06-05 13:31       ` Christoph Hellwig
2006-06-05 13:42       ` Arjan van de Ven
2006-06-05 16:24       ` Alan Cox
2006-06-29 14:26         ` ACX100 (softmac-based) driver ready to merge, but is it legal? -- " John W. Linville
     [not found]           ` <20060629144233.GB24463@tuxdriver.com>
2006-06-29 14:47             ` [Acx100-users] Denis Vlasenko, where are you? (mail bounced) Andreas Mohr
2006-06-05  1:32 ` merging new drivers (was Re: 2.6.18 -mm merge plans) Jeff Garzik
2006-06-05  1:47   ` Andrew Morton
2006-06-05  8:59     ` Christoph Hellwig
2006-06-05  9:10       ` Andrew Morton
2006-06-05  9:16         ` Arjan van de Ven
2006-06-05 11:10       ` Ivan Novick
2006-06-05 11:26         ` Adrian Bunk
2006-06-05  6:58   ` Francois Romieu
2006-06-05 10:32     ` Alan Cox
2006-06-05 10:36       ` Arjan van de Ven
2006-06-06  2:02         ` Chris Wright
2006-06-06  7:01           ` Andi Kleen
2006-06-06 13:04             ` Steven Rostedt
2006-06-05 13:38 ` 2.6.18 -mm merge plans -- GFS David Woodhouse
2006-06-05 14:10   ` Russell King
2006-06-05 15:01   ` Steven Whitehouse
2006-06-07  7:12     ` Steven Whitehouse
2006-06-05 14:08 ` 2.6.18 -mm merge plans Oleg Nesterov
2006-06-05 14:43 ` Serge E. Hallyn
2006-06-08 19:56   ` Eric W. Biederman
2006-06-09 13:02     ` Serge E. Hallyn
2006-06-09 23:25     ` Serge E. Hallyn
2006-06-10  0:39       ` Eric W. Biederman
2006-06-10  1:23         ` Serge E. Hallyn
2006-06-10  7:52           ` Eric W. Biederman
2006-06-10  8:09           ` Eric W. Biederman
2006-06-10  9:53       ` Christoph Hellwig
2006-06-06  0:54 ` Merge of per task delay accounting (was Re: 2.6.18 -mm merge plans) Balbir Singh
2006-06-06 22:28   ` Shailabh Nagar
2006-06-06 22:40     ` Andrew Morton
2006-06-08 14:27       ` Shailabh Nagar
2006-06-08 17:42         ` Andrew Morton
2006-06-08 18:36           ` Shailabh Nagar
2006-06-08 19:33             ` Balbir Singh
2006-06-06 22:52     ` Jay Lan
2006-06-06 22:55       ` Shailabh Nagar
2006-06-12 12:02       ` Martin Peschke
2006-06-12 13:28         ` Shailabh Nagar
2006-06-06 12:32 ` 2.6.18 -mm pi-futex merge Steven Rostedt
2006-06-06 13:34   ` Roman Zippel
2006-06-06 13:44     ` Steven Rostedt
2006-06-06 14:42 ` genirq Ingo Molnar
2006-06-06 16:56   ` genirq Daniel Walker
2006-06-07  8:42     ` genirq Ingo Molnar
2006-06-07  3:46   ` genirq Benjamin Herrenschmidt
2006-06-06 14:53 ` 2.6.18 -mm merge plans Ingo Molnar
2006-06-06 16:02   ` Andrew Morton
2006-06-06 16:35     ` Arjan van de Ven
2006-06-06 20:47     ` lock validator [2.6.18 -mm merge plans] Ingo Molnar
2006-06-07  3:52 ` mutex vs. local irqs (Was: 2.6.18 -mm merge plans) Benjamin Herrenschmidt
2006-06-07  4:29   ` Andrew Morton
2006-06-07  5:04     ` Benjamin Herrenschmidt
2006-06-07  5:29       ` Andrew Morton
2006-06-07  6:44         ` Benjamin Herrenschmidt
2006-06-07  7:03           ` Andrew Morton
2006-06-07 13:21           ` Ingo Molnar
2006-06-08  0:31             ` Benjamin Herrenschmidt
2006-06-08 10:49               ` David Woodhouse
2006-06-08 10:53                 ` Ingo Molnar
2006-06-08 11:01                   ` David Woodhouse
2006-06-08 11:17               ` Roman Zippel
2006-06-08 13:38                 ` Benjamin Herrenschmidt
2006-06-08 14:02                   ` Roman Zippel
2006-06-08 23:40                     ` Benjamin Herrenschmidt
2006-06-08 22:59             ` Paul Mackerras
2006-06-10 10:22 ` 2.6.18 -mm merge plans Christoph Hellwig
2006-06-14 15:18   ` Michael Halcrow

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=1150483684.5316.56.camel@localhost.localdomain \
    --to=johnstul@us.ibm.com \
    --cc=akpm@osdl.org \
    --cc=linux-kernel@vger.kernel.org \
    --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