Êíèãà: Programming with POSIX® Threads

9.3.8 Realtime scheduling

9.3.8 Realtime scheduling

Realtime scheduling provides a predictable response time to important events within the process. Note that "predictable" does not always mean "fast," and in many cases realtime scheduling may impose overhead that results in slower execution. Realtime scheduling is also subject to synchronization problems such as priority inversion (Sections 5.5.4 and 8.1.4), although Pthreads provides optional facilities to address some of these problems.

pthread_attr_getinheritsched....................................... [_POSIX_THREAD_PRIORITY_SCHEDULING]

int pthread_attr_getinheritsched (

const pthread_attr_t *attr,

int *inheritsched);

Determine whether threads created with attr will run using the scheduling policy and parameters of the creator or those specified in the attributes object. The default inheritsched is implementation-defined.

inheritsched

PTHREAD_INHERIT_SCHED

Use creator's scheduling policy and parameters.

PTHREAD_EXPLICIT_SCHED

Use scheduling policy and parameters in attributes object.

References: 5.2.3, 5.5 Headers: <pthread.h>

Errors: [ENOSYS] priority scheduling is not supported.

[EINVAL] attr invalid.

pthread_attr_getschedparam......................................[_POSIX_THREAD_PRIORITY_SCHEDLLING]

int pthread_attr_getschedparam (

const pthread_attr_t *attr, struct sched_param *param);

Determine the scheduling parameters used by threads created with attr. The default param is implementation defined.

References: 5.2.3, 5.5 Headers: <pthread.h>

Errors: [ENOSYS] priority schedulingis not supported.

[EINVAL] attr invalid.

pfhread_attr_getschedpolicy....................................... [_POSIX_THREAD_PRIORITY_SCHEDULING]

int pthread_attr_getschedpolicy (

const pthread_attr_t *attr, int *policy);

Determine the scheduling policy used by threads created with attr. The default policy is implementation defined.

SCHED_FIFO

SCHED_RR

SCHED_OTHER

policy

Run thread until it blocks; preempt lower-priority threads when ready.

Like SCHED_FIFO, but subject to periodic timeslicing.

Implementation defined (may be SCHED_FIFO, SCHED_RR, or something else).

References: 5.2.3, 5.5 Headers: <pthread.h>

Errors: [ENOSYS] priority scheduling is not supported.

[EINVAL] attr invalid.

pthread_attr_getscope.................................................[_POSIX_THREAD_PRIORITY_SCHEDULLING]

int pthread_attr_getscope (

const pthread_attr_t *attr,

int *contentionscope);

Determine the contention scope used by threads created with attr. The default is implementation defined.

contentionscope

PTHREAD_SCOPE_PROCESS

Thread contends with other threads in the process for processor resources.

PTHREAD SCOPE SYSTEM

Thread contends with threads in all processes for processor resources.

References: 5.2.3, 5.5 Headers: <pthread.h>

Errors: [ENOSYS] priority scheduling is not supported.

[EINVAL] attr invalid. Hint: Implementation must support one or both of these, but need not

support both.

pthread_attr_setinheritsched.......................................[_POSIX_THREAD_PRIORITY_SCHEDULING ]

int pthread_attr_setinheritsched ( pthread_attr_t *attr, int inheritsched);

Specify whether threads created with attr will run using the scheduling policy and parameters of the creator or those specified in the attributes object. When you change the scheduling policy or parameters in a thread attributes object, you must change the inheritsched attribute from PTHREAD_INHERIT_SCHED to PTHREAD_ EXPLICIT_SCHED. The default is implementation-defined.

inheritsched

PTHREAD_INHERIT_SCHED

Use creator's scheduling policy and parameters.

PTHREAD_EXPLICIT_SCHED

Use scheduling policy and parameters in attributes object.

References: 5.2.3, 5.5 Headers: <pthread.h>

Errors: [ENOSYS] priority scheduling is not supported.

[EINVAL] attr or inheritsched invalid.

pthread_attr_setschedparam......................................[_POSIX_THREAD_PRIORITY_SCHEDULING]

int pthread_attr_setschedparam (

pthread_attr_t *attr,

const struct sched_param *param);

Specify the scheduling parameters used by threads created with attr. The default param is implementation defined.

References: 5.2.3, 5.5 Headers: <pthread.h>

Errors: [ENOSYS] priority scheduling is not supported.

[EINVAL] attr or param invalid. [ENOTSUP] param set to supported value.

pthread_attr_setschedpolicy....................................... [_POSIX_THREAD_PRIORITY_SCHEDULING]

int pthread_attr_setschedpolicy ( pthread_attr_t *attr, int policy);

Specify the scheduling policy used by threads created with attr. The default policy is implementation defined.

