linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "John Yau" <jyau_kernel_dev@hotmail.com>
To: linux-kernel@vger.kernel.org
Subject: [PATCH] Minor scheduler fix to get rid of skipping in xmms
Date: Sat, 06 Sep 2003 05:46:37 -0400	[thread overview]
Message-ID: <Law12-F124jgZ3Vxq7b00024eb1@hotmail.com> (raw)

Hi folks,

I'm new to patch submission process, so bear with me.  This little patch I 
wrote seems to get rid of the annoying skipping in xmms except in the most 
extreme cases.  See comments inlined in code for details of the fix.

xmms still completely hangs every once in a while for me.  However I suspect 
it's due to a bug in xmms that deadlocks.  Anyone else experiencing hangs 
with xmms while tuning into Shoutcast???

Try out this patch and let me know if it fixes things for you.  Other than 
the hangs, xmms is behaving normally now for me.  Please CC me in all 
replies to this thread.


John Yau

--- linux-2.6.0-0.test4.1.32/kernel/sched.c	2003-08-22 19:58:43.000000000 
-0400
+++ linux-2.6.0-custom/kernel/sched.c	2003-09-06 04:20:09.000000000 -0400
@@ -1,4 +1,4 @@
-/*
+ /*
  *  kernel/sched.c
  *
  *  Kernel scheduler and related syscalls
@@ -14,6 +14,9 @@
  *		an array-switch method of distributing timeslices
  *		and per-CPU runqueues.  Cleanups and useful suggestions
  *		by Davide Libenzi, preemptible kernel bits by Robert Love.
+ *  2003-9-6    Changed recalculation of effective priority from being
+ *              calculated at exhaustion of time slices or sleep to
+ *              every use of 20 ms on the CPU by John Yau (jyau)
  */

#include <linux/mm.h>
@@ -1183,7 +1186,11 @@
		(STARVATION_LIMIT && ((rq)->expired_timestamp && \
		(jiffies - (rq)->expired_timestamp >= \
			STARVATION_LIMIT * ((rq)->nr_running) + 1)))
-
+/* jyau:
+ * Recalculate priorities every 20 ms that a task has
+ * used up in its time slice
+ */
+#define RECALCULATE_PRIORITY_TICK (HZ/50 ?: 1)
/*
  * This function gets called by the timer code, with HZ frequency.
  * We call it with interrupts disabled.
@@ -1237,6 +1244,26 @@
	 * goes to sleep or uses up its timeslice. This makes
	 * it possible for interactive tasks to use up their
	 * timeslices at their highest priority levels.
+	 *
+	 * jyau:
+	 *   Updating priority later is a bad idea.  Tasks like
+	 *   xmms will occasionally not get rescheduled quickly enough
+	 *   because they are penalized for using CPU quite a bit
+	 *   more heavily than occassional clicks in e.g. Mozilla,
+	 *   which should be considered a CPU hog when rendering
+	 *   webpages after a click because it will tend to completely
+	 *   use up its time slice.
+	 *
+	 *   I suspect xmms gets booted out of interactive status
+	 *   quite easily and thus have to wait on the order of
+	 *   1000+ ms to get rescheduled in some circumstances,
+	 *   especially if a couple interactive tasks are in line
+	 *   before it.
+	 *
+	 *   We fix this by updating priorities periodically every
+	 *   RECALCULATE_PRIORITY_TICKs that the process has
+	 *   been on the CPU. RECALCULATE_PRIORITY_TICKs is currently
+	 *   set to 20 ms.
	 */
	if (p->sleep_avg)
		p->sleep_avg--;
@@ -1258,11 +1285,12 @@
	}
	if (!--p->time_slice) {
		dequeue_task(p, rq->active);
+
		set_tsk_need_resched(p);
		p->prio = effective_prio(p);
		p->time_slice = task_timeslice(p);
		p->first_time_slice = 0;
-
+
		if (!TASK_INTERACTIVE(p) || EXPIRED_STARVING(rq)) {
			if (!rq->expired_timestamp)
				rq->expired_timestamp = jiffies;
@@ -1270,6 +1298,26 @@
		} else
			enqueue_task(p, rq->active);
	}
