Input: hil_mlc: convert timeval to time64_t
Subsystems (3)
PATCH 1/3 Input: hil_mlc: convert timeval to time64_t
From: WEN Pingbo <[email protected]>
Since mlc->lcv_t is only interested in seconds, directly using time64_t here.
This gets rid of the deprecated do_gettimeofday() and avoids problems with time going backwards since we now use the monotonic clocksource.
--- drivers/input/serio/hil_mlc.c | 8 +++----- include/linux/hil_mlc.h | 2 +- 2 files changed, 4 insertions(+), 6 deletions(-)
drivers/input/serio/hil_mlc.c +3 -5
@@ -274,14 +274,12 @@ static int hilse_match(hil_mlc *mlc, int unused)/* An LCV used to prevent runaway loops, forces 5 second sleep when reset. */ static int hilse_init_lcv (hil_mlc *mlc,int unused) { -struct timeval tv; +time64_t now =ktime_get_seconds (); -do_gettimeofday (&tv); - -if (mlc->lcv && (tv.tv_sec - mlc->lcv_tv.tv_sec) <5 ) +if (mlc->lcv && (now - mlc->lcv_time) <5 )return -1 ; - mlc->lcv_tv = tv; + mlc->lcv_time = now; mlc->lcv =0 ;return 0 ;
include/linux/hil_mlc.h +1 -1
@@ -149,7 +149,7 @@ struct hil_mlc {int ddi;/* Last operational device id */ int lcv;/* LCV to throttle loops */ -struct timeval lcv_tv;/* Time loop was started */ +time64_t lcv_time;/* Time loop was started */ int di_map[7 ];/* Maps below items to live devs */ struct hil_mlc_devinfo di[HIL_MLC_DEVMEM ];
Signature · 1 line
2.9.0
PATCH 2/3 input: hil_mlc: convert timeval to jiffies
From: WEN Pingbo <[email protected]>
struct timeval is not y2038 safe, and what mlc->instart do is scheduling a task in a fixed timeout, so jiffies is the simplest choice here.
In hilse_donode(), the expires in mod_timer equals
jiffies + intimeout - (now - instart)
If we use jiffies in 'now', the expires equals
instart + intimeout
So, all we need to do is that making sure expires is a future timestamp before passed it to mod_timer.
[arnd: slightly simplified patch further]
--- drivers/input/serio/hil_mlc.c | 18 +++++++----------- drivers/input/serio/hp_sdc_mlc.c | 5 +---- include/linux/hil_mlc.h | 4 ++-- 3 files changed, 10 insertions(+), 17 deletions(-)
drivers/input/serio/hil_mlc.c +7 -11
@@ -602,8 +602,8 @@ static inline void hilse_setup_input(hil_mlc *mlc, const struct hilse_node *nodeBUG (); } mlc->istarted =1 ; - mlc->intimeout = node->arg; -do_gettimeofday (&(mlc->instart)); + mlc->intimeout =usecs_to_jiffies (node->arg); + mlc->instart = jiffies; mlc->icount =15 ;memset (mlc->ipacket,0 ,16 *sizeof (hil_packet));BUG_ON (down_trylock (&mlc->isem));
@@ -708,7 +708,7 @@ static int hilse_donode(hil_mlc *mlc)break ; } mlc->ostarted =0 ; -do_gettimeofday (&(mlc->instart)); + mlc->instart = jiffies;write_unlock_irqrestore (&mlc->lock, flags); nextidx =HILSEN_NEXT ;break ;
@@ -729,18 +729,14 @@ static int hilse_donode(hil_mlc *mlc)#endif while (nextidx &HILSEN_SCHED ) { -struct timeval tv; +unsigned long now = jiffies;if (!sched_long) goto sched; -do_gettimeofday (&tv); - tv.tv_usec +=USEC_PER_SEC * (tv.tv_sec - mlc->instart.tv_sec); - tv.tv_usec -= mlc->instart.tv_usec; -if (tv.tv_usec >= mlc->intimeout) goto sched; - tv.tv_usec = (mlc->intimeout - tv.tv_usec) *HZ /USEC_PER_SEC ; -if (!tv.tv_usec) goto sched; -mod_timer (&hil_mlcs_kicker, jiffies + tv.tv_usec); +if (time_after (now, mlc->instart + mlc->intimeout)) + goto sched; +mod_timer (&hil_mlcs_kicker, mlc->instart + mlc->intimeout);break ; sched:tasklet_schedule (&hil_mlcs_tasklet);
drivers/input/serio/hp_sdc_mlc.c +1 -4
@@ -149,7 +149,6 @@ static int hp_sdc_mlc_in(hil_mlc *mlc, suseconds_t timeout)/* Try to down the semaphore */ if (down_trylock (&mlc->isem)) { -struct timeval tv;if (priv->emtestmode) { mlc->ipacket[0 ] = HIL_ERR_INT | (mlc->opacket &
@@ -160,9 +159,7 @@ static int hp_sdc_mlc_in(hil_mlc *mlc, suseconds_t timeout)/* printk(KERN_DEBUG PREFIX ">[%x]\n", mlc->ipacket[0]); */ goto wasup; } -do_gettimeofday (&tv); - tv.tv_usec +=USEC_PER_SEC * (tv.tv_sec - mlc->instart.tv_sec); -if (tv.tv_usec - mlc->instart.tv_usec > mlc->intimeout) { +if (time_after (jiffies, mlc->instart + mlc->intimeout)) {/* printk("!%i %i", tv.tv_usec - mlc->instart.tv_usec, mlc->intimeout);
include/linux/hil_mlc.h +2 -2
@@ -144,8 +144,8 @@ struct hil_mlc {hil_packet ipacket[16 ];hil_packet imatch;int icount; -struct timeval instart; -suseconds_t intimeout; +unsigned long instart; +unsigned long intimeout;int ddi;/* Last operational device id */ int lcv;/* LCV to throttle loops */
Signature · 1 line
2.9.0
PATCH 3/3 Input: hp_sdc: convert to ktime_get()
In reply to Arnd BergmannThis gets rid of the deprecated do_gettimeofday() call in favor of ktime_get(), which is also more reliable as it uses monotonic times. The code now gets a bit simpler.
--- drivers/input/serio/hp_sdc.c | 17 +++++++---------- include/linux/hp_sdc.h | 2 +- 2 files changed, 8 insertions(+), 11 deletions(-)
drivers/input/serio/hp_sdc.c +7 -10
@@ -193,7 +193,7 @@ static void hp_sdc_take(int irq, void *dev_id, uint8_t status, uint8_t data) curr->seq[curr->idx++] = status; curr->seq[curr->idx++] = data; hp_sdc.rqty -=2 ; -do_gettimeofday (&hp_sdc.rtv); + hp_sdc.rtime =ktime_get ();if (hp_sdc.rqty <=0 ) {/* All data has been gathered. */
@@ -306,13 +306,10 @@ static void hp_sdc_tasklet(unsigned long foo)write_lock_irq (&hp_sdc.rtq_lock);if (hp_sdc.rcurr >=0 ) { -struct timeval tv; +ktime_t now =ktime_get (); -do_gettimeofday (&tv); -if (tv.tv_sec > hp_sdc.rtv.tv_sec) - tv.tv_usec +=USEC_PER_SEC ; - -if (tv.tv_usec - hp_sdc.rtv.tv_usec >HP_SDC_MAX_REG_DELAY ) { +if (ktime_after (now,ktime_add_us (hp_sdc.rtime, +HP_SDC_MAX_REG_DELAY ))) {hp_sdc_transaction *curr;uint8_t tmp;
@@ -321,8 +318,8 @@ static void hp_sdc_tasklet(unsigned long foo)* we'll need to figure out a way to communicate * it back to the application. and be less verbose. */ - printk(KERN_WARNING PREFIX "read timeout (%ius)!\n", - (int)(tv.tv_usec - hp_sdc.rtv.tv_usec)); + printk(KERN_WARNING PREFIX "read timeout (%lldus)!\n", + ktime_us_delta(now, hp_sdc.rtime)); curr->idx += hp_sdc.rqty; hp_sdc.rqty =0 ; tmp = curr->seq[curr->actidx];
@@ -551,7 +548,7 @@ unsigned long hp_sdc_put(void)/* Start a new read */ hp_sdc.rqty = curr->seq[curr->idx]; -do_gettimeofday (&hp_sdc.rtv); + hp_sdc.rtime =ktime_get (); curr->idx++;/* Still need to lock here in case of spurious irq. */ write_lock_irq (&hp_sdc.rtq_lock);
include/linux/hp_sdc.h +1 -1
@@ -281,7 +281,7 @@ typedef struct {hp_sdc_transaction *tq[HP_SDC_QUEUE_LEN ];/* All pending read/writes */ int rcurr, rqty;/* Current read transact in process */ -struct timeval rtv;/* Time when current read started */ +ktime_t rtime;/* Time when current read started */ int wcurr;/* Current write transact in process */ int dev_err;/* carries status from registration */
Signature · 1 line
2.9.0