All of lore.kernel.org
 help / color / mirror / Atom feed
From: Andy Whitcroft <apw@canonical.com>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: Patrick Pannuto <ppannuto@codeaurora.org>,
	Jonathan Corbet <corbet@lwn.net>,
	Israel Schlesinger <israels@codeaurora.org>,
	linux-kernel@vger.kernel.org, joe@perches.com,
	Thomas Gleixner <tglx@linutronix.de>, Ingo Molnar <mingo@elte.hu>
Subject: Re: [PATCH] checkpatch: Add warnings for use of mdelay()
Date: Wed, 28 Jul 2010 10:44:14 +0100	[thread overview]
Message-ID: <20100728094414.GA3586@shadowen.org> (raw)
In-Reply-To: <20100727121610.64b38cfa.akpm@linux-foundation.org>

On Tue, Jul 27, 2010 at 12:16:10PM -0700, Andrew Morton wrote:
> On Tue, 27 Jul 2010 10:32:54 -0700
> Patrick Pannuto <ppannuto@codeaurora.org> wrote:
> 
> > On 07/27/2010 10:31 AM, Jonathan Corbet wrote:
> > > On Tue, 27 Jul 2010 10:11:11 -0700
> > > Israel Schlesinger <israels@codeaurora.org> wrote:
> > > 
> > >> mdelay is a busy-wait loop which is wasteful. If at all possible,
> > >> callers should use msleep instead of mdelay.
> > >>
> > >> The only time mdelay is really appropriate is in atomic context,
> > >> however, delays of 1ms+ in atomic context are rather expensive, so
> > >> a warning for this case is probably appropriate as well to encourage
> > >> people to move such expensive delays outside of atomic context
> > > 
> > > Once upon a time, msleep(1) would sleep for 20ms, while mdelay(1) gave
> > > a 1ms delay.  My patch to fix msleep() at that time didn't get in due
> > > to concerns about the cost of using hrtimers.  Perhaps msleep() has
> > > gotten better, but, if not, actually getting a 1ms delay remains a
> > > valid reason for using mdelay() instead IMO.  It made a difference of a
> > > few seconds at open time for a driver I was doing at the time.
> > > 
> > > jon
> > > --
> > > To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> > > the body of a message to majordomo@vger.kernel.org
> > > More majordomo info at  http://vger.kernel.org/majordomo-info.html
> > > Please read the FAQ at  http://www.tux.org/lkml/
> > 
> > Check out the recently added usleep in -tip, and the checkpatch patch
> > pending in my queue that fixes that case (I'll send in a few hours ;) )
> > 
> 
> The message should point people at usleep_range(), I'd suggest.  It's a
> more power-friendly way of sleeping.
> 
> That assumes that the below patch gets merged - the people who handle
> timer-related things are presently, err, asleep.
> 
> 
> From: Patrick Pannuto <ppannuto@codeaurora.org>
> 
> usleep[_range] are finer precision implementations of msleep and are
> designed to be drop-in replacements for udelay where a precise sleep /
> busy-wait is unnecessary.  They also allow an easy interface to specify
> slack when a precise (ish) wakeup is unnecessary to help minimize wakeups
> 
> Signed-off-by: Patrick Pannuto <ppannuto@codeaurora.org>
> Acked-by: Arjan van de Ven <arjan@linux.intel.com>
> Cc: Ingo Molnar <mingo@elte.hu>
> Cc: Thomas Gleixner <tglx@linutronix.de>
> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
> ---
> 
>  include/linux/delay.h |    6 ++++++
>  kernel/timer.c        |   22 ++++++++++++++++++++++
>  2 files changed, 28 insertions(+)
> 
> diff -puN include/linux/delay.h~timers-add-usleep-timer include/linux/delay.h
> --- a/include/linux/delay.h~timers-add-usleep-timer
> +++ a/include/linux/delay.h
> @@ -45,6 +45,12 @@ extern unsigned long lpj_fine;
>  void calibrate_delay(void);
>  void msleep(unsigned int msecs);
>  unsigned long msleep_interruptible(unsigned int msecs);
> +void usleep_range(unsigned long min, unsigned long max);
> +
> +static inline void usleep(unsigned long usecs)
> +{
> +	usleep_range(usecs, usecs);
> +}
>  
>  static inline void ssleep(unsigned int seconds)
>  {
> diff -puN kernel/timer.c~timers-add-usleep-timer kernel/timer.c
> --- a/kernel/timer.c~timers-add-usleep-timer
> +++ a/kernel/timer.c
> @@ -1763,3 +1763,25 @@ unsigned long msleep_interruptible(unsig
>  }
>  
>  EXPORT_SYMBOL(msleep_interruptible);
> +
> +static int __sched do_usleep_range(unsigned long min, unsigned long max)
> +{
> +	ktime_t kmin;
> +	unsigned long delta;
> +
> +	kmin = ktime_set(0, min * NSEC_PER_USEC);
> +	delta = max - min;

If this interface is taking a min and max in micro-seconds, then does
not the delta need also to be converted to nano-seconds?

schedule_hrtimeout_range seems to call hrtimer_set_expires_range_ns
which seems to generally be called with 'delta_ns'.  Something like:

delta = (max - min) * NSEC_PER_USEC;

> +	return schedule_hrtimeout_range(&kmin, delta, HRTIMER_MODE_REL);
> +}
> +
> +/**
> + * usleep_range - Drop in replacement for udelay where wakeup is flexible
> + * @min: Minimum time in usecs to sleep
> + * @max: Maximum time in usecs to sleep
> + */
> +void usleep_range(unsigned long min, unsigned long max)
> +{
> +	__set_current_state(TASK_UNINTERRUPTIBLE);
> +	do_usleep_range(min, max);
> +}
> +EXPORT_SYMBOL(usleep_range);

-apw

  reply	other threads:[~2010-07-28  9:44 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-07-27 17:11 [PATCH] checkpatch: Add warnings for use of mdelay() Israel Schlesinger
2010-07-27 17:22 ` Joe Perches
2010-07-27 17:31 ` Jonathan Corbet
2010-07-27 17:32   ` Patrick Pannuto
2010-07-27 19:16     ` Andrew Morton
2010-07-28  9:44       ` Andy Whitcroft [this message]
  -- strict thread matches above, loose matches on Subject: below --
2018-07-04 18:18 Prakruthi Deepak Heragu
2018-07-04 18:30 ` Joe Perches
2018-07-05  8:19   ` Dan Carpenter
2018-07-06  5:49     ` Julia Lawall
2018-07-07 12:09       ` Jia-Ju Bai

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=20100728094414.GA3586@shadowen.org \
    --to=apw@canonical.com \
    --cc=akpm@linux-foundation.org \
    --cc=corbet@lwn.net \
    --cc=israels@codeaurora.org \
    --cc=joe@perches.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@elte.hu \
    --cc=ppannuto@codeaurora.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.