SCHED_FIFO

SCHED_RR

SCHED_OTHER

policy

Run thread until it blocks; preempt lower-priority threads when ready.

Like SCHED_FIFO, but sub-ject to periodic timeslicing.

Implementation defined(may be SCHED_FIFO, SCHED_RR, or something else).

References: 5.2.3, 5.5 Headers: <pthread.h>

Errors: [ENOSYS] priority scheduling is not supported

[EINVAL] attr or policy invalid. [ENOTSUP] param set to supported value.

pthread_attr_setscope.................................................. [_POSIX_THREAD_PRIORITY_SCHEDULING]

int pthread_attr_setscope (

pthread_attr_t *attr,

int contentionscope);

Specify the contention scope used by threads created with attr. The default is implementation defined.

contentionscope

PTHREAD SCOPE PROCESS

Thread contends with other threads in the process for processor resources.

PTHREAD SCOPE SYSTEM

Thread contends with threads in all processes for processor resources.

References:

Headers:

Errors:

Hint:

5.2.3, 5.5 <pthread.h>

[ENOSYS] priority scheduling is not supported. [EINVAL] attr or contentionscope invalid. [ENOTSUP] contentionscope set to supported value. Implementation must support one or both of these, but need not support both.

pthread_getschedparam............................................. [_POSIX_THREAD_PRIORITY_SCHEDULING]

int pthread_getschedparam (

pthread_t thread,

int *policy

struct sched_param *param);

Determine the schedulingpolicy and parameters (param) currently used by thread.

policy

Run thread until it blocks; preempt lower-priority threads when ready.

SCHED_FIFO

SCHED_RR SCHED_OTHER

Like SCHED_FIFO, but subject to periodic timeslicing.

Implementation defined (may be SCHED_FIFO, SCHED_RR, or something else).

References: 5.2.3, 5.5 Headers: <pthread.h>

Errors: [ENOSYS] priority scheduling is not supported.

[ESRCH] thread does not refer to an existing thread. Hint: Try to avoid dynamically modifying thread scheduling policy and

parameters, if possible.

| prhread_mutex_getprioceiling...................................................[_POSIX_THREAD_PRIO_PROTECT]

int pthread_mutex_getprioceiling (

const pthread_mutex_t *mutex,

int *prioceiling);

Determine the priority ceiling at which threads will run while owning mutex.

References: 3.2,5.2.1,5.5.5 Headers: <pthread.h>

Errors: [ENOSYS] priority scheduling is not supported.

[EINVAL] mutex invalid. Hint: Protect protocol is inappropriate unless the creator of the mutex

also creates and controls all threads that might lock the mutex.

pthread_mutex_setprioceiling....................................................[_POSIX_THREAD_PRIO_PROTECT ]

int pthread_mutex_getprioceiling ( pthread_mutex_t *mutex, int prioceiling,

int *old_ceiling);

Specify the priority ceiling at which threads will run while owning mutex. Returns previous priority ceiling for mutex.

References: 3.2,5.2.1,5.5.5 Headers: <pthread.h>

Errors: [ENOSYS] priority scheduling is not supported.

[EINVAL] mutex invalid, or prioceiling out of range.

[EPERM] no privilege to set prioceiling. Hint: Protect protocol is inappropriate unless the creator of the mutex

also creates and controls all threads that might lock the mutex.

pthread_mutexattr_getprioceiling.............................................[_POSIX_THREAD_PRIO_PROTECT ]

int pthread_mutexattr_getprioceiling (

const pthread_mutexattr_t *attr,

int *prioceiling);

Determine the priority ceiling at which threads will run while owning a mutex created with attr.

References: 3.2, 5.2.1, 5.5.5 Headers: <pthread.h>

Errors: [ENOSYS] priority scheduling is not supported.

[EINVAL] attr invalid. Hint: Protect protocol is inappropriate unless the creator of the mutex

also creates and controls all threads that might lock the mutex.

pthread_mutexattr_getprotocol... [_POSIX_THREAD_PRIO_INHERIT_POSIX_THREAD_PRIO_PROTECT]

int pthread_mutexattr_getprotocol (

const pthread_mutexattr_t *attr,

int *protocol);

Determine whether mutexes created with attr have priority ceiling protocol protect), priority inheritance protocol (inherit), or no priority protocol (none).

protocol

PTHREAD_PRIO_NONE No priority inheritance

protocol.

PTHREAD_PRIO_INHERIT While owning mutex, thread

inherits highest priority of any thread waiting for the mutex.

PTHREAD_PRIO_PROTECT While owning mutex, thread

inherits mutex priority ceiling.

References: 3.2,5.2.1,5.5.5 Headers: <pthread.h>

