From: Davide Libenzi <davidel@xmailserver.org>
To: Linux Kernel Mailing List <linux-kernel@vger.kernel.org>
Subject: [patch] SCHED_SOFTRR starve-free linux scheduling policy ...
Date: Sun, 13 Jul 2003 14:51:11 -0700 (PDT) [thread overview]
Message-ID: <Pine.LNX.4.55.0307131442470.15022@bigblue.dev.mcafeelabs.com> (raw)
This should (hopefully) avoid other tasks starvation exploits :
http://www.xmailserver.org/linux-patches/softrr.html
Making SCHED_TS_KSOFTRR a proc tunable might be an option.
- Davide
diff -Nru linux-2.5.74.vanilla/include/linux/sched.h linux-2.5.74.mod/include/linux/sched.h
--- linux-2.5.74.vanilla/include/linux/sched.h Mon Jul 7 16:57:33 2003
+++ linux-2.5.74.mod/include/linux/sched.h Sun Jul 13 14:33:10 2003
@@ -124,6 +124,8 @@
#define SCHED_NORMAL 0
#define SCHED_FIFO 1
#define SCHED_RR 2
+#define SCHED_SOFTRR 3
+
struct sched_param {
int sched_priority;
diff -Nru linux-2.5.74.vanilla/kernel/sched.c linux-2.5.74.mod/kernel/sched.c
--- linux-2.5.74.vanilla/kernel/sched.c Mon Jul 7 16:57:33 2003
+++ linux-2.5.74.mod/kernel/sched.c Sun Jul 13 14:45:42 2003
@@ -76,6 +76,7 @@
#define MAX_SLEEP_AVG (10*HZ)
#define STARVATION_LIMIT (10*HZ)
#define NODE_THRESHOLD 125
+#define SCHED_TS_KSOFTRR 4
/*
* If a task is 'interactive' then we reinsert it in the active
@@ -158,7 +159,7 @@
struct runqueue {
spinlock_t lock;
unsigned long nr_running, nr_switches, expired_timestamp,
- nr_uninterruptible;
+ nr_uninterruptible, ts_timestamp;
task_t *curr, *idle;
struct mm_struct *prev_mm;
prio_array_t *active, *expired, arrays[2];
@@ -1175,6 +1176,7 @@
void scheduler_tick(int user_ticks, int sys_ticks)
{
int cpu = smp_processor_id();
+ unsigned int time_slice;
runqueue_t *rq = this_rq();
task_t *p = current;
@@ -1216,17 +1218,32 @@
p->sleep_avg--;
if (unlikely(rt_task(p))) {
/*
- * RR tasks need a special form of timeslice management.
+ * RR and SOFTRR tasks need a special form of timeslice management.
* FIFO tasks have no timeslices.
*/
- if ((p->policy == SCHED_RR) && !--p->time_slice) {
- p->time_slice = task_timeslice(p);
+ if ((p->policy == SCHED_RR || p->policy == SCHED_SOFTRR) &&
+ !--p->time_slice) {
+ p->time_slice = time_slice = task_timeslice(p);
p->first_time_slice = 0;
set_tsk_need_resched(p);
- /* put it at the end of the queue: */
+ /*
+ * We rotate SCHED_RR like POSIX states. On the
+ * contrary, SCHED_SOFTRR are real-time tasks without
+ * attitude and we do not want them to starve other
+ * tasks while we want them to be able to preempt
+ * SCHED_NORMAL tasks. The rule is that SCHED_SOFTRR
+ * will be expired if they require roughly more then
+ * 1/SCHED_TS_KSOFTRR percent of CPU time.
+ */
dequeue_task(p, rq->active);
- enqueue_task(p, rq->active);
+ if (p->policy == SCHED_RR ||
+ (jiffies - rq->ts_timestamp) > SCHED_TS_KSOFTRR * time_slice)
+ enqueue_task(p, rq->active);
+ else
+ enqueue_task(p, rq->expired);
+
+ rq->ts_timestamp = jiffies;
}
goto out_unlock;
}
@@ -1243,6 +1260,8 @@
enqueue_task(p, rq->expired);
} else
enqueue_task(p, rq->active);
+
+ rq->ts_timestamp = jiffies;
}
out_unlock:
spin_unlock(&rq->lock);
@@ -1740,12 +1759,22 @@
else {
retval = -EINVAL;
if (policy != SCHED_FIFO && policy != SCHED_RR &&
- policy != SCHED_NORMAL)
+ policy != SCHED_NORMAL && policy != SCHED_SOFTRR)
goto out_unlock;
}
/*
- * Valid priorities for SCHED_FIFO and SCHED_RR are
+ * If the caller requested a SCHED_RR policy without having the
+ * necessary rights, we downgrade the policy to SCHED_SOFTRR. This
+ * is currrently here to enable to test the new SOFTRR realtime
+ * policy with existing programs that try to ask for SCHED_RR. Not
+ * sure if this should remain as permanent feature.
+ */
+ if (policy == SCHED_RR && !capable(CAP_SYS_NICE))
+ policy = SCHED_SOFTRR;
+
+ /*
+ * Valid priorities for SCHED_FIFO, SCHED_RR and SCHED_SOFTRR are
* 1..MAX_USER_RT_PRIO-1, valid priority for SCHED_NORMAL is 0.
*/
retval = -EINVAL;
@@ -2069,6 +2098,7 @@
switch (policy) {
case SCHED_FIFO:
case SCHED_RR:
+ case SCHED_SOFTRR:
ret = MAX_USER_RT_PRIO-1;
break;
case SCHED_NORMAL:
@@ -2092,6 +2122,7 @@
switch (policy) {
case SCHED_FIFO:
case SCHED_RR:
+ case SCHED_SOFTRR:
ret = 1;
break;
case SCHED_NORMAL:
next prev reply other threads:[~2003-07-13 21:43 UTC|newest]
Thread overview: 36+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <Pine.LNX.4.55.0307131442470.15022@bigblue.dev.mcafeelabs.c om>
2003-07-14 7:11 ` Mike Galbraith
2003-07-13 21:51 ` Davide Libenzi [this message]
2003-08-09 14:05 ` Daniel Phillips
2003-08-09 17:47 ` Mike Galbraith
2003-08-09 23:58 ` Daniel Phillips
2003-08-10 6:06 ` Mike Galbraith
2003-08-10 0:41 ` Daniel Phillips
2003-08-10 6:41 ` Mike Galbraith
2003-08-10 15:46 ` Daniel Phillips
2003-08-10 17:49 ` Mike Galbraith
2003-08-10 20:28 ` Daniel Phillips
2003-08-11 5:31 ` Mike Galbraith
2003-08-11 13:54 ` Takashi Iwai
2003-08-10 2:05 ` Roger Larsson
2003-08-10 5:43 ` Nick Piggin
2003-08-10 7:41 ` Mike Galbraith
2003-08-10 7:56 ` Nick Piggin
2003-08-10 8:18 ` Mike Galbraith
2003-08-10 9:19 ` jw schultz
2003-08-11 17:01 ` Roger Larsson
2003-08-11 17:25 ` Takashi Iwai
[not found] ` <200308100405.52858.roger.larsson@skelleftea.mail.telia.com >
2003-08-10 7:11 ` Mike Galbraith
2003-08-12 7:23 ` Rob Landley
2003-08-12 23:35 ` Pavel Machek
2003-08-13 6:26 ` Mike Galbraith
2003-08-13 9:41 ` Pavel Machek
2003-07-14 7:12 ` Davide Libenzi
2003-07-14 7:24 ` Jamie Lokier
2003-07-14 7:35 ` Davide Libenzi
2003-07-14 9:11 ` Mike Galbraith
[not found] ` <Pine.LNX.4.55.0307140004390.3435@bigblue.dev.mcafeelabs.co m>
2003-07-14 8:14 ` Mike Galbraith
2003-07-14 15:09 ` Davide Libenzi
[not found] ` <Pine.LNX.4.55.0307140805220.4371@bigblue.dev.mcafeelabs.co m>
2003-07-14 16:06 ` Mike Galbraith
2003-07-14 17:22 ` Davide Libenzi
[not found] ` <Pine.LNX.4.55.0307141015010.4828@bigblue.dev.mcafeelabs.co m>
2003-07-15 4:56 ` Mike Galbraith
2003-07-15 15:47 ` Davide Libenzi
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.55.0307131442470.15022@bigblue.dev.mcafeelabs.com \
--to=davidel@xmailserver.org \
--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®