Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Alexander Gordeev and committed by
Linus Torvalds
6f4229b5 3003d55b

+45 -31
+2 -7
drivers/pps/clients/pps-ktimer.c
··· 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
+6 -12
drivers/pps/clients/pps-ldisc.c
··· 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",
+12 -7
drivers/pps/kapi.c
··· 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", ··· 285 284 if (!pps) 286 285 return; 287 286 288 - pr_debug("PPS event on source %d at %llu.%06u\n", 289 - pps->id, (unsigned long long) ts->sec, ts->nsec); 287 + pr_debug("PPS event on source %d at %ld.%09ld\n", 288 + pps->id, ts->ts_real.tv_sec, ts->ts_real.tv_nsec); 289 + 290 + timespec_to_pps_ktime(&ts_real, ts->ts_real); 290 291 291 292 spin_lock_irqsave(&pps->lock, flags); 292 293 ··· 302 299 (pps->params.mode & PPS_CAPTUREASSERT)) { 303 300 /* We have to add an offset? */ 304 301 if (pps->params.mode & PPS_OFFSETASSERT) 305 - pps_add_offset(ts, &pps->params.assert_off_tu); 302 + pps_add_offset(&ts_real, 303 + &pps->params.assert_off_tu); 306 304 307 305 /* Save the time stamp */ 308 - pps->assert_tu = *ts; 306 + pps->assert_tu = ts_real; 309 307 pps->assert_sequence++; 310 308 pr_debug("capture assert seq #%u for source %d\n", 311 309 pps->assert_sequence, source); ··· 317 313 (pps->params.mode & PPS_CAPTURECLEAR)) { 318 314 /* We have to add an offset? */ 319 315 if (pps->params.mode & PPS_OFFSETCLEAR) 320 - pps_add_offset(ts, &pps->params.clear_off_tu); 316 + pps_add_offset(&ts_real, 317 + &pps->params.clear_off_tu); 321 318 322 319 /* Save the time stamp */ 323 - pps->clear_tu = *ts; 320 + pps->clear_tu = ts_real; 324 321 pps->clear_sequence++; 325 322 pr_debug("capture clear seq #%u for source %d\n", 326 323 pps->clear_sequence, source);
+19 -1
include/linux/pps_kernel.h
··· 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 */ ··· 92 88 extern void pps_unregister_source(int source); 93 89 extern int pps_register_cdev(struct pps_device *pps); 94 90 extern void pps_unregister_cdev(struct pps_device *pps); 95 - extern void pps_event(int source, struct pps_ktime *ts, int event, void *data); 91 + extern void pps_event(int source, struct pps_event_time *ts, int event, 92 + void *data); 93 + 94 + static inline void timespec_to_pps_ktime(struct pps_ktime *kt, 95 + struct timespec ts) 96 + { 97 + kt->sec = ts.tv_sec; 98 + kt->nsec = ts.tv_nsec; 99 + } 100 + 101 + static inline void pps_get_ts(struct pps_event_time *ts) 102 + { 103 + getnstimeofday(&ts->ts_real); 104 + } 96 105 97 106 #endif /* LINUX_PPS_KERNEL_H */ 107 +
+3 -2
include/linux/serial_core.h
··· 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; ··· 529 528 struct uart_state *state = uport->state; 530 529 struct tty_port *port = &state->port; 531 530 struct tty_ldisc *ld = tty_ldisc_ref(port->tty); 532 - struct timespec ts; 531 + struct pps_event_time ts; 533 532 534 533 if (ld && ld->ops->dcd_change) 535 - getnstimeofday(&ts); 534 + pps_get_ts(&ts); 536 535 537 536 uport->icount.dcd++; 538 537 #ifdef CONFIG_HARD_PPS
+3 -2
include/linux/tty_ldisc.h
··· 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 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; ··· 144 143 char *fp, int count); 145 144 void (*write_wakeup)(struct tty_struct *); 146 145 void (*dcd_change)(struct tty_struct *, unsigned int, 147 - struct timespec *); 146 + struct pps_event_time *); 148 147 149 148 struct module *owner; 150 149