You are on page 1of 60

Introduction to Real-Time

Systems

Manish Sarawat
Asst. Prof(Dept. of MCA)
GITS Udaipur
What is a Real-Time System?
• Real-time systems have been defined as: "those systems
in which the correctness of the system depends not only
on the logical result of the computation, but also on the
time at which the results are produced” .
• Most, not all, real time systems are "embedded".
Embedded systems are electronically controlled system:
where One system consist of another system.
• Aircraft control system, ticket reservation system, over-
temperature monitor in nuclear power station, mobile
phone, oven temperature controller, ECG monitor are
some best examples of real time systems.
Real-Time Characteristics
• The Real-time systems are sometimes called reactive
since they react to changes in their environment

• Real-time systems often are consist of a controlling


system, controlled system and environment.
 Controlling system: acquires information about
environment using sensors and controls the environment
with actuators.
Typical Real-Time System

Controlled System

sensor
sensor
Controlling sensor
System sensor
Acquire information from
actuator Environment
Environment
using
Sensor & control it through actuator
actuator
actuator
actuator
Some Definitions
• Timing constraint: This is a constraint that is
implemented for timing behavior of a job: hard or soft.
• Release Time: This is Period of time when the job
becomes available for execution. If all jobs are released
when the system begins execution, then there is said to
be no release time.
• Deadline: It is Period of time a job's execution is
required to be completed. If deadline is infinity, then job
has no deadline.
• Response time: It is the time a taken by functional unit
to give first response to a given input.
RTS Operating System

• A real-time operating system is a multitasking


operating system that aims at executing real-time
applications. Real-time operating systems often use
specialized scheduling algorithms so that they can
achieve a deterministic nature of behavior. They have
an event-driven or time-sharing or both of types.
• An event-driven system switches between tasks based
on their priorities or external events while time-
sharing operating systems switch tasks based on clock
interrupts.
Multi-user Vs. Single-user
• Multi-user: A multi-user operating system allows
multiple users to access a computer system
concurrently. Time-sharing system can be classified
as multi-user systems as they enable a multiple user
access to a computer through the sharing of time.
• Unix is multi-user operating system, since it is
possible for Two users to login at a time and this
capability of the OS makes it a multi-user operating
system.
• Single-user operating systems: allow single user at
a time to work on the System. Example MS DOS.
Single Tasking Vs Multi Tasking
• Windows operating system does not make it
a multi-user system. Rather, only the
Network administrator is the real user.
• When a single program is allowed to run at
a time, the system is grouped under a
single-tasking system, while in case the
operating system allows the execution of
multiple tasks at one time, it is classified as
a multi-tasking operating system.
Hard versus Soft Dealines
• Real-time deadlines (constraints) are of two types:
hard and soft deadlines.
• Hard deadlines are constraints that absolutely must
be met A missed hard deadline results in a system
failure. A system with hard deadlines is called a hard
real-time system. In hard real-time systems, late data
is bad data. For example, a time constraint for a
flight monitoring system can be that once landing
permission is requested, a response must be provided
within 30 seconds
Hard Vs Soft…..
• Soft Real-time Systems are characterized by deadlines(soft
deadlines), which can be missed by small time derivations or
permissible variations constraints.
• Examples include on-line databases and flight reservation systems.
Therefore, in soft real-time Systems: late data may still be good
data, depending on some measure of the severity of the lateness.
• Hard Real Time Systems :Often specified on
 Deterministic constraints
 Probabilistic constraints
• Soft Real Time Systems: Often specified on probabilistic terms
Hard Vs Soft…..
Tasks and Jobs: Definitions
• Task (Ti): Set of related jobs jointly provide
function.
• Job (Jij): Unit of work, scheduled and executed
by system. characterized by the following
parameters:
Temporal parameters: timing constraints and
behavior.
Functional parameters: properties of the job.
Resource parameters: resource requirements.
Interconnection parameters: how it depends on other
jobs and how other jobs depend on it.
Resources
• Resources can be divided into passive and
active:
Active resources == Processors (Pi): they execute
jobs.
Every job must have one or more processors
Passive resource == Resource (Ri):

