1SPU_RUN(2)                 Linux Programmer's Manual                SPU_RUN(2)
2
3
4

NAME

6       spu_run - execute an SPU context
7

SYNOPSIS

9       #include <sys/spu.h>          /* Definition of SPU_* constants */
10       #include <sys/syscall.h>      /* Definition of SYS_* constants */
11       #include <unistd.h>
12
13       int spu_run(int fd, uint32_t *npc, uint32_t *event);
14
15       Note: glibc provides no wrapper for spu_run(), necessitating the use of
16       syscall(2).
17

DESCRIPTION

19       The spu_run() system call is used on PowerPC  machines  that  implement
20       the  Cell  Broadband Engine Architecture in order to access Synergistic
21       Processor Units (SPUs).  The fd argument is a file descriptor  returned
22       by  spu_create(2) that refers to a specific SPU context.  When the con‐
23       text gets scheduled to a physical SPU, it starts execution at  the  in‐
24       struction pointer passed in npc.
25
26       Execution  of  SPU  code  happens synchronously, meaning that spu_run()
27       blocks while the SPU is still running.  If there is a need  to  execute
28       SPU  code  in  parallel with other code on either the main CPU or other
29       SPUs, a new thread of execution must  be  created  first  (e.g.,  using
30       pthread_create(3)).
31
32       When spu_run() returns, the current value of the SPU program counter is
33       written to npc, so successive calls to spu_run() can use the  same  npc
34       pointer.
35
36       The  event  argument provides a buffer for an extended status code.  If
37       the SPU context was created with  the  SPU_CREATE_EVENTS_ENABLED  flag,
38       then  this buffer is populated by the Linux kernel before spu_run() re‐
39       turns.
40
41       The status code may be one (or more) of the following constants:
42
43       SPE_EVENT_DMA_ALIGNMENT
44              A DMA alignment error occurred.
45
46       SPE_EVENT_INVALID_DMA
47              An invalid MFC DMA command was attempted.
48
49       SPE_EVENT_SPE_DATA_STORAGE
50              A DMA storage error occurred.
51
52       SPE_EVENT_SPE_ERROR
53              An illegal instruction was executed.
54
55       NULL is a valid value for the event argument.  In this case, the events
56       will not be reported to the calling process.
57

RETURN VALUE

59       On success, spu_run() returns the value of the spu_status register.  On
60       failure, it returns -1 and sets errno is set to indicate the error.
61
62       The spu_status register value is a bit mask of status codes and option‐
63       ally a 14-bit code returned from the stop-and-signal instruction on the
64       SPU.  The bit masks for the status codes are:
65
66       0x02   SPU was stopped by a stop-and-signal instruction.
67
68       0x04   SPU was stopped by a halt instruction.
69
70       0x08   SPU is waiting for a channel.
71
72       0x10   SPU is in single-step mode.
73
74       0x20   SPU has tried to execute an invalid instruction.
75
76       0x40   SPU has tried to access an invalid channel.
77
78       0x3fff0000
79              The bits masked with this value contain the code returned from a
80              stop-and-signal  instruction.   These bits are valid only if the
81              0x02 bit is set.
82
83       If spu_run() has not returned an error, one  or  more  bits  among  the
84       lower eight ones are always set.
85

ERRORS

87       EBADF  fd is not a valid file descriptor.
88
89       EFAULT npc  is not a valid pointer, or event is non-NULL and an invalid
90              pointer.
91
92       EINTR  A signal occurred while spu_run()  was  in  progress;  see  sig‐
93              nal(7).   The  npc  value  has  been  updated to the new program
94              counter value if necessary.
95
96       EINVAL fd is not a valid file descriptor returned from spu_create(2).
97
98       ENOMEM There was not enough memory available to handle a page fault re‐
99              sulting  from  a  Memory Flow Controller (MFC) direct memory ac‐
100              cess.
101
102       ENOSYS The functionality is not provided by the current system, because
103              either the hardware does not provide SPUs or the spufs module is
104              not loaded.
105

VERSIONS

107       The spu_run() system call was added to Linux in kernel 2.6.16.
108

CONFORMING TO

110       This call is Linux-specific and implemented only by the PowerPC  archi‐
111       tecture.  Programs using this system call are not portable.
112

NOTES

114       spu_run()  is meant to be used from libraries that implement a more ab‐
115       stract interface to SPUs, not to be  used  from  regular  applications.
116       See   ⟨http://www.bsc.es/projects/deepcomputing/linuxoncell/⟩  for  the
117       recommended libraries.
118

EXAMPLES

120       The following is an example of running a  simple,  one-instruction  SPU
121       program with the spu_run() system call.
122
123       #include <stdlib.h>
124       #include <stdint.h>
125       #include <unistd.h>
126       #include <stdio.h>
127       #include <sys/types.h>
128       #include <fcntl.h>
129
130       #define handle_error(msg) \
131           do { perror(msg); exit(EXIT_FAILURE); } while (0)
132
133       int main(void)
134       {
135           int context, fd, spu_status;
136           uint32_t instruction, npc;
137
138           context = spu_create("/spu/example-context", 0, 0755);
139           if (context == -1)
140               handle_error("spu_create");
141
142           /*
143            * Write a 'stop 0x1234' instruction to the SPU's
144            * local store memory.
145            */
146           instruction = 0x00001234;
147
148           fd = open("/spu/example-context/mem", O_RDWR);
149           if (fd == -1)
150               handle_error("open");
151           write(fd, &instruction, sizeof(instruction));
152
153           /*
154            * set npc to the starting instruction address of the
155            * SPU program. Since we wrote the instruction at the
156            * start of the mem file, the entry point will be 0x0.
157            */
158           npc = 0;
159
160           spu_status = spu_run(context, &npc, NULL);
161           if (spu_status == -1)
162               handle_error("open");
163
164           /*
165            * We should see a status code of 0x1234002:
166            *   0x00000002 (spu was stopped due to stop-and-signal)
167            * | 0x12340000 (the stop-and-signal code)
168            */
169           printf("SPU Status: %#08x\n", spu_status);
170
171           exit(EXIT_SUCCESS);
172       }
173

SEE ALSO

175       close(2), spu_create(2), capabilities(7), spufs(7)
176

COLOPHON

178       This  page  is  part of release 5.13 of the Linux man-pages project.  A
179       description of the project, information about reporting bugs,  and  the
180       latest     version     of     this    page,    can    be    found    at
181       https://www.kernel.org/doc/man-pages/.
182
183
184
185Linux                             2021-03-22                        SPU_RUN(2)
Impressum