OSDN Git Service

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