linux-api.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: john stultz <johnstul@us.ibm.com>
To: Christoph Lameter <cl@linux.com>
Cc: Richard Cochran <richardcochran@gmail.com>,
	linux-kernel@vger.kernel.org,
	devicetree-discuss@lists.ozlabs.org, linux-api@vger.kernel.org,
	linux-arm-kernel@lists.infradead.org,
	linuxppc-dev@lists.ozlabs.org, netdev@vger.kernel.org,
	Arnd Bergmann <arnd@arndb.de>, David Miller <davem@davemloft.net>,
	Krzysztof Halasa <khc@pm.waw.pl>,
	Peter Zijlstra <peterz@infradead.org>,
	Rodolfo Giometti <giometti@linux.it>,
	Thomas Gleixner <tglx@linutronix.de>
Subject: Re: [PATCH v6 0/8] ptp: IEEE 1588 hardware clock support
Date: Thu, 23 Sep 2010 13:28:04 -0700	[thread overview]
Message-ID: <1285273684.2587.92.camel@localhost.localdomain> (raw)
In-Reply-To: <alpine.DEB.2.00.1009231402420.2962@router.home>

On Thu, 2010-09-23 at 14:15 -0500, Christoph Lameter wrote:
> On Thu, 23 Sep 2010, john stultz wrote:
> 
> > This was my initial gut reaction as well, but in the end, I agree with
> > Richard that in the case of one or multiple PTP hardware clocks, we
> > really can't abstract over the different time domains.
> 
> My (arguably still superficial) review of the source does not show
> anything that would make me reach that conclusion.
> 
> > I really don't think the PTP clock can be used as a clocksource sanely.
> >
> > First, the hardware access is much to slow for system timekeeping.
> 
> The HPET or pit timesource are also quite slow these days. You only need
> access periodically to essentially tune the TSC ratio.

If we're using the TSC, then we're not using the PTP clock as you
suggest. Further the HPET and PIT aren't used to steer the system time
when we are using the TSC as a clocksource. Its only used to calibrate
the initial constant freq used by the timekeeping code (and if its
non-constant, we throw it out).

> > Second, there is the problem that the system time is a software clock,
> > and adjustments made (like freq) are made in the layer that interprets
> > the underlying hardware cycle counter. Adjustments made in PTP (in order
> > to sync the network timestamps) are made at the hardware level.
> 
> From what I can see the PTP clocks are periodic hardware cycle counters
> like any other clock that we currently support. If its configurable enough
> then setup a hardware cycle counter that mimics nanoseconds since the
> epoch as closely as possible and use that to sync the TSC rate to. Makes
> it very easy.

I guess I'm confused by what you're suggesting.
If we're using the TSC, then that's the clocksource timekeeping uses.
The original issue seemed to be around the suggestion of using the PTP
clock as a clocksource, which I don't think is really feasible.

Again, that's because
1) The PTP access latency is slow (so is the PIT, true enough, but no
one should be using the PIT as a clocksource unless they really have no
better hardware - its really only useful for 486s and old freq scaling
laptops that have no other stable clocksource).

2) The way PTP clocks are steered to sync with network time causes their
hardware freq to actually change. Since these adjustments are done on
the hardware clock level, and not on the system time level, the
adjustments to sync the system time/freq would then be made incorrect by
PTP hardware adjustments. 

3) Further, the PTP hardware counter can be simply set to a new offset
to put it in line with the network time. This could cause trouble with
timekeeping much like unsynced TSCs do.


Now, what you seem to be suggesting is to use the TSC (or whatever
clocksource the system time is using) but to steer the system time using
the PTP clock. This is actually what is being proposed, however, the
steering is done in userland. This is due to the fact that there are two
components to the steering, 1) adjusting the PTP clock hardware to
network time and 2) adjusting the system time to the PTP hardware. By
exposing the PTP clock to userland via the posix clocks interface, we
allow this to easily be done.


> > This would cause a disconnect between the hardware freq understood by
> > the system time management code and the actual hardware freq.
> 
> We can switch underlying clocks for system time already. We can adapt to a
> different hw frequency.

Actually no. The timekeeping code requires a fixed freq counter. Dealing
with hardware freq changes is difficult, because error is introduced by
the latency between when the freq changes and when the timekeeping code
is notified of it. So the system treats the hardware counters as fixed
freq. Now, hardware does vary freq ever so slightly as thermal
conditions change, but this is addressed in userland and corrected via
adjtimex.

