LITMUS^RT: Linux Testbed for Multiprocessor Scheduling in Real-Time Systems

Step 2: Adding stub functions for a LITMUSRT plugin

The first step just added an empty file to the LITMUSRT kernel. In this step, we’ll actually include some placeholder code for the new module.

Basic scheduler plugin code

Modify sched_demo.c to contain the following code, which contains a minimal skeleton of a LITMUSRT scheduler plugin. For now, the plugin does not do anything, apart from registering itself as an available scheduler:

#include <linux/module.h>
#include <litmus/preempt.h>
#include <litmus/sched_plugin.h>

static struct task_struct* demo_schedule(struct task_struct * prev)
{
        /* This mandatory. It triggers a transition in the LITMUS^RT remote
         * preemption state machine. Call this AFTER the plugin has made a local
         * scheduling decision.
         */
        sched_state_task_picked();

        /* We don't schedule anything for now. NULL means "schedule background work". */
        return NULL;
}

static long demo_admit_task(struct task_struct *tsk)
{
        /* Reject every task. */
        return -EINVAL;
}

static struct sched_plugin demo_plugin = {
        .plugin_name            = "DEMO",
        .schedule               = demo_schedule,
        .admit_task             = demo_admit_task,
};

static int __init init_demo(void)
{
        return register_sched_plugin(&demo_plugin);
}

module_init(init_demo);

Explanation of the plugin code

This stub scheduler implementation is best explained from the bottom to the top line of sched_demo.c:

Testing the plugin

After you have finished adding the code to sched_demo.c, re-compile and re-install the kernel. When you reboot, run the following commands as root:

#Navigate to the directory where you built liblitmus
cd liblitmus

#Change the current system scheduler to our DEMO plugin
./setsched DEMO

#This should now print 'DEMO'
./showsched

#Creating a real-time task should fail due to an invalid argument error
./rt-spin 10 100 10

Source code

The full code for this step of the tutorial is available here.


legal imprint | data protection notice