Commit 6f4229b51106cbc859e9d8209b22c8a2ec749e64

Authored by Alexander Gordeev
Committed by Linus Torvalds
1 parent 3003d55b59

pps: unify timestamp gathering

Add a helper function to gather timestamps.  This way clients don't have
to duplicate it.

Signed-off-by: Alexander Gordeev <lasaine@lvk.cs.msu.su>
Acked-by: Rodolfo Giometti <giometti@linux.it>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

Showing 6 changed files with 45 additions and 31 deletions Side-by-side Diff

drivers/pps/clients/pps-ktimer.c
... ... @@ -40,17 +40,12 @@
40 40  
41 41 static void pps_ktimer_event(unsigned long ptr)
42 42 {
43   - struct timespec __ts;
44   - struct pps_ktime ts;
  43 + struct pps_event_time ts;
45 44  
46 45 /* First of all we get the time stamp... */
47   - getnstimeofday(&__ts);
  46 + pps_get_ts(&ts);
48 47  
49 48 pr_info("PPS event at %lu\n", jiffies);
50   -
51   - /* ... and translate it to PPS time data struct */
52   - ts.sec = __ts.tv_sec;
53   - ts.nsec = __ts.tv_nsec;
54 49  
55 50 pps_event(source, &ts, PPS_CAPTUREASSERT, NULL);
56 51  
drivers/pps/clients/pps-ldisc.c
... ... @@ -27,26 +27,20 @@
27 27 #define PPS_TTY_MAGIC 0x0001
28 28  
29 29 static void pps_tty_dcd_change(struct tty_struct *tty, unsigned int status,
30   - struct timespec *ts)
  30 + struct pps_event_time *ts)
31 31 {
32 32 int id = (long)tty->disc_data;
33   - struct timespec __ts;
34   - struct pps_ktime pps_ts;
  33 + struct pps_event_time __ts;
35 34  
36 35 /* First of all we get the time stamp... */
37   - getnstimeofday(&__ts);
  36 + pps_get_ts(&__ts);
38 37  
39 38 /* Does caller give us a timestamp? */
40   - if (ts) { /* Yes. Let's use it! */
41   - pps_ts.sec = ts->tv_sec;
42   - pps_ts.nsec = ts->tv_nsec;
43   - } else { /* No. Do it ourself! */
44   - pps_ts.sec = __ts.tv_sec;
45   - pps_ts.nsec = __ts.tv_nsec;
46   - }
  39 + if (!ts) /* No. Do it ourself! */
  40 + ts = &__ts;
47 41  
48 42 /* Now do the PPS event report */
49   - pps_event(id, &pps_ts, status ? PPS_CAPTUREASSERT : PPS_CAPTURECLEAR,
  43 + pps_event(id, ts, status ? PPS_CAPTUREASSERT : PPS_CAPTURECLEAR,
50 44 NULL);
51 45  
52 46 pr_debug("PPS %s at %lu on source #%d\n",
... ... @@ -268,11 +268,12 @@
268 268 * pps->info.echo(source, event, data);
269 269 */
270 270  
271   -void pps_event(int source, struct pps_ktime *ts, int event, void *data)
  271 +void pps_event(int source, struct pps_event_time *ts, int event, void *data)
272 272 {
273 273 struct pps_device *pps;
274 274 unsigned long flags;
275 275 int captured = 0;
  276 + struct pps_ktime ts_real;
276 277  
277 278 if ((event & (PPS_CAPTUREASSERT | PPS_CAPTURECLEAR)) == 0) {
278 279 printk(KERN_ERR "pps: unknown event (%x) for source %d\n",
279 280  
... ... @@ -284,9 +285,11 @@
284 285 if (!pps)
285 286 return;
286 287  
287   - pr_debug("PPS event on source %d at %llu.%06u\n",
288   - pps->id, (unsigned long long) ts->sec, ts->nsec);
  288 + pr_debug("PPS event on source %d at %ld.%09ld\n",
  289 + pps->id, ts->ts_real.tv_sec, ts->ts_real.tv_nsec);
289 290  
  291 + timespec_to_pps_ktime(&ts_real, ts->ts_real);
  292 +
290 293 spin_lock_irqsave(&pps->lock, flags);
291 294  
292 295 /* Must call the echo function? */
293 296  
... ... @@ -299,10 +302,11 @@
299 302 (pps->params.mode & PPS_CAPTUREASSERT)) {
300 303 /* We have to add an offset? */
301 304 if (pps->params.mode & PPS_OFFSETASSERT)
302   - pps_add_offset(ts, &pps->params.assert_off_tu);
  305 + pps_add_offset(&ts_real,
  306 + &pps->params.assert_off_tu);
303 307  
304 308 /* Save the time stamp */
305   - pps->assert_tu = *ts;
  309 + pps->assert_tu = ts_real;
306 310 pps->assert_sequence++;
307 311 pr_debug("capture assert seq #%u for source %d\n",
308 312 pps->assert_sequence, source);
309 313  
... ... @@ -313,10 +317,11 @@
313 317 (pps->params.mode & PPS_CAPTURECLEAR)) {
314 318 /* We have to add an offset? */
315 319 if (pps->params.mode & PPS_OFFSETCLEAR)
316   - pps_add_offset(ts, &pps->params.clear_off_tu);
  320 + pps_add_offset(&ts_real,
  321 + &pps->params.clear_off_tu);
317 322  
318 323 /* Save the time stamp */
319   - pps->clear_tu = *ts;
  324 + pps->clear_tu = ts_real;
320 325 pps->clear_sequence++;
321 326 pr_debug("capture clear seq #%u for source %d\n",
322 327 pps->clear_sequence, source);
include/linux/pps_kernel.h
... ... @@ -43,6 +43,10 @@
43 43 struct device *dev;
44 44 };
45 45  
  46 +struct pps_event_time {
  47 + struct timespec ts_real;
  48 +};
  49 +
46 50 /* The main struct */
47 51 struct pps_device {
48 52 struct pps_source_info info; /* PSS source info */
... ... @@ -88,7 +92,20 @@
88 92 extern void pps_unregister_source(int source);
89 93 extern int pps_register_cdev(struct pps_device *pps);
90 94 extern void pps_unregister_cdev(struct pps_device *pps);
91   -extern void pps_event(int source, struct pps_ktime *ts, int event, void *data);
  95 +extern void pps_event(int source, struct pps_event_time *ts, int event,
  96 + void *data);
  97 +
  98 +static inline void timespec_to_pps_ktime(struct pps_ktime *kt,
  99 + struct timespec ts)
  100 +{
  101 + kt->sec = ts.tv_sec;
  102 + kt->nsec = ts.tv_nsec;
  103 +}
  104 +
  105 +static inline void pps_get_ts(struct pps_event_time *ts)
  106 +{
  107 + getnstimeofday(&ts->ts_real);
  108 +}
92 109  
93 110 #endif /* LINUX_PPS_KERNEL_H */
include/linux/serial_core.h
... ... @@ -212,6 +212,7 @@
212 212 #include <linux/tty.h>
213 213 #include <linux/mutex.h>
214 214 #include <linux/sysrq.h>
  215 +#include <linux/pps_kernel.h>
215 216  
216 217 struct uart_port;
217 218 struct serial_struct;
218 219  
... ... @@ -528,10 +529,10 @@
528 529 struct uart_state *state = uport->state;
529 530 struct tty_port *port = &state->port;
530 531 struct tty_ldisc *ld = tty_ldisc_ref(port->tty);
531   - struct timespec ts;
  532 + struct pps_event_time ts;
532 533  
533 534 if (ld && ld->ops->dcd_change)
534   - getnstimeofday(&ts);
  535 + pps_get_ts(&ts);
535 536  
536 537 uport->icount.dcd++;
537 538 #ifdef CONFIG_HARD_PPS
include/linux/tty_ldisc.h
... ... @@ -101,7 +101,7 @@
101 101 * any pending driver I/O is completed.
102 102 *
103 103 * void (*dcd_change)(struct tty_struct *tty, unsigned int status,
104   - * struct timespec *ts)
  104 + * struct pps_event_time *ts)
105 105 *
106 106 * Tells the discipline that the DCD pin has changed its status and
107 107 * the relative timestamp. Pointer ts can be NULL.
... ... @@ -109,6 +109,7 @@
109 109  
110 110 #include <linux/fs.h>
111 111 #include <linux/wait.h>
  112 +#include <linux/pps_kernel.h>
112 113  
113 114 struct tty_ldisc_ops {
114 115 int magic;
... ... @@ -143,7 +144,7 @@
143 144 char *fp, int count);
144 145 void (*write_wakeup)(struct tty_struct *);
145 146 void (*dcd_change)(struct tty_struct *, unsigned int,
146   - struct timespec *);
  147 + struct pps_event_time *);
147 148  
148 149 struct module *owner;
149 150