All of lore.kernel.org
 help / color / mirror / Atom feed
From: Richard Cochran <richardcochran@gmail.com>
To: John Stultz <john.stultz@linaro.org>
Cc: linux-kernel@vger.kernel.org, linux-api@vger.kernel.org,
	netdev@vger.kernel.org, Alan Cox <alan@lxorguk.ukuu.org.uk>,
	Arnd Bergmann <arnd@arndb.de>, Christoph Lameter <cl@linux.com>,
	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>,
	Benjamin Herrenschmidt <benh@kernel.crashing.org>,
	"H. Peter Anvin" <hpa@zytor.com>, Ingo Molnar <mingo@redhat.com>,
	Mike Frysinger <vapier@gentoo.org>,
	Paul Mackerras <paulus@samba.org>,
	Russell King <linux@arm.linux.org.uk>
Subject: Re: [PATCH V10 12/15] ptp: Added a brand new class driver for ptp clocks.
Date: Fri, 11 Feb 2011 09:15:24 +0100	[thread overview]
Message-ID: <20110211081524.GA12270@riccoc20.at.omicron.at> (raw)
In-Reply-To: <1296612031.3336.201.camel@work-vm>

On Tue, Feb 01, 2011 at 06:00:31PM -0800, John Stultz wrote:
> On Thu, 2011-01-27 at 11:59 +0100, Richard Cochran wrote:

> You may want to tweak the kconfig a bit here. If I don't have pps
> enabled, if I go into the "PTP clock support" page, I get an empty
> screen.
> 
> Similarly, its not very discoverable to figure out what you need to
> enable to get the driver options to show up, as they depend the drivers
> enabled in the networking device section.

Okay, I'll see what I can come up with.

> > +#define PTP_MAX_ALARMS 4
> > +#define PTP_MAX_CLOCKS (MAX_CLOCKS/2)
> 
> Why MAX_CLOCKS/2 ? Should this scale as MAX_CLOCKS is increased?
> Or do you really just mean 8?

This is just left over from when I thought the PHCs would use the
static clock IDs. I'll fix that.

> > +static void enqueue_external_timestamp(struct timestamp_event_queue *queue,
> > +				       struct ptp_clock_event *src)
> > +{
> > +	struct ptp_extts_event *dst;
> > +	u32 remainder;
> > +
> > +	dst = &queue->buf[queue->tail];
> > +
> > +	dst->index = src->index;
> > +	dst->t.sec = div_u64_rem(src->timestamp, 1000000000, &remainder);
> > +	dst->t.nsec = remainder;
> > +
> > +	if (!queue_free(queue))
> > +		queue->overflow++;
> > +
> > +	queue->tail = (queue->tail + 1) % PTP_MAX_TIMESTAMPS;
> > +}
> 
> So what is serializing access to the timestamp_event_queue here? I don't
> see any usage of tsevq_mux by the callers. Am I missing it? It looks
> like its called from interrupt context, so do you really need a spinlock
> and not a mutex here?

The external timestamp FIFO is written only from interrupt context.
The readers are from user space via read() or sysfs. The readers must
hold a mutex. As you know, FIFOs with exactly one reader and one
writer don't need locking.

However, looking again at my own code (after spending a long time in
the posicx clock stuff), I notice that, although FIFO overflow is
detected, I do not offer a way for user space to find this out or to
clear the error. I'll fix that.

> > +#define PTP_MAX_TIMESTAMPS 128
> > +
> > +struct timestamp_event_queue {
> > +	struct ptp_extts_event buf[PTP_MAX_TIMESTAMPS];
> > +	int head;
> > +	int tail;
> > +	int overflow;
> > +};
> > +
> > +struct ptp_clock {
> > +	struct posix_clock clock;
> > +	struct device *dev;
> > +	struct ptp_clock_info *info;
> > +	dev_t devid;
> > +	int index; /* index into clocks.map */
> > +	struct pps_device *pps_source;
> > +	struct timestamp_event_queue tsevq; /* simple fifo for time stamps */
> > +	struct mutex tsevq_mux; /* one process at a time reading the fifo */
> > +	wait_queue_head_t tsev_wq;
> > +};
> > +
> > +static inline int queue_cnt(struct timestamp_event_queue *q)
> > +{
> > +	int cnt = q->tail - q->head;
> > +	return cnt < 0 ? PTP_MAX_TIMESTAMPS + cnt : cnt;
> > +}
> 
> This probably needs a comment as to its locking rules. Something like
> "Callers must hold tsevq_mux."

I'll add a comment explaining the readers mutex and why no
reader/writer locking is needed.

