aboutsummaryrefslogtreecommitdiffstats
path: root/setsched
blob: 750ccbf48752d58386cfc9ca76dd3ef6ffb0e424 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#!/bin/bash
#
# setsched: facilitate changing the active scheduler plugin.

ADIR=/proc/litmus/active_plugin
PDIR=/proc/litmus/plugins
DIALOG=`which dialog`

CHOICE=$1

if [ ! -e $ADIR ]; then
    KERN=`uname -s -r`
    echo "Error: LITMUS^RT interface not found on $KERN!"
    echo "Are you sure you booted the correct kernel?"
    echo "Is the /proc filesystem mounted correctly?"
    exit 1
fi

ACTIVE=`cat $ADIR`

if [ -z "$1" ]; then
    # Check for presence of dialog, some distros don't install it by default.
    if [ -z "$DIALOG" ]; then
	echo "Error: The dialog utility cannot be found."
	echo "       Please install the required package (dialog on Ubuntu)."
	echo "       Note that you can also use setsched by passing the"
	echo "       desired scheduling plugins as a commandline argument,"
	echo "       i.e., 'setsched GSN-EDF' activates GSN-EDF."
	exit 2
    fi
    TMP=`mktemp`
    (awk "{print \$1 \" 'Plugin'\"}" $PDIR | \
    xargs $DIALOG --title "Select Plugin" --backtitle "Current: $ACTIVE"  \
	--cancel-label "Cancel" --ok-label "Select Plugin" \
	--menu "Select a new plugin to run: " 15 60 6) 2> $TMP
    OK=$?
    clear
    if [ "$OK" != "0" ]; then
	exit 0;
    fi
    CHOICE=`cat $TMP`
    rm $TMP
fi


echo "$CHOICE" > $ADIR 2> /dev/null || \
    echo "Error: Cannot write to $ADIR. Do you have root privileges?"

ACTIVE=`cat $ADIR`

if [ "$ACTIVE" != "$CHOICE" ]; then
    echo "Error: Setting new plugin failed."
    echo "Are there any active real-time tasks?"
    exit 1
fi