• Two ways of designing real-time systems: event-triggered


and time-triggered
Event Triggered Vs Time Triggered
• In an event-triggered real-time system, the
computer reacts to events by immediately and
activate a task that should service the request
within a given time. The execution order of tasks
is decided by a system scheduling policy for
example, the resource requirements maybe
Normal or Urgent or Critical to provide the
service.
• The time-triggered systems observe the
environment and perform actions at pre-specified
points of time
Periodic Vs Aperiodic
• In Real Time Systems Task May be:
• Periodic: Tasks are activated at a fixed frequency, thus
all the points in time when such tasks are activated are
known beforehand. For example, a task with a period of
4 time units will be activated at times 0, 4, 8, etc.
• Aperiodic: tasks can be activated at any point in time,
to achieve timeliness in a real-time system, aperiodic
tasks must be specified with constraints on their
activation pattern. When such a constraint is present the
tasks are called sporadic.
• A traditional constraint of this type is a minimum inter-
arrival time between two successive task activations.
Statically Vs Dynamic Scheduled
• Further RTS may be Static or Dynamic Scheduled
Systems
• In statically scheduled systems all the future
activations of tasks are known beforehand,
whereas in dynamically scheduled systems, they
are not.
• Statically scheduled systems are often scheduled
before the system goes into operation, either by
assigning static priorities to a set of periodic tasks
or by explicitly constructing a schedule (for
example cyclic scheduling ).
Statically Vs Dynamic Scheduled
• A Time-triggered system is by definition statically
scheduled systems, these systems offer more
determinism and are therefore easier to analyze and
test. Because there is known activation pattern of
periodic tasks, repeats after a certain period of time.
This period is called a hyper-period.
• Dynamically Scheduled systems perform scheduling
decisions during operation and may change the order
of task execution depending on the system state,
locked resources, and new task activations.
• A Event-triggered system can be scheduled statically
or dynamically.
Schedules and Scheduling
•The scheduling order of Jobs in real time systems based
on a set of scheduling algorithms and access control
protocols.
•Scheduler: is a Module that implement the scheduling
algorithms
•Schedule: is the job execution order assigned to all jobs
ready to execute by scheduler.
•Valid schedule:
every processor assigned to at most one job at a time
every job assigned to at most one processor at a time
no job scheduled before its release time
Total amount of processor time assigned to every job is equal to its
maximum or actual execution time
Testing of RTS
• Conventional testing methods concentrate on Functional
(Logical Correctness) Testing but in RTS system
reliability depend upon functional as well as Timeliness
(Temporal Correctness) thus do not help to gain
confidence in temporal correctness.
• The Temporal Testing is complicated since large task sets
are required to compute and the complexity of testing is
much increased when many of tasks use shared resources
and are released in response to sporadic requests.
• Genetic Algorithms are suggested for Temporal Testing
because the test cases in this are based on Optimization
problem apply the computation to find minimum and
maximum execution time
Genetic Algorithms
• Genetic algorithms are an approach to optimization and
learning based on principles of biological evolution,
these are simple to construct, and its implementation
does not require a large amount of storage and it works
on Population not individual, it making them a
sufficient choice for an optimization problems.
• Genetic algorithms operate by iteratively refining a set
of solutions to an optimization problem through random
changes and by combining features from existing
solutions. In the context of genetic algorithms, the
solutions are called individuals and the set of solutions
is called the population.
Genetic Algorithms
• The Fitness function in genetic algorithms is to evaluate
the optimality or fitness of a particular individual.
• The individuals with the highest level of fitness in a
population and are more likely to be selected as input to
cross-over functions and these functions are applied on
the selected individuals to create new in individuals
with higher fitness in the next generation.
• We will implement the Rastragin’s Function for
optimization using GA in MATLAB.
• MATLAB (Matrix Laboratory), a product of
Mathworks, it is a scientific software package
developed to provide an integrated environment for
MATLAB…..
numeric computation and graphics visualization in high-
level programming language
• Matlab provides an optimization toolbox that includes a
GA-based solver. The toolbox can be start by typing
optimtool in the Matlab's command line and pressing
enter. As soon as the optimization window appears, we
can select the solver ga – Genetic Algorithm and now
matlab are ready to go.
• The user should program (by writing ‘m’ files) any
extended functionality required
• For Example the equation:
Ras(x) =20+x12+x22-10(cos2πx1+cos2πx2) an be coded as
Output of Optimtool
Rastragin’s Function coding

