[v3 1/1] Staging: comedi: replace timeval with ktime_t

41 views
Skip to first unread message

Somya Anand

unread,
Oct 11, 2014, 4:44:21 PM10/11/14
to ar...@arndb.de, opw-k...@googlegroups.com, somyaa...@gmail.com
'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.

*ktime_get() is better than using do_gettimeofday(),
because it uses the monotonic clock.

Changelog:
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: Somya Anand <somyaa...@gmail.com>
---
drivers/staging/comedi/drivers/comedi_test.c | 15 +++++++--------
1 file changed, 7 insertions(+), 8 deletions(-)

diff --git a/drivers/staging/comedi/drivers/comedi_test.c b/drivers/staging/comedi/drivers/comedi_test.c
index 00c03df..b3e25d2 100644
--- a/drivers/staging/comedi/drivers/comedi_test.c
+++ b/drivers/staging/comedi/drivers/comedi_test.c
@@ -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) */
@@ -170,14 +171,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;
@@ -316,8 +315,8 @@ 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;
--
1.9.1

Somya Anand

unread,
Oct 12, 2014, 4:06:07 AM10/12/14
to ar...@arndb.de, opw-k...@googlegroups.com, somyaa...@gmail.com
'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.

*ktime_get() is better than using do_gettimeofday(),
because it uses the monotonic clock.

Sarah Sharp

unread,
Oct 12, 2014, 6:32:35 PM10/12/14
to Somya Anand, ar...@arndb.de, opw-k...@googlegroups.com
Hi Somya,

The OPW kernel application period is being put on hold from October 10
to October 20. I sent out an email about this, but you may have missed
it, so here's the instructions I sent last Monday:

The Linux kernel OPW application period will be put on hold, starting
October 10th and resuming on October 20th. During that time, most
kernel mentors will be attending conferences (LinuxCon Europe, Linux
Plumbers Conf, and Embedded Linux Conference Europe). Please note that
most mentors will not be on the IRC channel, and will be slow at
answering emails.

From October 10th to October 20th, please *DO NOT* send kernel patches
to the OPW mailing list. No one will be available to respond to you,
and we won't be able to work through the patch back log. Please start
sending your patches on Monday, October 20th.

If you have not gotten a kernel patch accepted into the staging tree,
please focus on getting those in this week. If you haven't gotten ten
cleanup patches in by the end of this week, please work on those during
the hold period.

If you have ten or more kernel patches accepted into staging-next by the
end of this week, we suggest that you tackle a medium-sized advanced
project during the hold period, rather than preparing to send many small
clean up patches after the hold period is finished. If you plan on
tackling a small task from one of the mentors, please coordinate with
them this week, and ask any questions before they leave for conferences.

Another good thing to work on during that week is your official OPW
application. In order to be accepted as an OPW kernel intern, you must
have your application filled out, and you must have at least one patch
accepted into the Linux kernel.

Details on the application process are below.

OPW Application Form
====================

As of Fri Oct 3, the following people have successfully gotten a staging
driver cleanup patch into Greg's staging-next tree:

Gulsah Kose
Aybuke Ozdemir
Tapasweni Pathak
Mahati Chamarthy
Roberta Dobrescu
Roxana Blaj
Darshana Padmadas
Catalina Mocanu
Vaishali Thakkar
Heena Sirwani
Melike Yurtogl
Tina Johnson
Esra Altintas
Yeliz Taneroglu
Rajbinder Brar
Erin Grasmick
Ebru Akagunduz
Sarah Khan
Dilek Uzulmez
Feyza Yavuz
Mihaela Gaman
Georgiana Chelu
Nicoleta Birsan
Ankita Patil

If your name is on that list, *PLEASE* fill out your application form at
https://opw.gnome.org/

Make sure to read the "Application tips" section at
http://kernelnewbies.org/OPWApply

Small tasks
===========

Additionally, the following people have completed at least ten staging
driver patches:

Gulsah Kose
Aybuke Ozdemir
Tapasweni Pathak
Mahati Chamarthy
Roberta Dobrescu
Roxana Blaj
Darshana Padmadas
Catalina Mocanu
Vaishali Thakkar
Heena Sirwani
Melike Yurtogl

If your name is on that list, you are *highly encouraged* to start
working on more complex kernel patches, such as Sparse cleanups,
Coccinelle scripts, or small tasks from mentors. Please remember that
we will look at the quality, not quantity of patches, and we value
applicants that can move onto more advanced topics.

Sarah Sharp
> --
> You received this message because you are subscribed to the Google Groups "opw-kernel" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to opw-kernel+...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Greg KH

unread,
Oct 20, 2014, 12:54:23 AM10/20/14
to Somya Anand, ar...@arndb.de, opw-k...@googlegroups.com
On Sun, Oct 12, 2014 at 02:14:07AM +0530, Somya Anand wrote:
> '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.
>
> *ktime_get() is better than using do_gettimeofday(),
> because it uses the monotonic clock.
>
> Changelog:
> 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;

The changelog doesn't go here, it goes below the --- line.

Please fix that up and resend.

Also, Arnd, does this look correct?

thanks,

greg k-h

Arnd Bergmann

unread,
Oct 20, 2014, 10:07:50 AM10/20/14
to Greg KH, Somya Anand, opw-k...@googlegroups.com
Yes, it's correct. However it is a very subtle change that (as I
just replied on the resend) needs to be explained in detail.

Arnd
Reply all
Reply to author
Forward
0 new messages