+	else if (!(p->time_slice % RECALCULATE_PRIORITY_TICK)) {
+	        int prio;
+                prio = effective_prio(p);
+		if (p->prio != prio)
+		  {
+		    /* jyau:
+		     * The priority changed, alter the queue
+		     * to reflect the change and ask the
+		     * scheduler to find the next appropriate
+		     * process if the priority was demoted.
+		     */
+		    dequeue_task(p, rq->active);
+		    if (prio > p->prio)
+		      {
+			set_tsk_need_resched(p);
+		      }
+		    p->prio = prio;
+		    enqueue_task(p, rq->active);
+		  }
+        }
out_unlock:
	spin_unlock(&rq->lock);
out:

_________________________________________________________________
Try MSN Messenger 6.0 with integrated webcam functionality! 
http://www.msnmessenger-download.com/tracking/reach_webcam


             reply	other threads:[~2003-09-06  9:46 UTC|newest]

Thread overview: 58+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-09-06  9:46 John Yau [this message]
2003-09-06 10:03 ` [PATCH] Minor scheduler fix to get rid of skipping in xmms Michael Buesch
2003-09-06 17:01 ` Robert Love
2003-09-06 17:59   ` John Yau
2003-09-06 18:17   ` John Yau
2003-09-06 19:42     ` Rahul Karnik
2003-09-06 20:04     ` Robert Love
2003-09-06 22:41       ` John Yau
2003-09-07  2:40         ` Martin J. Bligh
2003-09-07  5:13         ` Nick Piggin
2003-09-07  7:48           ` Johnny Yau
2003-09-07  8:10             ` Nick Piggin
2003-09-07  8:35               ` John Yau
2003-09-07  9:26                 ` Nick Piggin
2003-09-07 17:30                   ` John Yau
2003-09-07 17:36                     ` Nick Piggin
2003-09-08  0:22                     ` Con Kolivas
2003-09-08  0:27                       ` David Lang
2003-09-08  0:47                         ` Con Kolivas
2003-09-07  5:08       ` Nick Piggin
2003-09-07  6:18         ` Andrew Morton
2003-09-07  6:29           ` Nick Piggin
2003-09-07  6:45             ` Andrew Morton
2003-09-07  6:59               ` Nick Piggin
2003-09-07  7:02                 ` Nick Piggin
2003-09-07 14:32             ` Martin J. Bligh
2003-09-07 17:02           ` Robert Love
2003-09-07 17:34             ` Andrew Morton
2003-09-07 18:12               ` Nick Piggin
2003-09-07 18:13             ` Nick Piggin
2003-09-06 15:58 John Yau
2003-09-06 16:57 ` Michael Buesch
2003-09-08 22:27 Steven Pratt
2003-09-08 22:56 ` Andrew Morton
2003-09-08 23:22   ` William Lee Irwin III
2003-09-09  2:10   ` Con Kolivas
2003-09-09  2:16     ` Con Kolivas
2003-09-09  2:31       ` Con Kolivas
2003-09-09  2:33         ` Andrew Morton
2003-09-09  4:14         ` Nick Piggin
2003-09-09  6:49           ` Con Kolivas
2003-09-09 23:53           ` Cliff White
2003-09-10  2:12             ` Nick Piggin
2003-09-10 19:05               ` Steven Pratt
2003-09-10 20:23                 ` Dave Hansen
     [not found]                 ` <3F5FE385.10204@cyberone.com.au>
     [not found]                   ` <3F607E62.3010903@austin.ibm.com>
     [not found]                     ` <3F60873B.4000005@cyberone.com.au>
2003-09-11 22:57                       ` Steven Pratt
2003-09-11  0:14               ` Cliff White
2003-09-09 22:06   ` Steven Pratt
2003-09-09 22:12     ` Andrew Morton
2003-09-10 13:59       ` Steven Pratt
2003-09-10 18:51   ` Steven Pratt
     [not found] <tCPY.4xU.1@gated-at.bofh.it>
     [not found] ` <tDsR.5tY.31@gated-at.bofh.it>
     [not found]   ` <tZ0f.49P.5@gated-at.bofh.it>
     [not found]     ` <tZjz.4Bn.7@gated-at.bofh.it>
2003-09-09 23:24       ` David Mosberger-Tang
2003-09-11  2:55 Andrew Theurer
2003-09-11 11:04 ` Nick Piggin
2003-09-11 13:05   ` Andrew Theurer
2003-09-11 13:53     ` Nick Piggin
2003-09-11 14:37       ` Andrew Theurer
2003-09-11 23:32 Craig Thomas

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=Law12-F124jgZ3Vxq7b00024eb1@hotmail.com \
    --to=jyau_kernel_dev@hotmail.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;
as well as URLs for NNTP newsgroup(s).