virtualization.lists.linux-foundation.org archive mirror
 help / color / mirror / Atom feed
* RFC: const_udelay in 018-delay functions patch
@ 2006-10-25  5:11 Zachary Amsden
  2006-10-25  6:03 ` Rusty Russell
  0 siblings, 1 reply; 4+ messages in thread
From: Zachary Amsden @ 2006-10-25  5:11 UTC (permalink / raw)
  To: Chris Wright, Rusty Russell, Virtualization Mailing List,
	Jeremy Fitzhardinge

[-- Attachment #1: Type: text/plain, Size: 259 bytes --]

So I implemented udelay and ndelay through a single paravirt_op, 
const_udelay, instead of having either two separate paravirt-ops for 
udelay or ndelay, or a redundant const_udelay paravirt_op.  Anybody have 
any objection to reworking the patch this way?



[-- Attachment #2: 018-delay-functions.patch --]
[-- Type: text/plain, Size: 5689 bytes --]

Add paravirtualized delay mechanisms to paravirt-ops.  There are two delays
used by native hardware that are unnecessary inside a virtual machine.  The
first of these is the hardware I/O delay used by io.h.  The second is udelay,
which is used in many places.  The only code that actually depends on a real
time delay in a virtual machine is SMP bootstrapping, which must wait for the
APs to come online.  For this purpose, I have introduced a way to override
the paravirt-ops implementation, by defining USE_REAL_TIME_DELAY before the
header files are included.  Similarly, the boot decompressor uses I/O
instructions, and it cannot yet use the paravirt-ops versions.  So it must
undefine CONFIG_PARAVIRT to prevent io_delay from being redefined.

Signed-off-by: Zachary Amsden <zach@vmware.com>

===================================================================
--- a/arch/i386/boot/compressed/misc.c
+++ b/arch/i386/boot/compressed/misc.c
@@ -9,6 +9,7 @@
  * High loaded stuff by Hans Lermen & Werner Almesberger, Feb. 1996
  */
 
+#undef CONFIG_PARAVIRT
 #include <linux/linkage.h>
 #include <linux/vmalloc.h>
 #include <linux/screen_info.h>
===================================================================
--- a/arch/i386/kernel/paravirt.c
+++ b/arch/i386/kernel/paravirt.c
@@ -21,6 +21,7 @@
 #include <asm/paravirt.h>
 #include <asm/desc.h>
 #include <asm/setup.h>
+#include <asm/delay.h>
 
 static fastcall void native_cpuid(unsigned int *eax, unsigned int *ebx,
 				  unsigned int *ecx, unsigned int *edx)
@@ -328,6 +329,11 @@ static fastcall void native_set_iopl_mas
 		      "popfl"
 		      : "=&r" (reg)
 		      : "i" (~X86_EFLAGS_IOPL), "r" (mask));
+}
+
+static fastcall void native_io_delay(void)
+{
+	asm volatile("outb %al,$0x80");
 }
 
 /* These are in entry.S */
@@ -445,6 +451,9 @@ struct paravirt_ops paravirt_ops = {
 	.write_idt_entry = native_write_idt_entry,
 
 	.set_iopl_mask = native_set_iopl_mask,
+	.io_delay = native_io_delay,
+	.const_udelay = __const_udelay,
+
 	.irq_enable_sysexit = native_irq_enable_sysexit,
 	.iret = native_iret,
 };
===================================================================
--- a/arch/i386/kernel/smpboot.c
+++ b/arch/i386/kernel/smpboot.c
@@ -33,6 +33,11 @@
  *		Dave Jones	:	Report invalid combinations of Athlon CPUs.
 *		Rusty Russell	:	Hacked into shape for new "hotplug" boot process. */
 
+
+/* SMP boot always wants to use real time delay to allow sufficient time for
+ * the APs to come online */
+#define USE_REAL_TIME_DELAY
+
 #include <linux/module.h>
 #include <linux/init.h>
 #include <linux/kernel.h>
===================================================================
--- a/drivers/net/de600.c
+++ b/drivers/net/de600.c
@@ -43,7 +43,6 @@ static const char version[] = "de600.c: 
  * modify the following "#define": (see <asm/io.h> for more info)
 #define REALLY_SLOW_IO
  */
-#define SLOW_IO_BY_JUMPING /* Looks "better" than dummy write to port 0x80 :-) */
 
 /* use 0 for production, 1 for verification, >2 for debug */
 #ifdef DE600_DEBUG
===================================================================
--- a/include/asm-i386/delay.h
+++ b/include/asm-i386/delay.h
@@ -15,6 +15,13 @@ extern void __const_udelay(unsigned long
 extern void __const_udelay(unsigned long usecs);
 extern void __delay(unsigned long loops);
 
+#if defined(CONFIG_PARAVIRT) && !defined(USE_REAL_TIME_DELAY)
+#define udelay(n) paravirt_ops.const_udelay((n) * 0x10c7ul)
+	
+#define ndelay(n) paravirt_ops.const_udelay((n) * 5ul)
+
+#else /* !PARAVIRT || USE_REAL_TIME_DELAY */
+
 #define udelay(n) (__builtin_constant_p(n) ? \
 	((n) > 20000 ? __bad_udelay() : __const_udelay((n) * 0x10c7ul)) : \
 	__udelay(n))
@@ -22,6 +29,7 @@ extern void __delay(unsigned long loops)
 #define ndelay(n) (__builtin_constant_p(n) ? \
 	((n) > 20000 ? __bad_ndelay() : __const_udelay((n) * 5ul)) : \
 	__ndelay(n))
+#endif
 
 void use_tsc_delay(void);
 
===================================================================
--- a/include/asm-i386/io.h
+++ b/include/asm-i386/io.h
@@ -256,11 +256,11 @@ static inline void flush_write_buffers(v
 
 #endif /* __KERNEL__ */
 
-#ifdef SLOW_IO_BY_JUMPING
-#define __SLOW_DOWN_IO "jmp 1f; 1: jmp 1f; 1:"
-#else
+#if defined(CONFIG_PARAVIRT) && !defined(USE_REAL_IO)
+#include <asm/paravirt.h>
+#else 
+
 #define __SLOW_DOWN_IO "outb %%al,$0x80;"
-#endif
 
 static inline void slow_down_io(void) {
 	__asm__ __volatile__(
@@ -270,6 +270,8 @@ static inline void slow_down_io(void) {
 #endif
 		: : );
 }
+
+#endif
 
 #ifdef CONFIG_X86_NUMAQ
 extern void *xquad_portio;    /* Where the IO area was mapped */
===================================================================
--- a/include/asm-i386/paravirt.h
+++ b/include/asm-i386/paravirt.h
@@ -98,6 +98,11 @@ struct paravirt_ops
 	void (fastcall *write_idt_entry)(void *dt, int entrynum, u64 entry);
 
 	void (fastcall *set_iopl_mask)(unsigned mask);
+	void (fastcall *io_delay)(void);
+
+	/* The native equivalents that are not fastcall, and presumably 
+	 * a nop in a VM, although driver domains may want real delay. */
+	void (*const_udelay)(unsigned long loops);
 
 	/* These two are jmp to, not actually called. */
 	void (fastcall *irq_enable_sysexit)(void);
@@ -224,6 +229,16 @@ static inline char *memory_setup(void)
 	return paravirt_ops.memory_setup();
 }
 
+/* The paravirtualized I/O functions */
+static inline void slow_down_io(void) {
+	paravirt_ops.io_delay();
+#ifdef REALLY_SLOW_IO
+	paravirt_ops.io_delay();
+	paravirt_ops.io_delay();
+	paravirt_ops.io_delay();
+#endif
+}
+
 /* These all sit in the .parainstructions section to tell us what to patch. */
 struct paravirt_patch {
 	u8 *instr; 		/* original instructions */

[-- Attachment #3: Type: text/plain, Size: 165 bytes --]

_______________________________________________
Virtualization mailing list
Virtualization@lists.osdl.org
https://lists.osdl.org/mailman/listinfo/virtualization

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: RFC: const_udelay in 018-delay functions patch
  2006-10-25  5:11 RFC: const_udelay in 018-delay functions patch Zachary Amsden
@ 2006-10-25  6:03 ` Rusty Russell
  2006-10-25  6:21   ` Zachary Amsden
  0 siblings, 1 reply; 4+ messages in thread
From: Rusty Russell @ 2006-10-25  6:03 UTC (permalink / raw)
  To: Zachary Amsden; +Cc: Chris Wright, Virtualization Mailing List

On Tue, 2006-10-24 at 22:11 -0700, Zachary Amsden wrote:
> So I implemented udelay and ndelay through a single paravirt_op, 
> const_udelay, instead of having either two separate paravirt-ops for 
> udelay or ndelay, or a redundant const_udelay paravirt_op.  Anybody have 
> any objection to reworking the patch this way?

Seems saner, but I'm not sure why x86 has an I/O delay separate from
udelay to start with?

Comments: 

> +#if defined(CONFIG_PARAVIRT) && !defined(USE_REAL_IO)
> +#include <asm/paravirt.h>
> +#else 

USE_REAL_IO? Is this defined anywhere?  Or just future-proofing?

Rusty.
-- 
Help! Save Australia from the worst of the DMCA: http://linux.org.au/law

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: RFC: const_udelay in 018-delay functions patch
  2006-10-25  6:03 ` Rusty Russell
@ 2006-10-25  6:21   ` Zachary Amsden
  2006-10-25 23:01     ` Rusty Russell
  0 siblings, 1 reply; 4+ messages in thread
From: Zachary Amsden @ 2006-10-25  6:21 UTC (permalink / raw)
  To: Rusty Russell; +Cc: Chris Wright, Virtualization Mailing List

Rusty Russell wrote:
> On Tue, 2006-10-24 at 22:11 -0700, Zachary Amsden wrote:
>   
>> So I implemented udelay and ndelay through a single paravirt_op, 
>> const_udelay, instead of having either two separate paravirt-ops for 
>> udelay or ndelay, or a redundant const_udelay paravirt_op.  Anybody have 
>> any objection to reworking the patch this way?
>>     
>
> Seems saner, but I'm not sure why x86 has an I/O delay separate from
> udelay to start with?
>   

I/O delay is for slow hardware that needs a couple bus cycles to settle, 
but doesn't have specified latency requirements - like many old floppy 
drive controllers.  Using the jmp 1f; thing doesn't seem very future 
proof, and the port I/O guarantees a bus access, which makes these 
fuggly older controllers work better.

> Comments: 
>
>   
>> +#if defined(CONFIG_PARAVIRT) && !defined(USE_REAL_IO)
>> +#include <asm/paravirt.h>
>> +#else 
>>     
>
> USE_REAL_IO? Is this defined anywhere?  Or just future-proofing?
>   

It has to be used for SMP bootstrapping - IPI acceptance requires real 
time cross-processor delay, even in a VM - and also can be added by a 
top-level define to kernel compiles for driver domains for Xen to give 
real time device delays.

Zach

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: RFC: const_udelay in 018-delay functions patch
  2006-10-25  6:21   ` Zachary Amsden
@ 2006-10-25 23:01     ` Rusty Russell
  0 siblings, 0 replies; 4+ messages in thread
From: Rusty Russell @ 2006-10-25 23:01 UTC (permalink / raw)
  To: Zachary Amsden; +Cc: Chris Wright, Virtualization Mailing List

On Tue, 2006-10-24 at 23:21 -0700, Zachary Amsden wrote:
> Rusty Russell wrote:
> > On Tue, 2006-10-24 at 22:11 -0700, Zachary Amsden wrote:
> >> +#if defined(CONFIG_PARAVIRT) && !defined(USE_REAL_IO)
> >> +#include <asm/paravirt.h>
> >> +#else 
> >>     
> >
> > USE_REAL_IO? Is this defined anywhere?  Or just future-proofing?
> >   
> 
> It has to be used for SMP bootstrapping - IPI acceptance requires real 
> time cross-processor delay, even in a VM

No, that's USE_REAL_TIME_DELAY: USE_REAL_IO is not currently defined
anywhere AFAICT.

>  - and also can be added by a 
> top-level define to kernel compiles for driver domains for Xen to give 
> real time device delays.

Makes sense...
Rusty.
-- 
Help! Save Australia from the worst of the DMCA: http://linux.org.au/law

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2006-10-25 23:01 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-10-25  5:11 RFC: const_udelay in 018-delay functions patch Zachary Amsden
2006-10-25  6:03 ` Rusty Russell
2006-10-25  6:21   ` Zachary Amsden
2006-10-25 23:01     ` Rusty Russell

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).