Commit dd28153b authored by Somya Anand's avatar Somya Anand Committed by Greg Kroah-Hartman

Staging: comedi: replace timeval with ktime_t

'struct timeval last' is used for recording last time interrupt.
'struct timeval now' is used for calculating elapsed time.

32-bit systems using 'struct timeval' will break in the year 2038,
so we have to replace that code with more appropriate types.
This patch changes the comedi driver to use ktime_t.

Since this code doesn't communicate the time values
to the outside (user space, file system, network).Thus ktime_get()
is a better than using do_gettimeofday() as it uses monotonic
clock.

ktime_to_us() returns an 's64', and using the '%' operator on that requires
doing a 64-bit division which needs an expensive library function call
the specific value of usec_current does not actually matter although it might
matter that it's not always the same
which will start with the offset from the lower 32 bit of the microsecond.
Therefore:
  devpriv->usec_current = (ktime_to_us(devpriv->last) % USEC_PER_SEC)
                          % devpriv->usec_period;
	is replaced by

  devpriv->usec_current = ((u32)ktime_to_us(devpriv->last))
                          % devpriv->usec_period;
Signed-off-by: default avatarSomya Anand <somyaanand214@gmail.com>
Signed-off-by: default avatarArnd Bergmann <arnd@arndb.de>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent b0ef3ed4
......@@ -52,13 +52,14 @@ zero volts).
#include "comedi_fc.h"
#include <linux/timer.h>
#include <linux/ktime.h>
#define N_CHANS 8
/* Data unique to this driver */
struct waveform_private {
struct timer_list timer;
struct timeval last; /* time last timer interrupt occurred */
ktime_t last; /* time last timer interrupt occurred */
unsigned int uvolt_amplitude; /* waveform amplitude in microvolts */
unsigned long usec_period; /* waveform period in microseconds */
unsigned long usec_current; /* current time (mod waveform period) */
......@@ -171,14 +172,12 @@ static void waveform_ai_interrupt(unsigned long arg)
/* all times in microsec */
unsigned long elapsed_time;
unsigned int num_scans;
struct timeval now;
ktime_t now;
bool stopping = false;
do_gettimeofday(&now);
now = ktime_get();
elapsed_time =
1000000 * (now.tv_sec - devpriv->last.tv_sec) + now.tv_usec -
devpriv->last.tv_usec;
elapsed_time = ktime_to_us(ktime_sub(now, devpriv->last));
devpriv->last = now;
num_scans =
(devpriv->usec_remainder + elapsed_time) / devpriv->scan_period;
......@@ -317,8 +316,9 @@ static int waveform_ai_cmd(struct comedi_device *dev,
else /* TRIG_TIMER */
devpriv->convert_period = cmd->convert_arg / nano_per_micro;
do_gettimeofday(&devpriv->last);
devpriv->usec_current = devpriv->last.tv_usec % devpriv->usec_period;
devpriv->last = ktime_get();
devpriv->usec_current =
((u32)ktime_to_us(devpriv->last)) % devpriv->usec_period;
devpriv->usec_remainder = 0;
devpriv->timer.expires = jiffies + 1;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment