Bitmap Scheduler Priority Levels

82 Chapter 5 • The Kernel in the system. The number of threads possible for the multilevel queue scheduler is independent from the number of priority levels. The maximum number of threads for the multilevel queue scheduler is dependent on the memory resources available. The maximum number of priority levels allowed is 32. A smaller value for the priority level corresponds the higher the priority of the thread. Item List 5.2 lists the kernel API functions for priority level manipulation of a given thread. Item List 5.2 Kernel Priority Level API Functions Syntax: void cyg_thread_set_priority cyg_handle_t thread, cyg_priority_t priority ; Context: Thread Parameters: thread—handle to the thread. priority—level to set the thread priority. Figure 5.4 Bitmap scheduler thread operation. Bitmap Scheduling Queue Maximum Priority 0 Minimum Priority 31 Thread A Thread B . . . . . . Thread C Thread A Time Thread C Deschedule Thread C Preemption Thread B Deschedule The Kernel 83 Description: Set the thread to the specified priority level. The valid ranges for the priority value are determined by the configuration option settings. The number of priority levels can be con- figured from 1 to 32, where lower values represent higher thread priorities. Syntax: cyg_priority_t cyg_thread_get_current_priority cyg_handle_t thread ; Context: ThreadDSR Parameters: thread—handle to the thread. Description: Return the current priority level for the specified thread. This priority value might differ from the priority set for the thread, during creation or by a cyg_thread_set_priority function call, since a thread priority boost might have occurred due to the thread using a mutex. Syntax: cyg_priority_t cyg_thread_get_priority cyg_handle_t thread ; Context: ThreadDSR Parameters: thread—handle to the thread. Description: Return the priority for the specified thread. This priority returned is the value last used in a call to cyg_thread_set_priority or the value when the thread was created.

5.1.3.4 Scheduler Configuration

The scheduler configuration options are located under the Kernel Schedulers component within eCos Kernel package. The configuration options allow you to tailor the resources used by the scheduler according to the specific needs of the application. Item List 5.3 details the configura- tion options available, as well as the different suboptions. Item List 5.3 Kernel Scheduler Configuration Options Option Name Multilevel Queue Scheduler CDL Name CYGSEM_KERNEL_SCHED_MLQUEUE Description Enables the multilevel queue scheduler implementation. Option Name Bitmap Scheduler CDL Name CYGSEM_KERNEL_SCHED_BITMAP Description Enables the bitmap scheduler implementation. Option Name Number of Priority Levels CDL Name CYGNUM_KERNEL_SCHED_PRIORITIES Description Specifies the number of available priority levels. This number determines the queue size for the specified scheduler. For the bitmap scheduler, this number also determines total number of threads possible. Valid values for this option are 1 to 32, with the default being set to 32. A suboption allows the selection of the de-queue method. When enabled, threads of equal pri- ority are de-queued with the oldest thread first. This suboption is disabled by default. 84 Chapter 5 • The Kernel Option Name Scheduler Timeslicing CDL Name CYGSEM_KERNEL_SCHED_TIMESLICE Description Enables timeslicing mode for the multilevel queue scheduler. The scheduler checks to determine if another thread at the same priority level is ready to run. If so, a context switch will take place after the timeslice period, selectable as a suboption in clock ticks between timeslices, expires. This option is enabled by default for the multilevel queue scheduler. Another suboption allows timeslicing to be dynamically enabled or disabled on a per-thread basis. Option Name Enable ASR Support CDL Name CYGSEM_KERNEL_SCHED_ASR_SUPPORT Description Controls Asynchronous Service Routine ASR support, which is a function called from the scheduler when it has exited the scheduler lock. This is typically used by compatibility layer packages, such as POSIX.

5.2 Summary

In this chapter, we looked at the functionality provided by the core of eCos, the kernel. We examined the kernel startup procedure. We also looked at the two scheduling algorithms available for the eCos kernel: bitmap and multilevel queue.