aboutsummaryrefslogtreecommitdiffstats
path: root/tools/perf
diff options
context:
space:
mode:
authorWang Nan <wangnan0@huawei.com>2016-04-20 14:59:48 -0400
committerArnaldo Carvalho de Melo <acme@redhat.com>2016-04-28 08:58:58 -0400
commit3dcc4436fa6f09ce093ff59bf8477c3059dc46df (patch)
tree74053f598a114a1c21e2d72199083c2ff2ade9ea /tools/perf
parent909b0360ae358f212f526e171ea4ef433b1b4103 (diff)
perf tools: Introduce trigger class
Use 'trigger' to model operations which need to be executed when an event (a signal, for example) is observed. States and transits: OFF--(on)--> READY --(hit)--> HIT ^ | | (ready) | | \_____________/ is_hit and is_ready are two key functions to query the state of a trigger. is_hit means the event already happen; is_ready means the trigger is waiting for the event. Signed-off-by: Wang Nan <wangnan0@huawei.com> Acked-by: Adrian 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-2-git-send-email-wangnan0@huawei.com Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools/perf')
-rw-r--r--tools/perf/util/trigger.h94
1 files changed, 94 insertions, 0 deletions
diff --git a/tools/perf/util/trigger.h b/tools/perf/util/trigger.h
new file mode 100644
index 000000000000..e97d7016d771
--- /dev/null
+++ b/tools/perf/util/trigger.h
@@ -0,0 +1,94 @@
1#ifndef __TRIGGER_H_
2#define __TRIGGER_H_ 1
3
4#include "util/debug.h"
5#include "asm/bug.h"
6
7/*
8 * Use trigger to model operations which need to be executed when
9 * an event (a signal, for example) is observed.
10 *
11 * States and transits:
12 *
13 *
14 * OFF--(on)--> READY --(hit)--> HIT
15 * ^ |
16 * | (ready)
17 * | |
18 * \_____________/
19 *
20 * is_hit and is_ready are two key functions to query the state of
21 * a trigger. is_hit means the event already happen; is_ready means the
22 * trigger is waiting for the event.
23 */
24
25struct trigger {
26 volatile enum {
27 TRIGGER_ERROR = -2,
28 TRIGGER_OFF = -1,
29 TRIGGER_READY = 0,
30 TRIGGER_HIT = 1,
31 } state;
32 const char *name;
33};
34
35#define TRIGGER_WARN_ONCE(t, exp) \
36 WARN_ONCE(t->state != exp, "trigger '%s' state transist error: %d in %s()\n", \
37 t->name, t->state, __func__)
38
39static inline bool trigger_is_available(struct trigger *t)
40{
41 return t->state >= 0;
42}
43
44static inline bool trigger_is_error(struct trigger *t)
45{
46 return t->state <= TRIGGER_ERROR;
47}
48
49static inline void trigger_on(struct trigger *t)
50{
51 TRIGGER_WARN_ONCE(t, TRIGGER_OFF);
52 t->state = TRIGGER_READY;
53}
54
55static inline void trigger_ready(struct trigger *t)
56{
57 if (!trigger_is_available(t))
58 return;
59 t->state = TRIGGER_READY;
60}
61
62static inline void trigger_hit(struct trigger *t)
63{
64 if (!trigger_is_available(t))
65 return;
66 TRIGGER_WARN_ONCE(t, TRIGGER_READY);
67 t->state = TRIGGER_HIT;
68}
69
70static inline void trigger_off(struct trigger *t)
71{
72 if (!trigger_is_available(t))
73 return;
74 t->state = TRIGGER_OFF;
75}
76
77static inline void trigger_error(struct trigger *t)
78{
79 t->state = TRIGGER_ERROR;
80}
81
82static inline bool trigger_is_ready(struct trigger *t)
83{
84 return t->state == TRIGGER_READY;
85}
86
87static inline bool trigger_is_hit(struct trigger *t)
88{
89 return t->state == TRIGGER_HIT;
90}
91
92#define DEFINE_TRIGGER(n) \
93struct trigger n = {.state = TRIGGER_OFF, .name = #n}
94#endif