netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Baolin Wang <baolin.wang@linaro.org>
To: richardcochran@gmail.com
Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
	john.stultz@linaro.com, tglx@linutronix.de, arnd@linaro.org,
	baolin.wang@linaro.org
Subject: [PATCH 1/4] ptp/chardev:Introduce another option to get/set time in ptp_clock_info structure
Date: Thu, 19 Mar 2015 13:45:06 +0800	[thread overview]
Message-ID: <1426743909-24335-2-git-send-email-baolin.wang@linaro.org> (raw)
In-Reply-To: <1426743909-24335-1-git-send-email-baolin.wang@linaro.org>

This patch introduces two options with "ktime_t" type to get/set time
in ptp_clock_info structure that will avoid breaking in the year 2038.

In ptp_chardev.c file, replace the gettime interface with getktime
interface using the "ktime_t" type to get the ptp clock time.

The patch's goal is to remove the original code using the "timespec" type,
and I expect to be done with that in the following merge window.

Signed-off-by: Baolin Wang <baolin.wang@linaro.org>
---
 drivers/ptp/ptp_chardev.c        |   27 ++++++++++++++++++---------
 include/linux/ptp_clock_kernel.h |    2 ++
 2 files changed, 20 insertions(+), 9 deletions(-)

diff --git a/drivers/ptp/ptp_chardev.c b/drivers/ptp/ptp_chardev.c
index f8a7609..4e14cc6 100644
--- a/drivers/ptp/ptp_chardev.c
+++ b/drivers/ptp/ptp_chardev.c
@@ -125,8 +125,10 @@ long ptp_ioctl(struct posix_clock *pc, unsigned int cmd, unsigned long arg)
 	struct ptp_clock_info *ops = ptp->info;
 	struct ptp_clock_time *pct;
 	struct timespec ts;
+	struct timespec64 ts64;
 	int enable, err = 0;
 	unsigned int i, pin_index;
+	ktime_t kt;
 
 	switch (cmd) {
 
@@ -197,18 +199,25 @@ long ptp_ioctl(struct posix_clock *pc, unsigned int cmd, unsigned long arg)
 		}
 		pct = &sysoff->ts[0];
 		for (i = 0; i < sysoff->n_samples; i++) {
-			getnstimeofday(&ts);
-			pct->sec = ts.tv_sec;
-			pct->nsec = ts.tv_nsec;
+			ktime_get_real_ts64(&ts64);
+			pct->sec = ts64.tv_sec;
+			pct->nsec = ts64.tv_nsec;
 			pct++;
-			ptp->info->gettime(ptp->info, &ts);
-			pct->sec = ts.tv_sec;
-			pct->nsec = ts.tv_nsec;
+			if (ptp->info->getktime) {
+				ptp->info->getktime(ptp->info, &kt);
+				ts64 = ktime_to_timespec64(kt);
+				pct->sec =  ts64.tv_sec;
+				pct->nsec = ts64.tv_nsec;
+			} else {
+				ptp->info->gettime(ptp->info, &ts);
+				pct->sec = ts.tv_sec;
+				pct->nsec = ts.tv_nsec;
+			}
 			pct++;
 		}
-		getnstimeofday(&ts);
-		pct->sec = ts.tv_sec;
-		pct->nsec = ts.tv_nsec;
+		ktime_get_real_ts64(&ts64);
+		pct->sec = ts64.tv_sec;
+		pct->nsec = ts64.tv_nsec;
 		if (copy_to_user((void __user *)arg, sysoff, sizeof(*sysoff)))
 			err = -EFAULT;
 		break;
diff --git a/include/linux/ptp_clock_kernel.h b/include/linux/ptp_clock_kernel.h
index 0d8ff3f..86decc2 100644
--- a/include/linux/ptp_clock_kernel.h
+++ b/include/linux/ptp_clock_kernel.h
@@ -105,7 +105,9 @@ struct ptp_clock_info {
 	int (*adjfreq)(struct ptp_clock_info *ptp, s32 delta);
 	int (*adjtime)(struct ptp_clock_info *ptp, s64 delta);
 	int (*gettime)(struct ptp_clock_info *ptp, struct timespec *ts);
+	int (*getktime)(struct ptp_clock_info *ptp, ktime_t *kt);
 	int (*settime)(struct ptp_clock_info *ptp, const struct timespec *ts);
+	int (*setktime)(struct ptp_clock_info *ptp, ktime_t kt);
 	int (*enable)(struct ptp_clock_info *ptp,
 		      struct ptp_clock_request *request, int on);
 	int (*verify)(struct ptp_clock_info *ptp, unsigned int pin,
-- 
1.7.9.5

  reply	other threads:[~2015-03-19  5:45 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-03-19  5:45 [PATCH 0/4] Introduce another options to set/get time with "ktime_t" type Baolin Wang
2015-03-19  5:45 ` Baolin Wang [this message]
2015-03-19  7:48   ` [PATCH 1/4] ptp/chardev:Introduce another option to get/set time in ptp_clock_info structure Richard Cochran
2015-03-19  5:45 ` [PATCH 2/4] ptp/clcok:Introduce the setktime/getktime interfaces with "ktime_t" type Baolin Wang
2015-03-19  7:54   ` Richard Cochran
     [not found]     ` <CAMz4kuKyDFCqd-LfoSKJf+tkXdzzLwtPJdp-nF6NbKU8W5HHpQ@mail.gmail.com>
2015-03-20  6:26       ` Richard Cochran
2015-03-20 13:43         ` Arnd Bergmann
2015-03-20 16:49           ` Richard Cochran
2015-03-21  1:16             ` Arnd Bergmann
2015-03-21  7:24               ` Richard Cochran
2015-03-21 16:52                 ` Richard Cochran
2015-03-22  2:47                 ` Arnd Bergmann
2015-03-21  9:21             ` Richard Cochran
2015-03-19  5:45 ` [PATCH 3/4] ptp/pch:Replace timespec with ktime_t in ptp_pch.c Baolin Wang
2015-03-19  5:45 ` [PATCH 4/4] ptp/ixp46x:Replace timespec with ktime_t in ptp_ixp46x.c Baolin Wang

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1426743909-24335-2-git-send-email-baolin.wang@linaro.org \
    --to=baolin.wang@linaro.org \
    --cc=arnd@linaro.org \
    --cc=john.stultz@linaro.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=richardcochran@gmail.com \
    --cc=tglx@linutronix.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).