Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 46010ab2 authored by Jiri Olsa's avatar Jiri Olsa Committed by Ingo Molnar
Browse files

perf/tool: Use data struct for arg passing in event parse function



Moving all the bison arguments into the structure. In upcomming
patches we are going to:

  - add more arguments
  - reuse the grammer for term parsing

so it's more clear to pack/separate related arguments.

Signed-off-by: default avatarJiri Olsa <jolsa@redhat.com>
Signed-off-by: default avatarPeter Zijlstra <a.p.zijlstra@chello.nl>
Link: http://lkml.kernel.org/r/1339741902-8449-10-git-send-email-zheng.z.yan@intel.com


Signed-off-by: default avatarIngo Molnar <mingo@kernel.org>
parent 7c94ee2e
Loading
Loading
Loading
Loading
+9 −7
Original line number Original line Diff line number Diff line
@@ -26,7 +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, int *idx);
int parse_events_parse(void *data);


#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
@@ -789,25 +789,27 @@ int parse_events_modifier(struct list_head *list, char *str)


int parse_events(struct perf_evlist *evlist, const char *str, int unset __used)
int parse_events(struct perf_evlist *evlist, const char *str, int unset __used)
{
{
	LIST_HEAD(list);
	struct parse_events_data__events data = {
	LIST_HEAD(list_tmp);
		.list = LIST_HEAD_INIT(data.list),
		.idx  = evlist->nr_entries,
	};
	YY_BUFFER_STATE buffer;
	YY_BUFFER_STATE buffer;
	int ret, idx = evlist->nr_entries;
	int ret;


	buffer = parse_events__scan_string(str);
	buffer = parse_events__scan_string(str);


#ifdef PARSER_DEBUG
#ifdef PARSER_DEBUG
	parse_events_debug = 1;
	parse_events_debug = 1;
#endif
#endif
	ret = parse_events_parse(&list, &idx);
	ret = parse_events_parse(&data);


	parse_events__flush_buffer(buffer);
	parse_events__flush_buffer(buffer);
	parse_events__delete_buffer(buffer);
	parse_events__delete_buffer(buffer);
	parse_events_lex_destroy();
	parse_events_lex_destroy();


	if (!ret) {
	if (!ret) {
		int entries = idx - evlist->nr_entries;
		int entries = data.idx - evlist->nr_entries;
		perf_evlist__splice_list_tail(evlist, &list, entries);
		perf_evlist__splice_list_tail(evlist, &data.list, entries);
		return 0;
		return 0;
	}
	}


+6 −2
Original line number Original line Diff line number Diff line
@@ -63,6 +63,11 @@ struct parse_events__term {
	struct list_head list;
	struct list_head list;
};
};


struct parse_events_data__events {
	struct list_head list;
	int idx;
};

int parse_events__is_hardcoded_term(struct parse_events__term *term);
int parse_events__is_hardcoded_term(struct parse_events__term *term);
int parse_events__term_num(struct parse_events__term **_term,
int parse_events__term_num(struct parse_events__term **_term,
			   int type_term, char *config, long num);
			   int type_term, char *config, long num);
@@ -83,8 +88,7 @@ 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(void *data, char const *msg);
			int *idx, char const *msg);
int parse_events__test(void);
int parse_events__test(void);


void print_events(const char *event_glob);
void print_events(const char *event_glob);
+35 −17
Original line number Original line Diff line number Diff line


%name-prefix "parse_events_"
%name-prefix "parse_events_"
%parse-param {struct list_head *list_all}
%parse-param {void *_data}
%parse-param {int *idx}


