[Cbe-oss-dev] [PATCH] libspe2: Don't use direct problem-state mapping for isolated load

Jeremy Kerr jk at ozlabs.org
Mon Sep 17 09:46:00 EST 2007


Previously (ie, in libspe1), we were using the direct problem-state
mapping to send mailbox messages to the SPE during isolated load.
Since writes to the psmap will become blocking when a SPE is not
running, we can't use SPE_MAP_PS during the isolated load procedure.

This change makes the isolated load use the wbox writes, rather than
the problem-state mapping, even when SPE_MAP_PS is set.

Signed-off-by: Jeremy Kerr <jk at ozlabs.org>

---

 spebase/load.c |   32 +++++++++++++++++++++++---------
 spebase/run.c  |    3 ++-
 2 files changed, 25 insertions(+), 10 deletions(-)

Index: libspe2/spebase/load.c
===================================================================
--- libspe2.orig/spebase/load.c
+++ libspe2/spebase/load.c
@@ -24,6 +24,7 @@
 #include <errno.h>
 
 #include "elf_loader.h"
+#include "create.h"
 #include "spebase.h"
 
 #ifndef SPE_EMULATED_LOADER_FILE
@@ -59,19 +60,34 @@ void _base_spe_program_load_complete(spe
 }
 
 /**
- * Send data to a SPU in mbox when space is available.
+ * Send the isolated app loading parameters to the SPE.
  *
  * Helper function for internal libspe use.
  *
  * @param spe The SPE thread to send the mailbox message to
- * @param data  Data to send to the mailbox
+ * @param addr_h  The high 32-bits of the address of the isolated app
+ * @param addr_l  The low 32-bits of the address of the isolated app
+ * @param size  The size of the isolated app binary
  * @return zero on success, non-zero on failure
  */
-static inline int __write_mbox_sync(struct spe_context *spe, unsigned int data)
+static inline int __write_isolated_load_params(struct spe_context *spe,
+		uint32_t addr_h, uint32_t addr_l, uint32_t size)
 {
-	while (_base_spe_in_mbox_status(spe) == 0);
-	return _base_spe_in_mbox_write(spe, &data, 1,
-			SPE_MBOX_ALL_BLOCKING) != 1;
+	int fd = _base_spe_open_if_closed(spe, FD_WBOX, 0);
+
+	if (fd < 0) {
+		DEBUG_PRINTF("%s: can't open wbox\n", __FUNCTION__);
+		return -1;
+	}
+
+	if ((write(fd, &addr_h, sizeof(uint32_t)) != sizeof(uint32_t)) ||
+	    (write(fd, &addr_l, sizeof(uint32_t)) != sizeof(uint32_t)) ||
+	    (write(fd, &size,   sizeof(uint32_t)) != sizeof(uint32_t))) {
+		DEBUG_PRINTF("%s: error writing to wbox\n", __FUNCTION__);
+		return -1;
+	}
+
+	return 0;
 }
 
 /**
@@ -108,9 +124,7 @@ static int spe_start_isolated_app(struct
 	DEBUG_PRINTF("%s: Sending isolated app params: 0x%08x 0x%08x 0x%08x\n",
 			__FUNCTION__, addr_h, addr_l, size);
 
-	if (__write_mbox_sync(spe, addr_h) ||
-		__write_mbox_sync(spe, addr_l) ||
-		__write_mbox_sync(spe, size)) {
+	if (__write_isolated_load_params(spe, addr_h, addr_l, size)) {
 		errno = EIO;
 		return -errno;
 	}
Index: libspe2/spebase/run.c
===================================================================
--- libspe2.orig/spebase/run.c
+++ libspe2/spebase/run.c
@@ -28,6 +28,7 @@
 #include <unistd.h>
 
 #include <sys/types.h>
+#include <sys/mman.h>
 
 #include <sys/spu.h>
 
@@ -76,7 +77,7 @@ static int issue_isolated_exit(struct sp
 	struct spe_spu_control_area *cntl_area =
 		spe->base_private->cntl_mmap_base;
 
-	if (!cntl_area) {
+	if (cntl_area == MAP_FAILED) {
 		DEBUG_PRINTF("%s: could not access SPE control area\n",
 				__FUNCTION__);
 		return -1;



More information about the cbe-oss-dev mailing list