All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] Staging: fbtbt: Replace timespec with timespec64
@ 2015-09-29 15:17 Ksenija Stanojevic
  2015-09-29 15:41 ` [Y2038] " Arnd Bergmann
  0 siblings, 1 reply; 2+ messages in thread
From: Ksenija Stanojevic @ 2015-09-29 15:17 UTC (permalink / raw)
  To: outreachy-kernel; +Cc: y2038, Ksenija Stanojevic

struct timespec will overflow in year 2038, so replace it with
timespec64. And replace functions that use struct timespec,
timespec_sub with timespec64_sub and getnstimeofday with
getnstimeofday64. Also use parameters to convert the timespec64 values
instead of hard code.

Signed-off-by: Ksenija Stanojevic <ksenija.stanojevic@gmail.com>
---
 drivers/staging/fbtft/fbtft-core.c | 26 +++++++++++++-------------
 drivers/staging/fbtft/fbtft.h      |  2 +-
 2 files changed, 14 insertions(+), 14 deletions(-)

diff --git a/drivers/staging/fbtft/fbtft-core.c b/drivers/staging/fbtft/fbtft-core.c
index 23392eb..3e4eeac 100644
--- a/drivers/staging/fbtft/fbtft-core.c
+++ b/drivers/staging/fbtft/fbtft-core.c
@@ -365,16 +365,16 @@ static void fbtft_update_display(struct fbtft_par *par, unsigned start_line,
 				 unsigned end_line)
 {
 	size_t offset, len;
-	struct timespec ts_start, ts_end, ts_fps, ts_duration;
+	struct timespec64 ts_start, ts_end, ts_fps, ts_duration;
 	long fps_ms, fps_us, duration_ms, duration_us;
-	long fps, throughput;
+	long  long fps, throughput;
 	bool timeit = false;
 	int ret = 0;
 
 	if (unlikely(par->debug & (DEBUG_TIME_FIRST_UPDATE | DEBUG_TIME_EACH_UPDATE))) {
 		if ((par->debug & DEBUG_TIME_EACH_UPDATE) ||
 				((par->debug & DEBUG_TIME_FIRST_UPDATE) && !par->first_update_done)) {
-			getnstimeofday(&ts_start);
+			getnstimeofday64(&ts_start);
 			timeit = true;
 		}
 	}
@@ -411,28 +411,28 @@ static void fbtft_update_display(struct fbtft_par *par, unsigned start_line,
 			__func__);
 
 	if (unlikely(timeit)) {
-		getnstimeofday(&ts_end);
+		getnstimeofday64(&ts_end);
 		if (par->update_time.tv_nsec == 0 && par->update_time.tv_sec == 0) {
 			par->update_time.tv_sec = ts_start.tv_sec;
 			par->update_time.tv_nsec = ts_start.tv_nsec;
 		}
-		ts_fps = timespec_sub(ts_start, par->update_time);
+		ts_fps = timespec64_sub(ts_start, par->update_time);
 		par->update_time.tv_sec = ts_start.tv_sec;
 		par->update_time.tv_nsec = ts_start.tv_nsec;
-		fps_ms = (ts_fps.tv_sec * 1000) + ((ts_fps.tv_nsec / 1000000) % 1000);
-		fps_us = (ts_fps.tv_nsec / 1000) % 1000;
-		fps = fps_ms * 1000 + fps_us;
+		fps_ms = (ts_fps.tv_sec * MSEC_PER_SEC) + (ts_fps.tv_nsec / NSEC_PER_MSEC);
+		fps_us = ts_fps.tv_nsec / NSEC_PER_USEC;
+		fps = fps_ms * USEC_PER_MSEC + fps_us;
 		fps = fps ? 1000000 / fps : 0;
 
-		ts_duration = timespec_sub(ts_end, ts_start);
-		duration_ms = (ts_duration.tv_sec * 1000) + ((ts_duration.tv_nsec / 1000000) % 1000);
-		duration_us = (ts_duration.tv_nsec / 1000) % 1000;
-		throughput = duration_ms * 1000 + duration_us;
+		ts_duration = timespec64_sub(ts_end, ts_start);
+		duration_ms = (ts_duration.tv_sec * MSEC_PER_SEC) + (ts_duration.tv_nsec / NSEC_PER_MSEC);
+		duration_us = ts_duration.tv_nsec / NSEC_PER_USEC;
+		throughput = duration_ms * USEC_PER_MSEC + duration_us;
 		throughput = throughput ? (len * 1000) / throughput : 0;
 		throughput = throughput * 1000 / 1024;
 
 		dev_info(par->info->device,
-			"Display update: %ld kB/s (%ld.%.3ld ms), fps=%ld (%ld.%.3ld ms)\n",
+			"Display update: %lld kB/s (%ld.%.3ld ms), fps=%lld (%ld.%.3ld ms)\n",
 			throughput, duration_ms, duration_us,
 			fps, fps_ms, fps_us);
 		par->first_update_done = true;
diff --git a/drivers/staging/fbtft/fbtft.h b/drivers/staging/fbtft/fbtft.h
index 7e9a506..bf4c358 100644
--- a/drivers/staging/fbtft/fbtft.h
+++ b/drivers/staging/fbtft/fbtft.h
@@ -251,7 +251,7 @@ struct fbtft_par {
 	} gamma;
 	unsigned long debug;
 	bool first_update_done;
-	struct timespec update_time;
+	struct timespec64 update_time;
 	bool bgr;
 	void *extra;
 };
-- 
1.9.1



^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [Y2038] [PATCH] Staging: fbtbt: Replace timespec with timespec64
  2015-09-29 15:17 [PATCH] Staging: fbtbt: Replace timespec with timespec64 Ksenija Stanojevic
@ 2015-09-29 15:41 ` Arnd Bergmann
  0 siblings, 0 replies; 2+ messages in thread
From: Arnd Bergmann @ 2015-09-29 15:41 UTC (permalink / raw)
  To: y2038; +Cc: Ksenija Stanojevic, outreachy-kernel

On Tuesday 29 September 2015 17:17:35 Ksenija Stanojevic wrote:
> struct timespec will overflow in year 2038, so replace it with
> timespec64. And replace functions that use struct timespec,
> timespec_sub with timespec64_sub and getnstimeofday with
> getnstimeofday64. Also use parameters to convert the timespec64 values
> instead of hard code.
> 
> Signed-off-by: Ksenija Stanojevic <ksenija.stanojevic@gmail.com>

The patch looks correct, and the changelog comment seems ok too.

However, I think it makes sense to do two other changes at the
same time here:

- use ktime_t with ktime_us_delta()/ktime_to_ns to simplify the
  code

- use monotonic time (ktime_get) instead of wall time
  (getnstimeofday64/ktime_get_real) to be more robust against
  leap seconds and settimeofday() calls

	Arnd


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2015-09-29 15:41 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-09-29 15:17 [PATCH] Staging: fbtbt: Replace timespec with timespec64 Ksenija Stanojevic
2015-09-29 15:41 ` [Y2038] " Arnd Bergmann

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.