everyone, I found this inside static int setscheduler(pid_t pid, int policy, struct sched_param *param) :
p->policy = policy;
if (policy != SCHED_OTHER) p->prio = MAX_USER_RT_PRIO-1 - p->rt_priority;
p is a pointer to the task descriptor with current pid (parameter above) so if it's policy is not SCHED_OHTER (it means SCHED_FIFO or SCHED_RR) but why do we change p->prio such way? what exactly does it mean rt_priority? thanks in advance
Short answer: rt_priority means real-time priority and for SCHED_RR and SCHED_FIFO it decides how much time the process will get.
Long answer
First of all Linux implements something called Realtime Process Scheduling (SCHED_RR and SCHED_FIFO). Processes operating under these policies always have priority over other processes.
Linux provides 99 realtime priority levels, numbered 1 (lowest) to 99 (highest).
In the kernel, if I recall correctly "smaller numbers mean better preference" - smaller p->prio means better priority.
Here us what sched_setscheduler looks like:
int sched_setscheduler(pid_t pid, int policy, const struct sched_param *param);
And sched_param
struct sched_param {
int sched_priority; /* Scheduling priority */
};
The integer sched_priority, for a policy of SCHED_RR or SCHED_FIFO means "realtime priority" which I assume is rt_priority. So the kernel does the right thing
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With