diff mbox

[05/53] perf tools: Test correct path of perf in build-test

Message ID 1452520124-2073-6-git-send-email-wangnan0@huawei.com
State Not Applicable, archived
Delegated to: David Miller
Headers show

Commit Message

Wangnan (F) Jan. 11, 2016, 1:47 p.m. UTC
If an 'O' is passed to 'make build-test', many 'test -x' and 'test -f'
will fail because perf resides in a different directory. Fix this by
computing PERF_OUT according to 'O' and test correct output files.
For make_kernelsrc and make_kernelsrc_tools, set KBUILD_OUTPUT_DIR
instead because the path is different from others ($(O)/perf vs
 $(O)/tools/perf).

Signed-off-by: Wang Nan <wangnan0@huawei.com>
Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
---
 tools/perf/tests/make | 23 +++++++++++++++--------
 1 file changed, 15 insertions(+), 8 deletions(-)

Comments

Arnaldo Carvalho de Melo Jan. 11, 2016, 3:24 p.m. UTC | #1
Em Mon, Jan 11, 2016 at 01:47:56PM +0000, Wang Nan escreveu:
> If an 'O' is passed to 'make build-test', many 'test -x' and 'test -f'
> will fail because perf resides in a different directory. Fix this by
> computing PERF_OUT according to 'O' and test correct output files.
> For make_kernelsrc and make_kernelsrc_tools, set KBUILD_OUTPUT_DIR
> instead because the path is different from others ($(O)/perf vs
>  $(O)/tools/perf).

Ok, applying up to this patch I now manage to almost cleanly build it using O=,
see below, but seems that we have some race, as not all tests end up producing
such warnings.

[acme@felicio linux]$ rm -rf /tmp/build/perf ; mkdir -p /tmp/build/perf ; make O=/tmp/build/perf -C tools/perf build-test
make: Entering directory `/home/acme/git/linux/tools/perf'
Testing Makefile
- make_no_libperl: cd . && make -f Makefile   DESTDIR=/tmp/tmp.m1nXBMqhSA NO_LIBPERL=1
find: ‘/tmp/build/perf/util/trace-event-scripting.o’: No such file or directory
find: ‘/tmp/build/perf/util/build-id.o’: No such file or directory
- make_no_libdw_dwarf_unwind: cd . && make -f Makefile   DESTDIR=/tmp/tmp.RB7Ile9C0b NO_LIBDW_DWARF_UNWIND=1
- make_no_backtrace: cd . && make -f Makefile   DESTDIR=/tmp/tmp.HeNpC0PW1O NO_BACKTRACE=1
find: ‘/tmp/build/perf/util/trace-event-scripting.o’: No such file or directory
find: ‘/tmp/build/perf/util/alias.o’: No such file or directory
- make_install_prefix: cd . && make -f Makefile   DESTDIR=/tmp/tmp.JPK5a72h53 install prefix=/tmp/krava
find: ‘/tmp/build/perf/libapi.a’: No such file or directory
- make_help: cd . && make -f Makefile   DESTDIR=/tmp/tmp.F3Z0qPtslS help
- make_doc: cd . && make -f Makefile   DESTDIR=/tmp/tmp.6a2HbvC2ej doc
Arnaldo Carvalho de Melo Jan. 11, 2016, 10:06 p.m. UTC | #2
Em Mon, Jan 11, 2016 at 12:24:56PM -0300, Arnaldo Carvalho de Melo escreveu:
> Em Mon, Jan 11, 2016 at 01:47:56PM +0000, Wang Nan escreveu:
> > If an 'O' is passed to 'make build-test', many 'test -x' and 'test -f'
> > will fail because perf resides in a different directory. Fix this by
> > computing PERF_OUT according to 'O' and test correct output files.
> > For make_kernelsrc and make_kernelsrc_tools, set KBUILD_OUTPUT_DIR
> > instead because the path is different from others ($(O)/perf vs
> >  $(O)/tools/perf).
> 
> Ok, applying up to this patch I now manage to almost cleanly build it using O=,
> see below, but seems that we have some race, as not all tests end up producing
> such warnings.
> 
> [acme@felicio linux]$ rm -rf /tmp/build/perf ; mkdir -p /tmp/build/perf ; make O=/tmp/build/perf -C tools/perf build-test
> make: Entering directory `/home/acme/git/linux/tools/perf'
> Testing Makefile
> - make_no_libperl: cd . && make -f Makefile   DESTDIR=/tmp/tmp.m1nXBMqhSA NO_LIBPERL=1
> find: ‘/tmp/build/perf/util/trace-event-scripting.o’: No such file or directory

Well, it is happening even without O=:


[acme@felicio linux]$ perf stat make -C tools/perf build-test
make: Entering directory `/home/acme/git/linux/tools/perf'
Testing Makefile
- make_doc: cd . && make -f Makefile   DESTDIR=/tmp/tmp.H8z3S3cEJ0 doc
- make_install_bin: cd . && make -f Makefile   DESTDIR=/tmp/tmp.njIAPXMF7f install-bin
- make_install_prefix: cd . && make -f Makefile   DESTDIR=/tmp/tmp.9FEKGBoeyN install prefix=/tmp/krava
- make_no_gtk2: cd . && make -f Makefile   DESTDIR=/tmp/tmp.nHl593wfMP NO_GTK2=1
- make_util_map_o: cd . && make -f Makefile   DESTDIR=/tmp/tmp.ZSmZP490hX util/map.o
- make_no_slang: cd . && make -f Makefile   DESTDIR=/tmp/tmp.7q24C1xmcu NO_SLANG=1
- make_pure: cd . && make -f Makefile   DESTDIR=/tmp/tmp.R51cy8kdWl 
- make_no_libpython: cd . && make -f Makefile   DESTDIR=/tmp/tmp.3t9tEc0e4b NO_LIBPYTHON=1
- make_no_libbionic: cd . && make -f Makefile   DESTDIR=/tmp/tmp.4yYelFUaq0 NO_LIBBIONIC=1
- make_no_newt: cd . && make -f Makefile   DESTDIR=/tmp/tmp.3Fg7hv3Hn1 NO_NEWT=1
- make_tags: cd . && make -f Makefile   DESTDIR=/tmp/tmp.8WMgskFkOH tags
- make_install: cd . && make -f Makefile   DESTDIR=/tmp/tmp.YQq3wOEkyB install
- make_no_libdw_dwarf_unwind: cd . && make -f Makefile   DESTDIR=/tmp/tmp.WKRVFDA2ty NO_LIBDW_DWARF_UNWIND=1
find: ‘/home/acme/git/linux/tools/perf/.gtk-in.o.cmd’: No such file or directory
find: ‘/home/acme/git/linux/tools/perf/builtin-script.o’: No such file or directory
- make_no_libunwind: cd . && make -f Makefile   DESTDIR=/tmp/tmp.SQftzGTUYf NO_LIBUNWIND=1
- make_no_auxtrace: cd . && make -f Makefile   DESTDIR=/tmp/tmp.Xy2xrSCVuO NO_AUXTRACE=1
- make_no_ui: cd . && make -f Makefile   DESTDIR=/tmp/tmp.ZFNEHWqQFN NO_NEWT=1 NO_SLANG=1 NO_GTK2=1
- make_no_libnuma: cd . && make -f Makefile   DESTDIR=/tmp/tmp.68zRtMaEqf NO_LIBNUMA=1
- make_no_backtrace: cd . && make -f Makefile   DESTDIR=/tmp/tmp.5xcea8XfdC NO_BACKTRACE=1
find: ‘/home/acme/git/linux/tools/perf/arch/x86/tests/dwarf-unwind.o’: No such file or directory
- make_install_prefix_slash: cd . && make -f Makefile   DESTDIR=/tmp/tmp.2c5BqUKGef install prefix=/tmp/krava/
find: ‘/home/acme/git/linux/tools/perf/builtin-record.o’: No such file or directory
find: ‘/home/acme/git/linux/tools/perf/builtin-inject.o’: No such file or directory
find: ‘/home/acme/git/linux/tools/perf/builtin-bench.o’: No such file or directory
find: ‘/home/acme/git/linux/tools/perf/.builtin-lock.o.cmd’: No such file or directory
find: ‘/home/acme/git/linux/tools/perf/perf.o’: No such file or directory
find: ‘/home/acme/git/linux/tools/perf/scripts/.libperf-in.o.cmd’: No such file or directory
find: ‘/home/acme/git/linux/tools/perf/tests/evsel-tp-sched.o’: No such file or directory
find: ‘/home/acme/git/linux/tools/perf/tests/hists_cumulate.o’: No such file or directory
- make_util_pmu_bison_o: cd . && make -f Makefile   DESTDIR=/tmp/tmp.aJUWyFbXsp util/pmu-bis
Arnaldo Carvalho de Melo Jan. 11, 2016, 10:39 p.m. UTC | #3
Em Mon, Jan 11, 2016 at 07:06:18PM -0300, Arnaldo Carvalho de Melo escreveu:
> Em Mon, Jan 11, 2016 at 12:24:56PM -0300, Arnaldo Carvalho de Melo escreveu:
> > Em Mon, Jan 11, 2016 at 01:47:56PM +0000, Wang Nan escreveu:
> > > If an 'O' is passed to 'make build-test', many 'test -x' and 'test -f'
> > > will fail because perf resides in a different directory. Fix this by
> > > computing PERF_OUT according to 'O' and test correct output files.
> > > For make_kernelsrc and make_kernelsrc_tools, set KBUILD_OUTPUT_DIR
> > > instead because the path is different from others ($(O)/perf vs
> > >  $(O)/tools/perf).
> > 
> > Ok, applying up to this patch I now manage to almost cleanly build it using O=,
> > see below, but seems that we have some race, as not all tests end up producing
> > such warnings.
> > 
> > [acme@felicio linux]$ rm -rf /tmp/build/perf ; mkdir -p /tmp/build/perf ; make O=/tmp/build/perf -C tools/perf build-test
> > make: Entering directory `/home/acme/git/linux/tools/perf'
> > Testing Makefile
> > - make_no_libperl: cd . && make -f Makefile   DESTDIR=/tmp/tmp.m1nXBMqhSA NO_LIBPERL=1
> > find: ‘/tmp/build/perf/util/trace-event-scripting.o’: No such file or directory
> 
> Well, it is happening even without O=:

