From patchwork Mon Nov 27 11:43:49 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 119683 Delivered-To: patch@linaro.org Received: by 10.140.22.227 with SMTP id 90csp133535qgn; Mon, 27 Nov 2017 03:45:20 -0800 (PST) X-Google-Smtp-Source: AGs4zMZOa1xwT2bc0xr+BzMaFfsswpx+D6hUfcQgX9bn3ZTg+u2QSN7R50lvoHB1h36Bw3yv6ozj X-Received: by 10.84.171.195 with SMTP id l61mr26254533plb.129.1511783120204; Mon, 27 Nov 2017 03:45:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1511783120; cv=none; d=google.com; s=arc-20160816; b=lGXIHI4T9kBL3eZRpDgSyVpIL7fGlLPY42BJ/u1c5rLXSiROaFekne4eGUNvunklJN JDJn4mSBfF9WhkvDcbCvoL3rkNcv38iIPusA5Ias8PES1YsdZSvz04gRjgTnqyyFPf3+ gtTeh9+fsNLEyqnqcMQcapKzA3AtzXhFPfKTV5JZwdNmiStP1tORIBk7vq3Lv41vB5y1 GtBcNuA8kefSonvt8SvdKJNMB30g/MasejQ8Fqg3J+wb38QLq+z98xqIrlED8MbZYH9T PJnEGPXtCYOnrPe0wyTa/QrLmCrG7orpWv9HHIkPDYc5NdGl28HHKzVDYrc58DMegNj6 t2DQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :arc-authentication-results; bh=adzG+Rd1kSvAUOuBwxAyRWcZ2PmHKzAnC3ObtxSaCt8=; b=tLXGxEh+2C4kmqzR+S9kW7cK3t9UvMT//fFf96fQW14sSnzUmrnX9F2uXB7Vkso4OF rlPbSWrXodeK/gpwRCCGDrii6roOMHLgnrOH+rLTEfALyGwgtXxC8GCmyMcxvFsAAhog knxd2IM+7EFbekb3dwohJVIIlb4TnF1ICTLS5leSxuIY3JJX6B8UG97nwH++JeBWiSla dx7itNR/T8flduF+AflgfQzEtLsejNeZodKQ2ro4zqUUa80cIV4wBSR8EAEQHxFtRzQ2 tZlcbtYLpwavRjiC9CtRsRXuc6Kew5pnyB3n/T3CalM2YxbEA/3X3WnxD/wYagX/S85g 8o/w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f23si23802542plk.488.2017.11.27.03.45.19; Mon, 27 Nov 2017 03:45:20 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751900AbdK0LpS (ORCPT + 28 others); Mon, 27 Nov 2017 06:45:18 -0500 Received: from mout.kundenserver.de ([212.227.126.187]:63686 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751658AbdK0LpQ (ORCPT ); Mon, 27 Nov 2017 06:45:16 -0500 Received: from wuerfel.lan ([109.193.157.232]) by mrelayeu.kundenserver.de (mreue001 [212.227.15.129]) with ESMTPA (Nemesis) id 0Mbour-1ebeC22jJ7-00J4Tk; Mon, 27 Nov 2017 12:44:07 +0100 From: Arnd Bergmann To: Rodolfo Giometti Cc: y2038@lists.linaro.org, Arnd Bergmann , linux-kernel@vger.kernel.org Subject: [PATCH] pps: parport: use timespec64 instead of timespec Date: Mon, 27 Nov 2017 12:43:49 +0100 Message-Id: <20171127114403.2599836-1-arnd@arndb.de> X-Mailer: git-send-email 2.9.0 X-Provags-ID: V03:K0:7mf1OvGeiWbzY+IFnS/qmvzzxN15EcOTDk7Tq050JGvoJ3d950v Q+8Hww2Pj5HjHNaVHDBCus0IMml3+QOCGoAeSo3S9TCEY4iVUaq2DouKvRFez7LG0X7ZbK1 3qLDABkFPHXzEEsc4Ut+nl1oXoRbExUhykZYSyn+fX4/KQTR2RQQsbhdgUR9CsMVNLNLM7C C1kg5CSP9dvWw5Gimd6DQ== X-UI-Out-Filterresults: notjunk:1; V01:K0:Xo/KdUHpOg0=:kWDo2fcPj67r29SfHOrfZT W5BI1DwzKftVk8I2UaRSLmB49wqzfeFJEkcVJNO6kmscdbAiRxALSmyTwai/psZKzF14BDUYs HS+duT2FF0Di3CpYQhMZIhrGWUswEWyarZ31w+CZlI5TZli/R4aGAigPSNilQGti+HRVwDNXn vKMIzQ5mIWjMNQk87haV5UAhMSNxnBegrvDXiCjOS16PKbobHTa4NiGRIIgbO452gW+qAgHLz iunBLQVXsgsZGj0pHyY7hqcfQkMt/9ppnYoYpRCgpfLEJ4DW5RZuNbYaxSV4YpmNB8FKjUSVM AWCr/DqMRM1G9ypr02hs60fJYeYlyWZh14EtJrNEEq5KYbHFMtZgoiLymGD1c5OLXlJqD2YTI 6RfWvXATDYE3uIKVjTq2MVGLHCP70AdmHAW37CkcLQXPafBxxYXk+fnB0oYg+FnPqoNDpEKeL P4MfnW0R5bl6zyiSi6gCqVm/VQ826FL+eVSddk89b5QT12atESNH+pNO/pIvyltC/aKxAoM5f uLATfsV92fTyA6UMa+QQrzDBstht0vRM2+Pz+RD13cQHYINw9Ij7ddYjf6m/bJERLXOYSYtsu WU2+0jBGVuLTNZrTIOW2II+8CgY3r2lNQcXCpqE0Z79WK4H11FG/MaiYSYMTJhLoDT5sBOBlm p6m2s3v6wp43ZPFFtE6ydDIaQlFBi8ye1kRDKxVh3An1H/bVB8M+no0XkUqS83yyPks4Arzeo seiC6Tu+77uSLBZbg94dyagMx6iodP8kYtY5FQ== Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. Signed-off-by: Arnd Bergmann --- drivers/pps/generators/pps_gen_parport.c | 40 ++++++++++++++++---------------- 1 file changed, 20 insertions(+), 20 deletions(-) -- 2.9.0 Acked-by: Rodolfo Giometti 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; /* the kernel hrtimer event */ static enum hrtimer_restart hrtimer_event(struct hrtimer *timer) { - struct timespec expire_time, ts1, ts2, ts3, dts; + struct timespec64 expire_time, ts1, ts2, ts3, dts; struct pps_generator_pp *dev; struct parport *port; long lim, delta; @@ -78,7 +78,7 @@ static enum hrtimer_restart hrtimer_event(struct hrtimer *timer) /* We have to disable interrupts here. The idea is to prevent * other interrupts on the same processor to introduce random - * lags while polling the clock. getnstimeofday() takes <1us on + * lags while polling the clock. ktime_get_real_ts64() takes <1us on * most machines while other interrupt handlers can take much * more potentially. * @@ -88,22 +88,22 @@ static enum hrtimer_restart hrtimer_event(struct hrtimer *timer) local_irq_save(flags); /* first of all we get the time stamp... */ - getnstimeofday(&ts1); - expire_time = ktime_to_timespec(hrtimer_get_softexpires(timer)); + ktime_get_real_ts64(&ts1); + expire_time = ktime_to_timespec64(hrtimer_get_softexpires(timer)); dev = container_of(timer, struct pps_generator_pp, timer); lim = NSEC_PER_SEC - send_delay - dev->port_write_time; /* check if we are late */ if (expire_time.tv_sec != ts1.tv_sec || ts1.tv_nsec > lim) { local_irq_restore(flags); - pr_err("we are late this time %ld.%09ld\n", - ts1.tv_sec, ts1.tv_nsec); + pr_err("we are late this time %lld.%09ld\n", + (s64)ts1.tv_sec, ts1.tv_nsec); goto done; } /* busy loop until the time is right for an assert edge */ do { - getnstimeofday(&ts2); + ktime_get_real_ts64(&ts2); } while (expire_time.tv_sec == ts2.tv_sec && ts2.tv_nsec < lim); /* set the signal */ @@ -113,25 +113,25 @@ static enum hrtimer_restart hrtimer_event(struct hrtimer *timer) /* busy loop until the time is right for a clear edge */ lim = NSEC_PER_SEC - dev->port_write_time; do { - getnstimeofday(&ts2); + ktime_get_real_ts64(&ts2); } while (expire_time.tv_sec == ts2.tv_sec && ts2.tv_nsec < lim); /* unset the signal */ port->ops->write_control(port, NO_SIGNAL); - getnstimeofday(&ts3); + ktime_get_real_ts64(&ts3); local_irq_restore(flags); /* update calibrated port write time */ - dts = timespec_sub(ts3, ts2); + dts = timespec64_sub(ts3, ts2); dev->port_write_time = - (dev->port_write_time + timespec_to_ns(&dts)) >> 1; + (dev->port_write_time + timespec64_to_ns(&dts)) >> 1; done: /* update calibrated hrtimer error */ - dts = timespec_sub(ts1, expire_time); - delta = timespec_to_ns(&dts); + dts = timespec64_sub(ts1, expire_time); + delta = timespec64_to_ns(&dts); /* If the new error value is bigger then the old, use the new * value, if not then slowly move towards the new value. This * way it should be safe in bad conditions and efficient in @@ -161,17 +161,17 @@ static void calibrate_port(struct pps_generator_pp *dev) long acc = 0; for (i = 0; i < (1 << PORT_NTESTS_SHIFT); i++) { - struct timespec a, b; + struct timespec64 a, b; unsigned long irq_flags; local_irq_save(irq_flags); - getnstimeofday(&a); + ktime_get_real_ts64(&a); port->ops->write_control(port, NO_SIGNAL); - getnstimeofday(&b); + ktime_get_real_ts64(&b); local_irq_restore(irq_flags); - b = timespec_sub(b, a); - acc += timespec_to_ns(&b); + b = timespec64_sub(b, a); + acc += timespec64_to_ns(&b); } dev->port_write_time = acc >> PORT_NTESTS_SHIFT; @@ -180,9 +180,9 @@ static void calibrate_port(struct pps_generator_pp *dev) static inline ktime_t next_intr_time(struct pps_generator_pp *dev) { - struct timespec ts; + struct timespec64 ts; - getnstimeofday(&ts); + ktime_get_real_ts64(&ts); return ktime_set(ts.tv_sec + ((ts.tv_nsec > 990 * NSEC_PER_MSEC) ? 1 : 0),