Patchwork perf, tools: Handle events including .c and .o

login
register
mail settings
Submitter Wang Nan
Date Sept. 18, 2016, 10:20 a.m.
Message ID <57DE6A54.1000407@huawei.com>
Download mbox | patch
Permalink /patch/9337721/
State New
Headers show

Comments

Wang Nan - Sept. 18, 2016, 10:20 a.m.
On 2016/9/18 9:02, Andi Kleen wrote:
> From: Andi Kleen <ak@linux.intel.com>
>
> This is a generic bug fix, but it helps with Sukadev's JSON event tree
> where such events can happen.
>
> Any event inclduing a .c/.o/.bpf currently triggers BPF compilation or loading
> and then an error.  This can happen for some Intel JSON events, which cannot
> be used.
>
> Fix the scanner to only match for .o or .c or .bpf at the end.
> This will prevent loading multiple BPF scripts separated with comma,
> but I assume this is acceptable.
>
> Cc: wangnan0@huawei.com
> Cc: sukadev@linux.vnet.ibm.com
> Signed-off-by: Andi Kleen <ak@linux.intel.com>

I tested '.c' in middle of an event:

  # perf trace --event 'aaa.ccc'
  invalid or unsupported event: 'aaa.ccc'
  Run 'perf list' for a list of valid events
  ...

It is not recongnized as a BPF source.

So could you please provide an example to show how
this potential bug breaks the parsing of new events?

> ---
>   tools/perf/util/parse-events.l | 4 ++--
>   1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/tools/perf/util/parse-events.l b/tools/perf/util/parse-events.l
> index 7a2519435da0..64ca26e4ed2d 100644
> --- a/tools/perf/util/parse-events.l
> +++ b/tools/perf/util/parse-events.l
> @@ -162,8 +162,8 @@ modifier_bp	[rwx]{1,3}
>   		}
>   
>   {event_pmu}	|
> -{bpf_object}	|
> -{bpf_source}	|
> +({bpf_object}$)	|
> +({bpf_source}$)	|

What about putting '$' at the definition of bpf_xxx like this?

  num_hex                0x[a-fA-F0-9]+

Thank you.

>   {event}		{
>   			BEGIN(INITIAL);
>   			REWIND(1);
Andi Kleen - Sept. 18, 2016, 2:56 p.m.
On Sun, Sep 18, 2016 at 06:20:04PM +0800, Wangnan (F) wrote:
> 
> 
> On 2016/9/18 9:02, Andi Kleen wrote:
> > From: Andi Kleen <ak@linux.intel.com>
> > 
> > This is a generic bug fix, but it helps with Sukadev's JSON event tree
> > where such events can happen.
> > 
> > Any event inclduing a .c/.o/.bpf currently triggers BPF compilation or loading
> > and then an error.  This can happen for some Intel JSON events, which cannot
> > be used.
> > 
> > Fix the scanner to only match for .o or .c or .bpf at the end.
> > This will prevent loading multiple BPF scripts separated with comma,
> > but I assume this is acceptable.
> > 
> > Cc: wangnan0@huawei.com
> > Cc: sukadev@linux.vnet.ibm.com
> > Signed-off-by: Andi Kleen <ak@linux.intel.com>
> 
> I tested '.c' in middle of an event:
> 
>  # perf trace --event 'aaa.ccc'
>  invalid or unsupported event: 'aaa.ccc'
>  Run 'perf list' for a list of valid events
>  ...
> 
> It is not recongnized as a BPF source.
> 
> So could you please provide an example to show how
> this potential bug breaks the parsing of new events?

This is with the upcoming JSON uncore events:

$ perf stat -e '{unc_p_clockticks,unc_p_power_state_occupancy.cores_c0}' -a -I 1000
ERROR: problems with path {unc_p_clockticks,unc_p_power_state_occupancy.c: No such file or directory
event syntax error: '{unc_p_clockticks,unc_p_power_state_occupancy.cores_c0}'
                     \___ Failed to load {unc_p_clockticks,unc_p_power_state_occupancy.c from source: Error when compiling BPF scriptlet

(add -v to see detail)
Run 'perf list' for a list of valid events

-Andi
Wang Nan - Sept. 19, 2016, 2:50 a.m.
On 2016/9/18 22:56, Andi Kleen wrote:
> On Sun, Sep 18, 2016 at 06:20:04PM +0800, Wangnan (F) wrote:
>>
>> On 2016/9/18 9:02, Andi Kleen wrote:
>>> From: Andi Kleen <ak@linux.intel.com>
>>>
>>> This is a generic bug fix, but it helps with Sukadev's JSON event tree
>>> where such events can happen.
>>>
>>> Any event inclduing a .c/.o/.bpf currently triggers BPF compilation or loading
>>> and then an error.  This can happen for some Intel JSON events, which cannot
>>> be used.
>>>
>>> Fix the scanner to only match for .o or .c or .bpf at the end.
>>> This will prevent loading multiple BPF scripts separated with comma,
>>> but I assume this is acceptable.
>>>
>>> Cc: wangnan0@huawei.com
>>> Cc: sukadev@linux.vnet.ibm.com
>>> Signed-off-by: Andi Kleen <ak@linux.intel.com>
>> I tested '.c' in middle of an event:
>>
>>   # perf trace --event 'aaa.ccc'
>>   invalid or unsupported event: 'aaa.ccc'
>>   Run 'perf list' for a list of valid events
>>   ...
>>
>> It is not recongnized as a BPF source.
>>
>> So could you please provide an example to show how
>> this potential bug breaks the parsing of new events?
> This is with the upcoming JSON uncore events:
>
> $ perf stat -e '{unc_p_clockticks,unc_p_power_state_occupancy.cores_c0}' -a -I 1000
> ERROR: problems with path {unc_p_clockticks,unc_p_power_state_occupancy.c: No such file or directory
> event syntax error: '{unc_p_clockticks,unc_p_power_state_occupancy.cores_c0}'
>                       \___ Failed to load {unc_p_clockticks,unc_p_power_state_occupancy.c from source: Error when compiling BPF scriptlet
>
> (add -v to see detail)
> Run 'perf list' for a list of valid events
>
> -Andi

I see, and your patch solve problem like this.

Tested-by: Wang Nan <wangnan0@huawei.com>

Patch

diff --git a/tools/perf/util/parse-events.l b/tools/perf/util/parse-events.l
index 9f43fda..d9ff690 100644
--- a/tools/perf/util/parse-events.l
+++ b/tools/perf/util/parse-events.l
@@ -136,8 +136,8 @@  do 
{                                                        \
  group          [^,{}/]*[{][^}]*[}][^,{}/]*
  event_pmu      [^,{}/]+[/][^/]*[/][^,{}/]*
  event          [^,{}/]+
-bpf_object     .*\.(o|bpf)
-bpf_source     .*\.c
+bpf_object     .*\.(o|bpf)$
+bpf_source     .*\.c$

  num_dec                [0-9]+