man-pages/man2/spu_run.2.html
2021-03-31 01:06:50 +01:00

379 lines
9.6 KiB
HTML

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML><HEAD><TITLE>Man page of SPU_RUN</TITLE>
</HEAD><BODY>
<H1>SPU_RUN</H1>
Section: Linux Programmer's Manual (2)<BR>Updated: 2019-03-06<BR><A HREF="#index">Index</A>
<A HREF="/cgi-bin/man/man2html">Return to Main Contents</A><HR>
<A NAME="lbAB">&nbsp;</A>
<H2>NAME</H2>
spu_run - execute an SPU context
<A NAME="lbAC">&nbsp;</A>
<H2>SYNOPSIS</H2>
<PRE>
<B>#include &lt;<A HREF="file:///usr/include/sys/spu.h">sys/spu.h</A>&gt;</B>
<B>int spu_run(int </B><I>fd</I><B>, unsigned int *</B><I>npc</I><B>, unsigned int *</B><I>event</I><B>);</B>
</PRE>
<P>
<I>Note</I>:
There is no glibc wrapper for this system call; see NOTES.
<A NAME="lbAD">&nbsp;</A>
<H2>DESCRIPTION</H2>
The
<B>spu_run</B>()
system call is used on PowerPC machines that implement the
Cell Broadband Engine Architecture in order to access Synergistic
Processor Units (SPUs).
The
<I>fd</I>
argument is a file descriptor returned by
<B><A HREF="/cgi-bin/man/man2html?2+spu_create">spu_create</A></B>(2)
that refers to a specific SPU context.
When the context gets scheduled to a physical SPU,
it starts execution at the instruction pointer passed in
<I>npc</I>.
<P>
Execution of SPU code happens synchronously, meaning that
<B>spu_run</B>()
blocks while the SPU is still running.
If there is a need
to execute SPU code in parallel with other code on either the
main CPU or other SPUs, a new thread of execution must be created
first (e.g., using
<B><A HREF="/cgi-bin/man/man2html?3+pthread_create">pthread_create</A></B>(3)).
<P>
When
<B>spu_run</B>()
returns, the current value of the SPU program counter is written to
<I>npc</I>,
so successive calls to
<B>spu_run</B>()
can use the same
<I>npc</I>
pointer.
<P>
The
<I>event</I>
argument provides a buffer for an extended status code.
If the SPU
context was created with the
<B>SPU_CREATE_EVENTS_ENABLED</B>
flag, then this buffer is populated by the Linux kernel before
<B>spu_run</B>()
returns.
<P>
The status code may be one (or more) of the following constants:
<DL COMPACT>
<DT id="1"><B>SPE_EVENT_DMA_ALIGNMENT</B>
<DD>
A DMA alignment error occurred.
<DT id="2"><B>SPE_EVENT_INVALID_DMA</B>
<DD>
An invalid MFC DMA command was attempted.
<DT id="3"><B>SPE_EVENT_SPE_DATA_STORAGE</B>
<DD>
A DMA storage error occurred.
<DT id="4"><B>SPE_EVENT_SPE_ERROR</B>
<DD>
An illegal instruction was executed.
</DL>
<P>
NULL
is a valid value for the
<I>event</I>
argument.
In this case, the events will not be reported to the calling process.
<A NAME="lbAE">&nbsp;</A>
<H2>RETURN VALUE</H2>
On success,
<B>spu_run</B>()
returns the value of the
<I>spu_status</I>
register.
On error, it returns -1 and sets
<I>errno</I>
to one of the error codes listed below.
<P>
The
<I>spu_status</I>
register value is a bit mask of status codes and
optionally a 14-bit code returned from the
<B>stop-and-signal</B>
instruction on the SPU.
The bit masks for the status codes
are:
<DL COMPACT>
<DT id="5"><B>0x02</B>
<DD>
SPU was stopped by a
<B>stop-and-signal</B>
instruction.
<DT id="6"><B>0x04</B>
<DD>
SPU was stopped by a
<B>halt</B>
instruction.
<DT id="7"><B>0x08</B>
<DD>
SPU is waiting for a channel.
<DT id="8"><B>0x10</B>
<DD>
SPU is in single-step mode.
<DT id="9"><B>0x20</B>
<DD>
SPU has tried to execute an invalid instruction.
<DT id="10"><B>0x40</B>
<DD>
SPU has tried to access an invalid channel.
<DT id="11"><B>0x3fff0000</B>
<DD>
The bits masked with this value contain the code returned from a
<B>stop-and-signal</B>
instruction.
These bits are valid only if the 0x02 bit is set.
</DL>
<P>
If
<B>spu_run</B>()
has not returned an error, one or more bits among the lower eight
ones are always set.
<A NAME="lbAF">&nbsp;</A>
<H2>ERRORS</H2>
<DL COMPACT>
<DT id="12"><B>EBADF</B>
<DD>
<I>fd</I>
is not a valid file descriptor.
<DT id="13"><B>EFAULT</B>
<DD>
<I>npc</I>
is not a valid pointer, or
<I>event</I>
is non-NULL and an invalid pointer.
<DT id="14"><B>EINTR</B>
<DD>
A signal occurred while
<B>spu_run</B>()
was in progress; see
<B><A HREF="/cgi-bin/man/man2html?7+signal">signal</A></B>(7).
The
<I>npc</I>
value has been updated to the new program counter value if
necessary.
<DT id="15"><B>EINVAL</B>
<DD>
<I>fd</I>
is not a valid file descriptor returned from
<B><A HREF="/cgi-bin/man/man2html?2+spu_create">spu_create</A></B>(2).
<DT id="16"><B>ENOMEM</B>
<DD>
There was not enough memory available to handle a page fault
resulting from a Memory Flow Controller (MFC) direct memory access.
<DT id="17"><B>ENOSYS</B>
<DD>
The functionality is not provided by the current system, because
either the hardware does not provide SPUs or the spufs module is not
loaded.
</DL>
<A NAME="lbAG">&nbsp;</A>
<H2>VERSIONS</H2>
The
<B>spu_run</B>()
system call was added to Linux in kernel 2.6.16.
<A NAME="lbAH">&nbsp;</A>
<H2>CONFORMING TO</H2>
This call is Linux-specific and implemented only by the PowerPC
architecture.
Programs using this system call are not portable.
<A NAME="lbAI">&nbsp;</A>
<H2>NOTES</H2>
Glibc does not provide a wrapper for this system call; call it using
<B><A HREF="/cgi-bin/man/man2html?2+syscall">syscall</A></B>(2).
Note however, that
<B>spu_run</B>()
is meant to be used from libraries that implement a more abstract
interface to SPUs, not to be used from regular applications.
See
for the recommended libraries.
<A NAME="lbAJ">&nbsp;</A>
<H2>EXAMPLE</H2>
The following is an example of running a simple, one-instruction SPU
program with the
<B>spu_run</B>()
system call.
<P>
#include &lt;<A HREF="file:///usr/include/stdlib.h">stdlib.h</A>&gt;
#include &lt;<A HREF="file:///usr/include/stdint.h">stdint.h</A>&gt;
#include &lt;<A HREF="file:///usr/include/unistd.h">unistd.h</A>&gt;
#include &lt;<A HREF="file:///usr/include/stdio.h">stdio.h</A>&gt;
#include &lt;<A HREF="file:///usr/include/sys/types.h">sys/types.h</A>&gt;
#include &lt;<A HREF="file:///usr/include/fcntl.h">fcntl.h</A>&gt;
<P>
#define handle_error(msg) \
<BR>&nbsp;&nbsp;&nbsp;&nbsp;do&nbsp;{&nbsp;perror(msg);&nbsp;exit(EXIT_FAILURE);&nbsp;}&nbsp;while&nbsp;(0)
<P>
int main(void)
{
<BR>&nbsp;&nbsp;&nbsp;&nbsp;int&nbsp;context,&nbsp;fd,&nbsp;spu_status;
<BR>&nbsp;&nbsp;&nbsp;&nbsp;uint32_t&nbsp;instruction,&nbsp;npc;
<P>
<BR>&nbsp;&nbsp;&nbsp;&nbsp;context&nbsp;=&nbsp;spu_create(&quot;/spu/example-context&quot;,&nbsp;0,&nbsp;0755);
<BR>&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;(context&nbsp;==&nbsp;-1)
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;handle_error(&quot;spu_create&quot;);
<P>
<BR>&nbsp;&nbsp;&nbsp;&nbsp;/*&nbsp;write&nbsp;a&nbsp;'stop&nbsp;0x1234'&nbsp;instruction&nbsp;to&nbsp;the&nbsp;SPU's
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;local&nbsp;store&nbsp;memory
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*/
<BR>&nbsp;&nbsp;&nbsp;&nbsp;instruction&nbsp;=&nbsp;0x00001234;
<P>
<BR>&nbsp;&nbsp;&nbsp;&nbsp;fd&nbsp;=&nbsp;open(&quot;/spu/example-context/mem&quot;,&nbsp;O_RDWR);
<BR>&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;(fd&nbsp;==&nbsp;-1)
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;handle_error(&quot;open&quot;);
<BR>&nbsp;&nbsp;&nbsp;&nbsp;write(fd,&nbsp;&amp;instruction,&nbsp;sizeof(instruction));
<P>
<BR>&nbsp;&nbsp;&nbsp;&nbsp;/*&nbsp;set&nbsp;npc&nbsp;to&nbsp;the&nbsp;starting&nbsp;instruction&nbsp;address&nbsp;of&nbsp;the
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;SPU&nbsp;program.&nbsp;Since&nbsp;we&nbsp;wrote&nbsp;the&nbsp;instruction&nbsp;at&nbsp;the
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;start&nbsp;of&nbsp;the&nbsp;mem&nbsp;file,&nbsp;the&nbsp;entry&nbsp;point&nbsp;will&nbsp;be&nbsp;0x0
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*/
<BR>&nbsp;&nbsp;&nbsp;&nbsp;npc&nbsp;=&nbsp;0;
<P>
<BR>&nbsp;&nbsp;&nbsp;&nbsp;spu_status&nbsp;=&nbsp;spu_run(context,&nbsp;&amp;npc,&nbsp;NULL);
<BR>&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;(spu_status&nbsp;==&nbsp;-1)
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;handle_error(&quot;open&quot;);
<P>
<BR>&nbsp;&nbsp;&nbsp;&nbsp;/*&nbsp;we&nbsp;should&nbsp;see&nbsp;a&nbsp;status&nbsp;code&nbsp;of&nbsp;0x1234002:
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;&nbsp;&nbsp;0x00000002&nbsp;(spu&nbsp;was&nbsp;stopped&nbsp;due&nbsp;to&nbsp;stop-and-signal)
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;|&nbsp;0x12340000&nbsp;(the&nbsp;stop-and-signal&nbsp;code)
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*/
<BR>&nbsp;&nbsp;&nbsp;&nbsp;printf(&quot;SPU&nbsp;Status:&nbsp;0x%08x\n&quot;,&nbsp;spu_status);
<P>
<BR>&nbsp;&nbsp;&nbsp;&nbsp;exit(EXIT_SUCCESS);
}
<A NAME="lbAK">&nbsp;</A>
<H2>SEE ALSO</H2>
<B><A HREF="/cgi-bin/man/man2html?2+close">close</A></B>(2),
<B><A HREF="/cgi-bin/man/man2html?2+spu_create">spu_create</A></B>(2),
<B><A HREF="/cgi-bin/man/man2html?7+capabilities">capabilities</A></B>(7),
<B><A HREF="/cgi-bin/man/man2html?7+spufs">spufs</A></B>(7)
<A NAME="lbAL">&nbsp;</A>
<H2>COLOPHON</H2>
This page is part of release 5.05 of the Linux
<I>man-pages</I>
project.
A description of the project,
information about reporting bugs,
and the latest version of this page,
can be found at
<A HREF="https://www.kernel.org/doc/man-pages/.">https://www.kernel.org/doc/man-pages/.</A>
<P>
<HR>
<A NAME="index">&nbsp;</A><H2>Index</H2>
<DL>
<DT id="18"><A HREF="#lbAB">NAME</A><DD>
<DT id="19"><A HREF="#lbAC">SYNOPSIS</A><DD>
<DT id="20"><A HREF="#lbAD">DESCRIPTION</A><DD>
<DT id="21"><A HREF="#lbAE">RETURN VALUE</A><DD>
<DT id="22"><A HREF="#lbAF">ERRORS</A><DD>
<DT id="23"><A HREF="#lbAG">VERSIONS</A><DD>
<DT id="24"><A HREF="#lbAH">CONFORMING TO</A><DD>
<DT id="25"><A HREF="#lbAI">NOTES</A><DD>
<DT id="26"><A HREF="#lbAJ">EXAMPLE</A><DD>
<DT id="27"><A HREF="#lbAK">SEE ALSO</A><DD>
<DT id="28"><A HREF="#lbAL">COLOPHON</A><DD>
</DL>
<HR>
This document was created by
<A HREF="/cgi-bin/man/man2html">man2html</A>,
using the manual pages.<BR>
Time: 00:05:34 GMT, March 31, 2021
</BODY>
</HTML>