简体   繁体   English

linux下pthread优先级和lwp优先级有什么关系?

[英]How does the pthread priority relate to lwp priority under linux?

I have an application running on Linux using SCHED_FIFO via pthread_attr_setschedpolicy.我有一个通过 pthread_attr_setschedpolicy 使用 SCHED_FIFO 在 Linux 上运行的应用程序。

My understanding is that pthread_attr_setschedparam() should allow setting the thread priority on a thread attributes structure before the thread is launched and Posix requires at least 32 levels are supported.我的理解是 pthread_attr_setschedparam() 应该允许在线程启动之前在线程属性结构上设置线程优先级,并且 Posix 要求至少支持 32 个级别。

Indeed while running:确实在运行时:

sched_get_priority_max(SCHED_FIFO) = 99
sched_get_priority_min(SCHED_FIFO) = 1

The thread priority is set before pthread_create using:线程优先级在 pthread_create 之前使用:

pthread_attr_setinheritsched(&thread_attr,PTHREAD_EXPLICIT_SCHED))
pthread_attr_setschedparam(&thread_attr)

If I interrogate it如果我审问它

pthread_attr_t thread_attr;
struct sched_param s_param;
int res = pthread_getattr_np(channel_data_p->thread, &thread_attr);
assert(res == 0);
res = pthread_attr_getschedparam (&thread_attr, &s_param);
assert(res == 0);
log_write("thread %d, priority = %d",threadId,s_param.sched_priority);

I see the expected priority.我看到了预期的优先级。 However, I'm not clear how to display the pthreads priority using ps -o, top -H or looking in /proc or how to relate Linux values like PR and NI (if they are the right fields to watch under top -H) back to the posix priority.但是,我不清楚如何使用 ps -o、top -H 或查看 /proc 来显示 pthreads 优先级,或者如何关联 PR 和 NI 等 Linux 值(如果它们是在 top -H 下观看的正确字段)回到posix优先级。

I have no intention of messing with the priorities dynamically so this is more of academic interest.我无意动态地弄乱优先级,所以这更多的是学术兴趣。

The pthreads priority maps directly to the Linux thread/process priority. pthreads 优先级直接映射到 Linux 线程/进程优先级。

This article describes the scheduler quite well (from the book Linux Kernel Development ):这篇文章很好地描述了调度器(来自Linux Kernel Development一书):

http://www.informit.com/articles/article.aspx?p=101760&seqNum=2 http://www.informit.com/articles/article.aspx?p=101760&seqNum=2

As noted here linux schedules threads nowadays and not processes using a 1:1 mapping of threads to processes.正如这里所指出的,现在 linux 调度线程,而不是使用线程到进程的1:1映射的进程。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM