mirror of
https://github.com/torvalds/linux.git
synced 2024-11-02 10:11:36 +00:00
1337173148
The current implementations of __ndelay and __udelay call a hypervisor service to delay, but the hypervisor service isn't actually implemented very well, and the consensus is that Linux should handle figuring this out natively and not use a hypervisor service. By converting nanoseconds to cycles, and then spinning until the cycle counter reaches the desired cycle, we get several benefits: first, we are sensitive to the actual clock speed; second, we use less power by issuing a slow SPR read once every six cycles while we delay; and third, we properly handle the case of an interrupt by exiting at the target time rather than after some number of cycles. Signed-off-by: Chris Metcalf <cmetcalf@tilera.com>
46 lines
1.2 KiB
C
46 lines
1.2 KiB
C
/*
|
|
* Copyright 2010 Tilera Corporation. All Rights Reserved.
|
|
*
|
|
* This program is free software; you can redistribute it and/or
|
|
* modify it under the terms of the GNU General Public License
|
|
* as published by the Free Software Foundation, version 2.
|
|
*
|
|
* This program is distributed in the hope that it will be useful, but
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
|
|
* NON INFRINGEMENT. See the GNU General Public License for
|
|
* more details.
|
|
*/
|
|
|
|
#include <linux/module.h>
|
|
#include <linux/delay.h>
|
|
#include <linux/thread_info.h>
|
|
#include <asm/timex.h>
|
|
|
|
void __udelay(unsigned long usecs)
|
|
{
|
|
if (usecs > ULONG_MAX / 1000) {
|
|
WARN_ON_ONCE(usecs > ULONG_MAX / 1000);
|
|
usecs = ULONG_MAX / 1000;
|
|
}
|
|
__ndelay(usecs * 1000);
|
|
}
|
|
EXPORT_SYMBOL(__udelay);
|
|
|
|
void __ndelay(unsigned long nsecs)
|
|
{
|
|
cycles_t target = get_cycles();
|
|
target += ns2cycles(nsecs);
|
|
while (get_cycles() < target)
|
|
cpu_relax();
|
|
}
|
|
EXPORT_SYMBOL(__ndelay);
|
|
|
|
void __delay(unsigned long cycles)
|
|
{
|
|
cycles_t target = get_cycles() + cycles;
|
|
while (get_cycles() < target)
|
|
cpu_relax();
|
|
}
|
|
EXPORT_SYMBOL(__delay);
|