Subject: [PATCH] ipconfig schedule fix

From: Magnus Damm <[email-masked]>
Date: Tue, 23 Nov 2004 23:50:35 +0100

Hi,

This simple patch makes the DHCP/BOOTP/RARP code sleep with
schedule_timeout() instead of hogging the cpu with cpu_relax() in a
loop. This comes handy when a guest kernel is booted inside QEMU.
Without the patch, the host operating system will consume cpu time
busy waiting.

Thanks,

/ magnus
--- linux-2.6.10-rc2-mm3/net/ipv4/ipconfig.c	2004-10-18 23:53:08.000000000 +0200
+++ linux-2.6.10-rc2-mm3-ipconfig_schedule/net/ipv4/ipconfig.c	2004-11-23 23:21:26.154463880 +0100
@@ -1102,8 +1102,8 @@
 
 		jiff = jiffies + (d->next ? CONF_INTER_TIMEOUT : timeout);
 		while (time_before(jiffies, jiff) && !ic_got_reply) {
-			barrier();
-			cpu_relax();
+			set_current_state(TASK_UNINTERRUPTIBLE);
+			schedule_timeout (1);
 		}
 #ifdef IPCONFIG_DHCP
 		/* DHCP isn't done until we get a DHCPACK. */
@@ -1245,7 +1245,6 @@
 
 static int __init ip_auto_config(void)
 {
-	unsigned long jiff;
 	u32 addr;
 
 #ifdef CONFIG_PROC_FS
@@ -1260,18 +1259,16 @@
  try_try_again:
 #endif
 	/* Give hardware a chance to settle */
-	jiff = jiffies + CONF_PRE_OPEN;
-	while (time_before(jiffies, jiff))
-		cpu_relax();
+	set_current_state(TASK_UNINTERRUPTIBLE);
+	schedule_timeout (CONF_PRE_OPEN);
 
 	/* Setup all network devices */
 	if (ic_open_devs() < 0)
 		return -1;
 
 	/* Give drivers a chance to settle */
-	jiff = jiffies + CONF_POST_OPEN;
-	while (time_before(jiffies, jiff))
-		cpu_relax();
+	set_current_state(TASK_UNINTERRUPTIBLE);
+	schedule_timeout (CONF_POST_OPEN);
 
 	/*
 	 * If the config information is insufficient (e.g., our IP address or