Real Time System Review

Document Sample
Real Time System Review Powered By Docstoc
					                                  FORECAST QUESTIONS

A. Task Assignment and Scheduling

1) What is Task Assignment?

    - It means selecting the CPU which is available for use before it is scheduled.

2) Given a case study, please explain the followings

    a) How do we do assignment?

    - We only do task assignment is we have more than 1 CPU. We do assignment by
      selecting the available CPU before we schedule it.

    - We normally do task assignment using heuristic method (trial and error), however, we
      cannot guarantee that an allocation will be found that permits all tasks to be feasibly

    - Sometime, we do task assignment by considering the communication cost to ensure
       the maximum task deadlines are met within reasonable cost.

    - Task assignment and scheduling for multiprocessor can be done using Utilization-
       balancing algorithm, or next-fit algorithm, Bin-packing, Myopic Offline Scheduling,
       Focused addressing and bidding or Fault-tolerant Scheduling.

    b) Suitability of algorithm

    c) Explain logic of it, use example

    d) Conclude which one is the best

3) How to get hard RTS on different, compromising environment?

  - We need to provide redundancy (make a lot of back-up of resources)

4) How to ensure all task-deadlines be met?

  (A) using classical uniprocessor scheduling algorithms?

  - We will use 2 venerable algorithms (Rate-Monotonic or RM and earliest deadline first or

- We will have to deal with precedence and exclusion constraint

- We will consider situations where multiple versions of software are available for the
   same task

- We have to make the following assumptions

  A1. No task has any non-pre-emptible and the cost of pre-emption is negligible

  A2. Only processing requirements are significant; memory, I/O, and other resource
  requirements are negligible

  A3. All tasks are independent; there are no precedence constraints

a) Rate-Monotonic (RM) Scheduling Algorithm

  - We have to add 2 more assumptions

    A4. All tasks in the task set are periodic (serial) – have deadline

    A5. The relative deadline of a task is equal to its period (This will ensure that there
        can be at most one iteration of any task alive at any time)

  - In RM, the priority of task is inversely related to its period. Thus, tasks with smaller
    period will be given higher priority. Higher-priority tasks can pre-empt lower-priority

  - It has a static-priority. In RM (Rate-Monotonic) “The shorter the period, the higher the
    priority” [Liu + Layland ‘73] whereas in DM (Deadline-Monotonic) “The shorter the
    relative deadline, the higher the priority” [Leung + Whitehead ‘82)

  - For arbitrary relative deadlines, DM outperforms RM.

  - For Dynamic-priority: we can use EDF (Earliest Deadline First), LST (Least-Stack-
    Time-First), FIFO/LIFO, etc.

b) Earliest Deadline First (EDF) – also known as Deadline Monotonic

    - It is a dynamic-priority scheduling algorithm. It means tasks with earlier deadline will
    be executed first.

    - All tasks are not periodic (unlike in RM Algorithm)

    - If the total utilization of the total task is less than 1, the task set can be feasibly
    schedule on a single processor by the EDF Algorithm.

    - it only can work with uniprocessor scheduling

    - it allows pre-emption

    Steps to do this scheduling

    1. Sort task instances that require execution in time interval [0,L] in reverse
    topological order.

    2. Initialize the deadline of the kth instance of task ti to (k-1)Ti = di, if necessary

    3. Revise the deadlines in reverse topological order

    4. Select the task with earliest deadline to execute

c) Increase Reward Increase Service (IRIS) (?)

    - Not necessary to run to completion. It uses an iterative algorithm (compare
    algorithm first before execution).

    - It is to refine the process until it converges to a fix value. But this will increase
    overhead. To balance this is to have dynamic resources. This will involve
    combinations of a lot of parameters.

    - We have to assume that to obtain an acceptable output a task has to run to
    completion. If the task is not run to completion, we get zero reward from it.

    - Schedule the task so that the reward is maximized subject to the requirements that
    the mandatory portions of all the tasks are completed.

(B) using multiprocessor scheduling algorithms?

 a) Utilization Balancing Algorithm

    - Means all tasks must be distributed balance-ly in a fair manner, regardless of
    deadline or priority.

    - Objective is to balance processor utilization, and proceeds by allocating the tasks
    one by one and selecting the least utilized processor

    -considerers running multiple copies for fault-tolerance systems

            For each task Ti, do

                     Allocate one copy of Ti to each of the ri least utilized processors

                     Update the processor allocation to account for the allocation of Ti

            End do

 b) Next-fit Algorithm (choose the nearest location of CPU)

    - Use 1st processor to maximum (100% utilization) then run next task which is

    - Next task has to wait until the processor is fully utilized.

  - The objective is to partition the task set so that each partition is scheduled later for
  execution on a processor by RM scheduling.

  - The characteristic of this task is that each task has constant period and deadlines
  constraints and independent (no precedence constraint).

  - We have to do defragment or segmentize the tasks

c) Bin-packing Algorithm (?)

  - Total utilization should not exceed 1 (100% capacity).

          Utilization = Consumption / Capacity

  - Assuming we have a set of periodic independent pre-emptible tasks to be assigned
  to a multiprocessor consisting of identical processor, the task deadlines equal their
  period. Other than processor time, tasks require no other resources.

  - It is good in making allocations.

- The main problem with bin-packing is when we want to minimize the number of
   processors needed. It is to use the least amount of bins to hold the required number
   of elements.

d) Focus Addressing and Bidding Algorithm

   - Focus Addressing -- nodes broadcast how much free space they have.

  - Bidding Algorithm – it is like ‘I want to help you but nodes will select for you’.

e) Assignment with precedence Constraints

  - All nodes in algorithm help each other. It is used to reduce communication cost by
    assigning (if possible) to the same processor tasks that heavily communicated with
    one another.

  - Each task may be composed of one or more subtasks. The release time of each
    task and the worst-case execution time of each subtask are given. Each subtask is
    associated with a latest finishing time (LFT). If a subtask does not finish by its LFT,
    then we will miss the deadline. However, meeting the LFT does not always
    guarantee that deadlines will all be met.

  - The algorithm is a trial-and-error process. We start with the set of subtasks and
    assign them to the processors one by one, in the order of their LFT values. If two
    subtasks have the same LFT value, the tie is broken by giving priority to the subtask
    with the greatest number of successor subtasks.

f) Myopic offline scheduling algorithm (MOS) – for non-pre-emptive tasks.

   - All nodes in algorithm help each other.
   - MOS is used not only for processing needs but also of any requirements that tasks
   may have for additional resources.

   - MOS is an offline algorithm in that we are given in advance the entire set of tasks,
   their arrival times, execution times, and deadlines. We only develop a node if it is
   strongly feasible. If we encounter a node that is not strongly feasible, we backtrack.
   That is we mark that node as hopeless, and then go back to its parent, resuming the
   schedule-building from that point.

   - One difficulty with the MOS algorithm is that, if the number of tasks is very large, it
   can take a long time to check if a node is strongly feasible.

(C) using commonly used approaches?

 a) Weighted Round Robin (WRR) (real-time)

   - Must have more than 1 queue. Every queue has equal fairness but different weight
   (different priority)

   - Task waiting in the FIFO queue. A task with weight wt gets wt time slices every

   - Suitable for scheduling real-time traffic in high-speed switched networks (a switch
   downstream can begin to transmit an earlier portion of the message upon receipt of
   the portion, without having to wait for the arrival of the later portion.)

   - No need for sorted priority queue -> speed up of scheduling

   - It is one of the simplest scheduling algorithms for processes in an operating system.
   A round-robin scheduler generally employs time-sharing, giving each job a time slot
   or its allowance of CPU time, and interrupting the job if it if not completed by then.
   The job is resumed next time a time is assigned to that process.

   Example: Job1 has a total time of 250ms to complete but the time slot is only 100ms,

   1. First allocation = 100ms

   2. Second allocation = 100ms

   3. Third allocation = 100ms but Job1 self-terminates after 50ms

   4. Total CPU time of Job1 = 250ms.

 b) Priority-driven Approach (non-real-time)

   - never lease any resource idle intentionally

   - greedy scheduling, list scheduling, work-conserving scheduling
       - most scheduling algorithms used in non-real-time systems are priority-driven

       - pre-emptive vs. non pre-emptive

    c) Clock-drive (time-driven) Approach (off-line)

       - tasks and their timing constraints are known a priority except for aperiodic tasks

       - relies on hardware timers

       - a static schedule

               * constructed off-line

               * cyclic schedule: periodic static schedule

               * clock-driven schedule: cyclic schedule for hard real-time tasks

       - foreground/background approach

               * foreground: interrupt-driven schedule

               * background: cyclic executive (“Big Loop”)

5) What is Fixed Priority Scheduling? (Similar to deadline-monotonic algorithm or DM)

