From: Wang Nan <wangnan0@huawei.com>
To: <acme@kernel.org>, <jolsa@redhat.com>
Cc: <linux-kernel@vger.kernel.org>, <pi3orama@163.com>,
Wang Nan <wangnan0@huawei.com>,
Adrian Hunter <adrian.hunter@intel.com>,
He Kuang <hekuang@huawei.com>, Jiri Olsa <jolsa@kernel.org>,
Masami Hiramatsu <mhiramat@kernel.org>,
Namhyung Kim <namhyung@kernel.org>, Zefan Li <lizefan@huawei.com>,
Arnaldo Carvalho de Melo <acme@redhat.com>
Subject: [PATCH v3 1/6] perf tools: Derive trigger class from auxtrace_snapshot
Date: Fri, 15 Apr 2016 18:20:15 +0000 [thread overview]
Message-ID: <1460744420-175165-2-git-send-email-wangnan0@huawei.com> (raw)
In-Reply-To: <1460744420-175165-1-git-send-email-wangnan0@huawei.com>
Create a new class named 'trigger' to model the state of a trigger and
implement auxtrace_snapshot with it.
auxtrace_record__snapshot_started and auxtrace_snapshot_err are absorbed.
'trigger' defines 4 state transitioning functions ('on', 'released',
'toggle' and 'colddown') and 2 state query function ('is_released') and
('is_toggled'). The state 'ON' and 'OFF' take higher priority than
'RELEASED' and 'TOGGLED'. A trigger must be 'on' before 'enable' and
'disable' take effect. A trigger can be colddown after being triggered.
Signed-off-by: Wang Nan <wangnan0@huawei.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: He Kuang <hekuang@huawei.com>
Cc: Jiri Olsa <jolsa@kernel.org>
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/1460643725-167413-2-git-send-email-wangnan0@huawei.com
[ Moved the trigger definitions to trigger.h ]
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
tools/perf/builtin-record.c | 73 ++++++++-----------------------
tools/perf/util/trigger.h | 103 ++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 122 insertions(+), 54 deletions(-)
create mode 100644 tools/perf/util/trigger.h
diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c
index 3239a6e..cfaa2df 100644
--- a/tools/perf/builtin-record.c
+++ b/tools/perf/builtin-record.c
@@ -34,6 +34,7 @@
#include "util/parse-regs-options.h"
#include "util/llvm-utils.h"
#include "util/bpf-loader.h"
+#include "util/trigger.h"
#include "asm/bug.h"
#include <unistd.h>
@@ -127,44 +128,7 @@ static volatile int done;
static volatile int signr = -1;
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 DEFINE_TRIGGER(auxtrace_snapshot, OFF);
static void sig_handler(int sig)
{
@@ -282,11 +246,12 @@ static void record__read_auxtrace_snapshot(struct record *rec)
{
pr_debug("Recording AUX area tracing snapshot\n");
if (record__auxtrace_read_snapshot_all(rec) < 0) {
- auxtrace_snapshot_err = -1;
+ auxtrace_snapshot_error();
} else {
- auxtrace_snapshot_err = auxtrace_record__snapshot_finish(rec->itr);
- if (!auxtrace_snapshot_err)
- auxtrace_snapshot_enable();
+ if (auxtrace_record__snapshot_finish(rec->itr))
+ auxtrace_snapshot_error();
+ else
+ auxtrace_snapshot_release();
}
}
@@ -815,21 +780,21 @@ static int __cmd_record(struct record *rec, int argc, const char **argv)
perf_evlist__enable(rec->evlist);
}
- auxtrace_snapshot_enable();
+ auxtrace_snapshot_release();
for (;;) {
unsigned long long hits = rec->samples;
if (record__mmap_read_all(rec) < 0) {
- auxtrace_snapshot_disable();
+ auxtrace_snapshot_error();
err = -1;
goto out_child;
}
- if (auxtrace_record__snapshot_started) {
- auxtrace_record__snapshot_started = 0;
- if (!auxtrace_snapshot_err)
+ if (auxtrace_snapshot_is_toggled()) {
+ auxtrace_snapshot_colddown();
+ if (!auxtrace_snapshot_is_error())
record__read_auxtrace_snapshot(rec);
- if (auxtrace_snapshot_err) {
+ if (auxtrace_snapshot_is_error()) {
pr_err("AUX area tracing snapshot failed\n");
err = -1;
goto out_child;
@@ -858,12 +823,12 @@ static int __cmd_record(struct record *rec, int argc, const char **argv)
* disable events in this case.
*/
if (done && !disabled && !target__none(&opts->target)) {
- auxtrace_snapshot_disable();
+ auxtrace_snapshot_off();
perf_evlist__disable(rec->evlist);
disabled = true;
}
}
- auxtrace_snapshot_disable();
+ auxtrace_snapshot_off();
if (forks && workload_exec_errno) {
char msg[STRERR_BUFSIZE];
@@ -1442,9 +1407,9 @@ out_symbol_exit:
static void snapshot_sig_handler(int sig __maybe_unused)
{
- if (!auxtrace_snapshot_is_enabled())
+ if (!auxtrace_snapshot_is_released())
return;
- auxtrace_snapshot_disable();
- auxtrace_snapshot_err = auxtrace_record__snapshot_start(record.itr);
- auxtrace_record__snapshot_started = 1;
+ auxtrace_snapshot_toggle();
+ if (auxtrace_record__snapshot_start(record.itr))
+ auxtrace_snapshot_error();
}
diff --git a/tools/perf/util/trigger.h b/tools/perf/util/trigger.h
new file mode 100644
index 0000000..162c1c8
--- /dev/null
+++ b/tools/perf/util/trigger.h
@@ -0,0 +1,103 @@
+#ifndef __TRIGGER_H_
+#define __TRIGGER_H_ 1
+
+struct trigger {
+ volatile enum {
+ TRIGGER_OFF = -1,
+ TRIGGER_RELEASED = 0,
+ TRIGGER_TOGGLED = 1,
+ TRIGGER_COLDDOWN = 2,
+ } state;
+ volatile bool error;
+};
+
+static inline void trigger_on(struct trigger *s)
+{
+ if (s->error)
+ return;
+ s->state = TRIGGER_RELEASED;
+}
+
+static inline void trigger_release(struct trigger *s)
+{
+ if (s->error)
+ return;
+ if (s->state != TRIGGER_OFF)
+ s->state = TRIGGER_RELEASED;
+}
+
+static inline void trigger_toggle(struct trigger *s)
+{
+ if (s->error)
+ return;
+ if (s->state != TRIGGER_OFF)
+ s->state = TRIGGER_TOGGLED;
+}
+
+static inline void trigger_colddown(struct trigger *s)
+{
+ if (s->error)
+ return;
+ if (s->state == TRIGGER_TOGGLED)
+ s->state = TRIGGER_COLDDOWN;
+}
+
+static inline void trigger_off(struct trigger *s)
+{
+ if (s->error)
+ return;
+ if (s->state != TRIGGER_OFF)
+ s->state = TRIGGER_OFF;
+}
+
+static inline void trigger_error(struct trigger *s)
+{
+ if (s->error)
+ return;
+ trigger_off(s);
+ s->error = true;
+}
+
+static inline bool trigger_is_released(struct trigger *s)
+{
+ if (s->error)
+ return false;
+ if (s->state != TRIGGER_OFF)
+ return s->state == TRIGGER_RELEASED;
+ return false;
+}
+
+static inline bool trigger_is_toggled(struct trigger *s)
+{
+ if (s->error)
+ return false;
+ if (s->state != TRIGGER_OFF)
+ return s->state == TRIGGER_TOGGLED;
+ return false;
+}
+
+static inline bool trigger_is_error(struct trigger *s)
+{
+ return s->error;
+}
+
+#define __TRIGGER_VAR(n) n##_state
+#define __DEF_TRIGGER_VOID_FUNC(n, op) \
+static inline void n##_##op(void) {trigger_##op(&__TRIGGER_VAR(n)); }
+
+#define __DEF_TRIGGER_FUNC(n, type, op) \
+static inline type n##_##op(void) {return trigger_##op(&__TRIGGER_VAR(n)); }
+
+#define DEFINE_TRIGGER(n, def) \
+struct trigger n##_state = {.state = TRIGGER_##def, .error = false,};\
+__DEF_TRIGGER_VOID_FUNC(n, on) \
+__DEF_TRIGGER_VOID_FUNC(n, release) \
+__DEF_TRIGGER_VOID_FUNC(n, toggle) \
+__DEF_TRIGGER_VOID_FUNC(n, colddown) \
+__DEF_TRIGGER_VOID_FUNC(n, off) \
+__DEF_TRIGGER_VOID_FUNC(n, error) \
+__DEF_TRIGGER_FUNC(n, bool, is_released) \
+__DEF_TRIGGER_FUNC(n, bool, is_toggled) \
+__DEF_TRIGGER_FUNC(n, bool, is_error)
+
+#endif
--
1.8.3.4
next prev parent reply other threads:[~2016-04-15 18:21 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-04-15 18:20 [PATCH v3 0/6] perf tools: Use SIGUSR2 control data dumpping Wang Nan
2016-04-15 18:20 ` Wang Nan [this message]
2016-04-17 11:50 ` [PATCH v3 1/6] perf tools: Derive trigger class from auxtrace_snapshot Jiri Olsa
2016-04-18 2:23 ` Wangnan (F)
2016-04-17 11:52 ` Jiri Olsa
2016-04-15 18:20 ` [PATCH v3 2/6] perf record: Split output into multiple files via '--switch-output' Wang Nan
2016-04-15 18:20 ` [PATCH v3 3/6] perf record: Force enable --timestamp-filename when --switch-output is provided Wang Nan
2016-04-15 18:20 ` [PATCH v3 4/6] perf record: Disable buildid cache options by default in switch output mode Wang Nan
2016-04-15 18:20 ` [PATCH v3 5/6] perf record: Re-synthesize tracking events after output switching Wang Nan
2016-04-15 18:20 ` [PATCH v3 6/6] perf record: Generate tracking events for process forked by perf Wang Nan
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=1460744420-175165-2-git-send-email-wangnan0@huawei.com \
--to=wangnan0@huawei.com \
--cc=acme@kernel.org \
--cc=acme@redhat.com \
--cc=adrian.hunter@intel.com \
--cc=hekuang@huawei.com \
--cc=jolsa@kernel.org \
--cc=jolsa@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=lizefan@huawei.com \
--cc=mhiramat@kernel.org \
--cc=namhyung@kernel.org \
--cc=pi3orama@163.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
all inboxes | Powered by JetHome®