libspe2  0.9a
Data Structures | Macros | Enumerations | Functions
spebase.h File Reference
#include <pthread.h>
#include "libspe2-types.h"
Include dependency graph for spebase.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  spe_context_base_priv
 
struct  spe_gang_context_base_priv
 

Macros

#define __PRINTF(fmt, args...)   { fprintf(stderr,fmt , ## args); }
 
#define DEBUG_PRINTF(fmt, args...)
 
#define LS_SIZE   0x40000 /* 256K (in bytes) */
 
#define PSMAP_SIZE   0x20000 /* 128K (in bytes) */
 
#define MFC_SIZE   0x1000
 
#define MSS_SIZE   0x1000
 
#define CNTL_SIZE   0x1000
 
#define SIGNAL_SIZE   0x1000
 
#define MSSYNC_OFFSET   0x00000
 
#define MFC_OFFSET   0x03000
 
#define CNTL_OFFSET   0x04000
 
#define SIGNAL1_OFFSET   0x14000
 
#define SIGNAL2_OFFSET   0x1c000
 
#define SPE_EMULATE_PARAM_BUFFER   0x3e000
 
#define SPE_PROGRAM_NORMAL_END   0x2000
 
#define SPE_PROGRAM_LIBRARY_CALL   0x2100
 
#define SPE_PROGRAM_ISOLATED_STOP   0x2200
 
#define SPE_PROGRAM_ISO_LOAD_COMPLETE   0x2206
 

Enumerations

enum  fd_name {
  FD_MBOX, FD_MBOX_STAT, FD_IBOX, FD_IBOX_NB,
  FD_IBOX_STAT, FD_WBOX, FD_WBOX_NB, FD_WBOX_STAT,
  FD_SIG1, FD_SIG2, FD_MFC, FD_MSS,
  NUM_MBOX_FDS
}
 

Functions

spe_context_ptr_t _base_spe_context_create (unsigned int flags, spe_gang_context_ptr_t gctx, spe_context_ptr_t aff_spe)
 
spe_gang_context_ptr_t _base_spe_gang_context_create (unsigned int flags)
 
int _base_spe_program_load (spe_context_ptr_t spectx, spe_program_handle_t *program)
 
void _base_spe_program_load_complete (spe_context_ptr_t spectx)
 
int _base_spe_emulated_loader_present (void)
 
int _base_spe_context_destroy (spe_context_ptr_t spectx)
 
int _base_spe_gang_context_destroy (spe_gang_context_ptr_t gctx)
 
int _base_spe_context_run (spe_context_ptr_t spe, unsigned int *entry, unsigned int runflags, void *argp, void *envp, spe_stop_info_t *stopinfo)
 
int _base_spe_image_close (spe_program_handle_t *handle)
 
spe_program_handle_t_base_spe_image_open (const char *filename)
 
int _base_spe_mfcio_put (spe_context_ptr_t spectx, unsigned int ls, void *ea, unsigned int size, unsigned int tag, unsigned int tid, unsigned int rid)
 
int _base_spe_mfcio_putb (spe_context_ptr_t spectx, unsigned int ls, void *ea, unsigned int size, unsigned int tag, unsigned int tid, unsigned int rid)
 
int _base_spe_mfcio_putf (spe_context_ptr_t spectx, unsigned int ls, void *ea, unsigned int size, unsigned int tag, unsigned int tid, unsigned int rid)
 
int _base_spe_mfcio_get (spe_context_ptr_t spectx, unsigned int ls, void *ea, unsigned int size, unsigned int tag, unsigned int tid, unsigned int rid)
 
int _base_spe_mfcio_getb (spe_context_ptr_t spectx, unsigned int ls, void *ea, unsigned int size, unsigned int tag, unsigned int tid, unsigned int rid)
 
int _base_spe_mfcio_getf (spe_context_ptr_t spectx, unsigned int ls, void *ea, unsigned int size, unsigned int tag, unsigned int tid, unsigned int rid)
 
int _base_spe_out_mbox_read (spe_context_ptr_t spectx, unsigned int mbox_data[], int count)
 
int _base_spe_in_mbox_write (spe_context_ptr_t spectx, unsigned int mbox_data[], int count, int behavior_flag)
 
int _base_spe_in_mbox_status (spe_context_ptr_t spectx)
 
int _base_spe_out_mbox_status (spe_context_ptr_t spectx)
 
int _base_spe_out_intr_mbox_status (spe_context_ptr_t spectx)
 
int _base_spe_out_intr_mbox_read (spe_context_ptr_t spectx, unsigned int mbox_data[], int count, int behavior_flag)
 
int _base_spe_signal_write (spe_context_ptr_t spectx, unsigned int signal_reg, unsigned int data)
 
int _base_spe_callback_handler_register (void *handler, unsigned int callnum, unsigned int mode)
 
int _base_spe_callback_handler_deregister (unsigned int callnum)
 
void * _base_spe_callback_handler_query (unsigned int callnum)
 
int _base_spe_stop_reason_get (spe_context_ptr_t spectx)
 
int _base_spe_mfcio_tag_status_read (spe_context_ptr_t spectx, unsigned int mask, unsigned int behavior, unsigned int *tag_status)
 
int __base_spe_stop_event_source_get (spe_context_ptr_t spectx)
 
int __base_spe_stop_event_target_get (spe_context_ptr_t spectx)
 
int _base_spe_stop_status_get (spe_context_ptr_t spectx)
 
int __base_spe_event_source_acquire (struct spe_context *spectx, enum fd_name fdesc)
 
void __base_spe_event_source_release (struct spe_context *spectx, enum fd_name fdesc)
 
void * _base_spe_ps_area_get (struct spe_context *spectx, enum ps_area area)
 
int __base_spe_spe_dir_get (struct spe_context *spectx)
 
void * _base_spe_ls_area_get (struct spe_context *spectx)
 
int _base_spe_ls_size_get (spe_context_ptr_t spe)
 
void _base_spe_context_lock (spe_context_ptr_t spe, enum fd_name fd)
 
void _base_spe_context_unlock (spe_context_ptr_t spe, enum fd_name fd)
 
int _base_spe_cpu_info_get (int info_requested, int cpu_node)
 
void __spe_context_update_event (void)
 
int _base_spe_mssync_start (spe_context_ptr_t spectx)
 
int _base_spe_mssync_status (spe_context_ptr_t spectx)
 

Detailed Description

spebase.h contains the public API funtions

Definition in file spebase.h.

Macro Definition Documentation

