This is the mail archive of the
newlib@sourceware.org
mailing list for the newlib project.
[patch] SPU gprof enhancements
- From: Ken Werner <ken at linux dot vnet dot ibm dot com>
- To: newlib at sourceware dot org
- Date: Fri, 3 Apr 2009 14:18:40 +0200
- Subject: [patch] SPU gprof enhancements
Hi,
the attached patch enables initial support for simultaneous SPU profiling. It
relies on the linux_getpid patch.
Regards
Ken
libgloss/ChangeLog:
2009-04-02 Ken Werner <ken.werner@de.ibm.com>
* spu/crt0.S (_start): Place spu_id in the first agument register.
newlib/ChangeLog:
2009-03-02 Ken Werner <ken.werner@de.ibm.com>
* libc/machine/spu/spu-gmon.c: Tweaks to support simultaneous SPU
profiling.
Index: src/libgloss/spu/crt0.S
===================================================================
--- src.orig/libgloss/spu/crt0.S
+++ src/libgloss/spu/crt0.S
@@ -161,9 +161,13 @@ _start:
#ifdef _PROFILE
/* Call monstartup if profiling is enabled
*/
+#ifdef _STD_MAIN
+ ila $3,0
+#else
+ ori $3,$80,0
+#endif
brsl $LR, __monstartup
#endif
-
ori $3,$80,0
ori $4,$81,0
#ifndef _STD_MAIN
Index: src/newlib/libc/machine/spu/spu-gmon.c
===================================================================
--- src.orig/newlib/libc/machine/spu/spu-gmon.c
+++ src/newlib/libc/machine/spu/spu-gmon.c
@@ -43,6 +43,7 @@ Author: Ken Werner <ken.werner@de.ibm.co
#include <spu_mfcio.h>
#include <spu_timer.h>
#include <limits.h>
+#include <sys/linux_syscalls.h>
/* Magic cookie. */
#define GMON_MAGIC_COOKIE "gmon"
@@ -113,6 +114,13 @@ struct rawarc
extern char _start;
extern char _etext;
+/* EAR entry for the starting address of SPE executable image. */
+extern const unsigned long long _EAR_;
+asm (".section .toe,\"a\",@nobits\n\r"
+ ".align 4\n\r"
+ ".type _EAR_, @object\n\r"
+ ".size _EAR_, 16\n" "_EAR_: .space 16\n" ".previous");
+
/* froms are indexing tos */
static __ea unsigned short *froms;
static __ea struct tostruct *tos = 0;
@@ -251,8 +259,9 @@ __mcleanup (void)
}
void
-__monstartup (void)
+__monstartup (unsigned long long spu_id)
{
+ char filename[64];
s_lowpc =
ROUNDDOWN ((uintptr_t) & _start, HISTFRACTION * sizeof (HISTCOUNTER));
s_highpc =
@@ -284,23 +293,35 @@ __monstartup (void)
}
memset_ea (tos, 0, tolimit * sizeof (struct tostruct));
+ /* Determine the gmon.out file name. */
+ if (spu_id)
+ snprintf (filename, sizeof (filename), "gmon-%d-%llu-%llu.out",
+ linux_getpid (), spu_id, _EAR_);
+ else
+ strncpy (filename, "gmon.out", sizeof (filename));
/* Open the gmon.out file. */
- fd = open ("gmon.out", O_RDWR | O_CREAT | O_TRUNC, 0644);
+ fd = open (filename, O_RDWR | O_CREAT | O_TRUNC, 0644);
if (fd == -1)
{
- perror ("can't open gmon.out file");
+ char errstr[128];
+ snprintf (errstr, sizeof (errstr), "Cannot open file: %s", filename);
+ perror (errstr);
return;
}
/* Truncate the file up to the size where the histogram fits in. */
if (ftruncate (fd,
- sizeof (struct gmon_hdr) + 1 + sizeof (struct gmon_hist_hdr) + hist_size) ==
- -1)
- perror ("can't truncate the gmon.out file");
+ sizeof (struct gmon_hdr) + 1 +
+ sizeof (struct gmon_hist_hdr) + hist_size) == -1)
+ {
+ char errstr[128];
+ snprintf (errstr, sizeof (errstr), "Cannot truncate file: %s", filename);
+ perror (errstr);
+ return;
+ }
/* Start the histogram sampler. */
spu_slih_register (MFC_DECREMENTER_EVENT, spu_clock_slih);
- timer_id = spu_timer_alloc (spu_timebase () / SAMPLE_INTERVAL,
- __sample);
+ timer_id = spu_timer_alloc (spu_timebase () / SAMPLE_INTERVAL, __sample);
spu_clock_start ();
spu_timer_start (timer_id);