Linux scheduling latency


This page contains a collection of notes and tools related to an effort to decrease the typical scheduling latency of the 2.4.x kernel.
 

Index

timepegs
schedlat
amlat
rtc-debug
downloads
things not to do
Ingo Molnar's patches

Tools

timepegs

The timepeg framework is a base tool which is used to measure time intervals between particular points in the kernel.  You're on the wrong page.  Go to here and grab it.


schedlat

This is a kernel patch which uses timepegs to measure intervals during which the kernel is ignoring reschedule requests.

What schedlat does is to record the interval between a process entering the kernel and leaving the kernel.  A process may enter the kernel in one of the following ways:
 

A process exits the kernel by:
  What schedlat does is to maintain four arrays of timepegs, each dimensioned by NR_syscalls:
 
 

                      |           |
                ______|___________|___________________________
syscall_start   | 0 | | | 2 | 3 | | | 5 | 6 | 7 | 8 | 9 |   |
                ------+-----------+--------------------------
                    A |         C |
                ______|________   |   _______________________
switchout       |   | | |   |     |     |   |   |   |   |   |
                ------+--------   |   -----------------------
                      |           |
                ______|________   |   _______________________
switchin        |   | | |   |     |     |   |   |   |   |   |
                ------+--------   |   -----------------------
                    B |           |
                ______|___________|__________________________
syscall_stop    |   | | |   |   | | |   |   |   |   |   |   |
                ------+-----------+--------------------------
                      |           |
                      V           V

Here, one code path enters syscall1, gets scheduled out, then gets scheduled back in and then exits the system call.  In this case schedlat will report the "A" and "B" intervals.

The other code path does not get scheduled out - it simply enters and leaves.  schedlat will report the "C" interval.

Here's some sample schedlat output:

        start_0004:0 -> stop_0004:0  65401     .30  8035.76     8.64  565621.23
        start_0006:0 -> stop_0006:0  1145      .22  7484.32    10.99   12592.34
   start_0005:0 -> switchout_0005:0  38      70.57  3729.48   253.28    9624.84
switchin_0005:0 -> switchout_0005:0  23      26.72  3208.19   342.06    7867.62
     switchin_0005:0 -> stop_0005:0  38      16.98  2140.33    99.25    3771.69
        start_0054:0 -> stop_0054:0  5105      .32  2001.27     1.76    9021.48
        start_0002:0 -> stop_0002:0  131    217.87  1882.48   428.13   56085.73

This shows syscall 4 taking 8035 microseconds to enter and exit the kernel.

It shows syscall 5 spending 7,484 microseconds between entering the kernel and getting scheduled out, and taking 2,140 microseconds between getting scheduled in and exitting the system call.

schedlat converts page fault events so they look like system call 255.  After all, page faults are just another way of entering the kernel and requesting services from it.
 

Using schedlat

You really should run amlat while testing things!  This introduces "scheduling pressure" and ensures that we are pushing all SCHED_OTHER tasks as hard as we can.  If `amlat' is not running, the SCHED_OTHER tasks may have no reason to be descheduled!

Schedlat is part of the timepeg patch, below.  It is enabled under the `kernel hacking' configuration item.


amlat

amlat is a little user-mode program which does the following:
  The importance of amlat is that it introduces scheduling pressure against SCHED_OTHER tasks, and that it does the read from /dev/rtc in the SIGIO handler. This read allows rtc-debug to generate good scheduling latency estimates.


rtc-debug

This is a patch against the /dev/rtc driver.  It is VERY useful! It does the following:
 

Downloads


Timepegs
amlat
rtc-debug

2.4.2-low-latency.patch  (See note below)
2.4.4-low-latency.patch (Thanks to Mark McCallister)
2.4.5-low-latency.patch.gz (Thanks to Josh Green)
2.4.7-low-latency.patch.gz
2.4.6-ac5-low-latency.patch.gz
2.4.8-pre6-low-latency.patch.gz  (Thanks to J Sloan)
2.4.8-low-latency.patch.gz  (Thanks to J Sloan)
2.4.9-low-latency.patch.gz  (Thanks to J Sloan and Nick Bellinger)
2.4.10-low-latency.patch.gz  (Thanks to Nick Bellinger)
2.4.11-pre3-low-latency.patch.gz  (Thanks to J Sloan)
2.4.12-ac2-low-latency.patch.gz
2.4.13-low-latency.patch.gz  (Thanks to Martin Schwenke)
2.4.14-low-latency.patch.gz  (Thanks to J Sloan)
2.4.13-ac8-low-latency.patch.gz
2.4.15-pre5-low-latency.patch.gz
2.4.15-pre7-low-latency.patch.gz
2.4.16-low-latency.patch.gz
2.4.17-pre2-low-latency.patch.gz
2.4.17-low-latency.patch.gz     (Also applies to 2.4.18-pre1)
2.4.18-pre6-low-latency.patch.gz
2.4.18-pre9-low-latency.patch.gz  (J Sloan)
2.4.18-rc1-low-latency.patch.gz
2.4.19-pre7-low-latency.patch.gz
2.4.19-pre10-low-latency.patch.gz  (Includes DRM additions from Jussi Laako)
2.4.19-low-latency.patch.gz
2.4.20-low-latency.patch.gz
2.4.21-low-latency.patch.gz
2.4.22-low-latency.patch.gz
2.4.23-low-latency.patch.gz
2.4.25-low-latency.patch.gz
2.4.29-low-latency.patch.gz

Paul Winkler has put up a nice page which shows how to build 2.4 kernels (including this patch).


The note below



Don't do that!

There are a few things you can do to your Linux system which will simply kill its scheduling latency.  This section describes those things as we discover them.  So far, none of these are show-stoppers - it is feasible to setup your system and it software so these things don't happen.
  If you observe all the above, you should be able to achieve consistent worse-case scheduling latencies of 0.5 milliseconds on a 500MHz machine.

If something goes wrong and you start seeing scheduling latencies, please try to investigate the source using the above tools (mainly rtc_debug and amlat) and let me know what you're doing to cause this.


Ingo Molnar's patches


Ingo Molnar wrote Linux's first low-latency scheduling patches.   Those patches use the same algorithmic approach as the ones here, and these patches borrow a few bits and pieces from Ingo's.

Ingo also has patches against the 2.2 kernels.

His work is available at http://people.redhat.com/mingo/lowlatency-patches/
 



AKPM Home
Andrew Morton, 7 Jan 2001