LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
From: "Liang, Kan" <kan.liang@linux.intel.com>
To: Jiri Olsa <jolsa@redhat.com>, Andi Kleen <ak@linux.intel.com>,
	Arnaldo Carvalho de Melo <acme@kernel.org>,
	Adrian Hunter <adrian.hunter@intel.com>
Cc: Ingo Molnar <mingo@kernel.org>,
	Clark Williams <williams@redhat.com>,
	linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org,
	Jiri Olsa <jolsa@kernel.org>,
	Alexander Shishkin <alexander.shishkin@linux.intel.com>,
	David Ahern <dsahern@gmail.com>,
	Namhyung Kim <namhyung@kernel.org>,
	Peter Zijlstra <peterz@infradead.org>,
	Arnaldo Carvalho de Melo <acme@redhat.com>
Subject: Re: [PATCH] perf tools: Fix parser for empty pmu terms case
Date: Sun, 6 May 2018 12:34:48 -0400	[thread overview]
Message-ID: <6a9f5464-eae8-c22e-d518-215c4c30019f@linux.intel.com> (raw)
In-Reply-To: <20180506142830.GA18865@krava>



On 5/6/2018 10:28 AM, Jiri Olsa wrote:
> On Sat, May 05, 2018 at 08:43:11PM -0700, Andi Kleen wrote:
>> Jiri Olsa <jolsa@redhat.com> writes:
>>
>> Please fix this quickly, PT is currently totally non functional in Linus
>> mainline.
> 
> attached.. Kan, could you please test it wrt your latest changes?
> 
> thanks,
> jirka
> 
> 
> ---
> Adrian reported broken event parsing for Intel PT:
> 
>    $ perf record -e intel_pt//u uname
>    event syntax error: 'intel_pt//u'
>                                 \___ parser error
>    Run 'perf list' for a list of valid events
> 
> It's caused by recent change in parsing grammar
> (see Fixes: for commit).
> 
> Adding special rule with empty terms config to handle
> the reported case and moving the common rule code into
> new parse_events_pmu function.
> 
> Fixes: 9a4a931ce847 ("perf pmu: Fix pmu events parsing rule")
> Reported-by: Adrian Hunter <adrian.hunter@intel.com>
> Cc: Andi Kleen <ak@linux.intel.com>
> Link: http://lkml.kernel.org/n/tip-uorb0azuem7b7ydace7cf6vc@git.kernel.org
> Signed-off-by: Jiri Olsa <jolsa@kernel.org>

The patch looks good to me.
I tested my latest change and Intel PT. Both looks good.

./perf stat -e '{unc_m_cas_count.all,unc_m_clockticks}' -a -I 1000   # 
         time             counts unit events
      1.001556622             95,686      unc_m_cas_count.all
      1.001556622      1,900,544,149      unc_m_clockticks
      2.002722048            159,598      unc_m_cas_count.all
      2.002722048      2,339,028,614      unc_m_clockticks

./perf record -e intel_pt//u
[ perf record: Woken up 1 times to write data ]
[ perf record: Captured and wrote 0.044 MB perf.data ]


Tested-by: Kan Liang <kan.liang@linux.intel.com>