#define __PRINTF (   fmt,
  args... 
)    { fprintf(stderr,fmt , ## args); }

Definition at line 34 of file spebase.h.

#define CNTL_OFFSET   0x04000

Definition at line 124 of file spebase.h.

Referenced by _base_spe_context_create().

#define CNTL_SIZE   0x1000

Definition at line 119 of file spebase.h.

Referenced by _base_spe_context_create().

#define DEBUG_PRINTF (   fmt,
  args... 
)

Definition at line 38 of file spebase.h.

#define LS_SIZE   0x40000 /* 256K (in bytes) */

Definition at line 115 of file spebase.h.

#define MFC_OFFSET   0x03000

Definition at line 123 of file spebase.h.

Referenced by _base_spe_context_create().

#define MFC_SIZE   0x1000

Definition at line 117 of file spebase.h.

Referenced by _base_spe_context_create().

#define MSS_SIZE   0x1000

Definition at line 118 of file spebase.h.

Referenced by _base_spe_context_create().

#define MSSYNC_OFFSET   0x00000

Definition at line 122 of file spebase.h.

Referenced by _base_spe_context_create().

#define PSMAP_SIZE   0x20000 /* 128K (in bytes) */

Definition at line 116 of file spebase.h.

Referenced by _base_spe_context_create().

#define SIGNAL1_OFFSET   0x14000

Definition at line 125 of file spebase.h.

Referenced by _base_spe_context_create().

#define SIGNAL2_OFFSET   0x1c000

Definition at line 126 of file spebase.h.

Referenced by _base_spe_context_create().

#define SIGNAL_SIZE   0x1000

Definition at line 120 of file spebase.h.

Referenced by _base_spe_context_create().

#define SPE_EMULATE_PARAM_BUFFER   0x3e000

Location of the PPE-assisted library call buffer for emulated isolation contexts.

Definition at line 132 of file spebase.h.

Referenced by _base_spe_handle_library_callback().

#define SPE_PROGRAM_ISO_LOAD_COMPLETE   0x2206

Definition at line 143 of file spebase.h.

Referenced by _base_spe_context_run().

#define SPE_PROGRAM_ISOLATED_STOP   0x2200

Isolated exit codes: 0x220x

Definition at line 142 of file spebase.h.

Referenced by _base_spe_context_run().

#define SPE_PROGRAM_LIBRARY_CALL   0x2100

Definition at line 137 of file spebase.h.

Referenced by _base_spe_context_run().

#define SPE_PROGRAM_NORMAL_END   0x2000

Definition at line 136 of file spebase.h.

Referenced by _base_spe_context_run().

Enumeration Type Documentation

enum fd_name

NOTE: NUM_MBOX_FDS must always be the last element in the enumeration

Enumerator
FD_MBOX 
FD_MBOX_STAT 
FD_IBOX 
FD_IBOX_NB 
FD_IBOX_STAT 
FD_WBOX 
FD_WBOX_NB 
FD_WBOX_STAT 
FD_SIG1 
FD_SIG2 
FD_MFC 
FD_MSS 
NUM_MBOX_FDS 

Definition at line 42 of file spebase.h.

42  {
43  FD_MBOX,
45  FD_IBOX,
46  FD_IBOX_NB,
48  FD_WBOX,
49  FD_WBOX_NB,
51  FD_SIG1,
52  FD_SIG2,
53  FD_MFC,
54  FD_MSS,
56 };
Definition: spebase.h:53
Definition: spebase.h:54

Function Documentation

int __base_spe_event_source_acquire ( struct spe_context spectx,
enum fd_name  fdesc 
)

__base_spe_event_source_acquire opens a file descriptor to the specified event source

Parameters
spectxSpecifies the SPE context
fdescSpecifies the event source
void __base_spe_event_source_release ( struct spe_context spectx,
enum fd_name  fdesc 
)

__base_spe_event_source_release releases the file descriptor to the specified event source

Parameters
spectxSpecifies the SPE context
fdescSpecifies the event source

Definition at line 79 of file accessors.c.

References _base_spe_close_if_open().

80 {
81  _base_spe_close_if_open(spe, fdesc);
82 }
void _base_spe_close_if_open(struct spe_context *spe, enum fd_name fdesc)
Definition: create.c:125

Here is the call graph for this function:

int __base_spe_spe_dir_get ( struct spe_context spectx)

__base_spe_spe_dir_get return the file descriptor of the SPE directory in spufs

Parameters
spectxSpecifies the SPE context
int __base_spe_stop_event_source_get ( spe_context_ptr_t  spe)

__base_spe_stop_event_source_get

Parameters
spectxSpecifies the SPE context

speevent users read from this end

Definition at line 92 of file accessors.c.

References spe_context::base_private, and spe_context_base_priv::ev_pipe.

93 {
94  return spe->base_private->ev_pipe[1];
95 }
struct spe_context_base_priv * base_private
Definition: libspe2-types.h:76
int __base_spe_stop_event_target_get ( spe_context_ptr_t  spe)

__base_spe_stop_event_target_get

Parameters
spectxSpecifies the SPE context

speevent writes to this end

Definition at line 100 of file accessors.c.

References spe_context::base_private, and spe_context_base_priv::ev_pipe.

101 {
102  return spe->base_private->ev_pipe[0];
103 }
struct spe_context_base_priv * base_private
Definition: libspe2-types.h:76
void __spe_context_update_event ( void  )

__spe_context_update_event internal function for gdb notification.

Referenced by _base_spe_context_destroy(), and _base_spe_program_load_complete().

int _base_spe_callback_handler_deregister ( unsigned int  callnum)

unregister a handler function for the specified number NOTE: unregistering a handler from call zero and one is ignored.

Definition at line 78 of file lib_builtin.c.

References MAX_CALLNUM, and RESERVED.

79 {
80  errno = 0;
81  if (callnum > MAX_CALLNUM) {
82  errno = EINVAL;
83  return -1;
84  }
85  if (callnum < RESERVED) {
86  errno = EACCES;
87  return -1;
88  }
89  if (handlers[callnum] == NULL) {
90  errno = ESRCH;
91  return -1;
92  }
93 
94  handlers[callnum] = NULL;
95  return 0;
96 }
#define MAX_CALLNUM
Definition: lib_builtin.h:25
#define RESERVED
Definition: lib_builtin.h:26
void* _base_spe_callback_handler_query ( unsigned int  callnum)

query a handler function for the specified number

Definition at line 98 of file lib_builtin.c.

References MAX_CALLNUM.

99 {
100  errno = 0;
101 
102  if (callnum > MAX_CALLNUM) {
103  errno = EINVAL;
104  return NULL;
105  }
106  if (handlers[callnum] == NULL) {
107  errno = ESRCH;
108  return NULL;
109  }
110  return handlers[callnum];
111 }
#define MAX_CALLNUM
Definition: lib_builtin.h:25
int _base_spe_callback_handler_register ( void *  handler,
unsigned int  callnum,
unsigned int  mode 
)

register a handler function for the specified number NOTE: registering a handler to call zero and one is ignored.

Definition at line 40 of file lib_builtin.c.

References MAX_CALLNUM, RESERVED, SPE_CALLBACK_NEW, and SPE_CALLBACK_UPDATE.

41 {
42  errno = 0;
43 
44  if (callnum > MAX_CALLNUM) {
45  errno = EINVAL;
46  return -1;
47  }
48 
49  switch(mode){
50  case SPE_CALLBACK_NEW:
51  if (callnum < RESERVED) {
52  errno = EACCES;
53  return -1;
54  }
55  if (handlers[callnum] != NULL) {
56  errno = EACCES;
57  return -1;
58  }
59  handlers[callnum] = handler;
60  break;
61 
63  if (handlers[callnum] == NULL) {
64  errno = ESRCH;
65  return -1;
66  }
67  handlers[callnum] = handler;
68  break;
69  default:
70  errno = EINVAL;
71  return -1;
72  break;
73  }
74  return 0;
75 
76 }
#define MAX_CALLNUM
Definition: lib_builtin.h:25
#define SPE_CALLBACK_NEW
#define RESERVED
Definition: lib_builtin.h:26
#define SPE_CALLBACK_UPDATE
spe_context_ptr_t _base_spe_context_create ( unsigned int  flags,
spe_gang_context_ptr_t  gctx,
spe_context_ptr_t  aff_spe 
)

_base_spe_context_create creates a single SPE context, i.e., the corresponding directory is created in SPUFS either as a subdirectory of a gang or individually (maybe this is best considered a gang of one)

Parameters
flags
gctxspecify NULL if not belonging to a gang
aff_spespecify NULL to skip affinity information

Definition at line 183 of file create.c.

References _base_spe_emulated_loader_present(), spe_context::base_private, spe_gang_context::base_private, spe_context_base_priv::cntl_mmap_base, CNTL_OFFSET, CNTL_SIZE, DEBUG_PRINTF, spe_context_base_priv::fd_lock, spe_context_base_priv::fd_spe_dir, spe_context_base_priv::flags, spe_gang_context_base_priv::gangname, spe_context_base_priv::loaded_program, LS_SIZE, spe_context_base_priv::mem_mmap_base, spe_context_base_priv::mfc_mmap_base, MFC_OFFSET, MFC_SIZE, MSS_SIZE, spe_context_base_priv::mssync_mmap_base, MSSYNC_OFFSET, NUM_MBOX_FDS, spe_context_base_priv::psmap_mmap_base, PSMAP_SIZE, spe_context_base_priv::signal1_mmap_base, SIGNAL1_OFFSET, spe_context_base_priv::signal2_mmap_base, SIGNAL2_OFFSET, SIGNAL_SIZE, SPE_AFFINITY_MEMORY, SPE_CFG_SIGNOTIFY1_OR, SPE_CFG_SIGNOTIFY2_OR, SPE_EVENTS_ENABLE, spe_context_base_priv::spe_fds_array, SPE_ISOLATE, SPE_ISOLATE_EMULATE, and SPE_MAP_PS.

185 {
186  char pathname[256];
187  int i, aff_spe_fd = 0;
188  unsigned int spu_createflags = 0;
189  struct spe_context *spe = NULL;
190  struct spe_context_base_priv *priv;
191 
192  /* We need a loader present to run in emulated isolated mode */
195  errno = EINVAL;
196  return NULL;
197  }
198 
199  /* Put some sane defaults into the SPE context */
200  spe = malloc(sizeof(*spe));
201  if (!spe) {
202  DEBUG_PRINTF("ERROR: Could not allocate spe context.\n");
203  return NULL;
204  }
205  memset(spe, 0, sizeof(*spe));
206 
207  spe->base_private = malloc(sizeof(*spe->base_private));
208  if (!spe->base_private) {
209  DEBUG_PRINTF("ERROR: Could not allocate "
210  "spe->base_private context.\n");
211  free(spe);
212  return NULL;
213  }
214 
215  /* just a convenience variable */
216  priv = spe->base_private;
217 
218  priv->fd_spe_dir = -1;
219  priv->mem_mmap_base = MAP_FAILED;
220  priv->psmap_mmap_base = MAP_FAILED;
221  priv->mssync_mmap_base = MAP_FAILED;
222  priv->mfc_mmap_base = MAP_FAILED;
223  priv->cntl_mmap_base = MAP_FAILED;
224  priv->signal1_mmap_base = MAP_FAILED;
225  priv->signal2_mmap_base = MAP_FAILED;
226  priv->loaded_program = NULL;
227 
228  for (i = 0; i < NUM_MBOX_FDS; i++) {
229  priv->spe_fds_array[i] = -1;
230  pthread_mutex_init(&priv->fd_lock[i], NULL);
231  }
232 
233  /* initialise spu_createflags */
234  if (flags & SPE_ISOLATE) {
235  flags |= SPE_MAP_PS;
236  spu_createflags |= SPU_CREATE_ISOLATE | SPU_CREATE_NOSCHED;
237  }
238 
239  if (flags & SPE_EVENTS_ENABLE)
240  spu_createflags |= SPU_CREATE_EVENTS_ENABLED;
241 
242  if (aff_spe)
243  spu_createflags |= SPU_CREATE_AFFINITY_SPU;
244 
246  spu_createflags |= SPU_CREATE_AFFINITY_MEM;
247 
248  /* Make the SPUFS directory for the SPE */
249  if (gctx == NULL)
250  sprintf(pathname, "/spu/spethread-%i-%lu",
251  getpid(), (unsigned long)spe);
252  else
253  sprintf(pathname, "/spu/%s/spethread-%i-%lu",
254  gctx->base_private->gangname, getpid(),
255  (unsigned long)spe);
256 
257  if (aff_spe)
258  aff_spe_fd = aff_spe->base_private->fd_spe_dir;
259 
260  priv->fd_spe_dir = spu_create(pathname, spu_createflags,
261  S_IRUSR | S_IWUSR | S_IXUSR, aff_spe_fd);
262 
263  if (priv->fd_spe_dir < 0) {
264  int errno_saved = errno; /* save errno to prevent being overwritten */
265  DEBUG_PRINTF("ERROR: Could not create SPE %s\n", pathname);
266  perror("spu_create()");
267  free_spe_context(spe);
268  /* we mask most errors, but leave ENODEV, etc */
269  switch (errno_saved) {
270  case ENOTSUP:
271  case EEXIST:
272  case EINVAL:
273  case EBUSY:
274  case EPERM:
275  case ENODEV:
276  errno = errno_saved; /* restore errno */
277  break;
278  default:
279  errno = EFAULT;
280  break;
281  }
282  return NULL;
283  }
284 
285  priv->flags = flags;
286 
287  /* Map the required areas into process memory */
288  priv->mem_mmap_base = mapfileat(priv->fd_spe_dir, "mem", LS_SIZE);
289  if (priv->mem_mmap_base == MAP_FAILED) {
290  DEBUG_PRINTF("ERROR: Could not map SPE memory.\n");
291  free_spe_context(spe);
292  errno = ENOMEM;
293  return NULL;
294  }
295 
296  if (flags & SPE_MAP_PS) {
297  /* It's possible to map the entire problem state area with
298  * one mmap - try this first */
299  priv->psmap_mmap_base = mapfileat(priv->fd_spe_dir,
300  "psmap", PSMAP_SIZE);
301 
302  if (priv->psmap_mmap_base != MAP_FAILED) {
303  priv->mssync_mmap_base =
305  priv->mfc_mmap_base =
306  priv->psmap_mmap_base + MFC_OFFSET;
307  priv->cntl_mmap_base =
309  priv->signal1_mmap_base =
311  priv->signal2_mmap_base =
313 
314  } else {
315  /* map each region separately */
316  priv->mfc_mmap_base =
317  mapfileat(priv->fd_spe_dir, "mfc", MFC_SIZE);
318  priv->mssync_mmap_base =
319  mapfileat(priv->fd_spe_dir, "mss", MSS_SIZE);
320  priv->cntl_mmap_base =
321  mapfileat(priv->fd_spe_dir, "cntl", CNTL_SIZE);
322  priv->signal1_mmap_base =
323  mapfileat(priv->fd_spe_dir, "signal1",
324  SIGNAL_SIZE);
325  priv->signal2_mmap_base =
326  mapfileat(priv->fd_spe_dir, "signal2",
327  SIGNAL_SIZE);
328 
329  if (priv->mfc_mmap_base == MAP_FAILED ||
330  priv->cntl_mmap_base == MAP_FAILED ||
331  priv->signal1_mmap_base == MAP_FAILED ||
332  priv->signal2_mmap_base == MAP_FAILED) {
333  DEBUG_PRINTF("ERROR: Could not map SPE "
334  "PS memory.\n");
335  free_spe_context(spe);
336  errno = ENOMEM;
337  return NULL;
338  }
339  }
340  }
341 
343  if (setsignotify(priv->fd_spe_dir, "signal1_type")) {
344  DEBUG_PRINTF("ERROR: Could not open SPE "
345  "signal1_type file.\n");
346  free_spe_context(spe);
347  errno = EFAULT;
348  return NULL;
349  }
350  }
351 
353  if (setsignotify(priv->fd_spe_dir, "signal2_type")) {
354  DEBUG_PRINTF("ERROR: Could not open SPE "
355  "signal2_type file.\n");
356  free_spe_context(spe);
357  errno = EFAULT;
358  return NULL;
359  }
360  }
361 
362  return spe;
363 }
#define SIGNAL1_OFFSET
Definition: spebase.h:125
void * signal2_mmap_base
Definition: spebase.h:90
#define MFC_SIZE
Definition: spebase.h:117
#define SPE_CFG_SIGNOTIFY1_OR
#define CNTL_OFFSET
Definition: spebase.h:124
#define DEBUG_PRINTF(fmt, args...)
Definition: elf_loader.c:45
int _base_spe_emulated_loader_present(void)
Definition: load.c:159
void * psmap_mmap_base
Definition: spebase.h:84
spe_program_handle_t * loaded_program
Definition: spebase.h:99
void * mssync_mmap_base
Definition: spebase.h:87
#define PSMAP_SIZE
Definition: spebase.h:116
#define CNTL_SIZE
Definition: spebase.h:119
#define SPE_EVENTS_ENABLE
void * cntl_mmap_base
Definition: spebase.h:88
void * mfc_mmap_base
Definition: spebase.h:86
void * signal1_mmap_base
Definition: spebase.h:89
#define SPE_CFG_SIGNOTIFY2_OR
#define SPE_MAP_PS
int spe_fds_array[NUM_MBOX_FDS]
Definition: spebase.h:77
#define MFC_OFFSET
Definition: spebase.h:123
#define SIGNAL2_OFFSET
Definition: spebase.h:126
#define MSSYNC_OFFSET
Definition: spebase.h:122
struct spe_context_base_priv * base_private
Definition: libspe2-types.h:76
#define SPE_AFFINITY_MEMORY
#define MSS_SIZE
Definition: spebase.h:118
#define SPE_ISOLATE_EMULATE
unsigned int flags
Definition: spebase.h:74
#define LS_SIZE
Definition: elf_loader.h:23
#define SPE_ISOLATE
void * mem_mmap_base
Definition: spebase.h:85
struct spe_gang_context_base_priv * base_private
Definition: libspe2-types.h:99
#define SIGNAL_SIZE
Definition: spebase.h:120
pthread_mutex_t fd_lock[NUM_MBOX_FDS]
Definition: spebase.h:65

