Topic
3 replies Latest Post - ‏2010-07-06T09:40:34Z by jk-
PedroGonnet
PedroGonnet
12 Posts
ACCEPTED ANSWER

Pinned topic How to access argp when restarting a spe_context?

‏2010-07-04T12:55:43Z |
Hi,

I have a re-entrant SPU code that, when called the first time with spu_context_run(...), loads some data from the main store, calls spu_stop(0) and waits for the main program to start it again with spe_context_run(...).

When the SPU code is called again, it re-enters at the correct point and everything is great, except that I really need to access the value of "argp" that I sent with the second call of spe_context_run(...). The value of that parameter on the spu, however, is still the old value from the first call to spe_context_run(...).

I've tried declaring the parameter as "volatile", but that changes nothing. I know that the value of "argp" should be in R3 when the code re-enters, but I have no idea how to get it out of there...

For clarity, my SPU code looks something like this:

int main ( unsigned long long id , volatile unsigned long long argp , unsigned long long envp ) {

/* print the contents of argp */
printf("runner_spu: fetching data from 0x%llx...\n",argp);

/* fetch some stuff from memory... */

/* give control back to the ppu and wait for more... */
spu_stop(0);

/* as of here I should have a new argp... */
printf("runner_spu: fetching data from 0x%llx...\n",argp);

}

In the above code, if I call spu_context_run(...) with two different values for "argp", the spu prints the first value twice.

Many thanks in advance,
Pedro
Updated on 2010-07-06T09:40:34Z at 2010-07-06T09:40:34Z by jk-
  • jk-
    jk-
    43 Posts
    ACCEPTED ANSWER

    Re: How to access argp when restarting a spe_context?

    ‏2010-07-05T01:28:00Z  in response to PedroGonnet
    Hi Pedro,

    The arguments to spe_context_run are only initialised if you're starting from the original entry point. If you specify a different value for the entry parameter, the libspe code does not transfer the new arguments; you'll need to find a different method of passing this parameter which need to be updated.

    Cheers,
    Jeremy
    • PedroGonnet
      PedroGonnet
      12 Posts
      ACCEPTED ANSWER

      Re: How to access argp when restarting a spe_context?

      ‏2010-07-05T09:46:03Z  in response to jk-
      Hi Jeremy,

      Thanks for the reply!

      Just to make sure I understand everything... So the arguments are not passed to the registers or they are just not transfered to the stack?

      If they are still transfered to the registers, is there any way I can pick them out from there?

      Cheers, Pedro.
      • jk-
        jk-
        43 Posts
        ACCEPTED ANSWER

        Re: How to access argp when restarting a spe_context?

        ‏2010-07-06T09:40:34Z  in response to PedroGonnet
        Hi Pedro,

        If *entry != SPE_DEFAULT_ENTRY, the argp value isn't passed to the SPE at all.

        The reason for this is that doing so would require knowledge of your program (ie, which register has the value of that variable (if any) at that point in time), and access to the register file would require the context to be de-scheduled from the SPE, which would be a performance hit.

        A slightly tricky way to get around this would be to pass the value through the SPE local store: add a variable to your program (it'll need to be marked 'volatile'), find the link address of this variable, and update the corresponding location in the LS before re-starting the context. It's a bit of a hack (you'll need to do some trickery with the compiled SPE executable to get the variable's address), but might work for your situation.

        Of course, you can just use the mailboxes or DMA transfers to achieve the same.

        Hope this helps,
        Jeremy