Differences between revisions 1 and 16 (spanning 15 versions)
Revision 1 as of 2012-08-13 12:03:35
Size: 2928
Editor: bbb
Comment:
Revision 16 as of 2012-08-14 10:32:35
Size: 2193
Editor: bbb
Comment:
Deletions are marked like this. Additions are marked like this.
Line 1: Line 1:
A brief guide to creating a new scheduling plugin in LITMUS^RT (based on version 2012.2.) = How to Create a Custom Scheduler Plugin in LITMUS^RT =
Line 3: Line 3:
As an example, we are going to implement a simple semi-partitioned EDF scheduler that migrates jobs among CPUs in a round-robin fashion every 500us of execution. While this is not an overly practical scheduler, it's a good example because it allows to demonstrate how to implement '''migrations''', '''per-processor state''', and '''custom scheduling timers'''. A brief guide to creating a new scheduling plugin in LITMUS^RT^ (based on version 2012.2.)
Line 5: Line 5:
= Prerequisites = == Prerequisites ==
Line 7: Line 7:
 * A testing environment (i.e., KVM/Qemu or Bochs).  * A testing environment (i.e., KVM/Qemu or Bochs). This tutorial assumes KVM.
Line 11: Line 11:

= General Guidelines =
== General Guidelines ==
Line 16: Line 15:
Commit early, commit often. Make many small commits a you go along. You can clean them up later using git rebase. Test incrementally to catch errors early. Compile test after each edit. Test-boot as often as possible. The earlier you catch an error, the easier it is to debug.

Commit early, commit often. Make many small commits a you go along. You can clean them up later using `git rebase`.
Line 20: Line 21:
Follow the kernel coding standard defined in Documentation/CodingStyle, even when writing “throw away” code. Follow the kernel coding standard defined in [[http://lxr.linux.no/linux/Documentation/CodingStyle|Documentation/CodingStyle]], even when writing “throw away” code.
Line 23: Line 24:
= Step 0: Checkout and Compile the Kernel = == Steps ==
Line 25: Line 26:
First, obtain a copy of the LITMUSRT kernel.
{{{
$ git clone http://www.litmus-rt.org/src/litmus-rt.git
}}}
The tutorial is structured in a series of steps, which are intended to be completed sequentially. When working through these, you should reproduce the instructions on your own local machine. If something seems unclear, please feel free to ask on the [[Mailinglist|mailinglist]] for clarification.
Line 30: Line 28:
Next, obtain a copy of liblitmus, the corresponding userspace library
{{{
$ git clone http://www.litmus-rt.org/src/liblitmus.git
Cloning into liblitmus...
$ cd liblitmus/
$ ls
INSTALL Makefile README arch bin inc include setsched showsched src tests
}}}
In the first seven steps, the tutorial re-creates a ''partitioned EDF'' (P-EDF) scheduler. In contrast to the PSN-EDF plugin shipping with LITMUS^RT^, the demo implementation does not support locking and non-preemptive sections to keep it simple.
Line 39: Line 30:
 * [[/Step0|Step 0: checkout and compile the kernel]]
 * [[/Step1|Step 1: add a source file to the build system]]
 * [[/Step2|Step 2: register a dummy plugin]]
 * [[/Step3|Step 3: log debug message with TRACE()]]
 * [[/Step4|Step 4: define P-EDF per-processor state]]
 * [[/Step5|Step 5: add P-EDF scheduling function]]
 * [[/Step6|Step 6: add support for task state changes]]
 * [[/Step7|Step 7: implement preemptive P-EDF]]
 * [[/Step8|Step 8: admit real-time tasks]]
Line 40: Line 40:
= Step 1: Dummy File =
Create a new file and add it to the build system.
 1. Create the file `litmus/sched_demo.c` (all file names are relative to the kernel repository).
 2. Edit the file `litmus/Makefile` to add `sched_demo.o` to the list named `obj-y`.
 3. Compile the kernel to see if everything works.

= Step 2: Dummy Plugin =

Edit the file `litmus/sched_demo.c` to declare a dummy plugin (that implements no particular policy and that rejects all tasks).

= Step 3: Define the Per-Processor State =
In this step, we define the scheduler state on each processor.

= Step 4: Augment the Per-Task State =
Our scheduler needs to keep track of...

= Step 5: Initialize the Scheduler Plugin =

= Step 6: Initialize new Tasks =

= Step 7: Enable Admission of Tasks =

= Step 8: Boot the Kernel in KVM =

{{{
kvm -gdb tcp::3008 -smp 4 -hda /RTS/litmus-rt/work/kvm-images/bbb-litmus-rt.img -m 2000 -net nic,model=e1000 -net user -k en-us -kernel /home/bbb/ldev/litmus-rt/arch/x86/boot/bzImage -append console=ttyS0 ro root=/dev/hda1 no_timer_check no_timer_check -nographic -redir tcp:2104::22
}}}

= Step 9: Observe the Debugging TRACE() Log =

= Step 10: Trace Task Execution =

= Step 11: Visualize the Trace =

= Step 12: Record Scheduling Overheads =

= Step 13: Analyze Scheduling Overheads =
''To be continued... please contribute.''

How to Create a Custom Scheduler Plugin in LITMUS^RT

A brief guide to creating a new scheduling plugin in LITMUSRT (based on version 2012.2.)

Prerequisites

  • A testing environment (i.e., KVM/Qemu or Bochs). This tutorial assumes KVM.
  • Strong C programming skills.
  • Ideally, some exposure to OS kernel development.

General Guidelines

Work in a checked-out git repository. Do not use the tarball from the web page. This will make keeping track of your edits and incorporating upstream changes much easier.

Test incrementally to catch errors early. Compile test after each edit. Test-boot as often as possible. The earlier you catch an error, the easier it is to debug.

Commit early, commit often. Make many small commits a you go along. You can clean them up later using git rebase.

Do not commit to the master branch. This will make incorporating upstream changes much easier.

Follow the kernel coding standard defined in Documentation/CodingStyle, even when writing “throw away” code.

Steps

The tutorial is structured in a series of steps, which are intended to be completed sequentially. When working through these, you should reproduce the instructions on your own local machine. If something seems unclear, please feel free to ask on the mailinglist for clarification.

In the first seven steps, the tutorial re-creates a partitioned EDF (P-EDF) scheduler. In contrast to the PSN-EDF plugin shipping with LITMUSRT, the demo implementation does not support locking and non-preemptive sections to keep it simple.

To be continued... please contribute.

CreateAPluginTutorial (last edited 2014-06-12 15:51:56 by bbb)