All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] Staging: fbtbt: Replace timespec with ktime_t
@ 2015-09-30 16:10 Ksenija Stanojevic
  2015-09-30 21:52 ` [Y2038] " Arnd Bergmann
  0 siblings, 1 reply; 11+ messages in thread
From: Ksenija Stanojevic @ 2015-09-30 16:10 UTC (permalink / raw)
  To: outreachy-kernel; +Cc: y2038, Ksenija Stanojevic

struct timespec will overflow in year 2038, so replace it with
ktime_t. And replace functions that use struct timespec,
timespec_sub with ktime_sub. Also use monotonic time instead of real
time, by replacing getnstimeofday with ktime_get, to be more robust
against leap seconds and settimeofday() calls.

Signed-off-by: Ksenija Stanojevic <ksenija.stanojevic@gmail.com>
---

Changes in v2:
        -use ktime_t instead timespec64
        -use ktime_sub instead timespec64_sub
        -use monotonic instead real-time.

 drivers/staging/fbtft/fbtft-core.c | 35 +++++++++++++----------------------
 drivers/staging/fbtft/fbtft.h      |  2 +-
 2 files changed, 14 insertions(+), 23 deletions(-)

diff --git a/drivers/staging/fbtft/fbtft-core.c b/drivers/staging/fbtft/fbtft-core.c
index 7f5fa3d..a1645e1 100644
--- a/drivers/staging/fbtft/fbtft-core.c
+++ b/drivers/staging/fbtft/fbtft-core.c
@@ -365,16 +365,15 @@ 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;
-	long fps_ms, fps_us, duration_ms, duration_us;
-	long fps, throughput;
+	ktime_t ts_start, ts_end, ts_fps;
+	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);
+			ts_start = ktime_get();
 			timeit = true;
 		}
 	}
@@ -411,30 +410,22 @@ static void fbtft_update_display(struct fbtft_par *par, unsigned start_line,
 			__func__);
 
 	if (unlikely(timeit)) {
-		getnstimeofday(&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);
-		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;
+		ts_end = ktime_get();
+		if (par->update_time.tv64 == 0)
+			par->update_time = ts_start;
+
+		ts_fps = ktime_sub(ts_start, par->update_time);
+		par->update_time = ts_start;
+		fps = ktime_to_us(ts_fps);
 		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;
+		throughput = ktime_us_delta(ts_end, ts_start);
 		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",
-			throughput, duration_ms, duration_us,
-			fps, fps_ms, fps_us);
+			"Display update: %lld kB/s, fps=%lld\n",
+			throughput, fps);
 		par->first_update_done = true;
 	}
 }
diff --git a/drivers/staging/fbtft/fbtft.h b/drivers/staging/fbtft/fbtft.h
index 7e9a506..8107f55 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;
+	ktime_t update_time;
 	bool bgr;
 	void *extra;
 };
-- 
1.9.1



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

end of thread, other threads:[~2015-10-07 19:08 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-09-30 16:10 [PATCH v2] Staging: fbtbt: Replace timespec with ktime_t Ksenija Stanojevic
2015-09-30 21:52 ` [Y2038] " Arnd Bergmann
2015-10-01 17:44   ` Ksenija Stanojević
2015-10-01 20:05     ` Arnd Bergmann
2015-10-03 19:15       ` Ksenija Stanojević
2015-10-04 19:34         ` Arnd Bergmann
2015-10-05  5:17           ` [Outreachy kernel] " Sudip Mukherjee
2015-10-05  8:20             ` Arnd Bergmann
2015-10-05 14:52               ` Sudip Mukherjee
2015-10-07 18:46           ` Ksenija Stanojević
2015-10-07 19:08             ` 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.