Anda di halaman 1dari 4

Optimization of Linux OS for real time embedded

application.
Padma1, Chandrashekaran2,Channabassappa baligar3 ,Srinivas rao4
1

M Tech, 4th Semester VLSI Design & Embedded Systems, VTU Regional Centre @ UTL Technologies, Bangalore -22
2
Scientist C, LRDE, DRDO, C V Raman Nagar, Bangalore-93
3
Visiting Professor, VTU Extension Centre, UTL technologies Ltd, Bangalore-22
4
Scientist E, LRDE, DRDO, C V Raman Nagar, Bangalore-93
1
padmaaug9@gmail.com , 2sekarchandran@gmail.com ,3baligarc@yahoo.co.in

AbstractThe Linux kernel is mainly used is general-purpose


operating system, i.e., in server and/or desktop environments.
During the last years, however, academic institutions and
companies showed an increasing interest in using it for realtime and control applications as well.
Since Linux has not been designed to be a real-time
operating, the best-effort scheduling policy is not suited to
provide high utilization and strong guarantees to timesensitive tasks. This paper present an enhancement of the
Linux scheduler through the implementation of the wellknown Earliest Deadline First algorithm for real-time tasks,
leaving the current behavior of existing policies unchanged .
And also the time slice of the round robin-scheduling
algorithm is reduced so that the real time task experience
shorter blockings.
I. INTRODUCTION
Linux is a General Purpose Operating System (GPOS)
originally designed to be used in server or desktop
environments. Since then, Linux has evolved and grown to be
used in almost all computer areas. An important part of Linux
is the process scheduler (or simply the scheduler). This
component of the kernel selects which process to execute at
any instant of time, and is responsible of dividing the finite
resource of processor time between all runnable processes in
the system.
During the last years, there has been a considerable interest in
using Linux also for real-time and control, from both
academic institutions and companies. Some reasons for this
could be the free availability of its source code, the support for
a great number of architectures, a rich set of already
developed device drivers and the existence of billions of
applications running on it. Unfortunately, Linux has not been
designed to be a Real-Time Operating System (RTOS), thus
not much attention has been given to real-time issues.
Therefore, making a classical real-time feasibility study of the
system under development is not possible, and developers
cannot be sure that timing requirements of tasks will be met
under every circumstance. POSIX-compliant fixed-priority
policies offered by Linux, on the other hand, are not much
sophisticated and often do not suit the specific application
requirements.

These issues are particularly critical when designing time


sensitive or control applications (e.g., MPEG players) for
embedded devices like smart-phones. In fact, when size,
processing power, energy consumption and cost are tightly
constrained, you need to efficiently exploit system resources,
and at the same time meet the real-time requirements of the
application.
It has to be said that companies exists that started selling
modified versions of the Linux kernel with improved real-time
support. However, these non-standard versions of Linux are
often non-free, and cannot avail themselves of the support
from the huge development community of the standard kernel.
Therefore, we believe that to be really general, Linux
should also provide enhanced real-time scheduling
capabilities. In this paper, thus, we propose an implementation
of the Earliest Deadline First (EDF) algorithm, the wellknown real-time dynamic-priority scheduling algorithm.
The paper is organized as follows: at the beginning the current
Linux scheduler is explained and the implementation of the
proposed scheduling policy (SCHED EDF) is provided, then
the explanation of the reduction of cpu quantum time is
provided. Last but not least, our implementation is evaluated
and validated through a test and experiments on real hardware,
and finally, conclusions are driven.
II. CURRENT LINUX SCHEDULER
Linux provides two real-time scheduling policies,
SCHED_FIFO and SCHED_RR. SCHED_FIFO (First In-First
Out) scheduling is simple, priority-based, pre-emptive
scheduler. It implements a simple FIFO algorithm without
time slices, meaning that when SCHED_FIFOtask becomes
runnable, it will continue to run until it blocks or explicitly
yields the processor. The only scheduling attribute this policy
takes is tasks priority.
Currently, Linux comes with two scheduling
classes
1.

Sched_fair: the Completely Fair Scheduler (CFS)


algorithm, for SCHED_NORMAL and SCHED_BATCH
policies. The idea here is to run tasks in parallel and at

precise weighted speeds, in, so that


receives a fair amount of processor share;
2.

each task Pick next task (...): chooses the most appropriate task
eligible to be run next;

Sched_rt: the POSIX fixed-priority real-time scheduling,


for SCHED FIFO or SCHED RR policies with 99 priority
levels.

Put prev task (...): makes a running task no longer running;


Select task rq(...): chooses on which runqueue (i.e., on which
CPU) a waking-up task has to be enqueued;

SCHED_FIFO: Linux uses priority arrays, data


structures, which contain one queue for each priority
level. A SCHED_FIFO task that has been preempted by
another task of higher priority will stay at the head of the
list for its priority and will be selected for execution as
soon as all tasks of higher priority are blocked again.
When a SCHED_FIFO task becomes runnable, it will be
inserted at the end of the list for its priority.

Task tick (...): accounts each periodic system tick


to the running tasks.

SCHED_RR: Round Robin scheduling is a real-time


round robin algorithm, a simple enhancement of
SCHED_FIFO, which allows tasks with same priority to
time slice amongst each other. Tasks running under
SCHED_RR run just like those running under
SCHED_FIFO, except that SCHED_RR tasks get to run
only for the time quantum before being put back to the
end of the queue for particular priority level.

