Pthreads 从Solaris上的pthread获取LWP id以与处理器绑定一起使用

Pthreads 从Solaris上的pthread获取LWP id以与处理器绑定一起使用,pthreads,solaris,setthreadaffinitymask,Pthreads,Solaris,Setthreadaffinitymask,在Solaris上,processor\u bind用于设置线程的关联性。您需要知道目标线程的LWPID,或者使用常量P_MYID来表示您自己 我有一个函数如下所示: void set_affinity(pthread_t thr, int cpu_number) { id_t lwpid = what_do_I_call_here(thr); processor_bind(P_LWPID, lwpid, cpu_number, NULL); } 事实上,我的函数中有很多跨平台的东

在Solaris上,
processor\u bind
用于设置线程的关联性。您需要知道目标线程的LWPID,或者使用常量
P_MYID
来表示您自己

我有一个函数如下所示:

void set_affinity(pthread_t thr, int cpu_number)
{
   id_t lwpid = what_do_I_call_here(thr);
   processor_bind(P_LWPID, lwpid, cpu_number, NULL);
}
事实上,我的函数中有很多跨平台的东西,为了清晰起见,我省略了这些东西

关键的一点是,我想设置任意pthread的亲和性,这样我就不能使用
p\u MYID


如何使用
处理器绑定
或替代接口实现这一点?

Solaris 11内核具有关键的线程优化功能。设置哪些线程需要特别注意,其余的由内核完成。这似乎是你想要的。请阅读这个简短的解释,看看我是否理解你的意思

https://blogs.oracle.com/observatory/entry/critical_threads_optimization
以上是另一种选择。对你来说,它可能根本飞不起来。但这是甲骨文的首选机制

对于Solaris 10,在调用
processor\u bind
时,使用LWP的
pthread\u t tid
idtype\u t
p\u LWPID
。这适用于Solaris 8->11。它仅适用于过程中的LWP。我不清楚这是否是你的模型


HTH

Solaris 11内核具有关键的线程优化。设置哪些线程需要特别注意,其余的由内核完成。这似乎是你想要的。请阅读这个简短的解释,看看我是否理解你的意思

https://blogs.oracle.com/observatory/entry/critical_threads_optimization
以上是另一种选择。对你来说,它可能根本飞不起来。但这是甲骨文的首选机制

对于Solaris 10,在调用
processor\u bind
时,使用LWP的
pthread\u t tid
idtype\u t
p\u LWPID
。这适用于Solaris 8->11。它仅适用于过程中的LWP。我不清楚这是否是你的模型


HTH

接下来,由于我的困惑:

lwpid是由创建的

pthread_create( &lwpid, NULL, some_func, NULL);
线程数据可通过
/proc
接口从外部提供给非执行
pthread\u create()
调用的进程

/proc/<pid>/lwp/<lwpid>/    lwpid == 1 is the main thread, 2 .. n are the lwpid in the above example.
可以读入包含更多信息的结构LWPInfo,从中可以确定是否正在查看所需的线程。请参见
/usr/include/sys/procfs.h


或者
man-s4 proc

跟进这个问题,由于我的困惑:

lwpid是由创建的

pthread_create( &lwpid, NULL, some_func, NULL);
线程数据可通过
/proc
接口从外部提供给非执行
pthread\u create()
调用的进程

/proc/<pid>/lwp/<lwpid>/    lwpid == 1 is the main thread, 2 .. n are the lwpid in the above example.
可以读入包含更多信息的结构LWPInfo,从中可以确定是否正在查看所需的线程。请参见
/usr/include/sys/procfs.h


或者
man-s4 proc

是否保证pthread_create()映射Solaris 10和11上的lwpid->pthread_t?pthread_t是一种数据类型。pthread_create的第一个参数将参数1修改为成功创建的线程的lwpid值。是的,我保证。在Solaris 10和11中/usr/include/sys/types.h:typedef uint\u t pthread\u t;/*=thread.h*/中的thread\u t是否保证pthread\u create()映射Solaris 10和11上的lwpid->pthread\u t?pthread\u t是一种数据类型。pthread_create的第一个参数将参数1修改为成功创建的线程的lwpid值。是的,我保证。在Solaris 10和11中/usr/include/sys/types.h:typedef uint\u t pthread\u t;/*=thread.h*/中的thread_t相当于
P_MYID
;该代码中既不能使用
pthread_self()
也不能使用
P_MYID
,因为它需要能够在任意目标线程上操作,而不仅仅是自身。这相当于
P_MYID
;该代码中既不能使用
pthread\u self()
也不能使用
P\u MYID
,因为它需要能够在任意目标线程上操作,而不仅仅是自身。