mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Chris Peterson <cpeterso@cpeterso.com>
To: Andi Kleen <andi@firstfloor.org>
Cc: linux-kernel@vger.kernel.org, tglx@linutronix.de
Subject: Re: [RFC] mod_timer() helper functions?
Date: Wed, 20 May 2009 00:11:37 -0700	[thread overview]
Message-ID: <a24804730905200011l202733abh89f5d4feaf69610e@mail.gmail.com> (raw)
In-Reply-To: <87eiumq3w2.fsf@basil.nowhere.org>

How about something like these helper functions?

The function names "timer_settime_msecs()" and "timer_settime_secs()"
are not fantastic, but they are inspired by the precedent set by the
POSIX Realtime function timer_settime().


/**
 * timer_settime_msecs - modify a timer's timeout
 * @timer: the timer to be modified
 * @msecs: minimum time in milliseconds to sleep for
 */
int timer_settime_msecs(struct timer_list *timer, int msecs)
{
	unsigned long expires = jiffies + msecs_to_jiffies(msecs);

	/* TODO? round_jiffies() if msecs parameter is large, say >= ~5000? */
        /* If people don't mind if timer_settime_msecs() rounds to
whole seconds, then timer_settime_secs() might be unnecessary. */

	return mod_timer(timer, expires);
}


/**
 * timer_settime_secs - modify a timer's timeout
 * @timer: the timer to be modified
 * @secs: approximate time in seconds to sleep for
 */
int timer_settime_secs(struct timer_list *timer, time_t secs)
{
	unsigned long expires = jiffies + (secs * HZ);

	/* If the caller doesn't mind waiting multiple seconds, then
	 * feel free to round up to whole seconds (to reduce wakeups).
	 */
	if (secs >= 2)
		expires = round_jiffies_up(expires);

	return mod_timer(timer, expires);
}

  reply	other threads:[~2009-05-20  7:11 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-05-16  7:36 Chris Peterson
2009-05-17  6:03 ` Andrew Morton
2009-05-17  7:50   ` Chris Peterson
2009-05-17  8:03     ` Andrew Morton
2009-05-17 12:13       ` Thomas Gleixner
2009-05-18  7:14 ` Andi Kleen
2009-05-20  7:11   ` Chris Peterson [this message]
2009-05-20  8:14     ` Andi Kleen
2009-05-21  5:11       ` Chris Peterson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=a24804730905200011l202733abh89f5d4feaf69610e@mail.gmail.com \
    --to=cpeterso@cpeterso.com \
    --cc=andi@firstfloor.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=tglx@linutronix.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®