United States-English |
|
|
HP-UX Reference > Rrtsched(2)HP-UX 11i Version 3: February 2007 |
|
NAMErtsched: sched_get_priority_max(), sched_get_priority_min(), sched_getparam(), sched_getscheduler(), sched_rr_get_interval(), sched_setparam(), sched_setscheduler(), sched_yield(), PRI_HPUX_TO_POSIX(), PRI_POSIX_TO_HPUX() — real-time scheduling operations SYNOPSIS#include <sched.h> int sched_setparam( pid_t pid, const struct sched_param *param ); int sched_getparam( pid_t pid, struct sched_param *param ); int sched_setscheduler( pid_t pid, int policy, const struct sched_param *param ); int sched_getscheduler( pid_t pid ); int sched_yield(); int sched_get_priority_max( int policy ); int sched_get_priority_min( int policy ); int sched_rr_get_interval( pid_t pid, struct timespec *interval ); int PRI_POSIX_TO_HPUX( int pri ); int PRI_HPUX_TO_POSIX( int pri ); DESCRIPTIONSummary
sched_setparam()The sched_setparam() function sets the scheduling parameters of the process specified by pid to the values specified by the sched_param structure pointed to by param. The value of the sched_priority member in the param structure is any integer within the inclusive priority range for the current scheduling policy of the process specified by pid. Higher numerical values for the priority represent higher (stronger) priorities. Note that this is different from the SCHED_HPUX, SCHED_TIMESHARE, SCHED_NOAGE, and SCHED_RTPRIO scheduling policies, where higher numerical values represent lower (weaker) priorities. See the PRI_HPUX_TO_POSIX() and PRI_POSIX_TO_HPUX() functions, and SCHED_RTPRIO, SCHED_NOAGE, and SCHED_OTHER in Scheduling Policies below. If a process described by pid exists and if the calling process has permission, the scheduling parameters are set for the process whose process ID is equal to pid. If pid is zero, the scheduling parameters are set for the calling process. If the process pid contains more than one thread or lightweight process (that is, the process is multithreaded), this function will affect the policy and priority of individual kernel schedulable entities in the process depending on their scheduling contention scope.
The priority returned is the old priority of the target process, though individual threads or lightweight processes may have a different value if some other interface is used to change an individual thread or lightweight processes priority. Only a user with the OWNER privilege may change the scheduling parameters of another process. The calling process must have the RTSCHED privilege to successfully call sched_setparam(). The target process, whether it is running or not running, will resume execution after all other runnable processes of equal or greater priority have been scheduled to run. If the priority of any kernel schedulable entities (threads) in the process is changed and is set higher than that of the lowest priority running thread, and if any of the modified threads is ready to run, then it will preempt the lower-priority running thread. Similarly, if the process calling sched_setparam() sets its own priority lower than that of one or more other nonempty thread lists, then the thread that is the head of the highest priority list will also preempt the calling thread. Thus, in either case, the originating process may not receive notification of the completion of the requested priority change until the higher priority thread has executed. sched_getparam()The sched_getparam() function returns the scheduling parameters of a process specified by pid in the sched_param structure pointed to by param. If a process described by pid exists, the scheduling parameters are returned for the process whose process ID is equal to pid. If the process pid contains more than one thread or lightweight process (that is, the process is multithreaded), this function shall only return the process scheduling policy and priority. Individual threads or lightweight processes in the target process will have their own scheduling policies and priorities which may be different from the scheduling policy and priority of their process. If pid is zero, the scheduling parameters are returned for the calling process. sched_setscheduler()The sched_setscheduler() function sets the scheduling policy and scheduling parameters of the process specified by pid to policy and the parameters specified in the sched_param structure pointed to by param, respectively. The value of the sched_priority member in the param structure can be any integer within the inclusive priority range for the scheduling policy specified by policy. The possible values for the policy parameter are defined in the header file <sched.h>, and mentioned below. If a process described by pid exists, the scheduling policy and scheduling parameters are set for the process whose process ID is equal to pid. If pid is zero, the scheduling policy and scheduling parameters are set for the calling process. If the process pid contains more than one thread or lightweight process (that is, the process is multithreaded), this function will affect the policy and priority of individual kernel schedulable entities in the process depending on their scheduling contention scope.
The priority returned is the old priority of the target process, though an individual thread or lightweight process may have a different value if some other interface is used to change individual thread's or lightweight process's priority. The OWNER privilege is required to change the scheduling parameters of another process. The calling process must have the RTSCHED privilege to successfully call sched_setscheduler(). The sched_setscheduler() function is considered successful if it succeeds in setting the scheduling policy and scheduling parameters of the process specified by pid to the values specified by policy and the structure param, respectively. sched_getscheduler()The sched_getscheduler() function returns the scheduling policy of the process specified by pid. The values that can be returned by sched_getscheduler() are defined in the header file <sched.h> (see sched_setscheduler()). If a process described by pid exists, the scheduling policy is returned for the process whose process ID is equal to pid. If pid is zero, the scheduling policy is returned for the calling process. If the process pid contains more than one thread or lightweight process (that is, the process is multithreaded), this function shall only return the process scheduling policy and priority. Individual threads or lightweight processes in the target process will have their own scheduling policies and priorities which may be different from the scheduling policy and priority of their process. sched_yield()The sched_yield() function forces the calling thread to relinquish the processor until it again becomes the head of its thread list. It takes no arguments. sched_get_priority_max(), sched_get_priority_min()The sched_get_priority_max() and sched_get_priority_min() functions return the appropriate maximum or minimum, respectively, for the scheduling policy specified by policy. The value of policy must be one of the scheduling policy values defined in <sched.h>. sched_rr_get_interval()The sched_rr_get_interval() function updates the timespec structure referenced by the interval argument to contain the current execution time limit (that is, time quantum) for the process indicated by pid under the SCHED_RR policy, at which a scheduling decision will be made when another process at the same priority is ready to execute. If pid is zero, the current execution time limit for the calling process is returned. PRI_HPUX_TO_POSIX(), PRI_POSIX_TO_HPUX()These two functions serve to map (translate) the range of HP-UX priorities into the POSIX.4 model. These translations are necessary because the POSIX.4 standard chose larger numbers to represent stronger priorities and the existing HP-UX behavior, which must be maintained for backward compatibility, uses smaller numbers for stronger priorities. The PRI_HPUX_TO_POSIX() function returns the POSIX.4 scheduling priority corresponding to the HP-UX priority passed in the argument pri. The value of pri can be any integer. The PRI_POSIX_TO_HPUX() function returns an HP-UX process priority corresponding to the priority passed in the argument pri. The value of pri can be any integer. The HP-UX priority returned is comparable to the values returned by getpriority() (see getpriority(2)). Scheduling PoliciesThe scheduling policies described are defined in terms of a conceptual model, which contains a set of thread lists. There is, conceptually, one thread list for each priority. Any runnable thread may be in any thread list. Multiple scheduling policies are provided. Each nonempty list is ordered, and contains a head as one end of its order, and a tail as the other. The purpose of a scheduling policy is to define the allowable operations on this set of lists (for example, moving threads between and within lists). Each thread will be controlled by an associated scheduling policy and priority. These parameters may be specified by explicit application execution of the sched_setscheduler() or sched_setparam() functions. (However, these functions change scheduling parameters at process level for multithreaded processes). Associated with each policy is a priority range. The priority ranges for each policy can (but need not) overlap the priority ranges of other policies. When a thread is to be selected to run, the thread that is at the head of the highest priority nonempty thread list is chosen. It is then removed from its thread list. The following scheduling policies are defined:
The threads in different processor sets do not compete with one another for processors based on their scheduling policy and priority values. The scheduler looks only at threads assigned to a processor's processor set to choose the next thread to run. A process with lower scheduling priority in one processor set may be executing while another process in another processor set with higher scheduling priority is waiting for the processor resources. This is applicable for all scheduling policies. Security RestrictionsSome or all of the actions associated with this system call are subject to compartmental restrictions. See compartments(5) for more information about compartmentalization on systems that support that feature. Compartmental restrictions can be overridden if the process possesses the COMMALLOWED privilege (PRIV_COMMALLOWED). Processes owned by the superuser may not have this privilege. Processes owned by any user may have this privilege, depending on system configuration. Some or all of the actions associated with this system call require the OWNER or the RTSCHED privilege. Processes owned by the superuser have these privileges. Processes owned by other users may have these privileges, depending on system configuration. See privileges(5) for more information about privileged access on systems that support fine-grained privileges. RETURN VALUEThe functions return the following values: sched_getparam(), sched_rr_get_interval(), sched_setparam(), sched_yield()
sched_setscheduler()
sched_getscheduler()
ERRORSIf the functions fail, errno is set to one of the following values. sched_setparam()
sched_getparam()
sched_setscheduler()
sched_getscheduler()
EXAMPLESChange the calling process to use the strongest FIFO priority: #include <sched.h> struct sched_param param; int maxpri; maxpri = sched_get_priority_max(SCHED_FIFO); if (maxpri == -1) { perror("sched_get_priority_max() failed"); exit(1); } param.sched_priority = maxpri; if (sched_setscheduler(getpid(), SCHED_FIFO, ¶m) == -1) { perror("sched_setscheduler() failed"); exit(1); } |
Printable version | ||
|