> > +struct ptp_clock_time {
> > +	__s64 sec;  /* seconds */
> > +	__u32 nsec; /* nanoseconds */
> > +	__u32 reserved;
> > +};
> > +
> > +struct ptp_clock_caps {
> > +	int max_adj;   /* Maximum frequency adjustment in parts per billon. */
> > +	int n_alarm;   /* Number of programmable alarms. */
> > +	int n_ext_ts;  /* Number of external time stamp channels. */
> > +	int n_per_out; /* Number of programmable periodic signals. */
> > +	int pps;       /* Whether the clock supports a PPS callback. */
> > +};
> > +
> > +struct ptp_extts_request {
> > +	unsigned int index; /* Which channel to configure. */
> > +	unsigned int flags; /* Bit field for PTP_xxx flags. */
> > +};
> > +
> > +struct ptp_perout_request {
> > +	struct ptp_clock_time start;  /* Absolute start time. */
> > +	struct ptp_clock_time period; /* Desired period, zero means disable. */
> > +	unsigned int index;           /* Which channel to configure. */
> > +	unsigned int flags;           /* Reserved for future use. */
> > +};
> 
> Since these are all new API/ABI structures, would it be wise to pad
> these out a bit more? You've got a couple of reserved fields, which is
> good, but if you think we're going to expand this at all, we may want to
> have a bit more wiggle room. The timex structure had something like 12
> unused ints (which came in handy when the tai field was added).
> 
> Not sure what the wider opinion is on this though.

Okay, I'll pad them a bit more.

However, I don't intend to ever offer more than simple functionality
here. A general purpose DAQ API is not so easy to define (look at
comedi, for example). Also, the capabilities of the current crop of
clocks varies quite a bit.

So, I think the PHC should offer a PPS, simple period outputs, and
simple external timestamping. If someone want more complex DAQ like
functions, then they can offer that through comedi or whatever.

> > +struct ptp_extts_event {
> > +	struct ptp_clock_time t; /* Time event occured. */
> > +	unsigned int index;      /* Which channel produced the event. */
> > +};
> 
> Same padding suggestion for this as well.

Okay, and thanks for the review,

Richard

WARNING: multiple messages have this Message-ID (diff)
From: Richard Cochran <richardcochran-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
To: John Stultz <john.stultz-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>
Cc: linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	linux-api-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	netdev-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	Alan Cox <alan-qBU/x9rampVanCEyBjwyrvXRex20P6io@public.gmane.org>,
	Arnd Bergmann <arnd-r2nGTMty4D4@public.gmane.org>,
	Christoph Lameter <cl-vYTEC60ixJUAvxtiuMwx3w@public.gmane.org>,
	David Miller <davem-fT/PcQaiUtIeIZ0/mPfg9Q@public.gmane.org>,
	Krzysztof Halasa <khc-9GfyWEdoJtJmR6Xm/wNWPw@public.gmane.org>,
	Peter Zijlstra <peterz-wEGCiKHe2LqWVfeAwA7xHQ@public.gmane.org>,
	Rodolfo Giometti <giometti-k2GhghHVRtY@public.gmane.org>,
	Thomas Gleixner <tglx-hfZtesqFncYOwBW4kG4KsQ@public.gmane.org>,
	Benjamin Herrenschmidt
	<benh-XVmvHMARGAS8U2dJNN8I7kB+6BGkLq7r@public.gmane.org>,
	"H. Peter Anvin" <hpa-YMNOUZJC4hwAvxtiuMwx3w@public.gmane.org>,
	Ingo Molnar <mingo-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>,
	Mike Frysinger <vapier-aBrp7R+bbdUdnm+yROfE0A@public.gmane.org>,
	Paul Mackerras <paulus-eUNUBHrolfbYtjvyW6yDsg@public.gmane.org>,
	Russell King <linux-lFZ/pmaqli7XmaaqVzeoHQ@public.gmane.org>
Subject: Re: [PATCH V10 12/15] ptp: Added a brand new class driver for ptp clocks.
Date: Fri, 11 Feb 2011 09:15:24 +0100	[thread overview]
Message-ID: <20110211081524.GA12270@riccoc20.at.omicron.at> (raw)
In-Reply-To: <1296612031.3336.201.camel@work-vm>

On Tue, Feb 01, 2011 at 06:00:31PM -0800, John Stultz wrote:
> On Thu, 2011-01-27 at 11:59 +0100, Richard Cochran wrote:

> You may want to tweak the kconfig a bit here. If I don't have pps
> enabled, if I go into the "PTP clock support" page, I get an empty
> screen.
> 
> Similarly, its not very discoverable to figure out what you need to
> enable to get the driver options to show up, as they depend the drivers
> enabled in the networking device section.

Okay, I'll see what I can come up with.

> > +#define PTP_MAX_ALARMS 4
> > +#define PTP_MAX_CLOCKS (MAX_CLOCKS/2)
> 
> Why MAX_CLOCKS/2 ? Should this scale as MAX_CLOCKS is increased?
> Or do you really just mean 8?