function y = rast(x)
% the default value of n = 2.
n = 2;
s = 0;
for j = 1:n
s = s+(x(j)^2-10*cos(2*pi*x(j)));
end
y = 10*n+s;
Rastragin’s Function Implementation

 Figure 2: Rastrigin’s function optimization with default setting


The best fitness function value (the smallest one since we
minimize (Final Point – it is very close to (0, 0)).
Now check the two plots. it is obvious that the population
converges, since the average distance between individuals
(solutions) in term of the fitness value is reduced, as the
generations pass.
Rastragin’s Function Implementation…
• It is seen from figure-2 the fitness value as it gradually gets
smaller. It is an indication that optimization takes place since
not only the fitness value of the best individual was reduced,
even the mean (average) fitness of the population was also
reduced.
• The performance of a GA is affected by the diversity of the
initial population. If the average distance between individuals
is large, it is indication of high diversity; if the average
distance is small its represent low diversity in the population.
• If the diversity is too high or too low, the genetic algorithm
might not perform well. We will explain this by the following:
Rastragin’s Function Implementation

Figure 3: Rastrigin’s function optimization with default setting, except Stopping


Criteria-Stall Generations set 100 and initial range set [1; 1.1]
By this we actually make it harder for the GA to search equally well in
all the solutions space. The GA returns the best fitness function value of
approximately:2
Rastragin’s Function Implementation

Figure 4: Rastrigin’s function optimization with default setting,


except Stopping Criteria-Stall Generations set 100 and initial
range set [1; 100] set Initial range to [1; 100] and run the
algorithm again.
The GA returns the best fitness value of approximately
3.3 This time, the genetic algorithm makes progress, but
because the average distance between individuals is so
large, the best individuals are far from the optimal
solution.
Rastragin’s Function Implementation

Fig 5: Rastrigin’s function optimization with default setting, except Stopping


Criteria-Stall Generations set 100 & initial range set [1; 2]
This returns the best fitness value of approximately 0.012 and displays
the plots that follow as in figure 5.
The diversity in this case is better suited to the problem, so the genetic
algorithm returns a much better result than in the previous two cases.
Affects of Population size
• In all the examples above, we had the Population Size
set to 20 (the default). This value determines the size of
the population at each generation. Increasing the
population size enables the genetic algorithm to search
more points and thereby obtain a better result.
However, the larger the population size, the longer
computation time and Memory.
• It is important to note that Population Size to be at least
the value of Number of variables, so that the individuals
in each population span the space being searched.
• The fitness scaling is the factor that control the
diversity between the population.
Affects of fitness values(scaled values)

Fig6:Raw fitness value lower


If the fitness values vary too widely Figure: 6, the individuals
with the lowest values reproduce too rapidly, taking over the
population pool too quickly and preventing the GA from
searching other areas of the solution space.
On the other hand, if the values vary only a little, all individuals
have approximately the same chance of reproduction and the
search will progress very slowly as in Fig7
fitness(scaled values)& Selection function…

Fig:7 Raw fitness value Higher


It is clear from the Figure: 6 Raw fitness values (lower is better) vary
too widely on the other hand Scaled values (figure: 7) do not alter the
selection advantage of the good individuals. They just reduce the
diversity that we have in the previous. This prevents the GA from
converging too early.
•Selection Function: that is, how individuals are selected to become
parents The Most well-known uniform selection method is presented
here.
•In this method each parent corresponds to selection of line of length
proportional to its scaled values. For Example
Uniform method of Selection…

Figure 8: Stochastic uniform selection method. For 6 parents we step the selection
line with steps equal to 15/6.
•A population of 4 individuals with scaled values 7, 4, 3 and 1. The
individual with the scaled value of 7 is the best and should contribute its
genes more than the rest. We create a line of length 1+3+4+7=15. Now, let's
say that we need to select 6 individuals for parents. We step over this line in
steps of 15/6 and select the individual for crossover.
•The Reproduction control how the GA creates the next generation.
•It specifies the amount of elitism and the fraction of the population of the
next generation that is generated through mating.
Elite count and Cross over fraction
• Elite Count: the number of individuals with the best
fitness values in the current generation that are
guaranteed to survive to the next generation. These
individuals are called elite children.
• The default value of Elite count is 1 or 2 (depending on
the population size).
• Crossover Fraction: is the fraction of individuals in the
next generation, other than elite children, that are created
by crossover (remaining is generated by mutation).
• A crossover fraction of ‘1’ indicates means that all
children other than elite individuals are crossover
children. A crossover fraction of ‘0’ indicates that all
children are mutation children
Mutation

• Mutation- It is the Random change one or


more digits in the string representing an
individual.
Objectives of Study

• The Main objectives of this study is to


proposed Genetic Algorithm based new
techniques for :
• Test Data Generation and
• Prioritization of test cases and modules
• Release Time and Cost estimation of RTS
• Reliability assessment
Test Data Generation
• The purpose of test data generation is to
generate test data automatically for testing
of Real Time System or software on the
basis of predefined constraints
How it is performed in GAs
• In Genetic Algorithms the set of test data
can be considered as population, each
individual (chromosome) is element of test
data set.
• The system can be applied to generate
feasible test data. The first set of test data is
Test Data Generation…..
generated randomly and then basic steps of
genetic algorithms like crossover and
mutation are applied to increase the fitness
of individuals, this process is remain
continue till the individuals reached on
maximum fitness or some specified
condition is matched.
• In this study test data generation using
genetic algorithm is proposed and explained
for test data generation for a program to
calculating xy.
Model Description
• Steps for Test Data Generation Using GAs
• Input: Generate inputs and convert it into
binary format so that crossover and mutation
operators can be performed.
• Evaluation: evaluate the fitness of each point.
The evaluation outcome is association of a
fitness value to each individual. The population
evaluation is performed for the aim to select
best solutions, carried out for each generation.
Model Description…..
• Selection: Selects parents for crossover and
mutation based on priority values.
• Crossover and Mutation: New inputs are
created from output of selection process. The
crossover and mutation points are selected
randomly by the system. The rules for crossover
and mutation are as:
• If (Priority< = 0.3), perform mutation.
• Else if (0.3> Priority < = 0.7), perform
crossover.
• Else (Priority >0.7), stop crossover and
mutation.
Model Description…..
• After crossover and mutation, the system
gets data for next generation.
• In our illustration, a small program of
calculating xy is implemented; the
predefined constraints for this program are
as:
• (a) The value of xy should be greater than
7000(lets assumed).
• (b) values of x and y should always be
positive.
Model Description….

• The fitness function used to evaluate each


candidate’s fitness, and for our case, it is
described as below:
• Per = xy /10,000*100
• Priority =Per/100
• Where x and y are input values
• Now the genetic algorithm operators are
applied as:
• First Generation: Data as Shown in table:
Model Description...

S.No Test Data Operation

(i) x=2, y=5 Mutation

(ii) x=5,y=3 Mutation

(iii) x=2, y=12 Crossover

(iv) x=8, y=1 Mutation


Test Data Generation using Genetic Algorithm and
Hamming Distance

• This is another proposed approach of test


data generation using genetic algorithm and
hamming distance. The individual whose
fitness values satisfies the criteria of the
fitness function are selected as output test
cases and whose individuals which does
not satisfy the target value, genetic
algorithm is applied over the individuals to
increase fitness value or make them fitter.
Test Data Generation using Genetic Algorithm and
Hamming Distance…..

• On the basis of fitness value, reproduction,


crossover and mutation operators are
applied over the individuals.
• In this approach the parameters of genetic
algorithms must be specified before the
starting the procedure. Next the Table
describes the parameters of genetic
algorithms for test data generation.
• The proposed model implemented for test
data generation for Power Generation
program
Test Data Generation using Genetic Algorithm and
Hamming Distance……

S.No Parameter Type Value

1 Population Size 15

2 Selection Method Roulette Wheel

3 Crossover Method Single Point

4 Crossover Probability 0.8


Fred Kuhns () CS523S: Operating Systems
Fred Kuhns () CS523S: Operating Systems
Fred Kuhns () CS523S: Operating Systems
Minimization of test cases
• There are various techniques for reducing
cost and time, like test suites minimization.
This lower the cost and time by reducing
test suites, but Harrold et al. observed that
fault detection of test suites are severely
compromised by using test suites
minimization. This leads us to using of test
case prioritization, where no test suites
reduction but order of execution is changed
by efficient manner to meet performance
goal.
What is Prioritization

• The purpose of prioritization is to fulfill the


objective of service oriented applications i.e
minimum cost and time. The prioritization
may implemented at two levels:
• Test Case/ Suite Prioritization
• Modules Prioritization
• Now a new test case prioritization approach
is proposed and explained for regression
testing on triangle classification problem
Test Case Prioritization: Model Description

Generation of Population [Chromosome]


• In our experiment the running sequence of test-cases is
chromosome and we are optimizing this sequence of test
cases execution to assure the quality of product after
making modifications or changes. For Instance there are
15 test-cases [T1, T2, T3….…..…..T15] and two different test
sequence of test cases identified to detect an error.
• Test-Suite (TS1) = T1 T2 T3 T4 T6 T8 T10 T12 T13 T11 T14
.T15 T5 T7 T9

•  Test-Suite (TS2) = T10 T4 T3 T5 T6 T8 T9 T11 T13 T12


T15 .T14 T2 T7 T1
• Fig : Two Test Suite (TS1 & TS2)
Test Case Prioritization: Model Description....
Crossover
• The selected individual are combined to generate new
chromosomes i.e single point crossover:
• C1: T1 T2 T3 T4 T6 T8 T10 T12 T13 T11 T15 T14 T5 T7 T9
• C2: T10 T4 T3 T5 T6 T8 T9 T11 T12 T7 T1 T2 T13
• For C1 write first part of TS1 and then second part of TS2
with constraint that a test case has not been added in to C1
and same process is followed to creation of C2.
• For doing mutation two genes are selected randomly
and swapped with each other, for example in C1 genes T10
and T5 are selected and swapped as:
• C1: T1 T2 T3 T4 T6 T8 T5 T12 T13 T11 T15 T14 T10 T7 T9.
Test Case Prioritization: Model Description....

• Let’s say a program(P) has test suite(TS),and now


we are doing modifications in the
program(P),suppose modified program is(P’),so
that now to test modified program(P’),we will
generate a prioritize sequence of test cases or test
suites from the designed test-cases and test suites
for the program(P’).
• The prioritization criterion is based on line of code
modified by test case. In this proposed following
Genetic Parameter are used:
Test Case Prioritization: Model Description....

• Fitness Function: following objective function


(fitness function) will be used to set prioritization
of test case or test suite:
• Fitness value (F) =∑ {order*(number of modified
lines covered by test cases or suite)}
• For example: A test case sequence is
T1_T2_T3_T4 and this covers 3,2,5,1 modified
lines of code respectively, then the fitness value of
sequence of will be:
• Test Suite(TS)(fitness)=(3*4)+(2*3)+(5*2)+(1*1)
• =29.
Test Case Prioritization: Model Description....

Fred Kuhns () CS523S: Operating Systems


Fred Kuhns () CS523S: Operating Systems
Fred Kuhns () CS523S: Operating Systems
Fred Kuhns () CS523S: Operating Systems
Test Case Prioritization……

Fred Kuhns () CS523S: Operating Systems

You might also like