From patchwork Tue Jan 16 17:14:38 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 124752 Delivered-To: patch@linaro.org Received: by 10.46.64.148 with SMTP id r20csp1084465lje; Tue, 16 Jan 2018 09:15:02 -0800 (PST) X-Google-Smtp-Source: ACJfBos/hCHKic05k+IV8BkiRO70wa8mLeI8uppr0GuBid8L7TnapgjmOo4FwYgoHazVkcArHJMO X-Received: by 10.84.210.195 with SMTP id a61mr5465509pli.335.1516122902379; Tue, 16 Jan 2018 09:15:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1516122902; cv=none; d=google.com; s=arc-20160816; b=OICq2okQ+Z1SwqKUK3HYNOGGuiVmkfm+vqv25SOvBJGhJW1+uekh+smBdt+QDRnUF+ AeHsj/UR6UU/A8xxwn/+dmgE/T4HEDozonJOgT4Nrwr/dobRbMyHIXzlPZlzlAHj0rEm pnMmrnCB9jdAFfv7Xsfi5bkVKngpBhRLSIYpH/RJLQ9GncbaN77s3NeyBoHUscRL++6G SbAMHFfBXz5QwwpQPzklP9DWr5gPQLqQEVgKBXEWk5ocICnFMVfBGhNHA44D23CXk0mO AuhLEVfbgnzW6xkpsze1J3ocp7BvTCaA3/SFubMAFRZfq1wwWpdmWe+HXRxFwMVgPiXg QYZg== 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=KDDPEqY65ZDA+t7CMuofDTDjGQLaAYkFECbf62lWsgk=; b=XOEOL/h8D3KJjEe5LoL0Ht7xJcBSFlRGOkSbW/a4gYTQVzLEI9Nf9qkByz6domzQSb aAB4d3U92TBvrGqtcH3uEDfe+bq+VxpdELw8/493DC5y+1PBcraIQOhDL8uxZjyunfo4 qZkJ9JiZ2+LYOqoT8JaZkHQzhBvIBTnrfTtlwlaRQ11TLM9g9CxkTWcVP8/8oLuW8gkH k0KNGNTp3w/7GvUrh+0czDLrWRac/4JXPDBT3BM0RWg1SHxYPq98xgN+nqDKZ2wOA4+f NhlG/fz3FVJnBt8AJKYSCyBUjXGpLNv+uqzTdr8MCk72h79F1p736/BwpMSTMYUfOJS3 E60Q== 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 a33si2308149pla.546.2018.01.16.09.15.02; Tue, 16 Jan 2018 09:15:02 -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 S1751394AbeAPRPA (ORCPT + 28 others); Tue, 16 Jan 2018 12:15:00 -0500 Received: from mout.kundenserver.de ([212.227.126.187]:61013 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750925AbeAPRO6 (ORCPT ); Tue, 16 Jan 2018 12:14:58 -0500 Received: from wuerfel.lan ([95.208.111.237]) by mrelayeu.kundenserver.de (mreue003 [212.227.15.129]) with ESMTPA (Nemesis) id 0Lvx61-1eudZy1Hqf-017iED; Tue, 16 Jan 2018 18:14:55 +0100 From: Arnd Bergmann To: Andrew Morton , Rodolfo Giometti Cc: y2038@lists.linaro.org, Arnd Bergmann , linux-kernel@vger.kernel.org Subject: [PATCH] pps: parport: use timespec64 instead of timespec Date: Tue, 16 Jan 2018 18:14:38 +0100 Message-Id: <20180116171451.3095620-1-arnd@arndb.de> X-Mailer: git-send-email 2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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. Acked-by: Rodolfo Giometti Signed-off-by: Arnd Bergmann --- Sent on Nov 28 originally, got an Ack, but nobody picked it up. Andrew, it seems you handled some pps generator patches in the past, can you take this one through -mm? --- drivers/pps/generators/pps_gen_parport.c | 40 ++++++++++++++++---------------- 1 file changed, 20 insertions(+), 20 deletions(-) -- 2.9.0 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),