Release 4.10 arch/x86/lib/delay.c
/*
* Precise Delay Loops for i386
*
* Copyright (C) 1993 Linus Torvalds
* Copyright (C) 1997 Martin Mares <mj@atrey.karlin.mff.cuni.cz>
* Copyright (C) 2008 Jiri Hladky <hladky _dot_ jiri _at_ gmail _dot_ com>
*
* The __delay function must _NOT_ be inlined as its execution time
* depends wildly on alignment on many x86 processors. The additional
* jump magic is needed to get the timing stable on all the CPU's
* we have to worry about.
*/
#include <linux/export.h>
#include <linux/sched.h>
#include <linux/timex.h>
#include <linux/preempt.h>
#include <linux/delay.h>
#include <asm/processor.h>
#include <asm/delay.h>
#include <asm/timer.h>
#include <asm/mwait.h>
#ifdef CONFIG_SMP
# include <asm/smp.h>
#endif
/* simple loop based delay: */
static void delay_loop(unsigned long loops)
{
asm volatile(
" test %0,%0 \n"
" jz 3f \n"
" jmp 1f \n"
".align 16 \n"
"1: jmp 2f \n"
".align 16 \n"
"2: dec %0 \n"
" jnz 2b \n"
"3: dec %0 \n"
: /* we don't need output */
:"a" (loops)
);
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
john stultz | john stultz | 10 | 66.67% | 1 | 25.00% |
glauber de oliveira costa | glauber de oliveira costa | 3 | 20.00% | 2 | 50.00% |
jiri hladky | jiri hladky | 2 | 13.33% | 1 | 25.00% |
| Total | 15 | 100.00% | 4 | 100.00% |
/* TSC based delay: */
static void delay_tsc(unsigned long __loops)
{
u64 bclock, now, loops = __loops;
int cpu;
preempt_disable();
cpu = smp_processor_id();
bclock = rdtsc_ordered();
for (;;) {
now = rdtsc_ordered();
if ((now - bclock) >= loops)
break;
/* Allow RT tasks to run */
preempt_enable();
rep_nop();
preempt_disable();
/*
* It is possible that we moved to another CPU, and
* since TSC's are per-cpu we need to calculate
* that. The delay must guarantee that we wait "at
* least" the amount of time. Being moved to another
* CPU could make the wait longer but we just need to
* make sure we waited long enough. Rebalance the
* counter for this CPU.
*/
if (unlikely(cpu != smp_processor_id())) {
loops -= (now - bclock);
cpu = smp_processor_id();
bclock = rdtsc_ordered();
}
}
preempt_enable();
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
steven rostedt | steven rostedt | 54 | 52.94% | 1 | 12.50% |
john stultz | john stultz | 25 | 24.51% | 1 | 12.50% |
andy lutomirski | andy lutomirski | 10 | 9.80% | 2 | 25.00% |
andrew morton | andrew morton | 6 | 5.88% | 1 | 12.50% |
thomas gleixner | thomas gleixner | 5 | 4.90% | 1 | 12.50% |
venkatesh pallipadi | venkatesh pallipadi | 1 | 0.98% | 1 | 12.50% |
pre-git | pre-git | 1 | 0.98% | 1 | 12.50% |
| Total | 102 | 100.00% | 8 | 100.00% |
/*
* On some AMD platforms, MWAITX has a configurable 32-bit timer, that
* counts with TSC frequency. The input value is the loop of the
* counter, it will exit when the timer expires.
*/
static void delay_mwaitx(unsigned long __loops)
{
u64 start, end, delay, loops = __loops;
start = rdtsc_ordered();
for (;;) {
delay = min_t(u64, MWAITX_MAX_LOOPS, loops);
/*
* Use cpu_tss as a cacheline-aligned, seldomly
* accessed per-cpu variable as the monitor target.
*/
__monitorx(raw_cpu_ptr(&cpu_tss), 0, 0);
/*
* AMD, like Intel, supports the EAX hint and EAX=0xf
* means, do not enter any deep C-state and we use it
* here in delay() to minimize wakeup latency.
*/
__mwaitx(MWAITX_DISABLE_CSTATES, delay, MWAITX_ECX_TIMER_ENABLE);
end = rdtsc_ordered();
if (loops <= end - start)
break;
loops -= end - start;
start = end;
}
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
huang rui | huang rui | 91 | 98.91% | 1 | 50.00% |
borislav petkov | borislav petkov | 1 | 1.09% | 1 | 50.00% |
| Total | 92 | 100.00% | 2 | 100.00% |
/*
* Since we calibrate only once at boot, this
* function should be set once at boot and not changed
*/
static void (*delay_fn)(unsigned long) = delay_loop;
void use_tsc_delay(void)
{
if (delay_fn == delay_loop)
delay_fn = delay_tsc;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
john stultz | john stultz | 11 | 64.71% | 1 | 50.00% |
huang rui | huang rui | 6 | 35.29% | 1 | 50.00% |
| Total | 17 | 100.00% | 2 | 100.00% |
void use_mwaitx_delay(void)
{
delay_fn = delay_mwaitx;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
huang rui | huang rui | 11 | 100.00% | 1 | 100.00% |
| Total | 11 | 100.00% | 1 | 100.00% |
int read_current_timer(unsigned long *timer_val)
{
if (delay_fn == delay_tsc) {
*timer_val = rdtsc();
return 0;
}
return -1;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
john stultz | john stultz | 28 | 90.32% | 1 | 33.33% |
andy lutomirski | andy lutomirski | 3 | 9.68% | 2 | 66.67% |
| Total | 31 | 100.00% | 3 | 100.00% |
void __delay(unsigned long loops)
{
delay_fn(loops);
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
pre-git | pre-git | 13 | 92.86% | 1 | 50.00% |
john stultz | john stultz | 1 | 7.14% | 1 | 50.00% |
| Total | 14 | 100.00% | 2 | 100.00% |
EXPORT_SYMBOL(__delay);
inline void __const_udelay(unsigned long xloops)
{
int d0;
xloops *= 4;
asm("mull %%edx"
:"=d" (xloops), "=&a" (d0)
:"1" (xloops), "0"
(this_cpu_read(cpu_info.loops_per_jiffy) * (HZ/4)));
__delay(++xloops);
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
pre-git | pre-git | 18 | 75.00% | 2 | 40.00% |
dominik brodowski | dominik brodowski | 5 | 20.83% | 2 | 40.00% |
christoph lameter | christoph lameter | 1 | 4.17% | 1 | 20.00% |
| Total | 24 | 100.00% | 5 | 100.00% |
EXPORT_SYMBOL(__const_udelay);
void __udelay(unsigned long usecs)
{
__const_udelay(usecs * 0x000010c7); /* 2**32 / 1000000 (rounded up) */
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
pre-git | pre-git | 15 | 88.24% | 1 | 50.00% |
dominik brodowski | dominik brodowski | 2 | 11.76% | 1 | 50.00% |
| Total | 17 | 100.00% | 2 | 100.00% |
EXPORT_SYMBOL(__udelay);
void __ndelay(unsigned long nsecs)
{
__const_udelay(nsecs * 0x00005); /* 2**32 / 1000000000 (rounded up) */
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
alan cox | alan cox | 17 | 100.00% | 1 | 100.00% |
| Total | 17 | 100.00% | 1 | 100.00% |
EXPORT_SYMBOL(__ndelay);
Overall Contributors
| Person | Tokens | Prop | Commits | CommitProp |
huang rui | huang rui | 112 | 27.12% | 1 | 3.57% |
john stultz | john stultz | 96 | 23.24% | 2 | 7.14% |
pre-git | pre-git | 62 | 15.01% | 4 | 14.29% |
steven rostedt | steven rostedt | 54 | 13.08% | 1 | 3.57% |
glauber de oliveira costa | glauber de oliveira costa | 18 | 4.36% | 2 | 7.14% |
alan cox | alan cox | 17 | 4.12% | 1 | 3.57% |
andy lutomirski | andy lutomirski | 13 | 3.15% | 4 | 14.29% |
andrew morton | andrew morton | 12 | 2.91% | 2 | 7.14% |
dominik brodowski | dominik brodowski | 7 | 1.69% | 3 | 10.71% |
alexey dobriyan | alexey dobriyan | 7 | 1.69% | 1 | 3.57% |
thomas gleixner | thomas gleixner | 5 | 1.21% | 1 | 3.57% |
linus torvalds | linus torvalds | 3 | 0.73% | 1 | 3.57% |
jiri hladky | jiri hladky | 3 | 0.73% | 1 | 3.57% |
venkatesh pallipadi | venkatesh pallipadi | 1 | 0.24% | 1 | 3.57% |
christoph lameter | christoph lameter | 1 | 0.24% | 1 | 3.57% |
paul gortmaker | paul gortmaker | 1 | 0.24% | 1 | 3.57% |
borislav petkov | borislav petkov | 1 | 0.24% | 1 | 3.57% |
| Total | 413 | 100.00% | 28 | 100.00% |
Information contained on this website is for historical information purposes only and does not indicate or represent copyright ownership.