mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Glauber Costa <gcosta@redhat.com>
To: linux-kernel@vger.kernel.org
Cc: tglx@linutronix.de, mingo@elte.hu, x86@kernel.org
Subject: [PATCH 05/39] integrate delay functions
Date: Fri, 27 Jun 2008 18:34:12 -0300	[thread overview]
Message-ID: <1214602486-17080-6-git-send-email-gcosta@redhat.com> (raw)
In-Reply-To: <1214602486-17080-5-git-send-email-gcosta@redhat.com>

delay_32.c, delay_64.c are now equal, and are integrated into delay.c

Signed-off-by: Glauber Costa <gcosta@redhat.com>
---
 arch/x86/lib/Makefile   |    2 +-
 arch/x86/lib/delay.c    |  137 ++++++++++++++++++++++++++++++++++++++++++++++
 arch/x86/lib/delay_32.c |  138 -----------------------------------------------
 arch/x86/lib/delay_64.c |  128 -------------------------------------------
 4 files changed, 138 insertions(+), 267 deletions(-)
 create mode 100644 arch/x86/lib/delay.c
 delete mode 100644 arch/x86/lib/delay_32.c
 delete mode 100644 arch/x86/lib/delay_64.c

diff --git a/arch/x86/lib/Makefile b/arch/x86/lib/Makefile
index 84aa288..700c2c3 100644
--- a/arch/x86/lib/Makefile
+++ b/arch/x86/lib/Makefile
@@ -4,7 +4,7 @@
 
 obj-$(CONFIG_SMP) := msr-on-cpu.o
 
-lib-y := delay_$(BITS).o
+lib-y := delay.o
 lib-y += thunk_$(BITS).o
 lib-y += usercopy_$(BITS).o getuser_$(BITS).o putuser_$(BITS).o
 lib-y += memcpy_$(BITS).o
diff --git a/arch/x86/lib/delay.c b/arch/x86/lib/delay.c
new file mode 100644
index 0000000..f456860
--- /dev/null
+++ b/arch/x86/lib/delay.c
@@ -0,0 +1,137 @@
+/*
+ *	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 <linux/init.h>
+
+#include <asm/processor.h>
+#include <asm/delay.h>
+#include <asm/timer.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)
+{
+	unsigned long bclock, now;
+	int cpu;
+
+	preempt_disable();
+	cpu = smp_processor_id();
+	rdtscl(bclock);
+	for (;;) {
+		rdtscl(now);
+		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();
+			rdtscl(bclock);
+		}
+	}
+	preempt_enable();
+}
+
+/*
+ * 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)
+{
+	delay_fn = delay_tsc;
+}
+
+int __devinit read_current_timer(unsigned long *timer_val)
+{
+	if (delay_fn == delay_tsc) {
+		rdtscll(*timer_val);
+		return 0;
+	}
+	return -1;
+}
+
+void __delay(unsigned long loops)
+{
+	delay_fn(loops);
+}
+EXPORT_SYMBOL(__delay);
+
+inline void __const_udelay(unsigned long xloops)
+{
+	int d0;
+
+	xloops *= 4;
+	asm("mull %%edx"
+		:"=d" (xloops), "=&a" (d0)
+		:"1" (xloops), "0"
+		(cpu_data(raw_smp_processor_id()).loops_per_jiffy * (HZ/4)));
+
+	__delay(++xloops);
+}
+EXPORT_SYMBOL(__const_udelay);
+
+void __udelay(unsigned long usecs)
+{
+	__const_udelay(usecs * 0x000010c7); /* 2**32 / 1000000 (rounded up) */
+}
+EXPORT_SYMBOL(__udelay);
+
+void __ndelay(unsigned long nsecs)
+{
+	__const_udelay(nsecs * 0x00005); /* 2**32 / 1000000000 (rounded up) */
+}
+EXPORT_SYMBOL(__ndelay);
diff --git a/arch/x86/lib/delay_32.c b/arch/x86/lib/delay_32.c
deleted file mode 100644
index 0b659a3..0000000
--- a/arch/x86/lib/delay_32.c
+++ /dev/null
@@ -1,138 +0,0 @@
-/*
- *	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 <linux/init.h>
-
-#include <asm/processor.h>
-#include <asm/delay.h>
-#include <asm/timer.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)
-{
-	unsigned long bclock, now;
-	int cpu;
-
-	preempt_disable();
-	cpu = smp_processor_id();
-	rdtscl(bclock);
-	for (;;) {
-		rdtscl(now);
-		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();
-			rdtscl(bclock);
-		}
-	}
-	preempt_enable();
-}
-
-/*
- * 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)
-{
-	delay_fn = delay_tsc;
-}
-
-int __devinit read_current_timer(unsigned long *timer_val)
-{
-	if (delay_fn == delay_tsc) {
-		rdtscll(*timer_val);
-		return 0;
-	}
-	return -1;
-}
-
-void __delay(unsigned long loops)
-{
-	delay_fn(loops);
-}
-
-inline void __const_udelay(unsigned long xloops)
-{
-	int d0;
-
-	xloops *= 4;
-	__asm__("mull %%edx"
-		:"=d" (xloops), "=&a" (d0)
-		:"1" (xloops), "0"
-		(cpu_data(raw_smp_processor_id()).loops_per_jiffy * (HZ/4)));
-
-	__delay(++xloops);
-}
-
-void __udelay(unsigned long usecs)
-{
-	__const_udelay(usecs * 0x000010c7); /* 2**32 / 1000000 (rounded up) */
-}
-
-void __ndelay(unsigned long nsecs)
-{
-	__const_udelay(nsecs * 0x00005); /* 2**32 / 1000000000 (rounded up) */
-}
-
-EXPORT_SYMBOL(__delay);
-EXPORT_SYMBOL(__const_udelay);
-EXPORT_SYMBOL(__udelay);
-EXPORT_SYMBOL(__ndelay);
diff --git a/arch/x86/lib/delay_64.c b/arch/x86/lib/delay_64.c
deleted file mode 100644
index ff3dfec..0000000
--- a/arch/x86/lib/delay_64.c
+++ /dev/null
@@ -1,128 +0,0 @@
-/*
- *	Precise Delay Loops for x86-64
- *
- *	Copyright (C) 1993 Linus Torvalds
- *	Copyright (C) 1997 Martin Mares <mj@atrey.karlin.mff.cuni.cz>
- *
- *	The __delay function must _NOT_ be inlined as its execution time
- *	depends wildly on alignment on many x86 processors. 
- */
-
-#include <linux/module.h>
-#include <linux/sched.h>
-#include <linux/timex.h>
-#include <linux/preempt.h>
-#include <linux/delay.h>
-#include <linux/init.h>
-
-#include <asm/delay.h>
-#include <asm/msr.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)
-	);
-}
-
-static void delay_tsc(unsigned long loops)
-{
-	unsigned bclock, now;
-	int cpu;
-
-	preempt_disable();
-	cpu = smp_processor_id();
-	rdtscl(bclock);
-	for (;;) {
-		rdtscl(now);
-		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();
-			rdtscl(bclock);
-		}
-	}
-	preempt_enable();
-}
-
-static void (*delay_fn)(unsigned long) = delay_loop;
-
-void use_tsc_delay(void)
-{
-	delay_fn = delay_tsc;
-}
-
-int __devinit read_current_timer(unsigned long *timer_value)
-{
-	if (delay_fn == delay_tsc) {
-		rdtscll(*timer_value);
-		return 0;
-	}
-	return -1;
-}
-
-void __delay(unsigned long loops)
-{
-	delay_fn(loops);
-}
-EXPORT_SYMBOL(__delay);
-
-inline void __const_udelay(unsigned long xloops)
-{
-	int d0;
-	xloops *= 4;
-	__asm__("mull %%edx"
-		:"=d" (xloops), "=&a" (d0)
-		:"1" (xloops), "0"
-		(cpu_data(raw_smp_processor_id()).loops_per_jiffy * (HZ/4)));
-
-	__delay(++xloops);
-}
-
-EXPORT_SYMBOL(__const_udelay);
-
-void __udelay(unsigned long usecs)
-{
-	__const_udelay(usecs * 0x000010c7);  /* 2**32 / 1000000 (rounded up) */
-}
-EXPORT_SYMBOL(__udelay);
-
-void __ndelay(unsigned long nsecs)
-{
-	__const_udelay(nsecs * 0x00005);  /* 2**32 / 1000000000 (rounded up) */
-}
-EXPORT_SYMBOL(__ndelay);
-- 
1.5.5.1


  reply	other threads:[~2008-06-27 21:38 UTC|newest]

Thread overview: 61+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-06-27 21:34 [PATCH 0/39] Merge files at x86/lib Glauber Costa
2008-06-27 21:34 ` [PATCH 01/39] Don't use size specifiers Glauber Costa
2008-06-27 21:34   ` [PATCH 02/39] provide delay loop for x86_64 Glauber Costa
2008-06-27 21:34     ` [PATCH 03/39] use rdtscll in read_current_timer for i386 Glauber Costa
2008-06-27 21:34       ` [PATCH 04/39] explicitly use edx in const delay function Glauber Costa
2008-06-27 21:34         ` Glauber Costa [this message]
2008-06-27 21:34           ` [PATCH 06/39] use something common for both architectures Glauber Costa
2008-06-27 21:34             ` [PATCH 07/39] don't clobber r8 nor use rcx Glauber Costa
2008-06-27 21:34               ` [PATCH 08/39] don't use word-size specifiers Glauber Costa
2008-06-27 21:34                 ` [PATCH 09/39] adapt x86_64 getuser functions Glauber Costa
2008-06-27 21:34                   ` [PATCH 10/39] rename threadinfo to TI Glauber Costa
2008-06-27 21:34                     ` [PATCH 11/39] Don't use word-size specifiers on getuser_64 Glauber Costa
2008-06-27 21:34                       ` [PATCH 12/39] introduce __ASM_REG macro Glauber Costa
2008-06-27 21:34                         ` [PATCH 13/39] use _ASM_PTR instead of explicit word-size pointers Glauber Costa
2008-06-27 21:34                           ` [PATCH 14/39] merge getuser asm functions Glauber Costa
2008-06-27 21:34                             ` [PATCH 15/39] don't save ebx in putuser_32.S Glauber Costa
2008-06-27 21:34                               ` [PATCH 16/39] user put_user_x instead of all variants Glauber Costa
2008-06-27 21:34                                 ` [PATCH 17/39] clobber rbx in putuser_64.S Glauber Costa
2008-06-27 21:34                                   ` [PATCH 18/39] pass argument to putuser_64 functions in ax register Glauber Costa
2008-06-27 21:34                                     ` [PATCH 19/39] change testing logic in putuser_64.S Glauber Costa
2008-06-27 21:34                                       ` [PATCH 20/39] replace function headers by macros Glauber Costa
2008-06-27 21:34                                         ` [PATCH 21/39] don't use word-size specifiers in putuser files Glauber Costa
2008-06-27 21:34                                           ` [PATCH 22/39] use macros from asm.h Glauber Costa
2008-06-27 21:34                                             ` [PATCH 23/39] merge putuser asm functions Glauber Costa
2008-06-27 21:34                                               ` [PATCH 24/39] commonize __range_not_ok Glauber Costa
2008-06-27 21:34                                                 ` [PATCH 25/39] merge common parts of uaccess Glauber Costa
2008-06-27 21:34                                                   ` [PATCH 26/39] merge getuser Glauber Costa
2008-06-27 21:34                                                     ` [PATCH 27/39] move __addr_ok to uaccess.h Glauber Costa
2008-06-27 21:34                                                       ` [PATCH 28/39] use k modifier for 4-byte access Glauber Costa
2008-06-27 21:34                                                         ` [PATCH 29/39] mark x86_64 as having a working WP Glauber Costa
2008-06-27 21:34                                                           ` [PATCH 30/39] don't always use EFAULT on __put_user_size Glauber Costa
2008-06-27 21:34                                                             ` [PATCH 31/39] merge __put_user_asm and its user Glauber Costa
2008-06-27 21:34                                                               ` [PATCH 32/39] don't always use EFAULT on __get_user_size Glauber Costa
2008-06-27 21:34                                                                 ` [PATCH 33/39] merge __get_user_asm and its users Glauber Costa
2008-06-27 21:34                                                                   ` [PATCH 34/39] Be more explicit in __put_user_x Glauber Costa
2008-06-27 21:34                                                                     ` [PATCH 35/39] turn __put_user_check directly into put_user Glauber Costa
2008-06-27 21:34                                                                       ` [PATCH 36/39] merge put_user Glauber Costa
2008-06-27 21:34                                                                         ` [PATCH 37/39] move __get_user and __put_user into uaccess.h Glauber Costa
2008-06-27 21:34                                                                           ` [PATCH 38/39] put movsl_mask " Glauber Costa
2008-06-27 21:34                                                                             ` [PATCH 39/39] define architectural characteristics in uaccess.h Glauber Costa
2008-06-30  6:30                                                   ` [PATCH 25/39] merge common parts of uaccess Ingo Molnar
2008-06-30  6:31                                                     ` Ingo Molnar
2008-06-30 16:31                                                       ` H. Peter Anvin
2008-06-30 18:48                                                     ` Glauber Costa
2008-06-30 18:53                                                       ` Ingo Molnar
2008-06-30 19:00                                                         ` Glauber Costa
2008-06-30 19:29                                                           ` Ingo Molnar
2008-06-28 12:12                                   ` [PATCH 17/39] clobber rbx in putuser_64.S Andi Kleen
2008-06-30 21:00                                     ` Glauber Costa
2008-06-30 23:45                                       ` Andi Kleen
2008-07-01  2:46                                         ` Glauber Costa
2008-07-01 15:11                                         ` Glauber Costa
2008-06-30 21:40                                     ` Glauber Costa
2008-06-28 12:10                               ` [PATCH 15/39] don't save ebx in putuser_32.S Andi Kleen
2008-06-30 20:43                                 ` Glauber Costa
2008-06-28 12:09                         ` [PATCH 12/39] introduce __ASM_REG macro Andi Kleen
2008-06-27 23:17                 ` [PATCH 08/39] don't use word-size specifiers H. Peter Anvin
2008-06-27 23:22                   ` H. Peter Anvin
2008-06-28  1:41                     ` Glauber Costa
2008-06-28  5:09                       ` H. Peter Anvin
2008-06-30  5:10 ` [PATCH 0/39] Merge files at x86/lib H. Peter Anvin

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=1214602486-17080-6-git-send-email-gcosta@redhat.com \
    --to=gcosta@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@elte.hu \
    --cc=tglx@linutronix.de \
    --cc=x86@kernel.org \
    /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

all inboxes | Powered by JetHome®