Example #1
0
Spurs *
initSpurs(const char *prefix_name)
{
   Spurs *spurs = NULL;
   SpursAttribute attributeSpurs;
   int ret;

   ret = sysSpuInitialize (6, 0);
   printf ("sysSpuInitialize return %d\n", ret);

   /* initialize spurs */
   printf ("Initializing spurs\n");
   spurs = (Spurs *)(void *)memalign (SPURS_ALIGN, sizeof (Spurs));
   printf ("Initializing spurs attribute\n");

   ret = spursAttributeInitialize (&attributeSpurs, 5, 250, 1000, true);
   if (ret)
     {
        printf ("error : spursAttributeInitialize failed  %x\n", ret);
        goto error;
     }

   printf ("Setting name prefix\n");
   if (!prefix_name)
     prefix_name = SPURS_DEFAULT_PREFIX_NAME;
   ret = spursAttributeSetNamePrefix (&attributeSpurs,
                                      prefix_name, strlen (prefix_name));
   if (ret)
     {
        printf ("error : spursAttributeInitialize failed %x\n", ret);
        goto error;
     }

   printf ("Initializing with attribute\n");
   ret = spursInitializeWithAttribute (spurs, &attributeSpurs);
   if (ret)
     {
        printf ("error: spursInitializeWithAttribute failed  %x\n", ret);
        goto error;
     }

   return spurs;

error:
   if (spurs)
     free (spurs);
   return NULL;
}
Example #2
0
int
initSpurs ()
{
  int ret;
  int i;
  sys_ppu_thread_t ppu_thread_id;
  int ppu_prio;
  unsigned int nthread;

  ret = sysSpuInitialize (6, 0);
  printf ("sysSpuInitialize return %d\n", ret);

  ret = sysThreadGetId (&ppu_thread_id);
  printf ("sysThreadGetId return %d ppu_thread_id %x\n", ret, ppu_thread_id);

  ret = sysThreadGetPriority (ppu_thread_id, &ppu_prio);
  printf ("sysThreadGetPriority return %d ppu_prio %d\n", ret, ppu_prio);

  /* initialize spurs */
  printf ("Initializing spurs\n");
  spurs = (void *) memalign (SPURS_ALIGN, sizeof (Spurs));
  printf ("Initializing spurs attribute\n");
  SpursAttribute attributeSpurs;

  ret = spursAttributeInitialize (&attributeSpurs, 5, 250, ppu_prio - 1, true);
  if (ret) {
    printf ("error : spursAttributeInitialize failed  %x\n", ret);
    return (ret);
  }

  printf ("Setting name prefix\n");
  ret =
      spursAttributeSetNamePrefix (&attributeSpurs, SPURS_PREFIX_NAME,
      strlen (SPURS_PREFIX_NAME));
  if (ret) {
    printf ("error : spursAttributeInitialize failed %x\n", ret);
    return (ret);
  }

  printf ("Initializing with attribute\n");
  ret = spursInitializeWithAttribute (spurs, &attributeSpurs);
  if (ret) {
    printf ("error: spursInitializeWithAttribute failed  %x\n", ret);
    return (ret);
  }

  ret = spursGetNumSpuThread (spurs, &nthread);
  if (ret) {
    printf ("error: spursGetNumSpuThread failed %x\n", ret);
  }

  sys_spu_thread_t *threads =
      (sys_spu_thread_t *) malloc (sizeof (sys_spu_thread_t) * nthread);

  ret = spursGetSpuThreadId (spurs, threads, &nthread);
  if (ret) {
    printf ("error: spursGetSpuThreadId failed %x\n", ret);
  }

  printf ("SPURS %d spu threads availables\n", nthread);
  for (i = 0; i < nthread; i++) {
    printf ("SPU Number:%d\tSPU Thread ID:%x\n", i, threads[i]);
  }
  printf ("\n");

  printf ("checking SpursInfo\n");
  SpursInfo info;

  ret = spursGetInfo (spurs, &info);
  if (ret) {
    printf ("error: spursGetInfo failed %x\n", ret);
  }
  printf ("SpursInfo: \n");
  printf ("nSpus=%d \n", info.nSpus);
  printf ("spuGroupPriority=%d \n", info.spuGroupPriority);
  printf ("ppuThreadPriority=%d \n", info.ppuThreadPriority);
  printf ("exitIfNoWork=%d \n", info.exitIfNoWork);
  printf ("namePrefix=%s \n", info.namePrefix);
  for (i = 0; i < info.nSpus; i++) {
    printf ("SPU Number:%d\tSPU Thread ID:%x\n", i, info.spuThreads[i]);
  }
  printf ("SPURS initialized correctly!!!\n");

}