In fixed priority scheduling we assume that

       - all tasks are periodic

       - jobs are ready as soon as they are released

       - pre-emption is allowed

       - tasks are independent

       - no aperiodic or sporadic tasks

       The higher the schedulable utilization, the better the algorithm is. Schedulable
       utilization is always less or equal to 1.0!

       With fixed priority pre-emptive scheduling, the scheduler ensures that at any given
       time, the processor executes the highest priority task of all those tasks that are
       currently ready to execute.

Pre-emptive scheduling consists of

       -   Rate monotonic scheduling

       -   Round-robin scheduling

       -   Fixed-priority scheduling

       -   Critical section pre-emptive scheduling

       -   Static time scheduling

B. Real-time Database

A transaction is a sequence of read and write operations. A transaction is said to be a query
if it consists only read operations. An update is when it consists only write operations.

In conventional database, transactions must satisfy the following properties:

Atomicity – either done completely or not at all.

Consistency – the transactions transforms the database from one consistent state to

Isolation – the actions of a transaction are not visible to any other transactions until and
unless that transaction has committed.

Durability – the actions of a transaction on a database (upon commitment) are permanent

Serial – if only transaction is active in the system at any one time.

1) How do you virtualize and classify the RTS? How you classify your priorities?

Generally, a desired programming language must have 2 main characteristics

a) Amount of control to impose on the users

b) Amount of protection to impose on the users

We must have balance between how much we want to impose to the users and how much
protection we impose on the user.

2) How to enhance this to increase utilization or to strike the ideal balance between
protection and utilization?

When protection is more, then there will be less utilization and vice versa. But we need to
balance out the use of protection and utilization.

To increase protection, need to have proper back-ups and recovery. However, increase the
back-up will increase overhead. This will reduce the capacity for utilization. Thus, the system
needs to be able to consolidate the control of storage system, storage network, replication
services and capacity management.

3) Compare a general purpose database with a real-time database.

There are 2 aspects that differentiate RTS and general purpose database

(1) queries to the database have deadlines associated with them.

(2) data returned in response to a query must have both absolute consistency (accurate) and
relative consistency (for multiple data, data must have been collected reasonably close to
one another.)

(3) In real-time system, the main memory need to be very large but in general purpose it is
not necessary because data can be stored in disks or external database.

(4) In RTS can use Multiple Version Approach for locking system whereas it is not applicable
for general purpose.

Since RTS database has deadlines associated with them, it is important that transaction
response times be predictable. However it is not easy to predict if

(1) it has ACID properties because it may have significant overhead.

Transaction may be aborted before they are completed to ensure serialization consistency or
to avoid deadlock.

(2) if database need to rely on disk system or external storage and not in main memory.
This may cause page faults which impose different overheads.

(3) if the transaction is data-dependent. It has to wait for other transactions to complete
before it can do reads/writes.

(4) if the transaction need to wait to access a datum that is currently being blocked by
another transaction.

C. Programming Languages

1) Compare your selected programming language with ADA programming language based
on 4 decompositions as below:

a) blocks -- e.g. for loops, if-else, while loops, etc.

Blocks in JAVA are ‘for loop’, ‘for-each loop’, ‘while loop’, ‘do-while loop’, ‘if-then-else
statement’ and ‘switch/case statement’.

Blocks in ADA consists of ‘while loop’, ‘endless loop’, ‘until loop’, ‘exit loop’, ‘for loop’ and
‘array loop’. ADA also has ‘if-else’ and ‘case’ statements. ADA can do ‘guess-works’ when it
is safe to do so.

b) procedures -- kind of work without specific job to return values

In ADA, a procedure call is a statement and does not return any value. The parameters can
be declared as ‘in’ or ‘out’.

Procedure and functions can’t protect one procedure to another procedure. They are called
as subprograms.

c) functions -- get some tasks or specific job and return a value based on input arguments

In ADA, a function returns a value and must therefore be a part of an expression. A function
can have ‘in’ and ‘access’ parameters but may not have ‘out’ parameters. Thus, ADA
functions behave more like mathematical functions than in other languages. The
specification of the function is necessary to show to the clients all the information needed to
invoke it.

d) packages -- a concept of classes.

   Packages are like black boxes. We don’t know what are inside the boxes. They normally
   consists of declaration of a type, package body and package interface. Packages are
   used a lot in object oriented programming. Even though ADA is created for real-time
   system programming and it is complementary of object oriented programming language,
   C# programming language is better in objected oriented programming.

   Advantage of ADA Packages:

   -    Can prevent naming collisions because package contents are places in a separate

   -    Can have information hiding because the implementation details of the packages can
        be hidden from the programmers.

   -    Packages can be separately compiled.

   -    It is object oriented which requires defining a type and tis primitive subprograms
        within a package.

