[LinuxPPS] how to tell if LinuxPPS and GPS are updating ntp (and system time)

clemens at dwf.com clemens at dwf.com
Tue Nov 24 18:22:23 CET 2009


> Hi Reg, hi team,
> 
> I am trying to catch up on the status of LinuxPPS right now, and I 've seen
> the new patches from Rodolfo, which I should be applying shortly to
> my test machines.
> 
> What I am not quite clear on is what Reg says here:
> 
> On Mon, Oct 26, 2009 at 18:35,  <clemens at dwf.com> wrote:
> > both seem to work fine, as noted I see interrupts on both ASSERT and CLEAR
> > when only ASSERT are asked for.  This works fine with the ONCORE driver,
> > It complains about every extra event, but it might be enough to cause
> > problems with other drivers, if both events are passed on to the upper
> > levels of the software.
> 
> and the resulting discussion, after which I've seen this other message
> with a "Mea Culpa":
> 
> http://ml.enneenne.com/pipermail/linuxpps/2009-October/003425.html
> 
> and the following question from Rodolfo:
> 
> > Did you applied also the patch regarding missing spinlocks in
> > GET_PARAMS?
> 
> So the question now is, shall I just patch the 2.6.31 kernel with the
> patch supplied by Rodolfo, or shall I also dig out the smaller patches
> related to ASSERT and CLEAR?
> 
> Thanks and ciao,
> 
> Luca
> 

Here is what I am running.
As I note below, I had expected the to patches included below to make
it into 2.6.31.6, but they didnt.  Im guessing 2.6.31.7 but who knows.
If you are using source beyond 2.6.31.6, you should check to see if these
patches are already there.

---

1) get linux-2.6.31.6.tar.bz2 from kernels.org, probably any of the 2.6.31 
series is ok.

2) get the patch http://ftp.enneenne.com/pub/misc/linuxpps/patches/tests/ntp-pp
s-v2.6.31.diff

3) cd into the top level, and patch with
	patch -p1 < <path to patch>/ntp-pps-v2.6.31.diff

4) put the following code in a file, call it file 1

---

From: Rodolfo Giometti <giometti at linux.it>

Userland programs may read/write PPS parameters at same time and these
operations may corrupt PPS data.

Signed-off-by: Rodolfo Giometti <giometti at linux.it>
Tested-by: Reg Clemens <clemens at dwf.com>
Cc: <stable at kernel.org>
Signed-off-by: Andrew Morton <akpm at linux-foundation.org>
---


diff -puN drivers/pps/pps.c~pps-locking-scheme-fix-up-for-pps_getparams 
drivers/pps/pps.c
--- a/drivers/pps/pps.c~pps-locking-scheme-fix-up-for-pps_getparams
+++ a/drivers/pps/pps.c
@@ -71,9 +71,14 @@ static long pps_cdev_ioctl(struct file *
 	case PPS_GETPARAMS:
 		pr_debug("PPS_GETPARAMS: source %d\n", pps->id);
 
-		/* Return current parameters */
-		err = copy_to_user(uarg, &pps->params,
-						sizeof(struct pps_kparams));
+		spin_lock_irq(&pps->lock);
+
+		/* Get the current parameters */
+		params = pps->params;
+
+		spin_unlock_irq(&pps->lock);
+
+		err = copy_to_user(uarg, &params, sizeof(struct pps_kparams));
 		if (err)
 			return -EFAULT;
 
_

---

5) patch from the top level with
	patch -p1 <path to file file1>/file1

6) put the following in a file, call it file2

---

From: Rodolfo Giometti <giometti at linux.it>

PPS events must be recorded according to PPS's mode settings.

If a process asks for (i.e.) capture-assert events only, when the PPS
client calls the pps_event() function to save the current PPS event, we
should verify the event type and then discard unwanted ones.

Also, without this patch userland processes waiting for a specific PPS
event (assert or clear but not both) may be awakened at wrong time.

Signed-off-by: Rodolfo Giometti <giometti at linux.it>
Tested-by: William S. Brasher <billb958 at door.net>
Tested-by: Reg Clemens <clemens at dwf.com>
Cc: <stable at kernel.org>
Signed-off-by: Andrew Morton <akpm at linux-foundation.org>
---


diff -puN drivers/pps/kapi.c~pps-events-reporting-fix-up drivers/pps/kapi.c
--- a/drivers/pps/kapi.c~pps-events-reporting-fix-up
+++ a/drivers/pps/kapi.c
@@ -271,6 +271,7 @@ void pps_event(int source, struct pps_kt
 {
 	struct pps_device *pps;
 	unsigned long flags;
+	int captured = 0;
 
 	if ((event & (PPS_CAPTUREASSERT | PPS_CAPTURECLEAR)) == 0) {
 		printk(KERN_ERR "pps: unknown event (%x) for source %d\n",
@@ -293,7 +294,8 @@ void pps_event(int source, struct pps_kt
 
 	/* Check the event */
 	pps->current_mode = pps->params.mode;
-	if (event & PPS_CAPTUREASSERT) {
+	if ((event & PPS_CAPTUREASSERT) &
+			(pps->params.mode & PPS_CAPTUREASSERT)) {
 		/* We have to add an offset? */
 		if (pps->params.mode & PPS_OFFSETASSERT)
 			pps_add_offset(ts, &pps->params.assert_off_tu);
@@ -303,8 +305,11 @@ void pps_event(int source, struct pps_kt
 		pps->assert_sequence++;
 		pr_debug("capture assert seq #%u for source %d\n",
 			pps->assert_sequence, source);
+
+		captured = ~0;
 	}
-	if (event & PPS_CAPTURECLEAR) {
+	if ((event & PPS_CAPTURECLEAR) &
+			(pps->params.mode & PPS_CAPTURECLEAR)) {
 		/* We have to add an offset? */
 		if (pps->params.mode & PPS_OFFSETCLEAR)
 			pps_add_offset(ts, &pps->params.clear_off_tu);
@@ -314,12 +319,17 @@ void pps_event(int source, struct pps_kt
 		pps->clear_sequence++;
 		pr_debug("capture clear seq #%u for source %d\n",
 			pps->clear_sequence, source);
+
+		captured = ~0;
 	}
 
-	pps->go = ~0;
-	wake_up_interruptible(&pps->queue);
+	/* Wake up iif captured somthing */
+	if (captured) {
+		pps->go = ~0;
+		wake_up_interruptible(&pps->queue);
 
-	kill_fasync(&pps->async_queue, SIGIO, POLL_IN);
+		kill_fasync(&pps->async_queue, SIGIO, POLL_IN);
+	}
 
 	spin_unlock_irqrestore(&pps->lock, flags);
 
_

---

7) patch from the top level with
	patch -p1 <path to file2>/file2

8) now go in and configure your kernel, (turning the pps stuff on)

I was expecting the 2nd and 3rd patch to make it into 2.6.31.6, but they didnt.
the stuff in the *v2* patch include the serial port code, and it would seem 
that
how we do that is still under discussion.

---

9) USER AREA STUFF: Add the following two lines to  /usr/include/sys/timex.h
(NOT to ../linux/timex.h which is not used by ntp)

#define MOD_NANO        ADJ_NANO
#define NOD_TAI         ADJ_TAI

---

You should now have all the patches, and be able to run nano-second time with
ntp.

					Reg.Clemens
					clemens at dwf.com









More information about the LinuxPPS mailing list