OSDN Git Service

(split) LDP: Update the version to 3.53 in PO files
[linuxjm/LDP_man-pages.git] / release / man3 / pthread_setaffinity_np.3
1 .\" Copyright (c) 2008 Linux Foundation, written by Michael Kerrisk
2 .\"     <mtk.manpages@gmail.com>
3 .\"
4 .\" %%%LICENSE_START(VERBATIM)
5 .\" Permission is granted to make and distribute verbatim copies of this
6 .\" manual provided the copyright notice and this permission notice are
7 .\" preserved on all copies.
8 .\"
9 .\" Permission is granted to copy and distribute modified versions of this
10 .\" manual under the conditions for verbatim copying, provided that the
11 .\" entire resulting derived work is distributed under the terms of a
12 .\" permission notice identical to this one.
13 .\"
14 .\" Since the Linux kernel and libraries are constantly changing, this
15 .\" manual page may be incorrect or out-of-date.  The author(s) assume no
16 .\" responsibility for errors or omissions, or for damages resulting from
17 .\" the use of the information contained herein.  The author(s) may not
18 .\" have taken the same level of care in the production of this manual,
19 .\" which is licensed free of charge, as they might when working
20 .\" professionally.
21 .\"
22 .\" Formatted or processed versions of this manual, if unaccompanied by
23 .\" the source, must acknowledge the copyright and authors of this work.
24 .\" %%%LICENSE_END
25 .\"
26 .\"*******************************************************************
27 .\"
28 .\" This file was generated with po4a. Translate the source file.
29 .\"
30 .\"*******************************************************************
31 .TH PTHREAD_SETAFFINITY_NP 3 2010\-09\-10 Linux "Linux Programmer's Manual"
32 .SH 名前
33 pthread_setaffinity_np, pthread_getaffinity_np \- スレッドの
34 CPU affinity の設定/取得を行う
35 .SH 書式
36 .nf
37 \fB#define _GNU_SOURCE\fP             /* See feature_test_macros(7) */
38 \fB#include <pthread.h>\fP
39
40 \fBint pthread_setaffinity_np(pthread_t \fP\fIthread\fP\fB, size_t \fP\fIcpusetsize\fP\fB,\fP
41 \fB                           const cpu_set_t *\fP\fIcpuset\fP\fB);\fP
42 \fBint pthread_getaffinity_np(pthread_t \fP\fIthread\fP\fB, size_t \fP\fIcpusetsize\fP\fB,\fP
43 \fB                           cpu_set_t *\fP\fIcpuset\fP\fB);\fP
44 .sp
45 \fI\-pthread\fP でコンパイルしてリンクする。
46 .fi
47 .SH 説明
48 \fBpthread_setaffinity_np\fP() 関数は、スレッド \fIthread\fP の CPU affinity
49 マスクに \fIcpuset\fP が指す CPU 集合を設定する。呼び出しが成功し、
50 そのスレッドが現在 \fIcpuset\fP で指定された CPU 上でが実行されていない
51 場合は、スレッドは指定された CPU のいずれかに移動される。
52
53 \fBpthread_getaffinity_np\fP() 関数は、スレッド \fIthread\fP の CPU affinity
54 マスクを、\fIcpuset\fP が指すバッファに入れて返す。
55
56 CPU affinity マスクの詳細については、
57 \fBsched_setaffinity\fP(2) を参照してほしい。
58 CPU 集合の操作や取得を行う際に利用できるマクロ群の説明は
59 \fBCPU_SET\fP(3) を参照してほしい。
60
61 引き数 \fIcpusetsize\fP は \fIcpuset\fP が指すバッファの長さ (バイト単位) で
62 ある。通常は、この引き数には \fIsizeof(cpu_set_t)\fP を指定する
63 (\fBCPU_SET\fP(3) に書かれているマクロを使って CPU 集合を動的に
64 割り当てている場合には、別の値になることもある)。
65 .SH 返り値
66 成功すると、これらの関数は 0 を返す。
67 エラーの場合、0 以外のエラー番号を返す。
68 .SH エラー
69 .TP 
70 \fBEFAULT\fP
71 指定されたメモリアドレスが無効である。
72 .TP 
73 \fBEINVAL\fP
74 (\fBpthread_setaffinity_np\fP()) affinity ビットマスク \fImask\fP に、
75 その時点でシステム上に物理的に存在して、かつそのスレッドに対して許可
76 されているプロセッサが一つも含まれていない。
77 スレッドに対してどのプロセッサの利用が許可されるかは、\fBcpuset\fP(7) で
78 説明されている "cpuset" 機構に適用される制限に基づいて決まる。
79 .TP 
80 \fBEINVAL\fP
81 .\" FIXME . ?
82 .\" Loic Domaigne commented: it seems that in the future the
83 .\" kernel developers want to make cpumask_t dynamic, so
84 .\" CONFIG_NR_CPUS might become obsolete in the future.
85 .\" cpumask_t
86 .\" The raw sched_getaffinity() system call returns the size (in bytes)
87 .\" of the cpumask_t type.
88 (\fBpthread_setaffinity_np\fP()) \fIcpuset\fP が、カーネルがサポートする CPU
89 集合に含まれない CPU を指定していた。(カーネルの設定オプション
90 \fBCONFIG_NR_CPUS\fP により、CPU 集合を表現するのに使われるカーネルの
91 データ型がサポートする CPU 集合の範囲が定義される。)
92 .TP 
93 \fBEINVAL\fP
94 (\fBpthread_getaffinity_np\fP()) \fIcpusetsize\fP がカーネルが使用する
95 affinity マスクの大きさよりも小さい。
96 .TP 
97 \fBESRCH\fP
98 ID が \fIthread\fP のスレッドが見つからなかった。
99 .SH バージョン
100 これらの関数は glibc バージョン 2.3.4 以降で提供されている。
101 .SH 準拠
102 これらの関数は非標準の GNU による拡張である。
103 そのため、名前に "_np" (nonportable; 移植性がない) という接尾辞が
104 付いている。
105 .SH 注意
106 \fBpthread_setaffinity_np\fP() を呼び出した後、
107 そのスレッドが実際に実行される CPU 集合は、
108 \fIcpuset\fP 引き数で指定された集合と
109 システムに実際に存在する CPU 集合の共通部分になる。
110 また、 \fBcpuset\fP(7) で説明されている "cpuset" 機構が使われている場合
111 には、そのスレッドが実行される CPU 集合がシステムによってさらに制限
112 される場合がある。そのスレッドが実行される実際の CPU 集合に対する
113 これらの制限は、カーネルにより黙って適用される。
114
115 これらの関数は、システムコール \fBsched_setaffinity\fP(2) と
116 \fBsched_getaffinity\fP(2) を使って実装されている。
117
118 (このバージョンだけであるが) glibc 2.3.3 では、
119 これらの関数は \fIcpusetsize\fP 引き数を持っていなかった。
120 内部で呼ばれるシステムコールに渡される CPU セットの大きさは
121 常に \fIsizeof(cpu_set_t)\fP であった。
122
123 \fBpthread_create\fP(3) で作成される新しいスレッドは、
124 作成者の CPU affinity マスクを継承する。
125 .SH 例
126 以下のプログラムでは、メインスレッドは
127 \fBpthread_setaffinity_np\fP() を使って自分の CPU affinity マスクに
128 CPU 0 から 7 が含まれるように設定し
129 (システム上には 0 から 7 に対応する CPU が全て存在するとは限らない)、
130 その後で \fBpthread_getaffinity_np\fP() を使って
131 スレッドに実際に設定された CPU affinity マスクを確認している。
132
133 .nf
134 #define _GNU_SOURCE
135 #include <pthread.h>
136 #include <stdio.h>
137 #include <stdlib.h>
138 #include <errno.h>
139
140 #define handle_error_en(en, msg) \e
141         do { errno = en; perror(msg); exit(EXIT_FAILURE); } while (0)
142
143 int
144 main(int argc, char *argv[])
145 {
146     int s, j;
147     cpu_set_t cpuset;
148     pthread_t thread;
149
150     thread = pthread_self();
151
152     /* Set affinity mask to include CPUs 0 to 7 */
153
154     CPU_ZERO(&cpuset);
155     for (j = 0; j < 8; j++)
156         CPU_SET(j, &cpuset);
157
158     s = pthread_setaffinity_np(thread, sizeof(cpu_set_t), &cpuset);
159     if (s != 0)
160         handle_error_en(s, "pthread_setaffinity_np");
161
162     /* Check the actual affinity mask assigned to the thread */
163
164     s = pthread_getaffinity_np(thread, sizeof(cpu_set_t), &cpuset);
165     if (s != 0)
166         handle_error_en(s, "pthread_getaffinity_np");
167
168     printf("Set returned by pthread_getaffinity_np() contained:\en");
169     for (j = 0; j < CPU_SETSIZE; j++)
170         if (CPU_ISSET(j, &cpuset))
171             printf("    CPU %d\en", j);
172
173     exit(EXIT_SUCCESS);
174 }
175 .fi
176 .SH 関連項目
177 \fBsched_setaffinity\fP(2), \fBsched_setscheduler\fP(2),
178 \fBpthread_attr_setaffinity_np\fP(3), \fBpthread_self\fP(3), \fBsched_getcpu\fP(3),
179 \fBcpuset\fP(7), \fBpthreads\fP(7)
180 .SH この文書について
181 この man ページは Linux \fIman\-pages\fP プロジェクトのリリース 3.53 の一部
182 である。プロジェクトの説明とバグ報告に関する情報は
183 http://www.kernel.org/doc/man\-pages/ に書かれている。