From: Masami Hiramatsu <mhiramat@redhat.com>
To: systemtap<systemtap@sources.redhat.com>
Subject: [PATCH 1/3] Signal-based file switching support for relay/ring buffer.
Date: Wed, 09 Sep 2009 16:33:00 -0000 [thread overview]
Message-ID: <20090909163426.22599.78814.stgit@localhost.localdomain> (raw)
In-Reply-To: <20090909163420.22599.87922.stgit@localhost.localdomain>
* runtime/staprun/relay_old.c (switch_outfile): New function for file
switching.
(reader_thread): Use switch_oldoutfile and block SIGUSR1 and SIGUSR2
in default.
(switchfile_handler): Send SIGUSR2 signal to reader threads for file
switching.
(init_relayfs): Assign switchfile_handler to SIGUSR1.
---
runtime/staprun/relay.c | 60 ++++++++++++++++++++++++++++++++++++++---------
1 files changed, 49 insertions(+), 11 deletions(-)
diff --git a/runtime/staprun/relay.c b/runtime/staprun/relay.c
index f4aa139..362a251 100644
--- a/runtime/staprun/relay.c
+++ b/runtime/staprun/relay.c
@@ -15,6 +15,7 @@
int out_fd[NR_CPUS];
static pthread_t reader[NR_CPUS];
static int relay_fd[NR_CPUS];
+static int switch_file[NR_CPUS];
static int bulkmode = 0;
static volatile int stop_threads = 0;
static time_t *time_backlog[NR_CPUS];
@@ -107,6 +108,21 @@ static int open_outfile(int fnum, int cpu, int remove_file)
return 0;
}
+static int switch_outfile(int cpu, int *fnum)
+{
+ int remove_file = 0;
+
+ dbug(3, "thread %d switching file\n", cpu);
+ close(out_fd[cpu]);
+ *fnum += 1;
+ if (fnum_max && *fnum >= fnum_max)
+ remove_file = 1;
+ if (open_outfile(*fnum, cpu, remove_file) < 0) {
+ perr("Couldn't open file for cpu %d, exiting.", cpu);
+ return -1;
+ }
+ return 0;
+}
/**
* reader_thread - per-cpu channel buffer reader
*/
@@ -122,9 +138,9 @@ static void *reader_thread(void *data)
struct sigaction sa;
off_t wsize = 0;
int fnum = 0;
- int remove_file = 0;
sigemptyset(&sigs);
+ sigaddset(&sigs,SIGUSR1);
sigaddset(&sigs,SIGUSR2);
pthread_sigmask(SIG_BLOCK, &sigs, NULL);
@@ -156,6 +172,7 @@ static void *reader_thread(void *data)
pollfd.events = POLLIN;
do {
+ dbug(3, "thread %d start ppoll\n", cpu);
rc = ppoll(&pollfd, 1, timeout, &sigs);
if (rc < 0) {
dbug(3, "cpu=%d poll=%d errno=%d\n", cpu, rc, errno);
@@ -164,25 +181,27 @@ static void *reader_thread(void *data)
goto error_out;
}
}
+ dbug(3, "thread %d end ppoll\n", cpu);
+ if (switch_file[cpu]) {
+ switch_file[cpu] = 0;
+ if (switch_outfile(cpu, &fnum) < 0)
+ goto error_out;
+ wsize = 0;
+ }
+
while ((rc = read(relay_fd[cpu], buf, sizeof(buf))) > 0) {
- wsize += rc;
/* Switching file */
- if (fsize_max && wsize > fsize_max) {
- close(out_fd[cpu]);
- fnum++;
- if (fnum_max && fnum == fnum_max)
- remove_file = 1;
- if (open_outfile(fnum, cpu, remove_file) < 0) {
- perr("Couldn't open file for cpu %d, exiting.", cpu);
+ if (fsize_max && wsize + rc > fsize_max) {
+ if (switch_outfile(cpu, &fnum) < 0)
goto error_out;
- }
- wsize = rc;
+ wsize = 0;
}
if (write(out_fd[cpu], buf, rc) != rc) {
if (errno != EPIPE)
perr("Couldn't write to output %d for cpu %d, exiting.", out_fd[cpu], cpu);
goto error_out;
}
+ wsize += rc;
}
} while (!stop_threads);
dbug(3, "exiting thread for cpu %d\n", cpu);
@@ -195,6 +214,19 @@ error_out:
return(NULL);
}
+static void switchfile_handler(int sig)
+{
+ int i;
+ dbug(3, "file switching signal %d received\n", sig);
+ for (i = 0; i < ncpus; i++) {
+ if (reader[i]) {
+ switch_file[i] = 1;
+ pthread_kill(reader[i], SIGUSR2);
+ } else
+ break;
+ }
+}
+
/**
* init_relayfs - create files and threads for relayfs processing
*
@@ -308,6 +340,12 @@ int init_relayfs(void)
}
if (!load_only) {
+ struct sigaction sa;
+
+ sa.sa_handler = switchfile_handler;
+ sa.sa_flags = 0;
+ sigemptyset(&sa.sa_mask);
+ sigaction(SIGUSR1, &sa, NULL);
dbug(2, "starting threads\n");
for (i = 0; i < ncpus; i++) {
if (pthread_create(&reader[i], NULL, reader_thread,
--
Masami Hiramatsu
Software Engineer
Hitachi Computer Products (America), Inc.
Software Solutions Division
e-mail: mhiramat@redhat.com
next prev parent reply other threads:[~2009-09-09 16:33 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-09-09 16:32 [PATCH 0/3] Signal-based file switching support Masami Hiramatsu
2009-09-09 16:33 ` Masami Hiramatsu [this message]
2009-09-09 16:33 ` [PATCH 3/3] Add signal based file switching testcase Masami Hiramatsu
2009-09-09 16:33 ` [PATCH 2/3] Signal-based file switching support for old relay Masami Hiramatsu
2009-09-12 0:48 ` [PATCH 0/3] Signal-based file switching support Masami Hiramatsu
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20090909163426.22599.78814.stgit@localhost.localdomain \
--to=mhiramat@redhat.com \
--cc=systemtap@sources.redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).