Skip to content Skip to navigation

Connexions

You are here: Home » Content » Task Scheduling

Navigation

Content Actions

  • Download module PDF
  • Add to ...
    Add the module to:
    • My Favorites
    • A lens
    • An external social bookmarking service
    • My Favorites (What is 'My Favorites'?)
      'My Favorites' is a special kind of lens which you can use to bookmark modules and collections directly in Connexions. 'My Favorites' can only be seen by you, and collections saved in 'My Favorites' can remember the last module you were on. You need a Connexions account to use 'My Favorites'.
    • A lens (What is a lens?)

      Definition of a lens

      Lenses

      A lens is a custom view of Connexions content. You can think of it as a fancy kind of list that will let you see Connexions through the eyes of organizations and people you trust.

      What is in a lens?

      Lens makers point to Connexions materials (modules and collections), creating a guide that includes their own comments and descriptive tags about the content.

      Who can create a lens?

      Any individual Connexions member, a community, or a respected organization.

      What are tags? tag icon

      Tags are descriptors added by lens makers to help label content, attaching a vocabulary that is meaningful in the context of the lens.

    • External bookmarks
  • E-mail the author
  • Rate this module (How does the rating system work?)

    Rating system

    Ratings

    Ratings allow you to judge the quality of modules. If other users have ranked the module then its average rating is displayed below. Ratings are calculated on a scale from one star (Poor) to five stars (Excellent).

    How to rate a module

    Hover over the star that corresponds to the rating you wish to assign. Click on the star to add your rating. Your rating should be based on the quality of the content. You must have an account and be logged in to rate content.

    (0 ratings)

Recently Viewed

This feature requires Javascript to be enabled.

Task Scheduling

Module by: CJ Ganier

Summary: Task scheduling allows multiple processes to run on a system without competing for resources.

Multitasking in embedded systems

There are situations in programming when the programmer has the luxury of the entire processor to himself. Embedded programming has many such situations; however, there are also many situations when the embedded programmer must be able to run many processes on the same processor at the same time. This situation is the norm on personal computers because users wish to simultaneously run many different applications.

Operating systems are an advanced way to allow multiple programs, also called applications or processes, to run on a single machine at the same time. The operating system moderates between processes to ensure that each program can access the system resources like the internet, display, keyboard, memory, and hard drive without that program having to know about the dozens of other programs running at the same time. This sharing includes being able to share the processor without the application programmer worry about this. Ideally, no program can crash the computer because the operating system will notice the problem and quit the program (kill the process). The operating system accomplishes these difficult tasks with the help of the processor itself. The processor is able to tell the difference between the operating system and other programs, and the processor will make sure to hand control of itself to the operating system from time to time. The operating system will then make sure that all of the other programs are running smoothly.

Embedded systems have operating systems, too. Embedded operating systems are much smaller affairs than PC operating systems because the embedded operating systems have fewer resources to work with. Interestingly, some of the most stable operating systems are for embedded systems because the controllers in nuclear power plants, military systems, life support equipment, etc. must never crash. A good embedded operating system should take up only a small portion of code memory, use only a small amount of time to handle important requests or switch between processes, and be predictable.

Task Scheduling

Embedded programmers are often most concerned with meeting specific time deadlines for tasks to occur. The difficulty in using an operating system with real time programming is that the operating system must be able to guarantee that the worst case response time for the operating system to give control to a process that needs attention is short enough that the process has time to handle events. One aid to ensuring sufficient response time is to prioritize processes so that more important processes always receive processor attention if they need it.

The process scheduler is the part of the operating system that responds to the requests by programs and interrupts for processor attention and gives control of the processor to those processes. A scheduler can also stand alone to act as a centerpiece to a program that requires moderation between many different tasks. In this capacity, each task the program must accomplish is written so that it can be called by the scheduler as necessary. Most embedded programs can be described as having a specific, discrete response to a stimulus or time interval. These programs can be ranked in priority, allowing the scheduler to hand control of the processor to each process in turn.