This is just left over from when I thought the PHCs would use the
static clock IDs. I'll fix that.

> > +static void enqueue_external_timestamp(struct timestamp_event_queue *queue,
> > +				       struct ptp_clock_event *src)
> > +{
> > +	struct ptp_extts_event *dst;
> > +	u32 remainder;
> > +
> > +	dst = &queue->buf[queue->tail];
> > +
> > +	dst->index = src->index;
> > +	dst->t.sec = div_u64_rem(src->timestamp, 1000000000, &remainder);
> > +	dst->t.nsec = remainder;
> > +
> > +	if (!queue_free(queue))
> > +		queue->overflow++;
> > +
> > +	queue->tail = (queue->tail + 1) % PTP_MAX_TIMESTAMPS;
> > +}
> 
> So what is serializing access to the timestamp_event_queue here? I don't
> see any usage of tsevq_mux by the callers. Am I missing it? It looks
> like its called from interrupt context, so do you really need a spinlock
> and not a mutex here?

The external timestamp FIFO is written only from interrupt context.
The readers are from user space via read() or sysfs. The readers must
hold a mutex. As you know, FIFOs with exactly one reader and one
writer don't need locking.

However, looking again at my own code (after spending a long time in
the posicx clock stuff), I notice that, although FIFO overflow is
detected, I do not offer a way for user space to find this out or to
clear the error. I'll fix that.

> > +#define PTP_MAX_TIMESTAMPS 128
> > +
> > +struct timestamp_event_queue {
> > +	struct ptp_extts_event buf[PTP_MAX_TIMESTAMPS];
> > +	int head;
> > +	int tail;
> > +	int overflow;
> > +};
> > +
> > +struct ptp_clock {
> > +	struct posix_clock clock;
> > +	struct device *dev;
> > +	struct ptp_clock_info *info;
> > +	dev_t devid;
> > +	int index; /* index into clocks.map */
> > +	struct pps_device *pps_source;
> > +	struct timestamp_event_queue tsevq; /* simple fifo for time stamps */
> > +	struct mutex tsevq_mux; /* one process at a time reading the fifo */
> > +	wait_queue_head_t tsev_wq;
> > +};
> > +
> > +static inline int queue_cnt(struct timestamp_event_queue *q)
> > +{
> > +	int cnt = q->tail - q->head;
> > +	return cnt < 0 ? PTP_MAX_TIMESTAMPS + cnt : cnt;
> > +}
> 
> This probably needs a comment as to its locking rules. Something like
> "Callers must hold tsevq_mux."

I'll add a comment explaining the readers mutex and why no
reader/writer locking is needed.

> > +struct ptp_clock_time {
> > +	__s64 sec;  /* seconds */
> > +	__u32 nsec; /* nanoseconds */
> > +	__u32 reserved;
> > +};
> > +
> > +struct ptp_clock_caps {
> > +	int max_adj;   /* Maximum frequency adjustment in parts per billon. */
> > +	int n_alarm;   /* Number of programmable alarms. */
> > +	int n_ext_ts;  /* Number of external time stamp channels. */
> > +	int n_per_out; /* Number of programmable periodic signals. */
> > +	int pps;       /* Whether the clock supports a PPS callback. */
> > +};
> > +
> > +struct ptp_extts_request {
> > +	unsigned int index; /* Which channel to configure. */
> > +	unsigned int flags; /* Bit field for PTP_xxx flags. */
> > +};
> > +
> > +struct ptp_perout_request {
> > +	struct ptp_clock_time start;  /* Absolute start time. */
> > +	struct ptp_clock_time period; /* Desired period, zero means disable. */
> > +	unsigned int index;           /* Which channel to configure. */
> > +	unsigned int flags;           /* Reserved for future use. */
> > +};
> 
> Since these are all new API/ABI structures, would it be wise to pad
> these out a bit more? You've got a couple of reserved fields, which is
> good, but if you think we're going to expand this at all, we may want to
> have a bit more wiggle room. The timex structure had something like 12
> unused ints (which came in handy when the tai field was added).
> 
> Not sure what the wider opinion is on this though.

Okay, I'll pad them a bit more.

However, I don't intend to ever offer more than simple functionality
here. A general purpose DAQ API is not so easy to define (look at
comedi, for example). Also, the capabilities of the current crop of
clocks varies quite a bit.

So, I think the PHC should offer a PPS, simple period outputs, and
simple external timestamping. If someone want more complex DAQ like
functions, then they can offer that through comedi or whatever.

> > +struct ptp_extts_event {
> > +	struct ptp_clock_time t; /* Time event occured. */
> > +	unsigned int index;      /* Which channel produced the event. */
> > +};
> 
> Same padding suggestion for this as well.

