All of lore.kernel.org
 help / color / mirror / Atom feed
From: Robert Love <rml@tech9.net>
To: alan@redhat.com
Cc: mingo@elte.hu, linux-kernel@vger.kernel.org
Subject: [PATCH] 2.4-ac: sched_yield()
Date: 11 Sep 2002 18:21:18 -0400	[thread overview]
Message-ID: <1031782879.937.29.camel@phantasy> (raw)

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

Hi Alan,

Following is a set of scheduler updates from 2.5.  All should be sane
and safe.  I would prefer to toss you obviously correct/tested bits in
pieces than a large single update.  You can also get all of these at:
	ftp://ftp.kernel.org/pub/linux/kernel/people/rml/sched/for_alan

Anyhow...

Attached patch gets sched_yield() right, fixing all outstanding issues.
Really. (from Ingo)

Also implement 2.5's yield() which sets task->state to be safe. (from
akpm)

Patch is against 2.4.20-pre5-ac4, please apply.

	Robert Love


[-- Attachment #2: 200-sched-yield.patch --]
[-- Type: text/x-patch, Size: 3655 bytes --]

diff -urN linux-2.4.20-pre5-ac4/include/linux/sched.h linux/include/linux/sched.h
--- linux-2.4.20-pre5-ac4/include/linux/sched.h	Mon Sep  9 19:27:59 2002
+++ linux/include/linux/sched.h	Wed Sep 11 16:13:21 2002
@@ -486,9 +486,7 @@
 extern int task_prio(task_t *p);
 extern int task_nice(task_t *p);
 extern int idle_cpu(int cpu);
-
-asmlinkage long sys_sched_yield(void);
-#define yield() sys_sched_yield()
+extern void yield(void);
 
 /*
  * The default (Linux) execution domain.
diff -urN linux-2.4.20-pre5-ac4/kernel/ksyms.c linux/kernel/ksyms.c
--- linux-2.4.20-pre5-ac4/kernel/ksyms.c	Mon Sep  9 19:27:58 2002
+++ linux/kernel/ksyms.c	Wed Sep 11 16:23:02 2002
@@ -455,7 +455,7 @@
 EXPORT_SYMBOL(interruptible_sleep_on_timeout);
 EXPORT_SYMBOL(schedule);
 EXPORT_SYMBOL(schedule_timeout);
-EXPORT_SYMBOL(sys_sched_yield);
+EXPORT_SYMBOL(yield);
 EXPORT_SYMBOL(set_user_nice);
 EXPORT_SYMBOL(task_nice);
 EXPORT_SYMBOL_GPL(idle_cpu);
diff -urN linux-2.4.20-pre5-ac4/kernel/sched.c linux/kernel/sched.c
--- linux-2.4.20-pre5-ac4/kernel/sched.c	Mon Sep  9 19:27:58 2002
+++ linux/kernel/sched.c	Wed Sep 11 16:13:31 2002
@@ -1366,46 +1366,31 @@
 	return real_len;
 }
 
+/**
+ * sys_sched_yield - yield the current processor to other threads.
+ *
+ * this function yields the current CPU by moving the calling thread
+ * to the expired array. If there are no other threads running on this
+ * CPU then this function will return.
+ */
 asmlinkage long sys_sched_yield(void)
 {
 	runqueue_t *rq = this_rq_lock();
 	prio_array_t *array = current->array;
 
 	/*
-	 * There are three levels of how a yielding task will give up
-	 * the current CPU:
+	 * We implement yielding by moving the task into the expired
+	 * queue.
 	 *
-	 *  #1 - it decreases its priority by one. This priority loss is
-	 *       temporary, it's recovered once the current timeslice
-	 *       expires.
-	 *
-	 *  #2 - once it has reached the lowest priority level,
-	 *       it will give up timeslices one by one. (We do not
-	 *       want to give them up all at once, it's gradual,
-	 *       to protect the casual yield()er.)
-	 *
-	 *  #3 - once all timeslices are gone we put the process into
-	 *       the expired array.
-	 *
-	 *  (special rule: RT tasks do not lose any priority, they just
-	 *  roundrobin on their current priority level.)
+	 * (special rule: RT tasks will just roundrobin in the active
+	 *  array.)
 	 */
-	if (likely(current->prio == MAX_PRIO-1)) {
-		if (current->time_slice <= 1) {
-			dequeue_task(current, rq->active);
-			enqueue_task(current, rq->expired);
-		} else
-			current->time_slice--;
-	} else if (unlikely(rt_task(current))) {
-		list_del(&current->run_list);
-		list_add_tail(&current->run_list, array->queue + current->prio);
+	if (likely(!rt_task(current))) {
+		dequeue_task(current, array);
+		enqueue_task(current, rq->expired);
 	} else {
 		list_del(&current->run_list);
-		if (list_empty(array->queue + current->prio))
-			__clear_bit(current->prio, array->bitmap);
-		current->prio++;
 		list_add_tail(&current->run_list, array->queue + current->prio);
-		__set_bit(current->prio, array->bitmap);
 	}
 	spin_unlock(&rq->lock);
 
@@ -1414,6 +1399,18 @@
 	return 0;
 }
 
+/**
+ * yield - yield the current processor to other threads.
+ *
+ * this is a shortcut for kernel-space yielding - it marks the
+ * thread runnable and calls sys_sched_yield().
+ */
+void yield(void)
+{
+	set_current_state(TASK_RUNNING);
+	sys_sched_yield();
+}
+
 asmlinkage long sys_sched_get_priority_max(int policy)
 {
 	int ret = -EINVAL;

                 reply	other threads:[~2002-09-11 22:16 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1031782879.937.29.camel@phantasy \
    --to=rml@tech9.net \
    --cc=alan@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@elte.hu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.