Here is the call graph for this function:

int _base_spe_context_destroy ( spe_context_ptr_t  spectx)

_base_spe_context_destroy cleans up what is left when an SPE executable has exited. Closes open file handles and unmaps memory areas.

Parameters
spectxSpecifies the SPE context

Definition at line 418 of file create.c.

References __spe_context_update_event().

419 {
420  int ret = free_spe_context(spe);
421 
423 
424  return ret;
425 }
void __spe_context_update_event(void)

Here is the call graph for this function:

void _base_spe_context_lock ( spe_context_ptr_t  spe,
enum fd_name  fd 
)

_base_spe_context_lock locks members of the SPE context

Parameters
spectxSpecifies the SPE context
fdSpecifies the file

Definition at line 91 of file create.c.

References spe_context::base_private, and spe_context_base_priv::fd_lock.

Referenced by _base_spe_close_if_open(), and _base_spe_open_if_closed().

92 {
93  pthread_mutex_lock(&spe->base_private->fd_lock[fdesc]);
94 }
struct spe_context_base_priv * base_private
Definition: libspe2-types.h:76
pthread_mutex_t fd_lock[NUM_MBOX_FDS]
Definition: spebase.h:65
int _base_spe_context_run ( spe_context_ptr_t  spe,
unsigned int *  entry,
unsigned int  runflags,
void *  argp,
void *  envp,
spe_stop_info_t stopinfo 
)

_base_spe_context_run starts execution of an SPE context with a loaded image

Parameters
spectxSpecifies the SPE context
entryentry point for the SPE programm. If set to 0, entry point is determined by the ELF loader.
runflagsvalid values are:
SPE_RUN_USER_REGS Specifies that the SPE setup registers r3, r4, and r5 are initialized with the 48 bytes pointed to by argp.
SPE_NO_CALLBACKS do not use built in library functions.
argpAn (optional) pointer to application specific data, and is passed as the second parameter to the SPE program.
envpAn (optional) pointer to environment specific data, and is passed as the third parameter to the SPE program.

Definition at line 99 of file run.c.

References __spe_current_active_context, _base_spe_handle_library_callback(), _base_spe_program_load_complete(), spe_context::base_private, DEBUG_PRINTF, spe_context_base_priv::emulated_entry, spe_context_base_priv::entry, spe_context_base_priv::fd_spe_dir, spe_context_base_priv::flags, LS_SIZE, spe_context_base_priv::mem_mmap_base, spe_context_info::npc, spe_context_info::prev, spe_stop_info::result, spe_stop_info::spe_callback_error, SPE_CALLBACK_ERROR, SPE_DEFAULT_ENTRY, SPE_EVENTS_ENABLE, SPE_EXIT, spe_stop_info::spe_exit_code, spe_context_info::spe_id, SPE_ISOLATE, SPE_ISOLATE_EMULATE, spe_stop_info::spe_isolation_error, SPE_ISOLATION_ERROR, SPE_NO_CALLBACKS, SPE_PROGRAM_ISO_LOAD_COMPLETE, SPE_PROGRAM_ISOLATED_STOP, SPE_PROGRAM_LIBRARY_CALL, SPE_PROGRAM_NORMAL_END, SPE_RUN_USER_REGS, spe_stop_info::spe_runtime_error, SPE_RUNTIME_ERROR, spe_stop_info::spe_runtime_exception, SPE_RUNTIME_EXCEPTION, spe_stop_info::spe_runtime_fatal, SPE_RUNTIME_FATAL, spe_stop_info::spe_signal_code, SPE_SPU_HALT, SPE_SPU_INVALID_CHANNEL, SPE_SPU_INVALID_INSTR, SPE_SPU_STOPPED_BY_STOP, SPE_SPU_WAITING_ON_CHANNEL, SPE_STOP_AND_SIGNAL, spe_stop_info::spu_status, spe_context_info::status, spe_stop_info::stop_reason, addr64::ui, and addr64::ull.

Referenced by _event_spe_context_run().

