From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 27858 invoked by alias); 9 Sep 2009 16:33:09 -0000 Received: (qmail 27695 invoked by uid 22791); 9 Sep 2009 16:33:06 -0000 X-SWARE-Spam-Status: No, hits=-0.8 required=5.0 tests=AWL,BAYES_00,J_CHICKENPOX_35,J_CHICKENPOX_62,J_CHICKENPOX_66,SPF_HELO_PASS,SPF_PASS X-Spam-Check-By: sourceware.org Received: from mx1-old.redhat.com (HELO mx1.redhat.com) (66.187.233.31) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Wed, 09 Sep 2009 16:33:01 +0000 Received: from int-mx01.intmail.prod.int.phx2.redhat.com ([10.11.47.254]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id n89GWwbh013188 for ; Wed, 9 Sep 2009 12:32:59 -0400 Received: from localhost.localdomain (dhcp-100-3-156.bos.redhat.com [10.16.3.156]) by int-mx01.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id n89GWwZM022470; Wed, 9 Sep 2009 12:32:58 -0400 From: Masami Hiramatsu Subject: [PATCH 2/3] Signal-based file switching support for old relay To: systemtap Date: Wed, 09 Sep 2009 16:33:00 -0000 Message-ID: <20090909163432.22599.64729.stgit@localhost.localdomain> In-Reply-To: <20090909163420.22599.87922.stgit@localhost.localdomain> References: <20090909163420.22599.87922.stgit@localhost.localdomain> User-Agent: StGIT/0.14.3 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit X-IsSubscribed: yes Mailing-List: contact systemtap-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Post: List-Help: , Sender: systemtap-owner@sourceware.org X-SW-Source: 2009-q3/txt/msg00633.txt.bz2 * runtime/staprun/relay_old.c (switch_oldoutfile): New function for file switching. (process_subbufs): Use switch_oldoutfile. (reader_thread): Block SIGUSR1 and SIGUSR2 in default, and use ppoll() instead of poll() for receiving SIGUSR2. (switchfile_handler): Send SIGUSR2 signal to reader threads for file switching. (init_oldrelayfs): Assign switchfile_handler to SIGUSR1. --- runtime/staprun/relay_old.c | 83 +++++++++++++++++++++++++++++++++++++------ 1 files changed, 71 insertions(+), 12 deletions(-) diff --git a/runtime/staprun/relay_old.c b/runtime/staprun/relay_old.c index 0254173..64bdf1c 100644 --- a/runtime/staprun/relay_old.c +++ b/runtime/staprun/relay_old.c @@ -19,6 +19,7 @@ static int proc_fd[NR_CPUS]; static FILE *percpu_tmpfile[NR_CPUS]; static char *relay_buffer[NR_CPUS]; static pthread_t reader[NR_CPUS]; +static int switch_file[NR_CPUS]; static int bulkmode = 0; unsigned subbuf_size = 0; unsigned n_subbufs = 0; @@ -214,6 +215,22 @@ err1: } +static int switch_oldoutfile(int cpu, struct switchfile_ctrl_block *scb) +{ + dbug(3, "thread %d switching file\n", cpu); + if (percpu_tmpfile[cpu]) + fclose(percpu_tmpfile[cpu]); + else + close(out_fd[cpu]); + scb->fnum ++; + if (fnum_max && scb->fnum == fnum_max) + scb->rmfile = 1; + if (open_oldoutfile(scb->fnum, cpu, scb->rmfile) < 0) { + perr("Couldn't open file for cpu %d, exiting.", cpu); + return -1; + } + return 0; +} /** * process_subbufs - write ready subbufs to disk */ @@ -238,11 +255,7 @@ static int process_subbufs(struct _stp_buf_info *info, len = (subbuf_size - sizeof(padding)) - padding; scb->wsize += len; if (fsize_max && scb->wsize > fsize_max) { - fclose(percpu_tmpfile[cpu]); - scb->fnum ++; - if (fnum_max && scb->fnum == fnum_max) - scb->rmfile = 1; - if (open_oldoutfile(scb->fnum, cpu, scb->rmfile) < 0) { + if (switch_oldoutfile(cpu, scb) < 0) { perr("Couldn't open file for cpu %d, exiting.", cpu); return -1; } @@ -264,6 +277,8 @@ static int process_subbufs(struct _stp_buf_info *info, /** * reader_thread - per-cpu channel buffer reader */ +static void empty_handler(int __attribute__((unused)) sig) { /* do nothing */ } + static void *reader_thread(void *data) { int rc; @@ -272,7 +287,23 @@ static void *reader_thread(void *data) struct _stp_consumed_info consumed_info; unsigned subbufs_consumed; cpu_set_t cpu_mask; + struct timespec tim = {.tv_sec=0, .tv_nsec=200000000}, *timeout = &tim; struct switchfile_ctrl_block scb = {0, 0, 0}; + sigset_t sigs; + struct sigaction sa; + + sigemptyset(&sigs); + sigaddset(&sigs,SIGUSR1); + sigaddset(&sigs,SIGUSR2); + pthread_sigmask(SIG_BLOCK, &sigs, NULL); + + sigfillset(&sigs); + sigdelset(&sigs,SIGUSR2); + + sa.sa_handler = empty_handler; + sa.sa_flags = 0; + sigemptyset(&sa.sa_mask); + sigaction(SIGUSR2, &sa, NULL); CPU_ZERO(&cpu_mask); CPU_SET(cpu, &cpu_mask); @@ -281,9 +312,17 @@ static void *reader_thread(void *data) pollfd.fd = relay_fd[cpu]; pollfd.events = POLLIN; +#ifdef NEED_PPOLL + /* Without a real ppoll, there is a small race condition that could */ + /* block ppoll(). So use a timeout to prevent that. */ + timeout->tv_sec = 10; + timeout->tv_nsec = 0; +#else + timeout = NULL; +#endif do { - rc = poll(&pollfd, 1, -1); + rc = ppoll(&pollfd, 1, timeout, &sigs); if (rc < 0) { if (errno != EINTR) { _perr("poll error"); @@ -292,6 +331,12 @@ static void *reader_thread(void *data) err("WARNING: poll warning: %s\n", strerror(errno)); rc = 0; } + if (switch_file[cpu]) { + switch_file[cpu] = 0; + if (switch_oldoutfile(cpu, &scb) < 0) + break; + scb.wsize = 0; + } rc = read(proc_fd[cpu], &status[cpu].info, sizeof(struct _stp_buf_info)); rc = process_subbufs(&status[cpu].info, &scb); @@ -324,12 +369,7 @@ int write_realtime_data(void *data, ssize_t nb) ssize_t bw; global_scb.wsize += nb; if (fsize_max && global_scb.wsize > fsize_max) { - close(out_fd[0]); - global_scb.fnum++; - if (fnum_max && global_scb.fnum == fnum_max) - global_scb.rmfile = 1; - if (open_oldoutfile(global_scb.fnum, 0, - global_scb.rmfile) < 0) { + if (switch_oldoutfile(0, &global_scb) < 0) { perr("Couldn't open file, exiting."); return -1; } @@ -343,6 +383,19 @@ int write_realtime_data(void *data, ssize_t nb) return bw != nb; } +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 * @@ -353,6 +406,12 @@ int init_oldrelayfs(void) int i, j; struct statfs st; char relay_filebase[PATH_MAX], proc_filebase[PATH_MAX]; + struct sigaction sa; + + sa.sa_handler = switchfile_handler; + sa.sa_flags = 0; + sigemptyset(&sa.sa_mask); + sigaction(SIGUSR1, &sa, NULL); dbug(2, "initializing relayfs.n_subbufs=%d subbuf_size=%d\n", n_subbufs, subbuf_size); -- Masami Hiramatsu Software Engineer Hitachi Computer Products (America), Inc. Software Solutions Division e-mail: mhiramat@redhat.com