Subject: Patch for chap-processes.xml (scheduling)
To: None <netbsd-docs@netbsd.org>
From: Daniel Sieger <dsieger@TechFak.Uni-Bielefeld.DE>
List: netbsd-docs
Date: 11/23/2006 10:55:12
--ZoaI/ZTpAVc4A5k6
Content-Type: multipart/mixed; boundary="jI8keyz6grp/JLjh"
Content-Disposition: inline


--jI8keyz6grp/JLjh
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

Hi,
attached is a diff that adds some information about scheduling to=20
NetBSD Internals. The content is taken from scheduler(9). Of course it
would be nice to have more information than just the man-page in the
future, but in the meantime this is better than just a "XXX write me".

Regards,
Daniel

--=20
Daniel Sieger
Faculty of Technology
Bielefeld University
wwwhomes.uni-bielefeld.de/dsieger

--jI8keyz6grp/JLjh
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename="chap-processes.diff"
Content-Transfer-Encoding: quoted-printable

Index: chap-processes.xml
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
RCS file: /cvsroot/htdocs/Documentation/internals/en/chap-processes.xml,v
retrieving revision 1.9
diff -b -u -r1.9 chap-processes.xml
--- chap-processes.xml	21 Nov 2006 22:17:06 -0000	1.9
+++ chap-processes.xml	23 Nov 2006 09:47:23 -0000
@@ -1203,8 +1203,69 @@
   <!-- =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D -->
=20
   <sect1 id=3D"scheduling">
-    <title>Threads scheduling</title>
-    <para>XXX write me</para>
+    <title>Thread scheduling</title>
+    <sect2 id=3D"overview">
+    <title>Overview</title>
+    <para>
+    NetBSD's scheduler algorithm is based on ``multilevel feedback
+    queues''.  All processes that are runnable are assigned a
+    scheduling priority that determines in which run queue they are
+    placed.  The currently running process does not exist on a run
+    queue.  In selecting a new process to run, the system scans the
+    run queues from highest to lowest priority and chooses the first
+    process on the first non-empty queue.  If multiple processes
+    reside on a queue, the system runs them round robin in the order
+    found on the queue.  If a process uses up the time slice
+    allocated to it, it is placed at the end of the queue from which
+    it came, and the process at the front of the queue is selected to
+    run.
+    </para>
+    <para>
+    The system adjusts the scheduling priority of a process
+    dynamically to reflect resource requirements (being blocked) and
+    the CPU utilization consumed by the process.  Processes are moved
+    between run queues based on changes in their scheduling priority
+    (hence the word feedback in the name).
+    </para>
+    <para>
+    The process CPU utilization is incremented in
+    <function>hardclock</function> each time that the system clock
+    ticks and the process is found to be executing.  CPU utilization
+    is adjusted once per second in <function>schedcpu</function> via
+    a digital decay filter.  Each time a process accumulates four
+    ticks in its CPU utilization, <function>schedclock</function>
+    invokes <function>resetpriority</function> to recalculate the
+    process's scheduling priority.
+    </para>
+    <para>
+    When a process other than the currently running process attains a
+    higher scheduling priority, the system notices this in
+    <function>resetpriority</function> and schedules a context switch
+    to the higher-priority process to occur on return to user mode.
+    </para>
+    <para>
+    A blocked process exists on the sleep queue and is not affected
+    by the scheduling behaviour discussed above.  However, each
+    second schedcpu() updates the time each process has been on the
+    sleep queue.  The system recomputes a process's CPU utilization
+    estimate in <function>updatepri</function> when it is awakened
+    and has been sleeping for longer than 1 second.  When the process
+    is placed on the run queue by <function>setrunnable</function>,
+    <function>resetpriority</function> is invoked to recalculate the
+    process's scheduling priority.
+    </para>
+    <para>
+    The system tailors this short-term scheduling algorithm to favor
+    interactive jobs by raising the scheduling priority of
+    processes that are blocked waiting for I/O for one or more
+    seconds, and by lowering the priority of processes that
+    accumulate significant amounts of CPU time.
+    </para>
+    <para>
+    The scheduler subsystem is implemented within the file
+    <filename>sys/kern/kern_synch.c.</filename>
+    </para>
+   </sect2>
   </sect1>
=20
   <!-- =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D -->

--jI8keyz6grp/JLjh--

--ZoaI/ZTpAVc4A5k6
Content-Type: application/pgp-signature
Content-Disposition: inline

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (SunOS)

iD8DBQFFZXAAJUKmeYzbnToRAiRGAKC88HM8Rw+nRIJ30yccmB9ov4cmAgCeOyWF
UWRj1+q7YW+Mpl74Q/3ACJI=
=wosD
-----END PGP SIGNATURE-----

--ZoaI/ZTpAVc4A5k6--