Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756648AbcDNOYz (ORCPT ); Thu, 14 Apr 2016 10:24:55 -0400 Received: from szxga01-in.huawei.com ([58.251.152.64]:13864 "EHLO szxga01-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753766AbcDNOWn (ORCPT ); Thu, 14 Apr 2016 10:22:43 -0400 From: Wang Nan To: CC: , , Wang Nan , Arnaldo Carvalho de Melo , "Adrian Hunter" , Jiri Olsa , "Masami Hiramatsu" , Namhyung Kim , Zefan Li , He Kuang Subject: [PATCH v2 1/6] perf tools: Extrace trigger class from auxtrace_snapshot Date: Thu, 14 Apr 2016 14:22:00 +0000 Message-ID: <1460643725-167413-2-git-send-email-wangnan0@huawei.com> X-Mailer: git-send-email 1.8.3.4 In-Reply-To: <1460643725-167413-1-git-send-email-wangnan0@huawei.com> References: <1460643725-167413-1-git-send-email-wangnan0@huawei.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.107.193.248] X-CFilter-Loop: Reflected X-Mirapoint-Virus-RAPID-Raw: score=unknown(0), refid=str=0001.0A020204.570FA79D.026B,ss=1,re=0.000,recu=0.000,reip=0.000,cl=1,cld=1,fgs=0, ip=0.0.0.0, so=2013-06-18 04:22:30, dmn=2013-03-21 17:37:32 X-Mirapoint-Loop-Id: acaba654c38585364d4d89e2bd5b8bc8 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 3746 Lines: 132 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 Cc: Arnaldo Carvalho de Melo Cc: Adrian Hunter Cc: Jiri Olsa Cc: Masami Hiramatsu Cc: Namhyung Kim Cc: Zefan Li Cc: pi3orama@163.com Cc: He Kuang --- 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