102 {
103  int retval = 0, run_rc;
104  unsigned int run_status, tmp_entry;
105  spe_stop_info_t stopinfo_buf;
106  struct spe_context_info this_context_info __attribute__((cleanup(cleanupspeinfo)));
107 
108  /* If the caller hasn't set a stopinfo buffer, provide a buffer on the
109  * stack instead. */
110  if (!stopinfo)
111  stopinfo = &stopinfo_buf;
112 
113 
114  /* In emulated isolated mode, the npc will always return as zero.
115  * use our private entry point instead */
117  tmp_entry = spe->base_private->emulated_entry;
118 
119  else if (*entry == SPE_DEFAULT_ENTRY)
120  tmp_entry = spe->base_private->entry;
121  else
122  tmp_entry = *entry;
123 
124  /* If we're starting the SPE binary from its original entry point,
125  * setup the arguments to main() */
126  if (tmp_entry == spe->base_private->entry &&
127  !(spe->base_private->flags &
129 
130  addr64 argp64, envp64, tid64, ls64;
131  unsigned int regs[128][4];
132 
133  /* setup parameters */
134  argp64.ull = (uint64_t)(unsigned long)argp;
135  envp64.ull = (uint64_t)(unsigned long)envp;
136  tid64.ull = (uint64_t)(unsigned long)spe;
137 
138  /* make sure the register values are 0 */
139  memset(regs, 0, sizeof(regs));
140 
141  /* set sensible values for stack_ptr and stack_size */
142  regs[1][0] = (unsigned int) LS_SIZE - 16; /* stack_ptr */
143  regs[2][0] = 0; /* stack_size ( 0 = default ) */
144 
145  if (runflags & SPE_RUN_USER_REGS) {
146  /* When SPE_USER_REGS is set, argp points to an array
147  * of 3x128b registers to be passed directly to the SPE
148  * program.
149  */
150  memcpy(regs[3], argp, sizeof(unsigned int) * 12);
151  } else {
152  regs[3][0] = tid64.ui[0];
153  regs[3][1] = tid64.ui[1];
154 
155  regs[4][0] = argp64.ui[0];
156  regs[4][1] = argp64.ui[1];
157 
158  regs[5][0] = envp64.ui[0];
159  regs[5][1] = envp64.ui[1];
160  }
161 
162  /* Store the LS base address in R6 */
163  ls64.ull = (uint64_t)(unsigned long)spe->base_private->mem_mmap_base;
164  regs[6][0] = ls64.ui[0];
165  regs[6][1] = ls64.ui[1];
166 
167  if (set_regs(spe, regs))
168  return -1;
169  }
170 
171  /*Leave a trail of breadcrumbs for the debugger to follow */
173  __spe_current_active_context = &this_context_info;
175  return -1;
177  } else {
178  struct spe_context_info *newinfo;
179  newinfo = &this_context_info;
180  if (!newinfo)
181  return -1;
184  }
185  /*remember the ls-addr*/
187 
188 do_run:
189  /*Remember the npc value*/
190  __spe_current_active_context->npc = tmp_entry;
191 
192  /* run SPE context */
193  run_rc = spu_run(spe->base_private->fd_spe_dir,
194  &tmp_entry, &run_status);
195 
196  /*Remember the npc value*/
197  __spe_current_active_context->npc = tmp_entry;
198  __spe_current_active_context->status = run_status;
199 
200  DEBUG_PRINTF("spu_run returned run_rc=0x%08x, entry=0x%04x, "
201  "ext_status=0x%04x.\n", run_rc, tmp_entry, run_status);
202 
203  /* set up return values and stopinfo according to spu_run exit
204  * conditions. This is overwritten on error.
205  */
206  stopinfo->spu_status = run_rc;
207 
208  if (spe->base_private->flags & SPE_ISOLATE_EMULATE) {
209  /* save the entry point, and pretend that the npc is zero */
210  spe->base_private->emulated_entry = tmp_entry;
211  *entry = 0;
212  } else {
213  *entry = tmp_entry;
214  }
215 
216  /* Return with stopinfo set on syscall error paths */
217  if (run_rc == -1) {
218  DEBUG_PRINTF("spu_run returned error %d, errno=%d\n",
219  run_rc, errno);
220  stopinfo->stop_reason = SPE_RUNTIME_FATAL;
221  stopinfo->result.spe_runtime_fatal = errno;
222  retval = -1;
223 
224  /* For isolated contexts, pass EPERM up to the
225  * caller.
226  */
227  if (!(spe->base_private->flags & SPE_ISOLATE
228  && errno == EPERM))
229  errno = EFAULT;
230 
231  } else if (run_rc & SPE_SPU_INVALID_INSTR) {
232  DEBUG_PRINTF("SPU has tried to execute an invalid "
233  "instruction. %d\n", run_rc);
234  stopinfo->stop_reason = SPE_RUNTIME_ERROR;
236  errno = EFAULT;
237  retval = -1;
238 
239  } else if ((spe->base_private->flags & SPE_EVENTS_ENABLE) && run_status) {
240  /* Report asynchronous error if return val are set and
241  * SPU events are enabled.
242  */
244  stopinfo->result.spe_runtime_exception = run_status;
245  stopinfo->spu_status = -1;
246  errno = EIO;
247  retval = -1;
248 
249  } else if (run_rc & SPE_SPU_STOPPED_BY_STOP) {
250  /* Stop & signals are broken down into three groups
251  * 1. SPE library call
252  * 2. SPE user defined stop & signal
253  * 3. SPE program end.
254  *
255  * These groups are signified by the 14-bit stop code:
256  */
257  int stopcode = (run_rc >> 16) & 0x3fff;
258 
259  /* Check if this is a library callback, and callbacks are
260  * allowed (ie, running without SPE_NO_CALLBACKS)
261  */
262  if ((stopcode & 0xff00) == SPE_PROGRAM_LIBRARY_CALL
263  && !(runflags & SPE_NO_CALLBACKS)) {
264 
265  int callback_rc, callback_number = stopcode & 0xff;
266 
267  /* execute library callback */
268  DEBUG_PRINTF("SPE library call: %d\n", callback_number);
269  callback_rc = _base_spe_handle_library_callback(spe,
270  callback_number, *entry);
271 
272  if (callback_rc) {
273  /* library callback failed; set errno and
274  * return immediately */
275  DEBUG_PRINTF("SPE library call failed: %d\n",
276  callback_rc);
277  stopinfo->stop_reason = SPE_CALLBACK_ERROR;
278  stopinfo->result.spe_callback_error =
279  callback_rc;
280  errno = EFAULT;
281  retval = -1;
282  } else {
283  /* successful library callback - restart the SPE
284  * program at the next instruction */
285  tmp_entry += 4;
286  goto do_run;
287  }
288 
289  } else if ((stopcode & 0xff00) == SPE_PROGRAM_NORMAL_END) {
290  /* The SPE program has exited by exit(X) */
291  stopinfo->stop_reason = SPE_EXIT;
292  stopinfo->result.spe_exit_code = stopcode & 0xff;
293 
294  if (spe->base_private->flags & SPE_ISOLATE) {
295  /* Issue an isolated exit, and re-run the SPE.
296  * We should see a return value without the
297  * 0x80 bit set. */
298  if (!issue_isolated_exit(spe))
299  goto do_run;
300  retval = -1;
301  }
302 
303  } else if ((stopcode & 0xfff0) == SPE_PROGRAM_ISOLATED_STOP) {
304 
305  /* 0x2206: isolated app has been loaded by loader;
306  * provide a hook for the debugger to catch this,
307  * and restart
308  */
309  if (stopcode == SPE_PROGRAM_ISO_LOAD_COMPLETE) {
311  goto do_run;
312  } else {
313  stopinfo->stop_reason = SPE_ISOLATION_ERROR;
314  stopinfo->result.spe_isolation_error =
315  stopcode & 0xf;
316  }
317 
318  } else if (spe->base_private->flags & SPE_ISOLATE &&
319  !(run_rc & 0x80)) {
320  /* We've successfully exited isolated mode */
321  retval = 0;
322 
323  } else {
324  /* User defined stop & signal, including
325  * callbacks when disabled */
326  stopinfo->stop_reason = SPE_STOP_AND_SIGNAL;
327  stopinfo->result.spe_signal_code = stopcode;
328  retval = stopcode;
329  }
330 
331  } else if (run_rc & SPE_SPU_HALT) {
332  DEBUG_PRINTF("SPU was stopped by halt. %d\n", run_rc);
333  stopinfo->stop_reason = SPE_RUNTIME_ERROR;
335  errno = EFAULT;
336  retval = -1;
337 
338  } else if (run_rc & SPE_SPU_WAITING_ON_CHANNEL) {
339  DEBUG_PRINTF("SPU is waiting on channel. %d\n", run_rc);
341  stopinfo->result.spe_runtime_exception = run_status;
342  stopinfo->spu_status = -1;
343  errno = EIO;
344  retval = -1;
345 
346  } else if (run_rc & SPE_SPU_INVALID_CHANNEL) {
347  DEBUG_PRINTF("SPU has tried to access an invalid "
348  "channel. %d\n", run_rc);
349  stopinfo->stop_reason = SPE_RUNTIME_ERROR;
351  errno = EFAULT;
352  retval = -1;
353 
354  } else {
355  DEBUG_PRINTF("spu_run returned invalid data: 0x%04x\n", run_rc);
356  stopinfo->stop_reason = SPE_RUNTIME_FATAL;
357  stopinfo->result.spe_runtime_fatal = -1;
358  stopinfo->spu_status = -1;
359  errno = EFAULT;
360  retval = -1;
361 
362  }
363 
364  freespeinfo();
365  return retval;
366 }
int _base_spe_handle_library_callback(struct spe_context *spe, int callnum, unsigned int npc)
Definition: lib_builtin.c:113
union spe_stop_info::@0 result
#define SPE_RUNTIME_EXCEPTION
#define SPE_SPU_HALT
#define SPE_RUNTIME_FATAL
__thread struct spe_context_info * __spe_current_active_context
#define SPE_PROGRAM_ISOLATED_STOP
Definition: spebase.h:142
#define DEBUG_PRINTF(fmt, args...)
Definition: elf_loader.c:45
unsigned int stop_reason
int spe_id
Definition: run.c:41
#define SPE_EVENTS_ENABLE
#define SPE_CALLBACK_ERROR
#define SPE_ISOLATION_ERROR
unsigned long long ull
Definition: elf_loader.h:30
int spe_runtime_exception
#define SPE_SPU_WAITING_ON_CHANNEL
#define SPE_RUNTIME_ERROR
#define SPE_PROGRAM_LIBRARY_CALL
Definition: spebase.h:137
#define SPE_SPU_INVALID_INSTR
#define SPE_PROGRAM_ISO_LOAD_COMPLETE
Definition: spebase.h:143
unsigned int status
Definition: run.c:43
#define SPE_NO_CALLBACKS
struct spe_context_base_priv * base_private
Definition: libspe2-types.h:76
#define SPE_SPU_INVALID_CHANNEL
#define SPE_STOP_AND_SIGNAL
#define SPE_ISOLATE_EMULATE
unsigned int flags
Definition: spebase.h:74
#define LS_SIZE
Definition: elf_loader.h:23
#define SPE_SPU_STOPPED_BY_STOP
#define SPE_ISOLATE
#define SPE_PROGRAM_NORMAL_END
Definition: spebase.h:136
void * mem_mmap_base
Definition: spebase.h:85
unsigned int ui[2]
Definition: elf_loader.h:31
#define SPE_DEFAULT_ENTRY
#define SPE_EXIT
unsigned int npc
Definition: run.c:42
#define SPE_RUN_USER_REGS
struct spe_context_info * prev
Definition: run.c:44
__attribute__((noinline))
Definition: accessors.c:69
void _base_spe_program_load_complete(spe_context_ptr_t spectx)
Definition: load.c:38

Here is the call graph for this function:

void _base_spe_context_unlock ( spe_context_ptr_t  spe,
enum fd_name  fd 
)

_base_spe_context_unlock unlocks members of the SPE context

Parameters
spectxSpecifies the SPE context
fdSpecifies the file

