Skip to contentSkip to conversation

use cpu_relax() in busy loop

PATCH Applied Chris Wright 3 participants 21 messages Sep 18, 2003 – Sep 20, 2003

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

PATCH 1/13 use cpu_relax() in busy loop

Replace busy loop barrier() with cpu_relax().

This is bordering on a gratuitous change given the arm def'n of cpu_relax(). But I was fixing up other busy loops, and my grep found this one.

===== drivers/scsi/arm/acornscsi.c 1.35 vs edited =====

drivers/scsi/arm/acornscsi.c +1 -1
@@ -319,7 +319,7 @@
     local_save_flags(flags);
     local_irq_enable();
 
-    while (time_before(jiffies, target_jiffies)) barrier();
+    while (time_before(jiffies, target_jiffies)) cpu_relax();
 
     local_irq_restore(flags);
 }
#1 lore raw

PATCH 2/13 use cpu_relax() in busy loop

[PATCH 2/13] use cpu_relax() in busy loop

Replace busy loop nop with cpu_relax().

===== drivers/atm/fore200e.c 1.19 vs edited =====

drivers/atm/fore200e.c +2 -1
@@ -248,7 +248,8 @@
 fore200e_spin(int msecs)
 {
     unsigned long timeout = jiffies + MSECS(msecs);
-    while (time_before(jiffies, timeout));
+    while (time_before(jiffies, timeout))
+    	cpu_relax();
 }
 
 
#2 lore raw

PATCH 3/13 use cpu_relax() in busy loop

Replace busy loop nop with cpu_relax().

===== drivers/block/ps2esdi.c 1.69 vs edited =====

drivers/block/ps2esdi.c +2 -1
@@ -550,7 +550,8 @@
 		printk("%s: hard reset...\n", DEVICE_NAME);
 		outb_p(CTRL_HARD_RESET, ESDI_CONTROL);
 		expire = jiffies + 2*HZ;
-		while (time_before(jiffies, expire));
+		while (time_before(jiffies, expire))
+			cpu_relax();
 		outb_p(1, ESDI_CONTROL);
 	}			/* hard reset */
 
#3 lore raw

PATCH 4/13 use cpu_relax() in busy loop

Replace busy loop nop with cpu_relax().

===== drivers/cdrom/sonycd535.c 1.39 vs edited =====

drivers/cdrom/sonycd535.c +2 -1
@@ -1526,7 +1526,8 @@
 		enable_interrupts();
 		outb(0, read_status_reg);	/* does a reset? */
 		delay = jiffies + HZ/10;
-		while (time_before(jiffies, delay)) ;
+		while (time_before(jiffies, delay))
+			cpu_relax();
 
 		sony535_irq_used = probe_irq_off(irq_mask);
 		disable_interrupts();
#4 lore raw

PATCH 5/13 use cpu_relax() in busy loop

Replace busy loop nop with cpu_relax().

===== drivers/char/isicom.c 1.25 vs edited =====

drivers/char/isicom.c +4 -2
@@ -153,12 +153,14 @@
 								
 			inw(base+0x8);
 			
-			for(i=jiffies+HZ/100;time_before(jiffies, i););
+			for(i=jiffies+HZ/100;time_before(jiffies, i);)
+				cpu_relax();
 				
 			outw(0,base+0x8); /* Reset */
 			
 			for(j=1;j<=3;j++) {
-				for(i=jiffies+HZ;time_before(jiffies, i););
+				for(i=jiffies+HZ;time_before(jiffies, i);)
+					cpu_relax();
 				printk(".");
 			}	
 			signature=(inw(base+0x4)) & 0xff;	
#5 lore raw

PATCH 6/13 use cpu_relax() in busy loop

Replace busy loop nop with cpu_relax().

===== drivers/char/moxa.c 1.25 vs edited =====

drivers/char/moxa.c +2 -1
@@ -2758,7 +2758,8 @@
 
 	st = jiffies;
 	et = st + tick;
-	while (time_before(jiffies, et));
+	while (time_before(jiffies, et))
+		cpu_relax();
 }
 
 static void moxafunc(unsigned long ofsAddr, int cmd, ushort arg)
#6 lore raw

PATCH 7/13 use cpu_relax() in busy loop

Replace busy loop nop with cpu_relax().

Jeff, here's a batch for net drivers. They all look pretty straight forward.

===== drivers/net/3c501.c 1.19 vs edited =====

drivers/net/3c501.c +2 -1
@@ -251,7 +251,8 @@
 		outb(0x00, AX_CMD);
 
 		delay = jiffies + HZ/50;
-		while (time_before(jiffies, delay)) ;
+		while (time_before(jiffies, delay))
+			cpu_relax();
 		autoirq = probe_irq_off(irq_mask);
 
 		if (autoirq == 0)

===== drivers/net/3c505.c 1.25 vs edited =====

drivers/net/3c505.c +8 -4
@@ -299,16 +299,20 @@
 	}
 	outb_control(adapter->hcr_val | ATTN | DIR, dev);
 	timeout = jiffies + 1*HZ/100;
-	while (time_before_eq(jiffies, timeout));
+	while (time_before_eq(jiffies, timeout))
+		cpu_relax();
 	outb_control(adapter->hcr_val & ~ATTN, dev);
 	timeout = jiffies + 1*HZ/100;
-	while (time_before_eq(jiffies, timeout));
+	while (time_before_eq(jiffies, timeout))
+		cpu_relax();
 	outb_control(adapter->hcr_val | FLSH, dev);
 	timeout = jiffies + 1*HZ/100;
-	while (time_before_eq(jiffies, timeout));
+	while (time_before_eq(jiffies, timeout))
+		cpu_relax();
 	outb_control(adapter->hcr_val & ~FLSH, dev);
 	timeout = jiffies + 1*HZ/100;
-	while (time_before_eq(jiffies, timeout));
+	while (time_before_eq(jiffies, timeout))
+		cpu_relax();
 
 	outb_control(orig_hcr, dev);
 	if (!start_receive(dev, &adapter->tx_pcb))

===== drivers/net/acenic.c 1.39 vs edited =====

drivers/net/acenic.c +2 -1
@@ -1757,7 +1757,8 @@
 	 * Wait for the firmware to spin up - max 3 seconds.
 	 */
 	myjif = jiffies + 3 * HZ;
-	while (time_before(jiffies, myjif) && !ap->fw_running);
+	while (time_before(jiffies, myjif) && !ap->fw_running)
+		cpu_relax();
 
 	if (!ap->fw_running) {
 		printk(KERN_ERR "%s: Firmware NOT running!\n", dev->name);

===== drivers/net/eepro.c 1.19 vs edited =====

drivers/net/eepro.c +2 -1
@@ -904,7 +904,8 @@
 			eepro_diag(ioaddr); /* RESET the 82595 */
 
 			delay = jiffies + HZ/50;
-			while (time_before(jiffies, delay)) ;
+			while (time_before(jiffies, delay))
+				cpu_relax();
 
 			if (*irqp == probe_irq_off(irq_mask))  /* It's a good IRQ line */
 				break;

===== drivers/net/ewrk3.c 1.26 vs edited =====

drivers/net/ewrk3.c +2 -1
@@ -579,7 +579,8 @@
 									irqnum = irq[((icr & IRQ_SEL) >> 4)];
 
 									delay = jiffies + HZ/50;
-									while (time_before(jiffies, delay)) ;
+									while (time_before(jiffies, delay))
+										cpu_relax();
 									dev->irq = probe_irq_off(irq_mask);
 									if ((dev->irq) && (irqnum == dev->irq)) {
 										printk(" and uses IRQ%d.\n", dev->irq);

===== drivers/net/lance.c 1.18 vs edited =====

drivers/net/lance.c +4 -2
@@ -554,7 +554,8 @@
 		outw(0x0041, ioaddr+LANCE_DATA);
 
 		delay = jiffies + HZ/50;
-		while (time_before(jiffies, delay)) ;
+		while (time_before(jiffies, delay))
+			cpu_relax();
 		dev->irq = probe_irq_off(irq_mask);
 		if (dev->irq)
 			printk(", probed IRQ %d", dev->irq);
@@ -627,7 +628,8 @@
 		outw(0x0041, ioaddr+LANCE_DATA);
 
 		delay = jiffies + HZ/25;
-		while (time_before(jiffies, delay)) ;
+		while (time_before(jiffies, delay))
+			cpu_relax();
 		dev->irq = probe_irq_off(irq_mask);
 		if (dev->irq == 0) {
 			printk("  Failed to detect the 7990 IRQ line.\n");

===== drivers/net/ni5010.c 1.11 vs edited =====

drivers/net/ni5010.c +2 -1
@@ -262,7 +262,8 @@
 		irq_mask = probe_irq_on();
 		trigger_irq(ioaddr);
 		delay = jiffies + HZ/50;
-		while (time_before(jiffies, delay)) ;
+		while (time_before(jiffies, delay))
+			cpu_relax();
 		dev->irq = probe_irq_off(irq_mask);
 
 		PRINTK2((KERN_DEBUG "%s: I/O #6 passed!\n", dev->name));

===== drivers/net/ni52.c 1.11 vs edited =====

drivers/net/ni52.c +2 -1
@@ -499,7 +499,8 @@
 		ni_attn586();
 
 		delay = jiffies + HZ/50;
-		while (time_before(jiffies, delay)) ;
+		while (time_before(jiffies, delay))
+			cpu_relax();
 		dev->irq = probe_irq_off(irq_mask);
 		if(!dev->irq)
 		{

===== drivers/net/rrunner.c 1.21 vs edited =====

drivers/net/rrunner.c +2 -1
@@ -721,7 +721,8 @@
 	 * Give the FirmWare time to chew on the `get running' command.
 	 */
 	myjif = jiffies + 5 * HZ;
-	while (time_before(jiffies, myjif) && !rrpriv->fw_running);
+	while (time_before(jiffies, myjif) && !rrpriv->fw_running)
+		cpu_relax();
 
 	netif_start_queue(dev);
 

===== drivers/net/wan/sbni.c 1.22 vs edited =====

drivers/net/wan/sbni.c +2 -1
@@ -343,7 +343,8 @@
 		outb( EN_INT | TR_REQ, ioaddr + CSR0 );
 		outb( PR_RES, ioaddr + CSR1 );
 		delay = jiffies + HZ/20;
-		while (time_before(jiffies, delay)) ;
+		while (time_before(jiffies, delay))
+			cpu_relax();
 		irq = probe_irq_off(irq_mask);
 		outb( 0, ioaddr + CSR0 );
 

===== drivers/net/wd.c 1.12 vs edited =====

drivers/net/wd.c +2 -1
@@ -249,7 +249,8 @@
 			outb_p(0x00, nic_addr + EN0_RCNTHI);
 			outb(E8390_RREAD+E8390_START, nic_addr); /* Trigger it... */
 			delay = jiffies + HZ/50;
-			while (time_before(jiffies, delay)) ;
+			while (time_before(jiffies, delay))
+				cpu_relax();
 			dev->irq = probe_irq_off(irq_mask);
 			
 			outb_p(0x00, nic_addr+EN0_IMR);	/* Mask all intrs. again. */
#7 lore raw

PATCH 8/13 use cpu_relax() in busy loop

Replace busy loop rep_nop() with cpu_relax().

This is bordering on a gratuitous change given the i386 def'n of cpu_relax(). But I was fixing up other busy loops, and my grep found this one.

===== arch/i386/kernel/smpboot.c 1.64 vs edited =====

arch/i386/kernel/smpboot.c +1 -1
@@ -378,7 +378,7 @@
 		 */
 		if (cpu_isset(cpuid, cpu_callout_map))
 			break;
-		rep_nop();
+		cpu_relax();
 	}
 
 	if (!time_before(jiffies, timeout)) {
#8 lore raw

PATCH 9/13 use cpu_relax() in busy loop

Replace busy loop nop with cpu_relax().

===== net/ipv4/ipconfig.c 1.29 vs edited =====

net/ipv4/ipconfig.c +2 -2
@@ -1153,7 +1153,7 @@
 	/* Give hardware a chance to settle */
 	jiff = jiffies + CONF_PRE_OPEN;
 	while (time_before(jiffies, jiff))
-		;
+		cpu_relax();
 
 	/* Setup all network devices */
 	if (ic_open_devs() < 0)
@@ -1162,7 +1162,7 @@
 	/* Give drivers a chance to settle */
 	jiff = jiffies + CONF_POST_OPEN;
 	while (time_before(jiffies, jiff))
-			;
+		cpu_relax();
 
 	/*
 	 * If the config information is insufficient (e.g., our IP address or
#9 lore raw

PATCH 10/13 use cpu_relax() in busy loop

Replace busy loop nop with cpu_relax().

===== drivers/isdn/hardware/avm/avmcard.h 1.17 vs edited =====

drivers/isdn/hardware/avm/avmcard.h +4 -2
@@ -233,7 +233,8 @@
 static inline unsigned char b1_get_byte(unsigned int base)
 {
 	unsigned long stop = jiffies + 1 * HZ;	/* maximum wait time 1 sec */
-	while (!b1_rx_full(base) && time_before(jiffies, stop));
+	while (!b1_rx_full(base) && time_before(jiffies, stop))
+		cpu_relax();
 	if (b1_rx_full(base))
 		return inb(base + B1_READ);
 	printk(KERN_CRIT "b1lli(0x%x): rx not full after 1 second\n", base);
@@ -264,7 +265,8 @@
 static inline int b1_save_put_byte(unsigned int base, unsigned char val)
 {
 	unsigned long stop = jiffies + 2 * HZ;
-	while (!b1_tx_empty(base) && time_before(jiffies,stop));
+	while (!b1_tx_empty(base) && time_before(jiffies,stop))
+		cpu_relax();
 	if (!b1_tx_empty(base)) return -1;
 	b1outp(base, B1_WRITE, val);
 	return 0;
#10 lore raw

PATCH 11/13 use cpu_relax() in busy loop

[PATCH 11/13] use cpu_relax() in busy loop

Replace busy loop nop with cpu_relax().

===== drivers/isdn/eicon/linio.c 1.8 vs edited =====

drivers/isdn/eicon/linio.c +2 -1
@@ -38,7 +38,8 @@
 {
 	unsigned long timeout = jiffies + ((ms * HZ) / 1000);
 
-	while (time_before(jiffies, timeout));
+	while (time_before(jiffies, timeout))
+		cpu_relax();
 }
 
 int UxCardHandleGet(ux_diva_card_t **card, dia_card_t *cfg)
#11 lore raw

PATCH 12/13 use cpu_relax() in busy loop

Replace busy loop nop with cpu_relax().

===== drivers/scsi/i91uscsi.c 1.6 vs edited =====

drivers/scsi/i91uscsi.c +2 -1
@@ -212,7 +212,8 @@
 {				/* Pause for amount jiffies */
 	unsigned long the_time = jiffies + amount;
 
-	while (time_before_eq(jiffies, the_time));
+	while (time_before_eq(jiffies, the_time))
+		cpu_relax();
 }
 
 /*-- forward reference --*/
#12 lore raw

PATCH 13/13 use cpu_relax() in busy loop

Replace busy loop rep_nop() with cpu_relax().

This is bordering on a gratuitous change given the x86_64 def'n of cpu_relax(). But I was fixing up other busy loops, and my grep found this one.

===== arch/x86_64/kernel/smpboot.c 1.21 vs edited =====

arch/x86_64/kernel/smpboot.c +1 -1
@@ -282,7 +282,7 @@
 		 */
 		if (cpu_isset(cpuid, cpu_callout_map))
 			break;
-		rep_nop();
+		cpu_relax();
 	}
 
 	if (!time_before(jiffies, timeout)) {
#14 lore raw
In reply to Chris Wright
Quoted 9 lines · Chris Wright

Replace busy loop nop with cpu_relax().

Jeff, here's a batch for net drivers. They all look pretty straight forward.

===== drivers/net/3c501.c 1.19 vs edited =====

drivers/net/3c501.c line 256

Quoted 7 lines
drivers/net/3c501.c +2 -1
@@ -251,7 +251,8 @@
 		outb(0x00, AX_CMD);
 
 		delay = jiffies + HZ/50;
-		while (time_before(jiffies, delay)) ;
+		while (time_before(jiffies, delay))
+			cpu_relax();
 		autoirq = probe_irq_off(irq_mask);

mdelay()

drivers/net/3c505.c line 303

Quoted 12 lines
drivers/net/3c501.c +0 -0
 		if (autoirq == 0)

===== drivers/net/3c505.c 1.25 vs edited =====

drivers/net/3c505.c +2 -1
@@ -299,16 +299,20 @@
 	}
 	outb_control(adapter->hcr_val | ATTN | DIR, dev);
 	timeout = jiffies + 1*HZ/100;
-	while (time_before_eq(jiffies, timeout));
+	while (time_before_eq(jiffies, timeout))
+		cpu_relax();

mdelay()

drivers/net/3c505.c line 303

Quoted 4 lines
drivers/net/3c505.c +2 -1
 	timeout = jiffies + 1*HZ/100;
-	while (time_before_eq(jiffies, timeout));
+	while (time_before_eq(jiffies, timeout))
+		cpu_relax();

mdelay()

drivers/net/3c505.c line 311

Quoted 5 lines
drivers/net/3c505.c +2 -1
 	outb_control(adapter->hcr_val | FLSH, dev);
 	timeout = jiffies + 1*HZ/100;
-	while (time_before_eq(jiffies, timeout));
+	while (time_before_eq(jiffies, timeout))
+		cpu_relax();

mdelay()

drivers/net/3c505.c line 316

Quoted 6 lines
drivers/net/3c505.c +2 -1
 	outb_control(adapter->hcr_val & ~FLSH, dev);
 	timeout = jiffies + 1*HZ/100;
-	while (time_before_eq(jiffies, timeout));
+	while (time_before_eq(jiffies, timeout))
+		cpu_relax();
 

mdelay()

drivers/net/eepro.c line 908

Quoted 10 lines

===== drivers/net/eepro.c 1.19 vs edited =====

drivers/net/eepro.c +2 -1
@@ -904,7 +904,8 @@
 			eepro_diag(ioaddr); /* RESET the 82595 */
 
 			delay = jiffies + HZ/50;
-			while (time_before(jiffies, delay)) ;
+			while (time_before(jiffies, delay))
+				cpu_relax();

mdelay()

drivers/net/lance.c line 558

Quoted 10 lines

===== drivers/net/lance.c 1.18 vs edited =====

drivers/net/lance.c +2 -1
@@ -554,7 +554,8 @@
 		outw(0x0041, ioaddr+LANCE_DATA);
 
 		delay = jiffies + HZ/50;
-		while (time_before(jiffies, delay)) ;
+		while (time_before(jiffies, delay))
+			cpu_relax();

mdelay()

#15 lore raw

[PATCH 7/13] use cpu_relax() in busy loop, or mdelay instead of busy loop

Replace busy loop nop with cpu_relax(), and just use mdelay where it's better.

These look ok?
-chris

===== drivers/net/3c501.c 1.19 vs edited =====

drivers/net/3c501.c +3 -3
@@ -123,6 +123,7 @@
 #include <linux/config.h>	/* for CONFIG_IP_MULTICAST */
 #include <linux/spinlock.h>
 #include <linux/ethtool.h>
+#include <linux/delay.h>
 
 #include <asm/uaccess.h>
 #include <asm/bitops.h>
@@ -241,7 +242,7 @@
 
 	if (dev->irq < 2)
 	{
-		unsigned long irq_mask, delay;
+		unsigned long irq_mask;
 
 		irq_mask = probe_irq_on();
 		inb(RX_STATUS);		/* Clear pending interrupts. */
@@ -250,8 +251,7 @@
 
 		outb(0x00, AX_CMD);
 
-		delay = jiffies + HZ/50;
-		while (time_before(jiffies, delay)) ;
+		mdelay(20);
 		autoirq = probe_irq_off(irq_mask);
 
 		if (autoirq == 0)

===== drivers/net/3c505.c 1.25 vs edited =====

drivers/net/3c505.c +4 -8
@@ -298,17 +298,13 @@
 		set_hsf(dev, HSF_PCB_NAK);
 	}
 	outb_control(adapter->hcr_val | ATTN | DIR, dev);
-	timeout = jiffies + 1*HZ/100;
-	while (time_before_eq(jiffies, timeout));
+	mdelay(10);
 	outb_control(adapter->hcr_val & ~ATTN, dev);
-	timeout = jiffies + 1*HZ/100;
-	while (time_before_eq(jiffies, timeout));
+	mdelay(10);
 	outb_control(adapter->hcr_val | FLSH, dev);
-	timeout = jiffies + 1*HZ/100;
-	while (time_before_eq(jiffies, timeout));
+	mdelay(10);
 	outb_control(adapter->hcr_val & ~FLSH, dev);
-	timeout = jiffies + 1*HZ/100;
-	while (time_before_eq(jiffies, timeout));
+	mdelay(10);
 
 	outb_control(orig_hcr, dev);
 	if (!start_receive(dev, &adapter->tx_pcb))

===== drivers/net/acenic.c 1.39 vs edited =====

drivers/net/acenic.c +2 -1
@@ -1757,7 +1757,8 @@
 	 * Wait for the firmware to spin up - max 3 seconds.
 	 */
 	myjif = jiffies + 3 * HZ;
-	while (time_before(jiffies, myjif) && !ap->fw_running);
+	while (time_before(jiffies, myjif) && !ap->fw_running)
+		cpu_relax();
 
 	if (!ap->fw_running) {
 		printk(KERN_ERR "%s: Firmware NOT running!\n", dev->name);

===== drivers/net/eepro.c 1.19 vs edited =====

drivers/net/eepro.c +2 -4
@@ -897,14 +897,12 @@
 		eepro_sw2bank0(ioaddr); /* Switch back to Bank 0 */
 
 		if (request_irq (*irqp, NULL, SA_SHIRQ, "bogus", dev) != EBUSY) {
-			unsigned long irq_mask, delay;
+			unsigned long irq_mask;
 			/* Twinkle the interrupt, and check if it's seen */
 			irq_mask = probe_irq_on();
 
 			eepro_diag(ioaddr); /* RESET the 82595 */
-
-			delay = jiffies + HZ/50;
-			while (time_before(jiffies, delay)) ;
+			mdelay(20);
 
 			if (*irqp == probe_irq_off(irq_mask))  /* It's a good IRQ line */
 				break;

===== drivers/net/ewrk3.c 1.26 vs edited =====

drivers/net/ewrk3.c +2 -3
@@ -564,7 +564,7 @@
 								if (dev->irq < 2) {
 #ifndef MODULE
 									u_char irqnum;
-									unsigned long irq_mask, delay;
+									unsigned long irq_mask;
 			
 
 									irq_mask = probe_irq_on();
@@ -578,8 +578,7 @@
 
 									irqnum = irq[((icr & IRQ_SEL) >> 4)];
 
-									delay = jiffies + HZ/50;
-									while (time_before(jiffies, delay)) ;
+									mdelay(20);
 									dev->irq = probe_irq_off(irq_mask);
 									if ((dev->irq) && (irqnum == dev->irq)) {
 										printk(" and uses IRQ%d.\n", dev->irq);

===== drivers/net/lance.c 1.18 vs edited =====

drivers/net/lance.c +4 -6
@@ -543,7 +543,7 @@
 	if (dev->irq >= 2)
 		printk(" assigned IRQ %d", dev->irq);
 	else if (lance_version != 0)  {	/* 7990 boards need DMA detection first. */
-		unsigned long irq_mask, delay;
+		unsigned long irq_mask;
 
 		/* To auto-IRQ we enable the initialization-done and DMA error
 		   interrupts. For ISA boards we get a DMA error, but VLB and PCI
@@ -553,8 +553,7 @@
 		/* Trigger an initialization just for the interrupt. */
 		outw(0x0041, ioaddr+LANCE_DATA);
 
-		delay = jiffies + HZ/50;
-		while (time_before(jiffies, delay)) ;
+		mdelay(20);
 		dev->irq = probe_irq_off(irq_mask);
 		if (dev->irq)
 			printk(", probed IRQ %d", dev->irq);
@@ -621,13 +620,12 @@
 	if (lance_version == 0 && dev->irq == 0) {
 		/* We may auto-IRQ now that we have a DMA channel. */
 		/* Trigger an initialization just for the interrupt. */
-		unsigned long irq_mask, delay;
+		unsigned long irq_mask;
 
 		irq_mask = probe_irq_on();
 		outw(0x0041, ioaddr+LANCE_DATA);
 
-		delay = jiffies + HZ/25;
-		while (time_before(jiffies, delay)) ;
+		mdelay(40);
 		dev->irq = probe_irq_off(irq_mask);
 		if (dev->irq == 0) {
 			printk("  Failed to detect the 7990 IRQ line.\n");

===== drivers/net/ni5010.c 1.11 vs edited =====

drivers/net/ni5010.c +2 -3
@@ -255,14 +255,13 @@
 	if (dev->irq == 0xff)
 		;
 	else if (dev->irq < 2) {
-		unsigned long irq_mask, delay;
+		unsigned long irq_mask;
 
 		PRINTK2((KERN_DEBUG "%s: I/O #5 passed!\n", dev->name));
 
 		irq_mask = probe_irq_on();
 		trigger_irq(ioaddr);
-		delay = jiffies + HZ/50;
-		while (time_before(jiffies, delay)) ;
+		mdelay(20);
 		dev->irq = probe_irq_off(irq_mask);
 
 		PRINTK2((KERN_DEBUG "%s: I/O #6 passed!\n", dev->name));

===== drivers/net/ni52.c 1.11 vs edited =====

drivers/net/ni52.c +2 -3
@@ -492,14 +492,13 @@
 
 	if(dev->irq < 2)
 	{
-		unsigned long irq_mask, delay;
+		unsigned long irq_mask;
 
 		irq_mask = probe_irq_on();
 		ni_reset586();
 		ni_attn586();
 
-		delay = jiffies + HZ/50;
-		while (time_before(jiffies, delay)) ;
+		mdelay(20);
 		dev->irq = probe_irq_off(irq_mask);
 		if(!dev->irq)
 		{

===== drivers/net/rrunner.c 1.21 vs edited =====

drivers/net/rrunner.c +2 -1
@@ -721,7 +721,8 @@
 	 * Give the FirmWare time to chew on the `get running' command.
 	 */
 	myjif = jiffies + 5 * HZ;
-	while (time_before(jiffies, myjif) && !rrpriv->fw_running);
+	while (time_before(jiffies, myjif) && !rrpriv->fw_running)
+		cpu_relax();
 
 	netif_start_queue(dev);
 

===== drivers/net/wan/sbni.c 1.22 vs edited =====

drivers/net/wan/sbni.c +3 -3
@@ -53,6 +53,7 @@
 #include <linux/skbuff.h>
 #include <linux/timer.h>
 #include <linux/init.h>
+#include <linux/delay.h>
 
 #include <net/arp.h>
 
@@ -337,13 +338,12 @@
 	outb( 0, ioaddr + CSR0 );
 
 	if( irq < 2 ) {
-		unsigned long irq_mask, delay;
+		unsigned long irq_mask;
 
 		irq_mask = probe_irq_on();
 		outb( EN_INT | TR_REQ, ioaddr + CSR0 );
 		outb( PR_RES, ioaddr + CSR1 );
-		delay = jiffies + HZ/20;
-		while (time_before(jiffies, delay)) ;
+		mdelay(50);
 		irq = probe_irq_off(irq_mask);
 		outb( 0, ioaddr + CSR0 );
 

===== drivers/net/wd.c 1.12 vs edited =====

drivers/net/wd.c +2 -3
@@ -235,7 +235,7 @@
 		int reg4 = inb(ioaddr+4);
 		if (ancient || reg1 == 0xff) {	/* Ack!! No way to read the IRQ! */
 			short nic_addr = ioaddr+WD_NIC_OFFSET;
-			unsigned long irq_mask, delay;
+			unsigned long irq_mask;
 
 			/* We have an old-style ethercard that doesn't report its IRQ
 			   line.  Do autoirq to find the IRQ line. Note that this IS NOT
@@ -248,8 +248,7 @@
 			outb_p(0x00, nic_addr + EN0_RCNTLO);
 			outb_p(0x00, nic_addr + EN0_RCNTHI);
 			outb(E8390_RREAD+E8390_START, nic_addr); /* Trigger it... */
-			delay = jiffies + HZ/50;
-			while (time_before(jiffies, delay)) ;
+			mdelay(20);
 			dev->irq = probe_irq_off(irq_mask);
 			
 			outb_p(0x00, nic_addr+EN0_IMR);	/* Mask all intrs. again. */
#16 lore raw
In reply to Chris Wright

drivers/cdrom/sonycd535.c line 1530

Quoted 12 lines · Chris Wright

Replace busy loop nop with cpu_relax().

===== drivers/cdrom/sonycd535.c 1.39 vs edited =====

drivers/cdrom/sonycd535.c +2 -1
@@ -1526,7 +1526,8 @@
 		enable_interrupts();
 		outb(0, read_status_reg);	/* does a reset? */
 		delay = jiffies + HZ/10;
-		while (time_before(jiffies, delay)) ;
+		while (time_before(jiffies, delay))
+			cpu_relax();

mdelay ?

#17 lore raw
Quoted 2 lines · * Arjan van de Ven ([email protected]) wrote:

mdelay ?

Yeah, good point. For these subsecond pauses mdelay() makes more sense. It'd be nice to get rid of long busy loops in general. Thanks for taking a look.

-chris

[PATCH 4/13] use mdelay() instead of busy loop

Replace busy loop with mdelay().

===== drivers/cdrom/sonycd535.c 1.39 vs edited =====

drivers/cdrom/sonycd535.c +3 -3
@@ -129,6 +129,7 @@
 #include <linux/mm.h>
 #include <linux/slab.h>
 #include <linux/init.h>
+#include <linux/delay.h>
 
 #define REALLY_SLOW_IO
 #include <asm/system.h>
@@ -1520,13 +1521,12 @@
 
 	/* A negative sony535_irq_used will attempt an autoirq. */
 	if (sony535_irq_used < 0) {
-		unsigned long irq_mask, delay;
+		unsigned long irq_mask;
 
 		irq_mask = probe_irq_on();
 		enable_interrupts();
 		outb(0, read_status_reg);	/* does a reset? */
-		delay = jiffies + HZ/10;
-		while (time_before(jiffies, delay)) ;
+		mdelay(100);
 
 		sony535_irq_used = probe_irq_off(irq_mask);
 		disable_interrupts();
#18 lore raw
Quoted 6 lines · Chris Wright
Quoted 2 lines · * Arjan van de Ven ([email protected]) wrote:

mdelay ?

Yeah, good point. For these subsecond pauses mdelay() makes more sense. It'd be nice to get rid of long busy loops in general.

yep; first step is making them grep-able by using mdelay ;)

#19 lore raw
In reply to Chris Wright
Quoted 8 lines · Chris Wright

[PATCH 2/13] use cpu_relax() in busy loop

Replace busy loop nop with cpu_relax().

===== drivers/atm/fore200e.c 1.19 vs edited =====

drivers/atm/fore200e.c line 253

Quoted 7 lines
drivers/atm/fore200e.c +2 -1
@@ -248,7 +248,8 @@
 fore200e_spin(int msecs)
 {
     unsigned long timeout = jiffies + MSECS(msecs);
-    while (time_before(jiffies, timeout));
+    while (time_before(jiffies, timeout))
+    	cpu_relax();
 }

ehmmm how about making this use mdelay instead ?
(not to speak of maybe making it sleep, but that's a less obvious transformation)

#20 lore raw
Quoted 3 lines · * Arjan van de Ven ([email protected]) wrote:

ehmmm how about making this use mdelay instead ?
(not to speak of maybe making it sleep, but that's a less obvious transformation)

I didn't want to change to sleep semantics of the call w/out better review of spinlocks held/irq disabled, etc. But, after feedback from Mitch, looks like these were only called during module init/exit. This look ok?

thanks,
-chris

[PATCH 2/13] use schedule_timeout() instead of busy loop

Replace fore200e_spin() busy loops with schedule_timeout().

===== fore200e.c 1.19 vs edited =====

fore200e.c renamed from drivers/atm/fore200e.c +6 -11
@@ -229,7 +229,8 @@
     u32 hb1, hb2;
 
     hb1 = fore200e->bus->read(&fore200e->cp_queues->heartbeat);
-    fore200e_spin(10);
+    set_current_state(TASK_UNINTERRUPTIBLE);
+    schedule_timeout(10 * HZ/1000);
     hb2 = fore200e->bus->read(&fore200e->cp_queues->heartbeat);
     
     if (hb2 <= hb1) {
@@ -244,14 +245,6 @@
 #endif 
 
 
-static void
-fore200e_spin(int msecs)
-{
-    unsigned long timeout = jiffies + MSECS(msecs);
-    while (time_before(jiffies, timeout));
-}
-
-
 static int
 fore200e_poll(struct fore200e* fore200e, volatile u32* addr, u32 val, int msecs)
 {
@@ -551,7 +544,8 @@
 fore200e_pca_reset(struct fore200e* fore200e)
 {
     writel(PCA200E_HCR_RESET, fore200e->regs.pca.hcr);
-    fore200e_spin(10);
+    set_current_state(TASK_UNINTERRUPTIBLE);
+    schedule_timeout(10 * HZ/1000);
     writel(0, fore200e->regs.pca.hcr);
 }
 
@@ -831,7 +825,8 @@
 fore200e_sba_reset(struct fore200e* fore200e)
 {
     fore200e->bus->write(SBA200E_HCR_RESET, fore200e->regs.sba.hcr);
-    fore200e_spin(10);
+    set_current_state(TASK_UNINTERRUPTIBLE);
+    schedule_timeout(10 * HZ/1000);
     fore200e->bus->write(0, fore200e->regs.sba.hcr);
 }