From: george anzinger <george@mvista.com>
To: "linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
Rik van Riel <riel@conectiva.com.br>
Subject: Child first after fork violates the SCHED_FIFO and SCHED_RR standard.
Date: Tue, 08 May 2001 15:31:45 -0700 [thread overview]
Message-ID: <3AF873D1.20463840@mvista.com> (raw)
[-- Attachment #1: Type: text/plain, Size: 863 bytes --]
The standard says a SCHED_FIFO task only gives up the processor if it
blocks, yields, or changes its priority.
The counter is not really used by SCHED_FIFO tasks, however the
update_process_times() code will set the "need_resched" flag on a
SCHED_FIFO task, even though schedule() effectively ignores the entry.
The attached patch addresses these issues by setting the counter to -100
for SCHED_FIFO tasks and "teaching" update_process_timers() to not count
down negative counters. This avoids the calling of schedule() every
jiffie while a SCHED_FIFO task is running.
I tried to keep the change to recalculate confined to only the data
elements it was already touching, however, the standard really doesn't
allow recalculate to touch the SCHED_RR counter. A standard conforming
test would restrict recalculate to only SCHED_OTHER tasks.
Comments?
George
[-- Attachment #2: fifo-2.4.4.patch --]
[-- Type: text/plain, Size: 2435 bytes --]
diff -urP -X /usr/src/patch.exclude linux-2.4.4-kb/kernel/fork.c linux/kernel/fork.c
--- linux-2.4.4-kb/kernel/fork.c Mon May 7 14:46:17 2001
+++ linux/kernel/fork.c Tue May 8 15:17:51 2001
@@ -673,10 +673,14 @@
* if the child for a fork() just wants to do a few simple things
* and then exec(). This is only important in the first timeslice.
* In the long run, the scheduling behavior is unchanged.
+ * SCHED_FIFO tasks don't count down and have a negative counter.
+ * Don't change these, least they all end up at -1.
*/
- p->counter = current->counter;
- current->counter = 0;
- current->need_resched = 1;
+ if (p->policy == SCHED_OTHER){
+ p->counter = current->counter;
+ current->counter = 0;
+ current->need_resched = 1;
+ }
/*
* Ok, add it to the run-queues and make it
diff -urP -X /usr/src/patch.exclude linux-2.4.4-kb/kernel/sched.c linux/kernel/sched.c
--- linux-2.4.4-kb/kernel/sched.c Mon May 7 14:46:17 2001
+++ linux/kernel/sched.c Tue May 8 13:43:54 2001
@@ -682,7 +682,10 @@
spin_unlock_irq(&runqueue_lock);
read_lock(&tasklist_lock);
for_each_task(p)
- p->counter = (p->counter >> 1) + NICE_TO_TICKS(p->nice);
+ if (p->counter >= 0 ){
+ p->counter = (p->counter >> 1) +
+ NICE_TO_TICKS(p->nice);
+ }
read_unlock(&tasklist_lock);
spin_lock_irq(&runqueue_lock);
}
@@ -932,6 +935,11 @@
retval = 0;
p->policy = policy;
+ if ( policy == SCHED_FIFO) {
+ p->counter = -100; /* we don't count down neg couters */
+ }else{
+ p->counter = NICE_TO_TICKS(p->nice);
+ }
p->rt_priority = lp.sched_priority;
if (task_on_runqueue(p))
move_first_runqueue(p);
diff -urP -X /usr/src/patch.exclude linux-2.4.4-kb/kernel/timer.c linux/kernel/timer.c
--- linux-2.4.4-kb/kernel/timer.c Sun Dec 10 09:53:19 2000
+++ linux/kernel/timer.c Tue May 8 15:14:37 2001
@@ -583,7 +583,11 @@
update_one_process(p, user_tick, system, cpu);
if (p->pid) {
- if (--p->counter <= 0) {
+ /*
+ * SCHED_FIFO and the idle(s) have counters set to -100,
+ * so we won't count them.
+ */
+ if (p->counter >= 0 && --p->counter <= 0) {
p->counter = 0;
p->need_resched = 1;
}
reply other threads:[~2001-05-08 22:32 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=3AF873D1.20463840@mvista.com \
--to=george@mvista.com \
--cc=linux-kernel@vger.kernel.org \
--cc=riel@conectiva.com.br \
/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;
as well as URLs for NNTP newsgroup(s).