如果我的调度策略是 SCHED_OTHER,使用 setpriority() 有什么影响吗
Does using setpriority() have any affect if my scheduling policy is SCHED_OTHER
我的调度策略是SCHED_OTHER。使用 setpriority() 更改 nice 值是否会产生任何影响。
我用的时候没看出有什么区别。
答案是不。在这种情况下,setpriority 不应影响进程。根据文档:
http://linux.die.net/man/3/setpriority
> 任何使用 SCHED_FIFO 或 SCHED_RR 的进程或线程都不应受到调用 setpriority() 的影响。这不被视为错误。随后恢复到 SCHED_OTHER 的进程不需要其优先级受到此类 setpriority() 调用的影响。
对不起,请仔细阅读 http://man7.org/linux/man-pages/man7/sched.7.html:
SCHED_OTHER: Default Linux time-sharing scheduling
SCHED_OTHER can be used at only static priority 0. SCHED_OTHER is
the standard Linux time-sharing scheduler that is intended for all
threads that do not require the special real-time mechanisms. The
thread to run is chosen from the static priority 0 list based on a
dynamic priority that is determined only inside this list. The
dynamic priority is based on the nice value (set by nice(2),
setpriority(2), or sched_setattr(2)) and increased for each time
quantum the thread is ready to run, but denied to run by the
scheduler. This ensures fair progress among all SCHED_OTHER threads.
因此,线程的 dynamic 优先级受调用 setpriority 的影响,它应该会导致调度发生变化(取决于调用中设置的新优先级值).
您还可以使用 nice() 降低动态优先级。
试试不错(9)。
#include <unistd.h>
int nice(int inc); // inc = increase, added to the current nice value
我的调度策略是SCHED_OTHER。使用 setpriority() 更改 nice 值是否会产生任何影响。 我用的时候没看出有什么区别。
对不起,请仔细阅读 http://man7.org/linux/man-pages/man7/sched.7.html:
SCHED_OTHER: Default Linux time-sharing scheduling SCHED_OTHER can be used at only static priority 0. SCHED_OTHER is the standard Linux time-sharing scheduler that is intended for all threads that do not require the special real-time mechanisms. The thread to run is chosen from the static priority 0 list based on a dynamic priority that is determined only inside this list. The dynamic priority is based on the nice value (set by nice(2), setpriority(2), or sched_setattr(2)) and increased for each time quantum the thread is ready to run, but denied to run by the scheduler. This ensures fair progress among all SCHED_OTHER threads.
因此,线程的 dynamic 优先级受调用 setpriority 的影响,它应该会导致调度发生变化(取决于调用中设置的新优先级值).
您还可以使用 nice() 降低动态优先级。
试试不错(9)。
#include <unistd.h>
int nice(int inc); // inc = increase, added to the current nice value