The scheduler itself is a loop that calls one of the other processes each time it executes. The process the scheduler calls is the highest priority process that needs the processor. Whether a process needs the attention is stored in an array of flags to indicate this. The simplest way to handle the problem is to give each program a turn. When a process gets its turn, the process can decide when to return control. This method does not support any notion of importance among processes, so it isn't as useful as it could be. The more complicated the scheduler or operating system, the more elaborate the kinds of scheduling information that can be maintained.

Some examples include:

  • A process might ask the scheduler to wait until there are no other processes of higher priority that need attention.
  • A process might ask the scheduler to only return to it when a certain minimum delay has passed. This is useful for fixed time periodic functions.
  • A process might ask for as much processor control as possible.
  • A process might ask for attention the next time an interrupt occurs.
  • A process might ask for attention when a variable changes.
  • A process might ask for attention whenever another process asks for it to have attention; this can allow processes to pass information among themselves.

Example 1

A microprocessor controlling the brake system on a car is running a simple operating system. Currently there are three processes running with priorities 8, 4, and 1 (with higher numbered priorities being more important). The highest priority process is the anti-lock braking process that pulses the pressure on the brake. The second highest priority process monitors the pressure on the brake pedal from the driver. Finally the brake pad maintenance process checks for degradation of the brake pads and has the lowest priority. At first, brake pedal is not depressed, and the brake pedal monitoring process is executing. Meanwhile, the anti-lock brake process waits for the brakes to be pressed before meriting attention, and the maintenance program is waiting for the pedal monitoring program to yield to it.

After some time, the brake process surrenders control to the scheduler even though the brake has not been pressed. The scheduler then checks the list of processes waiting to be scheduled and sees that Y is still the highest priority process needing attention. The brake pedal monitoring process then executes again. When the brake is pressed, the brake pedal notifies the anti-lock process that the brake is active. The scheduler updates the list of processes waiting to reflect the fact that the anti-lock brake process is waiting. When the pedal monitoring process returns control to the scheduler, the scheduler checks the data structure and sees that the anti-lock process is the highest priority process waiting. The scheduler then calls the anti-lock brake function. The anti-lock brake process controls the pressure on the brakes as needed, surrendering control to check the status of the pedal. Because it is finished, it notifies the scheduler by calling a function that it will wait for the brake pedal program to call it again. This function updates the scheduler's list of processes so that the anti-lock process is no longer shown as waiting. The anti-lock process then returns control to the scheduler. The scheduler sees that the pedal monitoring process is again at the top of the list, and allows that program to execute. The pedal process updates the status of the brake and notifies the scheduler that some more anti-lock compression is needed. This cycle of anti-lock pressure and pedal status continues for some time. Eventually the car is put into park, and the pedal and anti-lock processes are put into the waiting status.

The scheduler removes the anti-lock and pedal programs from the list of waiting processes. The scheduler then sees that only the maintenance program remains in the queue and it can execute the brake check. The maintenance process determines that it needs to warn the driver. The notifies the scheduler that a new process, a warning process, needs to be created with a priority of 2. The scheduler adds the warning process to its list of processes, ahead of the maintenance process. The maintenance process then notifies the scheduler that the warning process needs to execute and cedes control. The scheduler checks the queue of processes and sees that warning process is the highest priority process waiting for attention because the car is still in park. The scheduler calls the warning function which then blinks a dashboard warning.

Here are some useful terms for typing operating systems:

  • preemptive - The operating system will seize control of the processor from processes. This is usually associated with time-sharing.
  • cooperative - The operating system will wait for a process to surrender control. This is usually associated with even-driven operating systems.
  • event-driven - The operating system will change state only in response to events or messages from interrupts or processes. This is usually associated with cooperative operating systems.
  • time-sharing - The operating system will change state at time intervals. This is usually associated with preemptive operating systems.
  • flyback time - The time needed for the operating system to move a process into the queue and return to the appropriate process.
  • real time - The operating system is oriented toward predictable behavior, long term stability, and fixed worst case transitions. This usually means sacrificing average performance in favor of guaranteed performance on individual tasks.

Comments, questions, feedback, criticisms?

Send feedback