perf tools fixes for v6.6: 2nd batch

- Fix regression in reading scale and unit files from sysfs for PMU
  events, so that we can use that info to pretty print instead of
  printing raw numbers:

  # perf stat -e power/energy-ram/,power/energy-gpu/ sleep 2

   Performance counter stats for 'system wide':

              1.64 Joules power/energy-ram/
              0.20 Joules power/energy-gpu/

       2.001228914 seconds time elapsed
  # grep -m1 "model name" /proc/cpuinfo
  model name	: Intel(R) Core(TM) i7-8650U CPU @ 1.90GHz

- The small llvm.cpp file used to check if the llvm devel files are present was
  incorrectly deleted when removing the BPF event in 'perf trace', put it back
  as it is also used by tools/bpf/bpftool, that uses llvm routines to do
  disassembly of BPF object files.

- Fix use of addr_location__exit() in dlfilter__object_code(), making sure that
  it is only used to pair a previous addr_location__init() call.

Signed-off-by: Arnaldo Carvalho de Melo <>
tools build: Fix llvm feature detection, still used by bpftool

When removing the BPF event for perf a feature test that checks if the
llvm devel files are availabe was removed but that is also used by

bpftool uses it to decide what kind of disassembly it will use: llvm or
binutils based.

Removing the tools/build/feature/test-llvm.cpp file made bpftool to
always fallback to binutils disassembly, even with the llvm devel files
installed, fix it by restoring just that small test-llvm.cpp test file.

Fixes: 56b11a2126bf2f42 ("perf bpf: Remove support for embedding clang for compiling BPF events (-e foo.c)")
Reported-by: Manu Bretelle <>
Reviewed-by: Ian Rogers <>
Reviewed-by: Manu Bretelle <>
Acked-by: Quentin Monnet <>
Cc: Adrian Hunter <>
Cc: Alexander Shishkin <>
Cc: Andi Kleen <>
Cc: Andrii Nakryiko <>
Cc: Anshuman Khandual <>
Cc: Carsten Haitzler <>
Cc: Eduard Zingerman <>
Cc: Fangrui Song <>
Cc: He Kuang <>
Cc: Ingo Molnar <>
Cc: James Clark <>
Cc: Jiri Olsa <>
Cc: Kan Liang <>
Cc: Leo Yan <>
Cc: Madhavan Srinivasan <>
Cc: Mark Rutland <>
Cc: Namhyung Kim <>
Cc: Nathan Chancellor <>
Cc: Naveen N. Rao <>
Cc: Nick Desaulniers <>
Cc: Peter Zijlstra <>
Cc: Ravi Bangoria <>
Cc: Rob Herring <>
Cc: Tiezhu Yang <>
Cc: Tom Rix <>
Cc: Wang Nan <>
Cc: Wang ShaoBo <>
Cc: Yang Jihong <>
Cc: Yonghong Song <>
Cc: YueHaibing <>
Signed-off-by: Arnaldo Carvalho de Melo <>
1 file changed