[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <1460643725-167413-2-git-send-email-wangnan0@huawei.com>
Date: Thu, 14 Apr 2016 14:22:00 +0000
From: Wang Nan <wangnan0@...wei.com>
To: <acme@...nel.org>
CC: <linux-kernel@...r.kernel.org>, <pi3orama@....com>,
Wang Nan <wangnan0@...wei.com>,
Arnaldo Carvalho de Melo <acme@...hat.com>,
"Adrian Hunter" <adrian.hunter@...el.com>,
Jiri Olsa <jolsa@...nel.org>,
"Masami Hiramatsu" <mhiramat@...nel.org>,
Namhyung Kim <namhyung@...nel.org>,
Zefan Li <lizefan@...wei.com>, He Kuang <hekuang@...wei.com>
Subject: [PATCH v2 1/6] perf tools: Extrace trigger class from auxtrace_snapshot
Create a new 'class' named 'trigger' to model state of a trigger
and implement auxtrace_snapshot with it.
'trigger' defines 3 state transfering functions ('on', 'enable',
'disable') and 1 state query function ('is_enabled'). The state
'ON' and 'OFF' take higher priority than 'ENABLED' and 'DISABLED'.
A trigger must be 'on' before 'enable' and 'disable' take effect.
Signed-off-by: Wang Nan <wangnan0@...wei.com>
Cc: Arnaldo Carvalho de Melo <acme@...hat.com>
Cc: Adrian Hunter <adrian.hunter@...el.com>
Cc: Jiri Olsa <jolsa@...nel.org>
Cc: Masami Hiramatsu <mhiramat@...nel.org>
Cc: Namhyung Kim <namhyung@...nel.org>
Cc: Zefan Li <lizefan@...wei.com>
Cc: pi3orama@....com
Cc: He Kuang <hekuang@...wei.com>
---
tools/perf/builtin-record.c | 37 +-------------------------------
tools/perf/util/util.h | 51 +++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 52 insertions(+), 36 deletions(-)
diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c
index 3239a6e..13fe9a6 100644
--- a/tools/perf/builtin-record.c
+++ b/tools/perf/builtin-record.c
@@ -127,42 +127,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 DEFINE_TRIGGER(auxtrace_snapshot, OFF);
static volatile int auxtrace_snapshot_err;
static volatile int auxtrace_record__snapshot_started;
diff --git a/tools/perf/util/util.h b/tools/perf/util/util.h
index 3bf3de8..8121029 100644
--- a/tools/perf/util/util.h
+++ b/tools/perf/util/util.h
@@ -361,4 +361,55 @@ typedef void (*print_binary_t)(enum binary_printer_ops,
void print_binary(unsigned char *data, size_t len,
size_t bytes_per_line, print_binary_t printer,
void *extra);
+
+struct trigger {
+ volatile enum {
+ TRIGGER_OFF = -1,
+ TRIGGER_DISABLED = 0,
+ TRIGGER_ENABLED = 1,
+ } state;
+};
+
+static inline void
+trigger_on(struct trigger *s)
+{
+ s->state = TRIGGER_DISABLED;
+}
+
+static inline void
+trigger_enable(struct trigger *s)
+{
+ if (s->state != TRIGGER_OFF)
+ s->state = TRIGGER_ENABLED;
+}
+
+static inline void
+trigger_disable(struct trigger *s)
+{
+ if (s->state != TRIGGER_OFF)
+ s->state = TRIGGER_DISABLED;
+}
+
+static inline bool
+trigger_is_enabled(struct trigger *s)
+{
+ if (s->state != TRIGGER_OFF)
+ return s->state == TRIGGER_ENABLED;
+ return false;
+}
+
+#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};\
+__DEF_TRIGGER_VOID_FUNC(n, on) \
+__DEF_TRIGGER_VOID_FUNC(n, enable) \
+__DEF_TRIGGER_VOID_FUNC(n, disable) \
+__DEF_TRIGGER_FUNC(n, bool, is_enabled)
+
#endif /* GIT_COMPAT_UTIL_H */
--
1.8.3.4
Powered by blists - more mailing lists