[PATCH] staging: fbtft: Use monotonic clock
Wall time obtained from getnstimeofday is susceptible to sudden jumps due to user setting the time or due to NTP. Monotonic time is constantly increasing time better suited for comparing two timestamps Signed-off-by: Abhilash Jindal --- drivers/staging/fbtft/fbtft-core.c |4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/staging/fbtft/fbtft-core.c b/drivers/staging/fbtft/fbtft-core.c index 53b748b..af1817a 100644 --- a/drivers/staging/fbtft/fbtft-core.c +++ b/drivers/staging/fbtft/fbtft-core.c @@ -372,7 +372,7 @@ static void fbtft_update_display(struct fbtft_par *par, unsigned start_line, 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); + ktime_get_ts(&ts_start); timeit = true; } } @@ -409,7 +409,7 @@ static void fbtft_update_display(struct fbtft_par *par, unsigned start_line, __func__); if (unlikely(timeit)) { - getnstimeofday(&ts_end); + ktime_get_ts(&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; -- 1.7.9.5 ___ devel mailing list de...@linuxdriverproject.org http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel
[PATCH] staging: lirc_parallel.c: Use monotonic clock
Wall time obtained from do_gettimeofday is susceptible to sudden jumps due to user setting the time or due to NTP. Monotonic time is constantly increasing time better suited for comparing two timestamps. Signed-off-by: Abhilash Jindal --- drivers/staging/media/lirc/lirc_parallel.c | 42 1 file changed, 18 insertions(+), 24 deletions(-) diff --git a/drivers/staging/media/lirc/lirc_parallel.c b/drivers/staging/media/lirc/lirc_parallel.c index c140834..de2ec2e 100644 --- a/drivers/staging/media/lirc/lirc_parallel.c +++ b/drivers/staging/media/lirc/lirc_parallel.c @@ -144,33 +144,29 @@ static void lirc_off(void) static unsigned int init_lirc_timer(void) { - struct timeval tv, now; - unsigned int level, newlevel, timeelapsed, newtimer; + ktime_t tm, now; + unsigned int elapsedus, level, newlevel, newtimer; int count = 0; - do_gettimeofday(&tv); - tv.tv_sec++; /* wait max. 1 sec. */ + tm = ktime_get(); level = lirc_get_timer(); do { newlevel = lirc_get_timer(); if (level == 0 && newlevel != 0) count++; level = newlevel; - do_gettimeofday(&now); - } while (count < 1000 && (now.tv_sec < tv.tv_sec -|| (now.tv_sec == tv.tv_sec -&& now.tv_usec < tv.tv_usec))); - - timeelapsed = (now.tv_sec + 1 - tv.tv_sec)*100 -+ (now.tv_usec - tv.tv_usec); - if (count >= 1000 && timeelapsed > 0) { + now = ktime_get(); + elapsedus = ktime_us_delta(now, tm); + } while (count < 1000 && elapsedus < 100);/* wait max. 1 sec. */ + + if (count >= 1000 && elapsedus > 0) { if (default_timer == 0) { /* autodetect timer */ - newtimer = (100*count)/timeelapsed; + newtimer = (100*count)/elapsedus; pr_info("%u Hz timer detected\n", newtimer); return newtimer; } - newtimer = (100*count)/timeelapsed; + newtimer = (100*count)/elapsedus; if (abs(newtimer - default_timer) > default_timer/10) { /* bad timer */ pr_notice("bad timer: %u Hz\n", newtimer); @@ -220,10 +216,10 @@ static void rbuf_write(int signal) static void lirc_lirc_irq_handler(void *blah) { - struct timeval tv; - static struct timeval lasttv; + ktime_t tm; + static ktime_t lasttm; static int init; - long signal; + long signal, elapsedus; int data; unsigned int level, newlevel; unsigned int timeout; @@ -244,16 +240,14 @@ static void lirc_lirc_irq_handler(void *blah) #ifdef LIRC_TIMER if (init) { - do_gettimeofday(&tv); - - signal = tv.tv_sec - lasttv.tv_sec; + tm = ktime_get(); + elapsedus = ktime_us_delta(tm, lasttm); + signal = elapsedus/USEC_PER_SEC; if (signal > 15) /* really long time */ data = PULSE_MASK; else - data = (int) (signal*100 + -tv.tv_usec - lasttv.tv_usec + -LIRC_SFH506_DELAY); + data = (int) (elapsedus + LIRC_SFH506_DELAY); rbuf_write(data); /* space */ } else { @@ -301,7 +295,7 @@ static void lirc_lirc_irq_handler(void *blah) data = 1; rbuf_write(PULSE_BIT|data); /* pulse */ } - do_gettimeofday(&lasttv); + lasttm = ktime_get(); #else /* add your code here */ #endif -- 1.7.9.5 ___ devel mailing list de...@linuxdriverproject.org http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel
[PATCH] staging: comedi: Use monotonic clock
Wall time obtained from do_gettimeofday is susceptible to sudden jumps due to user setting the time or due to NTP. Monotonic time is constantly increasing time better suited for comparing two timestamps. Signed-off-by: Abhilash Jindal --- drivers/staging/comedi/drivers/serial2002.c | 10 +- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/drivers/staging/comedi/drivers/serial2002.c b/drivers/staging/comedi/drivers/serial2002.c index 83da162..5f19374 100644 --- a/drivers/staging/comedi/drivers/serial2002.c +++ b/drivers/staging/comedi/drivers/serial2002.c @@ -32,6 +32,7 @@ Status: in development #include #include #include +#include #include #include @@ -121,9 +122,9 @@ static int serial2002_tty_write(struct file *f, unsigned char *buf, int count) static void serial2002_tty_read_poll_wait(struct file *f, int timeout) { struct poll_wqueues table; - struct timeval start, now; + ktime_t start, now; - do_gettimeofday(&start); + start = ktime_get(); poll_initwait(&table); while (1) { long elapsed; @@ -134,9 +135,8 @@ static void serial2002_tty_read_poll_wait(struct file *f, int timeout) POLLHUP | POLLERR)) { break; } - do_gettimeofday(&now); - elapsed = 100 * (now.tv_sec - start.tv_sec) + - now.tv_usec - start.tv_usec; + now = ktime_get(); + elapsed = ktime_us_delta(now, start); if (elapsed > timeout) break; set_current_state(TASK_INTERRUPTIBLE); -- 1.7.9.5 ___ devel mailing list de...@linuxdriverproject.org http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel
[BUG] driver/staging/android/timed_gpio.c - very long gpio on if CPU suspends
timed_gpio.c uses hrtimer to switch off the gpio. However, hrtimer does not get fired after the CPU suspends. Hence, if the CPU suspends before the timer gets fired, the gpio stays on until the next time when CPU wakes up causing unnecessary battery drain (which can be as long as 15 minutes). IMHO, we should replace hrtimer by android alarm timer to make sure that CPU wakes up at the right time and gpio gets turned off. Thanks Abhilash ___ devel mailing list de...@linuxdriverproject.org http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel