2008-03-07 03:03:20

by Dave Young

[permalink] [raw]
Subject: [PATCH RFC] add time_after_now and other macros which compare with jiffies

Most of time_after like macros users just compare jiffies and
another number, so here add some other _now macros to do it.

Another aproach is changing original time_ macros to use jiffies to compare,
add a generic compare macro like time_compare(a, b)

Signed-off-by: Dave Young <[email protected]>

---
jiffies.h | 8 ++++++++
1 file changed, 8 insertions(+)

diff -upr linux/include/linux/jiffies.h linux.new/include/linux/jiffies.h
--- linux/include/linux/jiffies.h 2008-03-07 10:40:04.000000000 +0800
+++ linux.new/include/linux/jiffies.h 2008-03-07 10:50:12.000000000 +0800
@@ -134,6 +134,14 @@ static inline u64 get_jiffies_64(void)
((__s64)(a) - (__s64)(b) >= 0))
#define time_before_eq64(a,b) time_after_eq64(b,a)

+#define time_after_now(a) time_after(jiffies, a)
+
+#define time_before_now(a) time_before(jiffies, a)
+
+#define time_after_eq_now(a) time_after_eq(jiffies, a)
+
+#define time_before_eq_now(a) time_before_eq(jiffies, a)
+
/*
* Have the 32 bit jiffies value wrap 5 minutes after boot
* so jiffies wrap bugs show up earlier.


2008-03-07 09:03:21

by Andrew Morton

[permalink] [raw]
Subject: Re: [PATCH RFC] add time_after_now and other macros which compare with jiffies

On Fri, 7 Mar 2008 11:09:01 +0800 Dave Young <[email protected]> wrote:

> Most of time_after like macros users just compare jiffies and
> another number, so here add some other _now macros to do it.
>
> Another aproach is changing original time_ macros to use jiffies to compare,
> add a generic compare macro like time_compare(a, b)
>
> Signed-off-by: Dave Young <[email protected]>
>
> ---
> jiffies.h | 8 ++++++++
> 1 file changed, 8 insertions(+)
>
> diff -upr linux/include/linux/jiffies.h linux.new/include/linux/jiffies.h
> --- linux/include/linux/jiffies.h 2008-03-07 10:40:04.000000000 +0800
> +++ linux.new/include/linux/jiffies.h 2008-03-07 10:50:12.000000000 +0800
> @@ -134,6 +134,14 @@ static inline u64 get_jiffies_64(void)
> ((__s64)(a) - (__s64)(b) >= 0))
> #define time_before_eq64(a,b) time_after_eq64(b,a)
>
> +#define time_after_now(a) time_after(jiffies, a)
> +
> +#define time_before_now(a) time_before(jiffies, a)
> +
> +#define time_after_eq_now(a) time_after_eq(jiffies, a)
> +
> +#define time_before_eq_now(a) time_before_eq(jiffies, a)
> +
> /*
> * Have the 32 bit jiffies value wrap 5 minutes after boot
> * so jiffies wrap bugs show up earlier.

time_after() and friends drive me nutty. I *always* have to go and look at
the definition to make sure that people got the args the right way around.

(does that)

> * time_after(a,b) returns true if the time a is after time b.

so, umm, I think you got it backwards. Your time_after_now(a) will return
true if jiffies (ie: now) is after `a'. ie: if a is before or equal to
"now".

All this shouldn't be as hard as it is.

One lesson we can learn from this: whatever we do, it needs careful
commenting. Your change doesn't do that.

2008-03-07 09:21:06

by Dave Young

[permalink] [raw]
Subject: Re: [PATCH RFC] add time_after_now and other macros which compare with jiffies

On Fri, Mar 7, 2008 at 5:02 PM, Andrew Morton <[email protected]> wrote:
>
> On Fri, 7 Mar 2008 11:09:01 +0800 Dave Young <[email protected]> wrote:
>
> > Most of time_after like macros users just compare jiffies and
> > another number, so here add some other _now macros to do it.
> >
> > Another aproach is changing original time_ macros to use jiffies to compare,
> > add a generic compare macro like time_compare(a, b)
> >
> > Signed-off-by: Dave Young <[email protected]>
> >
> > ---
> > jiffies.h | 8 ++++++++
> > 1 file changed, 8 insertions(+)
> >
> > diff -upr linux/include/linux/jiffies.h linux.new/include/linux/jiffies.h
> > --- linux/include/linux/jiffies.h 2008-03-07 10:40:04.000000000 +0800
> > +++ linux.new/include/linux/jiffies.h 2008-03-07 10:50:12.000000000 +0800
> > @@ -134,6 +134,14 @@ static inline u64 get_jiffies_64(void)
> > ((__s64)(a) - (__s64)(b) >= 0))
> > #define time_before_eq64(a,b) time_after_eq64(b,a)
> >
> > +#define time_after_now(a) time_after(jiffies, a)
> > +
> > +#define time_before_now(a) time_before(jiffies, a)
> > +
> > +#define time_after_eq_now(a) time_after_eq(jiffies, a)
> > +
> > +#define time_before_eq_now(a) time_before_eq(jiffies, a)
> > +
> > /*
> > * Have the 32 bit jiffies value wrap 5 minutes after boot
> > * so jiffies wrap bugs show up earlier.
>
> time_after() and friends drive me nutty. I *always* have to go and look at
> the definition to make sure that people got the args the right way around.

Andrew, thanks for your patient.

>
> (does that)
>
> > * time_after(a,b) returns true if the time a is after time b.
>
> so, umm, I think you got it backwards. Your time_after_now(a) will return
> true if jiffies (ie: now) is after `a'. ie: if a is before or equal to
> "now".
>
> All this shouldn't be as hard as it is.
>
> One lesson we can learn from this: whatever we do, it needs careful
> commenting. Your change doesn't do that.
>

Indeed, I will add proper comment before them.

Thanks again.

2008-03-07 09:29:40

by Andrew Morton

[permalink] [raw]
Subject: Re: [PATCH RFC] add time_after_now and other macros which compare with jiffies

On Fri, 7 Mar 2008 17:12:29 +0800 "Dave Young" <[email protected]> wrote:

> Indeed, I will add proper comment before them.

Sob. Of the 809 usages of time_after(), it appears that over 700 are
comparing with jiffies. So with your (good) change, someone will get
buried in well-meaning convert-to-time_after_now patches.

I wonder who that might be?

2008-03-07 09:36:36

by Dave Young

[permalink] [raw]
Subject: Re: [PATCH RFC] add time_after_now and other macros which compare with jiffies

On Fri, Mar 7, 2008 at 5:22 PM, Andrew Morton <[email protected]> wrote:
> On Fri, 7 Mar 2008 17:12:29 +0800 "Dave Young" <[email protected]> wrote:
>
> > Indeed, I will add proper comment before them.
>
> Sob. Of the 809 usages of time_after(), it appears that over 700 are
> comparing with jiffies. So with your (good) change, someone will get
> buried in well-meaning convert-to-time_after_now patches.


Yes, there will be a lot of patches. Hope I have that time to do some.

>
> I wonder who that might be?
>