>  But then I do not know why adjust the freq? I
> thought the point was that the periodic clock was network synchronized and
> can be used as "the" master clock for multiple machines?

Not parsing that. What do you mean by periodic clock?

> > Richard, I'd actually strike this paragraph from the rational, as I feel
> > it has the tendency to confuse as it suggests having the PHC as a
> > clocksource is feasible when really it isn't. Or alternatively, maybe
> > express more clearly why its not feasible, so it doesn't just seem like
> > a minor design choice.
> 
> Sorry but I still feel that this is pretty much a misguided approach that
> creates unnecessary layers in the kernel.

Unnecessary layers? Where? This approach has less in-kernel layers, as
it exposes the PTP clock to userland, instead of trying to layer things
on top of it and stretching the system time abstraction to cover it.

>  The trivial easy approach was
> not done (copy a driver from drivers/clocksource, modify so that it
> programs access to a centralized periodic ptp signal and uses it for
> system sync).

I disagree.

I've argued through the approach trying to keep it all internal to the
kernel, but to do so would be anything but trivial. Further, there's the
case of master-clocks, where the PTP hardware must be synced to system
time, instead of the other way around. And then there's the case of
boundary-clocks, which may have multiple PTP hardware clocks that have
to be synced.

I think exposing this through the posix clock interface is really the
best approach. Its not a static clockid, so its not something most apps
will ever have to deal with, but it allows the few apps that really need
to have access to the PTP clock hardware can do so in a clean way.


And credits to Richard for having to slowly explain this to me (and
others) many times over, before I got it.

thanks
-john


  reply	other threads:[~2010-09-23 20:28 UTC|newest]

Thread overview: 53+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-09-23 17:30 [PATCH v6 0/8] ptp: IEEE 1588 hardware clock support Richard Cochran
2010-09-23 17:31 ` [PATCH 1/8] posix clocks: introduce a syscall for clock tuning Richard Cochran
     [not found]   ` <b94ef1cd9c04ef3ad5964408bd0af7251add78de.1285261534.git.richard.cochran-3mrvs1K0uXizZXS1Dc/lvw@public.gmane.org>
2010-09-23 19:48     ` john stultz
     [not found]       ` <1285271331.2587.56.camel-bi+AKbBUZKY6gyzm1THtWbp2dZbC/Bob@public.gmane.org>
2010-09-24  7:29         ` Richard Cochran
     [not found]           ` <20100924072946.GA5043-7KxsofuKt4IfAd9E5cN8NEzG7cXyKsk/@public.gmane.org>
2010-09-24 17:55             ` john stultz
2010-09-23 22:03     ` Benjamin Herrenschmidt
2010-09-23 22:12       ` Thomas Gleixner
     [not found]         ` <alpine.LFD.2.00.1009240008390.2416-bi+AKbBUZKagILUCTcTcHdKyNwTtLsGr@public.gmane.org>
2010-09-24  1:20           ` Benjamin Herrenschmidt
2010-09-24  7:55       ` Richard Cochran
     [not found]         ` <20100924075534.GB5043-7KxsofuKt4IfAd9E5cN8NEzG7cXyKsk/@public.gmane.org>
2010-09-24 22:12           ` Benjamin Herrenschmidt
2010-09-23 17:31 ` [PATCH 2/8] posix clocks: dynamic clock ids Richard Cochran
2010-09-23 17:31 ` [PATCH 3/8] posix clocks: introduce a sysfs presence Richard Cochran
     [not found] ` <cover.1285261533.git.richard.cochran-3mrvs1K0uXizZXS1Dc/lvw@public.gmane.org>
2010-09-23 17:32   ` [PATCH 4/8] ptp: Added a brand new class driver for ptp clocks Richard Cochran
2010-09-23 17:32 ` [PATCH 5/8] ptp: Added a simulated PTP hardware clock Richard Cochran
2010-09-23 17:33 ` [PATCH 6/8] ptp: Added a clock that uses the eTSEC found on the MPC85xx Richard Cochran
     [not found]   ` <57b64051c816dc9cb856bbb9f38fc901c9d3d651.1285261535.git.richard.cochran-3mrvs1K0uXizZXS1Dc/lvw@public.gmane.org>
2010-09-23 19:17     ` Christoph Lameter
     [not found]       ` <alpine.DEB.2.00.1009231348150.2962-sBS69tsa9Uj/9pzu0YdTqQ@public.gmane.org>
2010-09-23 20:43         ` Alan Cox
     [not found]           ` <20100923214359.3f287b11-qBU/x9rampVanCEyBjwyrvXRex20P6io@public.gmane.org>
2010-09-23 20:32             ` Christoph Lameter
2010-09-23 21:26           ` Christian Riesch
2010-09-24 11:52             ` Alan Cox
2010-09-24  8:49         ` Richard Cochran
2010-09-23 17:33 ` [PATCH 7/8] ptp: Added a clock driver for the IXP46x Richard Cochran
2010-09-23 17:34 ` [PATCH 8/8] ptp: Added a clock driver for the National Semiconductor PHYTER Richard Cochran
2010-09-23 17:53 ` [PATCH v6 0/8] ptp: IEEE 1588 hardware clock support Christoph Lameter
2010-09-23 18:21   ` Jacob Keller
2010-09-23 18:36     ` Christoph Lameter
     [not found]   ` <alpine.DEB.2.00.1009231238170.2962-sBS69tsa9Uj/9pzu0YdTqQ@public.gmane.org>
2010-09-23 18:59     ` john stultz
     [not found]       ` <1285268380.2587.11.camel-bi+AKbBUZKY6gyzm1THtWbp2dZbC/Bob@public.gmane.org>
2010-09-23 19:15         ` Christoph Lameter
2010-09-23 20:28           ` john stultz [this message]
2010-09-23 20:49             ` Christoph Lameter
     [not found]               ` <alpine.DEB.2.00.1009231533040.7522-sBS69tsa9Uj/9pzu0YdTqQ@public.gmane.org>
2010-09-23 21:34                 ` Alan Cox
2010-09-23 21:34                   ` Christian Riesch
     [not found]                     ` <4C9BC7CE.8020400-U4+xqT1Vg0VeoWH0uzbU5w@public.gmane.org>
