summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorhunt <hunt>2007-04-02 17:03:57 +0000
committerhunt <hunt>2007-04-02 17:03:57 +0000
commitda5bc00621edbd01f290b8f779b075d3048c99a0 (patch)
treed982f578f7a116e98512a9cde171c808b3fe2d5d
parent81406e9df9fe0b6f52fce796f070c4419bdf7986 (diff)
downloadsystemtap-steved-da5bc00621edbd01f290b8f779b075d3048c99a0.tar.gz
systemtap-steved-da5bc00621edbd01f290b8f779b075d3048c99a0.tar.xz
systemtap-steved-da5bc00621edbd01f290b8f779b075d3048c99a0.zip
2007-04-02 Martin Hunt <hunt@redhat.com>
* relay_old.c (close_oldrelayfs): If just detaching, call pthread_cancel. (open_relayfs_files): Just return 0 if relay_fd[cpu] not opened. (init_oldrelayfs): Scan percpu files to calculate ncpus. * mainloop.c (init_staprun): Call old transport init when necessary. (cleanup_and_exit): Ignore signals when cleaning up. * ctl.c (read_buffer_info): For old transport, need to read transport parameters.
-rw-r--r--runtime/staprun/ChangeLog13
-rw-r--r--runtime/staprun/ctl.c36
-rw-r--r--runtime/staprun/mainloop.c23
-rw-r--r--runtime/staprun/relay_old.c69
-rw-r--r--runtime/staprun/staprun.h6
5 files changed, 112 insertions, 35 deletions
diff --git a/runtime/staprun/ChangeLog b/runtime/staprun/ChangeLog
index 324e9bf8..b948db55 100644
--- a/runtime/staprun/ChangeLog
+++ b/runtime/staprun/ChangeLog
@@ -1,3 +1,16 @@
+2007-04-02 Martin Hunt <hunt@redhat.com>
+
+ * relay_old.c (close_oldrelayfs): If just detaching, call
+ pthread_cancel.
+ (open_relayfs_files): Just return 0 if relay_fd[cpu] not opened.
+ (init_oldrelayfs): Scan percpu files to calculate ncpus.
+
+ * mainloop.c (init_staprun): Call old transport init when necessary.
+ (cleanup_and_exit): Ignore signals when cleaning up.
+
+ * ctl.c (read_buffer_info): For old transport, need to read transport
+ parameters.
+
2007-03-26 Martin Hunt <hunt@redhat.com>
* mainloop.c (run_stp_check): Just use system() call.
diff --git a/runtime/staprun/ctl.c b/runtime/staprun/ctl.c
index a217d270..95337f59 100644
--- a/runtime/staprun/ctl.c
+++ b/runtime/staprun/ctl.c
@@ -12,6 +12,40 @@
#include "staprun.h"
+/* This is only used in the old relayfs code */
+static void read_buffer_info(void)
+{
+ char buf[128];
+ struct statfs st;
+ int fd, len, ret;
+
+ if (!use_old_transport)
+ return;
+
+ if (statfs("/sys/kernel/debug", &st) == 0 && (int) st.f_type == (int) DEBUGFS_MAGIC)
+ return;
+
+ sprintf (buf, "/proc/systemtap/%s/bufsize", modname);
+ fd = open(buf, O_RDONLY);
+ if (fd < 0)
+ return;
+
+ len = read(fd, buf, sizeof(buf));
+ if (len <= 0) {
+ fprintf (stderr, "ERROR: couldn't read bufsize.\n");
+ close(fd);
+ return;
+ }
+ ret = sscanf(buf, "%u,%u", &n_subbufs, &subbuf_size);
+ if (ret != 2)
+ fprintf (stderr, "ERROR: couldn't read bufsize.\n");
+
+ dbug("n_subbufs= %u, size=%u\n", n_subbufs, subbuf_size);
+ close(fd);
+ return;
+}
+
+
int init_ctl_channel(void)
{
char buf[128];
@@ -32,6 +66,8 @@ int init_ctl_channel(void)
fprintf (stderr, "errcode = %s\n", strerror(errno));
return -1;
}
+
+ read_buffer_info();
return 0;
}
diff --git a/runtime/staprun/mainloop.c b/runtime/staprun/mainloop.c
index d3b3d3b7..720f9ec5 100644
--- a/runtime/staprun/mainloop.c
+++ b/runtime/staprun/mainloop.c
@@ -143,9 +143,16 @@ int init_staprun(void)
if (attach_mod) {
if (init_ctl_channel() < 0)
return -1;
- if (init_relayfs() < 0) {
- close_ctl_channel();
- return -1;
+ if (use_old_transport) {
+ if (init_oldrelayfs() < 0) {
+ close_ctl_channel();
+ return -1;
+ }
+ } else {
+ if (init_relayfs() < 0) {
+ close_ctl_channel();
+ return -1;
+ }
}
return 0;
}
@@ -204,6 +211,11 @@ void cleanup_and_exit (int closed)
pid_t err;
static int exiting = 0;
+ signal(SIGINT, SIG_IGN);
+ signal(SIGTERM, SIG_IGN);
+ signal(SIGHUP, SIG_IGN);
+ signal(SIGQUIT, SIG_IGN);
+
if (exiting)
return;
exiting = 1;
@@ -217,7 +229,7 @@ void cleanup_and_exit (int closed)
while(wait(NULL) > 0) ;
if (use_old_transport)
- close_oldrelayfs();
+ close_oldrelayfs(closed == 2);
else
close_relayfs();
@@ -228,8 +240,7 @@ void cleanup_and_exit (int closed)
dbug("removing module\n");
snprintf(tmpbuf, sizeof(tmpbuf), "/sbin/rmmod -w %s", modname);
if (system(tmpbuf)) {
- fprintf(stderr, "ERROR: couldn't rmmod probe module %s. No output will be written.\n",
- modname);
+ fprintf(stderr, "ERROR: couldn't rmmod probe module %s.\n", modname);
exit(1);
}
} else if (closed == 2) {
diff --git a/runtime/staprun/relay_old.c b/runtime/staprun/relay_old.c
index 80c38a6c..b0d2e43d 100644
--- a/runtime/staprun/relay_old.c
+++ b/runtime/staprun/relay_old.c
@@ -21,8 +21,8 @@ static FILE *percpu_tmpfile[NR_CPUS];
static char *relay_buffer[NR_CPUS];
static pthread_t reader[NR_CPUS];
static int bulkmode = 0;
-static unsigned subbuf_size = 0;
-static unsigned n_subbufs = 0;
+unsigned subbuf_size = 0;
+unsigned n_subbufs = 0;
/* per-cpu buffer info */
static struct buf_status
@@ -38,7 +38,6 @@ static struct buf_status
static void close_relayfs_files(int cpu)
{
size_t total_bufsize = subbuf_size * n_subbufs;
- dbug("%d %d %d\n", cpu,(int) total_bufsize, relay_fd[cpu]);
if (relay_fd[cpu]) {
munmap(relay_buffer[cpu], total_bufsize);
close(relay_fd[cpu]);
@@ -51,23 +50,30 @@ static void close_relayfs_files(int cpu)
/**
* close_all_relayfs_files - close and munmap buffers and output files
*/
-void close_oldrelayfs(void)
+void close_oldrelayfs(int detach)
{
int i;
if (!bulkmode)
return;
-
- dbug("close_relayfs: %d\n", ncpus);
- for (i = 0; i < ncpus; i++)
- if (reader[i]) pthread_join(reader[i], NULL);
-
+
+ dbug("detach=%d, ncpus=%d\n", detach, ncpus);
+
+ if (detach) {
+ for (i = 0; i < ncpus; i++)
+ if (reader[i]) pthread_cancel(reader[i]);
+ } else {
+ for (i = 0; i < ncpus; i++)
+ if (reader[i]) pthread_join(reader[i], NULL);
+ }
+
for (i = 0; i < ncpus; i++)
- close_relayfs_files(i);
+ close_relayfs_files(i);
}
/**
- * open_relayfs_files - open and mmap buffer and open output file
+ * open_relayfs_files - open and mmap buffer and open output file.
+ * Returns -1 on unexpected failure, 0 if file not found, 1 on success.
*/
static int open_relayfs_files(int cpu, const char *relay_filebase, const char *proc_filebase)
{
@@ -80,8 +86,8 @@ static int open_relayfs_files(int cpu, const char *relay_filebase, const char *p
sprintf(tmp, "%s%d", relay_filebase, cpu);
relay_fd[cpu] = open(tmp, O_RDONLY | O_NONBLOCK);
if (relay_fd[cpu] < 0) {
- fprintf(stderr, "ERROR: couldn't open relayfs file %s: errcode = %s\n", tmp, strerror(errno));
- goto err0;
+ relay_fd[cpu] = 0;
+ return 0;
}
sprintf(tmp, "%s%d", proc_filebase, cpu);
@@ -108,7 +114,7 @@ static int open_relayfs_files(int cpu, const char *relay_filebase, const char *p
goto err3;
}
- return 0;
+ return 1;
err3:
fclose(percpu_tmpfile[cpu]);
@@ -116,7 +122,6 @@ err2:
close (proc_fd[cpu]);
err1:
close (relay_fd[cpu]);
-err0:
relay_fd[cpu] = 0;
return -1;
@@ -216,13 +221,11 @@ int init_oldrelayfs(void)
struct statfs st;
char relay_filebase[128], proc_filebase[128];
- for (i = 0; i < ncpus; i++){
- reader[i] = (pthread_t)0;
- relay_fd[i] = 0;
- }
+ dbug("initializing relayfs.n_subbufs=%d subbuf_size=%d\n", n_subbufs, subbuf_size);
-// t->bulk_mode;
- bulkmode = 0;
+ if (n_subbufs)
+ bulkmode = 1;
+
if (!bulkmode) {
if (outfile_name) {
out_fd[0] = open (outfile_name, O_CREAT|O_TRUNC|O_WRONLY, 0666);
@@ -235,10 +238,6 @@ int init_oldrelayfs(void)
return 0;
}
- n_subbufs = 0; /* t->n_subbufs;*/
- subbuf_size = 0; /* t->subbuf_size; */
- dbug("initializing relayfs. n_subbufs=%d subbuf_size=%d\n",n_subbufs, subbuf_size);
-
if (statfs("/sys/kernel/debug", &st) == 0 && (int) st.f_type == (int) DEBUGFS_MAGIC) {
sprintf(relay_filebase, "/sys/kernel/debug/systemtap/%s/trace", modname);
sprintf(proc_filebase, "/sys/kernel/debug/systemtap/%s/", modname);
@@ -249,12 +248,26 @@ int init_oldrelayfs(void)
fprintf(stderr,"Cannot find relayfs or debugfs mount point.\n");
return -1;
}
-
- for (i = 0; i < ncpus; i++) {
- if (open_relayfs_files(i, relay_filebase, proc_filebase) < 0) {
+
+
+ reader[0] = (pthread_t)0;
+ relay_fd[0] = 0;
+ out_fd[0] = 0;
+
+ for (i = 0; i < NR_CPUS; i++) {
+ int ret = open_relayfs_files(i, relay_filebase, proc_filebase);
+ if (ret == 0)
+ break;
+ if (ret < 0) {
fprintf(stderr, "ERROR: couldn't open relayfs files, cpu = %d\n", i);
goto err;
}
+ }
+
+ ncpus = i;
+ dbug("ncpus=%d\n", ncpus);
+
+ for (i = 0; i < ncpus; i++) {
/* create a thread for each per-cpu buffer */
if (pthread_create(&reader[i], NULL, reader_thread, (void *)(long)i) < 0) {
close_relayfs_files(i);
diff --git a/runtime/staprun/staprun.h b/runtime/staprun/staprun.h
index 36fbd940..c3599de6 100644
--- a/runtime/staprun/staprun.h
+++ b/runtime/staprun/staprun.h
@@ -68,7 +68,7 @@ void close_ctl_channel(void);
int init_relayfs(void);
void close_relayfs(void);
int init_oldrelayfs(void);
-void close_oldrelayfs(void);
+void close_oldrelayfs(int);
/*
* variables
@@ -97,3 +97,7 @@ extern gid_t cmd_gid;
/* relay*.c uses these */
extern int out_fd[NR_CPUS];
+
+/* relay_old uses these. Set in ctl.c */
+extern unsigned subbuf_size;
+extern unsigned n_subbufs;