[Cbe-oss-dev] libspe2: SPE_NO_CALLBACKS broken
Julio M. Merino Vidal
jmerino at ac.upc.edu
Thu Mar 29 19:14:41 EST 2007
Hello,
I've been reading the libspe2 documentation and, according to it, there
is a flag for spe_context_run (SPE_NO_CALLBACKS) to tell it not to handle
any SPE callbacks.
However, this flag does not work. If you set it, library callbacks are not
returned to the SPE thread. After inspecting the code, it is fairly clear
that this is broken because the check for SPE_NO_CALLBACKS is incorrectly
done. The code is using the binary not operation (~) to reverse the
condition, while it should really be using a logical not (!). Otherwise the
check is always true and, as a result, SPE_NO_CALLBACKS has no effect.
Furthermore, even after correcting the above, stop and signal calls for
library callbacks are not properly delivered to the caller. This is because
neither the return value nor the stop condition are updated appropriately
in the SPE_NO_CALLBACKS case (when fixed the above). I've fixed it by
changing the first else clause in the conditional to cover more cases.
The patch pasted below resolves the problems for me, although I'm not
completely sure it is correct.
King regards,
diff --git a/spebase/run.c b/spebase/run.c
index 85c7ac7..d8bcb7e 100644
--- a/spebase/run.c
+++ b/spebase/run.c
@@ -233,7 +233,7 @@ int _base_spe_context_run(spe_context_ptr_t spe, unsigned int *entry,
stopcode = ( ret >> 16 ) & 0x3fff;
// check if this is a library callback (stopcode has 0x2100 bits set)
// and callbacks are allowed (SPE_NO_CALLBACKS - don't run any library call functions)
- if ( ((stopcode & 0xff00) == SPE_PROGRAM_LIBRARY_CALL) && ~(runflags & SPE_NO_CALLBACKS) ) {
+ if ( ((stopcode & 0xff00) == SPE_PROGRAM_LIBRARY_CALL) && !(runflags & SPE_NO_CALLBACKS) ) {
// execute library callback
int callnum = stopcode & 0xff;
DEBUG_PRINTF ("SPE library call: %d\n",callnum);
@@ -253,7 +253,7 @@ int _base_spe_context_run(spe_context_ptr_t spe, unsigned int *entry,
run_again=1;
*entry += 4;
}
- } else if (stopcode < SPE_PROGRAM_NORMAL_END) {
+ } else if ((stopcode & 0xff00) != SPE_PROGRAM_NORMAL_END) {
// this SPE signald a user defined stop&signal
stopinfo->stop_reason = SPE_STOP_AND_SIGNAL;
stopinfo->result.spe_signal_code = stopcode;
More information about the cbe-oss-dev
mailing list