2010-09-27 15:37                       ` Christoph Lameter
2010-09-30  3:50                         ` Christian Riesch
2010-10-02  1:44                         ` M. Warner Losh
2010-09-23 21:42                 ` john stultz
     [not found]                   ` <1285278136.2587.154.camel-bi+AKbBUZKY6gyzm1THtWbp2dZbC/Bob@public.gmane.org>
2010-09-27 15:52                     ` Christoph Lameter
2010-09-27 16:14                       ` M. Warner Losh
     [not found]                         ` <20100927.101423.702773873740300798.imp-uzTCJ5RojNnQT0dZR+AlfA@public.gmane.org>
2010-09-28  6:34                           ` Richard Cochran
2010-09-24  8:33     ` Richard Cochran
2010-09-23 19:38 ` john stultz
     [not found]   ` <1285270733.2587.46.camel-bi+AKbBUZKY6gyzm1THtWbp2dZbC/Bob@public.gmane.org>
2010-09-24 13:50     ` Richard Cochran
     [not found]       ` <20100924135001.GB3113-7KxsofuKt4IfAd9E5cN8NEzG7cXyKsk/@public.gmane.org>
2010-09-24 14:57         ` Alan Cox
2010-09-23 20:36 ` Alan Cox
2010-09-23 20:49   ` john stultz
     [not found]     ` <1285274952.2587.113.camel-bi+AKbBUZKY6gyzm1THtWbp2dZbC/Bob@public.gmane.org>
2010-09-23 21:30       ` Alan Cox
2010-09-23 22:03         ` john stultz
     [not found]   ` <20100923213654.0c64b047-qBU/x9rampVanCEyBjwyrvXRex20P6io@public.gmane.org>
2010-09-24 13:14     ` Richard Cochran
     [not found]       ` <20100924131407.GA3113-7KxsofuKt4IfAd9E5cN8NEzG7cXyKsk/@public.gmane.org>
2010-09-24 14:02         ` Alan Cox
2010-09-24 14:07           ` Alan Cox
2010-09-27 15:56           ` Christoph Lameter
2010-09-27 17:05             ` Alan Cox
2010-09-28  6:47               ` Richard Cochran

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=1285273684.2587.92.camel@localhost.localdomain \
    --to=johnstul@us.ibm.com \
    --cc=arnd@arndb.de \
    --cc=cl@linux.com \
    --cc=davem@davemloft.net \
    --cc=devicetree-discuss@lists.ozlabs.org \
    --cc=giometti@linux.it \
    --cc=khc@pm.waw.pl \
    --cc=linux-api@vger.kernel.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linuxppc-dev@lists.ozlabs.org \
    --cc=netdev@vger.kernel.org \
    --cc=peterz@infradead.org \
    --cc=richardcochran@gmail.com \
    --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;
as well as URLs for NNTP newsgroup(s).