Commit b847cbdc authored by Jiri Olsa's avatar Jiri Olsa Committed by Arnaldo Carvalho de Melo

perf tools: Use allocated list for each parsed event

Switch from using static temporary event list into dynamically allocated
one. This way we dont need to pass temp list to the parse_events_parse
which makes the interface more clear.
Signed-off-by: default avatarJiri Olsa <jolsa@redhat.com>
Cc: Corey Ashford <cjashfor@linux.vnet.ibm.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Link: http://lkml.kernel.org/r/1337584373-2741-4-git-send-email-jolsa@redhat.comSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
parent 82ba1f2f
...@@ -26,8 +26,7 @@ struct event_symbol { ...@@ -26,8 +26,7 @@ struct event_symbol {
#ifdef PARSER_DEBUG #ifdef PARSER_DEBUG
extern int parse_events_debug; extern int parse_events_debug;
#endif #endif
int parse_events_parse(struct list_head *list, struct list_head *list_tmp, int parse_events_parse(struct list_head *list, int *idx);
int *idx);
#define CHW(x) .type = PERF_TYPE_HARDWARE, .config = PERF_COUNT_HW_##x #define CHW(x) .type = PERF_TYPE_HARDWARE, .config = PERF_COUNT_HW_##x
#define CSW(x) .type = PERF_TYPE_SOFTWARE, .config = PERF_COUNT_SW_##x #define CSW(x) .type = PERF_TYPE_SOFTWARE, .config = PERF_COUNT_SW_##x
...@@ -358,20 +357,30 @@ const char *__event_name(int type, u64 config) ...@@ -358,20 +357,30 @@ const char *__event_name(int type, u64 config)
return "unknown"; return "unknown";
} }
static int add_event(struct list_head *list, int *idx, static int add_event(struct list_head **_list, int *idx,
struct perf_event_attr *attr, char *name) struct perf_event_attr *attr, char *name)
{ {
struct perf_evsel *evsel; struct perf_evsel *evsel;
struct list_head *list = *_list;
if (!list) {
list = malloc(sizeof(*list));
if (!list)
return -ENOMEM;
INIT_LIST_HEAD(list);
}
event_attr_init(attr); event_attr_init(attr);
evsel = perf_evsel__new(attr, (*idx)++); evsel = perf_evsel__new(attr, (*idx)++);
if (!evsel) if (!evsel) {
free(list);
return -ENOMEM; return -ENOMEM;
}
list_add_tail(&evsel->node, list);
evsel->name = strdup(name); evsel->name = strdup(name);
list_add_tail(&evsel->node, list);
*_list = list;
return 0; return 0;
} }
...@@ -393,7 +402,7 @@ static int parse_aliases(char *str, const char *names[][MAX_ALIASES], int size) ...@@ -393,7 +402,7 @@ static int parse_aliases(char *str, const char *names[][MAX_ALIASES], int size)
return -1; return -1;
} }
int parse_events_add_cache(struct list_head *list, int *idx, int parse_events_add_cache(struct list_head **list, int *idx,
char *type, char *op_result1, char *op_result2) char *type, char *op_result1, char *op_result2)
{ {
struct perf_event_attr attr; struct perf_event_attr attr;
...@@ -454,7 +463,7 @@ int parse_events_add_cache(struct list_head *list, int *idx, ...@@ -454,7 +463,7 @@ int parse_events_add_cache(struct list_head *list, int *idx,
return add_event(list, idx, &attr, name); return add_event(list, idx, &attr, name);
} }
static int add_tracepoint(struct list_head *list, int *idx, static int add_tracepoint(struct list_head **list, int *idx,
char *sys_name, char *evt_name) char *sys_name, char *evt_name)
{ {
struct perf_event_attr attr; struct perf_event_attr attr;
...@@ -491,7 +500,7 @@ static int add_tracepoint(struct list_head *list, int *idx, ...@@ -491,7 +500,7 @@ static int add_tracepoint(struct list_head *list, int *idx,
return add_event(list, idx, &attr, name); return add_event(list, idx, &attr, name);
} }
static int add_tracepoint_multi(struct list_head *list, int *idx, static int add_tracepoint_multi(struct list_head **list, int *idx,
char *sys_name, char *evt_name) char *sys_name, char *evt_name)
{ {
char evt_path[MAXPATHLEN]; char evt_path[MAXPATHLEN];
...@@ -522,7 +531,7 @@ static int add_tracepoint_multi(struct list_head *list, int *idx, ...@@ -522,7 +531,7 @@ static int add_tracepoint_multi(struct list_head *list, int *idx,
return ret; return ret;
} }
int parse_events_add_tracepoint(struct list_head *list, int *idx, int parse_events_add_tracepoint(struct list_head **list, int *idx,
char *sys, char *event) char *sys, char *event)
{ {
int ret; int ret;
...@@ -566,7 +575,7 @@ parse_breakpoint_type(const char *type, struct perf_event_attr *attr) ...@@ -566,7 +575,7 @@ parse_breakpoint_type(const char *type, struct perf_event_attr *attr)
return 0; return 0;
} }
int parse_events_add_breakpoint(struct list_head *list, int *idx, int parse_events_add_breakpoint(struct list_head **list, int *idx,
void *ptr, char *type) void *ptr, char *type)
{ {
struct perf_event_attr attr; struct perf_event_attr attr;
...@@ -645,7 +654,7 @@ static int config_attr(struct perf_event_attr *attr, ...@@ -645,7 +654,7 @@ static int config_attr(struct perf_event_attr *attr,
return 0; return 0;
} }
int parse_events_add_numeric(struct list_head *list, int *idx, int parse_events_add_numeric(struct list_head **list, int *idx,
unsigned long type, unsigned long config, unsigned long type, unsigned long config,
struct list_head *head_config) struct list_head *head_config)
{ {
...@@ -663,7 +672,7 @@ int parse_events_add_numeric(struct list_head *list, int *idx, ...@@ -663,7 +672,7 @@ int parse_events_add_numeric(struct list_head *list, int *idx,
(char *) __event_name(type, config)); (char *) __event_name(type, config));
} }
int parse_events_add_pmu(struct list_head *list, int *idx, int parse_events_add_pmu(struct list_head **list, int *idx,
char *name, struct list_head *head_config) char *name, struct list_head *head_config)
{ {
struct perf_event_attr attr; struct perf_event_attr attr;
...@@ -696,7 +705,7 @@ void parse_events_update_lists(struct list_head *list_event, ...@@ -696,7 +705,7 @@ void parse_events_update_lists(struct list_head *list_event,
* list, for next event definition. * list, for next event definition.
*/ */
list_splice_tail(list_event, list_all); list_splice_tail(list_event, list_all);
INIT_LIST_HEAD(list_event); free(list_event);
} }
int parse_events_modifier(struct list_head *list, char *str) int parse_events_modifier(struct list_head *list, char *str)
...@@ -774,7 +783,7 @@ int parse_events(struct perf_evlist *evlist, const char *str, int unset __used) ...@@ -774,7 +783,7 @@ int parse_events(struct perf_evlist *evlist, const char *str, int unset __used)
#ifdef PARSER_DEBUG #ifdef PARSER_DEBUG
parse_events_debug = 1; parse_events_debug = 1;
#endif #endif
ret = parse_events_parse(&list, &list_tmp, &idx); ret = parse_events_parse(&list, &idx);
parse_events__flush_buffer(buffer); parse_events__flush_buffer(buffer);
parse_events__delete_buffer(buffer); parse_events__delete_buffer(buffer);
......
...@@ -68,25 +68,21 @@ int parse_events__term_num(struct parse_events__term **_term, ...@@ -68,25 +68,21 @@ int parse_events__term_num(struct parse_events__term **_term,
int parse_events__term_str(struct parse_events__term **_term, int parse_events__term_str(struct parse_events__term **_term,
int type_term, char *config, char *str); int type_term, char *config, char *str);
void parse_events__free_terms(struct list_head *terms); void parse_events__free_terms(struct list_head *terms);
int parse_events_modifier(struct list_head *list __used, char *str __used); int parse_events_modifier(struct list_head *list, char *str);
int parse_events_add_tracepoint(struct list_head *list, int *idx, int parse_events_add_tracepoint(struct list_head **list, int *idx,
char *sys, char *event); char *sys, char *event);
int parse_events_add_raw(struct perf_evlist *evlist, unsigned long config, int parse_events_add_numeric(struct list_head **list, int *idx,
unsigned long config1, unsigned long config2,
char *mod);
int parse_events_add_numeric(struct list_head *list, int *idx,
unsigned long type, unsigned long config, unsigned long type, unsigned long config,
struct list_head *head_config); struct list_head *head_config);
int parse_events_add_cache(struct list_head *list, int *idx, int parse_events_add_cache(struct list_head **list, int *idx,
char *type, char *op_result1, char *op_result2); char *type, char *op_result1, char *op_result2);
int parse_events_add_breakpoint(struct list_head *list, int *idx, int parse_events_add_breakpoint(struct list_head **list, int *idx,
void *ptr, char *type); void *ptr, char *type);
int parse_events_add_pmu(struct list_head *list, int *idx, int parse_events_add_pmu(struct list_head **list, int *idx,
char *pmu , struct list_head *head_config); char *pmu , struct list_head *head_config);
void parse_events_update_lists(struct list_head *list_event, void parse_events_update_lists(struct list_head *list_event,
struct list_head *list_all); struct list_head *list_all);
void parse_events_error(struct list_head *list_all, void parse_events_error(struct list_head *list_all,
struct list_head *list_event,
int *idx, char const *msg); int *idx, char const *msg);
int parse_events__test(void); int parse_events__test(void);
......
%name-prefix "parse_events_" %name-prefix "parse_events_"
%parse-param {struct list_head *list_all} %parse-param {struct list_head *list_all}
%parse-param {struct list_head *list_event}
%parse-param {int *idx} %parse-param {int *idx}
%{ %{
...@@ -41,6 +40,14 @@ do { \ ...@@ -41,6 +40,14 @@ do { \
%type <str> PE_MODIFIER_BP %type <str> PE_MODIFIER_BP
%type <head> event_config %type <head> event_config
%type <term> event_term %type <term> event_term
%type <head> event_pmu
%type <head> event_legacy_symbol
%type <head> event_legacy_cache
%type <head> event_legacy_mem
%type <head> event_legacy_tracepoint
%type <head> event_legacy_numeric
%type <head> event_legacy_raw
%type <head> event_def
%union %union
{ {
...@@ -62,13 +69,13 @@ event_def PE_MODIFIER_EVENT ...@@ -62,13 +69,13 @@ event_def PE_MODIFIER_EVENT
* (there could be more events added for multiple tracepoint * (there could be more events added for multiple tracepoint
* definitions via '*?'. * definitions via '*?'.
*/ */
ABORT_ON(parse_events_modifier(list_event, $2)); ABORT_ON(parse_events_modifier($1, $2));
parse_events_update_lists(list_event, list_all); parse_events_update_lists($1, list_all);
} }
| |
event_def event_def
{ {
parse_events_update_lists(list_event, list_all); parse_events_update_lists($1, list_all);
} }
event_def: event_pmu | event_def: event_pmu |
...@@ -82,71 +89,102 @@ event_def: event_pmu | ...@@ -82,71 +89,102 @@ event_def: event_pmu |
event_pmu: event_pmu:
PE_NAME '/' event_config '/' PE_NAME '/' event_config '/'
{ {
ABORT_ON(parse_events_add_pmu(list_event, idx, $1, $3)); struct list_head *list = NULL;
ABORT_ON(parse_events_add_pmu(&list, idx, $1, $3));
parse_events__free_terms($3); parse_events__free_terms($3);
$$ = list;
} }
event_legacy_symbol: event_legacy_symbol:
PE_VALUE_SYM '/' event_config '/' PE_VALUE_SYM '/' event_config '/'
{ {
struct list_head *list = NULL;
int type = $1 >> 16; int type = $1 >> 16;
int config = $1 & 255; int config = $1 & 255;
ABORT_ON(parse_events_add_numeric(list_event, idx, type, config, $3)); ABORT_ON(parse_events_add_numeric(&list, idx, type, config, $3));
parse_events__free_terms($3); parse_events__free_terms($3);
$$ = list;
} }
| |
PE_VALUE_SYM sep_slash_dc PE_VALUE_SYM sep_slash_dc
{ {
struct list_head *list = NULL;
int type = $1 >> 16; int type = $1 >> 16;
int config = $1 & 255; int config = $1 & 255;
ABORT_ON(parse_events_add_numeric(list_event, idx, type, config, NULL)); ABORT_ON(parse_events_add_numeric(&list, idx, type, config, NULL));
$$ = list;
} }
event_legacy_cache: event_legacy_cache:
PE_NAME_CACHE_TYPE '-' PE_NAME_CACHE_OP_RESULT '-' PE_NAME_CACHE_OP_RESULT PE_NAME_CACHE_TYPE '-' PE_NAME_CACHE_OP_RESULT '-' PE_NAME_CACHE_OP_RESULT
{ {
ABORT_ON(parse_events_add_cache(list_event, idx, $1, $3, $5)); struct list_head *list = NULL;
ABORT_ON(parse_events_add_cache(&list, idx, $1, $3, $5));
$$ = list;
} }
| |
PE_NAME_CACHE_TYPE '-' PE_NAME_CACHE_OP_RESULT PE_NAME_CACHE_TYPE '-' PE_NAME_CACHE_OP_RESULT
{ {
ABORT_ON(parse_events_add_cache(list_event, idx, $1, $3, NULL)); struct list_head *list = NULL;
ABORT_ON(parse_events_add_cache(&list, idx, $1, $3, NULL));
$$ = list;
} }
| |
PE_NAME_CACHE_TYPE PE_NAME_CACHE_TYPE
{ {
ABORT_ON(parse_events_add_cache(list_event, idx, $1, NULL, NULL)); struct list_head *list = NULL;
ABORT_ON(parse_events_add_cache(&list, idx, $1, NULL, NULL));
$$ = list;
} }
event_legacy_mem: event_legacy_mem:
PE_PREFIX_MEM PE_VALUE ':' PE_MODIFIER_BP sep_dc PE_PREFIX_MEM PE_VALUE ':' PE_MODIFIER_BP sep_dc
{ {
ABORT_ON(parse_events_add_breakpoint(list_event, idx, (void *) $2, $4)); struct list_head *list = NULL;
ABORT_ON(parse_events_add_breakpoint(&list, idx, (void *) $2, $4));
$$ = list;
} }
| |
PE_PREFIX_MEM PE_VALUE sep_dc PE_PREFIX_MEM PE_VALUE sep_dc
{ {
ABORT_ON(parse_events_add_breakpoint(list_event, idx, (void *) $2, NULL)); struct list_head *list = NULL;
ABORT_ON(parse_events_add_breakpoint(&list, idx, (void *) $2, NULL));
$$ = list;
} }
event_legacy_tracepoint: event_legacy_tracepoint:
PE_NAME ':' PE_NAME PE_NAME ':' PE_NAME
{ {
ABORT_ON(parse_events_add_tracepoint(list_event, idx, $1, $3)); struct list_head *list = NULL;
ABORT_ON(parse_events_add_tracepoint(&list, idx, $1, $3));
$$ = list;
} }
event_legacy_numeric: event_legacy_numeric:
PE_VALUE ':' PE_VALUE PE_VALUE ':' PE_VALUE
{ {
ABORT_ON(parse_events_add_numeric(list_event, idx, $1, $3, NULL)); struct list_head *list = NULL;
ABORT_ON(parse_events_add_numeric(&list, idx, $1, $3, NULL));
$$ = list;
} }
event_legacy_raw: event_legacy_raw:
PE_RAW PE_RAW
{ {
ABORT_ON(parse_events_add_numeric(list_event, idx, PERF_TYPE_RAW, $1, NULL)); struct list_head *list = NULL;
ABORT_ON(parse_events_add_numeric(&list, idx, PERF_TYPE_RAW, $1, NULL));
$$ = list;
} }
event_config: event_config:
...@@ -222,7 +260,6 @@ sep_slash_dc: '/' | ':' | ...@@ -222,7 +260,6 @@ sep_slash_dc: '/' | ':' |
%% %%
void parse_events_error(struct list_head *list_all __used, void parse_events_error(struct list_head *list_all __used,
struct list_head *list_event __used,
int *idx __used, int *idx __used,
char const *msg __used) char const *msg __used)
{ {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment