Skip to contentSkip to conversation

RFC: const_udelay in 018-delay functions patch

PATCH Zachary Amsden 2 participants 4 messages Oct 25, 2006

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

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?

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.

===================================================================

arch/i386/boot/compressed/misc.c +1 -0
@@ -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>

===================================================================

arch/i386/kernel/paravirt.c +9 -0
@@ -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,
 };

===================================================================

arch/i386/kernel/smpboot.c +5 -0
@@ -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>

===================================================================

drivers/net/de600.c +0 -1
@@ -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

===================================================================

include/asm-i386/delay.h +8 -0
@@ -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);
 

===================================================================

include/asm-i386/io.h +6 -4
@@ -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 */

===================================================================

include/asm-i386/paravirt.h +15 -0
@@ -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 */

_______________________________________________
Virtualization mailing list
[email protected]
https://lists.osdl.org/mailman/listinfo/virtualization

#1 lore raw
Quoted 4 lines · Zachary Amsden

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:

include/asm-i386/io.h static inline void flush_write_buffers(v · line 261

Quoted 3 lines
include/asm-i386/io.h +3 -0
+#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.

Signature · 1 line
Help! Save Australia from the worst of the DMCA: http://linux.org.au/law
#2 lore raw
Quoted 11 lines · Rusty Russell
Quoted 5 lines · Zachary Amsden

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.

Quoted 10 lines

Comments:

include/asm-i386/io.h static inline void flush_write_buffers(v · line 261

Quoted 4 lines
include/asm-i386/io.h +3 -0
+#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

#3 lore raw
Quoted 10 lines · Zachary Amsden
Quoted 8 lines · Rusty Russell

include/asm-i386/io.h static inline void flush_write_buffers(v · line 261

Quoted 4 lines · Zachary Amsden
include/asm-i386/io.h +3 -0
+#if defined(CONFIG_PARAVIRT) && !defined(USE_REAL_IO)
+#include <asm/paravirt.h>
+#else 

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

Quoted 2 lines

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.

Quoted 3 lines

- 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.

Signature · 1 line
Help! Save Australia from the worst of the DMCA: http://linux.org.au/law