Definition at line 96 of file create.c.

References spe_context::base_private, and spe_context_base_priv::fd_lock.

Referenced by _base_spe_close_if_open(), and _base_spe_open_if_closed().

97 {
98  pthread_mutex_unlock(&spe->base_private->fd_lock[fdesc]);
99 }
struct spe_context_base_priv * base_private
Definition: libspe2-types.h:76
pthread_mutex_t fd_lock[NUM_MBOX_FDS]
Definition: spebase.h:65
int _base_spe_cpu_info_get ( int  info_requested,
int  cpu_node 
)

_base_spe_info_get

Definition at line 105 of file info.c.

References _base_spe_count_physical_cpus(), _base_spe_count_physical_spes(), _base_spe_count_usable_spes(), SPE_COUNT_PHYSICAL_CPU_NODES, SPE_COUNT_PHYSICAL_SPES, and SPE_COUNT_USABLE_SPES.

105  {
106  int ret = 0;
107  errno = 0;
108 
109  switch (info_requested) {
111  ret = _base_spe_count_physical_cpus(cpu_node);
112  break;
114  ret = _base_spe_count_physical_spes(cpu_node);
115  break;
117  ret = _base_spe_count_usable_spes(cpu_node);
118  break;
119  default:
120  errno = EINVAL;
121  ret = -1;
122  }
123  return ret;
124 }
#define SPE_COUNT_PHYSICAL_CPU_NODES
int _base_spe_count_physical_spes(int cpu_node)
Definition: info.c:71
int _base_spe_count_physical_cpus(int cpu_node)
Definition: info.c:30
#define SPE_COUNT_PHYSICAL_SPES
#define SPE_COUNT_USABLE_SPES
int _base_spe_count_usable_spes(int cpu_node)
Definition: info.c:62

Here is the call graph for this function:

int _base_spe_emulated_loader_present ( void  )

Check if the emulated loader is present in the filesystem

Returns
Non-zero if the loader is available, otherwise zero.

Definition at line 159 of file load.c.

References _base_spe_verify_spe_elf_image().

Referenced by _base_spe_context_create().

160 {
161  spe_program_handle_t *loader = emulated_loader_program();
162 
163  if (!loader)
164  return 0;
165 
166  return !_base_spe_verify_spe_elf_image(loader);
167 }
int _base_spe_verify_spe_elf_image(spe_program_handle_t *handle)
Definition: elf_loader.c:99

Here is the call graph for this function:

spe_gang_context_ptr_t _base_spe_gang_context_create ( unsigned int  flags)

creates the directory in SPUFS that will contain all SPEs that are considered a gang Note: I would like to generalize this to a "group" or "set" Additional attributes maintained at the group level should be used to define scheduling constraints such "temporal" (e.g., scheduled all at the same time, i.e., a gang) "topology" (e.g., "closeness" of SPEs for optimal communication)

Definition at line 376 of file create.c.

References spe_gang_context::base_private, DEBUG_PRINTF, and spe_gang_context_base_priv::gangname.

377 {
378  char pathname[256];
379  struct spe_gang_context_base_priv *pgctx = NULL;
380  struct spe_gang_context *gctx = NULL;
381 
382  gctx = malloc(sizeof(*gctx));
383  if (!gctx) {
384  DEBUG_PRINTF("ERROR: Could not allocate spe context.\n");
385  return NULL;
386  }
387  memset(gctx, 0, sizeof(*gctx));
388 
389  pgctx = malloc(sizeof(*pgctx));
390  if (!pgctx) {
391  DEBUG_PRINTF("ERROR: Could not allocate spe context.\n");
392  free(gctx);
393  return NULL;
394  }
395  memset(pgctx, 0, sizeof(*pgctx));
396 
397  gctx->base_private = pgctx;
398 
399  sprintf(gctx->base_private->gangname, "gang-%i-%lu", getpid(),
400  (unsigned long)gctx);
401  sprintf(pathname, "/spu/%s", gctx->base_private->gangname);
402 
403  gctx->base_private->fd_gang_dir = spu_create(pathname, SPU_CREATE_GANG,
404  S_IRUSR | S_IWUSR | S_IXUSR);
405 
406  if (gctx->base_private->fd_gang_dir < 0) {
407  DEBUG_PRINTF("ERROR: Could not create Gang %s\n", pathname);
408  free_spe_gang_context(gctx);
409  errno = EFAULT;
410  return NULL;
411  }
412 
413  gctx->base_private->flags = flags;
414 
415  return gctx;
416 }
#define DEBUG_PRINTF(fmt, args...)
Definition: elf_loader.c:45
struct spe_gang_context_base_priv * base_private
Definition: libspe2-types.h:99
int _base_spe_gang_context_destroy ( spe_gang_context_ptr_t  gctx)

_base_spe_gang_context_destroy destroys a gang context and frees associated resources

Parameters
gctxSpecifies the SPE gang context

Definition at line 427 of file create.c.

428 {
429  return free_spe_gang_context(gctx);
430 }
int _base_spe_image_close ( spe_program_handle_t handle)

_base_spe_image_close unmaps an SPE ELF object that was previously mapped using spe_open_image.

Parameters
handlehandle to open file
Return values
0On success, spe_close_image returns 0.
-1On failure, -1 is returned and errno is set appropriately.
Possible values for errno:
EINVAL From spe_close_image, this indicates that the file, specified by filename, was not previously mapped by a call to spe_open_image.

Definition at line 96 of file image.c.

References spe_program_handle::elf_image, image_handle::map_size, image_handle::speh, and spe_program_handle::toe_shadow.

97 {
98  int ret = 0;
99  struct image_handle *ih;
100 
101  if (!handle) {
102  errno = EINVAL;
103  return -1;
104  }
105 
106  ih = (struct image_handle *)handle;
107 
108  if (!ih->speh.elf_image || !ih->map_size) {
109  errno = EINVAL;
110  return -1;
111  }
112 
113  if (ih->speh.toe_shadow)
114  free(ih->speh.toe_shadow);
115 
116  ret = munmap(ih->speh.elf_image, ih->map_size );
117  free(handle);
118 
119  return ret;
120 }
spe_program_handle_t speh
Definition: image.c:33
unsigned int map_size
Definition: image.c:34
spe_program_handle_t* _base_spe_image_open ( const char *  filename)

_base_spe_image_open maps an SPE ELF executable indicated by filename into system memory and returns the mapped address appropriate for use by the spe_create_thread API. It is often more convenient/appropriate to use the loading methodologies where SPE ELF objects are converted to PPE static or shared libraries with symbols which point to the SPE ELF objects after these special libraries are loaded. These libraries are then linked with the associated PPE code to provide a direct symbol reference to the SPE ELF object. The symbols in this scheme are equivalent to the address returned from the spe_open_image function. SPE ELF objects loaded using this function are not shared with other processes, but SPE ELF objects loaded using the other scheme, mentioned above, can be shared if so desired.

