From: Arnaldo Carvalho de Melo <acme@infradead.org>
To: Ingo Molnar <mingo@kernel.org>
Cc: linux-kernel@vger.kernel.org,
Arnaldo Carvalho de Melo <acme@redhat.com>,
Adrian Hunter <adrian.hunter@intel.com>,
David Ahern <dsahern@gmail.com>,
Frederic Weisbecker <fweisbec@gmail.com>,
Jiri Olsa <jolsa@redhat.com>, Mike Galbraith <efault@gmx.de>,
Namhyung Kim <namhyung@kernel.org>,
Paul Mackerras <paulus@samba.org>,
Peter Zijlstra <peterz@infradead.org>,
Stephane Eranian <eranian@google.com>
Subject: [PATCH 03/38] perf evlist: Move the SIGUSR1 error reporting logic to prepare_workload
Date: Mon, 13 Jan 2014 17:47:04 -0300 [thread overview]
Message-ID: <1389646059-24881-4-git-send-email-acme@infradead.org> (raw)
In-Reply-To: <1389646059-24881-1-git-send-email-acme@infradead.org>
From: Arnaldo Carvalho de Melo <acme@redhat.com>
So that we have the boilerplate in the preparation method, instead of
open coded in tools wanting the reporting when the exec fails.
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Link: http://lkml.kernel.org/n/tip-purbdzcphdveskh7wwmnm4t7@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
tools/perf/builtin-record.c | 16 ++--------------
tools/perf/builtin-stat.c | 17 ++---------------
tools/perf/builtin-trace.c | 2 +-
tools/perf/tests/perf-record.c | 3 +--
tools/perf/tests/task-exit.c | 19 ++++++++++++++-----
tools/perf/util/evlist.c | 12 ++++++++++--
tools/perf/util/evlist.h | 3 ++-
7 files changed, 32 insertions(+), 40 deletions(-)
diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c
index f987d385c6f0..ea7c3060e8e7 100644
--- a/tools/perf/builtin-record.c
+++ b/tools/perf/builtin-record.c
@@ -390,7 +390,7 @@ static int __cmd_record(struct record *rec, int argc, const char **argv)
if (forks) {
err = perf_evlist__prepare_workload(evsel_list, &opts->target,
argv, file->is_pipe,
- true);
+ workload_exec_failed_signal);
if (err < 0) {
pr_err("Couldn't run the workload!\n");
goto out_delete_session;
@@ -507,20 +507,8 @@ static int __cmd_record(struct record *rec, int argc, const char **argv)
/*
* Let the child rip
*/
- if (forks) {
- struct sigaction act = {
- .sa_flags = SA_SIGINFO,
- .sa_sigaction = workload_exec_failed_signal,
- };
- /*
- * perf_evlist__prepare_workload will, after we call
- * perf_evlist__start_Workload, send a SIGUSR1 if the exec call
- * fails, that we will catch in workload_signal to flip
- * workload_exec_errno.
- */
- sigaction(SIGUSR1, &act, NULL);
+ if (forks)
perf_evlist__start_workload(evsel_list);
- }
for (;;) {
int hits = rec->samples;
diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c
index 9d0d52d55ee6..f8456cad656d 100644
--- a/tools/perf/builtin-stat.c
+++ b/tools/perf/builtin-stat.c
@@ -58,7 +58,6 @@
#include "util/thread.h"
#include "util/thread_map.h"
-#include <signal.h>
#include <stdlib.h>
#include <sys/prctl.h>
#include <locale.h>
@@ -542,8 +541,8 @@ static int __run_perf_stat(int argc, const char **argv)
}
if (forks) {
- if (perf_evlist__prepare_workload(evsel_list, &target, argv,
- false, true) < 0) {
+ if (perf_evlist__prepare_workload(evsel_list, &target, argv, false,
+ workload_exec_failed_signal) < 0) {
perror("failed to prepare workload");
return -1;
}
@@ -598,18 +597,6 @@ static int __run_perf_stat(int argc, const char **argv)
clock_gettime(CLOCK_MONOTONIC, &ref_time);
if (forks) {
- struct sigaction act = {
- .sa_flags = SA_SIGINFO,
- .sa_sigaction = workload_exec_failed_signal,
- };
- /*
- * perf_evlist__prepare_workload will, after we call
- * perf_evlist__start_Workload, send a SIGUSR1 if the exec call
- * fails, that we will catch in workload_signal to flip
- * workload_exec_errno.
- */
- sigaction(SIGUSR1, &act, NULL);
-
perf_evlist__start_workload(evsel_list);
handle_initial_delay();
diff --git a/tools/perf/builtin-trace.c b/tools/perf/builtin-trace.c
index c5b4bc51175c..5498eacf8fc6 100644
--- a/tools/perf/builtin-trace.c
+++ b/tools/perf/builtin-trace.c
@@ -1895,7 +1895,7 @@ static int trace__run(struct trace *trace, int argc, const char **argv)
if (forks) {
err = perf_evlist__prepare_workload(evlist, &trace->opts.target,
- argv, false, false);
+ argv, false, NULL);
if (err < 0) {
fprintf(trace->output, "Couldn't run the workload!\n");
goto out_delete_maps;
diff --git a/tools/perf/tests/perf-record.c b/tools/perf/tests/perf-record.c
index eeba562920e9..fa0ed35afb9a 100644
--- a/tools/perf/tests/perf-record.c
+++ b/tools/perf/tests/perf-record.c
@@ -83,8 +83,7 @@ int test__PERF_RECORD(void)
* so that we have time to open the evlist (calling sys_perf_event_open
* on all the fds) and then mmap them.
*/
- err = perf_evlist__prepare_workload(evlist, &opts.target, argv,
- false, false);
+ err = perf_evlist__prepare_workload(evlist, &opts.target, argv, false, NULL);
if (err < 0) {
pr_debug("Couldn't run the workload!\n");
goto out_delete_maps;
diff --git a/tools/perf/tests/task-exit.c b/tools/perf/tests/task-exit.c
index d09ab579119e..44e339d4e297 100644
--- a/tools/perf/tests/task-exit.c
+++ b/tools/perf/tests/task-exit.c
@@ -9,12 +9,21 @@
static int exited;
static int nr_exit;
-static void sig_handler(int sig)
+static void sig_handler(int sig __maybe_unused)
{
exited = 1;
+}
- if (sig == SIGUSR1)
- nr_exit = -1;
+/*
+ * perf_evlist__prepare_workload will send a SIGUSR1 if the fork fails, since
+ * we asked by setting its exec_error to this handler.
+ */
+static void workload_exec_failed_signal(int signo __maybe_unused,
+ siginfo_t *info __maybe_unused,
+ void *ucontext __maybe_unused)
+{
+ exited = 1;
+ nr_exit = -1;
}
/*
@@ -35,7 +44,6 @@ int test__task_exit(void)
const char *argv[] = { "true", NULL };
signal(SIGCHLD, sig_handler);
- signal(SIGUSR1, sig_handler);
evlist = perf_evlist__new_default();
if (evlist == NULL) {
@@ -57,7 +65,8 @@ int test__task_exit(void)
goto out_delete_maps;
}
- err = perf_evlist__prepare_workload(evlist, &target, argv, false, true);
+ err = perf_evlist__prepare_workload(evlist, &target, argv, false,
+ workload_exec_failed_signal);
if (err < 0) {
pr_debug("Couldn't run the workload!\n");
goto out_delete_maps;
diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c
index 4a30c87d24ec..96b3ef547db4 100644
--- a/tools/perf/util/evlist.c
+++ b/tools/perf/util/evlist.c
@@ -1029,7 +1029,7 @@ out_err:
int perf_evlist__prepare_workload(struct perf_evlist *evlist, struct target *target,
const char *argv[], bool pipe_output,
- bool want_signal)
+ void (*exec_error)(int signo, siginfo_t *info, void *ucontext))
{
int child_ready_pipe[2], go_pipe[2];
char bf;
@@ -1073,7 +1073,7 @@ int perf_evlist__prepare_workload(struct perf_evlist *evlist, struct target *tar
execvp(argv[0], (char **)argv);
- if (want_signal) {
+ if (exec_error) {
union sigval val;
val.sival_int = errno;
@@ -1084,6 +1084,14 @@ int perf_evlist__prepare_workload(struct perf_evlist *evlist, struct target *tar
exit(-1);
}
+ if (exec_error) {
+ struct sigaction act = {
+ .sa_flags = SA_SIGINFO,
+ .sa_sigaction = exec_error,
+ };
+ sigaction(SIGUSR1, &act, NULL);
+ }
+
if (target__none(target))
evlist->threads->map[0] = evlist->workload.pid;
diff --git a/tools/perf/util/evlist.h b/tools/perf/util/evlist.h
index 2fe51958ed85..18d1222c0762 100644
--- a/tools/perf/util/evlist.h
+++ b/tools/perf/util/evlist.h
@@ -103,7 +103,8 @@ int record_opts__config(struct record_opts *opts);
int perf_evlist__prepare_workload(struct perf_evlist *evlist,
struct target *target,
const char *argv[], bool pipe_output,
- bool want_signal);
+ void (*exec_error)(int signo, siginfo_t *info,
+ void *ucontext));
int perf_evlist__start_workload(struct perf_evlist *evlist);
int perf_evlist__parse_mmap_pages(const struct option *opt,
--
1.8.1.4
next prev parent reply other threads:[~2014-01-13 20:54 UTC|newest]
Thread overview: 42+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-01-13 20:47 [GIT PULL 00/38] perf/core improvements and fixes Arnaldo Carvalho de Melo
2014-01-13 20:47 ` [PATCH 01/38] perf stat: Don't show counter information when workload fails Arnaldo Carvalho de Melo
2014-01-13 20:47 ` [PATCH 02/38] perf evlist: Send the errno in the signal " Arnaldo Carvalho de Melo
2014-01-13 20:47 ` Arnaldo Carvalho de Melo [this message]
2014-01-13 20:47 ` [PATCH 04/38] perf record: Remove old evsel_list usage Arnaldo Carvalho de Melo
2014-01-13 20:47 ` [PATCH 05/38] perf evlist: Move destruction of maps to evlist destructor Arnaldo Carvalho de Melo
2014-01-13 20:47 ` [PATCH 06/38] perf evlist: Close fds on destructor Arnaldo Carvalho de Melo
2014-01-13 20:47 ` [PATCH 07/38] perf evlist: Auto unmap " Arnaldo Carvalho de Melo
2014-01-13 20:47 ` [PATCH 08/38] perf tests: Fixup leak on error path in parse events test Arnaldo Carvalho de Melo
2014-01-13 20:47 ` [PATCH 09/38] perf stat: Remove misplaced __maybe_unused Arnaldo Carvalho de Melo
2014-01-13 20:47 ` [PATCH 10/38] perf tools: Move arch setup into seprate Makefile Arnaldo Carvalho de Melo
2014-01-13 20:47 ` [PATCH 11/38] perf tests: Fix installation tests path setup Arnaldo Carvalho de Melo
2014-01-13 20:47 ` [PATCH 12/38] tools lib traceevent: Replace tabs with spaces for all non-commands statements Arnaldo Carvalho de Melo
2014-01-13 20:47 ` [PATCH 13/38] tools lib traceevent: Shut up plugins make message Arnaldo Carvalho de Melo
2014-01-13 20:47 ` [PATCH 14/38] perf header: Pack 'struct perf_session_env' Arnaldo Carvalho de Melo
2014-01-13 20:47 ` [PATCH 15/38] perf trace: Pack 'struct trace' Arnaldo Carvalho de Melo
2014-01-13 20:47 ` [PATCH 16/38] perf tools: Automate setup of FEATURE_CHECK_(C|LD)FLAGS-all variables Arnaldo Carvalho de Melo
2014-01-13 20:47 ` [PATCH 17/38] perf machine: Fix id_hdr_size initialization Arnaldo Carvalho de Melo
2014-01-13 20:47 ` [PATCH 18/38] perf tools: Make perf_event__synthesize_mmap_events global Arnaldo Carvalho de Melo
2014-01-13 20:47 ` [PATCH 19/38] perf stat: Fix --delay option in man page Arnaldo Carvalho de Melo
2014-01-13 20:47 ` [PATCH 20/38] tools perf: Comment typo fix Arnaldo Carvalho de Melo
2014-01-13 20:47 ` [PATCH 21/38] perf report: Move logic to warn about kptr_restrict'ed kernels to separate function Arnaldo Carvalho de Melo
2014-01-13 20:47 ` [PATCH 22/38] perf report: Move hist browser selection code " Arnaldo Carvalho de Melo
2014-01-13 20:47 ` [PATCH 23/38] perf report: Move histogram entries collapsing " Arnaldo Carvalho de Melo
2014-01-13 20:47 ` [PATCH 24/38] perf evlist: Introduce evlist__for_each() & friends Arnaldo Carvalho de Melo
2014-01-13 20:47 ` [PATCH 25/38] tools include: Move perf's linux/compiler.h to a generic place Arnaldo Carvalho de Melo
2014-01-13 20:47 ` [PATCH 26/38] tools include: Define likely/unlikely in linux/compiler.h Arnaldo Carvalho de Melo
2014-01-13 20:47 ` [PATCH 27/38] tools include: Move perf's bug.h to a generic place Arnaldo Carvalho de Melo
2014-01-13 20:47 ` [PATCH 28/38] perf tools: Include tools/lib/api/ in MANIFEST Arnaldo Carvalho de Melo
2014-01-13 20:47 ` [PATCH 29/38] perf tools: Add test for building detached source tarballs Arnaldo Carvalho de Melo
2014-01-13 20:47 ` [PATCH 30/38] perf tools: Use the DWARF unwind info only if loaded Arnaldo Carvalho de Melo
2014-01-13 20:47 ` [PATCH 31/38] perf record: Add --initial-delay option Arnaldo Carvalho de Melo
2014-01-13 20:47 ` [PATCH 32/38] tools include: Include <linux/compiler.h> from asm/bug.h Arnaldo Carvalho de Melo
2014-01-13 20:47 ` [PATCH 33/38] perf tools: Generalize percent_color_snprintf() Arnaldo Carvalho de Melo
2014-01-13 20:47 ` [PATCH 34/38] perf diff: Color the Delta column Arnaldo Carvalho de Melo
2014-01-13 20:47 ` [PATCH 35/38] perf diff: Color the Ratio column Arnaldo Carvalho de Melo
2014-01-13 20:47 ` [PATCH 36/38] perf diff: Color the Weighted Diff column Arnaldo Carvalho de Melo
2014-01-13 20:47 ` [PATCH 37/38] perf probe: Fix build when DWARF support libraries not present Arnaldo Carvalho de Melo
2014-01-13 20:47 ` [PATCH 38/38] perf tools: Remove unused test-volatile-register-var.c Arnaldo Carvalho de Melo
2014-01-14 13:41 ` [GIT PULL 00/38] perf/core improvements and fixes Ingo Molnar
2014-01-14 14:03 ` Arnaldo Carvalho de Melo
2014-01-14 16:24 ` Ingo Molnar
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=1389646059-24881-4-git-send-email-acme@infradead.org \
--to=acme@infradead.org \
--cc=acme@redhat.com \
--cc=adrian.hunter@intel.com \
--cc=dsahern@gmail.com \
--cc=efault@gmx.de \
--cc=eranian@google.com \
--cc=fweisbec@gmail.com \
--cc=jolsa@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@kernel.org \
--cc=namhyung@kernel.org \
--cc=paulus@samba.org \
--cc=peterz@infradead.org \
/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 NNTP newsgroup(s).