So I removed a few patches and those aren't appearing anymore, please
take a look at my perf/core branch, running build-test on a few machines
now, will push soon.

My hunch is that build-test has issues with parallel builds, but I'm not
sure...

- Arnaldo
 
> 
> [acme@felicio linux]$ perf stat make -C tools/perf build-test
> make: Entering directory `/home/acme/git/linux/tools/perf'
> Testing Makefile
> - make_doc: cd . && make -f Makefile   DESTDIR=/tmp/tmp.H8z3S3cEJ0 doc
> - make_install_bin: cd . && make -f Makefile   DESTDIR=/tmp/tmp.njIAPXMF7f install-bin
> - make_install_prefix: cd . && make -f Makefile   DESTDIR=/tmp/tmp.9FEKGBoeyN install prefix=/tmp/krava
> - make_no_gtk2: cd . && make -f Makefile   DESTDIR=/tmp/tmp.nHl593wfMP NO_GTK2=1
> - make_util_map_o: cd . && make -f Makefile   DESTDIR=/tmp/tmp.ZSmZP490hX util/map.o
> - make_no_slang: cd . && make -f Makefile   DESTDIR=/tmp/tmp.7q24C1xmcu NO_SLANG=1
> - make_pure: cd . && make -f Makefile   DESTDIR=/tmp/tmp.R51cy8kdWl 
> - make_no_libpython: cd . && make -f Makefile   DESTDIR=/tmp/tmp.3t9tEc0e4b NO_LIBPYTHON=1
> - make_no_libbionic: cd . && make -f Makefile   DESTDIR=/tmp/tmp.4yYelFUaq0 NO_LIBBIONIC=1
> - make_no_newt: cd . && make -f Makefile   DESTDIR=/tmp/tmp.3Fg7hv3Hn1 NO_NEWT=1
> - make_tags: cd . && make -f Makefile   DESTDIR=/tmp/tmp.8WMgskFkOH tags
> - make_install: cd . && make -f Makefile   DESTDIR=/tmp/tmp.YQq3wOEkyB install
> - make_no_libdw_dwarf_unwind: cd . && make -f Makefile   DESTDIR=/tmp/tmp.WKRVFDA2ty NO_LIBDW_DWARF_UNWIND=1
> find: ‘/home/acme/git/linux/tools/perf/.gtk-in.o.cmd’: No such file or directory
> find: ‘/home/acme/git/linux/tools/perf/builtin-script.o’: No such file or directory
> - make_no_libunwind: cd . && make -f Makefile   DESTDIR=/tmp/tmp.SQftzGTUYf NO_LIBUNWIND=1
> - make_no_auxtrace: cd . && make -f Makefile   DESTDIR=/tmp/tmp.Xy2xrSCVuO NO_AUXTRACE=1
> - make_no_ui: cd . && make -f Makefile   DESTDIR=/tmp/tmp.ZFNEHWqQFN NO_NEWT=1 NO_SLANG=1 NO_GTK2=1
> - make_no_libnuma: cd . && make -f Makefile   DESTDIR=/tmp/tmp.68zRtMaEqf NO_LIBNUMA=1
> - make_no_backtrace: cd . && make -f Makefile   DESTDIR=/tmp/tmp.5xcea8XfdC NO_BACKTRACE=1
> find: ‘/home/acme/git/linux/tools/perf/arch/x86/tests/dwarf-unwind.o’: No such file or directory
> - make_install_prefix_slash: cd . && make -f Makefile   DESTDIR=/tmp/tmp.2c5BqUKGef install prefix=/tmp/krava/
> find: ‘/home/acme/git/linux/tools/perf/builtin-record.o’: No such file or directory
> find: ‘/home/acme/git/linux/tools/perf/builtin-inject.o’: No such file or directory
> find: ‘/home/acme/git/linux/tools/perf/builtin-bench.o’: No such file or directory
> find: ‘/home/acme/git/linux/tools/perf/.builtin-lock.o.cmd’: No such file or directory
> find: ‘/home/acme/git/linux/tools/perf/perf.o’: No such file or directory
> find: ‘/home/acme/git/linux/tools/perf/scripts/.libperf-in.o.cmd’: No such file or directory
> find: ‘/home/acme/git/linux/tools/perf/tests/evsel-tp-sched.o’: No such file or directory
> find: ‘/home/acme/git/linux/tools/perf/tests/hists_cumulate.o’: No such file or directory
> - make_util_pmu_bison_o: cd . && make -f Makefile   DESTDIR=/tmp/tmp.aJUWyFbXsp util/pmu-bis
Arnaldo Carvalho de Melo Jan. 11, 2016, 10:39 p.m. UTC | #4
Em Mon, Jan 11, 2016 at 07:39:04PM -0300, Arnaldo Carvalho de Melo escreveu:
> Em Mon, Jan 11, 2016 at 07:06:18PM -0300, Arnaldo Carvalho de Melo escreveu:
> > Em Mon, Jan 11, 2016 at 12:24:56PM -0300, Arnaldo Carvalho de Melo escreveu:
> > > Em Mon, Jan 11, 2016 at 01:47:56PM +0000, Wang Nan escreveu:
> > > > If an 'O' is passed to 'make build-test', many 'test -x' and 'test -f'
> > > > will fail because perf resides in a different directory. Fix this by
> > > > computing PERF_OUT according to 'O' and test correct output files.
> > > > For make_kernelsrc and make_kernelsrc_tools, set KBUILD_OUTPUT_DIR
> > > > instead because the path is different from others ($(O)/perf vs
> > > >  $(O)/tools/perf).
> > > 
> > > Ok, applying up to this patch I now manage to almost cleanly build it using O=,
> > > see below, but seems that we have some race, as not all tests end up producing
> > > such warnings.
> > > 
> > > [acme@felicio linux]$ rm -rf /tmp/build/perf ; mkdir -p /tmp/build/perf ; make O=/tmp/build/perf -C tools/perf build-test
> > > make: Entering directory `/home/acme/git/linux/tools/perf'
> > > Testing Makefile
> > > - make_no_libperl: cd . && make -f Makefile   DESTDIR=/tmp/tmp.m1nXBMqhSA NO_LIBPERL=1
> > > find: ‘/tmp/build/perf/util/trace-event-scripting.o’: No such file or directory
> > 
> > Well, it is happening even without O=:
> 
> So I removed a few patches and those aren't appearing anymore, please
> take a look at my perf/core branch, running build-test on a few machines
> now, will push soon.
> 
> My hunch is that build-test has issues with parallel builds, but I'm not
> sure...