Parameters
filenameSpecifies the filename of an SPE ELF executable to be loaded and mapped into system memory.
Returns
On success, spe_open_image returns the address at which the specified SPE ELF object has been mapped. On failure, NULL is returned and errno is set appropriately.
Possible values for errno include:
EACCES The calling process does not have permission to access the specified file.
EFAULT The filename parameter points to an address that was not contained in the calling process`s address space.

A number of other errno values could be returned by the open(2), fstat(2), mmap(2), munmap(2), or close(2) system calls which may be utilized by the spe_open_image or spe_close_image functions.

See Also
spe_create_thread

Definition at line 37 of file image.c.

References _base_spe_toe_ear(), _base_spe_verify_spe_elf_image(), spe_program_handle::elf_image, spe_program_handle::handle_size, image_handle::map_size, image_handle::speh, and spe_program_handle::toe_shadow.

38 {
39  /* allocate an extra integer in the spe handle to keep the mapped size information */
40  struct image_handle *ret;
41  int binfd = -1, f_stat;
42  struct stat statbuf;
43  size_t ps = getpagesize ();
44 
45  ret = malloc(sizeof(struct image_handle));
46  if (!ret)
47  return NULL;
48 
49  ret->speh.handle_size = sizeof(spe_program_handle_t);
50  ret->speh.toe_shadow = NULL;
51 
52  binfd = open(filename, O_RDONLY);
53  if (binfd < 0)
54  goto ret_err;
55 
56  f_stat = fstat(binfd, &statbuf);
57  if (f_stat < 0)
58  goto ret_err;
59 
60  /* Sanity: is it executable ?
61  */
62  if(!(statbuf.st_mode & (S_IXUSR | S_IXGRP | S_IXOTH))) {
63  errno=EACCES;
64  goto ret_err;
65  }
66 
67  /* now store the size at the extra allocated space */
68  ret->map_size = (statbuf.st_size + ps - 1) & ~(ps - 1);
69 
70  ret->speh.elf_image = mmap(NULL, ret->map_size,
71  PROT_WRITE | PROT_READ,
72  MAP_PRIVATE, binfd, 0);
73  if (ret->speh.elf_image == MAP_FAILED)
74  goto ret_err;
75 
76  /*Verify that this is a valid SPE ELF object*/
78  goto ret_err;
79 
80  if (_base_spe_toe_ear(&ret->speh))
81  goto ret_err;
82 
83  /* ok */
84  close(binfd);
85  return (spe_program_handle_t *)ret;
86 
87  /* err & cleanup */
88 ret_err:
89  if (binfd >= 0)
90  close(binfd);
91 
92  free(ret);
93  return NULL;
94 }
spe_program_handle_t speh
Definition: image.c:33
int _base_spe_verify_spe_elf_image(spe_program_handle_t *handle)
Definition: elf_loader.c:99
struct spe_program_handle spe_program_handle_t
int _base_spe_toe_ear(spe_program_handle_t *speh)
Definition: elf_loader.c:354
unsigned int handle_size
Definition: libspe2-types.h:49
unsigned int map_size
Definition: image.c:34

Here is the call graph for this function:

int _base_spe_in_mbox_status ( spe_context_ptr_t  spectx)

The _base_spe_in_mbox_status function fetches the status of the SPU inbound mailbox for the SPE thread specified by the speid parameter. A 0 value is return if the mailbox is full. A non-zero value specifies the number of available (32-bit) mailbox entries.

Parameters
spectxSpecifies the SPE context whose mailbox status is to be read.
Returns
On success, returns the current status of the mailbox, respectively. On failure, -1 is returned.
See Also
spe_read_out_mbox, spe_write_in_mbox, read (2)

Definition at line 202 of file mbox.c.

References _base_spe_open_if_closed(), spe_context::base_private, spe_context_base_priv::cntl_mmap_base, FD_WBOX_STAT, spe_context_base_priv::flags, SPE_MAP_PS, and spe_spu_control_area::SPU_Mbox_Stat.

203 {
204  int rc, ret;
205  volatile struct spe_spu_control_area *cntl_area =
206  spectx->base_private->cntl_mmap_base;
207 
208  if (spectx->base_private->flags & SPE_MAP_PS) {
209  ret = (cntl_area->SPU_Mbox_Stat >> 8) & 0xFF;
210  } else {
211  rc = read(_base_spe_open_if_closed(spectx,FD_WBOX_STAT, 0), &ret, 4);
212  if (rc != 4)
213  ret = -1;
214  }
215 
216  return ret;
217 
218 }
unsigned int SPU_Mbox_Stat
Definition: cbea_map.h:60
int _base_spe_open_if_closed(struct spe_context *spe, enum fd_name fdesc, int locked)
Definition: create.c:101
void * cntl_mmap_base
Definition: spebase.h:88
#define SPE_MAP_PS
struct spe_context_base_priv * base_private
Definition: libspe2-types.h:76
unsigned int flags
Definition: spebase.h:74

Here is the call graph for this function:

int _base_spe_in_mbox_write ( spe_context_ptr_t  spectx,
unsigned int  mbox_data[],
int  count,
int  behavior_flag 
)

The _base_spe_in_mbox_write function writes mbox_data to the SPE inbound mailbox for the SPE thread speid.

If the behavior flag indicates ALL_BLOCKING the call will try to write exactly count mailbox entries and block until the write request is satisfied, i.e., exactly count mailbox entries have been written. If the behavior flag indicates ANY_BLOCKING the call will try to write up to count mailbox entries, and block until the write request is satisfied, i.e., at least 1 mailbox entry has been written. If the behavior flag indicates ANY_NON_BLOCKING the call will not block until the write request is satisfied, but instead write whatever is immediately possible and return the number of mailbox entries written. spe_stat_in_mbox can be called to ensure that data can be written prior to calling the function.

Parameters
spectxSpecifies the SPE thread whose outbound mailbox is to be read.
mbox_data
count
behavior_flagALL_BLOCKING
ANY_BLOCKING
ANY_NON_BLOCKING
Return values
>=0the number of 32-bit mailbox messages written
-1error condition and errno is set
Possible values for errno:
EINVAL spectx is invalid
Exxxx what else do we need here??
void* _base_spe_ls_area_get ( struct spe_context spectx)

_base_spe_ls_area_get returns a pointer to the start of the memory mapped local store area

Parameters
spectxSpecifies the SPE context
int _base_spe_ls_size_get ( spe_context_ptr_t  spe)

_base_spe_ls_size_get returns the size of the local store area

Parameters
spectxSpecifies the SPE context

Definition at line 105 of file accessors.c.

References LS_SIZE.

106 {
107  return LS_SIZE;
108 }
#define LS_SIZE
Definition: elf_loader.h:23
int _base_spe_mfcio_get ( spe_context_ptr_t  spectx,
unsigned int  ls,
void *  ea,
unsigned int  size,
unsigned int  tag,
unsigned int  tid,
unsigned int  rid 
)

The _base_spe_mfcio_get function places a get DMA command on the proxy command queue of the SPE thread specified by speid. The get command transfers size bytes of data starting at the effective address specified by ea to the local store address specified by ls. The DMA is identified by the tag id specified by tag and performed according to the transfer class and replacement class specified by tid and rid respectively.

Parameters
spectxSpecifies the SPE context
lsSpecifies the starting local store destination address.
eaSpecifies the starting effective address source address.
sizeSpecifies the size, in bytes, to be transferred.
tagSpecifies the tag id used to identify the DMA command.
tidSpecifies the transfer class identifier of the DMA command.
ridSpecifies the replacement class identifier of the DMA command.
Returns
On success, return 0. On failure, -1 is returned.

Definition at line 160 of file dma.c.

References MFC_CMD_GET.

167 {
168  return spe_do_mfc_get(spectx, ls, ea, size, tag, tid, rid, MFC_CMD_GET);
169 }
int _base_spe_mfcio_getb ( spe_context_ptr_t  spectx,
unsigned int  ls,
void *  ea,
unsigned int  size,
unsigned int  tag,
unsigned int  tid,
unsigned int  rid 
)

The _base_spe_mfcio_getb function is identical to _base_spe_mfcio_get except that it places a getb (get with barrier) DMA command on the proxy command queue. The barrier form ensures that this command and all sequence commands with the same tag identifier as this command are locally ordered with respect to all previously issued commands with the same tag group and command queue.

Parameters
spectxSpecifies the SPE context
lsSpecifies the starting local store destination address.
eaSpecifies the starting effective address source address.
sizeSpecifies the size, in bytes, to be transferred.
tagSpecifies the tag id used to identify the DMA command.
tidSpecifies the transfer class identifier of the DMA command.
ridSpecifies the replacement class identifier of the DMA command.
Returns
On success, return 0. On failure, -1 is returned.

Definition at line 171 of file dma.c.

References MFC_CMD_GETB.

178 {
179  return spe_do_mfc_get(spectx, ls, ea, size, tag, rid, rid, MFC_CMD_GETB);
180 }
int _base_spe_mfcio_getf ( spe_context_ptr_t  spectx,
unsigned int  ls,
void *  ea,
unsigned int  size,
unsigned int  tag,
unsigned int  tid,
unsigned int  rid 
)

The _base_spe_mfcio_getf function is identical to _base_spe_mfcio_get except that it places a getf (get with fence) DMA command on the proxy command queue. The fence form ensure that this command is locally ordered with respect to all previously issued commands with the same tag group and command queue.

Parameters
spectxSpecifies the SPE context
lsSpecifies the starting local store destination address.
eaSpecifies the starting effective address source address.
sizeSpecifies the size, in bytes, to be transferred.
tagSpecifies the tag id used to identify the DMA command.
tidSpecifies the transfer class identifier of the DMA command.
ridSpecifies the replacement class identifier of the DMA command.
Returns
On success, return 0. On failure, -1 is returned.

Definition at line 182 of file dma.c.

References MFC_CMD_GETF.

189 {
190  return spe_do_mfc_get(spectx, ls, ea, size, tag, tid, rid, MFC_CMD_GETF);
191 }
int _base_spe_mfcio_put ( spe_context_ptr_t  spectx,
unsigned int  ls,
void *  ea,
unsigned int  size,
unsigned int  tag,
unsigned int  tid,
unsigned int  rid 
)

The _base_spe_mfcio_put function places a put DMA command on the proxy command queue of the SPE thread specified by speid. The put command transfers size bytes of data starting at the local store address specified by ls to the effective address specified by ea. The DMA is identified by the tag id specified by tag and performed according transfer class and replacement class specified by tid and rid respectively.

Parameters
spectxSpecifies the SPE context
lsSpecifies the starting local store destination address.
eaSpecifies the starting effective address source address.
sizeSpecifies the size, in bytes, to be transferred.
tagSpecifies the tag id used to identify the DMA command.
tidSpecifies the transfer class identifier of the DMA command.
ridSpecifies the replacement class identifier of the DMA command.
Returns
On success, return 0. On failure, -1 is returned.

Definition at line 126 of file dma.c.

References MFC_CMD_PUT.

133 {
134  return spe_do_mfc_put(spectx, ls, ea, size, tag, tid, rid, MFC_CMD_PUT);
135 }
int _base_spe_mfcio_putb ( spe_context_ptr_t  spectx,
unsigned int  ls,
void *  ea,
unsigned int  size,
unsigned int  tag,
unsigned int  tid,
unsigned int  rid 
)

The _base_spe_mfcio_putb function is identical to _base_spe_mfcio_put except that it places a putb (put with barrier) DMA command on the proxy command queue. The barrier form ensures that this command and all sequence commands with the same tag identifier as this command are locally ordered with respect to all previously i ssued commands with the same tag group and command queue.

Parameters
spectxSpecifies the SPE context
lsSpecifies the starting local store destination address.
eaSpecifies the starting effective address source address.
sizeSpecifies the size, in bytes, to be transferred.
tagSpecifies the tag id used to identify the DMA command.
tidSpecifies the transfer class identifier of the DMA command.
ridSpecifies the replacement class identifier of the DMA command.
Returns
On success, return 0. On failure, -1 is returned.

Definition at line 137 of file dma.c.

References MFC_CMD_PUTB.

144 {
145  return spe_do_mfc_put(spectx, ls, ea, size, tag, tid, rid, MFC_CMD_PUTB);
146 }
int _base_spe_mfcio_putf ( spe_context_ptr_t  spectx,
unsigned int  ls,
void *  ea,
unsigned int  size,
unsigned int  tag,
unsigned int  tid,
unsigned int  rid 
)

The _base_spe_mfcio_putf function is identical to _base_spe_mfcio_put except that it places a putf (put with fence) DMA command on the proxy command queue. The fence form ensures that this command is locally ordered with respect to all previously issued commands with the same tag group and command queue.

Parameters
spectxSpecifies the SPE context
lsSpecifies the starting local store destination address.
eaSpecifies the starting effective address source address.
sizeSpecifies the size, in bytes, to be transferred.
tagSpecifies the tag id used to identify the DMA command.
tidSpecifies the transfer class identifier of the DMA command.
ridSpecifies the replacement class identifier of the DMA command.
Returns
On success, return 0. On failure, -1 is returned.

Definition at line 148 of file dma.c.

References MFC_CMD_PUTF.

155 {
156  return spe_do_mfc_put(spectx, ls, ea, size, tag, tid, rid, MFC_CMD_PUTF);
157 }
int _base_spe_mfcio_tag_status_read ( spe_context_ptr_t  spectx,
unsigned int  mask,
unsigned int  behavior,
unsigned int *  tag_status 
)

_base_spe_mfcio_tag_status_read

No Idea

Definition at line 307 of file dma.c.

References spe_context_base_priv::active_tagmask, spe_context::base_private, spe_context_base_priv::flags, SPE_MAP_PS, SPE_TAG_ALL, SPE_TAG_ANY, and SPE_TAG_IMMEDIATE.

308 {
309  if ( mask != 0 ) {
310  if (!(spectx->base_private->flags & SPE_MAP_PS))
311  mask = 0;
312  } else {
313  if ((spectx->base_private->flags & SPE_MAP_PS))
314  mask = spectx->base_private->active_tagmask;
315  }
316 
317  if (!tag_status) {
318  errno = EINVAL;
319  return -1;
320  }
321 
322  switch (behavior) {
323  case SPE_TAG_ALL:
324  return spe_mfcio_tag_status_read_all(spectx, mask, tag_status);
325  case SPE_TAG_ANY:
326  return spe_mfcio_tag_status_read_any(spectx, mask, tag_status);
327  case SPE_TAG_IMMEDIATE:
328  return spe_mfcio_tag_status_read_immediate(spectx, mask, tag_status);
329  default:
330  errno = EINVAL;
331  return -1;
332  }
333 }
#define SPE_MAP_PS
struct spe_context_base_priv * base_private
Definition: libspe2-types.h:76
unsigned int flags
Definition: spebase.h:74
#define SPE_TAG_ALL
#define SPE_TAG_IMMEDIATE
#define SPE_TAG_ANY
int _base_spe_mssync_start ( spe_context_ptr_t  spectx)

_base_spe_mssync_start starts Multisource Synchronisation

Parameters
spectxSpecifies the SPE context

Definition at line 335 of file dma.c.

References _base_spe_open_if_closed(), spe_context::base_private, FD_MSS, spe_context_base_priv::flags, spe_mssync_area::MFC_MSSync, spe_context_base_priv::mssync_mmap_base, and SPE_MAP_PS.

336 {
337  int ret, fd;
338  unsigned int data = 1; /* Any value can be written here */
339 
340  volatile struct spe_mssync_area *mss_area =
342 
343  if (spectx->base_private->flags & SPE_MAP_PS) {
344  mss_area->MFC_MSSync = data;
345  return 0;
346  } else {
347  fd = _base_spe_open_if_closed(spectx, FD_MSS, 0);
348  if (fd != -1) {
349  ret = write(fd, &data, sizeof (data));
350  if ((ret < 0) && (errno != EIO)) {
351  perror("spe_mssync_start: internal error");
352  }
353  return ret < 0 ? -1 : 0;
354  } else
355  return -1;
356  }
357 }
void * mssync_mmap_base
Definition: spebase.h:87
int _base_spe_open_if_closed(struct spe_context *spe, enum fd_name fdesc, int locked)
Definition: create.c:101
#define SPE_MAP_PS
Definition: spebase.h:54
unsigned int MFC_MSSync
Definition: cbea_map.h:31
struct spe_context_base_priv * base_private
Definition: libspe2-types.h:76
unsigned int flags
Definition: spebase.h:74

Here is the call graph for this function:

int _base_spe_mssync_status ( spe_context_ptr_t  spectx)

_base_spe_mssync_status retrieves status of Multisource Synchronisation

Parameters
spectxSpecifies the SPE context

Definition at line 359 of file dma.c.

References _base_spe_open_if_closed(), spe_context::base_private, FD_MSS, spe_context_base_priv::flags, spe_mssync_area::MFC_MSSync, spe_context_base_priv::mssync_mmap_base, and SPE_MAP_PS.

360 {
361  int ret, fd;
362  unsigned int data;
363 
364  volatile struct spe_mssync_area *mss_area =
366 
367  if (spectx->base_private->flags & SPE_MAP_PS) {
368  return mss_area->MFC_MSSync;
369  } else {
370  fd = _base_spe_open_if_closed(spectx, FD_MSS, 0);
371  if (fd != -1) {
372  ret = read(fd, &data, sizeof (data));
373  if ((ret < 0) && (errno != EIO)) {
374  perror("spe_mssync_start: internal error");
375  }
376  return ret < 0 ? -1 : data;
377  } else
378  return -1;
379  }
380 }
void * mssync_mmap_base
Definition: spebase.h:87
int _base_spe_open_if_closed(struct spe_context *spe, enum fd_name fdesc, int locked)
Definition: create.c:101
#define SPE_MAP_PS
Definition: spebase.h:54
unsigned int MFC_MSSync
Definition: cbea_map.h:31
struct spe_context_base_priv * base_private
Definition: libspe2-types.h:76
unsigned int flags
Definition: spebase.h:74

Here is the call graph for this function:

int _base_spe_out_intr_mbox_read ( spe_context_ptr_t  spectx,
unsigned int  mbox_data[],
int  count,
int  behavior_flag 
)

The _base_spe_out_intr_mbox_read function reads the contents of the SPE outbound interrupting mailbox for the SPE context.

Definition at line 255 of file mbox.c.

References _base_spe_open_if_closed(), FD_IBOX, FD_IBOX_NB, SPE_MBOX_ALL_BLOCKING, SPE_MBOX_ANY_BLOCKING, and SPE_MBOX_ANY_NONBLOCKING.

259 {
260  int rc;
261  int total;
262 
263  if (mbox_data == NULL || count < 1){
264  errno = EINVAL;
265  return -1;
266  }
267 
268  switch (behavior_flag) {
269  case SPE_MBOX_ALL_BLOCKING: // read all, even if blocking
270  total = rc = 0;
271  while (total < 4*count) {
272  rc = read(_base_spe_open_if_closed(spectx,FD_IBOX, 0),
273  (char *)mbox_data + total, 4*count - total);
274  if (rc == -1) {
275  break;
276  }
277  total += rc;
278  }
279  break;
280 
281  case SPE_MBOX_ANY_BLOCKING: // read at least one, even if blocking
282  total = rc = read(_base_spe_open_if_closed(spectx,FD_IBOX, 0), mbox_data, 4*count);
283  break;
284 
285  case SPE_MBOX_ANY_NONBLOCKING: // only reaad, if non blocking
286  rc = read(_base_spe_open_if_closed(spectx,FD_IBOX_NB, 0), mbox_data, 4*count);
287  if (rc == -1 && errno == EAGAIN) {
288  rc = 0;
289  errno = 0;
290  }
291  total = rc;
292  break;
293 
294  default:
295  errno = EINVAL;
296  return -1;
297  }
298 
299  if (rc == -1) {
300  errno = EIO;
301  return -1;
302  }
303 
304  return rc / 4;
305 }
int _base_spe_open_if_closed(struct spe_context *spe, enum fd_name fdesc, int locked)
Definition: create.c:101
#define SPE_MBOX_ANY_NONBLOCKING
#define SPE_MBOX_ALL_BLOCKING
#define SPE_MBOX_ANY_BLOCKING

Here is the call graph for this function:

int _base_spe_out_intr_mbox_status ( spe_context_ptr_t  spectx)

The _base_spe_out_intr_mbox_status function fetches the status of the SPU outbound interrupt mailbox for the SPE thread specified by the speid parameter. A 0 value is return if the mailbox is empty. A non-zero value specifies the number of 32-bit unread mailbox entries.

Parameters
spectxSpecifies the SPE context whose mailbox status is to be read.
Returns
On success, returns the current status of the mailbox, respectively. On failure, -1 is returned.
See Also
spe_read_out_mbox, spe_write_in_mbox, read (2)

Definition at line 238 of file mbox.c.

References _base_spe_open_if_closed(), spe_context::base_private, spe_context_base_priv::cntl_mmap_base, FD_IBOX_STAT, spe_context_base_priv::flags, SPE_MAP_PS, and spe_spu_control_area::SPU_Mbox_Stat.

239 {
240  int rc, ret;
241  volatile struct spe_spu_control_area *cntl_area =
242  spectx->base_private->cntl_mmap_base;
243 
244  if (spectx->base_private->flags & SPE_MAP_PS) {
245  ret = (cntl_area->SPU_Mbox_Stat >> 16) & 0xFF;
246  } else {
247  rc = read(_base_spe_open_if_closed(spectx,FD_IBOX_STAT, 0), &ret, 4);
248  if (rc != 4)
249  ret = -1;
250 
251  }
252  return ret;
253 }
unsigned int SPU_Mbox_Stat
Definition: cbea_map.h:60
int _base_spe_open_if_closed(struct spe_context *spe, enum fd_name fdesc, int locked)
Definition: create.c:101
void * cntl_mmap_base
Definition: spebase.h:88
#define SPE_MAP_PS
struct spe_context_base_priv * base_private
Definition: libspe2-types.h:76
unsigned int flags
Definition: spebase.h:74

Here is the call graph for this function:

int _base_spe_out_mbox_read ( spe_context_ptr_t  spectx,
unsigned int  mbox_data[],
int  count 
)

The _base_spe_out_mbox_read function reads the contents of the SPE outbound interrupting mailbox for the SPE thread speid.

The call will not block until the read request is satisfied, but instead return up to count currently available mailbox entries.

spe_stat_out_intr_mbox can be called to ensure that data is available prior to reading the outbound interrupting mailbox.

Parameters
spectxSpecifies the SPE thread whose outbound mailbox is to be read.
mbox_data
count
Return values
>0the number of 32-bit mailbox messages read
=0no data available
-1error condition and errno is set
Possible values for errno:
EINVAL speid is invalid
Exxxx what else do we need here??

Definition at line 58 of file mbox.c.

References _base_spe_open_if_closed(), spe_context::base_private, DEBUG_PRINTF, FD_MBOX, spe_context_base_priv::flags, and SPE_MAP_PS.

61 {
62  int rc;
63 
64  if (mbox_data == NULL || count < 1){
65  errno = EINVAL;
66  return -1;
67  }
68 
69  if (spectx->base_private->flags & SPE_MAP_PS) {
70  rc = _base_spe_out_mbox_read_ps(spectx, mbox_data, count);
71  } else {
72  rc = read(_base_spe_open_if_closed(spectx,FD_MBOX, 0), mbox_data, count*4);
73  DEBUG_PRINTF("%s read rc: %d\n", __FUNCTION__, rc);
74  if (rc != -1) {
75  rc /= 4;
76  } else {
77  if (errno == EAGAIN ) { // no data ready to be read
78  errno = 0;
79  rc = 0;
80  }
81  }
82  }
83  return rc;
84 }
#define DEBUG_PRINTF(fmt, args...)
Definition: elf_loader.c:45
int _base_spe_open_if_closed(struct spe_context *spe, enum fd_name fdesc, int locked)
Definition: create.c:101
#define SPE_MAP_PS
struct spe_context_base_priv * base_private
Definition: libspe2-types.h:76
unsigned int flags
Definition: spebase.h:74

Here is the call graph for this function:

int _base_spe_out_mbox_status ( spe_context_ptr_t  spectx)

The _base_spe_out_mbox_status function fetches the status of the SPU outbound mailbox for the SPE thread specified by the speid parameter. A 0 value is return if the mailbox is empty. A non-zero value specifies the number of 32-bit unread mailbox entries.

Parameters
spectxSpecifies the SPE context whose mailbox status is to be read.
Returns
On success, returns the current status of the mailbox, respectively. On failure, -1 is returned.
See Also
spe_read_out_mbox, spe_write_in_mbox, read (2)

Definition at line 220 of file mbox.c.

References _base_spe_open_if_closed(), spe_context::base_private, spe_context_base_priv::cntl_mmap_base, FD_MBOX_STAT, spe_context_base_priv::flags, SPE_MAP_PS, and spe_spu_control_area::SPU_Mbox_Stat.

221 {
222  int rc, ret;
223  volatile struct spe_spu_control_area *cntl_area =
224  spectx->base_private->cntl_mmap_base;
225 
226  if (spectx->base_private->flags & SPE_MAP_PS) {
227  ret = cntl_area->SPU_Mbox_Stat & 0xFF;
228  } else {
229  rc = read(_base_spe_open_if_closed(spectx,FD_MBOX_STAT, 0), &ret, 4);
230  if (rc != 4)
231  ret = -1;
232  }
233 
234  return ret;
235 
236 }
unsigned int SPU_Mbox_Stat
Definition: cbea_map.h:60
int _base_spe_open_if_closed(struct spe_context *spe, enum fd_name fdesc, int locked)
Definition: create.c:101
void * cntl_mmap_base
Definition: spebase.h:88
#define SPE_MAP_PS
struct spe_context_base_priv * base_private
Definition: libspe2-types.h:76
unsigned int flags
Definition: spebase.h:74

Here is the call graph for this function:

int _base_spe_program_load ( spe_context_ptr_t  spectx,
spe_program_handle_t program 
)

_base_spe_program_load loads an ELF image into a context

Parameters
spectxSpecifies the SPE context
programhandle to the ELF image

Definition at line 203 of file load.c.

References _base_spe_load_spe_elf(), _base_spe_program_load_complete(), spe_context::base_private, DEBUG_PRINTF, spe_context_base_priv::emulated_entry, spe_ld_info::entry, spe_context_base_priv::entry, spe_context_base_priv::flags, spe_context_base_priv::loaded_program, spe_context_base_priv::mem_mmap_base, SPE_ISOLATE, and SPE_ISOLATE_EMULATE.

204 {
205  int rc = 0;
206  struct spe_ld_info ld_info;
207 
208  spe->base_private->loaded_program = program;
209 
210  if (spe->base_private->flags & SPE_ISOLATE) {
211  rc = spe_start_isolated_app(spe, program);
212 
213  } else if (spe->base_private->flags & SPE_ISOLATE_EMULATE) {
214  rc = spe_start_emulated_isolated_app(spe, program, &ld_info);
215 
216  } else {
217  rc = _base_spe_load_spe_elf(program,
218  spe->base_private->mem_mmap_base, &ld_info);
219  if (!rc)
221  }
222 
223  if (rc != 0) {
224  DEBUG_PRINTF ("Load SPE ELF failed..\n");
225  return -1;
226  }
227 
228  spe->base_private->entry = ld_info.entry;
229  spe->base_private->emulated_entry = ld_info.entry;
230 
231  return 0;
232 }
#define DEBUG_PRINTF(fmt, args...)
Definition: elf_loader.c:45
int _base_spe_load_spe_elf(spe_program_handle_t *handle, void *ld_buffer, struct spe_ld_info *ld_info)
Definition: elf_loader.c:201
#define SPE_ISOLATE_EMULATE
#define SPE_ISOLATE
void _base_spe_program_load_complete(spe_context_ptr_t spectx)
Definition: load.c:38

Here is the call graph for this function:

void _base_spe_program_load_complete ( spe_context_ptr_t  spectx)

Signal that the program load has completed. For normal apps, this is called directly in the load path. For (emulated) isolated apps, the load is asynchronous, so this needs to be called when we know that the load has completed

Precondition
spe->base_priv->loaded_program is a valid SPE program
Parameters
spectxThe spe context that has been loaded.

Register the SPE program's start address with the oprofile and gdb, by writing to the object-id file.

Definition at line 38 of file load.c.

References __spe_context_update_event(), spe_context::base_private, DEBUG_PRINTF, spe_program_handle::elf_image, spe_context_base_priv::fd_spe_dir, and spe_context_base_priv::loaded_program.

Referenced by _base_spe_context_run(), and _base_spe_program_load().

39 {
40  int objfd, len;
41  char buf[20];
42  spe_program_handle_t *program;
43 
44  program = spectx->base_private->loaded_program;
45 
46  if (!program || !program->elf_image) {
47  DEBUG_PRINTF("%s called, but no program loaded\n", __func__);
48  return;
49  }
50 
51  objfd = openat(spectx->base_private->fd_spe_dir, "object-id", O_RDWR);
52  if (objfd < 0)
53  return;
54 
55  len = sprintf(buf, "%p", program->elf_image);
56  write(objfd, buf, len + 1);
57  close(objfd);
58 
60 }
#define DEBUG_PRINTF(fmt, args...)
Definition: elf_loader.c:45
spe_program_handle_t * loaded_program
Definition: spebase.h:99
void __spe_context_update_event(void)
struct spe_context_base_priv * base_private
Definition: libspe2-types.h:76

Here is the call graph for this function:

void* _base_spe_ps_area_get ( struct spe_context spectx,
enum ps_area  area 
)

_base_spe_ps_area_get returns a pointer to the start of memory mapped problem state area

Parameters
spectxSpecifies the SPE context
areaspecifes the area to map
int _base_spe_signal_write ( spe_context_ptr_t  spectx,
unsigned int  signal_reg,
unsigned int  data 
)

The _base_spe_signal_write function writes data to the signal notification register specified by signal_reg for the SPE thread specified by the speid parameter.

Parameters
spectxSpecifies the SPE context whose signal register is to be written to.
signal_regSpecified the signal notification register to be written. Valid signal notification registers are:
SPE_SIG_NOTIFY_REG_1 SPE signal notification register 1
SPE_SIG_NOTIFY_REG_2 SPE signal notification register 2
dataThe 32-bit data to be written to the specified signal notification register.
Returns
On success, spe_write_signal returns 0. On failure, -1 is returned.
See Also
spe_get_ps_area, spe_write_in_mbox

Definition at line 307 of file mbox.c.

References _base_spe_close_if_open(), _base_spe_open_if_closed(), spe_context::base_private, FD_SIG1, FD_SIG2, spe_context_base_priv::flags, spe_context_base_priv::signal1_mmap_base, spe_context_base_priv::signal2_mmap_base, SPE_MAP_PS, SPE_SIG_NOTIFY_REG_1, SPE_SIG_NOTIFY_REG_2, spe_sig_notify_1_area::SPU_Sig_Notify_1, and spe_sig_notify_2_area::SPU_Sig_Notify_2.

310 {
311  int rc;
312 
313  if (spectx->base_private->flags & SPE_MAP_PS) {
314  if (signal_reg == SPE_SIG_NOTIFY_REG_1) {
316 
317  sig->SPU_Sig_Notify_1 = data;
318  } else if (signal_reg == SPE_SIG_NOTIFY_REG_2) {
320 
321  sig->SPU_Sig_Notify_2 = data;
322  } else {
323  errno = EINVAL;
324  return -1;
325  }
326  rc = 0;
327  } else {
328  if (signal_reg == SPE_SIG_NOTIFY_REG_1)
329  rc = write(_base_spe_open_if_closed(spectx,FD_SIG1, 0), &data, 4);
330  else if (signal_reg == SPE_SIG_NOTIFY_REG_2)
331  rc = write(_base_spe_open_if_closed(spectx,FD_SIG2, 0), &data, 4);
332  else {
333  errno = EINVAL;
334  return -1;
335  }
336 
337  if (rc == 4)
338  rc = 0;
339 
340  if (signal_reg == SPE_SIG_NOTIFY_REG_1)
342  else if (signal_reg == SPE_SIG_NOTIFY_REG_2)
344  }
345 
346  return rc;
347 }
void _base_spe_close_if_open(struct spe_context *spe, enum fd_name fdesc)
Definition: create.c:125
void * signal2_mmap_base
Definition: spebase.h:90
int _base_spe_open_if_closed(struct spe_context *spe, enum fd_name fdesc, int locked)
Definition: create.c:101
void * signal1_mmap_base
Definition: spebase.h:89
#define SPE_MAP_PS
unsigned int SPU_Sig_Notify_1
Definition: cbea_map.h:71
struct spe_context_base_priv * base_private
Definition: libspe2-types.h:76
unsigned int flags
Definition: spebase.h:74
#define SPE_SIG_NOTIFY_REG_1
unsigned int SPU_Sig_Notify_2
Definition: cbea_map.h:76
#define SPE_SIG_NOTIFY_REG_2

Here is the call graph for this function:

int _base_spe_stop_reason_get ( spe_context_ptr_t  spectx)

_base_spe_stop_reason_get

Parameters
spectxone thread for which to check why it was stopped
Return values
0success - eventid and eventdata set appropriately
1spe has not stopped after checking last, so no data was written to event
-1an error has happened, event was not touched, errno gets set
Possible vales for errno:
EINVAL speid is invalid
Exxxx what else do we need here??
int _base_spe_stop_status_get ( spe_context_ptr_t  spectx)

_base_spe_stop_status_get

Parameters
spectxSpecifies the SPE context