.\" This man page is Copyright (C) 2006 Andi Kleen . .\" .\" %%%LICENSE_START(VERBATIM_ONE_PARA) .\" Permission is granted to distribute possibly modified copies .\" of this page provided the header is included verbatim, .\" and in case of nontrivial modification author and date .\" of the modification is added to the header. .\" %%%LICENSE_END .\" .\" 2008, mtk, various edits .\" .\"******************************************************************* .\" .\" This file was generated with po4a. Translate the source file. .\" .\"******************************************************************* .\" .\" Japanese Version Copyright (c) 2012 Akihiro MOTOKI .\" all rights reserved. .\" Translated 2012-05-10, Akihiro MOTOKI .\" Updated 2012-05-29, Akihiro MOTOKI .\" Updated 2013-03-26, Akihiro MOTOKI .\" Updated 2013-05-04, Akihiro MOTOKI .\" .TH GETCPU 2 2013\-04\-03 Linux "Linux Programmer's Manual" .SH 名前 getcpu \- 呼び出し元スレッドが動作している CPU と NUMA ノードを判定する .SH 書式 .nf \fB#include \fP .sp \fBint getcpu(unsigned *\fP\fIcpu\fP\fB, unsigned *\fP\fInode\fP\fB, struct getcpu_cache *\fP\fItcache\fP\fB);\fP .fi \fI注\fP: このシステムコールには glibc のラッパー関数は存在しない。「注意」の節を参照。 .SH 説明 \fBgetcpu\fP() システムコールは、呼び出し元のスレッドやプロセスが 現在動作しているプロセッサやノードの情報を特定し、 それぞれ引き数 \fIcpu\fP と \fInode\fP が指す整数に書き込む。 プロセッサ情報は CPU を識別するための一意な小さな整数である。 ノード情報は NUMAノードを識別するための一意な小さな整数である。 \fIcpu\fP か \fInode\fP のいずれかが NULL であれば、 その引き数に対応する情報の書き込みは行われない。 このシステムコールの 3 番目の引き数は現在は使われておらず、 Linux 2.6.23 以前への移植性が必要な場合以外は NULL を渡すべきである (「注意」を参照)。 \fIcpu\fP に格納された情報が最新だと保証できるのは、システムコールが呼ばれ た時点だけである。\fBsched_setaffinity\fP(2) を使って CPU affinity が固定 されていない限り、カーネルはいつでも CPU を変更してもよい (スケジューラ はキャッシュが有効に働くように CPU の移動を最小限にしようとするので、 通常は CPU が変更されることはないが、起きる可能性はある)。 \fIcpu\fP や \fInode\fP で返された情報が呼び出しが返った時点ですでに 最新の状況と異なる可能性があり、呼び出し元はこの可能性を考慮して おかなければならない。 .SH 返り値 成功すると、0 を返す。 エラーの場合、\-1 を返し、 \fIerrno\fP にエラーを示す値を設定する。 .SH エラー .TP \fBEFAULT\fP 引き数が呼び出したプロセスのアドレス空間外を指している。 .SH バージョン \fBgetcpu\fP() はカーネル 2.6.19 で x86_64 と i386 向けに追加された. .SH 準拠 \fBgetcpu\fP() は Linux 固有である。 .SH 注意 Linux はこのシステムコールを可能な限り早く実行しようとする。 \fBgetcpu\fP() は、CPU 毎のデータに対する最適化や NUMA 環境での最適化を プログラムが行えるようにすることを目的として実装されているからである。 glibc はこのシステムコールに対するラッパー関数を提供していない。 \fBsyscall\fP(2) を使って呼び出すか、 代わりに \fBsched_getcpu\fP(3) を使用すること。 .\" commit 4307d1e5ada595c87f9a4d16db16ba5edb70dcb1 .\" Author: Ingo Molnar .\" Date: Wed Nov 7 18:37:48 2007 +0100 .\" x86: ignore the sys_getcpu() tcache parameter .\" .\" ===== Before kernel 2.6.24: ===== .\" .I tcache .\" is a pointer to a .\" .IR "struct getcpu_cache" .\" that is used as a cache by .\" .BR getcpu (). .\" The caller should put the cache into a thread-local variable .\" if the process is multithreaded, .\" because the cache cannot be shared between different threads. .\" .I tcache .\" can be NULL. .\" If it is not NULL .\" .BR getcpu () .\" will use it to speed up operation. .\" The information inside the cache is private to the system call .\" and should not be accessed by the user program. .\" The information placed in the cache can change between kernel releases. .\" .\" When no cache is specified .\" .BR getcpu () .\" will be slower, .\" but always retrieve the current CPU and node information. .\" With a cache .\" .BR getcpu () .\" is faster. .\" However, the cached information is updated only once per jiffy (see .\" .BR time (7)). .\" This means that the information could theoretically be out of date, .\" although in practice the scheduler's attempt to maintain .\" soft CPU affinity means that the information is unlikely to change .\" over the course of the caching interval. \fItcache\fP 引き数は Linux 2.6.24 以降では使用されない。以前のバージョン のカーネルでは、この引き数が NULL 以外の場合、この引き数には、呼び出し 元が割り当てたスレッド専用の記憶領域 (thread\-local storage) 内のバッファー を指すポインターが指定され、このバッファーは \fBgetcpu\fP() 用のキャッシュ機構 を提供するために利用されていた。非常に低い確率だが古い情報を返してしま うデメリットはあるものの、このキャッシュを使うことで \fBgetcpu\fP() システ ムコールを高速化できた。このキャッシュ機構はCPU 間でのスレッドの移動時 に問題になると考えられ、この引き数は今では無視されるようになっている。 .SH 関連項目 \fBmbind\fP(2), \fBsched_setaffinity\fP(2), \fBset_mempolicy\fP(2), \fBsched_getcpu\fP(3), \fBcpuset\fP(7) .SH この文書について この man ページは Linux \fIman\-pages\fP プロジェクトのリリース 3.79 の一部 である。プロジェクトの説明とバグ報告に関する情報は http://www.kernel.org/doc/man\-pages/ に書かれている。