Errors: [ENOSYS] priority scheduling is not supported.

[EINVAL] attr invalid. Hint: Inherit protocol is expensive, and protect protocol is inappropriate

unless the creator of the mutex also creates and controls all threads

that might lock the mutex.

pthread_mutexattr_setprioceiling...............................................[_POSIX_THREAD_PRIO_PROTECT ]

int pthread_mutexattr_setprioceiling ( pthread_mutexattr_t *attr,

int prioceiling);

Specify the priority ceiling at which threads will run while owning a mutex created with attr. The value of prioceiling must be a valid priority parameter for the

SCHED_FIFO policy.

References: 3.2,5.2.1,5.5.5 Headers: <pthread.h>

Errors: [ENOSYS] priority scheduling is not supported.

[EINVAL] attr or prioceiling invalid.

[EPERM] no permission to set prioceiling. Hint: Protect protocol is inappropriate unless the creator of the mutex

also creates and controls all threads that might lock the mutex.

pthread_mutexattr_setprotocol .... [_POSIX_THREAD_PRIO_INHERIT_POSIX_THREAD_PRIO_PROTECT]

int pthread_mutexattr_setprotocol (

pthread_mutexattr_t *attr,

int protocol);

Specify whether mutexes created with attr have priority ceiling protocol protect), priority inheritance protocol (inherit), or no priority protocol (none).

protocol

PTHREAD_PRIO_NONE No priority inheritance

protocol.

PTHREAD_PRIO_INHERIT While owning mutex, thread

inherits highest priority of any thread waiting for the mutex.

PTHREAD_PRIO_PROTECT While owning mutex, thread

inherits mutex priority ceiling.

References: 3.2,5.2.1,5.5.5 Headers: <pthread.h>

Errors: [ENOSYS] priority scheduling is not supported.

[EINVAL] attr or protocol invalid.

[ENOTSUP] protocol value is not supported. Hint: Inherit protocol is expensive, and protect protocol is inappropriate

unless the creator of the mutex also creates and controls all threads

that might lock the mutex.

pthread_setschedparam..............................................[_POSIX_THREAD_PRIORITY_SCHEDULING]

int pthread_setschedparam (

pthread_t thread,

int policy

const struct sched_param *param);

Specify the scheduling policy and parameters (param) to be used by thread.

policy

SCHED_FIFO

SCHED_RR

Run thread until it blocks; preempt lower-priority threads when ready.

Like SCHED_FIFO, but subject to periodic timeslicing.

SCHED_OTHER

Implementation defined (may be SCHED_FIFO, SCHED_RR, or something else).

References:

Headers:

Errors:

Hint:

5.5

<pthread.h>

[ENOSYS] priority scheduling is not supported.

[ESRCH] thread does not refer to an existing thread.

[EINVAL] policy or param is invalid.

[ENOTSUP] policy or param is unsupported value.

[EPERM] no permission to set policy or param.

Try to avoid dynamically modifying thread scheduling policy and

parameters, if possible.

sched_get_priority_max..............................................................[_POSIX_PRIORITY_SCHEDULING]

int sched_get_priority_max (

int policy);

Return the maximum integer priority allowed for the specified scheduling policy.

policy

Run thread until it blocks; preempt lower-priority threads when ready.

Like SCHED_FIFO, but subject to periodic timeslicing.

Implementation defined (may be SCHED_FIFO, SCHED_RR, or something else).

References: 5.5.2 Headers: <sched.h>

Errors: [ENOSYS] priority scheduling is not supported.

[EINVAL] policy is invalid. Hint: Priority min and max are integer values—you can compute relative

values, for example, half and quarter points in range.

SCHED_FIFO

SCHED_RR

SCHED_OTHER

[_POSIX_PRIORITY_SCHEDULING]

sched_get_priority_min.........................................................

int sched_get_priority_min (

int policy);

Return the minimum integer priority allowed for the specified scheduling policy.

References: 5.5.2 Headers: <sched.h>

Errors: [ENOSYS] priority scheduling is not supported.

[EINVAL] policy is invalid. Hint: Priority min and max are integer values — you can compute relative

values, for example, half and quarter points in range.

policy
SCHED_ _FIFO Run thread until it blocks;
preempt lower-priority
threads when ready.
SCHED_ _RR Like SCHED_FIFO, but sub-
ject to periodic timeslicing.
SCHED_ OTHER Implementation defined (may
be SCHED_FIFO, SCHED_RR,
or something else).

Îãëàâëåíèå êíèãè


Ãåíåðàöèÿ: 0.045. Çàïðîñîâ Ê ÁÄ/Cache: 0 / 3
ïîäåëèòüñÿ
Ââåðõ Âíèç