Commit 5f9cf599 authored by Wang Nan's avatar Wang Nan Committed by Arnaldo Carvalho de Melo

perf tools: Derive trigger class from auxtrace_snapshot

auxtrace_snapshot_state matches the trigger model. Use trigger to
implement it. auxtrace_snapshot_state and auxtrace_snapshot_err are
absorbed.
Signed-off-by: default avatarWang Nan <wangnan0@huawei.com>
Acked-by: default avatarAdrian Hunter <adrian.hunter@intel.com>
Cc: He Kuang <hekuang@huawei.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Masami Hiramatsu <mhiramat@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Zefan Li <lizefan@huawei.com>
Cc: pi3orama@163.com
Link: http://lkml.kernel.org/r/1461178794-40467-3-git-send-email-wangnan0@huawei.comSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
parent 3dcc4436
...@@ -34,6 +34,7 @@ ...@@ -34,6 +34,7 @@
#include "util/parse-regs-options.h" #include "util/parse-regs-options.h"
#include "util/llvm-utils.h" #include "util/llvm-utils.h"
#include "util/bpf-loader.h" #include "util/bpf-loader.h"
#include "util/trigger.h"
#include "asm/bug.h" #include "asm/bug.h"
#include <unistd.h> #include <unistd.h>
...@@ -127,44 +128,8 @@ static volatile int done; ...@@ -127,44 +128,8 @@ static volatile int done;
static volatile int signr = -1; static volatile int signr = -1;
static volatile int child_finished; static volatile int child_finished;
static volatile enum {
AUXTRACE_SNAPSHOT_OFF = -1,
AUXTRACE_SNAPSHOT_DISABLED = 0,
AUXTRACE_SNAPSHOT_ENABLED = 1,
} auxtrace_snapshot_state = AUXTRACE_SNAPSHOT_OFF;
static inline void
auxtrace_snapshot_on(void)
{
auxtrace_snapshot_state = AUXTRACE_SNAPSHOT_DISABLED;
}
static inline void
auxtrace_snapshot_enable(void)
{
if (auxtrace_snapshot_state == AUXTRACE_SNAPSHOT_OFF)
return;
auxtrace_snapshot_state = AUXTRACE_SNAPSHOT_ENABLED;
}
static inline void
auxtrace_snapshot_disable(void)
{
if (auxtrace_snapshot_state == AUXTRACE_SNAPSHOT_OFF)
return;
auxtrace_snapshot_state = AUXTRACE_SNAPSHOT_DISABLED;
}
static inline bool
auxtrace_snapshot_is_enabled(void)
{
if (auxtrace_snapshot_state == AUXTRACE_SNAPSHOT_OFF)
return false;
return auxtrace_snapshot_state == AUXTRACE_SNAPSHOT_ENABLED;
}
static volatile int auxtrace_snapshot_err;
static volatile int auxtrace_record__snapshot_started; static volatile int auxtrace_record__snapshot_started;
static DEFINE_TRIGGER(auxtrace_snapshot_trigger);
static void sig_handler(int sig) static void sig_handler(int sig)
{ {
...@@ -282,11 +247,12 @@ static void record__read_auxtrace_snapshot(struct record *rec) ...@@ -282,11 +247,12 @@ static void record__read_auxtrace_snapshot(struct record *rec)
{ {
pr_debug("Recording AUX area tracing snapshot\n"); pr_debug("Recording AUX area tracing snapshot\n");
if (record__auxtrace_read_snapshot_all(rec) < 0) { if (record__auxtrace_read_snapshot_all(rec) < 0) {
auxtrace_snapshot_err = -1; trigger_error(&auxtrace_snapshot_trigger);
} else { } else {
auxtrace_snapshot_err = auxtrace_record__snapshot_finish(rec->itr); if (auxtrace_record__snapshot_finish(rec->itr))
if (!auxtrace_snapshot_err) trigger_error(&auxtrace_snapshot_trigger);
auxtrace_snapshot_enable(); else
trigger_ready(&auxtrace_snapshot_trigger);
} }
} }
...@@ -686,7 +652,7 @@ static int __cmd_record(struct record *rec, int argc, const char **argv) ...@@ -686,7 +652,7 @@ static int __cmd_record(struct record *rec, int argc, const char **argv)
if (rec->opts.auxtrace_snapshot_mode) { if (rec->opts.auxtrace_snapshot_mode) {
signal(SIGUSR2, snapshot_sig_handler); signal(SIGUSR2, snapshot_sig_handler);
auxtrace_snapshot_on(); trigger_on(&auxtrace_snapshot_trigger);
} else { } else {
signal(SIGUSR2, SIG_IGN); signal(SIGUSR2, SIG_IGN);
} }
...@@ -815,21 +781,21 @@ static int __cmd_record(struct record *rec, int argc, const char **argv) ...@@ -815,21 +781,21 @@ static int __cmd_record(struct record *rec, int argc, const char **argv)
perf_evlist__enable(rec->evlist); perf_evlist__enable(rec->evlist);
} }
auxtrace_snapshot_enable(); trigger_ready(&auxtrace_snapshot_trigger);
for (;;) { for (;;) {
unsigned long long hits = rec->samples; unsigned long long hits = rec->samples;
if (record__mmap_read_all(rec) < 0) { if (record__mmap_read_all(rec) < 0) {
auxtrace_snapshot_disable(); trigger_error(&auxtrace_snapshot_trigger);
err = -1; err = -1;
goto out_child; goto out_child;
} }
if (auxtrace_record__snapshot_started) { if (auxtrace_record__snapshot_started) {
auxtrace_record__snapshot_started = 0; auxtrace_record__snapshot_started = 0;
if (!auxtrace_snapshot_err) if (!trigger_is_error(&auxtrace_snapshot_trigger))
record__read_auxtrace_snapshot(rec); record__read_auxtrace_snapshot(rec);
if (auxtrace_snapshot_err) { if (trigger_is_error(&auxtrace_snapshot_trigger)) {
pr_err("AUX area tracing snapshot failed\n"); pr_err("AUX area tracing snapshot failed\n");
err = -1; err = -1;
goto out_child; goto out_child;
...@@ -858,12 +824,12 @@ static int __cmd_record(struct record *rec, int argc, const char **argv) ...@@ -858,12 +824,12 @@ static int __cmd_record(struct record *rec, int argc, const char **argv)
* disable events in this case. * disable events in this case.
*/ */
if (done && !disabled && !target__none(&opts->target)) { if (done && !disabled && !target__none(&opts->target)) {
auxtrace_snapshot_disable(); trigger_off(&auxtrace_snapshot_trigger);
perf_evlist__disable(rec->evlist); perf_evlist__disable(rec->evlist);
disabled = true; disabled = true;
} }
} }
auxtrace_snapshot_disable(); trigger_off(&auxtrace_snapshot_trigger);
if (forks && workload_exec_errno) { if (forks && workload_exec_errno) {
char msg[STRERR_BUFSIZE]; char msg[STRERR_BUFSIZE];
...@@ -1445,9 +1411,10 @@ int cmd_record(int argc, const char **argv, const char *prefix __maybe_unused) ...@@ -1445,9 +1411,10 @@ int cmd_record(int argc, const char **argv, const char *prefix __maybe_unused)
static void snapshot_sig_handler(int sig __maybe_unused) static void snapshot_sig_handler(int sig __maybe_unused)
{ {
if (!auxtrace_snapshot_is_enabled()) if (trigger_is_ready(&auxtrace_snapshot_trigger)) {
return; trigger_hit(&auxtrace_snapshot_trigger);
auxtrace_snapshot_disable(); auxtrace_record__snapshot_started = 1;
auxtrace_snapshot_err = auxtrace_record__snapshot_start(record.itr); if (auxtrace_record__snapshot_start(record.itr))
auxtrace_record__snapshot_started = 1; trigger_error(&auxtrace_snapshot_trigger);
}
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment