Skip to contentSkip to conversation

#define yield() for 2.4 scheduler (anticipating O(1))

RFC PATCH In review Dan Chen 6 participants 8 messages Mar 1, 2002 – Mar 2, 2002

Subsystems (17)
lore
Share & tools
lore

Dan Chen

author
#0 lore raw

RFC PATCH 1/1 #define yield() for 2.4 scheduler (anticipating O(1))

In response to Rik's post concerning a #define yield(), I've done a quick egrep over the 2.4.19-pre2 tree and modified as necessary. This is a strict search and replace. Thanks to Rik and Davide for assistance. Please correct me if I erred.

Signature · 2 lines
Dan Chen                 [email protected]
GPG key:   www.unc.edu/~crimsun/pubkey.gpg.asc
arch/alpha/mm/fault.c +1 -2
diff -uNr linux.orig/arch/alpha/mm/fault.c linux/arch/alpha/mm/fault.c
@@ -196,8 +196,7 @@
  */
 out_of_memory:
 	if (current->pid == 1) {
-		current->policy |= SCHED_YIELD;
-		schedule();
+		yield();
 		down_read(&mm->mmap_sem);
 		goto survive;
 	}
arch/i386/mm/fault.c +1 -2
diff -uNr linux.orig/arch/i386/mm/fault.c linux/arch/i386/mm/fault.c
@@ -86,8 +86,7 @@
 
 out_of_memory:
 	if (current->pid == 1) {
-		current->policy |= SCHED_YIELD;
-		schedule();
+		yield();
 		goto survive;
 	}
 	goto bad_area;
arch/ia64/mm/fault.c +1 -2
diff -uNr linux.orig/arch/ia64/mm/fault.c linux/arch/ia64/mm/fault.c
@@ -196,8 +196,7 @@
   out_of_memory:
 	up_read(&mm->mmap_sem);
 	if (current->pid == 1) {
-		current->policy |= SCHED_YIELD;
-		schedule();
+		yield();
 		down_read(&mm->mmap_sem);
 		goto survive;
 	}
arch/ppc/mm/fault.c +1 -2
diff -uNr linux.orig/arch/ppc/mm/fault.c linux/arch/ppc/mm/fault.c
@@ -197,8 +197,7 @@
 out_of_memory:
 	up_read(&mm->mmap_sem);
 	if (current->pid == 1) {
-		current->policy |= SCHED_YIELD;
-		schedule();
+		yield();
 		down_read(&mm->mmap_sem);
 		goto survive;
 	}
arch/sh/mm/fault.c +1 -2
diff -uNr linux.orig/arch/sh/mm/fault.c linux/arch/sh/mm/fault.c
@@ -207,8 +207,7 @@
 out_of_memory:
 	up_read(&mm->mmap_sem);
 	if (current->pid == 1) {
-		current->policy |= SCHED_YIELD;
-		schedule();
+		yield();
 		down_read(&mm->mmap_sem);
 		goto survive;
 	}
drivers/char/drm-4.0/ffb_drv.c +1 -2
diff -uNr linux.orig/drivers/char/drm-4.0/ffb_drv.c linux/drivers/char/drm-4.0/ffb_drv.c
@@ -710,8 +710,7 @@
 		/* Contention */
 		atomic_inc(&dev->total_sleeps);
 		current->state = TASK_INTERRUPTIBLE;
-		current->policy |= SCHED_YIELD;
-		schedule();
+		yield();
 		if (signal_pending(current)) {
 			ret = -ERESTARTSYS;
 			break;
drivers/char/drm-4.0/tdfx_drv.c +2 -6
diff -uNr linux.orig/drivers/char/drm-4.0/tdfx_drv.c linux/drivers/char/drm-4.0/tdfx_drv.c
@@ -578,10 +578,7 @@
 
                                 /* Contention */
                         atomic_inc(&dev->total_sleeps);
-#if 1
-			current->policy |= SCHED_YIELD;
-#endif
-                        schedule();
+                        yield();
                         if (signal_pending(current)) {
                                 ret = -ERESTARTSYS;
                                 break;
@@ -604,8 +601,7 @@
                    when dev->last_context == lock.context
                    NOTE WE HOLD THE LOCK THROUGHOUT THIS
                    TIME! */
-		current->policy |= SCHED_YIELD;
-	        schedule();
+	        yield();
 	        current->state = TASK_RUNNING;
 	        remove_wait_queue(&dev->context_wait, &entry);
 	        if (signal_pending(current)) {
drivers/ide/ataraid.c +2 -4
diff -uNr linux.orig/drivers/ide/ataraid.c linux/drivers/ide/ataraid.c
@@ -123,8 +123,7 @@
 		ptr=kmalloc(sizeof(struct buffer_head),GFP_NOIO);
 		if (!ptr) {
 			__set_current_state(TASK_RUNNING);
-	                current->policy |= SCHED_YIELD;
-	                schedule();             
+	                yield();
 		}
 	}
 	return ptr;
@@ -139,8 +138,7 @@
 		ptr=kmalloc(sizeof(struct ataraid_bh_private),GFP_NOIO);
 		if (!ptr) {
 			__set_current_state(TASK_RUNNING);
-	                current->policy |= SCHED_YIELD;
-	                schedule();             
+	                yield();
 		}
 	}
 	return ptr;
fs/buffer.c +1 -2
diff -uNr linux.orig/fs/buffer.c linux/fs/buffer.c
@@ -735,9 +735,8 @@
 	wakeup_bdflush();
 	try_to_free_pages(zone, GFP_NOFS, 0);
 	run_task_queue(&tq_disk);
-	current->policy |= SCHED_YIELD;
 	__set_current_state(TASK_RUNNING);
-	schedule();
+	yield();
 }
 
 void init_buffer(struct buffer_head *bh, bh_end_io_t *handler, void *private)
fs/jbd/journal.c +3 -6
diff -uNr linux.orig/fs/jbd/journal.c linux/fs/jbd/journal.c
@@ -460,8 +460,7 @@
 			printk (KERN_NOTICE __FUNCTION__
 				": ENOMEM at get_unused_buffer_head, "
 				"trying again.\n");
-			current->policy |= SCHED_YIELD;
-			schedule();
+			yield();
 		}
 	} while (!new_bh);
 	/* keep subsequent assertions sane */
@@ -1541,8 +1540,7 @@
 			last_warning = jiffies;
 		}
 		
-		current->policy |= SCHED_YIELD;
-		schedule();
+		yield();
 	}
 }
 
@@ -1600,8 +1598,7 @@
 			last_warning = jiffies;
 		}
 		while (ret == 0) {
-			current->policy |= SCHED_YIELD;
-			schedule();
+			yield();
 			ret = kmem_cache_alloc(journal_head_cache, GFP_NOFS);
 		}
 	}
fs/jbd/revoke.c +1 -2
diff -uNr linux.orig/fs/jbd/revoke.c linux/fs/jbd/revoke.c
@@ -137,8 +137,7 @@
 	if (!journal_oom_retry)
 		return -ENOMEM;
 	jbd_debug(1, "ENOMEM in " __FUNCTION__ ", retrying.\n");
-	current->policy |= SCHED_YIELD;
-	schedule();
+	yield();
 	goto repeat;
 }
 
fs/jbd/transaction.c +1 -2
diff -uNr linux.orig/fs/jbd/transaction.c linux/fs/jbd/transaction.c
@@ -1379,8 +1379,7 @@
 		do {
 			old_handle_count = transaction->t_handle_count;
 			set_current_state(TASK_RUNNING);
-			current->policy |= SCHED_YIELD;
-			schedule();
+			yield();
 		} while (old_handle_count != transaction->t_handle_count);
 	}
 
fs/locks.c +1 -2
diff -uNr linux.orig/fs/locks.c linux/fs/locks.c
@@ -445,8 +445,7 @@
 			/* Let the blocked process remove waiter from the
 			 * block list when it gets scheduled.
 			 */
-			current->policy |= SCHED_YIELD;
-			schedule();
+			yield();
 		} else {
 			/* Remove waiter from the block list, because by the
 			 * time it wakes up blocker won't exist any more.
fs/nfs/pagelist.c +1 -2
diff -uNr linux.orig/fs/nfs/pagelist.c linux/fs/nfs/pagelist.c
@@ -96,8 +96,7 @@
 			continue;
 		if (signalled() && (server->flags & NFS_MOUNT_INTR))
 			return ERR_PTR(-ERESTARTSYS);
-		current->policy = SCHED_YIELD;
-		schedule();
+		yield();
 	}
 
 	/* Initialize the request struct. Initially, we assume a
fs/reiserfs/buffer2.c +1 -2
diff -uNr linux.orig/fs/reiserfs/buffer2.c linux/fs/reiserfs/buffer2.c
@@ -33,8 +33,7 @@
 			buffer_journal_dirty(bh) ? ' ' : '!');
     }
     run_task_queue(&tq_disk);
-    current->policy |= SCHED_YIELD;
-    schedule();
+    yield();
   }
   if (repeat_counter > 30000000) {
     reiserfs_warning("vs-3051: done waiting, ignore vs-3050 messages for (%b)\n", bh) ;
fs/reiserfs/journal.c +1 -2
diff -uNr linux.orig/fs/reiserfs/journal.c linux/fs/reiserfs/journal.c
@@ -149,8 +149,7 @@
   }
   bn = allocate_bitmap_node(p_s_sb) ;
   if (!bn) {
-    current->policy |= SCHED_YIELD ;
-    schedule() ;
+    yield();
     goto repeat ;
   }
   return bn ;
include/linux/sched.h +9 -0
diff -uNr linux.orig/include/linux/sched.h linux/include/linux/sched.h
@@ -122,6 +122,15 @@
  */
 #define SCHED_YIELD		0x10
 
+/*
+ * Anticipating inclusion of Ingo's O(1) scheduler...
+ */
+#define yield()					\
+	do {					\
+		current->policy |= SCHED_YIELD;	\
+		schedule();			\
+	} while (0)
+
 struct sched_param {
 	int sched_priority;
 };
init/do_mounts.c +2 -4
diff -uNr linux.orig/init/do_mounts.c linux/init/do_mounts.c
@@ -526,10 +526,8 @@
 
 		pid = kernel_thread(do_linuxrc, "/linuxrc", SIGCHLD);
 		if (pid > 0) {
-			while (pid != wait(&i)) {
-				current->policy |= SCHED_YIELD;
-				schedule();
-			}
+			while (pid != wait(&i))
+				yield();
 		}
 		if (MAJOR(real_root_dev) != RAMDISK_MAJOR
 		     || MINOR(real_root_dev) != 0) {
kernel/softirq.c +3 -6
diff -uNr linux.orig/kernel/softirq.c linux/kernel/softirq.c
@@ -260,8 +260,7 @@
 	while (test_and_set_bit(TASKLET_STATE_SCHED, &t->state)) {
 		current->state = TASK_RUNNING;
 		do {
-			current->policy |= SCHED_YIELD;
-			schedule();
+			yield();
 		} while (test_bit(TASKLET_STATE_SCHED, &t->state));
 	}
 	tasklet_unlock_wait(t);
@@ -405,10 +404,8 @@
 				  CLONE_FS | CLONE_FILES | CLONE_SIGNAL) < 0)
 			printk("spawn_ksoftirqd() failed for cpu %d\n", cpu);
 		else {
-			while (!ksoftirqd_task(cpu_logical_map(cpu))) {
-				current->policy |= SCHED_YIELD;
-				schedule();
-			}
+			while (!ksoftirqd_task(cpu_logical_map(cpu)))
+				yield();
 		}
 	}
 
mm/highmem.c +2 -4
diff -uNr linux.orig/mm/highmem.c linux/mm/highmem.c
@@ -354,9 +354,8 @@
 	/* we need to wait I/O completion */
 	run_task_queue(&tq_disk);
 
-	current->policy |= SCHED_YIELD;
 	__set_current_state(TASK_RUNNING);
-	schedule();
+	yield();
 	goto repeat_alloc;
 }
 
@@ -392,9 +391,8 @@
 	/* we need to wait I/O completion */
 	run_task_queue(&tq_disk);
 
-	current->policy |= SCHED_YIELD;
 	__set_current_state(TASK_RUNNING);
-	schedule();
+	yield();
 	goto repeat_alloc;
 }
 
mm/oom_kill.c +1 -2
diff -uNr linux.orig/mm/oom_kill.c linux/mm/oom_kill.c
@@ -188,8 +188,7 @@
 	 * killing itself before someone else gets the chance to ask
 	 * for more memory.
 	 */
-	current->policy |= SCHED_YIELD;
-	schedule();
+	yield();
 	return;
 }
 
mm/page_alloc.c +1 -2
diff -uNr linux.orig/mm/page_alloc.c linux/mm/page_alloc.c
@@ -429,9 +429,8 @@
 		return NULL;
 
 	/* Yield for kswapd, and try again */
-	current->policy |= SCHED_YIELD;
 	__set_current_state(TASK_RUNNING);
-	schedule();
+	yield();
 	goto rebalance;
 }
 
net/ipv4/tcp_output.c +1 -2
diff -uNr linux.orig/net/ipv4/tcp_output.c linux/net/ipv4/tcp_output.c
@@ -1009,8 +1009,7 @@
 			skb = alloc_skb(MAX_TCP_HEADER, GFP_KERNEL);
 			if (skb)
 				break;
-			current->policy |= SCHED_YIELD;
-			schedule();
+			yield();
 		}
 
 		/* Reserve space for headers and prepare control bits. */
net/sched/sch_generic.c +2 -4
diff -uNr linux.orig/net/sched/sch_generic.c linux/net/sched/sch_generic.c
@@ -475,10 +475,8 @@
 
 	dev_watchdog_down(dev);
 
-	while (test_bit(__LINK_STATE_SCHED, &dev->state)) {
-		current->policy |= SCHED_YIELD;
-		schedule();
-	}
+	while (test_bit(__LINK_STATE_SCHED, &dev->state))
+		yield();
 
 	spin_unlock_wait(&dev->xmit_lock);
 }
net/socket.c +1 -2
diff -uNr linux.orig/net/socket.c linux/net/socket.c
@@ -148,8 +148,7 @@
 	while (atomic_read(&net_family_lockct) != 0) {
 		spin_unlock(&net_family_lock);
 
-		current->policy |= SCHED_YIELD;
-		schedule();
+		yield();
 
 		spin_lock(&net_family_lock);
 	}
net/sunrpc/sched.c +3 -6
diff -uNr linux.orig/net/sunrpc/sched.c linux/net/sunrpc/sched.c
@@ -773,8 +773,7 @@
 		}
 		if (flags & RPC_TASK_ASYNC)
 			return NULL;
-		current->policy |= SCHED_YIELD;
-		schedule();
+		yield();
 	} while (!signalled());
 
 	return NULL;
@@ -1115,8 +1114,7 @@
 		__rpc_schedule();
 		if (all_tasks) {
 			dprintk("rpciod_killall: waiting for tasks to exit\n");
-			current->policy |= SCHED_YIELD;
-			schedule();
+			yield();
 		}
 	}
 
@@ -1186,8 +1184,7 @@
 	 * wait briefly before checking the process id.
 	 */
 	current->sigpending = 0;
-	current->policy |= SCHED_YIELD;
-	schedule();
+	yield();
 	/*
 	 * Display a message if we're going to wait longer.
 	 */
net/unix/af_unix.c +2 -4
diff -uNr linux.orig/net/unix/af_unix.c linux/net/unix/af_unix.c
@@ -565,10 +565,8 @@
 				      addr->hash)) {
 		write_unlock(&unix_table_lock);
 		/* Sanity yield. It is unusual case, but yet... */
-		if (!(ordernum&0xFF)) {
-			current->policy |= SCHED_YIELD;
-			schedule();
-		}
+		if (!(ordernum&0xFF))
+			yield();
 		goto retry;
 	}
 	addr->hash ^= sk->type;
#1 lore raw
Quoted 4 lines · Dan Chen

In response to Rik's post concerning a #define yield(), I've done a quick egrep over the 2.4.19-pre2 tree and modified as necessary. This is a strict search and replace. Thanks to Rik and Davide for assistance. Please correct me if I erred.

Feed it to Marcelo with a few lines of comment ( even if it's clear ).

- Davide

#2 lore raw
In reply to Dan Chen
Quoted 13 lines · Dan Chen

In response to Rik's post concerning a #define yield(), I've done a quick egrep over the 2.4.19-pre2 tree and modified as necessary. This is a strict search and replace. Thanks to Rik and Davide for assistance. Please correct me if I erred.

Signature · 4 lines
Dan Chen                 [email protected]
GPG key:   www.unc.edu/~crimsun/pubkey.gpg.asc

diff -uNr linux.orig/fs/buffer.c linux/fs/buffer.c

fs/buffer.c line 742

Quoted 10 lines
fs/buffer.c +1 -2
@@ -735,9 +735,8 @@
 	wakeup_bdflush();
 	try_to_free_pages(zone, GFP_NOFS, 0);
 	run_task_queue(&tq_disk);
-	current->policy |= SCHED_YIELD;
 	__set_current_state(TASK_RUNNING);
-	schedule();
+	yield();
 }
 
 void init_buffer(struct buffer_head *bh, bh_end_io_t *handler, void *private)

is __set_current_state(TASK_RUNNING) compatible with the new scheduler?

#3 lore raw
Quoted 23 lines · Mike Fedyk
Quoted 22 lines · Dan Chen

In response to Rik's post concerning a #define yield(), I've done a quick egrep over the 2.4.19-pre2 tree and modified as necessary. This is a strict search and replace. Thanks to Rik and Davide for assistance. Please correct me if I erred.

Signature · 4 lines
Dan Chen                 [email protected]
GPG key:   www.unc.edu/~crimsun/pubkey.gpg.asc

diff -uNr linux.orig/fs/buffer.c linux/fs/buffer.c
fs/buffer.c +1 -2
@@ -735,9 +735,8 @@
 	wakeup_bdflush();
 	try_to_free_pages(zone, GFP_NOFS, 0);
 	run_task_queue(&tq_disk);
-	current->policy |= SCHED_YIELD;
 	__set_current_state(TASK_RUNNING);
-	schedule();
+	yield();
 }
 
Quoted 4 lines

fs/buffer.c line 742

Quoted 1 line
fs/buffer.c +0 -0
 void init_buffer(struct buffer_head *bh, bh_end_io_t *handler, void *private)

is __set_current_state(TASK_RUNNING) compatible with the new scheduler? -

I once tried to apply the O(1) scheduler on 2.4.18-pre9 + aa vm and I made a similar change (the O(1) patch was rejected on buffer.c) and it caused so corruption on my file system (ext2), but I'm still not sure what cause it that change was my main concern. I think Ingo is using sys_sched_yield(); instead of yield. I will still be carefull about it though.

#4 lore raw
Quoted 2 lines · Bongani Hlope

I think Ingo is using sys_sched_yield(); instead of yield. I will still be carefull about it though.

Hmm, I guess it is kind of important to use the same name for yielding the CPU that ingo is using ;)

Rik

Signature · 4 lines
"Linux holds advantages over the single-vendor commercial OS"
    -- Microsoft's "Competing with Linux" document

http://www.surriel.com/		http://distro.conectiva.com/
author
#5 lore raw
In reply to Bongani Hlope
Quoted 7 lines · Rik van Riel
Quoted 2 lines · Bongani Hlope

I think Ingo is using sys_sched_yield(); instead of yield. I will still be carefull about it though.

Hmm, I guess it is kind of important to use the same name for yielding the CPU that ingo is using ;)

Ingo is using yield() as well.

Signature · 2 lines
Dan Chen                 [email protected]
GPG key:   www.unc.edu/~crimsun/pubkey.gpg.asc
#7 lore raw
In reply to Dan Chen

I doubt this is an issue specific to the kernel or patches -- I've had O(1) running with -aa and -rmap for quite some time with no problems. I was recoding rather than implementing the macro, but the concept was the same.

Signature · 2 lines
Ken.
[email protected]

On Fri, Mar 01, 2002 at 11:18:12PM +0200, Bongani Hlope wrote:

| I once tried to apply the O(1) scheduler on 2.4.18-pre9 + aa vm and I
| made a similar change (the O(1) patch was rejected on buffer.c) and it
| caused so corruption on my file system (ext2), but I'm still not sure
| what cause it that change was my main concern. I think Ingo is using
| sys_sched_yield(); instead of yield. I will still be carefull about it
| though.