Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1701800 > unrolled thread

Re: [PATCH v1 02/15] perf, tools: Tighten detection of BPF events

Started byJiri Olsa <jolsa@redhat.com>
First post2017-08-02 09:40 +0200
Last post2017-08-02 21:20 +0200
Articles 2 — 2 participants

Back to article view | Back to linux.kernel

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: [PATCH v1 02/15] perf, tools: Tighten detection of BPF events Jiri Olsa <jolsa@redhat.com> - 2017-08-02 09:40 +0200
    Re: [PATCH v1 02/15] perf, tools: Tighten detection of BPF events Arnaldo Carvalho de Melo <acme@kernel.org> - 2017-08-02 21:20 +0200

#1701800 — Re: [PATCH v1 02/15] perf, tools: Tighten detection of BPF events

FromJiri Olsa <jolsa@redhat.com>
Date2017-08-02 09:40 +0200
SubjectRe: [PATCH v1 02/15] perf, tools: Tighten detection of BPF events
Message-ID<u9Wq7-6U6-29@gated-at.bofh.it>
On Mon, Jul 24, 2017 at 04:40:02PM -0700, Andi Kleen wrote:
> From: Andi Kleen <ak@linux.intel.com>
> 
> perf stat -e cpu/uops_executed.core,cmask=1/
> 
> would be detected as a BPF source event because the .c matches the .c
> source BPF pattern.
> 
> Add lookahead to the BPF patterns and reject them if they are followed
> by more letters.
> 
> Signed-off-by: Andi Kleen <ak@linux.intel.com>

I don't have the llvm/bpf toolchain, so can't test that side,
but Arnaldo will run it for sure ;-) anyway looks ok to me:

Acked-by: Jiri Olsa <jolsa@kernel.org>

thanks,
jirka

> ---
>  tools/perf/util/parse-events.l | 12 ++++++++----
>  1 file changed, 8 insertions(+), 4 deletions(-)
> 
> diff --git a/tools/perf/util/parse-events.l b/tools/perf/util/parse-events.l
> index 660fca05bc93..7fa3f2e851b0 100644
> --- a/tools/perf/util/parse-events.l
> +++ b/tools/perf/util/parse-events.l
> @@ -182,9 +182,13 @@ modifier_bp	[rwx]{1,3}
>  			REWIND(0);
>  		}
>  
> +({bpf_object}|{bpf_source})/[^a-z] {
> +			BEGIN(INITIAL);
> +			REWIND(1);
> +			return PE_EVENT_NAME;
> +		}
> +
>  {event_pmu}	|
> -{bpf_object}	|
> -{bpf_source}	|
>  {event}		{
>  			BEGIN(INITIAL);
>  			REWIND(1);
> @@ -307,8 +311,8 @@ r{num_raw_hex}		{ return raw(yyscanner); }
>  {num_hex}		{ return value(yyscanner, 16); }
>  
>  {modifier_event}	{ return str(yyscanner, PE_MODIFIER_EVENT); }
> -{bpf_object}		{ return str(yyscanner, PE_BPF_OBJECT); }
> -{bpf_source}		{ return str(yyscanner, PE_BPF_SOURCE); }
> +{bpf_object}/[^a-z]	{ return str(yyscanner, PE_BPF_OBJECT); }
> +{bpf_source}/[^a-z]	{ return str(yyscanner, PE_BPF_SOURCE); }
>  {name}			{ return pmu_str_check(yyscanner); }
>  "/"			{ BEGIN(config); return '/'; }
>  -			{ return '-'; }
> -- 
> 2.9.4
> 

[toc] | [next] | [standalone]


#1702386

FromArnaldo Carvalho de Melo <acme@kernel.org>
Date2017-08-02 21:20 +0200
Message-ID<ua7lv-5EM-7@gated-at.bofh.it>
In reply to#1701800
CCing eBPF guys and linux-perf-users, as it shows an example of
attaching a eBPF proggie to a tracepoint and reading its result with the
default BPF tracepoint beautifier in a simple, compact 'perf trace'
command line, together with asking for the 'write' syscall to be as well
beautified.x

Em Wed, Aug 02, 2017 at 09:35:18AM +0200, Jiri Olsa escreveu:
> On Mon, Jul 24, 2017 at 04:40:02PM -0700, Andi Kleen wrote:
> > perf stat -e cpu/uops_executed.core,cmask=1/

> > would be detected as a BPF source event because the .c matches the .c
> > source BPF pattern.

> > Add lookahead to the BPF patterns and reject them if they are followed
> > by more letters.
 
> I don't have the llvm/bpf toolchain, so can't test that side,
> but Arnaldo will run it for sure ;-) anyway looks ok to me:
 
> Acked-by: Jiri Olsa <jolsa@kernel.org>

Sure, it regresses:

Before the patch:

  # perf trace -e write -e /home/acme/bpf/tracepoint.c cat /etc/passwd
  <SNIP>
     0.000 ( 0.010 ms): cat/6676 write(fd: 1, buf: 0x7f5fe3065000, count: 3494) ...
     0.010 (         ): raw_syscalls:sys_enter:NR 1 (1, 7f5fe3065000, da6, 7f5fe3064010, ffffffffffffffff, 0))
     0.013 (         ): perf_bpf_probe:_write:(ffffffffa625ea60))
     0.000 ( 0.208 ms): cat/6676  ... [continued]: write()) = 3494
  #

And after:

  # perf trace -e write -e /home/acme/bpf/tracepoint.c cat /etc/passwd
  invalid or unsupported event: '/home/acme/bpf/tracepoint.c'
  Run 'perf list' for a list of valid events

   Usage: perf trace [<options>] [<command>]
      or: perf trace [<options>] -- <command> [<options>]
      or: perf trace record [<options>] [<command>]
      or: perf trace record [<options>] -- <command> [<options>]

      -e, --event <event>   event/syscall selector. use 'perf list' to list available events
  #

For testing, please install clang and then use that proggie:

# cat /home/acme/bpf/tracepoint.c 
#include <uapi/linux/bpf.h>
#define SEC(NAME) __attribute__((section(NAME), used))
SEC("raw_syscalls:sys_enter")
int func(void *ctx)
{
      /*
       * /sys/kernel/debug/tracing/events/raw_syscalls/sys_enter/format:
       * ...
       * field:long id;	offset:8;	size:8;	signed:1;
       * ...
       * ctx + 8 select 'id'
       */
      u64 id = *((u64 *)(ctx + 8));
      if (id == 1)
      	return 1;
      return 0;
}
SEC("_write=sys_write")
int _write(void *ctx)
{
      return 1;
}
char _license[] SEC("license") = "GPL";
int _version SEC("version") = LINUX_VERSION_CODE;
#

BTW, count: 3494 = 0xda6 :-)

Cheers,

- Arnaldo

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web