Module Name:    src
Committed By:   kardel
Date:           Sun Jun 14 13:16:32 UTC 2009

Modified Files:
        src/sys/kern: kern_tc.c
        src/sys/sys: timepps.h

Log Message:
Make PPS work with fast time counters (> 2GHz)
by making the pps count time stamp and the update
time stamp u_int64.
The time delta between two PPS events can now
be correctly calculated avoiding any unaccounted
for wraps with 32-bit counters.


To generate a diff of this commit:
cvs rdiff -u -r1.39 -r1.40 src/sys/kern/kern_tc.c
cvs rdiff -u -r1.18 -r1.19 src/sys/sys/timepps.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/kern/kern_tc.c
diff -u src/sys/kern/kern_tc.c:1.39 src/sys/kern/kern_tc.c:1.40
--- src/sys/kern/kern_tc.c:1.39	Sat May 23 17:08:04 2009
+++ src/sys/kern/kern_tc.c	Sun Jun 14 13:16:32 2009
@@ -1,4 +1,4 @@
-/* $NetBSD: kern_tc.c,v 1.39 2009/05/23 17:08:04 ad Exp $ */
+/* $NetBSD: kern_tc.c,v 1.40 2009/06/14 13:16:32 kardel Exp $ */
 
 /*-
  * Copyright (c) 2008, 2009 The NetBSD Foundation, Inc.
@@ -40,7 +40,7 @@
 
 #include <sys/cdefs.h>
 /* __FBSDID("$FreeBSD: src/sys/kern/kern_tc.c,v 1.166 2005/09/19 22:16:31 andre Exp $"); */
-__KERNEL_RCSID(0, "$NetBSD: kern_tc.c,v 1.39 2009/05/23 17:08:04 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_tc.c,v 1.40 2009/06/14 13:16:32 kardel Exp $");
 
 #include "opt_ntp.h"
 
@@ -87,16 +87,19 @@
 
 struct timehands {
 	/* These fields must be initialized by the driver. */
-	struct timecounter	*th_counter;
-	int64_t			th_adjustment;
-	u_int64_t		th_scale;
-	u_int	 		th_offset_count;
-	struct bintime		th_offset;
-	struct timeval		th_microtime;
-	struct timespec		th_nanotime;
+	struct timecounter	*th_counter;     /* active timecounter */
+	int64_t			th_adjustment;   /* frequency adjustment */
+						 /* (NTP/adjtime) */
+	u_int64_t		th_scale;        /* scale factor (counter */
+						 /* tick->time) */
+	u_int64_t 		th_offset_count; /* offset at last time */
+						 /* update (tc_windup()) */
+	struct bintime		th_offset;       /* bin (up)time at windup */
+	struct timeval		th_microtime;    /* cached microtime */
+	struct timespec		th_nanotime;     /* cached nanotime */
 	/* Fields not to be copied in tc_windup start with th_generation. */
-	volatile u_int		th_generation;
-	struct timehands	*th_next;
+	volatile u_int		th_generation;   /* current genration */
+	struct timehands	*th_next;        /* next timehand */
 };
 
 static struct timehands th0;
@@ -732,7 +735,6 @@
 	else
 		ncount = 0;
 	th->th_offset_count += delta;
-	th->th_offset_count &= th->th_counter->tc_counter_mask;
 	bintime_addx(&th->th_offset, th->th_scale * delta);
 
 	/*
@@ -920,7 +922,7 @@
 	th = timehands;
 	pps->capgen = th->th_generation;
 	pps->capth = th;
-	pps->capcount = th->th_counter->tc_get_timecount(th->th_counter);
+	pps->capcount = (u_int64_t)tc_delta(th) + th->th_offset_count;
 	if (pps->capgen != th->th_generation)
 		pps->capgen = 0;
 }
@@ -930,7 +932,7 @@
 {
 	struct bintime bt;
 	struct timespec ts, *tsp, *osp;
-	u_int tcount, *pcount;
+	u_int64_t tcount, *pcount;
 	int foff, fhard;
 	pps_seq_t *pseq;
 
@@ -971,7 +973,6 @@
 
 	/* Convert the count to a timespec. */
 	tcount = pps->capcount - pps->capth->th_offset_count;
-	tcount &= pps->capth->th_counter->tc_counter_mask;
 	bt = pps->capth->th_offset;
 	bintime_addx(&bt, pps->capth->th_scale * tcount);
 	bintime_add(&bt, &timebasebin);

Index: src/sys/sys/timepps.h
diff -u src/sys/sys/timepps.h:1.18 src/sys/sys/timepps.h:1.19
--- src/sys/sys/timepps.h:1.18	Mon Apr 21 12:56:31 2008
+++ src/sys/sys/timepps.h	Sun Jun 14 13:16:32 2009
@@ -1,4 +1,4 @@
-/*	$NetBSD: timepps.h,v 1.18 2008/04/21 12:56:31 ad Exp $	*/
+/*	$NetBSD: timepps.h,v 1.19 2009/06/14 13:16:32 kardel Exp $	*/
 
 /*
  * Copyright (c) 1998 Jonathan Stone
@@ -139,7 +139,7 @@
 	/* Capture information. */
 	struct timehands *capth;
 	unsigned	capgen;
-	unsigned	capcount;
+	u_int64_t	capcount;
 
 	/* State information. */
 	pps_params_t	ppsparam;
@@ -147,7 +147,7 @@
 	int		kcmode;
 	int		ppscap;
 	struct timecounter *ppstc;
-	unsigned	ppscount[3];
+	u_int64_t	ppscount[3]; 
 };
 
 void pps_capture(struct pps_state *);

Reply via email to