Skip to content

Commit 367e856

Browse files
KsenijaSgregkh
authored andcommitted
Staging: fbtbt: Replace timespec with ktime_t
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 <[email protected]> Reviewed-by: Arnd Bergmann <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent f60c265 commit 367e856

File tree

2 files changed

+12
-22
lines changed

2 files changed

+12
-22
lines changed

drivers/staging/fbtft/fbtft-core.c

Lines changed: 11 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -346,16 +346,15 @@ static void fbtft_update_display(struct fbtft_par *par, unsigned start_line,
346346
unsigned end_line)
347347
{
348348
size_t offset, len;
349-
struct timespec ts_start, ts_end, ts_fps, ts_duration;
350-
long fps_ms, fps_us, duration_ms, duration_us;
349+
ktime_t ts_start, ts_end;
351350
long fps, throughput;
352351
bool timeit = false;
353352
int ret = 0;
354353

355354
if (unlikely(par->debug & (DEBUG_TIME_FIRST_UPDATE | DEBUG_TIME_EACH_UPDATE))) {
356355
if ((par->debug & DEBUG_TIME_EACH_UPDATE) ||
357356
((par->debug & DEBUG_TIME_FIRST_UPDATE) && !par->first_update_done)) {
358-
getnstimeofday(&ts_start);
357+
ts_start = ktime_get();
359358
timeit = true;
360359
}
361360
}
@@ -392,30 +391,21 @@ static void fbtft_update_display(struct fbtft_par *par, unsigned start_line,
392391
__func__);
393392

394393
if (unlikely(timeit)) {
395-
getnstimeofday(&ts_end);
396-
if (par->update_time.tv_nsec == 0 && par->update_time.tv_sec == 0) {
397-
par->update_time.tv_sec = ts_start.tv_sec;
398-
par->update_time.tv_nsec = ts_start.tv_nsec;
399-
}
400-
ts_fps = timespec_sub(ts_start, par->update_time);
401-
par->update_time.tv_sec = ts_start.tv_sec;
402-
par->update_time.tv_nsec = ts_start.tv_nsec;
403-
fps_ms = (ts_fps.tv_sec * 1000) + ((ts_fps.tv_nsec / 1000000) % 1000);
404-
fps_us = (ts_fps.tv_nsec / 1000) % 1000;
405-
fps = fps_ms * 1000 + fps_us;
394+
ts_end = ktime_get();
395+
if (ktime_to_ns(par->update_time))
396+
par->update_time = ts_start;
397+
398+
par->update_time = ts_start;
399+
fps = ktime_us_delta(ts_start, par->update_time);
406400
fps = fps ? 1000000 / fps : 0;
407401

408-
ts_duration = timespec_sub(ts_end, ts_start);
409-
duration_ms = (ts_duration.tv_sec * 1000) + ((ts_duration.tv_nsec / 1000000) % 1000);
410-
duration_us = (ts_duration.tv_nsec / 1000) % 1000;
411-
throughput = duration_ms * 1000 + duration_us;
402+
throughput = ktime_us_delta(ts_end, ts_start);
412403
throughput = throughput ? (len * 1000) / throughput : 0;
413404
throughput = throughput * 1000 / 1024;
414405

415406
dev_info(par->info->device,
416-
"Display update: %ld kB/s (%ld.%.3ld ms), fps=%ld (%ld.%.3ld ms)\n",
417-
throughput, duration_ms, duration_us,
418-
fps, fps_ms, fps_us);
407+
"Display update: %ld kB/s, fps=%ld\n",
408+
throughput, fps);
419409
par->first_update_done = true;
420410
}
421411
}

drivers/staging/fbtft/fbtft.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ struct fbtft_par {
246246
} gamma;
247247
unsigned long debug;
248248
bool first_update_done;
249-
struct timespec update_time;
249+
ktime_t update_time;
250250
bool bgr;
251251
void *extra;
252252
};

0 commit comments

Comments
 (0)