Okay, and thanks for the review,

Richard

  reply	other threads:[~2011-02-11  8:15 UTC|newest]

Thread overview: 46+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-01-27 10:53 [PATCH V10 00/15] ptp: IEEE 1588 hardware clock support Richard Cochran
2011-01-27 10:53 ` Richard Cochran
2011-01-27 10:54 ` [PATCH V10 01/15] time: Introduce timekeeping_inject_offset John Stultz
2011-01-27 18:48   ` John Stultz
2011-01-28  7:08     ` Richard Cochran
2011-01-28  7:08       ` Richard Cochran
2011-01-28 12:05       ` Arnd Bergmann
2011-01-28 12:05         ` Arnd Bergmann
2011-01-28 12:43         ` Peter Zijlstra
2011-01-28 12:54           ` Arnd Bergmann
2011-01-28 12:54             ` Arnd Bergmann
2011-01-27 10:54 ` [PATCH V10 02/15] time: Correct the *settime* parameters Richard Cochran
2011-01-27 10:55 ` [PATCH V10 03/15] ntp: add ADJ_SETOFFSET mode bit Richard Cochran
2011-01-27 10:55 ` [PATCH V10 04/15] posix clocks: introduce a syscall for clock tuning Richard Cochran
2011-01-27 10:55   ` Richard Cochran
2011-01-27 10:56 ` [PATCH V10 05/15] posix_clocks: add clock_adjtime for arm Richard Cochran
2011-01-27 10:56   ` Richard Cochran
2011-01-27 10:57 ` [PATCH V10 06/15] posix_clocks: add clock_adjtime for blackfin Richard Cochran
2011-01-27 10:57 ` [PATCH V10 07/15] posix_clocks: add clock_adjtime for powerpc Richard Cochran
2011-01-27 10:57 ` [PATCH V10 08/15] posix_clocks: add clock_adjtime for x86 Richard Cochran
2011-01-27 10:58 ` [PATCH V10 09/15] posix clocks: cleanup the CLOCK_DISPTACH macro Richard Cochran
2011-01-27 10:58   ` Richard Cochran
2011-01-27 10:58 ` [PATCH V10 10/15] posix clocks: remove useless default methods Richard Cochran
2011-01-27 10:58   ` Richard Cochran
2011-01-27 10:58 ` [PATCH V10 11/15] posix clocks: introduce dynamic clocks Richard Cochran
2011-01-27 10:58   ` Richard Cochran
2011-01-27 10:59 ` [PATCH V10 12/15] ptp: Added a brand new class driver for ptp clocks Richard Cochran
2011-02-02  2:00   ` John Stultz
2011-02-02  2:00     ` John Stultz
2011-02-11  8:15     ` Richard Cochran [this message]
2011-02-11  8:15       ` Richard Cochran
2011-02-15 17:29       ` Richard Cochran
2011-01-27 10:59 ` [PATCH V10 13/15] ptp: Added a clock that uses the eTSEC found on the MPC85xx Richard Cochran
2011-01-27 10:59   ` Richard Cochran
2011-02-02  2:04   ` john stultz
2011-02-02  2:04     ` john stultz
2011-01-27 11:00 ` [PATCH V10 14/15] ptp: Added a clock driver for the IXP46x Richard Cochran
2011-02-02  2:10   ` john stultz
2011-02-02  2:10     ` john stultz
2011-01-27 11:00 ` [PATCH V10 15/15] ptp: Added a clock driver for the National Semiconductor PHYTER Richard Cochran
2011-01-27 11:00   ` Richard Cochran
2011-02-02  2:11   ` john stultz
2011-02-02  2:11     ` john stultz
2011-02-11  8:19     ` Richard Cochran
2011-01-31  9:29 ` [PATCH V10 00/15] ptp: IEEE 1588 hardware clock support Thomas Gleixner
2011-01-31  9:29   ` Thomas Gleixner

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=20110211081524.GA12270@riccoc20.at.omicron.at \
    --to=richardcochran@gmail.com \
    --cc=alan@lxorguk.ukuu.org.uk \
    --cc=arnd@arndb.de \
    --cc=benh@kernel.crashing.org \
    --cc=cl@linux.com \
    --cc=davem@davemloft.net \
    --cc=giometti@linux.it \
    --cc=hpa@zytor.com \
    --cc=john.stultz@linaro.org \
    --cc=khc@pm.waw.pl \
    --cc=linux-api@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@arm.linux.org.uk \
    --cc=mingo@redhat.com \
    --cc=netdev@vger.kernel.org \
    --cc=paulus@samba.org \
    --cc=peterz@infradead.org \
    --cc=tglx@linutronix.de \
    --cc=vapier@gentoo.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.