From: "Bhavesh P. Davda" <bhavesh@avaya.com>
To: linux-kernel@vger.kernel.org
Cc: bhavesh@avaya.com
Subject: [PATCH] SCHED_FIFO and SCHED_RR scheduler fix, kernel 2.4.18
Date: Wed, 12 Jun 2002 10:19:51 -0600 (MDT) [thread overview]
Message-ID: <Pine.LNX.4.44.0206120942410.2422-200000@localhost.localdomain> (raw)
[-- Attachment #1: Type: TEXT/PLAIN, Size: 836 bytes --]
The 2.4.18 kernel was behaving incorrectly for SCHED_FIFO and SCHED_RR
scheduling.
The correct behaviour for SCHED_FIFO is priority preemption:
run to completion, or system call, or preemption by higher priority
process. The correct behaviour for SCHED_RR is the same as SCHED_FIFO for
the preemption case, or run for a time slice, and go to the back of the
run queue for that priority.
More details can be found at:
http://www.opengroup.org/onlinepubs/7908799/xsh/realtime.html
As a side note, SCHED_RR is completely broken in the 2.2 series kernels.
This is a small patch, but fixes the behaviour for SCHED_FIFO and SCHED_RR
scheduling in the 2.4.18 kernel. It also improves the efficiency of the
kernel by NOT calling schedule() for every tick for a SCHED_FIFO process.
--
Bhavesh P. Davda
Avaya Inc
bhavesh@avaya.com
[-- Attachment #2: Type: TEXT/PLAIN, Size: 2135 bytes --]
diff -Naur linux-2.4.18/kernel/sched.c linux-2.4.18-bpd/kernel/sched.c
--- linux-2.4.18/kernel/sched.c Fri Dec 21 10:42:04 2001
+++ linux-2.4.18-bpd/kernel/sched.c Wed Jun 12 09:12:12 2002
@@ -318,13 +318,17 @@
/*
* Careful!
*
- * This has to add the process to the _beginning_ of the
- * run-queue, not the end. See the comment about "This is
- * subtle" in the scheduler proper..
+ * This has to add the process to the _end_ of the
+ * run-queue, not the beginning. The goodness value will
+ * determine whether this process will run next. This is
+ * important to get SCHED_FIFO and SCHED_RR right, where
+ * a process that is either pre-empted or its time slice
+ * has expired, should be moved to the tail of the run
+ * queue for its priority - Bhavesh Davda
*/
static inline void add_to_runqueue(struct task_struct * p)
{
- list_add(&p->run_list, &runqueue_head);
+ list_add_tail(&p->run_list, &runqueue_head);
nr_running++;
}
@@ -334,12 +338,6 @@
list_add_tail(&p->run_list, &runqueue_head);
}
-static inline void move_first_runqueue(struct task_struct * p)
-{
- list_del(&p->run_list);
- list_add(&p->run_list, &runqueue_head);
-}
-
/*
* Wake up a process. Put it on the run-queue if it's not
* already there. The "current" process is always on the
@@ -955,8 +953,6 @@
retval = 0;
p->policy = policy;
p->rt_priority = lp.sched_priority;
- if (task_on_runqueue(p))
- move_first_runqueue(p);
current->need_resched = 1;
diff -Naur linux-2.4.18/kernel/timer.c linux-2.4.18-bpd/kernel/timer.c
--- linux-2.4.18/kernel/timer.c Mon Oct 8 11:41:41 2001
+++ linux-2.4.18-bpd/kernel/timer.c Wed Jun 12 09:13:43 2002
@@ -585,7 +585,14 @@
if (p->pid) {
if (--p->counter <= 0) {
p->counter = 0;
- p->need_resched = 1;
+ /*
+ * SCHED_FIFO is priority preemption, so this is
+ * not the place to decide whether to reschedule a
+ * SCHED_FIFO task or not - Bhavesh Davda
+ */
+ if (p->policy != SCHED_FIFO) {
+ p->need_resched = 1;
+ }
}
if (p->nice > 0)
kstat.per_cpu_nice[cpu] += user_tick;
next reply other threads:[~2002-06-12 16:19 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2002-06-12 16:19 Bhavesh P. Davda [this message]
2002-06-13 18:36 ` Ingo Molnar
2002-06-13 21:14 ` Bhavesh P. Davda
2002-06-13 21:24 ` Robert Love
2002-06-13 21:27 ` Ingo Molnar
2002-06-13 21:35 ` Ingo Molnar
2002-06-13 22:11 ` Richard Seaman, Jr.
2002-06-13 22:43 ` Bhavesh P. Davda
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=Pine.LNX.4.44.0206120942410.2422-200000@localhost.localdomain \
--to=bhavesh@avaya.com \
--cc=linux-kernel@vger.kernel.org \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®