mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Wang Nan <wangnan0@huawei.com>
To: <acme@kernel.org>
Cc: <linux-kernel@vger.kernel.org>, <pi3orama@163.com>,
	Wang Nan <wangnan0@huawei.com>,
	Arnaldo Carvalho de Melo <acme@redhat.com>,
	"Adrian Hunter" <adrian.hunter@intel.com>,
	Jiri Olsa <jolsa@kernel.org>,
	"Masami Hiramatsu" <mhiramat@kernel.org>,
	Namhyung Kim <namhyung@kernel.org>, Zefan Li <lizefan@huawei.com>,
	He Kuang <hekuang@huawei.com>
Subject: [PATCH v2 1/6] perf tools: Extrace trigger class from auxtrace_snapshot
Date: Thu, 14 Apr 2016 14:22:00 +0000	[thread overview]
Message-ID: <1460643725-167413-2-git-send-email-wangnan0@huawei.com> (raw)
In-Reply-To: <1460643725-167413-1-git-send-email-wangnan0@huawei.com>

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@huawei.com>
Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Adrian Hunter <adrian.hunter@intel.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
Cc: He Kuang <hekuang@huawei.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

  reply	other threads:[~2016-04-14 14:24 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-04-14 14:21 [PATCH v2 0/6] perf tools: Use SIGUSR2 control data dumpping Wang Nan
2016-04-14 14:22 ` Wang Nan [this message]
2016-04-14 14:22 ` [PATCH v2 2/6] perf record: Split output into multiple files via '--switch-output' Wang Nan
2016-04-14 23:59   ` Arnaldo Carvalho de Melo
2016-04-14 14:22 ` [PATCH v2 3/6] perf record: Force enable --timestamp-filename when --switch-output is provided Wang Nan
2016-04-14 14:22 ` [PATCH v2 4/6] perf record: Disable buildid cache options by default in switch output mode Wang Nan
2016-04-14 14:22 ` [PATCH v2 5/6] perf record: Re-synthesize tracking events after output switching Wang Nan
2016-04-14 14:22 ` [PATCH v2 6/6] perf record: Generate tracking events for process forked by perf Wang Nan
2016-04-15  0:19 ` [PATCH v2 0/6] perf tools: Use SIGUSR2 control data dumpping Arnaldo Carvalho de Melo
2016-04-15 13:14   ` Adrian Hunter
2016-04-15 13:35     ` Arnaldo Carvalho de Melo
2016-04-15 13:41       ` Wangnan (F)

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=1460643725-167413-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=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®