2005-09-04 23:33:44

by Johannes Stezenbach

[permalink] [raw]
Subject: [DVB patch 54/54] ttusb-budget: use time_after_eq()

From: Marcelo Feitoza Parisi <[email protected]>

Use of the time_after_eq() macro, defined at linux/jiffies.h, which deal
with wrapping correctly and are nicer to read.

Signed-off-by: Marcelo Feitoza Parisi <[email protected]>
Signed-off-by: Domen Puncer <[email protected]>
Signed-off-by: Johannes Stezenbach <[email protected]>

drivers/media/dvb/ttusb-budget/dvb-ttusb-budget.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)

--- linux-2.6.13-git4.orig/drivers/media/dvb/ttusb-budget/dvb-ttusb-budget.c 2005-09-04 22:28:03.000000000 +0200
+++ linux-2.6.13-git4/drivers/media/dvb/ttusb-budget/dvb-ttusb-budget.c 2005-09-04 22:31:06.000000000 +0200
@@ -18,6 +18,7 @@
#include <linux/delay.h>
#include <linux/time.h>
#include <linux/errno.h>
+#include <linux/jiffies.h>
#include <asm/semaphore.h>

#include "dvb_frontend.h"
@@ -570,7 +571,8 @@ static void ttusb_handle_sec_data(struct
const u8 * data, int len);
#endif

-static int numpkt = 0, lastj, numts, numstuff, numsec, numinvalid;
+static int numpkt = 0, numts, numstuff, numsec, numinvalid;
+static unsigned long lastj;

