public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Denis Vlasenko <vda@ilport.com.ua>
To: Arjan van de Ven <arjan@infradead.org>
Cc: Andrew Morton <akpm@osdl.org>,
	Russell King <rmk+lkml@arm.linux.org.uk>,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH] deinline sleep/delay functions
Date: Thu, 30 Jun 2005 14:44:51 +0300	[thread overview]
Message-ID: <200506301444.51463.vda@ilport.com.ua> (raw)
In-Reply-To: <1120130573.3181.42.camel@laptopd505.fenrus.org>

On Thursday 30 June 2005 14:22, Arjan van de Ven wrote:
> 
> > An if(usec > 2000) { printk(..); dump_stack(); } will do.
> 
> that's runtime not compile time.
> The old situation was a compile time check which is far more powerful.

Ok I like compile checks too, it will stay.

But it won't help on accidental mdelay(some math) == mdelay(-1)
== mdelay(4 000 000 000), so we _also_ will have an if() inside
udelay(), ok?

On Thursday 30 June 2005 14:21, Russell King wrote:
> Yes.  udelay() has overflow issues - if you pass too large a number
> to udelay() you get a randomised delay because you've lost the top
> bits.

Thus [umn]delay may fail in unpredictable ways with non-const
parameter which is too big. And this is good exactly why?

I'm ok with making it fail, but _predictably_. With printk(),
trace, whatever.

> The maximum delay is dependent on the architecture implementation,
> and it depends on bogomips.  There is no one single value for it.
> Architectures have to decide this from the way that they do the
> math and the expected range of bogomips.

In example I posted these limitations are lifted. Granted these
limitations were not critical, but removing them can't do harm,
I guess?

> Please - leave asm-*/delay.h alone.

Let's see what udelay(const) will compile down to on ppc:

asm-ppc/delay.h
===============
extern unsigned long loops_per_jiffy;
extern void __delay(unsigned int loops);
...
#define __MAX_UDELAY    (226050910UL/HZ)        /* maximum udelay argument */
#define __MAX_NDELAY    (4294967295UL/HZ)       /* maximum ndelay argument */

extern __inline__ void __udelay(unsigned int x)
{
        unsigned int loops;

        __asm__("mulhwu %0,%1,%2" : "=r" (loops) :
                "r" (x), "r" (loops_per_jiffy * 226));
        __delay(loops);
}

extern __inline__ void __ndelay(unsigned int x)
{
        unsigned int loops;

        __asm__("mulhwu %0,%1,%2" : "=r" (loops) :
                "r" (x), "r" (loops_per_jiffy * 5));
        __delay(loops);
}

extern void __bad_udelay(void);         /* deliberately undefined */
extern void __bad_ndelay(void);         /* deliberately undefined */

#define udelay(n) (__builtin_constant_p(n)? \
        ((n) > __MAX_UDELAY? __bad_udelay(): __udelay((n) * (19 * HZ))) : \
        __udelay((n) * (19 * HZ)))

#define ndelay(n) (__builtin_constant_p(n)? \
        ((n) > __MAX_NDELAY? __bad_ndelay(): __ndelay((n) * HZ)) : \
        __ndelay((n) * HZ))

Thus:

	udelay(const) = loops_per_jiffy * 5; mulhwu thing; call to __delay()

While with proposed code:

	udelay(const) = call to udelay()

Which is smaller.
--
vda


  reply	other threads:[~2005-06-30 11:45 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-06-30  5:52 [PATCH] deinline sleep/delay functions Denis Vlasenko
2005-06-30  8:52 ` Russell King
2005-06-30  9:11   ` Andrew Morton
2005-06-30  9:19     ` Arjan van de Ven
2005-06-30 10:21       ` Denis Vlasenko
2005-06-30 10:47         ` Arjan van de Ven
2005-06-30 11:10           ` Denis Vlasenko
2005-06-30 11:21             ` Russell King
2005-06-30 11:22             ` Arjan van de Ven
2005-06-30 11:44               ` Denis Vlasenko [this message]
2005-06-30 11:57                 ` Maciej W. Rozycki
2005-06-30 12:04                 ` Russell King
2005-06-30 12:20                   ` Denis Vlasenko
2005-07-01  7:54           ` Vojtech Pavlik
2005-06-30  9:44     ` Russell King
2005-07-01  7:53 ` Vojtech Pavlik

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=200506301444.51463.vda@ilport.com.ua \
    --to=vda@ilport.com.ua \
    --cc=akpm@osdl.org \
    --cc=arjan@infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=rmk+lkml@arm.linux.org.uk \
    /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