%{
%{


@@ -64,18 +63,22 @@ events ',' event | event
event:
event:
event_def PE_MODIFIER_EVENT
event_def PE_MODIFIER_EVENT
{
{
	struct parse_events_data__events *data = _data;

	/*
	/*
	 * Apply modifier on all events added by single event definition
	 * Apply modifier on all events added by single event definition
	 * (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($1, $2));
	ABORT_ON(parse_events_modifier($1, $2));
	parse_events_update_lists($1, list_all);
	parse_events_update_lists($1, &data->list);
}
}
|
|
event_def
event_def
{
{
	parse_events_update_lists($1, list_all);
	struct parse_events_data__events *data = _data;

	parse_events_update_lists($1, &data->list);
}
}


event_def: event_pmu |
event_def: event_pmu |
@@ -89,9 +92,10 @@ event_def: event_pmu |
event_pmu:
event_pmu:
PE_NAME '/' event_config '/'
PE_NAME '/' event_config '/'
{
{
	struct parse_events_data__events *data = _data;
	struct list_head *list = NULL;
	struct list_head *list = NULL;


	ABORT_ON(parse_events_add_pmu(&list, idx, $1, $3));
	ABORT_ON(parse_events_add_pmu(&list, &data->idx, $1, $3));
	parse_events__free_terms($3);
	parse_events__free_terms($3);
	$$ = list;
	$$ = list;
}
}
@@ -99,91 +103,106 @@ PE_NAME '/' event_config '/'
event_legacy_symbol:
event_legacy_symbol:
PE_VALUE_SYM '/' event_config '/'
PE_VALUE_SYM '/' event_config '/'
{
{
	struct parse_events_data__events *data = _data;
	struct list_head *list = NULL;
	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, idx, type, config, $3));
	ABORT_ON(parse_events_add_numeric(&list, &data->idx,
					  type, config, $3));
	parse_events__free_terms($3);
	parse_events__free_terms($3);
	$$ = list;
	$$ = list;
}
}
|
|
PE_VALUE_SYM sep_slash_dc
PE_VALUE_SYM sep_slash_dc
{
{
	struct parse_events_data__events *data = _data;
	struct list_head *list = NULL;
	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, idx, type, config, NULL));
	ABORT_ON(parse_events_add_numeric(&list, &data->idx,
					  type, config, NULL));
	$$ = list;
	$$ = 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
{
{
	struct parse_events_data__events *data = _data;
	struct list_head *list = NULL;
	struct list_head *list = NULL;


	ABORT_ON(parse_events_add_cache(&list, idx, $1, $3, $5));
	ABORT_ON(parse_events_add_cache(&list, &data->idx, $1, $3, $5));
	$$ = list;
	$$ = list;
}
}
|
|
PE_NAME_CACHE_TYPE '-' PE_NAME_CACHE_OP_RESULT
PE_NAME_CACHE_TYPE '-' PE_NAME_CACHE_OP_RESULT
{
{
	struct parse_events_data__events *data = _data;
	struct list_head *list = NULL;
	struct list_head *list = NULL;


	ABORT_ON(parse_events_add_cache(&list, idx, $1, $3, NULL));
	ABORT_ON(parse_events_add_cache(&list, &data->idx, $1, $3, NULL));
	$$ = list;
	$$ = list;
}
}
|
|
PE_NAME_CACHE_TYPE
PE_NAME_CACHE_TYPE
{
{
	struct parse_events_data__events *data = _data;
	struct list_head *list = NULL;
	struct list_head *list = NULL;


	ABORT_ON(parse_events_add_cache(&list, idx, $1, NULL, NULL));
	ABORT_ON(parse_events_add_cache(&list, &data->idx, $1, NULL, NULL));
	$$ = list;
	$$ = 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
{
{
	struct parse_events_data__events *data = _data;
	struct list_head *list = NULL;
	struct list_head *list = NULL;


	ABORT_ON(parse_events_add_breakpoint(&list, idx, (void *) $2, $4));
	ABORT_ON(parse_events_add_breakpoint(&list, &data->idx,
					     (void *) $2, $4));
	$$ = list;
	$$ = list;
}
}
|
|
PE_PREFIX_MEM PE_VALUE sep_dc
PE_PREFIX_MEM PE_VALUE sep_dc
{
{
	struct parse_events_data__events *data = _data;
	struct list_head *list = NULL;
	struct list_head *list = NULL;


	ABORT_ON(parse_events_add_breakpoint(&list, idx, (void *) $2, NULL));
	ABORT_ON(parse_events_add_breakpoint(&list, &data->idx,
					     (void *) $2, NULL));
	$$ = list;
	$$ = list;
}
}


event_legacy_tracepoint:
event_legacy_tracepoint:
PE_NAME ':' PE_NAME
PE_NAME ':' PE_NAME
{
{
	struct parse_events_data__events *data = _data;
	struct list_head *list = NULL;
	struct list_head *list = NULL;


	ABORT_ON(parse_events_add_tracepoint(&list, idx, $1, $3));
	ABORT_ON(parse_events_add_tracepoint(&list, &data->idx, $1, $3));
	$$ = list;
	$$ = list;
}
}


event_legacy_numeric:
event_legacy_numeric:
PE_VALUE ':' PE_VALUE
PE_VALUE ':' PE_VALUE
{
{
	struct parse_events_data__events *data = _data;
	struct list_head *list = NULL;
	struct list_head *list = NULL;


	ABORT_ON(parse_events_add_numeric(&list, idx, $1, $3, NULL));
	ABORT_ON(parse_events_add_numeric(&list, &data->idx, $1, $3, NULL));
	$$ = list;
	$$ = list;
}
}


event_legacy_raw:
event_legacy_raw:
PE_RAW
PE_RAW
{
{
	struct parse_events_data__events *data = _data;
	struct list_head *list = NULL;
	struct list_head *list = NULL;


	ABORT_ON(parse_events_add_numeric(&list, idx, PERF_TYPE_RAW, $1, NULL));
	ABORT_ON(parse_events_add_numeric(&list, &data->idx,
					  PERF_TYPE_RAW, $1, NULL));
	$$ = list;
	$$ = list;
}
}


@@ -267,8 +286,7 @@ sep_slash_dc: '/' | ':' |


%%
%%


void parse_events_error(struct list_head *list_all __used,
void parse_events_error(void *data __used,
			int *idx __used,
			char const *msg __used)
			char const *msg __used)
{
{
}
}