Good:

- make_perf_o_O: cd . && make -f Makefile O=/tmp/tmp.oLeg8aUaOo DESTDIR=/tmp/tmp.16WP4HTQJs perf.o
- make_util_pmu_bison_o_O: cd . && make -f Makefile O=/tmp/tmp.xNRV0pCXfD DESTDIR=/tmp/tmp.8dyU9uEbHe util/pmu-bison.o
- make_no_libdw_dwarf_unwind_O: cd . && make -f Makefile O=/tmp/tmp.pHH4HExHcH DESTDIR=/tmp/tmp.Wo0m8fF5cp NO_LIBDW_DWARF_UNWIND=1
- make_no_demangle_O: cd . && make -f Makefile O=/tmp/tmp.yWNsd4jOsI DESTDIR=/tmp/tmp.Q7eA4kCvwL NO_DEMANGLE=1
- tarpkg: ./tests/perf-targz-src-pkg .
- make -C <kernelsrc> tools/perf
- make -C <kernelsrc>/tools perf
OK
Wangnan (F) Jan. 12, 2016, 7:16 a.m. UTC | #5
On 2016/1/12 6:39, Arnaldo Carvalho de Melo wrote:
> Em Mon, Jan 11, 2016 at 07:39:04PM -0300, Arnaldo Carvalho de Melo escreveu:
>> Em Mon, Jan 11, 2016 at 07:06:18PM -0300, Arnaldo Carvalho de Melo escreveu:
>>> Em Mon, Jan 11, 2016 at 12:24:56PM -0300, Arnaldo Carvalho de Melo escreveu:
>>>> Em Mon, Jan 11, 2016 at 01:47:56PM +0000, Wang Nan escreveu:
>>>>> If an 'O' is passed to 'make build-test', many 'test -x' and 'test -f'
>>>>> will fail because perf resides in a different directory. Fix this by
>>>>> computing PERF_OUT according to 'O' and test correct output files.
>>>>> For make_kernelsrc and make_kernelsrc_tools, set KBUILD_OUTPUT_DIR
>>>>> instead because the path is different from others ($(O)/perf vs
>>>>>   $(O)/tools/perf).
>>>> Ok, applying up to this patch I now manage to almost cleanly build it using O=,
>>>> see below, but seems that we have some race, as not all tests end up producing
>>>> such warnings.
>>>>
>>>> [acme@felicio linux]$ rm -rf /tmp/build/perf ; mkdir -p /tmp/build/perf ; make O=/tmp/build/perf -C tools/perf build-test
>>>> make: Entering directory `/home/acme/git/linux/tools/perf'
>>>> Testing Makefile
>>>> - make_no_libperl: cd . && make -f Makefile   DESTDIR=/tmp/tmp.m1nXBMqhSA NO_LIBPERL=1
>>>> find: ‘/tmp/build/perf/util/trace-event-scripting.o’: No such file or directory

This can happen when you parallelly run find and rm on one directory. 
However,
I've never seen this message in build-test before.

>>> Well, it is happening even without O=:
>> So I removed a few patches and those aren't appearing anymore, please
>> take a look at my perf/core branch, running build-test on a few machines
>> now, will push soon.
>>
>> My hunch is that build-test has issues with parallel builds, but I'm not
>> sure...
>
> Good:
>
> - make_perf_o_O: cd . && make -f Makefile O=/tmp/tmp.oLeg8aUaOo DESTDIR=/tmp/tmp.16WP4HTQJs perf.o
> - make_util_pmu_bison_o_O: cd . && make -f Makefile O=/tmp/tmp.xNRV0pCXfD DESTDIR=/tmp/tmp.8dyU9uEbHe util/pmu-bison.o
> - make_no_libdw_dwarf_unwind_O: cd . && make -f Makefile O=/tmp/tmp.pHH4HExHcH DESTDIR=/tmp/tmp.Wo0m8fF5cp NO_LIBDW_DWARF_UNWIND=1
> - make_no_demangle_O: cd . && make -f Makefile O=/tmp/tmp.yWNsd4jOsI DESTDIR=/tmp/tmp.Q7eA4kCvwL NO_DEMANGLE=1
> - tarpkg: ./tests/perf-targz-src-pkg .
> - make -C <kernelsrc> tools/perf
> - make -C <kernelsrc>/tools perf
> OK
Glad to see this.

Thank you.
Arnaldo Carvalho de Melo Jan. 12, 2016, 2:08 p.m. UTC | #6
Em Tue, Jan 12, 2016 at 03:16:08PM +0800, Wangnan (F) escreveu:
> 
> 
> On 2016/1/12 6:39, Arnaldo Carvalho de Melo wrote:
> >Em Mon, Jan 11, 2016 at 07:39:04PM -0300, Arnaldo Carvalho de Melo escreveu:
> >>Em Mon, Jan 11, 2016 at 07:06:18PM -0300, Arnaldo Carvalho de Melo escreveu:
> >>>Em Mon, Jan 11, 2016 at 12:24:56PM -0300, Arnaldo Carvalho de Melo escreveu:
> >>>>Em Mon, Jan 11, 2016 at 01:47:56PM +0000, Wang Nan escreveu:
> >>>>>If an 'O' is passed to 'make build-test', many 'test -x' and 'test -f'
> >>>>>will fail because perf resides in a different directory. Fix this by
> >>>>>computing PERF_OUT according to 'O' and test correct output files.
> >>>>>For make_kernelsrc and make_kernelsrc_tools, set KBUILD_OUTPUT_DIR
> >>>>>instead because the path is different from others ($(O)/perf vs
> >>>>>  $(O)/tools/perf).
> >>>>Ok, applying up to this patch I now manage to almost cleanly build it using O=,
> >>>>see below, but seems that we have some race, as not all tests end up producing
> >>>>such warnings.
> >>>>
> >>>>[acme@felicio linux]$ rm -rf /tmp/build/perf ; mkdir -p /tmp/build/perf ; make O=/tmp/build/perf -C tools/perf build-test
> >>>>make: Entering directory `/home/acme/git/linux/tools/perf'
> >>>>Testing Makefile
> >>>>- make_no_libperl: cd . && make -f Makefile   DESTDIR=/tmp/tmp.m1nXBMqhSA NO_LIBPERL=1
> >>>>find: ‘/tmp/build/perf/util/trace-event-scripting.o’: No such file or directory
> 
> This can happen when you parallelly run find and rm on one directory.
> However,
> I've never seen this message in build-test before.