> ---
>   tools/perf/util/parse-events.c | 46 +++++++++++++++++++++++++++++++++++++
>   tools/perf/util/parse-events.h |  3 +++
>   tools/perf/util/parse-events.y | 51 +++++++++++++-----------------------------
>   3 files changed, 65 insertions(+), 35 deletions(-)
> 
> diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c
> index 3576aaaa9e4c..7cf326a8effe 100644
> --- a/tools/perf/util/parse-events.c
> +++ b/tools/perf/util/parse-events.c
> @@ -8,6 +8,7 @@
>   #include <sys/stat.h>
>   #include <fcntl.h>
>   #include <sys/param.h>
> +#include <fnmatch.h>
>   #include "term.h"
>   #include "../perf.h"
>   #include "evlist.h"
> @@ -1294,6 +1295,51 @@ int parse_events_add_pmu(struct parse_events_state *parse_state,
>   	return evsel ? 0 : -ENOMEM;
>   }
>   
> +int parse_events_pmu(struct parse_events_state *parse_state,
> +		     struct list_head *list, char *name,
> +		     struct list_head *head_config)
> +{
> +	struct list_head *orig_terms;
> +	struct perf_pmu *pmu = NULL;
> +	char *pattern = NULL;
> +	int ok = 0;
> +
> +	if (!parse_events_add_pmu(parse_state, list, name,
> +				  head_config, false, false))
> +		return 0;
> +
> +	if (parse_events_copy_term_list(head_config, &orig_terms))
> +		return -1;
> +
> +	if (asprintf(&pattern, "%s*", name) < 0)
> +		goto out;
> +
> +	while ((pmu = perf_pmu__scan(pmu)) != NULL) {
> +		char *tmp = pmu->name;
> +
> +		if (!strncmp(tmp, "uncore_", 7) &&
> +		    strncmp(name, "uncore_", 7))
> +			tmp += 7;
> +		if (!fnmatch(pattern, tmp, 0)) {
> +			struct list_head *terms;
> +
> +			if (parse_events_copy_term_list(orig_terms, &terms)) {
> +				ok = 0;
> +				goto out;
> +			}
> +			if (!parse_events_add_pmu(parse_state, list, pmu->name,
> +						  terms, true, false))
> +				ok++;
> +			parse_events_terms__delete(terms);
> +		}
> +	}
> +
> +out:
> +	parse_events_terms__delete(orig_terms);
> +	free(pattern);
> +	return ok ? 0 : -1;
> +}
> +
>   int parse_events_multi_pmu_add(struct parse_events_state *parse_state,
>   			       char *str, struct list_head **listp)
>   {
> diff --git a/tools/perf/util/parse-events.h b/tools/perf/util/parse-events.h
> index 4473dac27aee..553fcaf5d23e 100644
> --- a/tools/perf/util/parse-events.h
> +++ b/tools/perf/util/parse-events.h
> @@ -170,6 +170,9 @@ int parse_events_add_pmu(struct parse_events_state *parse_state,
>   			 struct list_head *head_config,
>   			 bool auto_merge_stats,
>   			 bool use_alias);
> +int parse_events_pmu(struct parse_events_state *parse_state,
> +		     struct list_head *list, char *name,
> +		     struct list_head *head_config);
>   
>   int parse_events_multi_pmu_add(struct parse_events_state *parse_state,
>   			       char *str,
> diff --git a/tools/perf/util/parse-events.y b/tools/perf/util/parse-events.y
> index 47f6399a309a..d44599bece43 100644
> --- a/tools/perf/util/parse-events.y
> +++ b/tools/perf/util/parse-events.y
> @@ -8,7 +8,6 @@
>   
>   #define YYDEBUG 1
>   
> -#include <fnmatch.h>
>   #include <linux/compiler.h>
>   #include <linux/list.h>
>   #include <linux/types.h>
> @@ -226,44 +225,26 @@ event_def: event_pmu |
>   event_pmu:
>   PE_NAME '/' event_config '/'
>   {
> -	struct list_head *list, *orig_terms, *terms;
> +	struct list_head *list;
> +
> +	ALLOC_LIST(list);
>   
> -	if (parse_events_copy_term_list($3, &orig_terms))
> +	if (parse_events_pmu(_parse_state, list, $1, $3))
>   		YYABORT;
>   
> -	ALLOC_LIST(list);
> -	if (parse_events_add_pmu(_parse_state, list, $1, $3, false, false)) {
> -		struct perf_pmu *pmu = NULL;
> -		int ok = 0;
> -		char *pattern;
> -
> -		if (asprintf(&pattern, "%s*", $1) < 0)
> -			YYABORT;
> -
> -		while ((pmu = perf_pmu__scan(pmu)) != NULL) {
> -			char *name = pmu->name;
> -
> -			if (!strncmp(name, "uncore_", 7) &&
> -			    strncmp($1, "uncore_", 7))
> -				name += 7;
> -			if (!fnmatch(pattern, name, 0)) {
> -				if (parse_events_copy_term_list(orig_terms, &terms)) {
> -					free(pattern);
> -					YYABORT;
> -				}
> -				if (!parse_events_add_pmu(_parse_state, list, pmu->name, terms, true, false))
> -					ok++;
> -				parse_events_terms__delete(terms);
> -			}
> -		}
> -
> -		free(pattern);
> -
> -		if (!ok)
> -			YYABORT;
> -	}
>   	parse_events_terms__delete($3);
> -	parse_events_terms__delete(orig_terms);
> +	$$ = list;
> +}
> +|
> +PE_NAME '/' '/'
> +{
> +	struct list_head *list;
> +
> +	ALLOC_LIST(list);
> +
> +	if (parse_events_pmu(_parse_state, list, $1, NULL))
> +		YYABORT;
> +
>   	$$ = list;
>   }
>   |
> 

  reply	other threads:[~2018-05-06 16:34 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-04-25 15:59 [GIT PULL 00/12] perf/urgent fixes Arnaldo Carvalho de Melo
2018-04-25 15:59 ` [PATCH 01/12] perf machine: Set main kernel end address properly Arnaldo Carvalho de Melo
2018-04-25 15:59 ` [PATCH 02/12] perf list: Remove s390 specific strcmp_cpuid_cmp function Arnaldo Carvalho de Melo
2018-04-25 15:59 ` [PATCH 03/12] perf test: Adapt test case record+probe_libc_inet_pton.sh for s390 Arnaldo Carvalho de Melo
2018-04-25 16:00 ` [PATCH 04/12] perf stat: Keep the / modifier separator in fallback Arnaldo Carvalho de Melo
2018-04-25 16:00 ` [PATCH 05/12] perf pmu: Fix pmu events parsing rule Arnaldo Carvalho de Melo
2018-05-03  8:25   ` Adrian Hunter
2018-05-03 10:37     ` Jiri Olsa
2018-05-03 11:38       ` Adrian Hunter
2018-05-03 11:47         ` Jiri Olsa
2018-05-04 16:02         ` Jiri Olsa
2018-05-06  3:43           ` Andi Kleen
2018-05-06 14:28             ` [PATCH] perf tools: Fix parser for empty pmu terms case Jiri Olsa
2018-05-06 16:34               ` Liang, Kan [this message]
2018-05-07  7:21               ` Adrian Hunter
2018-05-07  8:12                 ` Jiri Olsa
2018-05-07 15:04                   ` Arnaldo Carvalho de Melo
2018-05-07 18:37             ` [PATCH 05/12] perf pmu: Fix pmu events parsing rule Arnaldo Carvalho de Melo
2018-05-07 19:16               ` Jiri Olsa
2018-05-07 19:26                 ` Arnaldo Carvalho de Melo
2018-05-07 19:24               ` Arnaldo Carvalho de Melo
2018-05-07 19:42                 ` Jiri Olsa
2018-04-25 16:00 ` [PATCH 06/12] perf evsel: Disable write_backward for leader sampling group events Arnaldo Carvalho de Melo
2018-04-25 16:00 ` [PATCH 07/12] perf mem: Document incorrect and missing options Arnaldo Carvalho de Melo
2018-04-25 16:00 ` [PATCH 08/12] perf record: Fix s390 undefined record__auxtrace_init() return value Arnaldo Carvalho de Melo
2018-04-25 16:00 ` [PATCH 09/12] perf pmu: Fix core PMU alias list for X86 platform Arnaldo Carvalho de Melo
2018-04-25 16:00 ` [PATCH 10/12] perf stat: Print out hint for mixed PMU group error Arnaldo Carvalho de Melo
2018-04-25 16:00 ` [PATCH 11/12] perf evsel: Only fall back group read for leader Arnaldo Carvalho de Melo
2018-04-25 16:00 ` [PATCH 12/12] perf stat: Fix duplicate PMU name for interval print Arnaldo Carvalho de Melo
2018-04-26  5:33 ` [GIT PULL 00/12] perf/urgent fixes Ingo Molnar

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=6a9f5464-eae8-c22e-d518-215c4c30019f@linux.intel.com \
    --to=kan.liang@linux.intel.com \
    --cc=acme@kernel.org \
    --cc=acme@redhat.com \
    --cc=adrian.hunter@intel.com \
    --cc=ak@linux.intel.com \
    --cc=alexander.shishkin@linux.intel.com \
    --cc=dsahern@gmail.com \
    --cc=jolsa@kernel.org \
    --cc=jolsa@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-perf-users@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=namhyung@kernel.org \
    --cc=peterz@infradead.org \
    --cc=williams@redhat.com \
    --subject='Re: [PATCH] perf tools: Fix parser for empty pmu terms case' \
    /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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).