Skip to contentSkip to conversation

UAPI: perf fixes

GIT PULL In review David Howells 4 participants 20 messages Nov 8, 2012 – Dec 8, 2012

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

Hi Arnaldo,

Assuming my patches should be based on your perf/core branch, could you pull from my git tree at tag perf-uapi-20121108 into your perf/core branch?

Note the tree also contains a uapi-perf-x86-20121108 tag that has the UAPI disintegration branch for x86 merged on top for reference.

There are six commits, three preliminary patches:

(1) A patch to export asm/svm.h, asm/vmx.h and asm/perf_regs.h to UAPI.

(2) A merge for (1) - the patch in (1) is premerged by the UAPI disintegration for x86 also, and I'd rather not include your perf/core branch in that if I can avoid it.

(3) A patch to export and disintegrate linux/hw_breakpoint.h. It looks like it should perhaps have been exported already, given the __KERNEL__ markers in it.

and then the main three patches:

(4) Use a makefile $(call ...) function in tools/Makefile to make it easier to deal with.

(5) Fix handling of O= with a relative path when doing something like:

make tools/perf O=foo

from the top-level directory in the kernel source tree for all tools.

(6) Make perf work for x86 by adding -I flags and changing long #includes with "../../include" in them into short <asm/foo.h> type things.

David
---
The following changes since commit 8dfec403e39b7c37fd6e8813bacc01da1e1210ab:

perf tests: Removing 'optional' field (2012-11-05 14:03:59 -0300)

are available in the git repository at:

git://git.infradead.org/users/dhowells/linux-headers.git tags/perf-uapi-20121108

for you to fetch changes up to 028c2c390c71d3d37f91291ac8e827f5028f7975:

perf: Make perf build for x86 with UAPI disintegration applied (2012-11-08 11:55:58 +0000)

----------------------------------------------------------------
perf fixes 2012-11-08

----------------------------------------------------------------
David Howells (6):
x86: Export asm/{svm.h,vmx.h,perf_regs.h}
UAPI: Merge pre-disintegration bits for x86
UAPI: Export and disintegrate linux/hw_breakpoint.h
tools: Define a Makefile function to do subdir processing
tools: Honour the O= flag when tool build called from a higher Makefile
perf: Make perf build for x86 with UAPI disintegration applied

 Makefile                                |  6 ++++--
 arch/x86/include/asm/Kbuild             |  3 +++
 include/linux/hw_breakpoint.h           | 31 +------------------------------
 include/uapi/linux/Kbuild               |  1 +
 include/uapi/linux/hw_breakpoint.h      | 30 ++++++++++++++++++++++++++++++
 tools/Makefile                          | 24 ++++++++++++------------
 tools/perf/Makefile                     | 28 +++++++++++++++++++++++++++-
 tools/perf/arch/x86/include/perf_regs.h |  2 +-
 tools/perf/builtin-kvm.c                |  6 +++---
 tools/perf/perf.h                       | 16 +++-------------
 tools/perf/tests/builtin-test.c         |  2 +-
 tools/perf/tests/parse-events.c         |  2 +-
 tools/perf/util/evsel.c                 |  4 ++--
 tools/perf/util/evsel.h                 |  2 +-
 tools/perf/util/header.h                |  2 +-
 tools/perf/util/parse-events.c          |  2 +-
 tools/perf/util/parse-events.h          |  2 +-
 tools/perf/util/pmu.h                   |  2 +-
 tools/perf/util/session.h               |  2 +-
 tools/scripts/Makefile.include          | 23 ++++++++++++++++++++---
 20 files changed, 115 insertions(+), 75 deletions(-)
 create mode 100644 include/uapi/linux/hw_breakpoint.h
#1 lore raw
Quoted 3 lines · David Howells

(6) Make perf work for x86 by adding -I flags and changing long #includes with "../../include" in them into short <asm/foo.h> type things.

This patch seems to break building perf on ppc64. It fails with:

+ make -j16 -C tools/perf -s V=1 WERROR=0 HAVE_CPLUS_DEMANGLE=1 prefix=/usr all

<snip>

builtin-kvm.c:25:21: fatal error: asm/svm.h: No such file or directory compilation terminated.
make: *** [builtin-kvm.o] Error 1
make: *** Waiting for unfinished jobs....

And that is indeed because arch/powerpc/include/asm/svm.h doesn't exist (and therefore can't be exported like the first patch for x86 in this series does). You can find full build logs with this patch series applied here: http://ppc.koji.fedoraproject.org/koji/taskinfo?taskID=781782

However, without some form of fix for the ../.. includes, perf still fails to build on arches like ARM and powerpc with errors like this:

In file included from util/../perf.h:29:0,
from util/cache.h:7,
from util/quote.c:1:
util/../../../arch/powerpc/include/asm/unistd.h:12:29: fatal error:
uapi/asm/unistd.h: No such file or directory
compilation terminated.
make: *** [util/parse-events-test.o] Error 1

Full build logs here:
http://ppc.koji.fedoraproject.org/koji/taskinfo?taskID=781076

So. Something else might need to be done to fix perf builds for non-x86 arches.

josh

#2 lore raw
Quoted 1 line · Josh Boyer

This patch seems to break building perf on ppc64. It fails with:

Hmmm... Getting my hands on an ARM or ppc/ppc64 box running Fedora is a problem, and as far as I know, this needs to be built natively or maybe cross-compiled with a full environment (including graphics libs).

David

#3 lore raw
Quoted 7 lines · David Howells
Quoted 1 line · Josh Boyer

This patch seems to break building perf on ppc64. It fails with:

Hmmm... Getting my hands on an ARM or ppc/ppc64 box running Fedora is a problem, and as far as I know, this needs to be built natively or maybe cross-compiled with a full environment (including graphics libs).

Actually, having said that, it doesn't need to run Fedora specifically - only a sufficiently recent environment that it can build a cutting-edge kernel.

David

#4 lore raw
Quoted 4 lines · David Howells
Quoted 2 lines · David Howells

Josh Boyer <[email protected]> wrote:

Quoted 8 lines
Quoted 5 lines
Quoted 1 line

This patch seems to break building perf on ppc64. It fails with:

Hmmm... Getting my hands on an ARM or ppc/ppc64 box running Fedora is a problem, and as far as I know, this needs to be built natively or maybe cross-compiled with a full environment (including graphics libs).

Actually, having said that, it doesn't need to run Fedora specifically - only a sufficiently recent environment that it can build a cutting-edge kernel.

You can just use koji scratch builds if you want to test Fedora kernels Either arm-koji or ppc-koji should work. If you want actual access to a machine, I'm sure we can find one.

The error that is hitting ARM and ppc before your patch seemed to also be hit with sparc and was fixed by David Miller with commit 776260818 by just pointing to "../../arch/sparc/include/uapi/asm/unistd.h". That might be a temporary solution.

josh

#5 lore raw
In reply to Josh Boyer
Quoted 7 lines · Josh Boyer

This patch seems to break building perf on ppc64. It fails with:

+ make -j16 -C tools/perf -s V=1 WERROR=0 HAVE_CPLUS_DEMANGLE=1 prefix=/usr all

<snip>

builtin-kvm.c:25:21: fatal error: asm/svm.h: No such file or directory

tools/perf/builtin-kvm.c became x86-only with the following commit:

	commit bcf6edcd6fdb8965290f0b635a530fa3c6c212e1
	Author: Xiao Guangrong <[email protected]>
	Date:   Mon Sep 17 16:31:15 2012 +0800
	Subject: perf kvm: Events analysis tool

when it added:

	+#include "../../arch/x86/include/asm/svm.h"
	+#include "../../arch/x86/include/asm/vmx.h"
	+#include "../../arch/x86/include/asm/kvm.h"

and my changing these to <asm/foo.h> doesn't matter because of this in the same file:

	+struct exit_reasons_table vmx_exit_reasons[] = {
	+       VMX_EXIT_REASONS
	+};
	+
	+struct exit_reasons_table svm_exit_reasons[] = {
	+       SVM_EXIT_REASONS
	+};

which use macros only x86 defines.

Should the exported parts of these files be moved to asm-generic?

David

#6 lore raw
Quoted 34 lines · David Howells
Quoted 7 lines · Josh Boyer

This patch seems to break building perf on ppc64. It fails with:

+ make -j16 -C tools/perf -s V=1 WERROR=0 HAVE_CPLUS_DEMANGLE=1 prefix=/usr all

<snip>

builtin-kvm.c:25:21: fatal error: asm/svm.h: No such file or directory

tools/perf/builtin-kvm.c became x86-only with the following commit:

commit bcf6edcd6fdb8965290f0b635a530fa3c6c212e1
Author: Xiao Guangrong <[email protected]>
Date: Mon Sep 17 16:31:15 2012 +0800
Subject: perf kvm: Events analysis tool

when it added:

        +#include "../../arch/x86/include/asm/svm.h"
        +#include "../../arch/x86/include/asm/vmx.h"
        +#include "../../arch/x86/include/asm/kvm.h"

and my changing these to <asm/foo.h> doesn't matter because of this in the same file:

        +struct exit_reasons_table vmx_exit_reasons[] = {
        +       VMX_EXIT_REASONS
        +};
        +
        +struct exit_reasons_table svm_exit_reasons[] = {
        +       SVM_EXIT_REASONS
        +};
Quoted 1 line

which use macros only x86 defines.

Ah. You are quite right. So your patches actually fix the unistd.h error we were seeing early and just got us far enough to hit this other unrelated problem. My mistake.

Quoted 1 line

Should the exported parts of these files be moved to asm-generic?

Good question.

josh

#7 lore raw

Em Tue, Nov 13, 2012 at 10:42:02AM -0500, Josh Boyer escreveu:

Quoted 28 lines · David Howells
Quoted 25 lines

Josh Boyer <[email protected]> wrote:
tools/perf/builtin-kvm.c became x86-only with the following commit:

commit bcf6edcd6fdb8965290f0b635a530fa3c6c212e1
Author: Xiao Guangrong <[email protected]>
Date: Mon Sep 17 16:31:15 2012 +0800
Subject: perf kvm: Events analysis tool

when it added:

        +#include "../../arch/x86/include/asm/svm.h"
        +#include "../../arch/x86/include/asm/vmx.h"
        +#include "../../arch/x86/include/asm/kvm.h"

and my changing these to <asm/foo.h> doesn't matter because of this in the same file:

        +struct exit_reasons_table vmx_exit_reasons[] = {
        +       VMX_EXIT_REASONS
        +};
        +
        +struct exit_reasons_table svm_exit_reasons[] = {
        +       SVM_EXIT_REASONS
        +};
Quoted 1 line

which use macros only x86 defines.

Quoted 7 lines

Ah. You are quite right. So your patches actually fix the unistd.h error we were seeing early and just got us far enough to hit this other unrelated problem. My mistake.

Quoted 1 line

Should the exported parts of these files be moved to asm-generic?

Good question.

Probably we should do Makefile changes to build 'perf kvm' only on the platforms where it makes sense.

- Arnaldo

#8 lore raw
Quoted 33 lines · Arnaldo Carvalho de Melo

Em Tue, Nov 13, 2012 at 10:42:02AM -0500, Josh Boyer escreveu:

Quoted 32 lines · David Howells
Quoted 25 lines

Josh Boyer <[email protected]> wrote:
tools/perf/builtin-kvm.c became x86-only with the following commit:

commit bcf6edcd6fdb8965290f0b635a530fa3c6c212e1
Author: Xiao Guangrong <[email protected]>
Date: Mon Sep 17 16:31:15 2012 +0800
Subject: perf kvm: Events analysis tool

when it added:

        +#include "../../arch/x86/include/asm/svm.h"
        +#include "../../arch/x86/include/asm/vmx.h"
        +#include "../../arch/x86/include/asm/kvm.h"

and my changing these to <asm/foo.h> doesn't matter because of this in the same file:

        +struct exit_reasons_table vmx_exit_reasons[] = {
        +       VMX_EXIT_REASONS
        +};
        +
        +struct exit_reasons_table svm_exit_reasons[] = {
        +       SVM_EXIT_REASONS
        +};
Quoted 1 line

which use macros only x86 defines.

Ah. You are quite right. So your patches actually fix the unistd.h error we were seeing early and just got us far enough to hit this other unrelated problem. My mistake.

Quoted 6 lines
Quoted 3 lines
Quoted 1 line

Should the exported parts of these files be moved to asm-generic?

Good question.

Probably we should do Makefile changes to build 'perf kvm' only on the platforms where it makes sense.

Only 'perf kvm stat' command is only supported on x86, how about add "#ifdef ARCH_X86_64" around these code?

#9 lore raw

PATCH 1/2 perf kvm: rename perf_kvm to perf_kvm_stat

In reply to Arnaldo Carvalho de Melo

Then, let it only be used in 'perf kvm stat'

---
 tools/perf/builtin-kvm.c |  111 +++++++++++++++++++++++++---------------------
 1 files changed, 60 insertions(+), 51 deletions(-)
tools/perf/builtin-kvm.c +60 -51
index 836c82f..7fb426b 100644
@@ -58,7 +58,7 @@ struct kvm_event_key {
 };
 
 
-struct perf_kvm;
+struct perf_kvm_stat;
 
 struct kvm_events_ops {
 	bool (*is_begin_event)(struct perf_evsel *evsel,
@@ -66,7 +66,7 @@ struct kvm_events_ops {
 			       struct event_key *key);
 	bool (*is_end_event)(struct perf_evsel *evsel,
 			     struct perf_sample *sample, struct event_key *key);
-	void (*decode_key)(struct perf_kvm *kvm, struct event_key *key,
+	void (*decode_key)(struct perf_kvm_stat *kvm, struct event_key *key,
 			   char decode[20]);
 	const char *name;
 };
@@ -79,7 +79,7 @@ struct exit_reasons_table {
 #define EVENTS_BITS		12
 #define EVENTS_CACHE_SIZE	(1UL << EVENTS_BITS)
 
-struct perf_kvm {
+struct perf_kvm_stat {
 	struct perf_tool    tool;
 	struct perf_session *session;
 
@@ -146,7 +146,7 @@ static struct exit_reasons_table svm_exit_reasons[] = {
 	SVM_EXIT_REASONS
 };
 
-static const char *get_exit_reason(struct perf_kvm *kvm, u64 exit_code)
+static const char *get_exit_reason(struct perf_kvm_stat *kvm, u64 exit_code)
 {
 	int i = kvm->exit_reasons_size;
 	struct exit_reasons_table *tbl = kvm->exit_reasons;
@@ -162,7 +162,7 @@ static const char *get_exit_reason(struct perf_kvm *kvm, u64 exit_code)
 	return "UNKNOWN";
 }
 
-static void exit_event_decode_key(struct perf_kvm *kvm,
+static void exit_event_decode_key(struct perf_kvm_stat *kvm,
 				  struct event_key *key,
 				  char decode[20])
 {
@@ -228,7 +228,7 @@ static bool mmio_event_end(struct perf_evsel *evsel, struct perf_sample *sample,
 	return false;
 }
 
-static void mmio_event_decode_key(struct perf_kvm *kvm __maybe_unused,
+static void mmio_event_decode_key(struct perf_kvm_stat *kvm __maybe_unused,
 				  struct event_key *key,
 				  char decode[20])
 {
@@ -271,7 +271,7 @@ static bool ioport_event_end(struct perf_evsel *evsel,
 	return kvm_entry_event(evsel);
 }
 
-static void ioport_event_decode_key(struct perf_kvm *kvm __maybe_unused,
+static void ioport_event_decode_key(struct perf_kvm_stat *kvm __maybe_unused,
 				    struct event_key *key,
 				    char decode[20])
 {
@@ -286,7 +286,7 @@ static struct kvm_events_ops ioport_events = {
 	.name = "IO Port Access"
 };
 
-static bool register_kvm_events_ops(struct perf_kvm *kvm)
+static bool register_kvm_events_ops(struct perf_kvm_stat *kvm)
 {
 	bool ret = true;
 
@@ -311,7 +311,7 @@ struct vcpu_event_record {
 };
 
 
-static void init_kvm_event_record(struct perf_kvm *kvm)
+static void init_kvm_event_record(struct perf_kvm_stat *kvm)
 {
 	unsigned int i;
 
@@ -360,7 +360,7 @@ static struct kvm_event *kvm_alloc_init_event(struct event_key *key)
 	return event;
 }
 
-static struct kvm_event *find_create_kvm_event(struct perf_kvm *kvm,
+static struct kvm_event *find_create_kvm_event(struct perf_kvm_stat *kvm,
 					       struct event_key *key)
 {
 	struct kvm_event *event;
@@ -382,7 +382,7 @@ static struct kvm_event *find_create_kvm_event(struct perf_kvm *kvm,
 	return event;
 }
 
-static bool handle_begin_event(struct perf_kvm *kvm,
+static bool handle_begin_event(struct perf_kvm_stat *kvm,
 			       struct vcpu_event_record *vcpu_record,
 			       struct event_key *key, u64 timestamp)
 {
@@ -429,7 +429,7 @@ static bool update_kvm_event(struct kvm_event *event, int vcpu_id,
 	return true;
 }
 
-static bool handle_end_event(struct perf_kvm *kvm,
+static bool handle_end_event(struct perf_kvm_stat *kvm,
 			     struct vcpu_event_record *vcpu_record,
 			     struct event_key *key,
 			     u64 timestamp)
@@ -496,7 +496,7 @@ struct vcpu_event_record *per_vcpu_record(struct thread *thread,
 	return thread->priv;
 }
 
-static bool handle_kvm_event(struct perf_kvm *kvm,
+static bool handle_kvm_event(struct perf_kvm_stat *kvm,
 			     struct thread *thread,
 			     struct perf_evsel *evsel,
 			     struct perf_sample *sample)
@@ -556,7 +556,7 @@ static struct kvm_event_key keys[] = {
 	{ NULL, NULL }
 };
 
-static bool select_key(struct perf_kvm *kvm)
+static bool select_key(struct perf_kvm_stat *kvm)
 {
 	int i;
 
@@ -592,7 +592,8 @@ static void insert_to_result(struct rb_root *result, struct kvm_event *event,
 	rb_insert_color(&event->rb, result);
 }
 
-static void update_total_count(struct perf_kvm *kvm, struct kvm_event *event)
+static void
+update_total_count(struct perf_kvm_stat *kvm, struct kvm_event *event)
 {
 	int vcpu = kvm->trace_vcpu;
 
@@ -605,7 +606,7 @@ static bool event_is_valid(struct kvm_event *event, int vcpu)
 	return !!get_event_count(event, vcpu);
 }
 
-static void sort_result(struct perf_kvm *kvm)
+static void sort_result(struct perf_kvm_stat *kvm)
 {
 	unsigned int i;
 	int vcpu = kvm->trace_vcpu;
@@ -644,7 +645,7 @@ static void print_vcpu_info(int vcpu)
 		pr_info("VCPU %d:\n\n", vcpu);
 }
 
-static void print_result(struct perf_kvm *kvm)
+static void print_result(struct perf_kvm_stat *kvm)
 {
 	char decode[20];
 	struct kvm_event *event;
@@ -687,7 +688,8 @@ static int process_sample_event(struct perf_tool *tool,
 				struct machine *machine)
 {
 	struct thread *thread = machine__findnew_thread(machine, sample->tid);
-	struct perf_kvm *kvm = container_of(tool, struct perf_kvm, tool);
+	struct perf_kvm_stat *kvm = container_of(tool, struct perf_kvm_stat,
+						 tool);
 
 	if (thread == NULL) {
 		pr_debug("problem processing %d event, skipping it.\n",
@@ -718,7 +720,7 @@ static int get_cpu_isa(struct perf_session *session)
 	return isa;
 }
 
-static int read_events(struct perf_kvm *kvm)
+static int read_events(struct perf_kvm_stat *kvm)
 {
 	int ret;
 
@@ -767,7 +769,7 @@ static bool verify_vcpu(int vcpu)
 	return true;
 }
 
-static int kvm_events_report_vcpu(struct perf_kvm *kvm)
+static int kvm_events_report_vcpu(struct perf_kvm_stat *kvm)
 {
 	int ret = -EINVAL;
 	int vcpu = kvm->trace_vcpu;
@@ -815,7 +817,8 @@ static const char * const record_args[] = {
 		_p;			\
 	})
 
-static int kvm_events_record(struct perf_kvm *kvm, int argc, const char **argv)
+static int
+kvm_events_record(struct perf_kvm_stat *kvm, int argc, const char **argv)
 {
 	unsigned int rec_argc, i, j;
 	const char **rec_argv;
@@ -838,7 +841,8 @@ static int kvm_events_record(struct perf_kvm *kvm, int argc, const char **argv)
 	return cmd_record(i, rec_argv, NULL);
 }
 
-static int kvm_events_report(struct perf_kvm *kvm, int argc, const char **argv)
+static int
+kvm_events_report(struct perf_kvm_stat *kvm, int argc, const char **argv)
 {
 	const struct option kvm_events_report_options[] = {
 		OPT_STRING(0, "event", &kvm->report_event, "report event",
@@ -881,24 +885,36 @@ static void print_kvm_stat_usage(void)
 	printf("\nOtherwise, it is the alias of 'perf stat':\n");
 }
 
-static int kvm_cmd_stat(struct perf_kvm *kvm, int argc, const char **argv)
+static int kvm_cmd_stat(const char *file_name, int argc, const char **argv)
 {
+	struct perf_kvm_stat kvm = {
+		.file_name = file_name,
+
+		.trace_vcpu	= -1,
+		.report_event	= "vmexit",
+		.sort_key	= "sample",
+
+		.exit_reasons = svm_exit_reasons,
+		.exit_reasons_size = ARRAY_SIZE(svm_exit_reasons),
+		.exit_reasons_isa = "SVM",
+	};
+
 	if (argc == 1) {
 		print_kvm_stat_usage();
 		goto perf_stat;
 	}
 
 	if (!strncmp(argv[1], "rec", 3))
-		return kvm_events_record(kvm, argc - 1, argv + 1);
+		return kvm_events_record(&kvm, argc - 1, argv + 1);
 
 	if (!strncmp(argv[1], "rep", 3))
-		return kvm_events_report(kvm, argc - 1 , argv + 1);
+		return kvm_events_report(&kvm, argc - 1 , argv + 1);
 
 perf_stat:
 	return cmd_stat(argc, argv, NULL);
 }
 
-static int __cmd_record(struct perf_kvm *kvm, int argc, const char **argv)
+static int __cmd_record(const char *file_name, int argc, const char **argv)
 {
 	int rec_argc, i = 0, j;
 	const char **rec_argv;
@@ -907,7 +923,7 @@ static int __cmd_record(struct perf_kvm *kvm, int argc, const char **argv)
 	rec_argv = calloc(rec_argc + 1, sizeof(char *));
 	rec_argv[i++] = strdup("record");
 	rec_argv[i++] = strdup("-o");
-	rec_argv[i++] = strdup(kvm->file_name);
+	rec_argv[i++] = strdup(file_name);
 	for (j = 1; j < argc; j++, i++)
 		rec_argv[i] = argv[j];
 
@@ -916,7 +932,7 @@ static int __cmd_record(struct perf_kvm *kvm, int argc, const char **argv)
 	return cmd_record(i, rec_argv, NULL);
 }
 
-static int __cmd_report(struct perf_kvm *kvm, int argc, const char **argv)
+static int __cmd_report(const char *file_name, int argc, const char **argv)
 {
 	int rec_argc, i = 0, j;
 	const char **rec_argv;
@@ -925,7 +941,7 @@ static int __cmd_report(struct perf_kvm *kvm, int argc, const char **argv)
 	rec_argv = calloc(rec_argc + 1, sizeof(char *));
 	rec_argv[i++] = strdup("report");
 	rec_argv[i++] = strdup("-i");
-	rec_argv[i++] = strdup(kvm->file_name);
+	rec_argv[i++] = strdup(file_name);
 	for (j = 1; j < argc; j++, i++)
 		rec_argv[i] = argv[j];
 
@@ -934,7 +950,8 @@ static int __cmd_report(struct perf_kvm *kvm, int argc, const char **argv)
 	return cmd_report(i, rec_argv, NULL);
 }
 
-static int __cmd_buildid_list(struct perf_kvm *kvm, int argc, const char **argv)
+static int
+__cmd_buildid_list(const char *file_name, int argc, const char **argv)
 {
 	int rec_argc, i = 0, j;
 	const char **rec_argv;
@@ -943,7 +960,7 @@ static int __cmd_buildid_list(struct perf_kvm *kvm, int argc, const char **argv)
 	rec_argv = calloc(rec_argc + 1, sizeof(char *));
 	rec_argv[i++] = strdup("buildid-list");
 	rec_argv[i++] = strdup("-i");
-	rec_argv[i++] = strdup(kvm->file_name);
+	rec_argv[i++] = strdup(file_name);
 	for (j = 1; j < argc; j++, i++)
 		rec_argv[i] = argv[j];
 
@@ -954,20 +971,12 @@ static int __cmd_buildid_list(struct perf_kvm *kvm, int argc, const char **argv)
 
 int cmd_kvm(int argc, const char **argv, const char *prefix __maybe_unused)
 {
-	struct perf_kvm kvm = {
-		.trace_vcpu	= -1,
-		.report_event	= "vmexit",
-		.sort_key	= "sample",
-
-		.exit_reasons = svm_exit_reasons,
-		.exit_reasons_size = ARRAY_SIZE(svm_exit_reasons),
-		.exit_reasons_isa = "SVM",
-	};
+	const char *file_name;
 
 	const struct option kvm_options[] = {
-		OPT_STRING('i', "input", &kvm.file_name, "file",
+		OPT_STRING('i', "input", &file_name, "file",
 			   "Input file name"),
-		OPT_STRING('o', "output", &kvm.file_name, "file",
+		OPT_STRING('o', "output", &file_name, "file",
 			   "Output file name"),
 		OPT_BOOLEAN(0, "guest", &perf_guest,
 			    "Collect guest os data"),
@@ -1002,32 +1011,32 @@ int cmd_kvm(int argc, const char **argv, const char *prefix __maybe_unused)
 	if (!perf_host)
 		perf_guest = 1;
 
-	if (!kvm.file_name) {
+	if (!file_name) {
 		if (perf_host && !perf_guest)
-			kvm.file_name = strdup("perf.data.host");
+			file_name = strdup("perf.data.host");
 		else if (!perf_host && perf_guest)
-			kvm.file_name = strdup("perf.data.guest");
+			file_name = strdup("perf.data.guest");
 		else
-			kvm.file_name = strdup("perf.data.kvm");
+			file_name = strdup("perf.data.kvm");
 
-		if (!kvm.file_name) {
+		if (!file_name) {
 			pr_err("Failed to allocate memory for filename\n");
 			return -ENOMEM;
 		}
 	}
 
 	if (!strncmp(argv[0], "rec", 3))
-		return __cmd_record(&kvm, argc, argv);
+		return __cmd_record(file_name, argc, argv);
 	else if (!strncmp(argv[0], "rep", 3))
-		return __cmd_report(&kvm, argc, argv);
+		return __cmd_report(file_name, argc, argv);
 	else if (!strncmp(argv[0], "diff", 4))
 		return cmd_diff(argc, argv, NULL);
 	else if (!strncmp(argv[0], "top", 3))
 		return cmd_top(argc, argv, NULL);
 	else if (!strncmp(argv[0], "buildid-list", 12))
-		return __cmd_buildid_list(&kvm, argc, argv);
+		return __cmd_buildid_list(file_name, argc, argv);
 	else if (!strncmp(argv[0], "stat", 4))
-		return kvm_cmd_stat(&kvm, argc, argv);
+		return kvm_cmd_stat(file_name, argc, argv);
 	else
 		usage_with_options(kvm_usage, kvm_options);
 
Signature · 1 line
1.7.7.6
#10 lore raw

PATCH 2/2 perf kvm: fix building perf kvm on PowerPC

Now, 'perf kvm stat' is only supported on x86, let its code depend on ARCH_X86 to fix building it on other architectures

---
 tools/perf/arch/x86/Makefile |    2 ++
 tools/perf/builtin-kvm.c     |    4 ++++
 2 files changed, 6 insertions(+), 0 deletions(-)
tools/perf/arch/x86/Makefile +2 -0
index 815841c..320fb95 100644
@@ -1,3 +1,5 @@
+ARCH_CFLAGS += -DARCH_X86
+
 ifndef NO_DWARF
 PERF_HAVE_DWARF_REGS := 1
 LIB_OBJS += $(OUTPUT)arch/$(ARCH)/util/dwarf-regs.o
tools/perf/builtin-kvm.c +4 -0
index 7fb426b..75e998a 100644
@@ -22,6 +22,7 @@
 #include <pthread.h>
 #include <math.h>
 
+#ifdef ARCH_X86
 #include "../../arch/x86/include/asm/svm.h"
 #include "../../arch/x86/include/asm/vmx.h"
 #include "../../arch/x86/include/asm/kvm.h"
@@ -913,6 +914,7 @@ static int kvm_cmd_stat(const char *file_name, int argc, const char **argv)
 perf_stat:
 	return cmd_stat(argc, argv, NULL);
 }
+#endif
 
 static int __cmd_record(const char *file_name, int argc, const char **argv)
 {
@@ -1035,8 +1037,10 @@ int cmd_kvm(int argc, const char **argv, const char *prefix __maybe_unused)
 		return cmd_top(argc, argv, NULL);
 	else if (!strncmp(argv[0], "buildid-list", 12))
 		return __cmd_buildid_list(file_name, argc, argv);
+#ifdef ARCH_X86
 	else if (!strncmp(argv[0], "stat", 4))
 		return kvm_cmd_stat(file_name, argc, argv);
+#endif
 	else
 		usage_with_options(kvm_usage, kvm_options);
 
Signature · 1 line
1.7.7.6
#11 lore raw

Re: [PATCH 2/2] perf kvm: fix building perf kvm on PowerPC

Quoted 2 lines · Xiao Guangrong

Now, 'perf kvm stat' is only supported on x86, let its code depend on ARCH_X86 to fix building it on other architectures

Other parts of perf do this sort of thing:

	#if defined(__x86_64__) || defined(__i386__)

David

#12 lore raw

Re: [PATCH 2/2] perf kvm: fix building perf kvm on PowerPC

Quoted 9 lines · David Howells
Quoted 2 lines · Xiao Guangrong

Now, 'perf kvm stat' is only supported on x86, let its code depend on ARCH_X86 to fix building it on other architectures

Other parts of perf do this sort of thing:

	#if defined(__x86_64__) || defined(__i386__)

Yes, thanks for you point it out, David! How about this one?

Subject: [PATCH 2/2] perf kvm: fix building perf kvm on PowerPC

Now, 'perf kvm stat' is only supported on x86, let its code depend on ARCH_X86 to fix building it on other architectures

---
 tools/perf/builtin-kvm.c |    4 ++++
 1 files changed, 4 insertions(+), 0 deletions(-)
tools/perf/builtin-kvm.c +4 -0
index 7fb426b..df30ca0 100644
@@ -22,6 +22,7 @@
 #include <pthread.h>
 #include <math.h>
 
+#if defined(__i386__) || defined(__x86_64__)
 #include "../../arch/x86/include/asm/svm.h"
 #include "../../arch/x86/include/asm/vmx.h"
 #include "../../arch/x86/include/asm/kvm.h"
@@ -913,6 +914,7 @@ static int kvm_cmd_stat(const char *file_name, int argc, const char **argv)
 perf_stat:
 	return cmd_stat(argc, argv, NULL);
 }
+#endif
 
 static int __cmd_record(const char *file_name, int argc, const char **argv)
 {
@@ -1035,8 +1037,10 @@ int cmd_kvm(int argc, const char **argv, const char *prefix __maybe_unused)
 		return cmd_top(argc, argv, NULL);
 	else if (!strncmp(argv[0], "buildid-list", 12))
 		return __cmd_buildid_list(file_name, argc, argv);
+#if defined(__i386__) || defined(__x86_64__)
 	else if (!strncmp(argv[0], "stat", 4))
 		return kvm_cmd_stat(file_name, argc, argv);
+#endif
 	else
 		usage_with_options(kvm_usage, kvm_options);
 
Signature · 1 line
1.7.7.6
author Reviewed-by
#13 lore raw

Re: [PATCH 2/2] perf kvm: fix building perf kvm on PowerPC

Quoted 8 lines · Xiao Guangrong

Yes, thanks for you point it out, David! How about this one?

Subject: [PATCH 2/2] perf kvm: fix building perf kvm on PowerPC

Now, 'perf kvm stat' is only supported on x86, let its code depend on ARCH_X86 to fix building it on other architectures

#14 lore raw

[tip:perf/urgent] perf kvm: Fix building perf kvm on non x86 arches

In reply to Xiao Guangrong
Commit-ID:  7321090f6751c9987c26a8c81c63680d16a614d7
Gitweb:     http://git.kernel.org/tip/7321090f6751c9987c26a8c81c63680d16a614d7
Author:     Xiao Guangrong <[email protected]>
AuthorDate: Mon, 19 Nov 2012 16:19:21 +0800
Committer:  Arnaldo Carvalho de Melo <[email protected]>
CommitDate: Fri, 23 Nov 2012 20:40:17 -0300

perf kvm: Fix building perf kvm on non x86 arches

Now, 'perf kvm stat' is only supported on x86, let its code depend on (__x86_64__ || __i386__) to fix building it on other architectures.

---
 tools/perf/builtin-kvm.c | 4 ++++
 1 file changed, 4 insertions(+)
tools/perf/builtin-kvm.c +4 -0
index 9fa45fa..283b439 100644
@@ -22,6 +22,7 @@
 #include <pthread.h>
 #include <math.h>
 
+#if defined(__i386__) || defined(__x86_64__)
 #include <asm/svm.h>
 #include <asm/vmx.h>
 #include <asm/kvm.h>
@@ -896,6 +897,7 @@ static int kvm_cmd_stat(const char *file_name, int argc, const char **argv)
 perf_stat:
 	return cmd_stat(argc, argv, NULL);
 }
+#endif
 
 static int __cmd_record(const char *file_name, int argc, const char **argv)
 {
@@ -1018,8 +1020,10 @@ int cmd_kvm(int argc, const char **argv, const char *prefix __maybe_unused)
 		return cmd_top(argc, argv, NULL);
 	else if (!strncmp(argv[0], "buildid-list", 12))
 		return __cmd_buildid_list(file_name, argc, argv);
+#if defined(__i386__) || defined(__x86_64__)
 	else if (!strncmp(argv[0], "stat", 4))
 		return kvm_cmd_stat(file_name, argc, argv);
+#endif
 	else
 		usage_with_options(kvm_usage, kvm_options);
 
#15 lore raw

[tip:perf/urgent] perf kvm: Rename perf_kvm to perf_kvm_stat

In reply to Xiao Guangrong
Commit-ID:  3786063a3c0ba26a2400a04476c0c0ccfd3c6beb
Gitweb:     http://git.kernel.org/tip/3786063a3c0ba26a2400a04476c0c0ccfd3c6beb
Author:     Xiao Guangrong <[email protected]>
AuthorDate: Thu, 15 Nov 2012 14:17:01 +0800
Committer:  Arnaldo Carvalho de Melo <[email protected]>
CommitDate: Fri, 23 Nov 2012 19:44:05 -0300

perf kvm: Rename perf_kvm to perf_kvm_stat

Then let it only be used in 'perf kvm stat'.

Preparatory patch to stop trying to build parts of this tool that for now are only supported on x86.

---
 tools/perf/builtin-kvm.c | 111 +++++++++++++++++++++++++----------------------
 1 file changed, 60 insertions(+), 51 deletions(-)
tools/perf/builtin-kvm.c +60 -51
index e013bdb..9fa45fa 100644
@@ -58,7 +58,7 @@ struct kvm_event_key {
 };
 
 
-struct perf_kvm;
+struct perf_kvm_stat;
 
 struct kvm_events_ops {
 	bool (*is_begin_event)(struct perf_evsel *evsel,
@@ -66,7 +66,7 @@ struct kvm_events_ops {
 			       struct event_key *key);
 	bool (*is_end_event)(struct perf_evsel *evsel,
 			     struct perf_sample *sample, struct event_key *key);
-	void (*decode_key)(struct perf_kvm *kvm, struct event_key *key,
+	void (*decode_key)(struct perf_kvm_stat *kvm, struct event_key *key,
 			   char decode[20]);
 	const char *name;
 };
@@ -79,7 +79,7 @@ struct exit_reasons_table {
 #define EVENTS_BITS		12
 #define EVENTS_CACHE_SIZE	(1UL << EVENTS_BITS)
 
-struct perf_kvm {
+struct perf_kvm_stat {
 	struct perf_tool    tool;
 	struct perf_session *session;
 
@@ -146,7 +146,7 @@ static struct exit_reasons_table svm_exit_reasons[] = {
 	SVM_EXIT_REASONS
 };
 
-static const char *get_exit_reason(struct perf_kvm *kvm, u64 exit_code)
+static const char *get_exit_reason(struct perf_kvm_stat *kvm, u64 exit_code)
 {
 	int i = kvm->exit_reasons_size;
 	struct exit_reasons_table *tbl = kvm->exit_reasons;
@@ -162,7 +162,7 @@ static const char *get_exit_reason(struct perf_kvm *kvm, u64 exit_code)
 	return "UNKNOWN";
 }
 
-static void exit_event_decode_key(struct perf_kvm *kvm,
+static void exit_event_decode_key(struct perf_kvm_stat *kvm,
 				  struct event_key *key,
 				  char decode[20])
 {
@@ -228,7 +228,7 @@ static bool mmio_event_end(struct perf_evsel *evsel, struct perf_sample *sample,
 	return false;
 }
 
-static void mmio_event_decode_key(struct perf_kvm *kvm __maybe_unused,
+static void mmio_event_decode_key(struct perf_kvm_stat *kvm __maybe_unused,
 				  struct event_key *key,
 				  char decode[20])
 {
@@ -271,7 +271,7 @@ static bool ioport_event_end(struct perf_evsel *evsel,
 	return kvm_entry_event(evsel);
 }
 
-static void ioport_event_decode_key(struct perf_kvm *kvm __maybe_unused,
+static void ioport_event_decode_key(struct perf_kvm_stat *kvm __maybe_unused,
 				    struct event_key *key,
 				    char decode[20])
 {
@@ -286,7 +286,7 @@ static struct kvm_events_ops ioport_events = {
 	.name = "IO Port Access"
 };
 
-static bool register_kvm_events_ops(struct perf_kvm *kvm)
+static bool register_kvm_events_ops(struct perf_kvm_stat *kvm)
 {
 	bool ret = true;
 
@@ -311,7 +311,7 @@ struct vcpu_event_record {
 };
 
 
-static void init_kvm_event_record(struct perf_kvm *kvm)
+static void init_kvm_event_record(struct perf_kvm_stat *kvm)
 {
 	int i;
 
@@ -360,7 +360,7 @@ static struct kvm_event *kvm_alloc_init_event(struct event_key *key)
 	return event;
 }
 
-static struct kvm_event *find_create_kvm_event(struct perf_kvm *kvm,
+static struct kvm_event *find_create_kvm_event(struct perf_kvm_stat *kvm,
 					       struct event_key *key)
 {
 	struct kvm_event *event;
@@ -381,7 +381,7 @@ static struct kvm_event *find_create_kvm_event(struct perf_kvm *kvm,
 	return event;
 }
 
-static bool handle_begin_event(struct perf_kvm *kvm,
+static bool handle_begin_event(struct perf_kvm_stat *kvm,
 			       struct vcpu_event_record *vcpu_record,
 			       struct event_key *key, u64 timestamp)
 {
@@ -425,7 +425,7 @@ static bool update_kvm_event(struct kvm_event *event, int vcpu_id,
 	return true;
 }
 
-static bool handle_end_event(struct perf_kvm *kvm,
+static bool handle_end_event(struct perf_kvm_stat *kvm,
 			     struct vcpu_event_record *vcpu_record,
 			     struct event_key *key,
 			     u64 timestamp)
@@ -486,7 +486,7 @@ struct vcpu_event_record *per_vcpu_record(struct thread *thread,
 	return thread->priv;
 }
 
-static bool handle_kvm_event(struct perf_kvm *kvm,
+static bool handle_kvm_event(struct perf_kvm_stat *kvm,
 			     struct thread *thread,
 			     struct perf_evsel *evsel,
 			     struct perf_sample *sample)
@@ -541,7 +541,7 @@ static struct kvm_event_key keys[] = {
 	{ NULL, NULL }
 };
 
-static bool select_key(struct perf_kvm *kvm)
+static bool select_key(struct perf_kvm_stat *kvm)
 {
 	int i;
 
@@ -577,7 +577,8 @@ static void insert_to_result(struct rb_root *result, struct kvm_event *event,
 	rb_insert_color(&event->rb, result);
 }
 
-static void update_total_count(struct perf_kvm *kvm, struct kvm_event *event)
+static void
+update_total_count(struct perf_kvm_stat *kvm, struct kvm_event *event)
 {
 	int vcpu = kvm->trace_vcpu;
 
@@ -590,7 +591,7 @@ static bool event_is_valid(struct kvm_event *event, int vcpu)
 	return !!get_event_count(event, vcpu);
 }
 
-static void sort_result(struct perf_kvm *kvm)
+static void sort_result(struct perf_kvm_stat *kvm)
 {
 	unsigned int i;
 	int vcpu = kvm->trace_vcpu;
@@ -627,7 +628,7 @@ static void print_vcpu_info(int vcpu)
 		pr_info("VCPU %d:\n\n", vcpu);
 }
 
-static void print_result(struct perf_kvm *kvm)
+static void print_result(struct perf_kvm_stat *kvm)
 {
 	char decode[20];
 	struct kvm_event *event;
@@ -670,7 +671,8 @@ static int process_sample_event(struct perf_tool *tool,
 				struct machine *machine)
 {
 	struct thread *thread = machine__findnew_thread(machine, sample->tid);
-	struct perf_kvm *kvm = container_of(tool, struct perf_kvm, tool);
+	struct perf_kvm_stat *kvm = container_of(tool, struct perf_kvm_stat,
+						 tool);
 
 	if (thread == NULL) {
 		pr_debug("problem processing %d event, skipping it.\n",
@@ -701,7 +703,7 @@ static int get_cpu_isa(struct perf_session *session)
 	return isa;
 }
 
-static int read_events(struct perf_kvm *kvm)
+static int read_events(struct perf_kvm_stat *kvm)
 {
 	int ret;
 
@@ -750,7 +752,7 @@ static bool verify_vcpu(int vcpu)
 	return true;
 }
 
-static int kvm_events_report_vcpu(struct perf_kvm *kvm)
+static int kvm_events_report_vcpu(struct perf_kvm_stat *kvm)
 {
 	int ret = -EINVAL;
 	int vcpu = kvm->trace_vcpu;
@@ -798,7 +800,8 @@ static const char * const record_args[] = {
 		_p;			\
 	})
 
-static int kvm_events_record(struct perf_kvm *kvm, int argc, const char **argv)
+static int
+kvm_events_record(struct perf_kvm_stat *kvm, int argc, const char **argv)
 {
 	unsigned int rec_argc, i, j;
 	const char **rec_argv;
@@ -821,7 +824,8 @@ static int kvm_events_record(struct perf_kvm *kvm, int argc, const char **argv)
 	return cmd_record(i, rec_argv, NULL);
 }
 
-static int kvm_events_report(struct perf_kvm *kvm, int argc, const char **argv)
+static int
+kvm_events_report(struct perf_kvm_stat *kvm, int argc, const char **argv)
 {
 	const struct option kvm_events_report_options[] = {
 		OPT_STRING(0, "event", &kvm->report_event, "report event",
@@ -864,24 +868,36 @@ static void print_kvm_stat_usage(void)
 	printf("\nOtherwise, it is the alias of 'perf stat':\n");
 }
 
-static int kvm_cmd_stat(struct perf_kvm *kvm, int argc, const char **argv)
+static int kvm_cmd_stat(const char *file_name, int argc, const char **argv)
 {
+	struct perf_kvm_stat kvm = {
+		.file_name = file_name,
+
+		.trace_vcpu	= -1,
+		.report_event	= "vmexit",
+		.sort_key	= "sample",
+
+		.exit_reasons = svm_exit_reasons,
+		.exit_reasons_size = ARRAY_SIZE(svm_exit_reasons),
+		.exit_reasons_isa = "SVM",
+	};
+
 	if (argc == 1) {
 		print_kvm_stat_usage();
 		goto perf_stat;
 	}
 
 	if (!strncmp(argv[1], "rec", 3))
-		return kvm_events_record(kvm, argc - 1, argv + 1);
+		return kvm_events_record(&kvm, argc - 1, argv + 1);
 
 	if (!strncmp(argv[1], "rep", 3))
-		return kvm_events_report(kvm, argc - 1 , argv + 1);
+		return kvm_events_report(&kvm, argc - 1 , argv + 1);
 
 perf_stat:
 	return cmd_stat(argc, argv, NULL);
 }
 
-static int __cmd_record(struct perf_kvm *kvm, int argc, const char **argv)
+static int __cmd_record(const char *file_name, int argc, const char **argv)
 {
 	int rec_argc, i = 0, j;
 	const char **rec_argv;
@@ -890,7 +906,7 @@ static int __cmd_record(struct perf_kvm *kvm, int argc, const char **argv)
 	rec_argv = calloc(rec_argc + 1, sizeof(char *));
 	rec_argv[i++] = strdup("record");
 	rec_argv[i++] = strdup("-o");
-	rec_argv[i++] = strdup(kvm->file_name);
+	rec_argv[i++] = strdup(file_name);
 	for (j = 1; j < argc; j++, i++)
 		rec_argv[i] = argv[j];
 
@@ -899,7 +915,7 @@ static int __cmd_record(struct perf_kvm *kvm, int argc, const char **argv)
 	return cmd_record(i, rec_argv, NULL);
 }
 
-static int __cmd_report(struct perf_kvm *kvm, int argc, const char **argv)
+static int __cmd_report(const char *file_name, int argc, const char **argv)
 {
 	int rec_argc, i = 0, j;
 	const char **rec_argv;
@@ -908,7 +924,7 @@ static int __cmd_report(struct perf_kvm *kvm, int argc, const char **argv)
 	rec_argv = calloc(rec_argc + 1, sizeof(char *));
 	rec_argv[i++] = strdup("report");
 	rec_argv[i++] = strdup("-i");
-	rec_argv[i++] = strdup(kvm->file_name);
+	rec_argv[i++] = strdup(file_name);
 	for (j = 1; j < argc; j++, i++)
 		rec_argv[i] = argv[j];
 
@@ -917,7 +933,8 @@ static int __cmd_report(struct perf_kvm *kvm, int argc, const char **argv)
 	return cmd_report(i, rec_argv, NULL);
 }
 
-static int __cmd_buildid_list(struct perf_kvm *kvm, int argc, const char **argv)
+static int
+__cmd_buildid_list(const char *file_name, int argc, const char **argv)
 {
 	int rec_argc, i = 0, j;
 	const char **rec_argv;
@@ -926,7 +943,7 @@ static int __cmd_buildid_list(struct perf_kvm *kvm, int argc, const char **argv)
 	rec_argv = calloc(rec_argc + 1, sizeof(char *));
 	rec_argv[i++] = strdup("buildid-list");
 	rec_argv[i++] = strdup("-i");
-	rec_argv[i++] = strdup(kvm->file_name);
+	rec_argv[i++] = strdup(file_name);
 	for (j = 1; j < argc; j++, i++)
 		rec_argv[i] = argv[j];
 
@@ -937,20 +954,12 @@ static int __cmd_buildid_list(struct perf_kvm *kvm, int argc, const char **argv)
 
 int cmd_kvm(int argc, const char **argv, const char *prefix __maybe_unused)
 {
-	struct perf_kvm kvm = {
-		.trace_vcpu	= -1,
-		.report_event	= "vmexit",
-		.sort_key	= "sample",
-
-		.exit_reasons = svm_exit_reasons,
-		.exit_reasons_size = ARRAY_SIZE(svm_exit_reasons),
-		.exit_reasons_isa = "SVM",
-	};
+	const char *file_name;
 
 	const struct option kvm_options[] = {
-		OPT_STRING('i', "input", &kvm.file_name, "file",
+		OPT_STRING('i', "input", &file_name, "file",
 			   "Input file name"),
-		OPT_STRING('o', "output", &kvm.file_name, "file",
+		OPT_STRING('o', "output", &file_name, "file",
 			   "Output file name"),
 		OPT_BOOLEAN(0, "guest", &perf_guest,
 			    "Collect guest os data"),
@@ -985,32 +994,32 @@ int cmd_kvm(int argc, const char **argv, const char *prefix __maybe_unused)
 	if (!perf_host)
 		perf_guest = 1;
 
-	if (!kvm.file_name) {
+	if (!file_name) {
 		if (perf_host && !perf_guest)
-			kvm.file_name = strdup("perf.data.host");
+			file_name = strdup("perf.data.host");
 		else if (!perf_host && perf_guest)
-			kvm.file_name = strdup("perf.data.guest");
+			file_name = strdup("perf.data.guest");
 		else
-			kvm.file_name = strdup("perf.data.kvm");
+			file_name = strdup("perf.data.kvm");
 
-		if (!kvm.file_name) {
+		if (!file_name) {
 			pr_err("Failed to allocate memory for filename\n");
 			return -ENOMEM;
 		}
 	}
 
 	if (!strncmp(argv[0], "rec", 3))
-		return __cmd_record(&kvm, argc, argv);
+		return __cmd_record(file_name, argc, argv);
 	else if (!strncmp(argv[0], "rep", 3))
-		return __cmd_report(&kvm, argc, argv);
+		return __cmd_report(file_name, argc, argv);
 	else if (!strncmp(argv[0], "diff", 4))
 		return cmd_diff(argc, argv, NULL);
 	else if (!strncmp(argv[0], "top", 3))
 		return cmd_top(argc, argv, NULL);
 	else if (!strncmp(argv[0], "buildid-list", 12))
-		return __cmd_buildid_list(&kvm, argc, argv);
+		return __cmd_buildid_list(file_name, argc, argv);
 	else if (!strncmp(argv[0], "stat", 4))
-		return kvm_cmd_stat(&kvm, argc, argv);
+		return kvm_cmd_stat(file_name, argc, argv);
 	else
 		usage_with_options(kvm_usage, kvm_options);
 
#16 lore raw

[tip:perf/urgent] tools: Define a Makefile function to do subdir processing

In reply to David Howells
Commit-ID:  ca9dfc6cc45a8ae0297188f5fed23af242cc8a8d
Gitweb:     http://git.kernel.org/tip/ca9dfc6cc45a8ae0297188f5fed23af242cc8a8d
Author:     David Howells <[email protected]>
AuthorDate: Mon, 5 Nov 2012 15:15:24 +0000
Committer:  David Howells <[email protected]>
CommitDate: Mon, 19 Nov 2012 22:10:14 +0000

tools: Define a Makefile function to do subdir processing

Define a Makefile function that can be called with $(call ...) to wrap the subdir make invocations in tools/Makefile.

This will allow us in the next patch to insert bits in there to honour O= flags when called from the top-level Makefile.

---
 tools/Makefile                 | 24 ++++++++++++------------
 tools/scripts/Makefile.include |  8 ++++++++
 2 files changed, 20 insertions(+), 12 deletions(-)
tools/Makefile +12 -12
index 3ae4394..1f9a529 100644
@@ -31,44 +31,44 @@ help:
 	@echo '  clean: a summary clean target to clean _all_ folders'
 
 cpupower: FORCE
-	$(QUIET_SUBDIR0)power/$@/ $(QUIET_SUBDIR1)
+	$(call descend,power/$@)
 
 firewire lguest perf usb virtio vm: FORCE
-	$(QUIET_SUBDIR0)$@/ $(QUIET_SUBDIR1)
+	$(call descend,$@)
 
 selftests: FORCE
-	$(QUIET_SUBDIR0)testing/$@/ $(QUIET_SUBDIR1)
+	$(call descend,testing/$@)
 
 turbostat x86_energy_perf_policy: FORCE
-	$(QUIET_SUBDIR0)power/x86/$@/ $(QUIET_SUBDIR1)
+	$(call descend,power/x86/$@)
 
 cpupower_install:
-	$(QUIET_SUBDIR0)power/$(@:_install=)/ $(QUIET_SUBDIR1) install
+	$(call descend,power/$(@:_install=),install)
 
 firewire_install lguest_install perf_install usb_install virtio_install vm_install:
-	$(QUIET_SUBDIR0)$(@:_install=)/ $(QUIET_SUBDIR1) install
+	$(call descend,$(@:_install=),install)
 
 selftests_install:
-	$(QUIET_SUBDIR0)testing/$(@:_clean=)/ $(QUIET_SUBDIR1) install
+	$(call descend,testing/$(@:_clean=),install)
 
 turbostat_install x86_energy_perf_policy_install:
-	$(QUIET_SUBDIR0)power/x86/$(@:_install=)/ $(QUIET_SUBDIR1) install
+	$(call descend,power/x86/$(@:_install=),install)
 
 install: cpupower_install firewire_install lguest_install perf_install \
 		selftests_install turbostat_install usb_install virtio_install \
 		vm_install x86_energy_perf_policy_install
 
 cpupower_clean:
-	$(QUIET_SUBDIR0)power/cpupower/ $(QUIET_SUBDIR1) clean
+	$(call descend,power/cpupower,clean)
 
 firewire_clean lguest_clean perf_clean usb_clean virtio_clean vm_clean:
-	$(QUIET_SUBDIR0)$(@:_clean=)/ $(QUIET_SUBDIR1) clean
+	$(call descend,$(@:_clean=),clean)
 
 selftests_clean:
-	$(QUIET_SUBDIR0)testing/$(@:_clean=)/ $(QUIET_SUBDIR1) clean
+	$(call descend,testing/$(@:_clean=),clean)
 
 turbostat_clean x86_energy_perf_policy_clean:
-	$(QUIET_SUBDIR0)power/x86/$(@:_clean=)/ $(QUIET_SUBDIR1) clean
+	$(call descend,power/x86/$(@:_clean=),clean)
 
 clean: cpupower_clean firewire_clean lguest_clean perf_clean selftests_clean \
 		turbostat_clean usb_clean virtio_clean vm_clean \
tools/scripts/Makefile.include +8 -0
index 96ce80a..4a9e317 100644
@@ -41,6 +41,14 @@ else
 NO_SUBDIR = :
 endif
 
+#
+# Define a callable command for descending to a new directory
+#
+# Call by doing: $(call descend,directory[,target])
+#
+descend = \
+	$(QUIET_SUBDIR0)$(1) $(QUIET_SUBDIR1) $(2)
+
 QUIET_SUBDIR0  = +$(MAKE) -C # space to separate -C and subdir
 QUIET_SUBDIR1  =
 
#17 lore raw

[tip:perf/urgent] tools: Honour the O= flag when tool build called from a higher Makefile

In reply to David Howells
Commit-ID:  bf35182ffcd00d8b36d56210ffdac110e5624d7d
Gitweb:     http://git.kernel.org/tip/bf35182ffcd00d8b36d56210ffdac110e5624d7d
Author:     David Howells <[email protected]>
AuthorDate: Mon, 5 Nov 2012 21:02:08 +0000
Committer:  David Howells <[email protected]>
CommitDate: Mon, 19 Nov 2012 22:10:30 +0000

tools: Honour the O= flag when tool build called from a higher Makefile

Honour the O= flag that was passed to a higher level Makefile and then passed down as part of a tool build.

To make this work, the top-level Makefile passes the original O= flag and subdir=tools to the tools/Makefile, and that in turn passes subdir=$(O)/$(subdir)/foodir when building tool foo in directory $(O)/$(subdir)/foodir (where the intervening slashes aren't added if an element is missing).

For example, take perf. This is found in tools/perf/. Assume we're building into directory ~/zebra/, so we pass O=~/zebra to make. Dependening on where we run the build from, we see:

	make run in dir		$(OUTPUT) dir
	=======================	==================
	linux			~/zebra/tools/perf/
	linux/tools		~/zebra/perf/
	linux/tools/perf	~/zebra/

and if O= is not set, we get:

	make run in dir		$(OUTPUT) dir
	=======================	==================
	linux			linux/tools/perf/
	linux/tools		linux/tools/perf/
	linux/tools/perf	linux/tools/perf/

The output directories are created by the descend function if they don't already exist.

---
 Makefile                       |  6 ++++--
 tools/scripts/Makefile.include | 17 +++++++++++++----
 2 files changed, 17 insertions(+), 6 deletions(-)
Makefile +4 -2
index 42d0e56..71dc31e 100644
@@ -1321,10 +1321,12 @@ kernelversion:
 
 # Clear a bunch of variables before executing the submake
 tools/: FORCE
-	$(Q)$(MAKE) LDFLAGS= MAKEFLAGS= -C $(src)/tools/
+	$(Q)mkdir -p $(objtree)/tools
+	$(Q)$(MAKE) LDFLAGS= MAKEFLAGS= O=$(objtree) subdir=tools -C $(src)/tools/
 
 tools/%: FORCE
-	$(Q)$(MAKE) LDFLAGS= MAKEFLAGS= -C $(src)/tools/ $*
+	$(Q)mkdir -p $(objtree)/tools
+	$(Q)$(MAKE) LDFLAGS= MAKEFLAGS= O=$(objtree) subdir=tools -C $(src)/tools/ $*
 
 # Single targets
 # ---------------------------------------------------------------------------
tools/scripts/Makefile.include +13 -4
index 4a9e317..87467b1 100644
@@ -1,8 +1,11 @@
-ifeq ("$(origin O)", "command line")
+ifeq ($(origin O), command line)
 	dummy := $(if $(shell test -d $(O) || echo $(O)),$(error O=$(O) does not exist),)
 	ABSOLUTE_O := $(shell cd $(O) ; pwd)
-	OUTPUT := $(ABSOLUTE_O)/
+	OUTPUT := $(ABSOLUTE_O)/$(if $(subdir),$(subdir)/)
 	COMMAND_O := O=$(ABSOLUTE_O)
+ifeq ($(objtree),)
+	objtree := $(O)
+endif
 endif
 
 ifneq ($(OUTPUT),)
@@ -47,9 +50,10 @@ endif
 # Call by doing: $(call descend,directory[,target])
 #
 descend = \
-	$(QUIET_SUBDIR0)$(1) $(QUIET_SUBDIR1) $(2)
+	+mkdir -p $(OUTPUT)$(1) && \
+	$(MAKE) $(COMMAND_O) subdir=$(if $(subdir),$(subdir)/$(1),$(1)) $(PRINT_DIR) -C $(1)
 
-QUIET_SUBDIR0  = +$(MAKE) -C # space to separate -C and subdir
+QUIET_SUBDIR0  = +$(MAKE) $(COMMAND_O) -C # space to separate -C and subdir
 QUIET_SUBDIR1  =
 
 ifneq ($(findstring $(MAKEFLAGS),s),s)
@@ -64,5 +68,10 @@ ifndef V
 			 $(MAKE) $(PRINT_DIR) -C $$subdir
 	QUIET_FLEX     = @echo '   ' FLEX $@;
 	QUIET_BISON    = @echo '   ' BISON $@;
+
+	descend = \
+		@echo '   ' DESCEND $(1); \
+		mkdir -p $(OUTPUT)$(1) && \
+		$(MAKE) $(COMMAND_O) subdir=$(if $(subdir),$(subdir)/$(1),$(1)) $(PRINT_DIR) -C $(1)
 endif
 endif
#18 lore raw

[tip:perf/core] tools: Define a Makefile function to do subdir processing

In reply to David Howells
Commit-ID:  0bca6cff89c6e7d1e383993cccf0f59146874a34
Gitweb:     http://git.kernel.org/tip/0bca6cff89c6e7d1e383993cccf0f59146874a34
Author:     David Howells <[email protected]>
AuthorDate: Mon, 5 Nov 2012 15:15:24 +0000
Committer:  Arnaldo Carvalho de Melo <[email protected]>
CommitDate: Wed, 14 Nov 2012 16:53:11 -0300

tools: Define a Makefile function to do subdir processing

Define a Makefile function that can be called with $(call ...) to wrap the subdir make invocations in tools/Makefile.

This will allow us in the next patch to insert bits in there to honour O= flags when called from the top-level Makefile.

---
 tools/Makefile                 | 24 ++++++++++++------------
 tools/scripts/Makefile.include |  8 ++++++++
 2 files changed, 20 insertions(+), 12 deletions(-)
tools/Makefile +12 -12
index 3ae4394..1f9a529 100644
@@ -31,44 +31,44 @@ help:
 	@echo '  clean: a summary clean target to clean _all_ folders'
 
 cpupower: FORCE
-	$(QUIET_SUBDIR0)power/$@/ $(QUIET_SUBDIR1)
+	$(call descend,power/$@)
 
 firewire lguest perf usb virtio vm: FORCE
-	$(QUIET_SUBDIR0)$@/ $(QUIET_SUBDIR1)
+	$(call descend,$@)
 
 selftests: FORCE
-	$(QUIET_SUBDIR0)testing/$@/ $(QUIET_SUBDIR1)
+	$(call descend,testing/$@)
 
 turbostat x86_energy_perf_policy: FORCE
-	$(QUIET_SUBDIR0)power/x86/$@/ $(QUIET_SUBDIR1)
+	$(call descend,power/x86/$@)
 
 cpupower_install:
-	$(QUIET_SUBDIR0)power/$(@:_install=)/ $(QUIET_SUBDIR1) install
+	$(call descend,power/$(@:_install=),install)
 
 firewire_install lguest_install perf_install usb_install virtio_install vm_install:
-	$(QUIET_SUBDIR0)$(@:_install=)/ $(QUIET_SUBDIR1) install
+	$(call descend,$(@:_install=),install)
 
 selftests_install:
-	$(QUIET_SUBDIR0)testing/$(@:_clean=)/ $(QUIET_SUBDIR1) install
+	$(call descend,testing/$(@:_clean=),install)
 
 turbostat_install x86_energy_perf_policy_install:
-	$(QUIET_SUBDIR0)power/x86/$(@:_install=)/ $(QUIET_SUBDIR1) install
+	$(call descend,power/x86/$(@:_install=),install)
 
 install: cpupower_install firewire_install lguest_install perf_install \
 		selftests_install turbostat_install usb_install virtio_install \
 		vm_install x86_energy_perf_policy_install
 
 cpupower_clean:
-	$(QUIET_SUBDIR0)power/cpupower/ $(QUIET_SUBDIR1) clean
+	$(call descend,power/cpupower,clean)
 
 firewire_clean lguest_clean perf_clean usb_clean virtio_clean vm_clean:
-	$(QUIET_SUBDIR0)$(@:_clean=)/ $(QUIET_SUBDIR1) clean
+	$(call descend,$(@:_clean=),clean)
 
 selftests_clean:
-	$(QUIET_SUBDIR0)testing/$(@:_clean=)/ $(QUIET_SUBDIR1) clean
+	$(call descend,testing/$(@:_clean=),clean)
 
 turbostat_clean x86_energy_perf_policy_clean:
-	$(QUIET_SUBDIR0)power/x86/$(@:_clean=)/ $(QUIET_SUBDIR1) clean
+	$(call descend,power/x86/$(@:_clean=),clean)
 
 clean: cpupower_clean firewire_clean lguest_clean perf_clean selftests_clean \
 		turbostat_clean usb_clean virtio_clean vm_clean \
tools/scripts/Makefile.include +8 -0
index 96ce80a..4a9e317 100644
@@ -41,6 +41,14 @@ else
 NO_SUBDIR = :
 endif
 
+#
+# Define a callable command for descending to a new directory
+#
+# Call by doing: $(call descend,directory[,target])
+#
+descend = \
+	$(QUIET_SUBDIR0)$(1) $(QUIET_SUBDIR1) $(2)
+
 QUIET_SUBDIR0  = +$(MAKE) -C # space to separate -C and subdir
 QUIET_SUBDIR1  =
 
#19 lore raw

[tip:perf/core] tools: Honour the O= flag when tool build called from a higher Makefile

In reply to David Howells
Commit-ID:  9db48cd5ccd0d127e991c15509a0241a18043e91
Gitweb:     http://git.kernel.org/tip/9db48cd5ccd0d127e991c15509a0241a18043e91
Author:     David Howells <[email protected]>
AuthorDate: Mon, 5 Nov 2012 21:02:08 +0000
Committer:  Arnaldo Carvalho de Melo <[email protected]>
CommitDate: Wed, 14 Nov 2012 16:53:22 -0300

tools: Honour the O= flag when tool build called from a higher Makefile

Honour the O= flag that was passed to a higher level Makefile and then passed down as part of a tool build.

To make this work, the top-level Makefile passes the original O= flag and subdir=tools to the tools/Makefile, and that in turn passes subdir=$(O)/$(subdir)/foodir when building tool foo in directory $(O)/$(subdir)/foodir (where the intervening slashes aren't added if an element is missing).

For example, take perf. This is found in tools/perf/. Assume we're building into directory ~/zebra/, so we pass O=~/zebra to make. Dependening on where we run the build from, we see:

	make run in dir		$(OUTPUT) dir
	=======================	==================
	linux			~/zebra/tools/perf/
	linux/tools		~/zebra/perf/
	linux/tools/perf	~/zebra/

and if O= is not set, we get:

	make run in dir		$(OUTPUT) dir
	=======================	==================
	linux			linux/tools/perf/
	linux/tools		linux/tools/perf/
	linux/tools/perf	linux/tools/perf/

The output directories are created by the descend function if they don't already exist.

---
 Makefile                       |  6 ++++--
 tools/scripts/Makefile.include | 17 +++++++++++++----
 2 files changed, 17 insertions(+), 6 deletions(-)
Makefile +4 -2
index 14c93b3..08a31d8 100644
@@ -1321,10 +1321,12 @@ kernelversion:
 
 # Clear a bunch of variables before executing the submake
 tools/: FORCE
-	$(Q)$(MAKE) LDFLAGS= MAKEFLAGS= -C $(src)/tools/
+	$(Q)mkdir -p $(objtree)/tools
+	$(Q)$(MAKE) LDFLAGS= MAKEFLAGS= O=$(objtree) subdir=tools -C $(src)/tools/
 
 tools/%: FORCE
-	$(Q)$(MAKE) LDFLAGS= MAKEFLAGS= -C $(src)/tools/ $*
+	$(Q)mkdir -p $(objtree)/tools
+	$(Q)$(MAKE) LDFLAGS= MAKEFLAGS= O=$(objtree) subdir=tools -C $(src)/tools/ $*
 
 # Single targets
 # ---------------------------------------------------------------------------
tools/scripts/Makefile.include +13 -4
index 4a9e317..87467b1 100644
@@ -1,8 +1,11 @@
-ifeq ("$(origin O)", "command line")
+ifeq ($(origin O), command line)
 	dummy := $(if $(shell test -d $(O) || echo $(O)),$(error O=$(O) does not exist),)
 	ABSOLUTE_O := $(shell cd $(O) ; pwd)
-	OUTPUT := $(ABSOLUTE_O)/
+	OUTPUT := $(ABSOLUTE_O)/$(if $(subdir),$(subdir)/)
 	COMMAND_O := O=$(ABSOLUTE_O)
+ifeq ($(objtree),)
+	objtree := $(O)
+endif
 endif
 
 ifneq ($(OUTPUT),)
@@ -47,9 +50,10 @@ endif
 # Call by doing: $(call descend,directory[,target])
 #
 descend = \
-	$(QUIET_SUBDIR0)$(1) $(QUIET_SUBDIR1) $(2)
+	+mkdir -p $(OUTPUT)$(1) && \
+	$(MAKE) $(COMMAND_O) subdir=$(if $(subdir),$(subdir)/$(1),$(1)) $(PRINT_DIR) -C $(1)
 
-QUIET_SUBDIR0  = +$(MAKE) -C # space to separate -C and subdir
+QUIET_SUBDIR0  = +$(MAKE) $(COMMAND_O) -C # space to separate -C and subdir
 QUIET_SUBDIR1  =
 
 ifneq ($(findstring $(MAKEFLAGS),s),s)
@@ -64,5 +68,10 @@ ifndef V
 			 $(MAKE) $(PRINT_DIR) -C $$subdir
 	QUIET_FLEX     = @echo '   ' FLEX $@;
 	QUIET_BISON    = @echo '   ' BISON $@;
+
+	descend = \
+		@echo '   ' DESCEND $(1); \
+		mkdir -p $(OUTPUT)$(1) && \
+		$(MAKE) $(COMMAND_O) subdir=$(if $(subdir),$(subdir)/$(1),$(1)) $(PRINT_DIR) -C $(1)
 endif
 endif