1 .\" Copyright (c) International Business Machines Corp., 2006
3 .\" This program is free software; you can redistribute it and/or
4 .\" modify it under the terms of the GNU General Public License as
5 .\" published by the Free Software Foundation; either version 2 of
6 .\" the License, or (at your option) any later version.
8 .\" This program is distributed in the hope that it will be useful,
9 .\" but WITHOUT ANY WARRANTY; without even the implied warranty of
10 .\" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
11 .\" the GNU General Public License for more details.
13 .\" You should have received a copy of the GNU General Public License
14 .\" along with this program; if not, write to the Free Software
15 .\" Foundation, Inc., 59 Temple Place, Suite 330, Boston,
19 .\" 2005-09-28, created by Arnd Bergmann <arndb@de.ibm.com>
20 .\" 2006-06-16, revised by Eduardo M. Fleury <efleury@br.ibm.com>
21 .\" 2007-07-10, some polishing by mtk
22 .\" 2007-09-28, updates for newer kernels, added example
23 .\" by Jeremy Kerr <jk@ozlabs.org>
25 .\"*******************************************************************
27 .\" This file was generated with po4a. Translate the source file.
29 .\"*******************************************************************
30 .TH SPU_RUN 2 2007\-11\-25 Linux "Linux Programmer's Manual"
32 spu_run \- SPU コンテキストを実行する
35 \fB#include <sys/spu.h>\fP
37 \fBint spu_run(int \fP\fIfd\fP\fB, unsigned int *\fP\fInpc\fP\fB, unsigned int *\fP\fIevent\fP\fB);\fP
40 \fBspu_run\fP() システムコールは、Cell Broadband Engine アーキテクチャを実装した PowerPC マシンで
41 Synergistic Processor Units (SPU) にアクセスするために 使用される。 \fIfd\fP 引き数は、
42 \fBspu_create\fP(2) が返すファイルディスクリプタで、 特定の SPU コンテキストを参照する。 そのコンテキストが物理 SPU
43 に割り当てられると、 \fInpc\fP で渡された命令ポインタ (instruction pointer) から実行が開始される。
45 SPU コードの実行は同期的 (synchronously) に行われる、つまり SPU が実行中は \fBspu_run\fP() は停止 (block)
46 する。 SPU コードの実行をメイン CPU や他の SPU と並行して行う必要がある場合は、 最初に、その SPU
47 コードを実行する新しいスレッドを、(例えば \fBpthread_create\fP(3) などを使って) 生成しなければならない。
49 \fBspu_run\fP() が返るときには、SPU のプログラムカウンタの現在値が \fInpc\fP に書き込まれる。 これにより、連続する
50 \fBspu_run\fP() の呼び出しで同じ \fInpc\fP ポインタを使うことができる。
52 \fIevent\fP 引き数には、拡張ステータスコード用のバッファを指定する。 \fBSPU_CREATE_EVENTS_ENABLED\fP フラグ付きで
53 SPU コンテキストが作成されると、 \fBspu_run\fP() が返る前に Linux カーネルによりこのバッファに
56 ステータスコードには以下の定数が一つ以上入る。
58 \fBSPE_EVENT_DMA_ALIGNMENT\fP
59 DMA (direct memory access) のアライメント・エラーが発生した。
61 \fBSPE_EVENT_INVALID_DMA\fP
62 無効な MFC (Memory Flow Controller) DMA コマンドを行おうとした。
64 \fBSPE_EVENT_SPE_DATA_STORAGE\fP
67 \fBSPE_EVENT_SPE_ERROR\fP
70 NULL は \fIevent\fP 引き数として有効な値である。 この場合、イベントは呼び出し元のプロセスに報告されない。
72 成功すると、 \fBspu_run\fP() は \fIspu_status\fP レジスタの値を返す。 エラーの場合、\-1 を返し、 \fIerrno\fP
75 \fIspu_status\fP レジスタの値は、ステータスコードと SPU の \fBstop\-and\-signal\fP 命令が返す 14 ビットのコードの
76 ビットマスクで構成される。 後者の 14 ビットのコードはオプションである。 ステータスコードのビットマスクは下記の通りである。
79 SPU が \fBstop\-and\-signal\fP 命令で停止した。
82 SPU が \fBhalt (停止)\fP 命令で止まった。
94 SPU が不正なチャンネルにアクセスしようとした。
97 この値のマスクを適用して得られたビット値には、 stop\-and\-signal 命令から返されたコードが入っている。 これらのビットは 0x02
98 ビットがセットされている場合にのみ有効である。
100 \fBspu_run\fP() がエラーを返さなかった場合、下位 8 ビットのうち 1 つ以上は 常にセットされる。
104 \fIfd\fP が有効なファイルディスクリプタでない。
107 \fInpc\fP が有効なポインタでない。または \fIevent\fP が NULL 以外で、しかも無効なポインタである。
110 \fBspu_run\fP() の実行中にシグナルが発生した。 \fBsignal\fP(7) 参照。 必要であれば、 \fInpc\fP
111 の値は新しいプログラムカウンタの値に更新される。
114 \fIfd\fP が \fBspu_create\fP(2) が返した有効なファイルディスクリプタでない。
117 Memory Flow Controller (MFC) DMA により発生したページフォールトを 処理するのに必要なメモリがなかった。
120 機能が動作中のシステムで提供されていない。理由は、 ハードウェアで SPU が提供されていないか、 spufs
121 モジュールがロードされていないか、のどちらかである。
123 \fBspu_run\fP() システムコールはカーネル 2.6.16 で Linux に追加された。
125 このシステムコールは Linux 固有であり、 PowerPC アーキテクチャでのみ実装されている。
126 このシステムコールを使ったプログラムは移植性がない。
128 glibc はこのシステムコールに対するラッパー関数を提供していない。 \fBsyscall\fP(2) を使うこと。ただし、 \fBspu_run\fP()
129 は より抽象度の高い SPU へのインタフェースを実装するライブラリから 利用されることを意図したものであり、通常のアプリケーションから
130 使用は意図されていない。推奨のライブラリについては
131 \fIhttp://www.bsc.es/projects/deepcomputing/linuxoncell/\fP を参照のこと。
133 以下は、簡単な 1 命令の SPU プログラムを \fBspu_run\fP() システムコールを使って実行させる例である。
140 #include <sys/types.h>
143 #define handle_error(msg) \e
144 do { perror(msg); exit(EXIT_FAILURE); } while (0)
148 int context, fd, spu_status;
149 uint32_t instruction, npc;
151 context = spu_create("/spu/example\-context", 0, 0755);
153 handle_error("spu_create");
155 /* write a \(aqstop 0x1234\(aq instruction to the SPU\(aqs
158 instruction = 0x00001234;
160 fd = open("/spu/example\-context/mem", O_RDWR);
162 handle_error("open");
163 write(fd, &instruction, sizeof(instruction));
165 /* set npc to the starting instruction address of the
166 * SPU program. Since we wrote the instruction at the
167 * start of the mem file, the entry point will be 0x0
171 spu_status = spu_run(context, &npc, NULL);
172 if (spu_status == \-1)
173 handle_error("open");
175 /* we should see a status code of 0x1234002:
176 * 0x00000002 (spu was stopped due to stop\-and\-signal)
177 * | 0x12340000 (the stop\-and\-signal code)
179 printf("SPU Status: 0x%08x\en", spu_status);
185 .\" Arnd Bergmann <arndb@de.ibm.com>, Jeremy Kerr <jk@ozlabs.org>
187 \fBclose\fP(2), \fBspu_create\fP(2), \fBcapabilities\fP(7), \fBspufs\fP(7)