I'll leave this in the backburner for now, there are other, more
important patches to process, we should revisit this as soon as we
process the other eBPF patches :-\
 
> >>>Well, it is happening even without O=:
> >>So I removed a few patches and those aren't appearing anymore, please
> >>take a look at my perf/core branch, running build-test on a few machines
> >>now, will push soon.
> >>
> >>My hunch is that build-test has issues with parallel builds, but I'm not
> >>sure...
> >
> >Good:
> >
> >- make_perf_o_O: cd . && make -f Makefile O=/tmp/tmp.oLeg8aUaOo DESTDIR=/tmp/tmp.16WP4HTQJs perf.o
> >- make_util_pmu_bison_o_O: cd . && make -f Makefile O=/tmp/tmp.xNRV0pCXfD DESTDIR=/tmp/tmp.8dyU9uEbHe util/pmu-bison.o
> >- make_no_libdw_dwarf_unwind_O: cd . && make -f Makefile O=/tmp/tmp.pHH4HExHcH DESTDIR=/tmp/tmp.Wo0m8fF5cp NO_LIBDW_DWARF_UNWIND=1
> >- make_no_demangle_O: cd . && make -f Makefile O=/tmp/tmp.yWNsd4jOsI DESTDIR=/tmp/tmp.Q7eA4kCvwL NO_DEMANGLE=1
> >- tarpkg: ./tests/perf-targz-src-pkg .
> >- make -C <kernelsrc> tools/perf
> >- make -C <kernelsrc>/tools perf
> >OK
> Glad to see this.
> 
> Thank you.
diff mbox

