thread_setsched Kernel Service

Purpose

Sets kernel thread scheduling parameters.

Syntax

#include <sys/thread.h>
#include <sys/sched.h>

int thread_setsched ( tid,  priority,  policy)
tid_t tid;
int priority;
int policy;

Parameters

Item Description
tid Specifies the kernel thread.
priority Specifies the priority. It must be in the range from 0 to PRI_LOW; 0 is the most favored priority.
policy Specifies the scheduling policy. It must have one of the following values:
SCHED_FIFO
Denotes fixed priority first-in first-out scheduling.
SCHED_FIFO2
Allows a thread that sleeps for a relatively short amount of time to be requeued to the head, rather than the tail, of its priority run queue.
SCHED_FIFO3
Causes threads to be enqueued to the head of their run queues.
SCHED_RR
Denotes fixed priority round-robin scheduling.
SCHED_OTHER
Denotes the default scheduling policy.

Description

The thread_setsched subroutine sets the scheduling parameters for a kernel thread. This includes both the priority and the scheduling policy, which are specified in the priority and policy parameters. The calling and the target thread must be in the same process.

When setting the scheduling policy to SCHED_OTHER, the system chooses the priority; the priority parameter is ignored. The only way to influence the priority of a thread using the default scheduling policy is to change the process nice value.

The calling thread must belong to a process with root authority to change the scheduling policy of a thread to either SCHED_FIFO, SCHED_FIFO2, SCHED_FIFO3, or SCHED_RR.

Execution Environment

The thread_setsched kernel service can be called from the process environment only.

Return Values

Upon successful completion, 0 is returned. Otherwise, -1 is returned, and the error code can be checked by calling the getuerror kernel service.

Error Codes

Item Description
EINVAL The priority or policy parameters are not valid.
EPERM The calling kernel thread does not have sufficient privilege to perform the operation.
ESRCH The kernel thread tid does not exist.