[PATCH AUTOSEL for 4.9 072/293] perf evsel: Fix probing of precise_ip level for default cycles event

2018-04-08 Thread Sasha Levin
From: Arnaldo Carvalho de Melo 

[ Upstream commit 7a1ac110c22eb726684c837544a2d42c33e07be7 ]

Since commit 18e7a45af91a ("perf/x86: Reject non sampling events with
precise_ip") returns -EINVAL for sys_perf_event_open() with an attribute
with (attr.precise_ip > 0 && attr.sample_period == 0), just like is done
in the routine used to probe the max precise level when no events were
passed to 'perf record' or 'perf top', i.e.:

perf_evsel__new_cycles()
perf_event_attr__set_max_precise_ip()

The x86 code, in x86_pmu_hw_config(), which is called all the way from
sys_perf_event_open() did, starting with the aforementioned commit:

/* There's no sense in having PEBS for non sampling events: */
if (!is_sampling_event(event))
return -EINVAL;

Which makes it fail for cycles:ppp, cycles:pp and cycles:p, always using
just the non precise cycles variant.

To make sure that this is the case, I tested it, before this patch,
with:

  # perf probe -L x86_pmu_hw_config
  
0  int x86_pmu_hw_config(struct perf_event *event)
1  {
2 if (event->attr.precise_ip) {

   17 if (event->attr.precise_ip > precise)
   18 return -EOPNOTSUPP;

  /* There's no sense in having PEBS for non sampling 
events: */
   21 if (!is_sampling_event(event))
   22 return -EINVAL;
  }

  # perf probe x86_pmu_hw_config:22
  Added new events:
probe:x86_pmu_hw_config (on x86_pmu_hw_config:22)
probe:x86_pmu_hw_config_1 (on x86_pmu_hw_config:22)

  You can now use it in all perf tools, such as:

perf record -e probe:x86_pmu_hw_config_1 -aR sleep 1

  # perf trace -e perf_event_open,probe:x86_pmu_hwconfig*/max-stack=16/ perf 
record usleep 1
 0.000 ( 0.015 ms): perf/4150 perf_event_open(attr_uptr: 0x7ffebc8ba110, 
cpu: -1, group_fd: -1  ) ...
 0.015 ( ): probe:x86_pmu_hw_config:(9c0065e1))
   x86_pmu_hw_config ([kernel.kallsyms])
   hsw_hw_config ([kernel.kallsyms])
   x86_pmu_event_init ([kernel.kallsyms])
   perf_try_init_event ([kernel.kallsyms])
   perf_event_alloc ([kernel.kallsyms])
   SYSC_perf_event_open ([kernel.kallsyms])
   sys_perf_event_open ([kernel.kallsyms])
   do_syscall_64 ([kernel.kallsyms])
   return_from_SYSCALL_64 
([kernel.kallsyms])
   syscall (/usr/lib64/libc-2.24.so)
   perf_event_attr__set_max_precise_ip 
(/home/acme/bin/perf)
   perf_evsel__new_cycles 
(/home/acme/bin/perf)
   perf_evlist__add_default 
(/home/acme/bin/perf)
   cmd_record (/home/acme/bin/perf)
   run_builtin (/home/acme/bin/perf)
   handle_internal_command 
(/home/acme/bin/perf)
 0.000 ( 0.021 ms): perf/4150  ... [continued]: perf_event_open()) = -1 
EINVAL Invalid argument
 0.023 ( 0.002 ms): perf/4150 perf_event_open(attr_uptr: 0x7ffebc8ba110, 
cpu: -1, group_fd: -1  ) ...
 0.025 ( ): probe:x86_pmu_hw_config:(9c0065e1))
   x86_pmu_hw_config ([kernel.kallsyms])
   hsw_hw_config ([kernel.kallsyms])
   x86_pmu_event_init ([kernel.kallsyms])
   perf_try_init_event ([kernel.kallsyms])
   perf_event_alloc ([kernel.kallsyms])
   SYSC_perf_event_open ([kernel.kallsyms])
   sys_perf_event_open ([kernel.kallsyms])
   do_syscall_64 ([kernel.kallsyms])
   return_from_SYSCALL_64 
([kernel.kallsyms])
   syscall (/usr/lib64/libc-2.24.so)
   perf_event_attr__set_max_precise_ip 
(/home/acme/bin/perf)
   perf_evsel__new_cycles 
(/home/acme/bin/perf)
   perf_evlist__add_default 
(/home/acme/bin/perf)
   cmd_record (/home/acme/bin/perf)
   run_builtin (/home/acme/bin/perf)
   handle_internal_command 
(/home/acme/bin/perf)
 0.023 ( 0.004 ms): perf/4150  

[PATCH AUTOSEL for 4.9 072/293] perf evsel: Fix probing of precise_ip level for default cycles event

2018-04-08 Thread Sasha Levin
From: Arnaldo Carvalho de Melo 

[ Upstream commit 7a1ac110c22eb726684c837544a2d42c33e07be7 ]

Since commit 18e7a45af91a ("perf/x86: Reject non sampling events with
precise_ip") returns -EINVAL for sys_perf_event_open() with an attribute
with (attr.precise_ip > 0 && attr.sample_period == 0), just like is done
in the routine used to probe the max precise level when no events were
passed to 'perf record' or 'perf top', i.e.:

perf_evsel__new_cycles()
perf_event_attr__set_max_precise_ip()

The x86 code, in x86_pmu_hw_config(), which is called all the way from
sys_perf_event_open() did, starting with the aforementioned commit:

/* There's no sense in having PEBS for non sampling events: */
if (!is_sampling_event(event))
return -EINVAL;

Which makes it fail for cycles:ppp, cycles:pp and cycles:p, always using
just the non precise cycles variant.

To make sure that this is the case, I tested it, before this patch,
with:

  # perf probe -L x86_pmu_hw_config
  
0  int x86_pmu_hw_config(struct perf_event *event)
1  {
2 if (event->attr.precise_ip) {

   17 if (event->attr.precise_ip > precise)
   18 return -EOPNOTSUPP;

  /* There's no sense in having PEBS for non sampling 
events: */
   21 if (!is_sampling_event(event))
   22 return -EINVAL;
  }

  # perf probe x86_pmu_hw_config:22
  Added new events:
probe:x86_pmu_hw_config (on x86_pmu_hw_config:22)
probe:x86_pmu_hw_config_1 (on x86_pmu_hw_config:22)

  You can now use it in all perf tools, such as:

perf record -e probe:x86_pmu_hw_config_1 -aR sleep 1

  # perf trace -e perf_event_open,probe:x86_pmu_hwconfig*/max-stack=16/ perf 
record usleep 1
 0.000 ( 0.015 ms): perf/4150 perf_event_open(attr_uptr: 0x7ffebc8ba110, 
cpu: -1, group_fd: -1  ) ...
 0.015 ( ): probe:x86_pmu_hw_config:(9c0065e1))
   x86_pmu_hw_config ([kernel.kallsyms])
   hsw_hw_config ([kernel.kallsyms])
   x86_pmu_event_init ([kernel.kallsyms])
   perf_try_init_event ([kernel.kallsyms])
   perf_event_alloc ([kernel.kallsyms])
   SYSC_perf_event_open ([kernel.kallsyms])
   sys_perf_event_open ([kernel.kallsyms])
   do_syscall_64 ([kernel.kallsyms])
   return_from_SYSCALL_64 
([kernel.kallsyms])
   syscall (/usr/lib64/libc-2.24.so)
   perf_event_attr__set_max_precise_ip 
(/home/acme/bin/perf)
   perf_evsel__new_cycles 
(/home/acme/bin/perf)
   perf_evlist__add_default 
(/home/acme/bin/perf)
   cmd_record (/home/acme/bin/perf)
   run_builtin (/home/acme/bin/perf)
   handle_internal_command 
(/home/acme/bin/perf)
 0.000 ( 0.021 ms): perf/4150  ... [continued]: perf_event_open()) = -1 
EINVAL Invalid argument
 0.023 ( 0.002 ms): perf/4150 perf_event_open(attr_uptr: 0x7ffebc8ba110, 
cpu: -1, group_fd: -1  ) ...
 0.025 ( ): probe:x86_pmu_hw_config:(9c0065e1))
   x86_pmu_hw_config ([kernel.kallsyms])
   hsw_hw_config ([kernel.kallsyms])
   x86_pmu_event_init ([kernel.kallsyms])
   perf_try_init_event ([kernel.kallsyms])
   perf_event_alloc ([kernel.kallsyms])
   SYSC_perf_event_open ([kernel.kallsyms])
   sys_perf_event_open ([kernel.kallsyms])
   do_syscall_64 ([kernel.kallsyms])
   return_from_SYSCALL_64 
([kernel.kallsyms])
   syscall (/usr/lib64/libc-2.24.so)
   perf_event_attr__set_max_precise_ip 
(/home/acme/bin/perf)
   perf_evsel__new_cycles 
(/home/acme/bin/perf)
   perf_evlist__add_default 
(/home/acme/bin/perf)
   cmd_record (/home/acme/bin/perf)
   run_builtin (/home/acme/bin/perf)
   handle_internal_command 
(/home/acme/bin/perf)
 0.023 ( 0.004 ms): perf/4150  ... [continued]: perf_event_open()) = -1 
EINVAL Invalid argument
 0.028 (