Re: [RFC] mod_timer() helper functions?

From: Andi Kleen
Date: Mon May 18 2009 - 03:14:42 EST


Chris Peterson <cpeterso@xxxxxxxxxxxx> writes:
>
> Any suggestions? Is there enough value to warrant adding helper
> function like these as an alternative to mod_timer()?

I like the basic idea. The opencoding has always annoyed me.
>
>
> chris
>
> ---
> static inline int mod_timer_seconds(struct timer_list *timer, time_t seconds)

I would prefer a name like mod_timer_in_secs() to make it clear it's relative

> {
> return mod_timer(timer, round_jiffies(jiffies + seconds * HZ));
> }

>
> static inline int mod_timer_msecs(struct timer_list *timer, unsigned int msecs)
> {
> /* TODO? Round jiffies if within some epsilon of a whole second? */
> return mod_timer(timer, jiffies + msecs_to_jiffies(msecs));

This is a bit misleading because depending on HZ the accuracy is far from
a millisecond (worst case 10ms error with HZ==100). Naming should make
that clearer. Or maybe these users should all switch to hrtimers,
but then those could be not available either.

I suspect you also want a helper for longer term delays that uses
deferred timers or more aggressive rounding.


> }
>
> static inline int mod_timer_yield(struct timer_list *timer)
> {
> /* After these messages, we'll be right back. */
> return mod_timer(timer, jiffies + 1);

Can't say I like the name here, although I don't have a better one.

-Andi

--
ak@xxxxxxxxxxxxxxx -- Speaking for myself only.
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/