IV. REDUCING TIMESLICE


The time slice of RR scheduling is usually around 20
milliseconds in kernel 2.6.24 so it is reduced to around 4
milliseconds.

V. TESTING
An application code has been written to test the new scheduler
and also to test the time slice of RR.

III. IMPLEMENTING NEW SCHEDULER CLASS


EDF is a dynamic algorithm that does not require tasks to be
periodic or that they would need the same run time per CPU
bursts as does for ex. RMS algorithm. The scheduler keeps a
list of runnable tasks, sorted on deadline, and runs the first
task from the list, i.e. the one with closest deadline. Whenever
a new task becomes runnable, the system checks to see if its
deadline occurs before that of the currently running task. If so,
the new task preempts the current task.
EDF algorithm is superior to RMS in the way that it works for
any schedulable set of tasks and it can achieve 100% CPU
utilization.
Fig.1.a:- Output of EDF scheduler
A (partial) list of the hooks a scheduling class may provide, by
filling them in its own struct sched class structure, follows:
enqueue task(...): enqueues a task in the data structure used
to keep all runnable tasks (runqueue); usually called when the
task enters a runnable state;
dequeue task(...): removes a task from the runqueue; usually
called when the task stop being runnable;
Yield task (...): yields the processor for other tasks to have a
chance to be run;
Check preempt curr(...): checks if a task shall preempt the
currently running task;
Fig 1.b:- Output of EDF scheduler

ACKNOWLEDGMENT
The author wishes to acknowledge LRDE and, VTU
extension centre, UTL technologies for their extensive
support.

Fig 2 Time quantum without modification

Fig 3: Time quantum with modification


Fig1.a and Fig1.b shows the output of EDF scheduler in that
the process 3 has a deadline of 14 so it is executed first
followed by pid2, pid4 and pid1, Fig 2 shows the time
quantum of a RR scheduler without any modification and Fig
3 shows the time quantum of a RR scheduler with
modification

Conclusions
The real time capability is achieved by two new kernel
mechanisms, first the time slice of the Round Robin is
reduced and second a new scheduling algorithm (earliest
deadline first) is added in the Linux kernel so that real time
jobs will experience shorter blockings.

REFERENCES
[1] W.Richard Stevens, Advance programming in the UNIX
Environment, Pearson Education ,second edition.
[2] Yashavanth Kanetkar, UNIX Shell programming, BPB
publication.
[3] Philip A.Laplante, Real- Time System design and
analysis ,second edition.
[4] Maobing Dai, Toshihiro Matsui, Yutaka Ishikawa, A
Light Lock Management Mechanism for Optimizing
Real-Time and Non-Real-Time Performance in
Embedded Linux 2008 IEEE/IFIP International
Conference on Embedded and Ubiquitous Computing.
[5] Huaidong Shi, Ming Cai, Jinxiang Dong, Interrupt
Synchronization Lock for Real-time Operating Systems.
In Proceedings of 6th IEEE CIT, 2006.
[6] Jupyung Lee, Kyu-Ho Park, Delayed Locking Technique
for Improving Real-Time Performance of Embedded
Linux by Prediction of Timer Interrupt. In Proceedings
of the 11th IEEE RTAS,2005.
[7] A,Heursch, D.Grambow, A.Horstkotte, H. Rzehak,Steps
Towards a Fully Preemptable Linux Kernel. In 27th
IEEE Workshop on Real-Time Programming, Lagow,
Poland, May 2003.
[8] Yu-Chung Wang, Kwei-Jay Lin, Implementing a General
Real-Time Scheduling Framework in the RED-Linux
Real-Time Kernel. In Proceedings of the 11th IEEE
RTAS, 2005.
[9] M. Becketal. Linux Kernel Internals, 2nd
Edition.,Addison-Wesley, 1998.
[10] Yu-Chung Wang and Kwei-Jay Lin, Enhancing the RealTime Capability of the Linux Kernel, In proceeding of
the 11th IEEE RTAS,2005.
[11]Ching-Chih Han and Kwei-Jay Lin. Scheduling distanceconstrained real-time tasks. In Proc.IEEE Real-Time
Systems Symposium, pages 300-308, December 1992.
[12] R. Holte, A. Mok, L. Rosier, I. Tulchinsky, and D. Varvel.
The pinwheel: A real-time scheduling problem. In Proc.
of the 22nd Hawaii International Conference on System
Science, pages 693-702, January 1989.
[13] Chih-wen Hsueh and Kwei-Jay Lin. On-line schedulers
for pinwheel tasks using the time-driven approach. In
Proc. of the 10th Euromicro Workshop on Real-Time
Systems, Berlin, Germany, June 1998.

[14] Kwei-Jay Lin and Ansgar Herkert. Jitter control in timetriggered systems. In Proc. 29th Hawaii Conference on
System Sciences, Maui, Hawaii,January 1996.
[15] C. L. Liu and J. Layland. Scheduling algorithms for
multiprogramming in a hard real-time environment.
Journal of the ACM, 10(1):46{61, 1973.
[16] A. Silberschatz and P. B. Galvin. Operating System
Concepts, 5th Ed., Addison-Wesley, 1998.
[17] B. Srinivasan. A firm real-time system implementation
using commercial of-the shelf hardware and free

software. In Proc. IEEE Real-TimeTechnology and


Application Symposium, pages 112-119, June 1998.
[18] http://www.kernel.org.