Ada programming is good in large programming scale because it has advantages in terms of

   -   It is an extremely strong, static and safe type system, which allows the programmer
       to construct powerful abstraction that reflect the real world, and allow the compiler to
       detect many logic errors before they become bugs.

   -   Modularity -- where the compiler directly manages the construction of very large
       software systems from sources.

   -   Information hiding -- The language separates interfaces from implementation, and
       provides fine-grained control over visibility.

   -   Readability -- it helps programmer review and verify code. The program text is close
       to English prose.

   -   Portability -- the language definition allows compilers to differ only in a few controlled
       ways, and otherwise defines the semantics of program very precisely; as a result,
       Ada source text is very portable across compilers and across target hardware
       platforms. Most often, the program can be recompiled without any changes.

   -   Standardization – Ada compilers supports all other languages that use the same

2) What are the characteristics of good programming language for RTS?

   1) Can it make the deadline to be met?

       The RTS using the language must me able to do analysis for schedulability, allow
       prioritization and control the run-time application. It needs to be able to analyse how
       much resources and which processors to use to ensure all tasks meet the deadline. It
       also able to avoid features that can affect the tight execution-time bounds i.e.
       avoiding using recursion, looping, etc.

   2) Can it interact with I/O devices which have different cycle times

       It is an advantage if the language used does not require the programmers to write
       their own coding if they want the system to be able to communicate with I/O devices
       such as sensors and actuators. By having pre-programmed coding or functions that
       can be plugged in by the programmers, it will help to reduce a lot of programming
       errors. It needs to have high level language instead of machine codes.

   3) Is the language portable?

       The language is portable if it allows the program to be compiled by several types of
       compilers. The programmers will have to properly use the formalized algorithms that
       can be translated or understood by different types of compilers to reduce ambiguity.

       JAVA is good in portability because it has virtual machine.

   4) Is the language giving some flexibility to programmers?

       The flexibility here means by using the language, the programmers can run a
       program while controlling the scheduling of all resources. The resources to be used
       first must be selected based on its availability limitations. ADA language allows
       programmers to manually run the schedule especially when hard deadlines are to be

   5) Does it have the ability to schedule processors and resources?

      It needs to use the language at the very low level which might not be able to be done
      by other processors.

   6) Is it able to precisely specify specific delays?

   7) Can it improve comprehensibility and modularity?

      Modularity means if we have big program, we can make it smaller and each smaller
      ones is unique. It can be shared, isolated from each other and can have information
      hiding. However, each module is not necessarily of same size. We abstract it at
      different levels (data abstraction).

3) What are the characteristics of good RTS (Real-time System)?

   The designed real-time system is good if it

   a) can handle any types of application demand such as

          a. Large scale, specific, rich in heterogeneity, fault tolerance and time sensitive.

          b. Multitasking

          c. Exceptional handling

   b) is highly reliable. This means there are very few tolerable errors or zero errors. Errors
      should be minimized as much as possible because it may result in major disaster
      even with small mistake in the program. In addition, when writing the program, the
      written programs needs to be readable – the program must be easy for debugging
      and easy to be understood by the person who will do the maintenance of the system.
      It san be dome with consistent data types. ADA language allows the programmers to
      minimize error by setting proper data types, etc.

4) Try to prepare several examples that have exceptional handling situations?

   a) In patient’s health monitoring,

       If the doctors want to monitor the body temperature of a patient where the normal
       body temperature of a healthy person is between 36oC – 37oC, and ‘error reading’ if
       body temperature is below 26oC and above 40oC, the algorithm could be as follows:-

       if (bodyTemp <36) {

              alert(“Body temperature is very low!”); }

       elseif (bodyTemp >37) {

              alert(“Body temperature is too high!”); }

       elseif ((bodyTemp <26) or (bodyTemp > 40)) {

              alert(“Error reading!”); }


   b) In toll gate system using prepaid card i.e. Touch N Go,

       If the Touch N Go card has enough balance, then the toll gate will open after the
       amount has been deducted. The gate will not open and there will be ‘error reading’ if
       card balance show negative amount and alert message if the card balance amount is
       lesser than the toll rate. The algorithm could be as follows:-

       if (cardBalance <0) {

              alert(“Error reading!”); }

       elseif (cardBalance < tollRate) {

              alert(“Sorry, the amount is not enough, please top-up the amount!”); }


3) Given a scenario, you do a benchmark?


Shared By: