TOC PREV NEXT INDEX

POSIX 1.b Migration Guide


Scheduling

Scheduler Priority

The main difference in scheduling functionality is the way scheduling priorities are handled. In Draft 9, scheduling priorities are defined as type int. However, POSIX.1b defines a new structure, sched_param, which encloses the priority field as type sched_priority. A pointer to the structure sched_param must be passed to all scheduling functions. An example of these changes is shown below.

Draft 9 code

#include <sys/sched.h>

main()
{
int prio;
pid_t pid;
:
prio = getprio(pid);
:
}

Equivalent POSIX.1b code

#include <sched.h>

main()
{
int prio;
struct sched_param parameter;
pid_t pid;
:
sched_getparam(pid, &parameter);
prio = parameter.sched_priority;
:
}

Changes to Macros

Another minor change is that a number of Draft 9 macros are replaced by functions in POSIX.1b as explained in the table below.

Scheduling Interface Changes  
Draft 9
POSIX.1b
<sys/sched.h>
<sched.h>
No Equivalent
struct sched_param
setscheduler()
sched_setscheduler()
getscheduler()
sched_getscheduler()
setprio()
sched_setparam()
getprio()
sched_getparam()
yield()
sched_yield()
PRIO_??_MAX macros
sched_get_priority_max()
PRIO_??_MIN macros
sched_get_priority_min()
RR_INTERVAL macro
sched_rr_get_interval()

The following examples illustrates these changes:

Draft 9 code

#include <sys/sched.h>

main()
{
printf("FIFO min prio = %d\n", PRIO_FIFO_MIN);
}

Equivalent POSIX.1b code

#include <sched.h>

main()
{
printf("FIFO min prio = %d\n",
sched_get_priority_min(SCHED_FIFO));
}

Macros vs. Functions

Draft 9 defines a number of macros for certain scheduler parameters. Six of these macros defined the minimum and maximum scheduler priorities for the three scheduling policies:

PRIO_FIFO_MIN
PRIO_RR_MIN
PRIO_OTHER_MIN
PRIO_FIFO_MAX
PRIO_RR_MAX
PRIO_OTHER_MAX

These were replaced by two functions in POSIX.1b. The function sched_get_priority_min() takes a scheduling policy as input and returns the minimum priority for it. The function sched_get_priority_max() takes a scheduling policy as input and returns the maximum priority for it.

Draft 9 defines the macro RR_INTERVAL for the interval for the SCHED_RR policy. This is replaced by a new function sched_rr_get_interval() in POSIX.1b.

yield ()

The Draft 9 yield() function does not return anything, and sets no error numbers. The equivalent sched_yield() function in POSIX.1b returns an int and sets an error number on failure.

SCHED_OTHER

The behavior for the SCHED_OTHER scheduling policy has not changed. This is the same as SCHED_DEFAULT, which is the LynxOS proprietary scheduling policy.

Non-Preemptible Scheduling Policy

LynxOS implements a non-preemptible scheduling policy called SCHED_NONPREEMPT. A process running under this policy cannot be preempted by any other process until it voluntarily sleeps or blocks waiting for a semaphore or mutex object. An example of this policy is a garbage collector running with low priority and performing critical work so that it must not be interrupted. The sample code of the application is as follows:

void garbage_collector(arg)
void *arg;
{
...
while (1) { /* endless loop */
if (waste_ratio() > max_waste_ratio) {
/* garbage collection, critical area
*/
...
}
sleep(GC_TIMEOUT);
} /* end of loop */
}

main()
{
pthread_attr_t attr;
struct sched_param prio;
pthread_t tid;
...
pthread_attr_create(&attr);
pthread_attr_setinheritsched(&attr, PTHREAD_EXPLICIT_SCHED);
pthread_attr_setschedpolicy(&attr, SCHED_NONPREEMPT);
prio.sched_priority = PRIO_NONPREEMPT_MIN;
pthread_attr_setschedparam(&attr, &prio);
pthread_create(&tid, &attr, garbage_collector, NULL);
...
}

LynxOS also defines 2 constants for the SCHED_NONPREEMPT policy designating the maximum and minimum priorities for this policy. These constants are:

These priorities can also be obtained using the sched_get_priority_max() and sched_get_priority_min() functions.

Interoperability

There have been no changes in the standard scheduling facilities, and, therefore, interoperability is preserved. Two processes, one using Draft 9 scheduling and another using POSIX.1b scheduling would get the CPU slices as if they used the same version of scheduling.



LynuxWorks, Inc.
855 Branham Lane East
San Jose, CA 95138
http://www.lynuxworks.com
1.800.255.5969
TOC PREV NEXT INDEX