Skip to content
Snippets Groups Projects
Select Git revision
  • 2f51c8204ab3ea211ac92f3b7b88a38595ed6412
  • vme-testing default
  • ci-test
  • master
  • remoteproc
  • am625-sk-ov5640
  • pcal6534-upstreaming
  • lps22df-upstreaming
  • msc-upstreaming
  • imx8mp
  • iio/noa1305
  • vme-next
  • vme-next-4.14-rc4
  • v4.14-rc4
  • v4.14-rc3
  • v4.14-rc2
  • v4.14-rc1
  • v4.13
  • vme-next-4.13-rc7
  • v4.13-rc7
  • v4.13-rc6
  • v4.13-rc5
  • v4.13-rc4
  • v4.13-rc3
  • v4.13-rc2
  • v4.13-rc1
  • v4.12
  • v4.12-rc7
  • v4.12-rc6
  • v4.12-rc5
  • v4.12-rc4
  • v4.12-rc3
32 results

delay.c

Blame
  • delay.c 3.74 KiB
    /*
     *	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/module.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)
    	);
    }
    
    /* 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