Patch

diff --git a/tools/perf/tests/make b/tools/perf/tests/make
index a32615a3..0f5afcb 100644
--- a/tools/perf/tests/make
+++ b/tools/perf/tests/make
@@ -11,10 +11,12 @@  else
 endif
 else
 PERF := .
+PERF_OUT := $(PERF)
 O_OPT :=
 
 ifneq ($(O),)
   FULL_O := $(shell readlink -f $(O) || echo $(O))
+  PERF_OUT := $(FULL_O)
   ifeq ($(SET_O),1)
     O_OPT := 'O=$(FULL_O)'
   endif
@@ -159,11 +161,11 @@  test_make_doc    := $(test_ok)
 test_make_help_O := $(test_ok)
 test_make_doc_O  := $(test_ok)
 
-test_make_python_perf_so := test -f $(PERF)/python/perf.so
+test_make_python_perf_so := test -f $(PERF_OUT)/python/perf.so
 
-test_make_perf_o           := test -f $(PERF)/perf.o
-test_make_util_map_o       := test -f $(PERF)/util/map.o
-test_make_util_pmu_bison_o := test -f $(PERF)/util/pmu-bison.o
+test_make_perf_o           := test -f $(PERF_OUT)/perf.o
+test_make_util_map_o       := test -f $(PERF_OUT)/util/map.o
+test_make_util_pmu_bison_o := test -f $(PERF_OUT)/util/pmu-bison.o
 
 define test_dest_files
   for file in $(1); do				\
@@ -230,7 +232,7 @@  test_make_perf_o_O            := test -f $$TMP_O/perf.o
 test_make_util_map_o_O        := test -f $$TMP_O/util/map.o
 test_make_util_pmu_bison_o_O := test -f $$TMP_O/util/pmu-bison.o
 
-test_default = test -x $(PERF)/perf
+test_default = test -x $(PERF_OUT)/perf
 test = $(if $(test_$1),$(test_$1),$(test_default))
 
 test_default_O = test -x $$TMP_O/perf
@@ -250,7 +252,7 @@  endif
 
 MAKEFLAGS := --no-print-directory
 
-clean := @(cd $(PERF); make -s -f $(MK) clean >/dev/null)
+clean := @(cd $(PERF); make -s -f $(MK) O=$(PERF_OUT) clean >/dev/null; make -s -f $(MK) clean >/dev/null)
 
 $(run):
 	$(call clean)
@@ -279,17 +281,22 @@  tarpkg:
 	( eval $$cmd ) >> $@ 2>&1 && \
 	rm -f $@
 
+KBUILD_OUTPUT_DIR := ../..
+ifneq ($(O),)
+  KBUILD_OUTPUT_DIR := $(O)
+endif
+
 make_kernelsrc:
 	@echo "- make -C <kernelsrc> $(PARALLEL_OPT) tools/perf"
 	$(call clean); \
 	(make -C ../.. $(PARALLEL_OPT) tools/perf) > $@ 2>&1 && \
-	test -x perf && rm -f $@ || (cat $@ ; false)
+	test -x $(KBUILD_OUTPUT_DIR)/tools/perf && rm -f $@ || (cat $@ ; false)
 
 make_kernelsrc_tools:
 	@echo "- make -C <kernelsrc>/tools $(PARALLEL_OPT) perf"
 	$(call clean); \
 	(make -C ../../tools $(PARALLEL_OPT) perf) > $@ 2>&1 && \
-	test -x perf && rm -f $@ || (cat $@ ; false)
+	test -x $(KBUILD_OUTPUT_DIR)/tools/perf && rm -f $@ || (cat $@ ; false)
 
 all: $(run) $(run_O) tarpkg make_kernelsrc make_kernelsrc_tools
 	@echo OK