static void ttusb_process_muxpack(struct ttusb *ttusb, const u8 * muxpack,
int len)
@@ -779,7 +781,7 @@ static void ttusb_iso_irq(struct urb *ur
u8 *data;
int len;
numpkt++;
- if ((jiffies - lastj) >= HZ) {
+ if (time_after_eq(jiffies, lastj + HZ)) {
#if DEBUG > 2
printk
("frames/s: %d (ts: %d, stuff %d, sec: %d, invalid: %d, all: %d)\n",

--


2005-09-04 23:45:43

by Nish Aravamudan

[permalink] [raw]
Subject: Re: [DVB patch 54/54] ttusb-budget: use time_after_eq()

On 9/4/05, Johannes Stezenbach <[email protected]> wrote:
> From: Marcelo Feitoza Parisi <[email protected]>
>
> Use of the time_after_eq() macro, defined at linux/jiffies.h, which deal
> with wrapping correctly and are nicer to read.
>
> Signed-off-by: Marcelo Feitoza Parisi <[email protected]>
> Signed-off-by: Domen Puncer <[email protected]>
> Signed-off-by: Johannes Stezenbach <[email protected]>
>
> drivers/media/dvb/ttusb-budget/dvb-ttusb-budget.c | 6 ++++--
> 1 file changed, 4 insertions(+), 2 deletions(-)
>
> --- linux-2.6.13-git4.orig/drivers/media/dvb/ttusb-budget/dvb-ttusb-budget.c 2005-09-04 22:28:03.000000000 +0200
> +++ linux-2.6.13-git4/drivers/media/dvb/ttusb-budget/dvb-ttusb-budget.c 2005-09-04 22:31:06.000000000 +0200
> @@ -18,6 +18,7 @@
> #include <linux/delay.h>
> #include <linux/time.h>
> #include <linux/errno.h>
> +#include <linux/jiffies.h>
> #include <asm/semaphore.h>
>
> #include "dvb_frontend.h"
> @@ -570,7 +571,8 @@ static void ttusb_handle_sec_data(struct
> const u8 * data, int len);
> #endif
>
> -static int numpkt = 0, lastj, numts, numstuff, numsec, numinvalid;
> +static int numpkt = 0, numts, numstuff, numsec, numinvalid;
> +static unsigned long lastj;
>
> static void ttusb_process_muxpack(struct ttusb *ttusb, const u8 * muxpack,
> int len)
> @@ -779,7 +781,7 @@ static void ttusb_iso_irq(struct urb *ur
> u8 *data;
> int len;
> numpkt++;
> - if ((jiffies - lastj) >= HZ) {
> + if (time_after_eq(jiffies, lastj + HZ)) {

I think you actually want:

static void ttusb_iso_irq(....)
{
unsigned long lastj;

...

lastj = jiffies + HZ;
if (time_after_eq(jiffies, lastj)) {
...

}

The current code doesn't assign jiffies to lastj at any point that I see.

Thanks,
Nish

2005-09-05 00:08:08

by Johannes Stezenbach

[permalink] [raw]
Subject: Re: [DVB patch 54/54] ttusb-budget: use time_after_eq()

On Sun, Sep 04, 2005 Nish Aravamudan wrote:
> On 9/4/05, Johannes Stezenbach <[email protected]> wrote:
> >
> > -static int numpkt = 0, lastj, numts, numstuff, numsec, numinvalid;
> > +static int numpkt = 0, numts, numstuff, numsec, numinvalid;
> > +static unsigned long lastj;
> >
> > static void ttusb_process_muxpack(struct ttusb *ttusb, const u8 * muxpack,
> > int len)
> > @@ -779,7 +781,7 @@ static void ttusb_iso_irq(struct urb *ur
> > u8 *data;
> > int len;
> > numpkt++;
> > - if ((jiffies - lastj) >= HZ) {
> > + if (time_after_eq(jiffies, lastj + HZ)) {
>
> I think you actually want:
>
> static void ttusb_iso_irq(....)
> {
> unsigned long lastj;
>
> ...
>
> lastj = jiffies + HZ;
> if (time_after_eq(jiffies, lastj)) {
> ...
>
> }
>
> The current code doesn't assign jiffies to lastj at any point that I see.

The code in question is used to print a one-per-second debug output,
and lastj is assigned after every print.

I agree that it's ugly, though.

Johannes

2005-09-05 00:14:35

by Nish Aravamudan

[permalink] [raw]
Subject: Re: [DVB patch 54/54] ttusb-budget: use time_after_eq()

On 9/4/05, Johannes Stezenbach <[email protected]> wrote:
> On Sun, Sep 04, 2005 Nish Aravamudan wrote:
> > On 9/4/05, Johannes Stezenbach <[email protected]> wrote:
> > >
> > > -static int numpkt = 0, lastj, numts, numstuff, numsec, numinvalid;
> > > +static int numpkt = 0, numts, numstuff, numsec, numinvalid;
> > > +static unsigned long lastj;
> > >
> > > static void ttusb_process_muxpack(struct ttusb *ttusb, const u8 * muxpack,
> > > int len)
> > > @@ -779,7 +781,7 @@ static void ttusb_iso_irq(struct urb *ur
> > > u8 *data;
> > > int len;
> > > numpkt++;
> > > - if ((jiffies - lastj) >= HZ) {
> > > + if (time_after_eq(jiffies, lastj + HZ)) {
> >
> > I think you actually want:
> >
> > static void ttusb_iso_irq(....)
> > {
> > unsigned long lastj;
> >
> > ...
> >
> > lastj = jiffies + HZ;
> > if (time_after_eq(jiffies, lastj)) {
> > ...
> >
> > }
> >
> > The current code doesn't assign jiffies to lastj at any point that I see.
>
> The code in question is used to print a one-per-second debug output,
> and lastj is assigned after every print.

Ah yes, didn't see that in the current code, sorry for that noise.
Still, lastj is local to ttusb_iso_irq(), right?

> I agree that it's ugly, though.

Fair enough :)

Thanks,
Nish

2005-09-05 00:19:31

by Johannes Stezenbach

[permalink] [raw]
Subject: Re: [DVB patch 54/54] ttusb-budget: use time_after_eq()

On Sun, Sep 04, 2005 Nish Aravamudan wrote:
> On 9/4/05, Johannes Stezenbach <[email protected]> wrote:
> > On Sun, Sep 04, 2005 Nish Aravamudan wrote:
> > > On 9/4/05, Johannes Stezenbach <[email protected]> wrote:
> > > >
> > > > -static int numpkt = 0, lastj, numts, numstuff, numsec, numinvalid;
> > > > +static int numpkt = 0, numts, numstuff, numsec, numinvalid;
> > > > +static unsigned long lastj;
> > > >
> > >
> > > I think you actually want:
> > >
> > > static void ttusb_iso_irq(....)
> > > {
> > > unsigned long lastj;
> > >
> >
> > The code in question is used to print a one-per-second debug output,
> > and lastj is assigned after every print.
>
> Ah yes, didn't see that in the current code, sorry for that noise.
> Still, lastj is local to ttusb_iso_irq(), right?

Yes, but it needs to be static.

Johannes