aboutsummaryrefslogtreecommitdiff
path: root/libgo/runtime/go-signal.c
diff options
context:
space:
mode:
authorIan Lance Taylor <ian@gcc.gnu.org>2011-03-27 19:14:55 +0000
committerIan Lance Taylor <ian@gcc.gnu.org>2011-03-27 19:14:55 +0000
commitc29301d6b19c28277b5a419e74297261d66e719e (patch)
tree697642cd2e886980983c07df0c23953228a22714 /libgo/runtime/go-signal.c
parentd253656a7be7461c2fc7bb638e93b9943a91de9b (diff)
downloadgcc-c29301d6b19c28277b5a419e74297261d66e719e.zip
gcc-c29301d6b19c28277b5a419e74297261d66e719e.tar.gz
gcc-c29301d6b19c28277b5a419e74297261d66e719e.tar.bz2
Add runtime profiling infrastructure, not yet working.
From-SVN: r171579
Diffstat (limited to 'libgo/runtime/go-signal.c')
-rw-r--r--libgo/runtime/go-signal.c106
1 files changed, 78 insertions, 28 deletions
diff --git a/libgo/runtime/go-signal.c b/libgo/runtime/go-signal.c
index 8898f84..edeeccc 100644
--- a/libgo/runtime/go-signal.c
+++ b/libgo/runtime/go-signal.c
@@ -6,6 +6,7 @@
#include <signal.h>
#include <stdlib.h>
+#include <sys/time.h>
#include "go-assert.h"
#include "go-panic.h"
@@ -13,10 +14,8 @@
#include "runtime.h"
-#undef int
-
-#ifndef SA_ONSTACK
-#define SA_ONSTACK 0
+#ifndef SA_RESTART
+ #define SA_RESTART 0
#endif
/* What to do for a signal. */
@@ -27,68 +26,70 @@ struct sigtab
int sig;
/* Nonzero if the signal should be ignored. */
_Bool ignore;
+ /* Nonzero if we should restart system calls. */
+ _Bool restart;
};
/* What to do for signals. */
static struct sigtab signals[] =
{
- { SIGHUP, 0 },
- { SIGINT, 0 },
- { SIGALRM, 1 },
- { SIGTERM, 0 },
+ { SIGHUP, 0, 1 },
+ { SIGINT, 0, 1 },
+ { SIGALRM, 1, 1 },
+ { SIGTERM, 0, 1 },
#ifdef SIGBUS
- { SIGBUS, 0 },
+ { SIGBUS, 0, 0 },
#endif
#ifdef SIGFPE
- { SIGFPE, 0 },
+ { SIGFPE, 0, 0 },
#endif
#ifdef SIGUSR1
- { SIGUSR1, 1 },
+ { SIGUSR1, 1, 1 },
#endif
#ifdef SIGSEGV
- { SIGSEGV, 0 },
+ { SIGSEGV, 0, 0 },
#endif
#ifdef SIGUSR2
- { SIGUSR2, 1 },
+ { SIGUSR2, 1, 1 },
#endif
#ifdef SIGPIPE
- { SIGPIPE, 1 },
+ { SIGPIPE, 1, 0 },
#endif
#ifdef SIGCHLD
- { SIGCHLD, 1 },
+ { SIGCHLD, 1, 1 },
#endif
#ifdef SIGTSTP
- { SIGTSTP, 1 },
+ { SIGTSTP, 1, 1 },
#endif
#ifdef SIGTTIN
- { SIGTTIN, 1 },
+ { SIGTTIN, 1, 1 },
#endif
#ifdef SIGTTOU
- { SIGTTOU, 1 },
+ { SIGTTOU, 1, 1 },
#endif
#ifdef SIGURG
- { SIGURG, 1 },
+ { SIGURG, 1, 1 },
#endif
#ifdef SIGXCPU
- { SIGXCPU, 1 },
+ { SIGXCPU, 1, 1 },
#endif
#ifdef SIGXFSZ
- { SIGXFSZ, 1 },
+ { SIGXFSZ, 1, 1 },
#endif
#ifdef SIGVTARLM
- { SIGVTALRM, 1 },
+ { SIGVTALRM, 1, 1 },
#endif
#ifdef SIGWINCH
- { SIGWINCH, 1 },
+ { SIGWINCH, 1, 1 },
#endif
#ifdef SIGIO
- { SIGIO, 1 },
+ { SIGIO, 1, 1 },
#endif
#ifdef SIGPWR
- { SIGPWR, 1 },
+ { SIGPWR, 1, 1 },
#endif
- { -1, 0 }
+ { -1, 0, 0 }
};
/* The Go signal handler. */
@@ -99,6 +100,13 @@ sighandler (int sig)
const char *msg;
int i;
+ if (sig == SIGPROF)
+ {
+ /* FIXME. */
+ runtime_sigprof (0, 0, nil);
+ return;
+ }
+
/* FIXME: Should check siginfo for more information when
available. */
msg = NULL;
@@ -192,6 +200,48 @@ __initsig ()
__go_assert (i == 0);
for (i = 0; signals[i].sig != -1; ++i)
- if (sigaction (signals[i].sig, &sa, NULL) != 0)
- __go_assert (0);
+ {
+ sa.sa_flags = signals[i].restart ? SA_RESTART : 0;
+ if (sigaction (signals[i].sig, &sa, NULL) != 0)
+ __go_assert (0);
+ }
+}
+
+void
+runtime_resetcpuprofiler(int32 hz)
+{
+ struct itimerval it;
+ struct sigaction sa;
+ int i;
+
+ memset (&it, 0, sizeof it);
+
+ memset (&sa, 0, sizeof sa);
+ i = sigfillset (&sa.sa_mask);
+ __go_assert (i == 0);
+
+ if (hz == 0)
+ {
+ i = setitimer (ITIMER_PROF, &it, NULL);
+ __go_assert (i == 0);
+
+ sa.sa_handler = SIG_IGN;
+ i = sigaction (SIGPROF, &sa, NULL);
+ __go_assert (i == 0);
+ }
+ else
+ {
+ sa.sa_handler = sighandler;
+ sa.sa_flags = SA_RESTART;
+ i = sigaction (SIGPROF, &sa, NULL);
+ __go_assert (i == 0);
+
+ it.it_interval.tv_sec = 0;
+ it.it_interval.tv_usec = 1000000 / hz;
+ it.it_value = it.it_interval;
+ i = setitimer (ITIMER_PROF, &it, NULL);
+ __go_assert (i == 0);
+ }
+
+ m->profilehz = hz;
}