[Cbe-oss-dev] [RFC/PATCH]Add debugging info for Tracing PPE-Assisted library calls

D. Herrendoerfer d.herrendoerfer at herrendoerfer.name
Wed May 16 15:16:20 EST 2007


This patch adds information to the PPE thread that is handling a
PPE-Assisted call so the debugger can associate a SPE program to the
running call.
This info is placed in a thread local variable and points to the SPE fd
that is currently stopped.

This patch also initializes the SPE registers 1 and 2 with stack size
and start as defined in the SPE ABI.

Signed-Off-by: D.Herrendoerfer <herrend at de.ibm.com>

Index: libspe2/spebase/run.c
===================================================================
--- libspe2/spebase/run.c	(revision 39)
+++ libspe2/spebase/run.c	(working copy)
@@ -22,6 +22,7 @@
 #include <fcntl.h>
 #include <stdio.h>
 #include <stdint.h>
+#include <stdlib.h>
 #include <string.h>
 #include <syscall.h>
 #include <unistd.h>
@@ -34,6 +35,14 @@
 #include "lib_builtin.h"
 #include "spebase.h"
 
+/*Thread-local variable for use by the debugger*/
+__thread struct spe_context_info {
+	struct spe_thread_info *prev;
+	int spe_id;
+	unsigned int npc_p;
+	unsigned int status_p;
+} *__spe_current_active_context;
+
 static int set_regs(struct spe_context *spe, void *regs)
 {
 	int fd_regs, rc;
@@ -72,6 +81,14 @@ static int issue_isolated_exit(struct sp
 	return 0;
 }
 
+inline int freespeinfo()
+{
+	/*Clean up the debug variable*/
+	struct spe_context_info *tmp = __spe_current_active_context->prev;
+	free(__spe_current_active_context);
+	__spe_current_active_context = tmp;
+}
+
 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)
@@ -104,6 +121,10 @@ int _base_spe_context_run(spe_context_pt
 		/* make sure the register values are 0 */
 		memset(regs, 0, sizeof(regs));
 
+		/* set sensible values for stack_ptr and stack_size */
+		regs[1][0] = (unsigned int) LS_SIZE - 16; 	/* stack_ptr */
+		regs[2][0] = 0; 							/* stack_size ( 0 = default ) */
+
 		if (runflags & SPE_RUN_USER_REGS) {
 			/* When SPE_USER_REGS is set, argp points to an array
 			 * of 3x128b registers to be passed directly to the SPE
@@ -125,10 +146,34 @@ int _base_spe_context_run(spe_context_pt
 			return -1;
 	}
 
+	/*Leave a trail of breadcrumbs for the debugger to follow */
+	if (!__spe_current_active_context) {
+		__spe_current_active_context = malloc( sizeof(struct
spe_context_info));
+		if (!__spe_current_active_context)
+			return -1;
+		__spe_current_active_context->prev = NULL;
+	} else {
+		struct spe_context_info *newinfo;
+		newinfo = malloc( sizeof(struct spe_context_info));
+		if (!newinfo)
+			return -1;
+		newinfo->prev = __spe_current_active_context;
+		__spe_current_active_context = newinfo;
+	}
+	/*remember the ls-addr*/
+	__spe_current_active_context->spe_id = spe->base_private->fd_spe_dir;
+
 do_run:
+	/*Remember the npc value*/
+	__spe_current_active_context->npc_p = *entry;
+
 	/* run SPE context */
 	run_rc = spu_run(spe->base_private->fd_spe_dir, entry, &run_status);
 
+	/*Remember the npc value*/
+	__spe_current_active_context->npc_p = *entry;
+	__spe_current_active_context->status_p = run_status;
+
 	DEBUG_PRINTF("spu_run returned run_rc=0x%08x, entry=0x%04x, "
 			"ext_status=0x%04x.\n", run_rc, *entry, run_status);
 
@@ -156,7 +201,8 @@ do_run:
 			errno = EFAULT;
 		}
 
-		return -1;
+		freespeinfo();
+		return -1; 
 	}
 
 	if ((spe->base_private->flags & SPE_EVENTS_ENABLE)
@@ -277,5 +323,6 @@ do_run:
 
 	}
 
+	freespeinfo();
 	return retval;
 }

===================================================================

Best regards,

D.Herrendoerfer




More information about the cbe-oss-dev mailing list