aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/pps
diff options
context:
space:
mode:
authorArnd Bergmann <arnd@arndb.de>2018-02-06 18:40:21 -0500
committerLinus Torvalds <torvalds@linux-foundation.org>2018-02-06 21:32:46 -0500
commit28f3a488ed83ac4a01406490941a6486806d1333 (patch)
tree7f6df93c01d2c71460d3d4ac55af6f0913c53918 /drivers/pps
parent2ee0826085d1c0281cb60c1f4bc3e0c27efeedc3 (diff)
pps: parport: use timespec64 instead of timespec
getnstimeofday() is deprecated, so I'm converting this to use ktime_get_real_ts64() as a safe replacement. I considered using ktime_get_real() instead, but since the algorithm here depends on the exact timing, I decided to introduce fewer changes and leave the code that determines the nanoseconds since the last seconds wrap untouched. It's not entirely clear to me whether we should also change the time base to CLOCK_BOOTTIME or CLOCK_TAI. With boottime, we would be independent of changes due to settimeofday() and only see the speed adjustment from the upstream clock source, with the downside of having the signal be at an arbirary offset from the start of the UTC second signal. With CLOCK_TAI, we would use the same offset from the UTC second as before and still suffer from settimeofday() adjustments, but would be less confused during leap seconds. Both boottime and tai only offer usable (i.e. avoiding ktime_t to timespec64 conversion) interfaces for ktime_t though, so either way, changing it wouldn't take significantly more work. CLOCK_MONOTONIC could be used with ktime_get_ts64(), but would lose synchronization across a suspend/resume cycle, which seems worse. Link: http://lkml.kernel.org/r/20180116171451.3095620-1-arnd@arndb.de Signed-off-by: Arnd Bergmann <arnd@arndb.de> Acked-by: Rodolfo Giometti <giometti@enneenne.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'drivers/pps')
-rw-r--r--drivers/pps/generators/pps_gen_parport.c40
1 files changed, 20 insertions, 20 deletions
diff --git a/drivers/pps/generators/pps_gen_parport.c b/drivers/pps/generators/pps_gen_parport.c
index dcd39fba6ddd..51cfde6afffd 100644
--- a/drivers/pps/generators/pps_gen_parport.c
+++ b/drivers/pps/generators/pps_gen_parport.c
@@ -70,7 +70,7 @@ static long hrtimer_error = SAFETY_INTERVAL;
70/* the kernel hrtimer event */ 70/* the kernel hrtimer event */
71static enum hrtimer_restart hrtimer_event(struct hrtimer *timer) 71static enum hrtimer_restart hrtimer_event(struct hrtimer *timer)
72{ 72{
73 struct timespec expire_time, ts1, ts2, ts3, dts; 73 struct timespec64 expire_time, ts1, ts2, ts3, dts;
74 struct pps_generator_pp *dev; 74 struct pps_generator_pp *dev;
75 struct parport *port; 75 struct parport *port;
76 long lim, delta; 76 long lim, delta;
@@ -78,7 +78,7 @@ static enum hrtimer_restart hrtimer_event(struct hrtimer *timer)
78 78
79 /* We have to disable interrupts here. The idea is to prevent 79 /* We have to disable interrupts here. The idea is to prevent
80 * other interrupts on the same processor to introduce random 80 * other interrupts on the same processor to introduce random
81 * lags while polling the clock. getnstimeofday() takes <1us on 81 * lags while polling the clock. ktime_get_real_ts64() takes <1us on
82 * most machines while other interrupt handlers can take much 82 * most machines while other interrupt handlers can take much
83 * more potentially. 83 * more potentially.
84 * 84 *
@@ -88,22 +88,22 @@ static enum hrtimer_restart hrtimer_event(struct hrtimer *timer)
88 local_irq_save(flags); 88 local_irq_save(flags);
89 89
90 /* first of all we get the time stamp... */ 90 /* first of all we get the time stamp... */
91 getnstimeofday(&ts1); 91 ktime_get_real_ts64(&ts1);
92 expire_time = ktime_to_timespec(hrtimer_get_softexpires(timer)); 92 expire_time = ktime_to_timespec64(hrtimer_get_softexpires(timer));
93 dev = container_of(timer, struct pps_generator_pp, timer); 93 dev = container_of(timer, struct pps_generator_pp, timer);
94 lim = NSEC_PER_SEC - send_delay - dev->port_write_time; 94 lim = NSEC_PER_SEC - send_delay - dev->port_write_time;
95 95
96 /* check if we are late */ 96 /* check if we are late */
97 if (expire_time.tv_sec != ts1.tv_sec || ts1.tv_nsec > lim) { 97 if (expire_time.tv_sec != ts1.tv_sec || ts1.tv_nsec > lim) {
98 local_irq_restore(flags); 98 local_irq_restore(flags);
99 pr_err("we are late this time %ld.%09ld\n", 99 pr_err("we are late this time %lld.%09ld\n",
100 ts1.tv_sec, ts1.tv_nsec); 100 (s64)ts1.tv_sec, ts1.tv_nsec);
101 goto done; 101 goto done;
102 } 102 }
103 103
104 /* busy loop until the time is right for an assert edge */ 104 /* busy loop until the time is right for an assert edge */
105 do { 105 do {
106 getnstimeofday(&ts2); 106 ktime_get_real_ts64(&ts2);
107 } while (expire_time.tv_sec == ts2.tv_sec && ts2.tv_nsec < lim); 107 } while (expire_time.tv_sec == ts2.tv_sec && ts2.tv_nsec < lim);
108 108
109 /* set the signal */ 109 /* set the signal */
@@ -113,25 +113,25 @@ static enum hrtimer_restart hrtimer_event(struct hrtimer *timer)
113 /* busy loop until the time is right for a clear edge */ 113 /* busy loop until the time is right for a clear edge */
114 lim = NSEC_PER_SEC - dev->port_write_time; 114 lim = NSEC_PER_SEC - dev->port_write_time;
115 do { 115 do {
116 getnstimeofday(&ts2); 116 ktime_get_real_ts64(&ts2);
117 } while (expire_time.tv_sec == ts2.tv_sec && ts2.tv_nsec < lim); 117 } while (expire_time.tv_sec == ts2.tv_sec && ts2.tv_nsec < lim);
118 118
119 /* unset the signal */ 119 /* unset the signal */
120 port->ops->write_control(port, NO_SIGNAL); 120 port->ops->write_control(port, NO_SIGNAL);
121 121
122 getnstimeofday(&ts3); 122 ktime_get_real_ts64(&ts3);
123 123
124 local_irq_restore(flags); 124 local_irq_restore(flags);
125 125
126 /* update calibrated port write time */ 126 /* update calibrated port write time */
127 dts = timespec_sub(ts3, ts2); 127 dts = timespec64_sub(ts3, ts2);
128 dev->port_write_time = 128 dev->port_write_time =
129 (dev->port_write_time + timespec_to_ns(&dts)) >> 1; 129 (dev->port_write_time + timespec64_to_ns(&dts)) >> 1;
130 130
131done: 131done:
132 /* update calibrated hrtimer error */ 132 /* update calibrated hrtimer error */
133 dts = timespec_sub(ts1, expire_time); 133 dts = timespec64_sub(ts1, expire_time);
134 delta = timespec_to_ns(&dts); 134 delta = timespec64_to_ns(&dts);
135 /* If the new error value is bigger then the old, use the new 135 /* If the new error value is bigger then the old, use the new
136 * value, if not then slowly move towards the new value. This 136 * value, if not then slowly move towards the new value. This
137 * way it should be safe in bad conditions and efficient in 137 * way it should be safe in bad conditions and efficient in
@@ -161,17 +161,17 @@ static void calibrate_port(struct pps_generator_pp *dev)
161 long acc = 0; 161 long acc = 0;
162 162
163 for (i = 0; i < (1 << PORT_NTESTS_SHIFT); i++) { 163 for (i = 0; i < (1 << PORT_NTESTS_SHIFT); i++) {
164 struct timespec a, b; 164 struct timespec64 a, b;
165 unsigned long irq_flags; 165 unsigned long irq_flags;
166 166
167 local_irq_save(irq_flags); 167 local_irq_save(irq_flags);
168 getnstimeofday(&a); 168 ktime_get_real_ts64(&a);
169 port->ops->write_control(port, NO_SIGNAL); 169 port->ops->write_control(port, NO_SIGNAL);
170 getnstimeofday(&b); 170 ktime_get_real_ts64(&b);
171 local_irq_restore(irq_flags); 171 local_irq_restore(irq_flags);
172 172
173 b = timespec_sub(b, a); 173 b = timespec64_sub(b, a);
174 acc += timespec_to_ns(&b); 174 acc += timespec64_to_ns(&b);
175 } 175 }
176 176
177 dev->port_write_time = acc >> PORT_NTESTS_SHIFT; 177 dev->port_write_time = acc >> PORT_NTESTS_SHIFT;
@@ -180,9 +180,9 @@ static void calibrate_port(struct pps_generator_pp *dev)
180 180
181static inline ktime_t next_intr_time(struct pps_generator_pp *dev) 181static inline ktime_t next_intr_time(struct pps_generator_pp *dev)
182{ 182{
183 struct timespec ts; 183 struct timespec64 ts;
184 184
185 getnstimeofday(&ts); 185 ktime_get_real_ts64(&ts);
186 186
187 return ktime_set(ts.tv_sec + 187 return ktime_set(ts.tv_sec +
188 ((ts.tv_nsec > 990 * NSEC_PER_MSEC) ? 1 : 0), 188 ((ts.tv_nsec > 990 * NSEC_PER_MSEC) ? 1 : 0),