LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
* [PATCH v2] add time_now_after and other macros which compare with jiffies
@ 2008-03-07 23:35 Dave Young
2008-03-08 16:12 ` Johannes Weiner
0 siblings, 1 reply; 12+ messages in thread
From: Dave Young @ 2008-03-07 23:35 UTC (permalink / raw)
To: akpm; +Cc: linux-kernel
Changes from previous version:
1. Add comments
2. Change names easy to understand. For example, now time_now_after(a) means time now after a will return true.
---
Signed-off-by: Dave Young <hidave.darkstar@gmail.com>
---
include/linux/jiffies.h | 16 ++++++++++++++++
1 file changed, 16 insertions(+)
diff -upr linux/include/linux/jiffies.h linux.new/include/linux/jiffies.h
--- linux/include/linux/jiffies.h 2008-03-07 19:56:02.000000000 +0800
+++ linux.new/include/linux/jiffies.h 2008-03-07 20:10:25.000000000 +0800
@@ -135,6 +135,22 @@ static inline u64 get_jiffies_64(void)
#define time_before_eq64(a,b) time_after_eq64(b,a)
/*
+ * These four macros compare jiffies and 'a' for convenience.
+ */
+
+/* time_now_after(a) return true if now (jiffies) is after a */
+#define time_now_after(a) time_after(jiffies, a)
+
+/* time_now_before(a) return true if now (jiffies) is before a */
+#define time_now_before(a) time_before(jiffies, a)
+
+/* time_now_after_eq(a) return true if now (jiffies) is after or equal to a */
+#define time_now_after_eq(a) time_after_eq(jiffies, a)
+
+/* time_now_before_eq(a) return true if now (jiffies) is before or equal to a */
+#define time_now_before_eq(a) time_before_eq(jiffies, a)
+
+/*
* Have the 32 bit jiffies value wrap 5 minutes after boot
* so jiffies wrap bugs show up earlier.
*/
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH v2] add time_now_after and other macros which compare with jiffies
2008-03-07 23:35 [PATCH v2] add time_now_after and other macros which compare with jiffies Dave Young
@ 2008-03-08 16:12 ` Johannes Weiner
2008-03-09 0:54 ` Dave Young
0 siblings, 1 reply; 12+ messages in thread
From: Johannes Weiner @ 2008-03-08 16:12 UTC (permalink / raw)
To: Dave Young; +Cc: akpm, linux-kernel
Hi Dave, Andrew and all
Dave Young <hidave.darkstar@gmail.com> writes:
> +/* time_now_after(a) return true if now (jiffies) is after a */
> +#define time_now_after(a) time_after(jiffies, a)
> +
> +/* time_now_before(a) return true if now (jiffies) is before a */
> +#define time_now_before(a) time_before(jiffies, a)
> +
> +/* time_now_after_eq(a) return true if now (jiffies) is after or equal to a */
> +#define time_now_after_eq(a) time_after_eq(jiffies, a)
> +
> +/* time_now_before_eq(a) return true if now (jiffies) is before or equal to a */
> +#define time_now_before_eq(a) time_before_eq(jiffies, a)
How about even more obvious names like time_is_past(), time_is_future(),
...?
Sorry, I missed v1. Should have proposed that earlier.
Hannes
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH v2] add time_now_after and other macros which compare with jiffies
2008-03-08 16:12 ` Johannes Weiner
@ 2008-03-09 0:54 ` Dave Young
2008-03-09 9:58 ` Alan Cox
0 siblings, 1 reply; 12+ messages in thread
From: Dave Young @ 2008-03-09 0:54 UTC (permalink / raw)
To: Johannes Weiner; +Cc: akpm, linux-kernel
On Sun, Mar 9, 2008 at 12:12 AM, Johannes Weiner <hannes@saeurebad.de> wrote:
> Hi Dave, Andrew and all
>
>
> Dave Young <hidave.darkstar@gmail.com> writes:
>
> > +/* time_now_after(a) return true if now (jiffies) is after a */
> > +#define time_now_after(a) time_after(jiffies, a)
> > +
> > +/* time_now_before(a) return true if now (jiffies) is before a */
> > +#define time_now_before(a) time_before(jiffies, a)
> > +
> > +/* time_now_after_eq(a) return true if now (jiffies) is after or equal to a */
> > +#define time_now_after_eq(a) time_after_eq(jiffies, a)
> > +
> > +/* time_now_before_eq(a) return true if now (jiffies) is before or equal to a */
> > +#define time_now_before_eq(a) time_before_eq(jiffies, a)
>
> How about even more obvious names like time_is_past(), time_is_future(),
> ...?
Thanks for comment.
Then how do we name the _eq version? IMHO, the time_now_* is enough.
>
> Sorry, I missed v1. Should have proposed that earlier.
>
> Hannes
>
Regards
dave
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH v2] add time_now_after and other macros which compare with jiffies
2008-03-09 0:54 ` Dave Young
@ 2008-03-09 9:58 ` Alan Cox
2008-03-09 10:44 ` Dave Young
2008-03-09 18:36 ` Andrew Morton
0 siblings, 2 replies; 12+ messages in thread
From: Alan Cox @ 2008-03-09 9:58 UTC (permalink / raw)
To: Dave Young; +Cc: Johannes Weiner, akpm, linux-kernel
> > > +/* time_now_before_eq(a) return true if now (jiffies) is before or equal to a */
> > > +#define time_now_before_eq(a) time_before_eq(jiffies, a)
> >
> > How about even more obvious names like time_is_past(), time_is_future(),
> > ...?
>
> Thanks for comment.
>
> Then how do we name the _eq version? IMHO, the time_now_* is enough.
Why do you even need them. I don't see the point of *any* of these extra
macros as they simply obfuscate code and hide what is actually going on.
The initial macros were added because of the type safety and correct
comparison rules being complex. They have a purpose.
Even if you want these you can use !time_future() if you don't want the
_eq variants. Generally speaking drivers should be using timers not
polled loops, and most of our loops comparing with jiffies want removing.
Alan
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH v2] add time_now_after and other macros which compare with jiffies
2008-03-09 9:58 ` Alan Cox
@ 2008-03-09 10:44 ` Dave Young
2008-03-09 11:08 ` Alan Cox
2008-03-09 18:36 ` Andrew Morton
1 sibling, 1 reply; 12+ messages in thread
From: Dave Young @ 2008-03-09 10:44 UTC (permalink / raw)
To: Alan Cox; +Cc: Johannes Weiner, akpm, linux-kernel
On 3/9/08, Alan Cox <alan@lxorguk.ukuu.org.uk> wrote:
> > > > +/* time_now_before_eq(a) return true if now (jiffies) is before or equal to a */
> > > > +#define time_now_before_eq(a) time_before_eq(jiffies, a)
> > >
> > > How about even more obvious names like time_is_past(), time_is_future(),
> > > ...?
> >
> > Thanks for comment.
> >
> > Then how do we name the _eq version? IMHO, the time_now_* is enough.
>
>
> Why do you even need them. I don't see the point of *any* of these extra
> macros as they simply obfuscate code and hide what is actually going on.
> The initial macros were added because of the type safety and correct
> comparison rules being complex. They have a purpose.
Yes, This has a purpose as well. You will find most of the usage of these
macros are just compare some value with jiffies after doing some grep.
For these cases this adding will easy use and understand.
>
> Even if you want these you can use !time_future() if you don't want the
> _eq variants. Generally speaking drivers should be using timers not
> polled loops, and most of our loops comparing with jiffies want removing.
>
IMO time_after is a confusing name actually, If I don't read the comment I
will think it as time_future
To some extent I agree with you that the timer will be better.
>
> Alan
>
Thanks
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH v2] add time_now_after and other macros which compare with jiffies
2008-03-09 10:44 ` Dave Young
@ 2008-03-09 11:08 ` Alan Cox
2008-03-09 19:01 ` Andrew Morton
0 siblings, 1 reply; 12+ messages in thread
From: Alan Cox @ 2008-03-09 11:08 UTC (permalink / raw)
To: Dave Young; +Cc: Johannes Weiner, akpm, linux-kernel
> Yes, This has a purpose as well. You will find most of the usage of these
> macros are just compare some value with jiffies after doing some grep.
That is no reason to add more macros that hide how they do it, or make
jiffies itself invisible to the grep search or variable usage finding
tools (and for tickless that very thing is important)
> For these cases this adding will easy use and understand.
It hides information.
Alan
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH v2] add time_now_after and other macros which compare with jiffies
2008-03-09 9:58 ` Alan Cox
2008-03-09 10:44 ` Dave Young
@ 2008-03-09 18:36 ` Andrew Morton
2008-03-09 20:03 ` Alan Cox
1 sibling, 1 reply; 12+ messages in thread
From: Andrew Morton @ 2008-03-09 18:36 UTC (permalink / raw)
To: Alan Cox; +Cc: Dave Young, Johannes Weiner, linux-kernel
On Sun, 9 Mar 2008 09:58:02 +0000 Alan Cox <alan@lxorguk.ukuu.org.uk> wrote:
> > > > +/* time_now_before_eq(a) return true if now (jiffies) is before or equal to a */
> > > > +#define time_now_before_eq(a) time_before_eq(jiffies, a)
> > >
> > > How about even more obvious names like time_is_past(), time_is_future(),
> > > ...?
> >
> > Thanks for comment.
> >
> > Then how do we name the _eq version? IMHO, the time_now_* is enough.
>
> Why do you even need them. I don't see the point of *any* of these extra
> macros as they simply obfuscate code and hide what is actually going on.
Two reasons:
a) the existing macros are (I believe) a right royal pita. It's very
hard to remember which order the args are supposed to be in.
So each time I see a time_foo() when reviewing a patch I have to go
off and re-read the implementation then have a big think to check that
they got it right (a sure sign of a poor interface, no)?
And I'm not the only one - people get this wrong fairly regularly.
b) around 90% of the usages of time_after() are to compare against jiffies!
The macros which Dave is developing aren't just less-error-prone,
easier-to-review transformations - they offer higher-level functionality.
Because time_after() is just a basic comparison operation, whereas
time_now_before() is an *application* of that operation.
Trust me on this - they will lead to easier-to-review code and less bugs.
> The initial macros were added because of the type safety and correct
> comparison rules being complex. They have a purpose.
They are hard to use and hard to review.
> Even if you want these you can use !time_future() if you don't want the
> _eq variants. Generally speaking drivers should be using timers not
> polled loops, and most of our loops comparing with jiffies want removing.
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH v2] add time_now_after and other macros which compare with jiffies
2008-03-09 11:08 ` Alan Cox
@ 2008-03-09 19:01 ` Andrew Morton
2008-03-09 20:06 ` Alan Cox
2008-03-10 2:03 ` Dave Young
0 siblings, 2 replies; 12+ messages in thread
From: Andrew Morton @ 2008-03-09 19:01 UTC (permalink / raw)
To: Alan Cox; +Cc: Dave Young, Johannes Weiner, linux-kernel
On Sun, 9 Mar 2008 11:08:08 +0000 Alan Cox <alan@lxorguk.ukuu.org.uk> wrote:
> > Yes, This has a purpose as well. You will find most of the usage of these
> > macros are just compare some value with jiffies after doing some grep.
>
> That is no reason to add more macros that hide how they do it, or make
> jiffies itself invisible to the grep search or variable usage finding
> tools (and for tickless that very thing is important)
We could call them time_is_after_jiffies(), time_is_before_jiffies(), etc.
Those names are actually better than time_after_now(), etc.
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH v2] add time_now_after and other macros which compare with jiffies
2008-03-09 18:36 ` Andrew Morton
@ 2008-03-09 20:03 ` Alan Cox
0 siblings, 0 replies; 12+ messages in thread
From: Alan Cox @ 2008-03-09 20:03 UTC (permalink / raw)
To: Andrew Morton; +Cc: Dave Young, Johannes Weiner, linux-kernel
> a) the existing macros are (I believe) a right royal pita. It's very
> hard to remember which order the args are supposed to be in.
Its operator(first, second) - the C++ infix operators aren't available in
C so there isn't much choice.
Really we should be trying to stamp out all these uses of jiffies tests
so that we can make tickless work ever better.
Alan
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH v2] add time_now_after and other macros which compare with jiffies
2008-03-09 19:01 ` Andrew Morton
@ 2008-03-09 20:06 ` Alan Cox
2008-03-10 2:03 ` Dave Young
1 sibling, 0 replies; 12+ messages in thread
From: Alan Cox @ 2008-03-09 20:06 UTC (permalink / raw)
To: Andrew Morton; +Cc: Dave Young, Johannes Weiner, linux-kernel
> We could call them time_is_after_jiffies(), time_is_before_jiffies(), etc.
>
> Those names are actually better than time_after_now(), etc.
Agreed - and if you think its worth doing I bow to your expertise on
buggy patch submissions..
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH v2] add time_now_after and other macros which compare with jiffies
2008-03-09 19:01 ` Andrew Morton
2008-03-09 20:06 ` Alan Cox
@ 2008-03-10 2:03 ` Dave Young
2008-03-10 2:41 ` Johannes Weiner
1 sibling, 1 reply; 12+ messages in thread
From: Dave Young @ 2008-03-10 2:03 UTC (permalink / raw)
To: Andrew Morton; +Cc: Alan Cox, Johannes Weiner, linux-kernel
On Mon, Mar 10, 2008 at 3:01 AM, Andrew Morton
<akpm@linux-foundation.org> wrote:
> On Sun, 9 Mar 2008 11:08:08 +0000 Alan Cox <alan@lxorguk.ukuu.org.uk> wrote:
>
> > > Yes, This has a purpose as well. You will find most of the usage of these
> > > macros are just compare some value with jiffies after doing some grep.
> >
> > That is no reason to add more macros that hide how they do it, or make
> > jiffies itself invisible to the grep search or variable usage finding
> > tools (and for tickless that very thing is important)
>
> We could call them time_is_after_jiffies(), time_is_before_jiffies(), etc.
>
> Those names are actually better than time_after_now(), etc.
>
>
Andrew, Hannes, Alan,
thanks for your comment, I have send the new time_is_* patch as v3.
Hannes, It's more like your is_past/is_future but looks better when
along with _eq
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH v2] add time_now_after and other macros which compare with jiffies
2008-03-10 2:03 ` Dave Young
@ 2008-03-10 2:41 ` Johannes Weiner
0 siblings, 0 replies; 12+ messages in thread
From: Johannes Weiner @ 2008-03-10 2:41 UTC (permalink / raw)
To: Dave Young; +Cc: Andrew Morton, Alan Cox, linux-kernel
Hi Dave,
"Dave Young" <hidave.darkstar@gmail.com> writes:
> Hannes, It's more like your is_past/is_future but looks better when
> along with _eq
I agree. And it's better to have `jiffies' in the names, anyway.
Hannes
^ permalink raw reply [flat|nested] 12+ messages in thread
end of thread, other threads:[~2008-03-10 2:43 UTC | newest]
Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-03-07 23:35 [PATCH v2] add time_now_after and other macros which compare with jiffies Dave Young
2008-03-08 16:12 ` Johannes Weiner
2008-03-09 0:54 ` Dave Young
2008-03-09 9:58 ` Alan Cox
2008-03-09 10:44 ` Dave Young
2008-03-09 11:08 ` Alan Cox
2008-03-09 19:01 ` Andrew Morton
2008-03-09 20:06 ` Alan Cox
2008-03-10 2:03 ` Dave Young
2008-03-10 2:41 ` Johannes Weiner
2008-03-09 18:36 ` Andrew Morton
2008-03-09 20:03 ` Alan Cox
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).