* [GIT PULL 00/30] perf/core improvements and fixes
@ 2012-09-24 15:59 Arnaldo Carvalho de Melo
2012-09-24 15:59 ` [PATCH 01/30] perf tools: Fix a compiling error in trace-event-perl.c for 32 bits machine Arnaldo Carvalho de Melo
` (29 more replies)
0 siblings, 30 replies; 41+ messages in thread
From: Arnaldo Carvalho de Melo @ 2012-09-24 15:59 UTC (permalink / raw)
To: Ingo Molnar
Cc: linux-kernel, Arnaldo Carvalho de Melo, Arjan van de Ven,
Avi Kivity, David Ahern, Dong Hao, Eric Sandeen, Feng Tang,
Frederic Weisbecker, Irina Tirdea, Jiri Olsa, kvm,
Marcelo Tosatti, Markus Trippelsdorf, Masami Hiramatsu,
Mike Frysinger, Mike Galbraith, Namhyung Kim, Paul Mackerras,
Peter Zijlstra, Robert Richter, Runzhen Wang, Stephane Eranian,
Steven Rostedt, Xiao Guangrong, Arnaldo Carvalho de Melo
Hi Ingo,
Please consider pulling,
- Arnaldo
The following changes since commit 1e6dd8adc78d4a153db253d051fd4ef6c49c9019:
perf: Fix off by one test in perf_reg_value() (2012-09-19 17:08:40 +0200)
are available in the git repository at:
git://git.kernel.org/pub/scm/linux/kernel/git/acme/linux tags/perf-core-for-mingo
for you to fetch changes up to b1ac754b67b5a875d63bee880f60ccb0c6bd8899:
tools lib traceevent: Handle alloc_arg failure (2012-09-24 12:31:52 -0300)
----------------------------------------------------------------
perf/core improvements and fixes:
. Convert the trace builtins to use the growing evsel/evlist
tracepoint infrastructure, removing several open coded constructs
like switch like series of strcmp to dispatch events, etc.
Basically what had already been showcased in 'perf sched'.
. Add evsel constructor for tracepoints, that uses libtraceevent
just to parse the /format events file, use it in a new 'perf test'
to make sure the libtraceevent format parsing regressions can
be more readily caught.
. Some strange errors were happening in some builds, but not on the
next, reported by several people, problem was some parser related
files, generated during the build, didn't had proper make deps,
fix from Eric Sandeen.
. Fix some compiling errors on 32-bit, from Feng Tang.
. Don't use sscanf extension %as, not available on bionic, reimplementation
by Irina Tirdea.
. Fix bfd.h/libbfd detection with recent binutils, from Markus Trippelsdorf.
. Introduce struct and cache information about the environment where a
perf.data file was captured, from Namhyung Kim.
. Fix several error paths in libtraceevent, from Namhyung Kim.
Print event causing perf_event_open() to fail in 'perf record',
from Stephane Eranian.
. New 'kvm' analysis tool, from Xiao Guangrong.
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
----------------------------------------------------------------
Arnaldo Carvalho de Melo (11):
perf kvm: Use perf_evsel__intval
perf kmem: Use perf_evsel__intval and perf_session__set_tracepoints_handlers
perf lock: Use perf_evsel__intval and perf_session__set_tracepoints_handlers
perf timechart: Use zalloc and fix a couple leaks
tools lib traceevent: Use asprintf were applicable
tools lib traceevent: Use calloc were applicable
tools lib traceevent: Fix afterlife gotos
tools lib traceevent: Remove some die() calls
tools lib traceevent: Carve out events format parsing routine
perf evsel: Provide a new constructor for tracepoints
perf test: Add test for the sched tracepoint format fields
Eric Sandeen (1):
perf tools: Fix parallel build
Feng Tang (2):
perf tools: Fix a compiling error in trace-event-perl.c for 32 bits machine
perf tools: Fix a compiling error in util/map.c
Irina Tirdea (1):
perf tools: remove sscanf extension %as
Markus Trippelsdorf (1):
perf tools: bfd.h/libbfd detection fails with recent binutils
Namhyung Kim (11):
perf header: Add struct perf_session_env
perf header: Add ->process callbacks to most of features
perf header: Use pre-processed session env when printing
perf header: Remove unused @feat arg from ->process callback
perf kvm: Use perf_session_env for reading cpuid
perf header: Remove perf_header__read_feature
tools lib traceevent: Fix error path on process_array()
tools lib traceevent: Make sure that arg->op.right is set properly
tools lib traceevent: Free field if an error occurs on process_fields
tools lib traceevent: Free field if an error occurs on process_flags/symbols
tools lib traceevent: Handle alloc_arg failure
Stephane Eranian (1):
perf record: Print event causing perf_event_open() to fail
Xiao Guangrong (2):
KVM: x86: Export svm/vmx exit code and vector code to userspace
perf kvm: Events analysis tool
arch/x86/include/asm/kvm.h | 16 +
arch/x86/include/asm/kvm_host.h | 16 -
arch/x86/include/asm/svm.h | 205 +++--
arch/x86/include/asm/vmx.h | 127 ++-
arch/x86/kvm/trace.h | 89 ---
tools/lib/traceevent/event-parse.c | 570 +++++++++----
tools/lib/traceevent/event-parse.h | 3 +
tools/perf/Documentation/perf-kvm.txt | 30 +-
tools/perf/MANIFEST | 3 +
tools/perf/Makefile | 6 +-
tools/perf/builtin-kmem.c | 90 +--
tools/perf/builtin-kvm.c | 836 +++++++++++++++++++-
tools/perf/builtin-lock.c | 233 ++----
tools/perf/builtin-record.c | 6 +-
tools/perf/builtin-test.c | 86 ++
tools/perf/builtin-timechart.c | 40 +-
tools/perf/util/evsel.c | 88 ++-
tools/perf/util/evsel.h | 5 +
tools/perf/util/header.c | 547 +++++++++----
tools/perf/util/header.h | 24 +
tools/perf/util/map.c | 5 +-
tools/perf/util/probe-event.c | 36 +-
.../perf/util/scripting-engines/trace-event-perl.c | 2 +-
tools/perf/util/symbol.h | 1 +
tools/perf/util/thread.h | 2 +
tools/perf/util/trace-event-parse.c | 18 +-
26 files changed, 2278 insertions(+), 806 deletions(-)
^ permalink raw reply [flat|nested] 41+ messages in thread
* [PATCH 01/30] perf tools: Fix a compiling error in trace-event-perl.c for 32 bits machine
2012-09-24 15:59 [GIT PULL 00/30] perf/core improvements and fixes Arnaldo Carvalho de Melo
@ 2012-09-24 15:59 ` Arnaldo Carvalho de Melo
2012-09-24 15:59 ` [PATCH 02/30] perf tools: Fix a compiling error in util/map.c Arnaldo Carvalho de Melo
` (28 subsequent siblings)
29 siblings, 0 replies; 41+ messages in thread
From: Arnaldo Carvalho de Melo @ 2012-09-24 15:59 UTC (permalink / raw)
To: Ingo Molnar
Cc: linux-kernel, Feng Tang, David Ahern, Namhyung Kim,
Peter Zijlstra, Arnaldo Carvalho de Melo
From: Feng Tang <feng.tang@intel.com>
On my x86_32 mahcine, there is a compile error:
CC util/scripting-engines/trace-event-perl.o
cc1: warnings being treated as errors
util/scripting-engines/trace-event-perl.c: In function
perl_process_tracepoint:
util/scripting-engines/trace-event-perl.c:285: error: format
expects type 'int', but argument 2 has type '__u64'
make: *** [util/scripting-engines/trace-event-perl.o] Error 1
Fix it by using the "%PRIu64" for __u64.
v2: use PRIu64 as suggested by Arnaldo.
Signed-off-by: Feng Tang <feng.tang@intel.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Link: http://lkml.kernel.org/r/20120828101730.6b2fd97e@feng-i7
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
.../perf/util/scripting-engines/trace-event-perl.c | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/tools/perf/util/scripting-engines/trace-event-perl.c b/tools/perf/util/scripting-engines/trace-event-perl.c
index ffde3e4..f80605e 100644
--- a/tools/perf/util/scripting-engines/trace-event-perl.c
+++ b/tools/perf/util/scripting-engines/trace-event-perl.c
@@ -282,7 +282,7 @@ static void perl_process_tracepoint(union perf_event *perf_event __maybe_unused,
event = find_cache_event(evsel);
if (!event)
- die("ug! no event found for type %d", evsel->attr.config);
+ die("ug! no event found for type %" PRIu64, evsel->attr.config);
pid = raw_field_value(event, "common_pid", data);
--
1.7.1
^ permalink raw reply related [flat|nested] 41+ messages in thread
* [PATCH 02/30] perf tools: Fix a compiling error in util/map.c
2012-09-24 15:59 [GIT PULL 00/30] perf/core improvements and fixes Arnaldo Carvalho de Melo
2012-09-24 15:59 ` [PATCH 01/30] perf tools: Fix a compiling error in trace-event-perl.c for 32 bits machine Arnaldo Carvalho de Melo
@ 2012-09-24 15:59 ` Arnaldo Carvalho de Melo
2012-09-24 15:59 ` [PATCH 03/30] perf record: Print event causing perf_event_open() to fail Arnaldo Carvalho de Melo
` (27 subsequent siblings)
29 siblings, 0 replies; 41+ messages in thread
From: Arnaldo Carvalho de Melo @ 2012-09-24 15:59 UTC (permalink / raw)
To: Ingo Molnar
Cc: linux-kernel, Feng Tang, David Ahern, Ingo Molnar, Namhyung Kim,
Peter Zijlstra, Arnaldo Carvalho de Melo
From: Feng Tang <feng.tang@intel.com>
This patch fix a compile warning taken as error:
CC util/map.o
cc1: warnings being treated as errors
util/map.c: In function ‘map__fprintf_dsoname’:
util/map.c:240: error: ‘dsoname’ may be used uninitialized in this function
make: *** [util/map.o] Error 1
Signed-off-by: Feng Tang <feng.tang@intel.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Link: http://lkml.kernel.org/r/1346053107-11946-3-git-send-email-feng.tang@intel.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
tools/perf/util/map.c | 5 ++---
1 files changed, 2 insertions(+), 3 deletions(-)
diff --git a/tools/perf/util/map.c b/tools/perf/util/map.c
index b442ee4..ead5316 100644
--- a/tools/perf/util/map.c
+++ b/tools/perf/util/map.c
@@ -243,15 +243,14 @@ size_t map__fprintf(struct map *self, FILE *fp)
size_t map__fprintf_dsoname(struct map *map, FILE *fp)
{
- const char *dsoname;
+ const char *dsoname = "[unknown]";
if (map && map->dso && (map->dso->name || map->dso->long_name)) {
if (symbol_conf.show_kernel_path && map->dso->long_name)
dsoname = map->dso->long_name;
else if (map->dso->name)
dsoname = map->dso->name;
- } else
- dsoname = "[unknown]";
+ }
return fprintf(fp, "%s", dsoname);
}
--
1.7.1
^ permalink raw reply related [flat|nested] 41+ messages in thread
* [PATCH 03/30] perf record: Print event causing perf_event_open() to fail
2012-09-24 15:59 [GIT PULL 00/30] perf/core improvements and fixes Arnaldo Carvalho de Melo
2012-09-24 15:59 ` [PATCH 01/30] perf tools: Fix a compiling error in trace-event-perl.c for 32 bits machine Arnaldo Carvalho de Melo
2012-09-24 15:59 ` [PATCH 02/30] perf tools: Fix a compiling error in util/map.c Arnaldo Carvalho de Melo
@ 2012-09-24 15:59 ` Arnaldo Carvalho de Melo
2012-09-24 15:59 ` [PATCH 04/30] perf tools: Fix parallel build Arnaldo Carvalho de Melo
` (26 subsequent siblings)
29 siblings, 0 replies; 41+ messages in thread
From: Arnaldo Carvalho de Melo @ 2012-09-24 15:59 UTC (permalink / raw)
To: Ingo Molnar
Cc: linux-kernel, Stephane Eranian, David Ahern, Ingo Molnar,
Peter Zijlstra, Arnaldo Carvalho de Melo
From: Stephane Eranian <eranian@google.com>
Got tired of not getting the event that caused the perf_event_open()
syscall to fail. So I fixed the error message. This is very useful when
monitoring lots of events in a single run.
Signed-off-by: Stephane Eranian <eranian@google.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: http://lkml.kernel.org/r/20120920161945.GA7064@quad
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
tools/perf/builtin-record.c | 6 ++++--
1 files changed, 4 insertions(+), 2 deletions(-)
diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c
index c643ed6..2cb7434 100644
--- a/tools/perf/builtin-record.c
+++ b/tools/perf/builtin-record.c
@@ -297,8 +297,10 @@ try_again:
}
printf("\n");
- error("sys_perf_event_open() syscall returned with %d (%s). /bin/dmesg may provide additional information.\n",
- err, strerror(err));
+ error("sys_perf_event_open() syscall returned with %d "
+ "(%s) for event %s. /bin/dmesg may provide "
+ "additional information.\n",
+ err, strerror(err), perf_evsel__name(pos));
#if defined(__i386__) || defined(__x86_64__)
if (attr->type == PERF_TYPE_HARDWARE &&
--
1.7.1
^ permalink raw reply related [flat|nested] 41+ messages in thread
* [PATCH 04/30] perf tools: Fix parallel build
2012-09-24 15:59 [GIT PULL 00/30] perf/core improvements and fixes Arnaldo Carvalho de Melo
` (2 preceding siblings ...)
2012-09-24 15:59 ` [PATCH 03/30] perf record: Print event causing perf_event_open() to fail Arnaldo Carvalho de Melo
@ 2012-09-24 15:59 ` Arnaldo Carvalho de Melo
2012-09-24 15:59 ` [PATCH 05/30] KVM: x86: Export svm/vmx exit code and vector code to userspace Arnaldo Carvalho de Melo
` (25 subsequent siblings)
29 siblings, 0 replies; 41+ messages in thread
From: Arnaldo Carvalho de Melo @ 2012-09-24 15:59 UTC (permalink / raw)
To: Ingo Molnar
Cc: linux-kernel, Eric Sandeen, Namhyung Kim, Arnaldo Carvalho de Melo
From: Eric Sandeen <sandeen@redhat.com>
Parallel builds of perf were failing for me on a 32p box, with:
* new build flags or prefix
util/pmu.l:7:23: error: pmu-bison.h: No such file or directory
...
make: *** [util/pmu-flex.o] Error 1
make: *** Waiting for unfinished jobs....
This can pretty quickly be seen by adding a sleep in front of the bison
calls in tools/perf/Makefile and running make -j4 on a smaller box i.e.:
sleep 10; $(QUIET_BISON)$(BISON) -v util/pmu.y -d -o $(OUTPUT)util/pmu-bison.c
Adding the following dependencies fixes it for me.
Signed-off-by: Eric Sandeen <sandeen@redhat.com>
Reviewed-by: Namhyung Kim <namhyung@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Link: http://lkml.kernel.org/r/505BD190.40707@redhat.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
tools/perf/Makefile | 4 ++--
1 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/tools/perf/Makefile b/tools/perf/Makefile
index 5077f8e..3ae6a59 100644
--- a/tools/perf/Makefile
+++ b/tools/perf/Makefile
@@ -233,13 +233,13 @@ export PERL_PATH
FLEX = flex
BISON= bison
-$(OUTPUT)util/parse-events-flex.c: util/parse-events.l
+$(OUTPUT)util/parse-events-flex.c: util/parse-events.l $(OUTPUT)util/parse-events-bison.c
$(QUIET_FLEX)$(FLEX) --header-file=$(OUTPUT)util/parse-events-flex.h $(PARSER_DEBUG_FLEX) -t util/parse-events.l > $(OUTPUT)util/parse-events-flex.c
$(OUTPUT)util/parse-events-bison.c: util/parse-events.y
$(QUIET_BISON)$(BISON) -v util/parse-events.y -d $(PARSER_DEBUG_BISON) -o $(OUTPUT)util/parse-events-bison.c
-$(OUTPUT)util/pmu-flex.c: util/pmu.l
+$(OUTPUT)util/pmu-flex.c: util/pmu.l $(OUTPUT)util/pmu-bison.c
$(QUIET_FLEX)$(FLEX) --header-file=$(OUTPUT)util/pmu-flex.h -t util/pmu.l > $(OUTPUT)util/pmu-flex.c
$(OUTPUT)util/pmu-bison.c: util/pmu.y
--
1.7.1
^ permalink raw reply related [flat|nested] 41+ messages in thread
* [PATCH 05/30] KVM: x86: Export svm/vmx exit code and vector code to userspace
2012-09-24 15:59 [GIT PULL 00/30] perf/core improvements and fixes Arnaldo Carvalho de Melo
` (3 preceding siblings ...)
2012-09-24 15:59 ` [PATCH 04/30] perf tools: Fix parallel build Arnaldo Carvalho de Melo
@ 2012-09-24 15:59 ` Arnaldo Carvalho de Melo
2012-09-24 15:59 ` [PATCH 06/30] perf kvm: Events analysis tool Arnaldo Carvalho de Melo
` (24 subsequent siblings)
29 siblings, 0 replies; 41+ messages in thread
From: Arnaldo Carvalho de Melo @ 2012-09-24 15:59 UTC (permalink / raw)
To: Ingo Molnar
Cc: linux-kernel, Xiao Guangrong, Dong Hao, Avi Kivity, David Ahern,
Marcelo Tosatti, kvm, Runzhen Wang, Arnaldo Carvalho de Melo
From: Xiao Guangrong <xiaoguangrong@linux.vnet.ibm.com>
Exporting KVM exit information to userspace to be consumed by perf.
Signed-off-by: Dong Hao <haodong@linux.vnet.ibm.com>
[ Dong Hao <haodong@linux.vnet.ibm.com>: rebase it on acme's git tree ]
Signed-off-by: Xiao Guangrong <xiaoguangrong@linux.vnet.ibm.com>
Acked-by: Marcelo Tosatti <mtosatti@redhat.com>
Cc: Avi Kivity <avi@redhat.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Marcelo Tosatti <mtosatti@redhat.com>
Cc: kvm@vger.kernel.org
Cc: Runzhen Wang <runzhen@linux.vnet.ibm.com>
Link: http://lkml.kernel.org/r/1347870675-31495-2-git-send-email-haodong@linux.vnet.ibm.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
arch/x86/include/asm/kvm.h | 16 +++
arch/x86/include/asm/kvm_host.h | 16 ---
arch/x86/include/asm/svm.h | 205 +++++++++++++++++++++++++--------------
arch/x86/include/asm/vmx.h | 127 ++++++++++++++++--------
arch/x86/kvm/trace.h | 89 -----------------
5 files changed, 230 insertions(+), 223 deletions(-)
diff --git a/arch/x86/include/asm/kvm.h b/arch/x86/include/asm/kvm.h
index 246617e..41e08cb 100644
--- a/arch/x86/include/asm/kvm.h
+++ b/arch/x86/include/asm/kvm.h
@@ -9,6 +9,22 @@
#include <linux/types.h>
#include <linux/ioctl.h>
+#define DE_VECTOR 0
+#define DB_VECTOR 1
+#define BP_VECTOR 3
+#define OF_VECTOR 4
+#define BR_VECTOR 5
+#define UD_VECTOR 6
+#define NM_VECTOR 7
+#define DF_VECTOR 8
+#define TS_VECTOR 10
+#define NP_VECTOR 11
+#define SS_VECTOR 12
+#define GP_VECTOR 13
+#define PF_VECTOR 14
+#define MF_VECTOR 16
+#define MC_VECTOR 18
+
/* Select x86 specific features in <linux/kvm.h> */
#define __KVM_HAVE_PIT
#define __KVM_HAVE_IOAPIC
diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h
index 09155d6..1eaa6b0 100644
--- a/arch/x86/include/asm/kvm_host.h
+++ b/arch/x86/include/asm/kvm_host.h
@@ -75,22 +75,6 @@
#define KVM_HPAGE_MASK(x) (~(KVM_HPAGE_SIZE(x) - 1))
#define KVM_PAGES_PER_HPAGE(x) (KVM_HPAGE_SIZE(x) / PAGE_SIZE)
-#define DE_VECTOR 0
-#define DB_VECTOR 1
-#define BP_VECTOR 3
-#define OF_VECTOR 4
-#define BR_VECTOR 5
-#define UD_VECTOR 6
-#define NM_VECTOR 7
-#define DF_VECTOR 8
-#define TS_VECTOR 10
-#define NP_VECTOR 11
-#define SS_VECTOR 12
-#define GP_VECTOR 13
-#define PF_VECTOR 14
-#define MF_VECTOR 16
-#define MC_VECTOR 18
-
#define SELECTOR_TI_MASK (1 << 2)
#define SELECTOR_RPL_MASK 0x03
diff --git a/arch/x86/include/asm/svm.h b/arch/x86/include/asm/svm.h
index f2b83bc..cdf5674 100644
--- a/arch/x86/include/asm/svm.h
+++ b/arch/x86/include/asm/svm.h
@@ -1,6 +1,135 @@
#ifndef __SVM_H
#define __SVM_H
+#define SVM_EXIT_READ_CR0 0x000
+#define SVM_EXIT_READ_CR3 0x003
+#define SVM_EXIT_READ_CR4 0x004
+#define SVM_EXIT_READ_CR8 0x008
+#define SVM_EXIT_WRITE_CR0 0x010
+#define SVM_EXIT_WRITE_CR3 0x013
+#define SVM_EXIT_WRITE_CR4 0x014
+#define SVM_EXIT_WRITE_CR8 0x018
+#define SVM_EXIT_READ_DR0 0x020
+#define SVM_EXIT_READ_DR1 0x021
+#define SVM_EXIT_READ_DR2 0x022
+#define SVM_EXIT_READ_DR3 0x023
+#define SVM_EXIT_READ_DR4 0x024
+#define SVM_EXIT_READ_DR5 0x025
+#define SVM_EXIT_READ_DR6 0x026
+#define SVM_EXIT_READ_DR7 0x027
+#define SVM_EXIT_WRITE_DR0 0x030
+#define SVM_EXIT_WRITE_DR1 0x031
+#define SVM_EXIT_WRITE_DR2 0x032
+#define SVM_EXIT_WRITE_DR3 0x033
+#define SVM_EXIT_WRITE_DR4 0x034
+#define SVM_EXIT_WRITE_DR5 0x035
+#define SVM_EXIT_WRITE_DR6 0x036
+#define SVM_EXIT_WRITE_DR7 0x037
+#define SVM_EXIT_EXCP_BASE 0x040
+#define SVM_EXIT_INTR 0x060
+#define SVM_EXIT_NMI 0x061
+#define SVM_EXIT_SMI 0x062
+#define SVM_EXIT_INIT 0x063
+#define SVM_EXIT_VINTR 0x064
+#define SVM_EXIT_CR0_SEL_WRITE 0x065
+#define SVM_EXIT_IDTR_READ 0x066
+#define SVM_EXIT_GDTR_READ 0x067
+#define SVM_EXIT_LDTR_READ 0x068
+#define SVM_EXIT_TR_READ 0x069
+#define SVM_EXIT_IDTR_WRITE 0x06a
+#define SVM_EXIT_GDTR_WRITE 0x06b
+#define SVM_EXIT_LDTR_WRITE 0x06c
+#define SVM_EXIT_TR_WRITE 0x06d
+#define SVM_EXIT_RDTSC 0x06e
+#define SVM_EXIT_RDPMC 0x06f
+#define SVM_EXIT_PUSHF 0x070
+#define SVM_EXIT_POPF 0x071
+#define SVM_EXIT_CPUID 0x072
+#define SVM_EXIT_RSM 0x073
+#define SVM_EXIT_IRET 0x074
+#define SVM_EXIT_SWINT 0x075
+#define SVM_EXIT_INVD 0x076
+#define SVM_EXIT_PAUSE 0x077
+#define SVM_EXIT_HLT 0x078
+#define SVM_EXIT_INVLPG 0x079
+#define SVM_EXIT_INVLPGA 0x07a
+#define SVM_EXIT_IOIO 0x07b
+#define SVM_EXIT_MSR 0x07c
+#define SVM_EXIT_TASK_SWITCH 0x07d
+#define SVM_EXIT_FERR_FREEZE 0x07e
+#define SVM_EXIT_SHUTDOWN 0x07f
+#define SVM_EXIT_VMRUN 0x080
+#define SVM_EXIT_VMMCALL 0x081
+#define SVM_EXIT_VMLOAD 0x082
+#define SVM_EXIT_VMSAVE 0x083
+#define SVM_EXIT_STGI 0x084
+#define SVM_EXIT_CLGI 0x085
+#define SVM_EXIT_SKINIT 0x086
+#define SVM_EXIT_RDTSCP 0x087
+#define SVM_EXIT_ICEBP 0x088
+#define SVM_EXIT_WBINVD 0x089
+#define SVM_EXIT_MONITOR 0x08a
+#define SVM_EXIT_MWAIT 0x08b
+#define SVM_EXIT_MWAIT_COND 0x08c
+#define SVM_EXIT_XSETBV 0x08d
+#define SVM_EXIT_NPF 0x400
+
+#define SVM_EXIT_ERR -1
+
+#define SVM_EXIT_REASONS \
+ { SVM_EXIT_READ_CR0, "read_cr0" }, \
+ { SVM_EXIT_READ_CR3, "read_cr3" }, \
+ { SVM_EXIT_READ_CR4, "read_cr4" }, \
+ { SVM_EXIT_READ_CR8, "read_cr8" }, \
+ { SVM_EXIT_WRITE_CR0, "write_cr0" }, \
+ { SVM_EXIT_WRITE_CR3, "write_cr3" }, \
+ { SVM_EXIT_WRITE_CR4, "write_cr4" }, \
+ { SVM_EXIT_WRITE_CR8, "write_cr8" }, \
+ { SVM_EXIT_READ_DR0, "read_dr0" }, \
+ { SVM_EXIT_READ_DR1, "read_dr1" }, \
+ { SVM_EXIT_READ_DR2, "read_dr2" }, \
+ { SVM_EXIT_READ_DR3, "read_dr3" }, \
+ { SVM_EXIT_WRITE_DR0, "write_dr0" }, \
+ { SVM_EXIT_WRITE_DR1, "write_dr1" }, \
+ { SVM_EXIT_WRITE_DR2, "write_dr2" }, \
+ { SVM_EXIT_WRITE_DR3, "write_dr3" }, \
+ { SVM_EXIT_WRITE_DR5, "write_dr5" }, \
+ { SVM_EXIT_WRITE_DR7, "write_dr7" }, \
+ { SVM_EXIT_EXCP_BASE + DB_VECTOR, "DB excp" }, \
+ { SVM_EXIT_EXCP_BASE + BP_VECTOR, "BP excp" }, \
+ { SVM_EXIT_EXCP_BASE + UD_VECTOR, "UD excp" }, \
+ { SVM_EXIT_EXCP_BASE + PF_VECTOR, "PF excp" }, \
+ { SVM_EXIT_EXCP_BASE + NM_VECTOR, "NM excp" }, \
+ { SVM_EXIT_EXCP_BASE + MC_VECTOR, "MC excp" }, \
+ { SVM_EXIT_INTR, "interrupt" }, \
+ { SVM_EXIT_NMI, "nmi" }, \
+ { SVM_EXIT_SMI, "smi" }, \
+ { SVM_EXIT_INIT, "init" }, \
+ { SVM_EXIT_VINTR, "vintr" }, \
+ { SVM_EXIT_CPUID, "cpuid" }, \
+ { SVM_EXIT_INVD, "invd" }, \
+ { SVM_EXIT_HLT, "hlt" }, \
+ { SVM_EXIT_INVLPG, "invlpg" }, \
+ { SVM_EXIT_INVLPGA, "invlpga" }, \
+ { SVM_EXIT_IOIO, "io" }, \
+ { SVM_EXIT_MSR, "msr" }, \
+ { SVM_EXIT_TASK_SWITCH, "task_switch" }, \
+ { SVM_EXIT_SHUTDOWN, "shutdown" }, \
+ { SVM_EXIT_VMRUN, "vmrun" }, \
+ { SVM_EXIT_VMMCALL, "hypercall" }, \
+ { SVM_EXIT_VMLOAD, "vmload" }, \
+ { SVM_EXIT_VMSAVE, "vmsave" }, \
+ { SVM_EXIT_STGI, "stgi" }, \
+ { SVM_EXIT_CLGI, "clgi" }, \
+ { SVM_EXIT_SKINIT, "skinit" }, \
+ { SVM_EXIT_WBINVD, "wbinvd" }, \
+ { SVM_EXIT_MONITOR, "monitor" }, \
+ { SVM_EXIT_MWAIT, "mwait" }, \
+ { SVM_EXIT_XSETBV, "xsetbv" }, \
+ { SVM_EXIT_NPF, "npf" }
+
+#ifdef __KERNEL__
+
enum {
INTERCEPT_INTR,
INTERCEPT_NMI,
@@ -264,81 +393,6 @@ struct __attribute__ ((__packed__)) vmcb {
#define SVM_EXITINFO_REG_MASK 0x0F
-#define SVM_EXIT_READ_CR0 0x000
-#define SVM_EXIT_READ_CR3 0x003
-#define SVM_EXIT_READ_CR4 0x004
-#define SVM_EXIT_READ_CR8 0x008
-#define SVM_EXIT_WRITE_CR0 0x010
-#define SVM_EXIT_WRITE_CR3 0x013
-#define SVM_EXIT_WRITE_CR4 0x014
-#define SVM_EXIT_WRITE_CR8 0x018
-#define SVM_EXIT_READ_DR0 0x020
-#define SVM_EXIT_READ_DR1 0x021
-#define SVM_EXIT_READ_DR2 0x022
-#define SVM_EXIT_READ_DR3 0x023
-#define SVM_EXIT_READ_DR4 0x024
-#define SVM_EXIT_READ_DR5 0x025
-#define SVM_EXIT_READ_DR6 0x026
-#define SVM_EXIT_READ_DR7 0x027
-#define SVM_EXIT_WRITE_DR0 0x030
-#define SVM_EXIT_WRITE_DR1 0x031
-#define SVM_EXIT_WRITE_DR2 0x032
-#define SVM_EXIT_WRITE_DR3 0x033
-#define SVM_EXIT_WRITE_DR4 0x034
-#define SVM_EXIT_WRITE_DR5 0x035
-#define SVM_EXIT_WRITE_DR6 0x036
-#define SVM_EXIT_WRITE_DR7 0x037
-#define SVM_EXIT_EXCP_BASE 0x040
-#define SVM_EXIT_INTR 0x060
-#define SVM_EXIT_NMI 0x061
-#define SVM_EXIT_SMI 0x062
-#define SVM_EXIT_INIT 0x063
-#define SVM_EXIT_VINTR 0x064
-#define SVM_EXIT_CR0_SEL_WRITE 0x065
-#define SVM_EXIT_IDTR_READ 0x066
-#define SVM_EXIT_GDTR_READ 0x067
-#define SVM_EXIT_LDTR_READ 0x068
-#define SVM_EXIT_TR_READ 0x069
-#define SVM_EXIT_IDTR_WRITE 0x06a
-#define SVM_EXIT_GDTR_WRITE 0x06b
-#define SVM_EXIT_LDTR_WRITE 0x06c
-#define SVM_EXIT_TR_WRITE 0x06d
-#define SVM_EXIT_RDTSC 0x06e
-#define SVM_EXIT_RDPMC 0x06f
-#define SVM_EXIT_PUSHF 0x070
-#define SVM_EXIT_POPF 0x071
-#define SVM_EXIT_CPUID 0x072
-#define SVM_EXIT_RSM 0x073
-#define SVM_EXIT_IRET 0x074
-#define SVM_EXIT_SWINT 0x075
-#define SVM_EXIT_INVD 0x076
-#define SVM_EXIT_PAUSE 0x077
-#define SVM_EXIT_HLT 0x078
-#define SVM_EXIT_INVLPG 0x079
-#define SVM_EXIT_INVLPGA 0x07a
-#define SVM_EXIT_IOIO 0x07b
-#define SVM_EXIT_MSR 0x07c
-#define SVM_EXIT_TASK_SWITCH 0x07d
-#define SVM_EXIT_FERR_FREEZE 0x07e
-#define SVM_EXIT_SHUTDOWN 0x07f
-#define SVM_EXIT_VMRUN 0x080
-#define SVM_EXIT_VMMCALL 0x081
-#define SVM_EXIT_VMLOAD 0x082
-#define SVM_EXIT_VMSAVE 0x083
-#define SVM_EXIT_STGI 0x084
-#define SVM_EXIT_CLGI 0x085
-#define SVM_EXIT_SKINIT 0x086
-#define SVM_EXIT_RDTSCP 0x087
-#define SVM_EXIT_ICEBP 0x088
-#define SVM_EXIT_WBINVD 0x089
-#define SVM_EXIT_MONITOR 0x08a
-#define SVM_EXIT_MWAIT 0x08b
-#define SVM_EXIT_MWAIT_COND 0x08c
-#define SVM_EXIT_XSETBV 0x08d
-#define SVM_EXIT_NPF 0x400
-
-#define SVM_EXIT_ERR -1
-
#define SVM_CR0_SELECTIVE_MASK (X86_CR0_TS | X86_CR0_MP)
#define SVM_VMLOAD ".byte 0x0f, 0x01, 0xda"
@@ -350,3 +404,4 @@ struct __attribute__ ((__packed__)) vmcb {
#endif
+#endif
diff --git a/arch/x86/include/asm/vmx.h b/arch/x86/include/asm/vmx.h
index 74fcb96..36ec21c 100644
--- a/arch/x86/include/asm/vmx.h
+++ b/arch/x86/include/asm/vmx.h
@@ -25,6 +25,88 @@
*
*/
+#define VMX_EXIT_REASONS_FAILED_VMENTRY 0x80000000
+
+#define EXIT_REASON_EXCEPTION_NMI 0
+#define EXIT_REASON_EXTERNAL_INTERRUPT 1
+#define EXIT_REASON_TRIPLE_FAULT 2
+
+#define EXIT_REASON_PENDING_INTERRUPT 7
+#define EXIT_REASON_NMI_WINDOW 8
+#define EXIT_REASON_TASK_SWITCH 9
+#define EXIT_REASON_CPUID 10
+#define EXIT_REASON_HLT 12
+#define EXIT_REASON_INVD 13
+#define EXIT_REASON_INVLPG 14
+#define EXIT_REASON_RDPMC 15
+#define EXIT_REASON_RDTSC 16
+#define EXIT_REASON_VMCALL 18
+#define EXIT_REASON_VMCLEAR 19
+#define EXIT_REASON_VMLAUNCH 20
+#define EXIT_REASON_VMPTRLD 21
+#define EXIT_REASON_VMPTRST 22
+#define EXIT_REASON_VMREAD 23
+#define EXIT_REASON_VMRESUME 24
+#define EXIT_REASON_VMWRITE 25
+#define EXIT_REASON_VMOFF 26
+#define EXIT_REASON_VMON 27
+#define EXIT_REASON_CR_ACCESS 28
+#define EXIT_REASON_DR_ACCESS 29
+#define EXIT_REASON_IO_INSTRUCTION 30
+#define EXIT_REASON_MSR_READ 31
+#define EXIT_REASON_MSR_WRITE 32
+#define EXIT_REASON_INVALID_STATE 33
+#define EXIT_REASON_MWAIT_INSTRUCTION 36
+#define EXIT_REASON_MONITOR_INSTRUCTION 39
+#define EXIT_REASON_PAUSE_INSTRUCTION 40
+#define EXIT_REASON_MCE_DURING_VMENTRY 41
+#define EXIT_REASON_TPR_BELOW_THRESHOLD 43
+#define EXIT_REASON_APIC_ACCESS 44
+#define EXIT_REASON_EPT_VIOLATION 48
+#define EXIT_REASON_EPT_MISCONFIG 49
+#define EXIT_REASON_WBINVD 54
+#define EXIT_REASON_XSETBV 55
+#define EXIT_REASON_INVPCID 58
+
+#define VMX_EXIT_REASONS \
+ { EXIT_REASON_EXCEPTION_NMI, "EXCEPTION_NMI" }, \
+ { EXIT_REASON_EXTERNAL_INTERRUPT, "EXTERNAL_INTERRUPT" }, \
+ { EXIT_REASON_TRIPLE_FAULT, "TRIPLE_FAULT" }, \
+ { EXIT_REASON_PENDING_INTERRUPT, "PENDING_INTERRUPT" }, \
+ { EXIT_REASON_NMI_WINDOW, "NMI_WINDOW" }, \
+ { EXIT_REASON_TASK_SWITCH, "TASK_SWITCH" }, \
+ { EXIT_REASON_CPUID, "CPUID" }, \
+ { EXIT_REASON_HLT, "HLT" }, \
+ { EXIT_REASON_INVLPG, "INVLPG" }, \
+ { EXIT_REASON_RDPMC, "RDPMC" }, \
+ { EXIT_REASON_RDTSC, "RDTSC" }, \
+ { EXIT_REASON_VMCALL, "VMCALL" }, \
+ { EXIT_REASON_VMCLEAR, "VMCLEAR" }, \
+ { EXIT_REASON_VMLAUNCH, "VMLAUNCH" }, \
+ { EXIT_REASON_VMPTRLD, "VMPTRLD" }, \
+ { EXIT_REASON_VMPTRST, "VMPTRST" }, \
+ { EXIT_REASON_VMREAD, "VMREAD" }, \
+ { EXIT_REASON_VMRESUME, "VMRESUME" }, \
+ { EXIT_REASON_VMWRITE, "VMWRITE" }, \
+ { EXIT_REASON_VMOFF, "VMOFF" }, \
+ { EXIT_REASON_VMON, "VMON" }, \
+ { EXIT_REASON_CR_ACCESS, "CR_ACCESS" }, \
+ { EXIT_REASON_DR_ACCESS, "DR_ACCESS" }, \
+ { EXIT_REASON_IO_INSTRUCTION, "IO_INSTRUCTION" }, \
+ { EXIT_REASON_MSR_READ, "MSR_READ" }, \
+ { EXIT_REASON_MSR_WRITE, "MSR_WRITE" }, \
+ { EXIT_REASON_MWAIT_INSTRUCTION, "MWAIT_INSTRUCTION" }, \
+ { EXIT_REASON_MONITOR_INSTRUCTION, "MONITOR_INSTRUCTION" }, \
+ { EXIT_REASON_PAUSE_INSTRUCTION, "PAUSE_INSTRUCTION" }, \
+ { EXIT_REASON_MCE_DURING_VMENTRY, "MCE_DURING_VMENTRY" }, \
+ { EXIT_REASON_TPR_BELOW_THRESHOLD, "TPR_BELOW_THRESHOLD" }, \
+ { EXIT_REASON_APIC_ACCESS, "APIC_ACCESS" }, \
+ { EXIT_REASON_EPT_VIOLATION, "EPT_VIOLATION" }, \
+ { EXIT_REASON_EPT_MISCONFIG, "EPT_MISCONFIG" }, \
+ { EXIT_REASON_WBINVD, "WBINVD" }
+
+#ifdef __KERNEL__
+
#include <linux/types.h>
/*
@@ -241,49 +323,6 @@ enum vmcs_field {
HOST_RIP = 0x00006c16,
};
-#define VMX_EXIT_REASONS_FAILED_VMENTRY 0x80000000
-
-#define EXIT_REASON_EXCEPTION_NMI 0
-#define EXIT_REASON_EXTERNAL_INTERRUPT 1
-#define EXIT_REASON_TRIPLE_FAULT 2
-
-#define EXIT_REASON_PENDING_INTERRUPT 7
-#define EXIT_REASON_NMI_WINDOW 8
-#define EXIT_REASON_TASK_SWITCH 9
-#define EXIT_REASON_CPUID 10
-#define EXIT_REASON_HLT 12
-#define EXIT_REASON_INVD 13
-#define EXIT_REASON_INVLPG 14
-#define EXIT_REASON_RDPMC 15
-#define EXIT_REASON_RDTSC 16
-#define EXIT_REASON_VMCALL 18
-#define EXIT_REASON_VMCLEAR 19
-#define EXIT_REASON_VMLAUNCH 20
-#define EXIT_REASON_VMPTRLD 21
-#define EXIT_REASON_VMPTRST 22
-#define EXIT_REASON_VMREAD 23
-#define EXIT_REASON_VMRESUME 24
-#define EXIT_REASON_VMWRITE 25
-#define EXIT_REASON_VMOFF 26
-#define EXIT_REASON_VMON 27
-#define EXIT_REASON_CR_ACCESS 28
-#define EXIT_REASON_DR_ACCESS 29
-#define EXIT_REASON_IO_INSTRUCTION 30
-#define EXIT_REASON_MSR_READ 31
-#define EXIT_REASON_MSR_WRITE 32
-#define EXIT_REASON_INVALID_STATE 33
-#define EXIT_REASON_MWAIT_INSTRUCTION 36
-#define EXIT_REASON_MONITOR_INSTRUCTION 39
-#define EXIT_REASON_PAUSE_INSTRUCTION 40
-#define EXIT_REASON_MCE_DURING_VMENTRY 41
-#define EXIT_REASON_TPR_BELOW_THRESHOLD 43
-#define EXIT_REASON_APIC_ACCESS 44
-#define EXIT_REASON_EPT_VIOLATION 48
-#define EXIT_REASON_EPT_MISCONFIG 49
-#define EXIT_REASON_WBINVD 54
-#define EXIT_REASON_XSETBV 55
-#define EXIT_REASON_INVPCID 58
-
/*
* Interruption-information format
*/
@@ -488,3 +527,5 @@ enum vm_instruction_error_number {
};
#endif
+
+#endif
diff --git a/arch/x86/kvm/trace.h b/arch/x86/kvm/trace.h
index a71faf7..bca63f0 100644
--- a/arch/x86/kvm/trace.h
+++ b/arch/x86/kvm/trace.h
@@ -183,95 +183,6 @@ TRACE_EVENT(kvm_apic,
#define KVM_ISA_VMX 1
#define KVM_ISA_SVM 2
-#define VMX_EXIT_REASONS \
- { EXIT_REASON_EXCEPTION_NMI, "EXCEPTION_NMI" }, \
- { EXIT_REASON_EXTERNAL_INTERRUPT, "EXTERNAL_INTERRUPT" }, \
- { EXIT_REASON_TRIPLE_FAULT, "TRIPLE_FAULT" }, \
- { EXIT_REASON_PENDING_INTERRUPT, "PENDING_INTERRUPT" }, \
- { EXIT_REASON_NMI_WINDOW, "NMI_WINDOW" }, \
- { EXIT_REASON_TASK_SWITCH, "TASK_SWITCH" }, \
- { EXIT_REASON_CPUID, "CPUID" }, \
- { EXIT_REASON_HLT, "HLT" }, \
- { EXIT_REASON_INVLPG, "INVLPG" }, \
- { EXIT_REASON_RDPMC, "RDPMC" }, \
- { EXIT_REASON_RDTSC, "RDTSC" }, \
- { EXIT_REASON_VMCALL, "VMCALL" }, \
- { EXIT_REASON_VMCLEAR, "VMCLEAR" }, \
- { EXIT_REASON_VMLAUNCH, "VMLAUNCH" }, \
- { EXIT_REASON_VMPTRLD, "VMPTRLD" }, \
- { EXIT_REASON_VMPTRST, "VMPTRST" }, \
- { EXIT_REASON_VMREAD, "VMREAD" }, \
- { EXIT_REASON_VMRESUME, "VMRESUME" }, \
- { EXIT_REASON_VMWRITE, "VMWRITE" }, \
- { EXIT_REASON_VMOFF, "VMOFF" }, \
- { EXIT_REASON_VMON, "VMON" }, \
- { EXIT_REASON_CR_ACCESS, "CR_ACCESS" }, \
- { EXIT_REASON_DR_ACCESS, "DR_ACCESS" }, \
- { EXIT_REASON_IO_INSTRUCTION, "IO_INSTRUCTION" }, \
- { EXIT_REASON_MSR_READ, "MSR_READ" }, \
- { EXIT_REASON_MSR_WRITE, "MSR_WRITE" }, \
- { EXIT_REASON_MWAIT_INSTRUCTION, "MWAIT_INSTRUCTION" }, \
- { EXIT_REASON_MONITOR_INSTRUCTION, "MONITOR_INSTRUCTION" }, \
- { EXIT_REASON_PAUSE_INSTRUCTION, "PAUSE_INSTRUCTION" }, \
- { EXIT_REASON_MCE_DURING_VMENTRY, "MCE_DURING_VMENTRY" }, \
- { EXIT_REASON_TPR_BELOW_THRESHOLD, "TPR_BELOW_THRESHOLD" }, \
- { EXIT_REASON_APIC_ACCESS, "APIC_ACCESS" }, \
- { EXIT_REASON_EPT_VIOLATION, "EPT_VIOLATION" }, \
- { EXIT_REASON_EPT_MISCONFIG, "EPT_MISCONFIG" }, \
- { EXIT_REASON_WBINVD, "WBINVD" }
-
-#define SVM_EXIT_REASONS \
- { SVM_EXIT_READ_CR0, "read_cr0" }, \
- { SVM_EXIT_READ_CR3, "read_cr3" }, \
- { SVM_EXIT_READ_CR4, "read_cr4" }, \
- { SVM_EXIT_READ_CR8, "read_cr8" }, \
- { SVM_EXIT_WRITE_CR0, "write_cr0" }, \
- { SVM_EXIT_WRITE_CR3, "write_cr3" }, \
- { SVM_EXIT_WRITE_CR4, "write_cr4" }, \
- { SVM_EXIT_WRITE_CR8, "write_cr8" }, \
- { SVM_EXIT_READ_DR0, "read_dr0" }, \
- { SVM_EXIT_READ_DR1, "read_dr1" }, \
- { SVM_EXIT_READ_DR2, "read_dr2" }, \
- { SVM_EXIT_READ_DR3, "read_dr3" }, \
- { SVM_EXIT_WRITE_DR0, "write_dr0" }, \
- { SVM_EXIT_WRITE_DR1, "write_dr1" }, \
- { SVM_EXIT_WRITE_DR2, "write_dr2" }, \
- { SVM_EXIT_WRITE_DR3, "write_dr3" }, \
- { SVM_EXIT_WRITE_DR5, "write_dr5" }, \
- { SVM_EXIT_WRITE_DR7, "write_dr7" }, \
- { SVM_EXIT_EXCP_BASE + DB_VECTOR, "DB excp" }, \
- { SVM_EXIT_EXCP_BASE + BP_VECTOR, "BP excp" }, \
- { SVM_EXIT_EXCP_BASE + UD_VECTOR, "UD excp" }, \
- { SVM_EXIT_EXCP_BASE + PF_VECTOR, "PF excp" }, \
- { SVM_EXIT_EXCP_BASE + NM_VECTOR, "NM excp" }, \
- { SVM_EXIT_EXCP_BASE + MC_VECTOR, "MC excp" }, \
- { SVM_EXIT_INTR, "interrupt" }, \
- { SVM_EXIT_NMI, "nmi" }, \
- { SVM_EXIT_SMI, "smi" }, \
- { SVM_EXIT_INIT, "init" }, \
- { SVM_EXIT_VINTR, "vintr" }, \
- { SVM_EXIT_CPUID, "cpuid" }, \
- { SVM_EXIT_INVD, "invd" }, \
- { SVM_EXIT_HLT, "hlt" }, \
- { SVM_EXIT_INVLPG, "invlpg" }, \
- { SVM_EXIT_INVLPGA, "invlpga" }, \
- { SVM_EXIT_IOIO, "io" }, \
- { SVM_EXIT_MSR, "msr" }, \
- { SVM_EXIT_TASK_SWITCH, "task_switch" }, \
- { SVM_EXIT_SHUTDOWN, "shutdown" }, \
- { SVM_EXIT_VMRUN, "vmrun" }, \
- { SVM_EXIT_VMMCALL, "hypercall" }, \
- { SVM_EXIT_VMLOAD, "vmload" }, \
- { SVM_EXIT_VMSAVE, "vmsave" }, \
- { SVM_EXIT_STGI, "stgi" }, \
- { SVM_EXIT_CLGI, "clgi" }, \
- { SVM_EXIT_SKINIT, "skinit" }, \
- { SVM_EXIT_WBINVD, "wbinvd" }, \
- { SVM_EXIT_MONITOR, "monitor" }, \
- { SVM_EXIT_MWAIT, "mwait" }, \
- { SVM_EXIT_XSETBV, "xsetbv" }, \
- { SVM_EXIT_NPF, "npf" }
-
/*
* Tracepoint for kvm guest exit:
*/
--
1.7.1
^ permalink raw reply related [flat|nested] 41+ messages in thread
* [PATCH 06/30] perf kvm: Events analysis tool
2012-09-24 15:59 [GIT PULL 00/30] perf/core improvements and fixes Arnaldo Carvalho de Melo
` (4 preceding siblings ...)
2012-09-24 15:59 ` [PATCH 05/30] KVM: x86: Export svm/vmx exit code and vector code to userspace Arnaldo Carvalho de Melo
@ 2012-09-24 15:59 ` Arnaldo Carvalho de Melo
2012-09-24 15:59 ` [PATCH 07/30] perf kvm: Use perf_evsel__intval Arnaldo Carvalho de Melo
` (23 subsequent siblings)
29 siblings, 0 replies; 41+ messages in thread
From: Arnaldo Carvalho de Melo @ 2012-09-24 15:59 UTC (permalink / raw)
To: Ingo Molnar
Cc: linux-kernel, Xiao Guangrong, Dong Hao, Runzhen Wang, Avi Kivity,
David Ahern, Marcelo Tosatti, kvm, Arnaldo Carvalho de Melo
From: Xiao Guangrong <xiaoguangrong@linux.vnet.ibm.com>
Add 'perf kvm stat' support to analyze kvm vmexit/mmio/ioport smartly
Usage:
- kvm stat
run a command and gather performance counter statistics, it is the alias of
perf stat
- trace kvm events:
perf kvm stat record, or, if other tracepoints are interesting as well, we
can append the events like this:
perf kvm stat record -e timer:* -a
If many guests are running, we can track the specified guest by using -p or
--pid, -a is used to track events generated by all guests.
- show the result:
perf kvm stat report
The output example is following:
13005
13059
total 2 guests are running on the host
Then, track the guest whose pid is 13059:
^C[ perf record: Woken up 1 times to write data ]
[ perf record: Captured and wrote 0.253 MB perf.data.guest (~11065 samples) ]
See the vmexit events:
Analyze events for all VCPUs:
VM-EXIT Samples Samples% Time% Avg time
APIC_ACCESS 460 70.55% 0.01% 22.44us ( +- 1.75% )
HLT 93 14.26% 99.98% 832077.26us ( +- 10.42% )
EXTERNAL_INTERRUPT 64 9.82% 0.00% 35.35us ( +- 14.21% )
PENDING_INTERRUPT 24 3.68% 0.00% 9.29us ( +- 31.39% )
CR_ACCESS 7 1.07% 0.00% 8.12us ( +- 5.76% )
IO_INSTRUCTION 3 0.46% 0.00% 18.00us ( +- 11.79% )
EXCEPTION_NMI 1 0.15% 0.00% 5.83us ( +- -nan% )
Total Samples:652, Total events handled time:77396109.80us.
See the mmio events:
Analyze events for all VCPUs:
MMIO Access Samples Samples% Time% Avg time
0xfee00380:W 387 84.31% 79.28% 8.29us ( +- 3.32% )
0xfee00300:W 24 5.23% 9.96% 16.79us ( +- 1.97% )
0xfee00300:R 24 5.23% 7.83% 13.20us ( +- 3.00% )
0xfee00310:W 24 5.23% 2.93% 4.94us ( +- 3.84% )
Total Samples:459, Total events handled time:4044.59us.
See the ioport event:
Analyze events for all VCPUs:
IO Port Access Samples Samples% Time% Avg time
0xc050:POUT 3 100.00% 100.00% 13.75us ( +- 10.83% )
Total Samples:3, Total events handled time:41.26us.
And, --vcpu is used to track the specified vcpu and --key is used to sort the
result:
Analyze events for VCPU 0:
VM-EXIT Samples Samples% Time% Avg time
HLT 27 13.85% 99.97% 405790.24us ( +- 12.70% )
EXTERNAL_INTERRUPT 13 6.67% 0.00% 27.94us ( +- 22.26% )
APIC_ACCESS 146 74.87% 0.03% 21.69us ( +- 2.91% )
IO_INSTRUCTION 2 1.03% 0.00% 17.77us ( +- 20.56% )
CR_ACCESS 2 1.03% 0.00% 8.55us ( +- 6.47% )
PENDING_INTERRUPT 5 2.56% 0.00% 6.27us ( +- 3.94% )
Total Samples:195, Total events handled time:10959950.90us.
Signed-off-by: Dong Hao <haodong@linux.vnet.ibm.com>
Signed-off-by: Runzhen Wang <runzhen@linux.vnet.ibm.com>
[ Dong Hao <haodong@linux.vnet.ibm.com>
Runzhen Wang <runzhen@linux.vnet.ibm.com>:
- rebase it on current acme's tree
- fix the compiling-error on i386 ]
Signed-off-by: Xiao Guangrong <xiaoguangrong@linux.vnet.ibm.com>
Acked-by: David Ahern <dsahern@gmail.com>
Cc: Avi Kivity <avi@redhat.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Marcelo Tosatti <mtosatti@redhat.com>
Cc: kvm@vger.kernel.org
Cc: Runzhen Wang <runzhen@linux.vnet.ibm.com>
Link: http://lkml.kernel.org/r/1347870675-31495-4-git-send-email-haodong@linux.vnet.ibm.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
tools/perf/Documentation/perf-kvm.txt | 30 ++-
tools/perf/MANIFEST | 3 +
tools/perf/builtin-kvm.c | 840 ++++++++++++++++++++++++++++++++-
| 59 +++-
| 1 +
tools/perf/util/thread.h | 2 +
6 files changed, 929 insertions(+), 6 deletions(-)
diff --git a/tools/perf/Documentation/perf-kvm.txt b/tools/perf/Documentation/perf-kvm.txt
index dd84cb2..326f2cb 100644
--- a/tools/perf/Documentation/perf-kvm.txt
+++ b/tools/perf/Documentation/perf-kvm.txt
@@ -12,7 +12,7 @@ SYNOPSIS
[--guestkallsyms=<path> --guestmodules=<path> | --guestvmlinux=<path>]]
{top|record|report|diff|buildid-list}
'perf kvm' [--host] [--guest] [--guestkallsyms=<path> --guestmodules=<path>
- | --guestvmlinux=<path>] {top|record|report|diff|buildid-list}
+ | --guestvmlinux=<path>] {top|record|report|diff|buildid-list|stat}
DESCRIPTION
-----------
@@ -38,6 +38,18 @@ There are a couple of variants of perf kvm:
so that other tools can be used to fetch packages with matching symbol tables
for use by perf report.
+ 'perf kvm stat <command>' to run a command and gather performance counter
+ statistics.
+ Especially, perf 'kvm stat record/report' generates a statistical analysis
+ of KVM events. Currently, vmexit, mmio and ioport events are supported.
+ 'perf kvm stat record <command>' records kvm events and the events between
+ start and end <command>.
+ And this command produces a file which contains tracing results of kvm
+ events.
+
+ 'perf kvm stat report' reports statistical data which includes events
+ handled time, samples, and so on.
+
OPTIONS
-------
-i::
@@ -68,7 +80,21 @@ OPTIONS
--guestvmlinux=<path>::
Guest os kernel vmlinux.
+STAT REPORT OPTIONS
+-------------------
+--vcpu=<value>::
+ analyze events which occures on this vcpu. (default: all vcpus)
+
+--events=<value>::
+ events to be analyzed. Possible values: vmexit, mmio, ioport.
+ (default: vmexit)
+-k::
+--key=<value>::
+ Sorting key. Possible values: sample (default, sort by samples
+ number), time (sort by average time).
+
SEE ALSO
--------
linkperf:perf-top[1], linkperf:perf-record[1], linkperf:perf-report[1],
-linkperf:perf-diff[1], linkperf:perf-buildid-list[1]
+linkperf:perf-diff[1], linkperf:perf-buildid-list[1],
+linkperf:perf-stat[1]
diff --git a/tools/perf/MANIFEST b/tools/perf/MANIFEST
index 0518079..80db3f4 100644
--- a/tools/perf/MANIFEST
+++ b/tools/perf/MANIFEST
@@ -16,3 +16,6 @@ arch/*/lib/memset*.S
include/linux/poison.h
include/linux/magic.h
include/linux/hw_breakpoint.h
+arch/x86/include/asm/svm.h
+arch/x86/include/asm/vmx.h
+arch/x86/include/asm/kvm_host.h
diff --git a/tools/perf/builtin-kvm.c b/tools/perf/builtin-kvm.c
index 4d2aa2c..1878947 100644
--- a/tools/perf/builtin-kvm.c
+++ b/tools/perf/builtin-kvm.c
@@ -1,6 +1,7 @@
#include "builtin.h"
#include "perf.h"
+#include "util/evsel.h"
#include "util/util.h"
#include "util/cache.h"
#include "util/symbol.h"
@@ -10,8 +11,10 @@
#include "util/parse-options.h"
#include "util/trace-event.h"
-
#include "util/debug.h"
+#include "util/debugfs.h"
+#include "util/tool.h"
+#include "util/stat.h"
#include <sys/prctl.h>
@@ -19,11 +22,840 @@
#include <pthread.h>
#include <math.h>
-static const char *file_name;
+#include "../../arch/x86/include/asm/svm.h"
+#include "../../arch/x86/include/asm/vmx.h"
+#include "../../arch/x86/include/asm/kvm.h"
+
+struct event_key {
+ #define INVALID_KEY (~0ULL)
+ u64 key;
+ int info;
+};
+
+struct kvm_events_ops {
+ bool (*is_begin_event)(struct event_format *event, void *data,
+ struct event_key *key);
+ bool (*is_end_event)(struct event_format *event, void *data,
+ struct event_key *key);
+ void (*decode_key)(struct event_key *key, char decode[20]);
+ const char *name;
+};
+
+static void exit_event_get_key(struct event_format *event, void *data,
+ struct event_key *key)
+{
+ key->info = 0;
+ key->key = raw_field_value(event, "exit_reason", data);
+}
+
+static bool kvm_exit_event(struct event_format *event)
+{
+ return !strcmp(event->name, "kvm_exit");
+}
+
+static bool exit_event_begin(struct event_format *event, void *data,
+ struct event_key *key)
+{
+ if (kvm_exit_event(event)) {
+ exit_event_get_key(event, data, key);
+ return true;
+ }
+
+ return false;
+}
+
+static bool kvm_entry_event(struct event_format *event)
+{
+ return !strcmp(event->name, "kvm_entry");
+}
+
+static bool exit_event_end(struct event_format *event, void *data __maybe_unused,
+ struct event_key *key __maybe_unused)
+{
+ return kvm_entry_event(event);
+}
+
+struct exit_reasons_table {
+ unsigned long exit_code;
+ const char *reason;
+};
+
+struct exit_reasons_table vmx_exit_reasons[] = {
+ VMX_EXIT_REASONS
+};
+
+struct exit_reasons_table svm_exit_reasons[] = {
+ SVM_EXIT_REASONS
+};
+
+static int cpu_isa;
+
+static const char *get_exit_reason(u64 exit_code)
+{
+ int table_size = ARRAY_SIZE(svm_exit_reasons);
+ struct exit_reasons_table *table = svm_exit_reasons;
+
+ if (cpu_isa == 1) {
+ table = vmx_exit_reasons;
+ table_size = ARRAY_SIZE(vmx_exit_reasons);
+ }
+
+ while (table_size--) {
+ if (table->exit_code == exit_code)
+ return table->reason;
+ table++;
+ }
+
+ pr_err("unknown kvm exit code:%lld on %s\n",
+ (unsigned long long)exit_code, cpu_isa ? "VMX" : "SVM");
+ return "UNKNOWN";
+}
+
+static void exit_event_decode_key(struct event_key *key, char decode[20])
+{
+ const char *exit_reason = get_exit_reason(key->key);
+
+ scnprintf(decode, 20, "%s", exit_reason);
+}
+
+static struct kvm_events_ops exit_events = {
+ .is_begin_event = exit_event_begin,
+ .is_end_event = exit_event_end,
+ .decode_key = exit_event_decode_key,
+ .name = "VM-EXIT"
+};
+
+ /*
+ * For the mmio events, we treat:
+ * the time of MMIO write: kvm_mmio(KVM_TRACE_MMIO_WRITE...) -> kvm_entry
+ * the time of MMIO read: kvm_exit -> kvm_mmio(KVM_TRACE_MMIO_READ...).
+ */
+static void mmio_event_get_key(struct event_format *event, void *data,
+ struct event_key *key)
+{
+ key->key = raw_field_value(event, "gpa", data);
+ key->info = raw_field_value(event, "type", data);
+}
+
+#define KVM_TRACE_MMIO_READ_UNSATISFIED 0
+#define KVM_TRACE_MMIO_READ 1
+#define KVM_TRACE_MMIO_WRITE 2
+
+static bool mmio_event_begin(struct event_format *event, void *data,
+ struct event_key *key)
+{
+ /* MMIO read begin event in kernel. */
+ if (kvm_exit_event(event))
+ return true;
+
+ /* MMIO write begin event in kernel. */
+ if (!strcmp(event->name, "kvm_mmio") &&
+ raw_field_value(event, "type", data) == KVM_TRACE_MMIO_WRITE) {
+ mmio_event_get_key(event, data, key);
+ return true;
+ }
+
+ return false;
+}
+
+static bool mmio_event_end(struct event_format *event, void *data,
+ struct event_key *key)
+{
+ /* MMIO write end event in kernel. */
+ if (kvm_entry_event(event))
+ return true;
+
+ /* MMIO read end event in kernel.*/
+ if (!strcmp(event->name, "kvm_mmio") &&
+ raw_field_value(event, "type", data) == KVM_TRACE_MMIO_READ) {
+ mmio_event_get_key(event, data, key);
+ return true;
+ }
+
+ return false;
+}
+
+static void mmio_event_decode_key(struct event_key *key, char decode[20])
+{
+ scnprintf(decode, 20, "%#lx:%s", (unsigned long)key->key,
+ key->info == KVM_TRACE_MMIO_WRITE ? "W" : "R");
+}
+
+static struct kvm_events_ops mmio_events = {
+ .is_begin_event = mmio_event_begin,
+ .is_end_event = mmio_event_end,
+ .decode_key = mmio_event_decode_key,
+ .name = "MMIO Access"
+};
+
+ /* The time of emulation pio access is from kvm_pio to kvm_entry. */
+static void ioport_event_get_key(struct event_format *event, void *data,
+ struct event_key *key)
+{
+ key->key = raw_field_value(event, "port", data);
+ key->info = raw_field_value(event, "rw", data);
+}
+
+static bool ioport_event_begin(struct event_format *event, void *data,
+ struct event_key *key)
+{
+ if (!strcmp(event->name, "kvm_pio")) {
+ ioport_event_get_key(event, data, key);
+ return true;
+ }
+
+ return false;
+}
+
+static bool ioport_event_end(struct event_format *event, void *data __maybe_unused,
+ struct event_key *key __maybe_unused)
+{
+ if (kvm_entry_event(event))
+ return true;
+
+ return false;
+}
+
+static void ioport_event_decode_key(struct event_key *key, char decode[20])
+{
+ scnprintf(decode, 20, "%#llx:%s", (unsigned long long)key->key,
+ key->info ? "POUT" : "PIN");
+}
+
+static struct kvm_events_ops ioport_events = {
+ .is_begin_event = ioport_event_begin,
+ .is_end_event = ioport_event_end,
+ .decode_key = ioport_event_decode_key,
+ .name = "IO Port Access"
+};
+
+static const char *report_event = "vmexit";
+struct kvm_events_ops *events_ops;
+
+static bool register_kvm_events_ops(void)
+{
+ bool ret = true;
+
+ if (!strcmp(report_event, "vmexit"))
+ events_ops = &exit_events;
+ else if (!strcmp(report_event, "mmio"))
+ events_ops = &mmio_events;
+ else if (!strcmp(report_event, "ioport"))
+ events_ops = &ioport_events;
+ else {
+ pr_err("Unknown report event:%s\n", report_event);
+ ret = false;
+ }
+
+ return ret;
+}
+
+struct kvm_event_stats {
+ u64 time;
+ struct stats stats;
+};
+
+struct kvm_event {
+ struct list_head hash_entry;
+ struct rb_node rb;
+
+ struct event_key key;
+
+ struct kvm_event_stats total;
+
+ #define DEFAULT_VCPU_NUM 8
+ int max_vcpu;
+ struct kvm_event_stats *vcpu;
+};
+
+struct vcpu_event_record {
+ int vcpu_id;
+ u64 start_time;
+ struct kvm_event *last_event;
+};
+
+#define EVENTS_BITS 12
+#define EVENTS_CACHE_SIZE (1UL << EVENTS_BITS)
+
+static u64 total_time;
+static u64 total_count;
+static struct list_head kvm_events_cache[EVENTS_CACHE_SIZE];
+
+static void init_kvm_event_record(void)
+{
+ int i;
+
+ for (i = 0; i < (int)EVENTS_CACHE_SIZE; i++)
+ INIT_LIST_HEAD(&kvm_events_cache[i]);
+}
+
+static int kvm_events_hash_fn(u64 key)
+{
+ return key & (EVENTS_CACHE_SIZE - 1);
+}
+
+static bool kvm_event_expand(struct kvm_event *event, int vcpu_id)
+{
+ int old_max_vcpu = event->max_vcpu;
+
+ if (vcpu_id < event->max_vcpu)
+ return true;
+
+ while (event->max_vcpu <= vcpu_id)
+ event->max_vcpu += DEFAULT_VCPU_NUM;
+
+ event->vcpu = realloc(event->vcpu,
+ event->max_vcpu * sizeof(*event->vcpu));
+ if (!event->vcpu) {
+ pr_err("Not enough memory\n");
+ return false;
+ }
+
+ memset(event->vcpu + old_max_vcpu, 0,
+ (event->max_vcpu - old_max_vcpu) * sizeof(*event->vcpu));
+ return true;
+}
+
+static struct kvm_event *kvm_alloc_init_event(struct event_key *key)
+{
+ struct kvm_event *event;
+
+ event = zalloc(sizeof(*event));
+ if (!event) {
+ pr_err("Not enough memory\n");
+ return NULL;
+ }
+
+ event->key = *key;
+ return event;
+}
+
+static struct kvm_event *find_create_kvm_event(struct event_key *key)
+{
+ struct kvm_event *event;
+ struct list_head *head;
+
+ BUG_ON(key->key == INVALID_KEY);
+
+ head = &kvm_events_cache[kvm_events_hash_fn(key->key)];
+ list_for_each_entry(event, head, hash_entry)
+ if (event->key.key == key->key && event->key.info == key->info)
+ return event;
+
+ event = kvm_alloc_init_event(key);
+ if (!event)
+ return NULL;
+
+ list_add(&event->hash_entry, head);
+ return event;
+}
+
+static bool handle_begin_event(struct vcpu_event_record *vcpu_record,
+ struct event_key *key, u64 timestamp)
+{
+ struct kvm_event *event = NULL;
+
+ if (key->key != INVALID_KEY)
+ event = find_create_kvm_event(key);
+
+ vcpu_record->last_event = event;
+ vcpu_record->start_time = timestamp;
+ return true;
+}
+
+static void
+kvm_update_event_stats(struct kvm_event_stats *kvm_stats, u64 time_diff)
+{
+ kvm_stats->time += time_diff;
+ update_stats(&kvm_stats->stats, time_diff);
+}
+
+static double kvm_event_rel_stddev(int vcpu_id, struct kvm_event *event)
+{
+ struct kvm_event_stats *kvm_stats = &event->total;
+
+ if (vcpu_id != -1)
+ kvm_stats = &event->vcpu[vcpu_id];
+
+ return rel_stddev_stats(stddev_stats(&kvm_stats->stats),
+ avg_stats(&kvm_stats->stats));
+}
+
+static bool update_kvm_event(struct kvm_event *event, int vcpu_id,
+ u64 time_diff)
+{
+ kvm_update_event_stats(&event->total, time_diff);
+
+ if (!kvm_event_expand(event, vcpu_id))
+ return false;
+
+ kvm_update_event_stats(&event->vcpu[vcpu_id], time_diff);
+ return true;
+}
+
+static bool handle_end_event(struct vcpu_event_record *vcpu_record,
+ struct event_key *key, u64 timestamp)
+{
+ struct kvm_event *event;
+ u64 time_begin, time_diff;
+
+ event = vcpu_record->last_event;
+ time_begin = vcpu_record->start_time;
+
+ /* The begin event is not caught. */
+ if (!time_begin)
+ return true;
+
+ /*
+ * In some case, the 'begin event' only records the start timestamp,
+ * the actual event is recognized in the 'end event' (e.g. mmio-event).
+ */
+
+ /* Both begin and end events did not get the key. */
+ if (!event && key->key == INVALID_KEY)
+ return true;
+
+ if (!event)
+ event = find_create_kvm_event(key);
+
+ if (!event)
+ return false;
+
+ vcpu_record->last_event = NULL;
+ vcpu_record->start_time = 0;
+
+ BUG_ON(timestamp < time_begin);
+
+ time_diff = timestamp - time_begin;
+ return update_kvm_event(event, vcpu_record->vcpu_id, time_diff);
+}
+
+static struct vcpu_event_record
+*per_vcpu_record(struct thread *thread, struct event_format *event, void *data)
+{
+ /* Only kvm_entry records vcpu id. */
+ if (!thread->priv && kvm_entry_event(event)) {
+ struct vcpu_event_record *vcpu_record;
+
+ vcpu_record = zalloc(sizeof(struct vcpu_event_record));
+ if (!vcpu_record) {
+ pr_err("Not enough memory\n");
+ return NULL;
+ }
+
+ vcpu_record->vcpu_id = raw_field_value(event, "vcpu_id", data);
+ thread->priv = vcpu_record;
+ }
+
+ return (struct vcpu_event_record *)thread->priv;
+}
+
+static bool handle_kvm_event(struct thread *thread, struct event_format *event,
+ void *data, u64 timestamp)
+{
+ struct vcpu_event_record *vcpu_record;
+ struct event_key key = {.key = INVALID_KEY};
+
+ vcpu_record = per_vcpu_record(thread, event, data);
+ if (!vcpu_record)
+ return true;
+
+ if (events_ops->is_begin_event(event, data, &key))
+ return handle_begin_event(vcpu_record, &key, timestamp);
+
+ if (events_ops->is_end_event(event, data, &key))
+ return handle_end_event(vcpu_record, &key, timestamp);
+
+ return true;
+}
+
+typedef int (*key_cmp_fun)(struct kvm_event*, struct kvm_event*, int);
+struct kvm_event_key {
+ const char *name;
+ key_cmp_fun key;
+};
+
+static int trace_vcpu = -1;
+#define GET_EVENT_KEY(func, field) \
+static u64 get_event_ ##func(struct kvm_event *event, int vcpu) \
+{ \
+ if (vcpu == -1) \
+ return event->total.field; \
+ \
+ if (vcpu >= event->max_vcpu) \
+ return 0; \
+ \
+ return event->vcpu[vcpu].field; \
+}
+
+#define COMPARE_EVENT_KEY(func, field) \
+GET_EVENT_KEY(func, field) \
+static int compare_kvm_event_ ## func(struct kvm_event *one, \
+ struct kvm_event *two, int vcpu)\
+{ \
+ return get_event_ ##func(one, vcpu) > \
+ get_event_ ##func(two, vcpu); \
+}
+
+GET_EVENT_KEY(time, time);
+COMPARE_EVENT_KEY(count, stats.n);
+COMPARE_EVENT_KEY(mean, stats.mean);
+
+#define DEF_SORT_NAME_KEY(name, compare_key) \
+ { #name, compare_kvm_event_ ## compare_key }
+
+static struct kvm_event_key keys[] = {
+ DEF_SORT_NAME_KEY(sample, count),
+ DEF_SORT_NAME_KEY(time, mean),
+ { NULL, NULL }
+};
+
+static const char *sort_key = "sample";
+static key_cmp_fun compare;
+
+static bool select_key(void)
+{
+ int i;
+
+ for (i = 0; keys[i].name; i++) {
+ if (!strcmp(keys[i].name, sort_key)) {
+ compare = keys[i].key;
+ return true;
+ }
+ }
+
+ pr_err("Unknown compare key:%s\n", sort_key);
+ return false;
+}
+
+static struct rb_root result;
+static void insert_to_result(struct kvm_event *event, key_cmp_fun bigger,
+ int vcpu)
+{
+ struct rb_node **rb = &result.rb_node;
+ struct rb_node *parent = NULL;
+ struct kvm_event *p;
+
+ while (*rb) {
+ p = container_of(*rb, struct kvm_event, rb);
+ parent = *rb;
+
+ if (bigger(event, p, vcpu))
+ rb = &(*rb)->rb_left;
+ else
+ rb = &(*rb)->rb_right;
+ }
+
+ rb_link_node(&event->rb, parent, rb);
+ rb_insert_color(&event->rb, &result);
+}
+
+static void update_total_count(struct kvm_event *event, int vcpu)
+{
+ total_count += get_event_count(event, vcpu);
+ total_time += get_event_time(event, vcpu);
+}
+
+static bool event_is_valid(struct kvm_event *event, int vcpu)
+{
+ return !!get_event_count(event, vcpu);
+}
+
+static void sort_result(int vcpu)
+{
+ unsigned int i;
+ struct kvm_event *event;
+
+ for (i = 0; i < EVENTS_CACHE_SIZE; i++)
+ list_for_each_entry(event, &kvm_events_cache[i], hash_entry)
+ if (event_is_valid(event, vcpu)) {
+ update_total_count(event, vcpu);
+ insert_to_result(event, compare, vcpu);
+ }
+}
+
+/* returns left most element of result, and erase it */
+static struct kvm_event *pop_from_result(void)
+{
+ struct rb_node *node = rb_first(&result);
+
+ if (!node)
+ return NULL;
+
+ rb_erase(node, &result);
+ return container_of(node, struct kvm_event, rb);
+}
+
+static void print_vcpu_info(int vcpu)
+{
+ pr_info("Analyze events for ");
+
+ if (vcpu == -1)
+ pr_info("all VCPUs:\n\n");
+ else
+ pr_info("VCPU %d:\n\n", vcpu);
+}
+
+static void print_result(int vcpu)
+{
+ char decode[20];
+ struct kvm_event *event;
+
+ pr_info("\n\n");
+ print_vcpu_info(vcpu);
+ pr_info("%20s ", events_ops->name);
+ pr_info("%10s ", "Samples");
+ pr_info("%9s ", "Samples%");
+
+ pr_info("%9s ", "Time%");
+ pr_info("%16s ", "Avg time");
+ pr_info("\n\n");
+
+ while ((event = pop_from_result())) {
+ u64 ecount, etime;
+
+ ecount = get_event_count(event, vcpu);
+ etime = get_event_time(event, vcpu);
+
+ events_ops->decode_key(&event->key, decode);
+ pr_info("%20s ", decode);
+ pr_info("%10llu ", (unsigned long long)ecount);
+ pr_info("%8.2f%% ", (double)ecount / total_count * 100);
+ pr_info("%8.2f%% ", (double)etime / total_time * 100);
+ pr_info("%9.2fus ( +-%7.2f%% )", (double)etime / ecount/1e3,
+ kvm_event_rel_stddev(vcpu, event));
+ pr_info("\n");
+ }
+
+ pr_info("\nTotal Samples:%lld, Total events handled time:%.2fus.\n\n",
+ (unsigned long long)total_count, total_time / 1e3);
+}
+
+static int process_sample_event(struct perf_tool *tool __maybe_unused,
+ union perf_event *event,
+ struct perf_sample *sample,
+ struct perf_evsel *evsel,
+ struct machine *machine)
+{
+ struct thread *thread = machine__findnew_thread(machine, sample->tid);
+
+ if (thread == NULL) {
+ pr_debug("problem processing %d event, skipping it.\n",
+ event->header.type);
+ return -1;
+ }
+
+ if (!handle_kvm_event(thread, evsel->tp_format, sample->raw_data,
+ sample->time))
+ return -1;
+
+ return 0;
+}
+
+static struct perf_tool eops = {
+ .sample = process_sample_event,
+ .comm = perf_event__process_comm,
+ .ordered_samples = true,
+};
+
+static int get_cpu_isa(struct perf_session *session)
+{
+ char *cpuid;
+ int isa;
+
+ cpuid = perf_header__read_feature(session, HEADER_CPUID);
+
+ if (!cpuid) {
+ pr_err("read HEADER_CPUID failed.\n");
+ return -ENOTSUP;
+ }
+
+ if (strstr(cpuid, "Intel"))
+ isa = 1;
+ else if (strstr(cpuid, "AMD"))
+ isa = 0;
+ else {
+ pr_err("CPU %s is not supported.\n", cpuid);
+ isa = -ENOTSUP;
+ }
+
+ free(cpuid);
+ return isa;
+}
+
+static const char *file_name;
+
+static int read_events(void)
+{
+ struct perf_session *kvm_session;
+ int ret;
+
+ kvm_session = perf_session__new(file_name, O_RDONLY, 0, false, &eops);
+ if (!kvm_session) {
+ pr_err("Initializing perf session failed\n");
+ return -EINVAL;
+ }
+
+ if (!perf_session__has_traces(kvm_session, "kvm record"))
+ return -EINVAL;
+
+ /*
+ * Do not use 'isa' recorded in kvm_exit tracepoint since it is not
+ * traced in the old kernel.
+ */
+ ret = get_cpu_isa(kvm_session);
+
+ if (ret < 0)
+ return ret;
+
+ cpu_isa = ret;
+
+ return perf_session__process_events(kvm_session, &eops);
+}
+
+static bool verify_vcpu(int vcpu)
+{
+ if (vcpu != -1 && vcpu < 0) {
+ pr_err("Invalid vcpu:%d.\n", vcpu);
+ return false;
+ }
+
+ return true;
+}
+
+static int kvm_events_report_vcpu(int vcpu)
+{
+ int ret = -EINVAL;
+
+ if (!verify_vcpu(vcpu))
+ goto exit;
+
+ if (!select_key())
+ goto exit;
+
+ if (!register_kvm_events_ops())
+ goto exit;
+
+ init_kvm_event_record();
+ setup_pager();
+
+ ret = read_events();
+ if (ret)
+ goto exit;
+
+ sort_result(vcpu);
+ print_result(vcpu);
+exit:
+ return ret;
+}
+
+static const char * const record_args[] = {
+ "record",
+ "-R",
+ "-f",
+ "-m", "1024",
+ "-c", "1",
+ "-e", "kvm:kvm_entry",
+ "-e", "kvm:kvm_exit",
+ "-e", "kvm:kvm_mmio",
+ "-e", "kvm:kvm_pio",
+};
+
+#define STRDUP_FAIL_EXIT(s) \
+ ({ char *_p; \
+ _p = strdup(s); \
+ if (!_p) \
+ return -ENOMEM; \
+ _p; \
+ })
+
+static int kvm_events_record(int argc, const char **argv)
+{
+ unsigned int rec_argc, i, j;
+ const char **rec_argv;
+
+ rec_argc = ARRAY_SIZE(record_args) + argc + 2;
+ rec_argv = calloc(rec_argc + 1, sizeof(char *));
+
+ if (rec_argv == NULL)
+ return -ENOMEM;
+
+ for (i = 0; i < ARRAY_SIZE(record_args); i++)
+ rec_argv[i] = STRDUP_FAIL_EXIT(record_args[i]);
+
+ rec_argv[i++] = STRDUP_FAIL_EXIT("-o");
+ rec_argv[i++] = STRDUP_FAIL_EXIT(file_name);
+
+ for (j = 1; j < (unsigned int)argc; j++, i++)
+ rec_argv[i] = argv[j];
+
+ return cmd_record(i, rec_argv, NULL);
+}
+
+static const char * const kvm_events_report_usage[] = {
+ "perf kvm stat report [<options>]",
+ NULL
+};
+
+static const struct option kvm_events_report_options[] = {
+ OPT_STRING(0, "event", &report_event, "report event",
+ "event for reporting: vmexit, mmio, ioport"),
+ OPT_INTEGER(0, "vcpu", &trace_vcpu,
+ "vcpu id to report"),
+ OPT_STRING('k', "key", &sort_key, "sort-key",
+ "key for sorting: sample(sort by samples number)"
+ " time (sort by avg time)"),
+ OPT_END()
+};
+
+static int kvm_events_report(int argc, const char **argv)
+{
+ symbol__init();
+
+ if (argc) {
+ argc = parse_options(argc, argv,
+ kvm_events_report_options,
+ kvm_events_report_usage, 0);
+ if (argc)
+ usage_with_options(kvm_events_report_usage,
+ kvm_events_report_options);
+ }
+
+ return kvm_events_report_vcpu(trace_vcpu);
+}
+
+static void print_kvm_stat_usage(void)
+{
+ printf("Usage: perf kvm stat <command>\n\n");
+
+ printf("# Available commands:\n");
+ printf("\trecord: record kvm events\n");
+ printf("\treport: report statistical data of kvm events\n");
+
+ printf("\nOtherwise, it is the alias of 'perf stat':\n");
+}
+
+static int kvm_cmd_stat(int argc, const char **argv)
+{
+ if (argc == 1) {
+ print_kvm_stat_usage();
+ goto perf_stat;
+ }
+
+ if (!strncmp(argv[1], "rec", 3))
+ return kvm_events_record(argc - 1, argv + 1);
+
+ if (!strncmp(argv[1], "rep", 3))
+ return kvm_events_report(argc - 1 , argv + 1);
+
+perf_stat:
+ return cmd_stat(argc, argv, NULL);
+}
+
static char name_buffer[256];
static const char * const kvm_usage[] = {
- "perf kvm [<options>] {top|record|report|diff|buildid-list}",
+ "perf kvm [<options>] {top|record|report|diff|buildid-list|stat}",
NULL
};
@@ -135,6 +967,8 @@ 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(argc, argv);
+ else if (!strncmp(argv[0], "stat", 4))
+ return kvm_cmd_stat(argc, argv);
else
usage_with_options(kvm_usage, kvm_options);
--git a/tools/perf/util/header.c b/tools/perf/util/header.c
index acbf633..ad72b28 100644
--- a/tools/perf/util/header.c
+++ b/tools/perf/util/header.c
@@ -1673,6 +1673,11 @@ static int process_build_id(struct perf_file_section *section,
return 0;
}
+static char *read_cpuid(struct perf_header *ph, int fd)
+{
+ return do_read_string(fd, ph);
+}
+
static struct perf_evsel *
perf_evlist__find_by_index(struct perf_evlist *evlist, int idx)
{
@@ -1726,6 +1731,7 @@ process_event_desc(struct perf_file_section *section __maybe_unused,
struct feature_ops {
int (*write)(int fd, struct perf_header *h, struct perf_evlist *evlist);
void (*print)(struct perf_header *h, int fd, FILE *fp);
+ char *(*read)(struct perf_header *h, int fd);
int (*process)(struct perf_file_section *section,
struct perf_header *h, int feat, int fd, void *data);
const char *name;
@@ -1740,6 +1746,9 @@ struct feature_ops {
#define FEAT_OPF(n, func) \
[n] = { .name = #n, .write = write_##func, .print = print_##func, \
.full_only = true }
+#define FEAT_OPA_R(n, func) \
+ [n] = { .name = #n, .write = write_##func, .print = print_##func, \
+ .read = read_##func }
/* feature_ops not implemented: */
#define print_tracing_data NULL
@@ -1754,7 +1763,7 @@ static const struct feature_ops feat_ops[HEADER_LAST_FEATURE] = {
FEAT_OPA(HEADER_ARCH, arch),
FEAT_OPA(HEADER_NRCPUS, nrcpus),
FEAT_OPA(HEADER_CPUDESC, cpudesc),
- FEAT_OPA(HEADER_CPUID, cpuid),
+ FEAT_OPA_R(HEADER_CPUID, cpuid),
FEAT_OPA(HEADER_TOTAL_MEM, total_mem),
FEAT_OPP(HEADER_EVENT_DESC, event_desc),
FEAT_OPA(HEADER_CMDLINE, cmdline),
@@ -1809,6 +1818,54 @@ int perf_header__fprintf_info(struct perf_session *session, FILE *fp, bool full)
return 0;
}
+struct header_read_data {
+ int feat;
+ char *result;
+};
+
+static int perf_file_section__read_feature(struct perf_file_section *section,
+ struct perf_header *ph,
+ int feat, int fd, void *data)
+{
+ struct header_read_data *hd = data;
+
+ if (feat != hd->feat)
+ return 0;
+
+ if (lseek(fd, section->offset, SEEK_SET) == (off_t)-1) {
+ pr_debug("Failed to lseek to %" PRIu64 " offset for feature "
+ "%d, continuing...\n", section->offset, feat);
+ return 0;
+ }
+
+ if (feat >= HEADER_LAST_FEATURE) {
+ pr_warning("unknown feature %d\n", feat);
+ return 0;
+ }
+
+ if (!feat_ops[feat].read) {
+ pr_warning("read is not supported for feature %d\n", feat);
+ return 0;
+ }
+
+ hd->result = feat_ops[feat].read(ph, fd);
+ return 0;
+}
+
+char *perf_header__read_feature(struct perf_session *session, int feat)
+{
+ struct perf_header *header = &session->header;
+ struct header_read_data hd;
+ int fd = session->fd;
+
+ hd.feat = feat;
+ hd.result = NULL;
+
+ perf_header__process_sections(header, fd, &hd,
+ perf_file_section__read_feature);
+ return hd.result;
+}
+
static int do_write_feat(int fd, struct perf_header *h, int type,
struct perf_file_section **p,
struct perf_evlist *evlist)
--git a/tools/perf/util/header.h b/tools/perf/util/header.h
index 209dad4..58de08b 100644
--- a/tools/perf/util/header.h
+++ b/tools/perf/util/header.h
@@ -94,6 +94,7 @@ int perf_header__process_sections(struct perf_header *header, int fd,
int feat, int fd, void *data));
int perf_header__fprintf_info(struct perf_session *s, FILE *fp, bool full);
+char *perf_header__read_feature(struct perf_session *session, int feat);
int build_id_cache__add_s(const char *sbuild_id, const char *debugdir,
const char *name, bool is_kallsyms, bool is_vdso);
diff --git a/tools/perf/util/thread.h b/tools/perf/util/thread.h
index 70c2c13..f66610b 100644
--- a/tools/perf/util/thread.h
+++ b/tools/perf/util/thread.h
@@ -16,6 +16,8 @@ struct thread {
bool comm_set;
char *comm;
int comm_len;
+
+ void *priv;
};
struct machine;
--
1.7.1
^ permalink raw reply related [flat|nested] 41+ messages in thread
* [PATCH 07/30] perf kvm: Use perf_evsel__intval
2012-09-24 15:59 [GIT PULL 00/30] perf/core improvements and fixes Arnaldo Carvalho de Melo
` (5 preceding siblings ...)
2012-09-24 15:59 ` [PATCH 06/30] perf kvm: Events analysis tool Arnaldo Carvalho de Melo
@ 2012-09-24 15:59 ` Arnaldo Carvalho de Melo
2012-09-24 15:59 ` [PATCH 08/30] perf kmem: Use perf_evsel__intval and perf_session__set_tracepoints_handlers Arnaldo Carvalho de Melo
` (22 subsequent siblings)
29 siblings, 0 replies; 41+ messages in thread
From: Arnaldo Carvalho de Melo @ 2012-09-24 15:59 UTC (permalink / raw)
To: Ingo Molnar
Cc: linux-kernel, Arnaldo Carvalho de Melo, David Ahern, Dong Hao,
Frederic Weisbecker, Jiri Olsa, Mike Galbraith, Namhyung Kim,
Paul Mackerras, Peter Zijlstra, Stephane Eranian, Xiao Guangrong,
Runzhen Wang
From: Arnaldo Carvalho de Melo <acme@redhat.com>
Using plain raw_field_value(evsel->tp_format) will look at the common
fields as well, and since this tool doesn't need those, speed it up a
bit by looking at just the event specific fields.
Also in general use just evsel and sample, just like was done in 'perf
sched'.
v2: Fixed up test against evsel->name, that contains the subsys name
too, by David Ahern.
Cc: David Ahern <dsahern@gmail.com>
Cc: Dong Hao <haodong@linux.vnet.ibm.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Namhyung Kim <namhyung@gmail.com>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Cc: Xiao Guangrong <xiaoguangrong@linux.vnet.ibm.com>
Cc: Runzhen Wang <runzhen@linux.vnet.ibm.com>
Link: http://lkml.kernel.org/n/tip-v9x3q9rv4caxtox7wtjpchq5@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
tools/perf/builtin-kvm.c | 130 ++++++++++++++++++++++++----------------------
1 files changed, 67 insertions(+), 63 deletions(-)
diff --git a/tools/perf/builtin-kvm.c b/tools/perf/builtin-kvm.c
index 1878947..3eb53e3 100644
--- a/tools/perf/builtin-kvm.c
+++ b/tools/perf/builtin-kvm.c
@@ -33,46 +33,49 @@ struct event_key {
};
struct kvm_events_ops {
- bool (*is_begin_event)(struct event_format *event, void *data,
- struct event_key *key);
- bool (*is_end_event)(struct event_format *event, void *data,
- struct event_key *key);
+ bool (*is_begin_event)(struct perf_evsel *evsel,
+ struct perf_sample *sample,
+ struct event_key *key);
+ bool (*is_end_event)(struct perf_evsel *evsel,
+ struct perf_sample *sample, struct event_key *key);
void (*decode_key)(struct event_key *key, char decode[20]);
const char *name;
};
-static void exit_event_get_key(struct event_format *event, void *data,
- struct event_key *key)
+static void exit_event_get_key(struct perf_evsel *evsel,
+ struct perf_sample *sample,
+ struct event_key *key)
{
key->info = 0;
- key->key = raw_field_value(event, "exit_reason", data);
+ key->key = perf_evsel__intval(evsel, sample, "exit_reason");
}
-static bool kvm_exit_event(struct event_format *event)
+static bool kvm_exit_event(struct perf_evsel *evsel)
{
- return !strcmp(event->name, "kvm_exit");
+ return !strcmp(evsel->name, "kvm:kvm_exit");
}
-static bool exit_event_begin(struct event_format *event, void *data,
- struct event_key *key)
+static bool exit_event_begin(struct perf_evsel *evsel,
+ struct perf_sample *sample, struct event_key *key)
{
- if (kvm_exit_event(event)) {
- exit_event_get_key(event, data, key);
+ if (kvm_exit_event(evsel)) {
+ exit_event_get_key(evsel, sample, key);
return true;
}
return false;
}
-static bool kvm_entry_event(struct event_format *event)
+static bool kvm_entry_event(struct perf_evsel *evsel)
{
- return !strcmp(event->name, "kvm_entry");
+ return !strcmp(evsel->name, "kvm:kvm_entry");
}
-static bool exit_event_end(struct event_format *event, void *data __maybe_unused,
- struct event_key *key __maybe_unused)
+static bool exit_event_end(struct perf_evsel *evsel,
+ struct perf_sample *sample __maybe_unused,
+ struct event_key *key __maybe_unused)
{
- return kvm_entry_event(event);
+ return kvm_entry_event(evsel);
}
struct exit_reasons_table {
@@ -130,45 +133,45 @@ static struct kvm_events_ops exit_events = {
* the time of MMIO write: kvm_mmio(KVM_TRACE_MMIO_WRITE...) -> kvm_entry
* the time of MMIO read: kvm_exit -> kvm_mmio(KVM_TRACE_MMIO_READ...).
*/
-static void mmio_event_get_key(struct event_format *event, void *data,
- struct event_key *key)
+static void mmio_event_get_key(struct perf_evsel *evsel, struct perf_sample *sample,
+ struct event_key *key)
{
- key->key = raw_field_value(event, "gpa", data);
- key->info = raw_field_value(event, "type", data);
+ key->key = perf_evsel__intval(evsel, sample, "gpa");
+ key->info = perf_evsel__intval(evsel, sample, "type");
}
#define KVM_TRACE_MMIO_READ_UNSATISFIED 0
#define KVM_TRACE_MMIO_READ 1
#define KVM_TRACE_MMIO_WRITE 2
-static bool mmio_event_begin(struct event_format *event, void *data,
- struct event_key *key)
+static bool mmio_event_begin(struct perf_evsel *evsel,
+ struct perf_sample *sample, struct event_key *key)
{
/* MMIO read begin event in kernel. */
- if (kvm_exit_event(event))
+ if (kvm_exit_event(evsel))
return true;
/* MMIO write begin event in kernel. */
- if (!strcmp(event->name, "kvm_mmio") &&
- raw_field_value(event, "type", data) == KVM_TRACE_MMIO_WRITE) {
- mmio_event_get_key(event, data, key);
+ if (!strcmp(evsel->name, "kvm:kvm_mmio") &&
+ perf_evsel__intval(evsel, sample, "type") == KVM_TRACE_MMIO_WRITE) {
+ mmio_event_get_key(evsel, sample, key);
return true;
}
return false;
}
-static bool mmio_event_end(struct event_format *event, void *data,
- struct event_key *key)
+static bool mmio_event_end(struct perf_evsel *evsel, struct perf_sample *sample,
+ struct event_key *key)
{
/* MMIO write end event in kernel. */
- if (kvm_entry_event(event))
+ if (kvm_entry_event(evsel))
return true;
/* MMIO read end event in kernel.*/
- if (!strcmp(event->name, "kvm_mmio") &&
- raw_field_value(event, "type", data) == KVM_TRACE_MMIO_READ) {
- mmio_event_get_key(event, data, key);
+ if (!strcmp(evsel->name, "kvm:kvm_mmio") &&
+ perf_evsel__intval(evsel, sample, "type") == KVM_TRACE_MMIO_READ) {
+ mmio_event_get_key(evsel, sample, key);
return true;
}
@@ -189,31 +192,31 @@ static struct kvm_events_ops mmio_events = {
};
/* The time of emulation pio access is from kvm_pio to kvm_entry. */
-static void ioport_event_get_key(struct event_format *event, void *data,
- struct event_key *key)
+static void ioport_event_get_key(struct perf_evsel *evsel,
+ struct perf_sample *sample,
+ struct event_key *key)
{
- key->key = raw_field_value(event, "port", data);
- key->info = raw_field_value(event, "rw", data);
+ key->key = perf_evsel__intval(evsel, sample, "port");
+ key->info = perf_evsel__intval(evsel, sample, "rw");
}
-static bool ioport_event_begin(struct event_format *event, void *data,
- struct event_key *key)
+static bool ioport_event_begin(struct perf_evsel *evsel,
+ struct perf_sample *sample,
+ struct event_key *key)
{
- if (!strcmp(event->name, "kvm_pio")) {
- ioport_event_get_key(event, data, key);
+ if (!strcmp(evsel->name, "kvm:kvm_pio")) {
+ ioport_event_get_key(evsel, sample, key);
return true;
}
return false;
}
-static bool ioport_event_end(struct event_format *event, void *data __maybe_unused,
+static bool ioport_event_end(struct perf_evsel *evsel,
+ struct perf_sample *sample __maybe_unused,
struct event_key *key __maybe_unused)
{
- if (kvm_entry_event(event))
- return true;
-
- return false;
+ return kvm_entry_event(evsel);
}
static void ioport_event_decode_key(struct event_key *key, char decode[20])
@@ -430,41 +433,43 @@ static bool handle_end_event(struct vcpu_event_record *vcpu_record,
return update_kvm_event(event, vcpu_record->vcpu_id, time_diff);
}
-static struct vcpu_event_record
-*per_vcpu_record(struct thread *thread, struct event_format *event, void *data)
+static
+struct vcpu_event_record *per_vcpu_record(struct thread *thread,
+ struct perf_evsel *evsel,
+ struct perf_sample *sample)
{
/* Only kvm_entry records vcpu id. */
- if (!thread->priv && kvm_entry_event(event)) {
+ if (!thread->priv && kvm_entry_event(evsel)) {
struct vcpu_event_record *vcpu_record;
- vcpu_record = zalloc(sizeof(struct vcpu_event_record));
+ vcpu_record = zalloc(sizeof(*vcpu_record));
if (!vcpu_record) {
- pr_err("Not enough memory\n");
+ pr_err("%s: Not enough memory\n", __func__);
return NULL;
}
- vcpu_record->vcpu_id = raw_field_value(event, "vcpu_id", data);
+ vcpu_record->vcpu_id = perf_evsel__intval(evsel, sample, "vcpu_id");
thread->priv = vcpu_record;
}
- return (struct vcpu_event_record *)thread->priv;
+ return thread->priv;
}
-static bool handle_kvm_event(struct thread *thread, struct event_format *event,
- void *data, u64 timestamp)
+static bool handle_kvm_event(struct thread *thread, struct perf_evsel *evsel,
+ struct perf_sample *sample)
{
struct vcpu_event_record *vcpu_record;
struct event_key key = {.key = INVALID_KEY};
- vcpu_record = per_vcpu_record(thread, event, data);
+ vcpu_record = per_vcpu_record(thread, evsel, sample);
if (!vcpu_record)
return true;
- if (events_ops->is_begin_event(event, data, &key))
- return handle_begin_event(vcpu_record, &key, timestamp);
+ if (events_ops->is_begin_event(evsel, sample, &key))
+ return handle_begin_event(vcpu_record, &key, sample->time);
- if (events_ops->is_end_event(event, data, &key))
- return handle_end_event(vcpu_record, &key, timestamp);
+ if (events_ops->is_end_event(evsel, sample, &key))
+ return handle_end_event(vcpu_record, &key, sample->time);
return true;
}
@@ -645,8 +650,7 @@ static int process_sample_event(struct perf_tool *tool __maybe_unused,
return -1;
}
- if (!handle_kvm_event(thread, evsel->tp_format, sample->raw_data,
- sample->time))
+ if (!handle_kvm_event(thread, evsel, sample))
return -1;
return 0;
--
1.7.1
^ permalink raw reply related [flat|nested] 41+ messages in thread
* [PATCH 08/30] perf kmem: Use perf_evsel__intval and perf_session__set_tracepoints_handlers
2012-09-24 15:59 [GIT PULL 00/30] perf/core improvements and fixes Arnaldo Carvalho de Melo
` (6 preceding siblings ...)
2012-09-24 15:59 ` [PATCH 07/30] perf kvm: Use perf_evsel__intval Arnaldo Carvalho de Melo
@ 2012-09-24 15:59 ` Arnaldo Carvalho de Melo
2012-09-24 15:59 ` [PATCH 09/30] perf lock: " Arnaldo Carvalho de Melo
` (21 subsequent siblings)
29 siblings, 0 replies; 41+ messages in thread
From: Arnaldo Carvalho de Melo @ 2012-09-24 15:59 UTC (permalink / raw)
To: Ingo Molnar
Cc: linux-kernel, Arnaldo Carvalho de Melo, David Ahern,
Frederic Weisbecker, Jiri Olsa, Mike Galbraith, Namhyung Kim,
Paul Mackerras, Peter Zijlstra, Stephane Eranian
From: Arnaldo Carvalho de Melo <acme@redhat.com>
Following the model of 'perf sched':
. raw_field_value searches first on the common fields, that are unused
in this tool
. Using perf_session__set_tracepoints_handlers will save all those
strcmp to find the right handler at sample processing time, do it just
once and get the handler from evsel->handler.func.
Cc: David Ahern <dsahern@gmail.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Namhyung Kim <namhyung@gmail.com>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Link: http://lkml.kernel.org/n/tip-v9x3q9rv4caxtox7wtjpchq5@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
tools/perf/builtin-kmem.c | 90 ++++++++++++++++++++++----------------------
1 files changed, 45 insertions(+), 45 deletions(-)
diff --git a/tools/perf/builtin-kmem.c b/tools/perf/builtin-kmem.c
index f5f8a6b..bc912c6 100644
--- a/tools/perf/builtin-kmem.c
+++ b/tools/perf/builtin-kmem.c
@@ -1,6 +1,7 @@
#include "builtin.h"
#include "perf.h"
+#include "util/evlist.h"
#include "util/evsel.h"
#include "util/util.h"
#include "util/cache.h"
@@ -212,36 +213,38 @@ static int insert_caller_stat(unsigned long call_site,
}
static int perf_evsel__process_alloc_event(struct perf_evsel *evsel,
- struct perf_sample *sample, int node)
+ struct perf_sample *sample)
{
- struct event_format *event = evsel->tp_format;
- void *data = sample->raw_data;
- unsigned long call_site;
- unsigned long ptr;
- int bytes_req, cpu = sample->cpu;
- int bytes_alloc;
- int node1, node2;
-
- ptr = raw_field_value(event, "ptr", data);
- call_site = raw_field_value(event, "call_site", data);
- bytes_req = raw_field_value(event, "bytes_req", data);
- bytes_alloc = raw_field_value(event, "bytes_alloc", data);
-
- if (insert_alloc_stat(call_site, ptr, bytes_req, bytes_alloc, cpu) ||
+ unsigned long ptr = perf_evsel__intval(evsel, sample, "ptr"),
+ call_site = perf_evsel__intval(evsel, sample, "call_site");
+ int bytes_req = perf_evsel__intval(evsel, sample, "bytes_req"),
+ bytes_alloc = perf_evsel__intval(evsel, sample, "bytes_alloc");
+
+ if (insert_alloc_stat(call_site, ptr, bytes_req, bytes_alloc, sample->cpu) ||
insert_caller_stat(call_site, bytes_req, bytes_alloc))
return -1;
total_requested += bytes_req;
total_allocated += bytes_alloc;
- if (node) {
- node1 = cpunode_map[cpu];
- node2 = raw_field_value(event, "node", data);
+ nr_allocs++;
+ return 0;
+}
+
+static int perf_evsel__process_alloc_node_event(struct perf_evsel *evsel,
+ struct perf_sample *sample)
+{
+ int ret = perf_evsel__process_alloc_event(evsel, sample);
+
+ if (!ret) {
+ int node1 = cpunode_map[sample->cpu],
+ node2 = perf_evsel__intval(evsel, sample, "node");
+
if (node1 != node2)
nr_cross_allocs++;
}
- nr_allocs++;
- return 0;
+
+ return ret;
}
static int ptr_cmp(struct alloc_stat *, struct alloc_stat *);
@@ -275,8 +278,7 @@ static struct alloc_stat *search_alloc_stat(unsigned long ptr,
static int perf_evsel__process_free_event(struct perf_evsel *evsel,
struct perf_sample *sample)
{
- unsigned long ptr = raw_field_value(evsel->tp_format, "ptr",
- sample->raw_data);
+ unsigned long ptr = perf_evsel__intval(evsel, sample, "ptr");
struct alloc_stat *s_alloc, *s_caller;
s_alloc = search_alloc_stat(ptr, 0, &root_alloc_stat, ptr_cmp);
@@ -297,28 +299,8 @@ static int perf_evsel__process_free_event(struct perf_evsel *evsel,
return 0;
}
-static int perf_evsel__process_kmem_event(struct perf_evsel *evsel,
- struct perf_sample *sample)
-{
- struct event_format *event = evsel->tp_format;
-
- if (!strcmp(event->name, "kmalloc") ||
- !strcmp(event->name, "kmem_cache_alloc")) {
- return perf_evsel__process_alloc_event(evsel, sample, 0);
- }
-
- if (!strcmp(event->name, "kmalloc_node") ||
- !strcmp(event->name, "kmem_cache_alloc_node")) {
- return perf_evsel__process_alloc_event(evsel, sample, 1);
- }
-
- if (!strcmp(event->name, "kfree") ||
- !strcmp(event->name, "kmem_cache_free")) {
- return perf_evsel__process_free_event(evsel, sample);
- }
-
- return 0;
-}
+typedef int (*tracepoint_handler)(struct perf_evsel *evsel,
+ struct perf_sample *sample);
static int process_sample_event(struct perf_tool *tool __maybe_unused,
union perf_event *event,
@@ -336,7 +318,12 @@ static int process_sample_event(struct perf_tool *tool __maybe_unused,
dump_printf(" ... thread: %s:%d\n", thread->comm, thread->pid);
- return perf_evsel__process_kmem_event(evsel, sample);
+ if (evsel->handler.func != NULL) {
+ tracepoint_handler f = evsel->handler.func;
+ return f(evsel, sample);
+ }
+
+ return 0;
}
static struct perf_tool perf_kmem = {
@@ -498,6 +485,14 @@ static int __cmd_kmem(void)
{
int err = -EINVAL;
struct perf_session *session;
+ const struct perf_evsel_str_handler kmem_tracepoints[] = {
+ { "kmem:kmalloc", perf_evsel__process_alloc_event, },
+ { "kmem:kmem_cache_alloc", perf_evsel__process_alloc_event, },
+ { "kmem:kmalloc_node", perf_evsel__process_alloc_node_event, },
+ { "kmem:kmem_cache_alloc_node", perf_evsel__process_alloc_node_event, },
+ { "kmem:kfree", perf_evsel__process_free_event, },
+ { "kmem:kmem_cache_free", perf_evsel__process_free_event, },
+ };
session = perf_session__new(input_name, O_RDONLY, 0, false, &perf_kmem);
if (session == NULL)
@@ -509,6 +504,11 @@ static int __cmd_kmem(void)
if (!perf_session__has_traces(session, "kmem record"))
goto out_delete;
+ if (perf_session__set_tracepoints_handlers(session, kmem_tracepoints)) {
+ pr_err("Initializing perf session tracepoint handlers failed\n");
+ return -1;
+ }
+
setup_pager();
err = perf_session__process_events(session, &perf_kmem);
if (err != 0)
--
1.7.1
^ permalink raw reply related [flat|nested] 41+ messages in thread
* [PATCH 09/30] perf lock: Use perf_evsel__intval and perf_session__set_tracepoints_handlers
2012-09-24 15:59 [GIT PULL 00/30] perf/core improvements and fixes Arnaldo Carvalho de Melo
` (7 preceding siblings ...)
2012-09-24 15:59 ` [PATCH 08/30] perf kmem: Use perf_evsel__intval and perf_session__set_tracepoints_handlers Arnaldo Carvalho de Melo
@ 2012-09-24 15:59 ` Arnaldo Carvalho de Melo
2012-09-24 15:59 ` [PATCH 10/30] perf timechart: Use zalloc and fix a couple leaks Arnaldo Carvalho de Melo
` (20 subsequent siblings)
29 siblings, 0 replies; 41+ messages in thread
From: Arnaldo Carvalho de Melo @ 2012-09-24 15:59 UTC (permalink / raw)
To: Ingo Molnar
Cc: linux-kernel, Arnaldo Carvalho de Melo, David Ahern,
Frederic Weisbecker, Jiri Olsa, Mike Galbraith, Namhyung Kim,
Paul Mackerras, Peter Zijlstra, Stephane Eranian
From: Arnaldo Carvalho de Melo <acme@redhat.com>
Following the model of 'perf sched':
. raw_field_value searches first on the common fields, that are unused
in this tool
. Leave using perf_evsel__intval to the actual handlers, some may not
need to incur some of the cost because they may not need all the
fields values.
. Using perf_session__set_tracepoints_handlers will save all those
strcmp to find the right handler at sample processing time, do it just
once and get the handler from evsel->handler.func.
Cc: David Ahern <dsahern@gmail.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Namhyung Kim <namhyung@gmail.com>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Link: http://lkml.kernel.org/n/tip-v9x3q9rv4caxtox7wtjpchq5@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
tools/perf/builtin-lock.c | 233 +++++++++++++++++----------------------------
1 files changed, 87 insertions(+), 146 deletions(-)
diff --git a/tools/perf/builtin-lock.c b/tools/perf/builtin-lock.c
index a803520..7d6e099 100644
--- a/tools/perf/builtin-lock.c
+++ b/tools/perf/builtin-lock.c
@@ -1,6 +1,7 @@
#include "builtin.h"
#include "perf.h"
+#include "util/evlist.h"
#include "util/evsel.h"
#include "util/util.h"
#include "util/cache.h"
@@ -41,7 +42,7 @@ struct lock_stat {
struct rb_node rb; /* used for sorting */
/*
- * FIXME: raw_field_value() returns unsigned long long,
+ * FIXME: perf_evsel__intval() returns u64,
* so address of lockdep_map should be dealed as 64bit.
* Is there more better solution?
*/
@@ -336,44 +337,18 @@ alloc_failed:
static const char *input_name;
-struct raw_event_sample {
- u32 size;
- char data[0];
-};
-
-struct trace_acquire_event {
- void *addr;
- const char *name;
- int flag;
-};
-
-struct trace_acquired_event {
- void *addr;
- const char *name;
-};
-
-struct trace_contended_event {
- void *addr;
- const char *name;
-};
-
-struct trace_release_event {
- void *addr;
- const char *name;
-};
-
struct trace_lock_handler {
- int (*acquire_event)(struct trace_acquire_event *,
- const struct perf_sample *sample);
+ int (*acquire_event)(struct perf_evsel *evsel,
+ struct perf_sample *sample);
- int (*acquired_event)(struct trace_acquired_event *,
- const struct perf_sample *sample);
+ int (*acquired_event)(struct perf_evsel *evsel,
+ struct perf_sample *sample);
- int (*contended_event)(struct trace_contended_event *,
- const struct perf_sample *sample);
+ int (*contended_event)(struct perf_evsel *evsel,
+ struct perf_sample *sample);
- int (*release_event)(struct trace_release_event *,
- const struct perf_sample *sample);
+ int (*release_event)(struct perf_evsel *evsel,
+ struct perf_sample *sample);
};
static struct lock_seq_stat *get_seq(struct thread_stat *ts, void *addr)
@@ -412,15 +387,20 @@ enum acquire_flags {
READ_LOCK = 2,
};
-static int
-report_lock_acquire_event(struct trace_acquire_event *acquire_event,
- const struct perf_sample *sample)
+static int report_lock_acquire_event(struct perf_evsel *evsel,
+ struct perf_sample *sample)
{
+ void *addr;
struct lock_stat *ls;
struct thread_stat *ts;
struct lock_seq_stat *seq;
+ const char *name = perf_evsel__strval(evsel, sample, "name");
+ u64 tmp = perf_evsel__intval(evsel, sample, "lockdep_addr");
+ int flag = perf_evsel__intval(evsel, sample, "flag");
- ls = lock_stat_findnew(acquire_event->addr, acquire_event->name);
+ memcpy(&addr, &tmp, sizeof(void *));
+
+ ls = lock_stat_findnew(addr, name);
if (!ls)
return -1;
if (ls->discard)
@@ -430,19 +410,19 @@ report_lock_acquire_event(struct trace_acquire_event *acquire_event,
if (!ts)
return -1;
- seq = get_seq(ts, acquire_event->addr);
+ seq = get_seq(ts, addr);
if (!seq)
return -1;
switch (seq->state) {
case SEQ_STATE_UNINITIALIZED:
case SEQ_STATE_RELEASED:
- if (!acquire_event->flag) {
+ if (!flag) {
seq->state = SEQ_STATE_ACQUIRING;
} else {
- if (acquire_event->flag & TRY_LOCK)
+ if (flag & TRY_LOCK)
ls->nr_trylock++;
- if (acquire_event->flag & READ_LOCK)
+ if (flag & READ_LOCK)
ls->nr_readlock++;
seq->state = SEQ_STATE_READ_ACQUIRED;
seq->read_count = 1;
@@ -450,7 +430,7 @@ report_lock_acquire_event(struct trace_acquire_event *acquire_event,
}
break;
case SEQ_STATE_READ_ACQUIRED:
- if (acquire_event->flag & READ_LOCK) {
+ if (flag & READ_LOCK) {
seq->read_count++;
ls->nr_acquired++;
goto end;
@@ -480,17 +460,20 @@ end:
return 0;
}
-static int
-report_lock_acquired_event(struct trace_acquired_event *acquired_event,
- const struct perf_sample *sample)
+static int report_lock_acquired_event(struct perf_evsel *evsel,
+ struct perf_sample *sample)
{
- u64 timestamp = sample->time;
+ void *addr;
struct lock_stat *ls;
struct thread_stat *ts;
struct lock_seq_stat *seq;
u64 contended_term;
+ const char *name = perf_evsel__strval(evsel, sample, "name");
+ u64 tmp = perf_evsel__intval(evsel, sample, "lockdep_addr");
+
+ memcpy(&addr, &tmp, sizeof(void *));
- ls = lock_stat_findnew(acquired_event->addr, acquired_event->name);
+ ls = lock_stat_findnew(addr, name);
if (!ls)
return -1;
if (ls->discard)
@@ -500,7 +483,7 @@ report_lock_acquired_event(struct trace_acquired_event *acquired_event,
if (!ts)
return -1;
- seq = get_seq(ts, acquired_event->addr);
+ seq = get_seq(ts, addr);
if (!seq)
return -1;
@@ -511,7 +494,7 @@ report_lock_acquired_event(struct trace_acquired_event *acquired_event,
case SEQ_STATE_ACQUIRING:
break;
case SEQ_STATE_CONTENDED:
- contended_term = timestamp - seq->prev_event_time;
+ contended_term = sample->time - seq->prev_event_time;
ls->wait_time_total += contended_term;
if (contended_term < ls->wait_time_min)
ls->wait_time_min = contended_term;
@@ -536,20 +519,24 @@ report_lock_acquired_event(struct trace_acquired_event *acquired_event,
seq->state = SEQ_STATE_ACQUIRED;
ls->nr_acquired++;
- seq->prev_event_time = timestamp;
+ seq->prev_event_time = sample->time;
end:
return 0;
}
-static int
-report_lock_contended_event(struct trace_contended_event *contended_event,
- const struct perf_sample *sample)
+static int report_lock_contended_event(struct perf_evsel *evsel,
+ struct perf_sample *sample)
{
+ void *addr;
struct lock_stat *ls;
struct thread_stat *ts;
struct lock_seq_stat *seq;
+ const char *name = perf_evsel__strval(evsel, sample, "name");
+ u64 tmp = perf_evsel__intval(evsel, sample, "lockdep_addr");
+
+ memcpy(&addr, &tmp, sizeof(void *));
- ls = lock_stat_findnew(contended_event->addr, contended_event->name);
+ ls = lock_stat_findnew(addr, name);
if (!ls)
return -1;
if (ls->discard)
@@ -559,7 +546,7 @@ report_lock_contended_event(struct trace_contended_event *contended_event,
if (!ts)
return -1;
- seq = get_seq(ts, contended_event->addr);
+ seq = get_seq(ts, addr);
if (!seq)
return -1;
@@ -592,15 +579,19 @@ end:
return 0;
}
-static int
-report_lock_release_event(struct trace_release_event *release_event,
- const struct perf_sample *sample)
+static int report_lock_release_event(struct perf_evsel *evsel,
+ struct perf_sample *sample)
{
+ void *addr;
struct lock_stat *ls;
struct thread_stat *ts;
struct lock_seq_stat *seq;
+ const char *name = perf_evsel__strval(evsel, sample, "name");
+ u64 tmp = perf_evsel__intval(evsel, sample, "lockdep_addr");
- ls = lock_stat_findnew(release_event->addr, release_event->name);
+ memcpy(&addr, &tmp, sizeof(void *));
+
+ ls = lock_stat_findnew(addr, name);
if (!ls)
return -1;
if (ls->discard)
@@ -610,7 +601,7 @@ report_lock_release_event(struct trace_release_event *release_event,
if (!ts)
return -1;
- seq = get_seq(ts, release_event->addr);
+ seq = get_seq(ts, addr);
if (!seq)
return -1;
@@ -663,96 +654,33 @@ static struct trace_lock_handler *trace_handler;
static int perf_evsel__process_lock_acquire(struct perf_evsel *evsel,
struct perf_sample *sample)
{
- struct trace_acquire_event acquire_event;
- struct event_format *event = evsel->tp_format;
- void *data = sample->raw_data;
- u64 tmp; /* this is required for casting... */
- int rc = 0;
-
- tmp = raw_field_value(event, "lockdep_addr", data);
- memcpy(&acquire_event.addr, &tmp, sizeof(void *));
- acquire_event.name = (char *)raw_field_ptr(event, "name", data);
- acquire_event.flag = (int)raw_field_value(event, "flag", data);
-
if (trace_handler->acquire_event)
- rc = trace_handler->acquire_event(&acquire_event, sample);
-
- return rc;
+ return trace_handler->acquire_event(evsel, sample);
+ return 0;
}
static int perf_evsel__process_lock_acquired(struct perf_evsel *evsel,
struct perf_sample *sample)
{
- struct trace_acquired_event acquired_event;
- struct event_format *event = evsel->tp_format;
- void *data = sample->raw_data;
- u64 tmp; /* this is required for casting... */
- int rc = 0;
-
- tmp = raw_field_value(event, "lockdep_addr", data);
- memcpy(&acquired_event.addr, &tmp, sizeof(void *));
- acquired_event.name = (char *)raw_field_ptr(event, "name", data);
-
if (trace_handler->acquired_event)
- rc = trace_handler->acquired_event(&acquired_event, sample);
-
- return rc;
+ return trace_handler->acquired_event(evsel, sample);
+ return 0;
}
static int perf_evsel__process_lock_contended(struct perf_evsel *evsel,
- struct perf_sample *sample)
+ struct perf_sample *sample)
{
- struct trace_contended_event contended_event;
- struct event_format *event = evsel->tp_format;
- void *data = sample->raw_data;
- u64 tmp; /* this is required for casting... */
- int rc = 0;
-
- tmp = raw_field_value(event, "lockdep_addr", data);
- memcpy(&contended_event.addr, &tmp, sizeof(void *));
- contended_event.name = (char *)raw_field_ptr(event, "name", data);
-
if (trace_handler->contended_event)
- rc = trace_handler->contended_event(&contended_event, sample);
-
- return rc;
+ return trace_handler->contended_event(evsel, sample);
+ return 0;
}
static int perf_evsel__process_lock_release(struct perf_evsel *evsel,
- struct perf_sample *sample)
+ struct perf_sample *sample)
{
- struct trace_release_event release_event;
- struct event_format *event = evsel->tp_format;
- void *data = sample->raw_data;
- u64 tmp; /* this is required for casting... */
- int rc = 0;
-
- tmp = raw_field_value(event, "lockdep_addr", data);
- memcpy(&release_event.addr, &tmp, sizeof(void *));
- release_event.name = (char *)raw_field_ptr(event, "name", data);
-
if (trace_handler->release_event)
- rc = trace_handler->release_event(&release_event, sample);
-
- return rc;
-}
-
-static int perf_evsel__process_lock_event(struct perf_evsel *evsel,
- struct perf_sample *sample)
-{
- struct event_format *event = evsel->tp_format;
- int rc = 0;
-
- if (!strcmp(event->name, "lock_acquire"))
- rc = perf_evsel__process_lock_acquire(evsel, sample);
- if (!strcmp(event->name, "lock_acquired"))
- rc = perf_evsel__process_lock_acquired(evsel, sample);
- if (!strcmp(event->name, "lock_contended"))
- rc = perf_evsel__process_lock_contended(evsel, sample);
- if (!strcmp(event->name, "lock_release"))
- rc = perf_evsel__process_lock_release(evsel, sample);
-
- return rc;
+ return trace_handler->release_event(evsel, sample);
+ return 0;
}
static void print_bad_events(int bad, int total)
@@ -870,6 +798,9 @@ static int dump_info(void)
return rc;
}
+typedef int (*tracepoint_handler)(struct perf_evsel *evsel,
+ struct perf_sample *sample);
+
static int process_sample_event(struct perf_tool *tool __maybe_unused,
union perf_event *event,
struct perf_sample *sample,
@@ -884,7 +815,12 @@ static int process_sample_event(struct perf_tool *tool __maybe_unused,
return -1;
}
- return perf_evsel__process_lock_event(evsel, sample);
+ if (evsel->handler.func != NULL) {
+ tracepoint_handler f = evsel->handler.func;
+ return f(evsel, sample);
+ }
+
+ return 0;
}
static struct perf_tool eops = {
@@ -893,6 +829,13 @@ static struct perf_tool eops = {
.ordered_samples = true,
};
+static const struct perf_evsel_str_handler lock_tracepoints[] = {
+ { "lock:lock_acquire", perf_evsel__process_lock_acquire, }, /* CONFIG_LOCKDEP */
+ { "lock:lock_acquired", perf_evsel__process_lock_acquired, }, /* CONFIG_LOCKDEP, CONFIG_LOCK_STAT */
+ { "lock:lock_contended", perf_evsel__process_lock_contended, }, /* CONFIG_LOCKDEP, CONFIG_LOCK_STAT */
+ { "lock:lock_release", perf_evsel__process_lock_release, }, /* CONFIG_LOCKDEP */
+};
+
static int read_events(void)
{
session = perf_session__new(input_name, O_RDONLY, 0, false, &eops);
@@ -901,6 +844,11 @@ static int read_events(void)
return -1;
}
+ if (perf_session__set_tracepoints_handlers(session, lock_tracepoints)) {
+ pr_err("Initializing perf session tracepoint handlers failed\n");
+ return -1;
+ }
+
return perf_session__process_events(session, &eops);
}
@@ -967,13 +915,6 @@ static const struct option lock_options[] = {
OPT_END()
};
-static const char * const lock_tracepoints[] = {
- "lock:lock_acquire", /* CONFIG_LOCKDEP */
- "lock:lock_acquired", /* CONFIG_LOCKDEP, CONFIG_LOCK_STAT */
- "lock:lock_contended", /* CONFIG_LOCKDEP, CONFIG_LOCK_STAT */
- "lock:lock_release", /* CONFIG_LOCKDEP */
-};
-
static const char *record_args[] = {
"record",
"-R",
@@ -988,10 +929,10 @@ static int __cmd_record(int argc, const char **argv)
const char **rec_argv;
for (i = 0; i < ARRAY_SIZE(lock_tracepoints); i++) {
- if (!is_valid_tracepoint(lock_tracepoints[i])) {
+ if (!is_valid_tracepoint(lock_tracepoints[i].name)) {
pr_err("tracepoint %s is not enabled. "
"Are CONFIG_LOCKDEP and CONFIG_LOCK_STAT enabled?\n",
- lock_tracepoints[i]);
+ lock_tracepoints[i].name);
return 1;
}
}
@@ -1009,7 +950,7 @@ static int __cmd_record(int argc, const char **argv)
for (j = 0; j < ARRAY_SIZE(lock_tracepoints); j++) {
rec_argv[i++] = "-e";
- rec_argv[i++] = strdup(lock_tracepoints[j]);
+ rec_argv[i++] = strdup(lock_tracepoints[j].name);
}
for (j = 1; j < (unsigned int)argc; j++, i++)
--
1.7.1
^ permalink raw reply related [flat|nested] 41+ messages in thread
* [PATCH 10/30] perf timechart: Use zalloc and fix a couple leaks
2012-09-24 15:59 [GIT PULL 00/30] perf/core improvements and fixes Arnaldo Carvalho de Melo
` (8 preceding siblings ...)
2012-09-24 15:59 ` [PATCH 09/30] perf lock: " Arnaldo Carvalho de Melo
@ 2012-09-24 15:59 ` Arnaldo Carvalho de Melo
2012-09-24 15:59 ` [PATCH 11/30] perf header: Add struct perf_session_env Arnaldo Carvalho de Melo
` (19 subsequent siblings)
29 siblings, 0 replies; 41+ messages in thread
From: Arnaldo Carvalho de Melo @ 2012-09-24 15:59 UTC (permalink / raw)
To: Ingo Molnar
Cc: linux-kernel, Arnaldo Carvalho de Melo, Arjan van de Ven,
David Ahern, Frederic Weisbecker, Jiri Olsa, Mike Galbraith,
Namhyung Kim, Paul Mackerras, Peter Zijlstra, Stephane Eranian
From: Arnaldo Carvalho de Melo <acme@redhat.com>
Use zalloc for the malloc+memset open coded sequence.
Fix leak on the #ifdef'ed C state handling and when detecting invalid
data in p_state_change().
Cc: Arjan van de Ven <arjan@linux.intel.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Namhyung Kim <namhyung@gmail.com>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Link: http://lkml.kernel.org/n/tip-v9x3q9rv4caxtox7wtjpchq5@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
tools/perf/builtin-timechart.c | 40 ++++++++++++++--------------------------
1 files changed, 14 insertions(+), 26 deletions(-)
diff --git a/tools/perf/builtin-timechart.c b/tools/perf/builtin-timechart.c
index 55a3a6c..b1a8a3b 100644
--- a/tools/perf/builtin-timechart.c
+++ b/tools/perf/builtin-timechart.c
@@ -168,9 +168,8 @@ static struct per_pid *find_create_pid(int pid)
return cursor;
cursor = cursor->next;
}
- cursor = malloc(sizeof(struct per_pid));
+ cursor = zalloc(sizeof(*cursor));
assert(cursor != NULL);
- memset(cursor, 0, sizeof(struct per_pid));
cursor->pid = pid;
cursor->next = all_data;
all_data = cursor;
@@ -195,9 +194,8 @@ static void pid_set_comm(int pid, char *comm)
}
c = c->next;
}
- c = malloc(sizeof(struct per_pidcomm));
+ c = zalloc(sizeof(*c));
assert(c != NULL);
- memset(c, 0, sizeof(struct per_pidcomm));
c->comm = strdup(comm);
p->current = c;
c->next = p->all;
@@ -239,17 +237,15 @@ pid_put_sample(int pid, int type, unsigned int cpu, u64 start, u64 end)
p = find_create_pid(pid);
c = p->current;
if (!c) {
- c = malloc(sizeof(struct per_pidcomm));
+ c = zalloc(sizeof(*c));
assert(c != NULL);
- memset(c, 0, sizeof(struct per_pidcomm));
p->current = c;
c->next = p->all;
p->all = c;
}
- sample = malloc(sizeof(struct cpu_sample));
+ sample = zalloc(sizeof(*sample));
assert(sample != NULL);
- memset(sample, 0, sizeof(struct cpu_sample));
sample->start_time = start;
sample->end_time = end;
sample->type = type;
@@ -373,11 +369,10 @@ static void c_state_start(int cpu, u64 timestamp, int state)
static void c_state_end(int cpu, u64 timestamp)
{
- struct power_event *pwr;
- pwr = malloc(sizeof(struct power_event));
+ struct power_event *pwr = zalloc(sizeof(*pwr));
+
if (!pwr)
return;
- memset(pwr, 0, sizeof(struct power_event));
pwr->state = cpus_cstate_state[cpu];
pwr->start_time = cpus_cstate_start_times[cpu];
@@ -392,14 +387,13 @@ static void c_state_end(int cpu, u64 timestamp)
static void p_state_change(int cpu, u64 timestamp, u64 new_freq)
{
struct power_event *pwr;
- pwr = malloc(sizeof(struct power_event));
if (new_freq > 8000000) /* detect invalid data */
return;
+ pwr = zalloc(sizeof(*pwr));
if (!pwr)
return;
- memset(pwr, 0, sizeof(struct power_event));
pwr->state = cpus_pstate_state[cpu];
pwr->start_time = cpus_pstate_start_times[cpu];
@@ -429,15 +423,13 @@ static void p_state_change(int cpu, u64 timestamp, u64 new_freq)
static void
sched_wakeup(int cpu, u64 timestamp, int pid, struct trace_entry *te)
{
- struct wake_event *we;
struct per_pid *p;
struct wakeup_entry *wake = (void *)te;
+ struct wake_event *we = zalloc(sizeof(*we));
- we = malloc(sizeof(struct wake_event));
if (!we)
return;
- memset(we, 0, sizeof(struct wake_event));
we->time = timestamp;
we->waker = pid;
@@ -579,13 +571,12 @@ static void end_sample_processing(void)
struct power_event *pwr;
for (cpu = 0; cpu <= numcpus; cpu++) {
- pwr = malloc(sizeof(struct power_event));
+ /* C state */
+#if 0
+ pwr = zalloc(sizeof(*pwr));
if (!pwr)
return;
- memset(pwr, 0, sizeof(struct power_event));
- /* C state */
-#if 0
pwr->state = cpus_cstate_state[cpu];
pwr->start_time = cpus_cstate_start_times[cpu];
pwr->end_time = last_time;
@@ -597,10 +588,9 @@ static void end_sample_processing(void)
#endif
/* P state */
- pwr = malloc(sizeof(struct power_event));
+ pwr = zalloc(sizeof(*pwr));
if (!pwr)
return;
- memset(pwr, 0, sizeof(struct power_event));
pwr->state = cpus_pstate_state[cpu];
pwr->start_time = cpus_pstate_start_times[cpu];
@@ -830,11 +820,9 @@ static void draw_process_bars(void)
static void add_process_filter(const char *string)
{
- struct process_filter *filt;
- int pid;
+ int pid = strtoull(string, NULL, 10);
+ struct process_filter *filt = malloc(sizeof(*filt));
- pid = strtoull(string, NULL, 10);
- filt = malloc(sizeof(struct process_filter));
if (!filt)
return;
--
1.7.1
^ permalink raw reply related [flat|nested] 41+ messages in thread
* [PATCH 11/30] perf header: Add struct perf_session_env
2012-09-24 15:59 [GIT PULL 00/30] perf/core improvements and fixes Arnaldo Carvalho de Melo
` (9 preceding siblings ...)
2012-09-24 15:59 ` [PATCH 10/30] perf timechart: Use zalloc and fix a couple leaks Arnaldo Carvalho de Melo
@ 2012-09-24 15:59 ` Arnaldo Carvalho de Melo
2012-09-24 15:59 ` [PATCH 12/30] perf header: Add ->process callbacks to most of features Arnaldo Carvalho de Melo
` (18 subsequent siblings)
29 siblings, 0 replies; 41+ messages in thread
From: Arnaldo Carvalho de Melo @ 2012-09-24 15:59 UTC (permalink / raw)
To: Ingo Molnar
Cc: linux-kernel, Namhyung Kim, Namhyung Kim, David Ahern,
Paul Mackerras, Peter Zijlstra, Stephane Eranian,
Arnaldo Carvalho de Melo
From: Namhyung Kim <namhyung.kim@lge.com>
The struct perf_session_env will preserve environment information at the
time of perf record. It can be accessed anytime after parsing a
perf.data file if needed.
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
Cc: David Ahern <dsahern@gmail.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Stephane Eranian <eranian@google.com>
Link: http://lkml.kernel.org/r/1348474503-15070-2-git-send-email-namhyung@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
| 24 ++++++++++++++++++++++++
1 files changed, 24 insertions(+), 0 deletions(-)
--git a/tools/perf/util/header.h b/tools/perf/util/header.h
index 58de08b..5867c7d 100644
--- a/tools/perf/util/header.h
+++ b/tools/perf/util/header.h
@@ -58,6 +58,29 @@ struct perf_header;
int perf_file_header__read(struct perf_file_header *header,
struct perf_header *ph, int fd);
+struct perf_session_env {
+ char *hostname;
+ char *os_release;
+ char *version;
+ char *arch;
+ int nr_cpus_online;
+ int nr_cpus_avail;
+ char *cpu_desc;
+ char *cpuid;
+ unsigned long long total_mem;
+
+ int nr_cmdline;
+ char *cmdline;
+ int nr_sibling_cores;
+ char *sibling_cores;
+ int nr_sibling_threads;
+ char *sibling_threads;
+ int nr_numa_nodes;
+ char *numa_nodes;
+ int nr_pmu_mappings;
+ char *pmu_mappings;
+};
+
struct perf_header {
int frozen;
bool needs_swap;
@@ -67,6 +90,7 @@ struct perf_header {
u64 event_offset;
u64 event_size;
DECLARE_BITMAP(adds_features, HEADER_FEAT_BITS);
+ struct perf_session_env env;
};
struct perf_evlist;
--
1.7.1
^ permalink raw reply related [flat|nested] 41+ messages in thread
* [PATCH 12/30] perf header: Add ->process callbacks to most of features
2012-09-24 15:59 [GIT PULL 00/30] perf/core improvements and fixes Arnaldo Carvalho de Melo
` (10 preceding siblings ...)
2012-09-24 15:59 ` [PATCH 11/30] perf header: Add struct perf_session_env Arnaldo Carvalho de Melo
@ 2012-09-24 15:59 ` Arnaldo Carvalho de Melo
2012-09-24 15:59 ` [PATCH 13/30] perf header: Use pre-processed session env when printing Arnaldo Carvalho de Melo
` (17 subsequent siblings)
29 siblings, 0 replies; 41+ messages in thread
From: Arnaldo Carvalho de Melo @ 2012-09-24 15:59 UTC (permalink / raw)
To: Ingo Molnar
Cc: linux-kernel, Namhyung Kim, David Ahern, Paul Mackerras,
Peter Zijlstra, Robert Richter, Stephane Eranian,
Arnaldo Carvalho de Melo
From: Namhyung Kim <namhyung@kernel.org>
>From now on each feature information is processed and saved in perf
header so that it can be used wherever needed. The BRANCH_STACK feature
is an exception since it needs nothing to be done.
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
Cc: David Ahern <dsahern@gmail.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Robert Richter <robert.richter@amd.com>
Cc: Stephane Eranian <eranian@google.com>
Link: http://lkml.kernel.org/r/1348474503-15070-3-git-send-email-namhyung@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
| 319 ++++++++++++++++++++++++++++++++++++++++++++--
1 files changed, 308 insertions(+), 11 deletions(-)
--git a/tools/perf/util/header.c b/tools/perf/util/header.c
index ad72b28..d74b58d 100644
--- a/tools/perf/util/header.c
+++ b/tools/perf/util/header.c
@@ -22,6 +22,7 @@
#include "cpumap.h"
#include "pmu.h"
#include "vdso.h"
+#include "strbuf.h"
static bool no_buildid_cache = false;
@@ -1673,6 +1674,99 @@ static int process_build_id(struct perf_file_section *section,
return 0;
}
+static int process_hostname(struct perf_file_section *section __maybe_unused,
+ struct perf_header *ph, int feat __maybe_unused,
+ int fd, void *data __maybe_unused)
+{
+ ph->env.hostname = do_read_string(fd, ph);
+ return ph->env.hostname ? 0 : -ENOMEM;
+}
+
+static int process_osrelease(struct perf_file_section *section __maybe_unused,
+ struct perf_header *ph, int feat __maybe_unused,
+ int fd, void *data __maybe_unused)
+{
+ ph->env.os_release = do_read_string(fd, ph);
+ return ph->env.os_release ? 0 : -ENOMEM;
+}
+
+static int process_version(struct perf_file_section *section __maybe_unused,
+ struct perf_header *ph, int feat __maybe_unused,
+ int fd, void *data __maybe_unused)
+{
+ ph->env.version = do_read_string(fd, ph);
+ return ph->env.version ? 0 : -ENOMEM;
+}
+
+static int process_arch(struct perf_file_section *section __maybe_unused,
+ struct perf_header *ph, int feat __maybe_unused,
+ int fd, void *data __maybe_unused)
+{
+ ph->env.arch = do_read_string(fd, ph);
+ return ph->env.arch ? 0 : -ENOMEM;
+}
+
+static int process_nrcpus(struct perf_file_section *section __maybe_unused,
+ struct perf_header *ph, int feat __maybe_unused,
+ int fd, void *data __maybe_unused)
+{
+ size_t ret;
+ u32 nr;
+
+ ret = read(fd, &nr, sizeof(nr));
+ if (ret != sizeof(nr))
+ return -1;
+
+ if (ph->needs_swap)
+ nr = bswap_32(nr);
+
+ ph->env.nr_cpus_online = nr;
+
+ ret = read(fd, &nr, sizeof(nr));
+ if (ret != sizeof(nr))
+ return -1;
+
+ if (ph->needs_swap)
+ nr = bswap_32(nr);
+
+ ph->env.nr_cpus_avail = nr;
+ return 0;
+}
+
+static int process_cpudesc(struct perf_file_section *section __maybe_unused,
+ struct perf_header *ph, int feat __maybe_unused,
+ int fd, void *data __maybe_unused)
+{
+ ph->env.cpu_desc = do_read_string(fd, ph);
+ return ph->env.cpu_desc ? 0 : -ENOMEM;
+}
+
+static int process_cpuid(struct perf_file_section *section __maybe_unused,
+ struct perf_header *ph, int feat __maybe_unused,
+ int fd, void *data __maybe_unused)
+{
+ ph->env.cpuid = do_read_string(fd, ph);
+ return ph->env.cpuid ? 0 : -ENOMEM;
+}
+
+static int process_total_mem(struct perf_file_section *section __maybe_unused,
+ struct perf_header *ph, int feat __maybe_unused,
+ int fd, void *data __maybe_unused)
+{
+ uint64_t mem;
+ size_t ret;
+
+ ret = read(fd, &mem, sizeof(mem));
+ if (ret != sizeof(mem))
+ return -1;
+
+ if (ph->needs_swap)
+ mem = bswap_64(mem);
+
+ ph->env.total_mem = mem;
+ return 0;
+}
+
static char *read_cpuid(struct perf_header *ph, int fd)
{
return do_read_string(fd, ph);
@@ -1728,6 +1822,208 @@ process_event_desc(struct perf_file_section *section __maybe_unused,
return 0;
}
+static int process_cmdline(struct perf_file_section *section __maybe_unused,
+ struct perf_header *ph, int feat __maybe_unused,
+ int fd, void *data __maybe_unused)
+{
+ size_t ret;
+ char *str;
+ u32 nr, i;
+ struct strbuf sb;
+
+ ret = read(fd, &nr, sizeof(nr));
+ if (ret != sizeof(nr))
+ return -1;
+
+ if (ph->needs_swap)
+ nr = bswap_32(nr);
+
+ ph->env.nr_cmdline = nr;
+ strbuf_init(&sb, 128);
+
+ for (i = 0; i < nr; i++) {
+ str = do_read_string(fd, ph);
+ if (!str)
+ goto error;
+
+ /* include a NULL character at the end */
+ strbuf_add(&sb, str, strlen(str) + 1);
+ free(str);
+ }
+ ph->env.cmdline = strbuf_detach(&sb, NULL);
+ return 0;
+
+error:
+ strbuf_release(&sb);
+ return -1;
+}
+
+static int process_cpu_topology(struct perf_file_section *section __maybe_unused,
+ struct perf_header *ph, int feat __maybe_unused,
+ int fd, void *data __maybe_unused)
+{
+ size_t ret;
+ u32 nr, i;
+ char *str;
+ struct strbuf sb;
+
+ ret = read(fd, &nr, sizeof(nr));
+ if (ret != sizeof(nr))
+ return -1;
+
+ if (ph->needs_swap)
+ nr = bswap_32(nr);
+
+ ph->env.nr_sibling_cores = nr;
+ strbuf_init(&sb, 128);
+
+ for (i = 0; i < nr; i++) {
+ str = do_read_string(fd, ph);
+ if (!str)
+ goto error;
+
+ /* include a NULL character at the end */
+ strbuf_add(&sb, str, strlen(str) + 1);
+ free(str);
+ }
+ ph->env.sibling_cores = strbuf_detach(&sb, NULL);
+
+ ret = read(fd, &nr, sizeof(nr));
+ if (ret != sizeof(nr))
+ return -1;
+
+ if (ph->needs_swap)
+ nr = bswap_32(nr);
+
+ ph->env.nr_sibling_threads = nr;
+
+ for (i = 0; i < nr; i++) {
+ str = do_read_string(fd, ph);
+ if (!str)
+ goto error;
+
+ /* include a NULL character at the end */
+ strbuf_add(&sb, str, strlen(str) + 1);
+ free(str);
+ }
+ ph->env.sibling_threads = strbuf_detach(&sb, NULL);
+ return 0;
+
+error:
+ strbuf_release(&sb);
+ return -1;
+}
+
+static int process_numa_topology(struct perf_file_section *section __maybe_unused,
+ struct perf_header *ph, int feat __maybe_unused,
+ int fd, void *data __maybe_unused)
+{
+ size_t ret;
+ u32 nr, node, i;
+ char *str;
+ uint64_t mem_total, mem_free;
+ struct strbuf sb;
+
+ /* nr nodes */
+ ret = read(fd, &nr, sizeof(nr));
+ if (ret != sizeof(nr))
+ goto error;
+
+ if (ph->needs_swap)
+ nr = bswap_32(nr);
+
+ ph->env.nr_numa_nodes = nr;
+ strbuf_init(&sb, 256);
+
+ for (i = 0; i < nr; i++) {
+ /* node number */
+ ret = read(fd, &node, sizeof(node));
+ if (ret != sizeof(node))
+ goto error;
+
+ ret = read(fd, &mem_total, sizeof(u64));
+ if (ret != sizeof(u64))
+ goto error;
+
+ ret = read(fd, &mem_free, sizeof(u64));
+ if (ret != sizeof(u64))
+ goto error;
+
+ if (ph->needs_swap) {
+ node = bswap_32(node);
+ mem_total = bswap_64(mem_total);
+ mem_free = bswap_64(mem_free);
+ }
+
+ strbuf_addf(&sb, "%u:%"PRIu64":%"PRIu64":",
+ node, mem_total, mem_free);
+
+ str = do_read_string(fd, ph);
+ if (!str)
+ goto error;
+
+ /* include a NULL character at the end */
+ strbuf_add(&sb, str, strlen(str) + 1);
+ free(str);
+ }
+ ph->env.numa_nodes = strbuf_detach(&sb, NULL);
+ return 0;
+
+error:
+ strbuf_release(&sb);
+ return -1;
+}
+
+static int process_pmu_mappings(struct perf_file_section *section __maybe_unused,
+ struct perf_header *ph, int feat __maybe_unused,
+ int fd, void *data __maybe_unused)
+{
+ size_t ret;
+ char *name;
+ u32 pmu_num;
+ u32 type;
+ struct strbuf sb;
+
+ ret = read(fd, &pmu_num, sizeof(pmu_num));
+ if (ret != sizeof(pmu_num))
+ return -1;
+
+ if (ph->needs_swap)
+ pmu_num = bswap_32(pmu_num);
+
+ if (!pmu_num) {
+ pr_debug("pmu mappings not available\n");
+ return 0;
+ }
+
+ ph->env.nr_pmu_mappings = pmu_num;
+ strbuf_init(&sb, 128);
+
+ while (pmu_num) {
+ if (read(fd, &type, sizeof(type)) != sizeof(type))
+ goto error;
+ if (ph->needs_swap)
+ type = bswap_32(type);
+
+ name = do_read_string(fd, ph);
+ if (!name)
+ goto error;
+
+ strbuf_addf(&sb, "%u:%s", type, name);
+ /* include a NULL character at the end */
+ strbuf_add(&sb, "", 1);
+
+ free(name);
+ pmu_num--;
+ }
+ ph->env.pmu_mappings = strbuf_detach(&sb, NULL);
+ return 0;
+
+error:
+ strbuf_release(&sb);
+ return -1;
+}
+
struct feature_ops {
int (*write)(int fd, struct perf_header *h, struct perf_evlist *evlist);
void (*print)(struct perf_header *h, int fd, FILE *fp);
@@ -1745,10 +2041,11 @@ struct feature_ops {
.process = process_##func }
#define FEAT_OPF(n, func) \
[n] = { .name = #n, .write = write_##func, .print = print_##func, \
- .full_only = true }
+ .process = process_##func, .full_only = true }
#define FEAT_OPA_R(n, func) \
[n] = { .name = #n, .write = write_##func, .print = print_##func, \
- .read = read_##func }
+ .read = read_##func, .process = process_##func, \
+ .full_only = true }
/* feature_ops not implemented: */
#define print_tracing_data NULL
@@ -1757,20 +2054,20 @@ struct feature_ops {
static const struct feature_ops feat_ops[HEADER_LAST_FEATURE] = {
FEAT_OPP(HEADER_TRACING_DATA, tracing_data),
FEAT_OPP(HEADER_BUILD_ID, build_id),
- FEAT_OPA(HEADER_HOSTNAME, hostname),
- FEAT_OPA(HEADER_OSRELEASE, osrelease),
- FEAT_OPA(HEADER_VERSION, version),
- FEAT_OPA(HEADER_ARCH, arch),
- FEAT_OPA(HEADER_NRCPUS, nrcpus),
- FEAT_OPA(HEADER_CPUDESC, cpudesc),
+ FEAT_OPP(HEADER_HOSTNAME, hostname),
+ FEAT_OPP(HEADER_OSRELEASE, osrelease),
+ FEAT_OPP(HEADER_VERSION, version),
+ FEAT_OPP(HEADER_ARCH, arch),
+ FEAT_OPP(HEADER_NRCPUS, nrcpus),
+ FEAT_OPP(HEADER_CPUDESC, cpudesc),
FEAT_OPA_R(HEADER_CPUID, cpuid),
- FEAT_OPA(HEADER_TOTAL_MEM, total_mem),
+ FEAT_OPP(HEADER_TOTAL_MEM, total_mem),
FEAT_OPP(HEADER_EVENT_DESC, event_desc),
- FEAT_OPA(HEADER_CMDLINE, cmdline),
+ FEAT_OPP(HEADER_CMDLINE, cmdline),
FEAT_OPF(HEADER_CPU_TOPOLOGY, cpu_topology),
FEAT_OPF(HEADER_NUMA_TOPOLOGY, numa_topology),
FEAT_OPA(HEADER_BRANCH_STACK, branch_stack),
- FEAT_OPA(HEADER_PMU_MAPPINGS, pmu_mappings),
+ FEAT_OPP(HEADER_PMU_MAPPINGS, pmu_mappings),
};
struct header_print_data {
--
1.7.1
^ permalink raw reply related [flat|nested] 41+ messages in thread
* [PATCH 13/30] perf header: Use pre-processed session env when printing
2012-09-24 15:59 [GIT PULL 00/30] perf/core improvements and fixes Arnaldo Carvalho de Melo
` (11 preceding siblings ...)
2012-09-24 15:59 ` [PATCH 12/30] perf header: Add ->process callbacks to most of features Arnaldo Carvalho de Melo
@ 2012-09-24 15:59 ` Arnaldo Carvalho de Melo
2012-09-24 15:59 ` [PATCH 14/30] perf header: Remove unused @feat arg from ->process callback Arnaldo Carvalho de Melo
` (16 subsequent siblings)
29 siblings, 0 replies; 41+ messages in thread
From: Arnaldo Carvalho de Melo @ 2012-09-24 15:59 UTC (permalink / raw)
To: Ingo Molnar
Cc: linux-kernel, Namhyung Kim, David Ahern, Paul Mackerras,
Peter Zijlstra, Robert Richter, Stephane Eranian,
Arnaldo Carvalho de Melo
From: Namhyung Kim <namhyung@kernel.org>
>From now on each feature information is processed and saved in perf
header so that it can be used for printing. The event desc and branch
stack features are not touched since they're not saved.
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
Cc: David Ahern <dsahern@gmail.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Robert Richter <robert.richter@amd.com>
Cc: Stephane Eranian <eranian@google.com>
Link: http://lkml.kernel.org/r/1348474503-15070-4-git-send-email-namhyung@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
| 207 +++++++++++++++-------------------------------
1 files changed, 66 insertions(+), 141 deletions(-)
--git a/tools/perf/util/header.c b/tools/perf/util/header.c
index d74b58d..b2929d7 100644
--- a/tools/perf/util/header.c
+++ b/tools/perf/util/header.c
@@ -1103,118 +1103,80 @@ static int write_branch_stack(int fd __maybe_unused,
return 0;
}
-static void print_hostname(struct perf_header *ph, int fd, FILE *fp)
+static void print_hostname(struct perf_header *ph, int fd __maybe_unused,
+ FILE *fp)
{
- char *str = do_read_string(fd, ph);
- fprintf(fp, "# hostname : %s\n", str);
- free(str);
+ fprintf(fp, "# hostname : %s\n", ph->env.hostname);
}
-static void print_osrelease(struct perf_header *ph, int fd, FILE *fp)
+static void print_osrelease(struct perf_header *ph, int fd __maybe_unused,
+ FILE *fp)
{
- char *str = do_read_string(fd, ph);
- fprintf(fp, "# os release : %s\n", str);
- free(str);
+ fprintf(fp, "# os release : %s\n", ph->env.os_release);
}
-static void print_arch(struct perf_header *ph, int fd, FILE *fp)
+static void print_arch(struct perf_header *ph, int fd __maybe_unused, FILE *fp)
{
- char *str = do_read_string(fd, ph);
- fprintf(fp, "# arch : %s\n", str);
- free(str);
+ fprintf(fp, "# arch : %s\n", ph->env.arch);
}
-static void print_cpudesc(struct perf_header *ph, int fd, FILE *fp)
+static void print_cpudesc(struct perf_header *ph, int fd __maybe_unused,
+ FILE *fp)
{
- char *str = do_read_string(fd, ph);
- fprintf(fp, "# cpudesc : %s\n", str);
- free(str);
+ fprintf(fp, "# cpudesc : %s\n", ph->env.cpu_desc);
}
-static void print_nrcpus(struct perf_header *ph, int fd, FILE *fp)
+static void print_nrcpus(struct perf_header *ph, int fd __maybe_unused,
+ FILE *fp)
{
- ssize_t ret;
- u32 nr;
-
- ret = read(fd, &nr, sizeof(nr));
- if (ret != (ssize_t)sizeof(nr))
- nr = -1; /* interpreted as error */
-
- if (ph->needs_swap)
- nr = bswap_32(nr);
-
- fprintf(fp, "# nrcpus online : %u\n", nr);
-
- ret = read(fd, &nr, sizeof(nr));
- if (ret != (ssize_t)sizeof(nr))
- nr = -1; /* interpreted as error */
-
- if (ph->needs_swap)
- nr = bswap_32(nr);
-
- fprintf(fp, "# nrcpus avail : %u\n", nr);
+ fprintf(fp, "# nrcpus online : %u\n", ph->env.nr_cpus_online);
+ fprintf(fp, "# nrcpus avail : %u\n", ph->env.nr_cpus_avail);
}
-static void print_version(struct perf_header *ph, int fd, FILE *fp)
+static void print_version(struct perf_header *ph, int fd __maybe_unused,
+ FILE *fp)
{
- char *str = do_read_string(fd, ph);
- fprintf(fp, "# perf version : %s\n", str);
- free(str);
+ fprintf(fp, "# perf version : %s\n", ph->env.version);
}
-static void print_cmdline(struct perf_header *ph, int fd, FILE *fp)
+static void print_cmdline(struct perf_header *ph, int fd __maybe_unused,
+ FILE *fp)
{
- ssize_t ret;
+ int nr, i;
char *str;
- u32 nr, i;
-
- ret = read(fd, &nr, sizeof(nr));
- if (ret != (ssize_t)sizeof(nr))
- return;
- if (ph->needs_swap)
- nr = bswap_32(nr);
+ nr = ph->env.nr_cmdline;
+ str = ph->env.cmdline;
fprintf(fp, "# cmdline : ");
for (i = 0; i < nr; i++) {
- str = do_read_string(fd, ph);
fprintf(fp, "%s ", str);
- free(str);
+ str += strlen(str) + 1;
}
fputc('\n', fp);
}
-static void print_cpu_topology(struct perf_header *ph, int fd, FILE *fp)
+static void print_cpu_topology(struct perf_header *ph, int fd __maybe_unused,
+ FILE *fp)
{
- ssize_t ret;
- u32 nr, i;
+ int nr, i;
char *str;
- ret = read(fd, &nr, sizeof(nr));
- if (ret != (ssize_t)sizeof(nr))
- return;
-
- if (ph->needs_swap)
- nr = bswap_32(nr);
+ nr = ph->env.nr_sibling_cores;
+ str = ph->env.sibling_cores;
for (i = 0; i < nr; i++) {
- str = do_read_string(fd, ph);
fprintf(fp, "# sibling cores : %s\n", str);
- free(str);
+ str += strlen(str) + 1;
}
- ret = read(fd, &nr, sizeof(nr));
- if (ret != (ssize_t)sizeof(nr))
- return;
-
- if (ph->needs_swap)
- nr = bswap_32(nr);
+ nr = ph->env.nr_sibling_threads;
+ str = ph->env.sibling_threads;
for (i = 0; i < nr; i++) {
- str = do_read_string(fd, ph);
fprintf(fp, "# sibling threads : %s\n", str);
- free(str);
+ str += strlen(str) + 1;
}
}
@@ -1375,126 +1337,89 @@ static void print_event_desc(struct perf_header *ph, int fd, FILE *fp)
free_event_desc(events);
}
-static void print_total_mem(struct perf_header *h __maybe_unused, int fd,
+static void print_total_mem(struct perf_header *ph, int fd __maybe_unused,
FILE *fp)
{
- uint64_t mem;
- ssize_t ret;
-
- ret = read(fd, &mem, sizeof(mem));
- if (ret != sizeof(mem))
- goto error;
-
- if (h->needs_swap)
- mem = bswap_64(mem);
-
- fprintf(fp, "# total memory : %"PRIu64" kB\n", mem);
- return;
-error:
- fprintf(fp, "# total memory : unknown\n");
+ fprintf(fp, "# total memory : %Lu kB\n", ph->env.total_mem);
}
-static void print_numa_topology(struct perf_header *h __maybe_unused, int fd,
+static void print_numa_topology(struct perf_header *ph, int fd __maybe_unused,
FILE *fp)
{
- ssize_t ret;
u32 nr, c, i;
- char *str;
+ char *str, *tmp;
uint64_t mem_total, mem_free;
/* nr nodes */
- ret = read(fd, &nr, sizeof(nr));
- if (ret != (ssize_t)sizeof(nr))
- goto error;
-
- if (h->needs_swap)
- nr = bswap_32(nr);
+ nr = ph->env.nr_numa_nodes;
+ str = ph->env.numa_nodes;
for (i = 0; i < nr; i++) {
-
/* node number */
- ret = read(fd, &c, sizeof(c));
- if (ret != (ssize_t)sizeof(c))
+ c = strtoul(str, &tmp, 0);
+ if (*tmp != ':')
goto error;
- if (h->needs_swap)
- c = bswap_32(c);
-
- ret = read(fd, &mem_total, sizeof(u64));
- if (ret != sizeof(u64))
+ str = tmp + 1;
+ mem_total = strtoull(str, &tmp, 0);
+ if (*tmp != ':')
goto error;
- ret = read(fd, &mem_free, sizeof(u64));
- if (ret != sizeof(u64))
+ str = tmp + 1;
+ mem_free = strtoull(str, &tmp, 0);
+ if (*tmp != ':')
goto error;
- if (h->needs_swap) {
- mem_total = bswap_64(mem_total);
- mem_free = bswap_64(mem_free);
- }
-
fprintf(fp, "# node%u meminfo : total = %"PRIu64" kB,"
" free = %"PRIu64" kB\n",
- c,
- mem_total,
- mem_free);
+ c, mem_total, mem_free);
- str = do_read_string(fd, h);
+ str = tmp + 1;
fprintf(fp, "# node%u cpu list : %s\n", c, str);
- free(str);
}
return;
error:
fprintf(fp, "# numa topology : not available\n");
}
-static void print_cpuid(struct perf_header *ph, int fd, FILE *fp)
+static void print_cpuid(struct perf_header *ph, int fd __maybe_unused, FILE *fp)
{
- char *str = do_read_string(fd, ph);
- fprintf(fp, "# cpuid : %s\n", str);
- free(str);
+ fprintf(fp, "# cpuid : %s\n", ph->env.cpuid);
}
static void print_branch_stack(struct perf_header *ph __maybe_unused,
- int fd __maybe_unused,
- FILE *fp)
+ int fd __maybe_unused, FILE *fp)
{
fprintf(fp, "# contains samples with branch stack\n");
}
-static void print_pmu_mappings(struct perf_header *ph, int fd, FILE *fp)
+static void print_pmu_mappings(struct perf_header *ph, int fd __maybe_unused,
+ FILE *fp)
{
const char *delimiter = "# pmu mappings: ";
- char *name;
- int ret;
+ char *str, *tmp;
u32 pmu_num;
u32 type;
- ret = read(fd, &pmu_num, sizeof(pmu_num));
- if (ret != sizeof(pmu_num))
- goto error;
-
- if (ph->needs_swap)
- pmu_num = bswap_32(pmu_num);
-
+ pmu_num = ph->env.nr_pmu_mappings;
if (!pmu_num) {
fprintf(fp, "# pmu mappings: not available\n");
return;
}
+ str = ph->env.pmu_mappings;
+
while (pmu_num) {
- if (read(fd, &type, sizeof(type)) != sizeof(type))
- break;
- if (ph->needs_swap)
- type = bswap_32(type);
+ type = strtoul(str, &tmp, 0);
+ if (*tmp != ':')
+ goto error;
+
+ str = tmp + 1;
+ fprintf(fp, "%s%s = %" PRIu32, delimiter, str, type);
- name = do_read_string(fd, ph);
- if (!name)
- break;
- pmu_num--;
- fprintf(fp, "%s%s = %" PRIu32, delimiter, name, type);
- free(name);
delimiter = ", ";
+ str += strlen(str) + 1;
+ pmu_num--;
}
fprintf(fp, "\n");
--
1.7.1
^ permalink raw reply related [flat|nested] 41+ messages in thread
* [PATCH 14/30] perf header: Remove unused @feat arg from ->process callback
2012-09-24 15:59 [GIT PULL 00/30] perf/core improvements and fixes Arnaldo Carvalho de Melo
` (12 preceding siblings ...)
2012-09-24 15:59 ` [PATCH 13/30] perf header: Use pre-processed session env when printing Arnaldo Carvalho de Melo
@ 2012-09-24 15:59 ` Arnaldo Carvalho de Melo
2012-09-24 15:59 ` [PATCH 15/30] perf kvm: Use perf_session_env for reading cpuid Arnaldo Carvalho de Melo
` (15 subsequent siblings)
29 siblings, 0 replies; 41+ messages in thread
From: Arnaldo Carvalho de Melo @ 2012-09-24 15:59 UTC (permalink / raw)
To: Ingo Molnar
Cc: linux-kernel, Namhyung Kim, Namhyung Kim, David Ahern,
Paul Mackerras, Peter Zijlstra, Robert Richter, Stephane Eranian,
Arnaldo Carvalho de Melo
From: Namhyung Kim <namhyung.kim@lge.com>
As the @feat arg is not used anywhere, get rid of it from the signature.
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
Cc: David Ahern <dsahern@gmail.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Robert Richter <robert.richter@amd.com>
Cc: Stephane Eranian <eranian@google.com>
Link: http://lkml.kernel.org/r/1348474503-15070-5-git-send-email-namhyung@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
| 70 +++++++++++++++++++++++-----------------------
1 files changed, 35 insertions(+), 35 deletions(-)
--git a/tools/perf/util/header.c b/tools/perf/util/header.c
index b2929d7..4b028df 100644
--- a/tools/perf/util/header.c
+++ b/tools/perf/util/header.c
@@ -1580,18 +1580,16 @@ out:
return err;
}
-static int process_tracing_data(struct perf_file_section *section
- __maybe_unused,
- struct perf_header *ph __maybe_unused,
- int feat __maybe_unused, int fd, void *data)
+static int process_tracing_data(struct perf_file_section *section __maybe_unused,
+ struct perf_header *ph __maybe_unused,
+ int fd, void *data)
{
trace_report(fd, data, false);
return 0;
}
static int process_build_id(struct perf_file_section *section,
- struct perf_header *ph,
- int feat __maybe_unused, int fd,
+ struct perf_header *ph, int fd,
void *data __maybe_unused)
{
if (perf_header__read_build_ids(ph, fd, section->offset, section->size))
@@ -1600,40 +1598,40 @@ static int process_build_id(struct perf_file_section *section,
}
static int process_hostname(struct perf_file_section *section __maybe_unused,
- struct perf_header *ph, int feat __maybe_unused,
- int fd, void *data __maybe_unused)
+ struct perf_header *ph, int fd,
+ void *data __maybe_unused)
{
ph->env.hostname = do_read_string(fd, ph);
return ph->env.hostname ? 0 : -ENOMEM;
}
static int process_osrelease(struct perf_file_section *section __maybe_unused,
- struct perf_header *ph, int feat __maybe_unused,
- int fd, void *data __maybe_unused)
+ struct perf_header *ph, int fd,
+ void *data __maybe_unused)
{
ph->env.os_release = do_read_string(fd, ph);
return ph->env.os_release ? 0 : -ENOMEM;
}
static int process_version(struct perf_file_section *section __maybe_unused,
- struct perf_header *ph, int feat __maybe_unused,
- int fd, void *data __maybe_unused)
+ struct perf_header *ph, int fd,
+ void *data __maybe_unused)
{
ph->env.version = do_read_string(fd, ph);
return ph->env.version ? 0 : -ENOMEM;
}
static int process_arch(struct perf_file_section *section __maybe_unused,
- struct perf_header *ph, int feat __maybe_unused,
- int fd, void *data __maybe_unused)
+ struct perf_header *ph, int fd,
+ void *data __maybe_unused)
{
ph->env.arch = do_read_string(fd, ph);
return ph->env.arch ? 0 : -ENOMEM;
}
static int process_nrcpus(struct perf_file_section *section __maybe_unused,
- struct perf_header *ph, int feat __maybe_unused,
- int fd, void *data __maybe_unused)
+ struct perf_header *ph, int fd,
+ void *data __maybe_unused)
{
size_t ret;
u32 nr;
@@ -1659,24 +1657,24 @@ static int process_nrcpus(struct perf_file_section *section __maybe_unused,
}
static int process_cpudesc(struct perf_file_section *section __maybe_unused,
- struct perf_header *ph, int feat __maybe_unused,
- int fd, void *data __maybe_unused)
+ struct perf_header *ph, int fd,
+ void *data __maybe_unused)
{
ph->env.cpu_desc = do_read_string(fd, ph);
return ph->env.cpu_desc ? 0 : -ENOMEM;
}
static int process_cpuid(struct perf_file_section *section __maybe_unused,
- struct perf_header *ph, int feat __maybe_unused,
- int fd, void *data __maybe_unused)
+ struct perf_header *ph, int fd,
+ void *data __maybe_unused)
{
ph->env.cpuid = do_read_string(fd, ph);
return ph->env.cpuid ? 0 : -ENOMEM;
}
static int process_total_mem(struct perf_file_section *section __maybe_unused,
- struct perf_header *ph, int feat __maybe_unused,
- int fd, void *data __maybe_unused)
+ struct perf_header *ph, int fd,
+ void *data __maybe_unused)
{
uint64_t mem;
size_t ret;
@@ -1711,7 +1709,8 @@ perf_evlist__find_by_index(struct perf_evlist *evlist, int idx)
}
static void
-perf_evlist__set_event_name(struct perf_evlist *evlist, struct perf_evsel *event)
+perf_evlist__set_event_name(struct perf_evlist *evlist,
+ struct perf_evsel *event)
{
struct perf_evsel *evsel;
@@ -1730,15 +1729,16 @@ perf_evlist__set_event_name(struct perf_evlist *evlist, struct perf_evsel *event
static int
process_event_desc(struct perf_file_section *section __maybe_unused,
- struct perf_header *header, int feat __maybe_unused, int fd,
+ struct perf_header *header, int fd,
void *data __maybe_unused)
{
- struct perf_session *session = container_of(header, struct perf_session, header);
+ struct perf_session *session;
struct perf_evsel *evsel, *events = read_event_desc(header, fd);
if (!events)
return 0;
+ session = container_of(header, struct perf_session, header);
for (evsel = events; evsel->attr.size; evsel++)
perf_evlist__set_event_name(session->evlist, evsel);
@@ -1748,8 +1748,8 @@ process_event_desc(struct perf_file_section *section __maybe_unused,
}
static int process_cmdline(struct perf_file_section *section __maybe_unused,
- struct perf_header *ph, int feat __maybe_unused,
- int fd, void *data __maybe_unused)
+ struct perf_header *ph, int fd,
+ void *data __maybe_unused)
{
size_t ret;
char *str;
@@ -1784,8 +1784,8 @@ error:
}
static int process_cpu_topology(struct perf_file_section *section __maybe_unused,
- struct perf_header *ph, int feat __maybe_unused,
- int fd, void *data __maybe_unused)
+ struct perf_header *ph, int fd,
+ void *data __maybe_unused)
{
size_t ret;
u32 nr, i;
@@ -1840,8 +1840,8 @@ error:
}
static int process_numa_topology(struct perf_file_section *section __maybe_unused,
- struct perf_header *ph, int feat __maybe_unused,
- int fd, void *data __maybe_unused)
+ struct perf_header *ph, int fd,
+ void *data __maybe_unused)
{
size_t ret;
u32 nr, node, i;
@@ -1900,8 +1900,8 @@ error:
}
static int process_pmu_mappings(struct perf_file_section *section __maybe_unused,
- struct perf_header *ph, int feat __maybe_unused,
- int fd, void *data __maybe_unused)
+ struct perf_header *ph, int fd,
+ void *data __maybe_unused)
{
size_t ret;
char *name;
@@ -1954,7 +1954,7 @@ struct feature_ops {
void (*print)(struct perf_header *h, int fd, FILE *fp);
char *(*read)(struct perf_header *h, int fd);
int (*process)(struct perf_file_section *section,
- struct perf_header *h, int feat, int fd, void *data);
+ struct perf_header *h, int fd, void *data);
const char *name;
bool full_only;
};
@@ -2520,7 +2520,7 @@ static int perf_file_section__process(struct perf_file_section *section,
if (!feat_ops[feat].process)
return 0;
- return feat_ops[feat].process(section, ph, feat, fd, data);
+ return feat_ops[feat].process(section, ph, fd, data);
}
static int perf_file_header__read_pipe(struct perf_pipe_file_header *header,
--
1.7.1
^ permalink raw reply related [flat|nested] 41+ messages in thread
* [PATCH 15/30] perf kvm: Use perf_session_env for reading cpuid
2012-09-24 15:59 [GIT PULL 00/30] perf/core improvements and fixes Arnaldo Carvalho de Melo
` (13 preceding siblings ...)
2012-09-24 15:59 ` [PATCH 14/30] perf header: Remove unused @feat arg from ->process callback Arnaldo Carvalho de Melo
@ 2012-09-24 15:59 ` Arnaldo Carvalho de Melo
2012-09-24 15:59 ` [PATCH 16/30] perf header: Remove perf_header__read_feature Arnaldo Carvalho de Melo
` (14 subsequent siblings)
29 siblings, 0 replies; 41+ messages in thread
From: Arnaldo Carvalho de Melo @ 2012-09-24 15:59 UTC (permalink / raw)
To: Ingo Molnar
Cc: linux-kernel, Namhyung Kim, Namhyung Kim, David Ahern, Dong Hao,
Paul Mackerras, Peter Zijlstra, Stephane Eranian, Xiao Guangrong,
Arnaldo Carvalho de Melo
From: Namhyung Kim <namhyung.kim@lge.com>
We have processed and saved cpuid information to perf_session_env so
reuse it for get_cpu_isa().
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
Cc: David Ahern <dsahern@gmail.com>
Cc: Dong Hao <haodong@linux.vnet.ibm.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Stephane Eranian <eranian@google.com>
Cc: Xiao Guangrong <xiaoguangrong@linux.vnet.ibm.com>
Link: http://lkml.kernel.org/r/1348474503-15070-6-git-send-email-namhyung@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
tools/perf/builtin-kvm.c | 10 +---------
1 files changed, 1 insertions(+), 9 deletions(-)
diff --git a/tools/perf/builtin-kvm.c b/tools/perf/builtin-kvm.c
index 3eb53e3..a28c9ca 100644
--- a/tools/perf/builtin-kvm.c
+++ b/tools/perf/builtin-kvm.c
@@ -664,16 +664,9 @@ static struct perf_tool eops = {
static int get_cpu_isa(struct perf_session *session)
{
- char *cpuid;
+ char *cpuid = session->header.env.cpuid;
int isa;
- cpuid = perf_header__read_feature(session, HEADER_CPUID);
-
- if (!cpuid) {
- pr_err("read HEADER_CPUID failed.\n");
- return -ENOTSUP;
- }
-
if (strstr(cpuid, "Intel"))
isa = 1;
else if (strstr(cpuid, "AMD"))
@@ -683,7 +676,6 @@ static int get_cpu_isa(struct perf_session *session)
isa = -ENOTSUP;
}
- free(cpuid);
return isa;
}
--
1.7.1
^ permalink raw reply related [flat|nested] 41+ messages in thread
* [PATCH 16/30] perf header: Remove perf_header__read_feature
2012-09-24 15:59 [GIT PULL 00/30] perf/core improvements and fixes Arnaldo Carvalho de Melo
` (14 preceding siblings ...)
2012-09-24 15:59 ` [PATCH 15/30] perf kvm: Use perf_session_env for reading cpuid Arnaldo Carvalho de Melo
@ 2012-09-24 15:59 ` Arnaldo Carvalho de Melo
2012-09-24 15:59 ` [PATCH 17/30] perf tools: remove sscanf extension %as Arnaldo Carvalho de Melo
` (13 subsequent siblings)
29 siblings, 0 replies; 41+ messages in thread
From: Arnaldo Carvalho de Melo @ 2012-09-24 15:59 UTC (permalink / raw)
To: Ingo Molnar
Cc: linux-kernel, Namhyung Kim, Namhyung Kim, David Ahern, Dong Hao,
Paul Mackerras, Peter Zijlstra, Stephane Eranian, Xiao Guangrong,
Arnaldo Carvalho de Melo
From: Namhyung Kim <namhyung.kim@lge.com>
Because its only user builtin-kvm::get_cpu_isa() has gone, It can be
removed safely. In general, we have the feature information in
perf_session_env already, no need to read it again.
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
Cc: David Ahern <dsahern@gmail.com>
Cc: Dong Hao <haodong@linux.vnet.ibm.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Stephane Eranian <eranian@google.com>
Cc: Xiao Guangrong <xiaoguangrong@linux.vnet.ibm.com>
Link: http://lkml.kernel.org/r/1348474503-15070-7-git-send-email-namhyung@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
| 60 +---------------------------------------------
| 1 -
2 files changed, 1 insertions(+), 60 deletions(-)
--git a/tools/perf/util/header.c b/tools/perf/util/header.c
index 4b028df..6aae329 100644
--- a/tools/perf/util/header.c
+++ b/tools/perf/util/header.c
@@ -1690,11 +1690,6 @@ static int process_total_mem(struct perf_file_section *section __maybe_unused,
return 0;
}
-static char *read_cpuid(struct perf_header *ph, int fd)
-{
- return do_read_string(fd, ph);
-}
-
static struct perf_evsel *
perf_evlist__find_by_index(struct perf_evlist *evlist, int idx)
{
@@ -1952,7 +1947,6 @@ error:
struct feature_ops {
int (*write)(int fd, struct perf_header *h, struct perf_evlist *evlist);
void (*print)(struct perf_header *h, int fd, FILE *fp);
- char *(*read)(struct perf_header *h, int fd);
int (*process)(struct perf_file_section *section,
struct perf_header *h, int fd, void *data);
const char *name;
@@ -1967,10 +1961,6 @@ struct feature_ops {
#define FEAT_OPF(n, func) \
[n] = { .name = #n, .write = write_##func, .print = print_##func, \
.process = process_##func, .full_only = true }
-#define FEAT_OPA_R(n, func) \
- [n] = { .name = #n, .write = write_##func, .print = print_##func, \
- .read = read_##func, .process = process_##func, \
- .full_only = true }
/* feature_ops not implemented: */
#define print_tracing_data NULL
@@ -1985,7 +1975,7 @@ static const struct feature_ops feat_ops[HEADER_LAST_FEATURE] = {
FEAT_OPP(HEADER_ARCH, arch),
FEAT_OPP(HEADER_NRCPUS, nrcpus),
FEAT_OPP(HEADER_CPUDESC, cpudesc),
- FEAT_OPA_R(HEADER_CPUID, cpuid),
+ FEAT_OPP(HEADER_CPUID, cpuid),
FEAT_OPP(HEADER_TOTAL_MEM, total_mem),
FEAT_OPP(HEADER_EVENT_DESC, event_desc),
FEAT_OPP(HEADER_CMDLINE, cmdline),
@@ -2040,54 +2030,6 @@ int perf_header__fprintf_info(struct perf_session *session, FILE *fp, bool full)
return 0;
}
-struct header_read_data {
- int feat;
- char *result;
-};
-
-static int perf_file_section__read_feature(struct perf_file_section *section,
- struct perf_header *ph,
- int feat, int fd, void *data)
-{
- struct header_read_data *hd = data;
-
- if (feat != hd->feat)
- return 0;
-
- if (lseek(fd, section->offset, SEEK_SET) == (off_t)-1) {
- pr_debug("Failed to lseek to %" PRIu64 " offset for feature "
- "%d, continuing...\n", section->offset, feat);
- return 0;
- }
-
- if (feat >= HEADER_LAST_FEATURE) {
- pr_warning("unknown feature %d\n", feat);
- return 0;
- }
-
- if (!feat_ops[feat].read) {
- pr_warning("read is not supported for feature %d\n", feat);
- return 0;
- }
-
- hd->result = feat_ops[feat].read(ph, fd);
- return 0;
-}
-
-char *perf_header__read_feature(struct perf_session *session, int feat)
-{
- struct perf_header *header = &session->header;
- struct header_read_data hd;
- int fd = session->fd;
-
- hd.feat = feat;
- hd.result = NULL;
-
- perf_header__process_sections(header, fd, &hd,
- perf_file_section__read_feature);
- return hd.result;
-}
-
static int do_write_feat(int fd, struct perf_header *h, int type,
struct perf_file_section **p,
struct perf_evlist *evlist)
--git a/tools/perf/util/header.h b/tools/perf/util/header.h
index 5867c7d..99bdd3a 100644
--- a/tools/perf/util/header.h
+++ b/tools/perf/util/header.h
@@ -118,7 +118,6 @@ int perf_header__process_sections(struct perf_header *header, int fd,
int feat, int fd, void *data));
int perf_header__fprintf_info(struct perf_session *s, FILE *fp, bool full);
-char *perf_header__read_feature(struct perf_session *session, int feat);
int build_id_cache__add_s(const char *sbuild_id, const char *debugdir,
const char *name, bool is_kallsyms, bool is_vdso);
--
1.7.1
^ permalink raw reply related [flat|nested] 41+ messages in thread
* [PATCH 17/30] perf tools: remove sscanf extension %as
2012-09-24 15:59 [GIT PULL 00/30] perf/core improvements and fixes Arnaldo Carvalho de Melo
` (15 preceding siblings ...)
2012-09-24 15:59 ` [PATCH 16/30] perf header: Remove perf_header__read_feature Arnaldo Carvalho de Melo
@ 2012-09-24 15:59 ` Arnaldo Carvalho de Melo
2012-09-24 15:59 ` [PATCH 18/30] tools lib traceevent: Fix error path on process_array() Arnaldo Carvalho de Melo
` (12 subsequent siblings)
29 siblings, 0 replies; 41+ messages in thread
From: Arnaldo Carvalho de Melo @ 2012-09-24 15:59 UTC (permalink / raw)
To: Ingo Molnar
Cc: linux-kernel, Irina Tirdea, David Ahern, Ingo Molnar,
Masami Hiramatsu, Namhyung Kim, Paul Mackerras, Peter Zijlstra,
Steven Rostedt, Arnaldo Carvalho de Melo
From: Irina Tirdea <irina.tirdea@intel.com>
perf uses sscanf extension %as to read and allocate a string in the same
step. This is a non-standard extension only present in new versions of
glibc.
Replacing the use of sscanf and %as with strtok_r calls in order to
parse a given string into its components. This is needed in Android
since bionic does not support
%as extension for sscanf.
Reviewed-by: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
Tested-by: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
Signed-off-by: Irina Tirdea <irina.tirdea@intel.com>
Acked-by: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
Cc: Namhyung Kim <namhyung.kim@lge.com>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Steven Rostedt <rostedt@goodmis.org>
Link: http://lkml.kernel.org/r/1348173470-4936-1-git-send-email-irina.tirdea@gmail.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
tools/perf/util/probe-event.c | 36 ++++++++++++++++++++++++++++------
tools/perf/util/trace-event-parse.c | 18 +++++++---------
2 files changed, 37 insertions(+), 17 deletions(-)
diff --git a/tools/perf/util/probe-event.c b/tools/perf/util/probe-event.c
index 4ce04c2..49a256e 100644
--- a/tools/perf/util/probe-event.c
+++ b/tools/perf/util/probe-event.c
@@ -1100,6 +1100,7 @@ static int parse_probe_trace_command(const char *cmd,
struct probe_trace_point *tp = &tev->point;
char pr;
char *p;
+ char *argv0_str = NULL, *fmt, *fmt1_str, *fmt2_str, *fmt3_str;
int ret, i, argc;
char **argv;
@@ -1116,14 +1117,27 @@ static int parse_probe_trace_command(const char *cmd,
}
/* Scan event and group name. */
- ret = sscanf(argv[0], "%c:%a[^/ \t]/%a[^ \t]",
- &pr, (float *)(void *)&tev->group,
- (float *)(void *)&tev->event);
- if (ret != 3) {
+ argv0_str = strdup(argv[0]);
+ if (argv0_str == NULL) {
+ ret = -ENOMEM;
+ goto out;
+ }
+ fmt1_str = strtok_r(argv0_str, ":", &fmt);
+ fmt2_str = strtok_r(NULL, "/", &fmt);
+ fmt3_str = strtok_r(NULL, " \t", &fmt);
+ if (fmt1_str == NULL || strlen(fmt1_str) != 1 || fmt2_str == NULL
+ || fmt3_str == NULL) {
semantic_error("Failed to parse event name: %s\n", argv[0]);
ret = -EINVAL;
goto out;
}
+ pr = fmt1_str[0];
+ tev->group = strdup(fmt2_str);
+ tev->event = strdup(fmt3_str);
+ if (tev->group == NULL || tev->event == NULL) {
+ ret = -ENOMEM;
+ goto out;
+ }
pr_debug("Group:%s Event:%s probe:%c\n", tev->group, tev->event, pr);
tp->retprobe = (pr == 'r');
@@ -1135,10 +1149,17 @@ static int parse_probe_trace_command(const char *cmd,
p++;
} else
p = argv[1];
- ret = sscanf(p, "%a[^+]+%lu", (float *)(void *)&tp->symbol,
- &tp->offset);
- if (ret == 1)
+ fmt1_str = strtok_r(p, "+", &fmt);
+ tp->symbol = strdup(fmt1_str);
+ if (tp->symbol == NULL) {
+ ret = -ENOMEM;
+ goto out;
+ }
+ fmt2_str = strtok_r(NULL, "", &fmt);
+ if (fmt2_str == NULL)
tp->offset = 0;
+ else
+ tp->offset = strtoul(fmt2_str, NULL, 10);
tev->nargs = argc - 2;
tev->args = zalloc(sizeof(struct probe_trace_arg) * tev->nargs);
@@ -1162,6 +1183,7 @@ static int parse_probe_trace_command(const char *cmd,
}
ret = 0;
out:
+ free(argv0_str);
argv_free(argv);
return ret;
}
diff --git a/tools/perf/util/trace-event-parse.c b/tools/perf/util/trace-event-parse.c
index aa4c860..3aabcd6 100644
--- a/tools/perf/util/trace-event-parse.c
+++ b/tools/perf/util/trace-event-parse.c
@@ -229,24 +229,22 @@ void parse_proc_kallsyms(struct pevent *pevent,
char *next = NULL;
char *addr_str;
char *mod;
- char ch;
+ char *fmt;
line = strtok_r(file, "\n", &next);
while (line) {
mod = NULL;
- sscanf(line, "%as %c %as\t[%as",
- (float *)(void *)&addr_str, /* workaround gcc warning */
- &ch, (float *)(void *)&func, (float *)(void *)&mod);
+ addr_str = strtok_r(line, " ", &fmt);
addr = strtoull(addr_str, NULL, 16);
- free(addr_str);
-
- /* truncate the extra ']' */
+ /* skip character */
+ strtok_r(NULL, " ", &fmt);
+ func = strtok_r(NULL, "\t", &fmt);
+ mod = strtok_r(NULL, "]", &fmt);
+ /* truncate the extra '[' */
if (mod)
- mod[strlen(mod) - 1] = 0;
+ mod = mod + 1;
pevent_register_function(pevent, func, addr, mod);
- free(func);
- free(mod);
line = strtok_r(NULL, "\n", &next);
}
--
1.7.1
^ permalink raw reply related [flat|nested] 41+ messages in thread
* [PATCH 18/30] tools lib traceevent: Fix error path on process_array()
2012-09-24 15:59 [GIT PULL 00/30] perf/core improvements and fixes Arnaldo Carvalho de Melo
` (16 preceding siblings ...)
2012-09-24 15:59 ` [PATCH 17/30] perf tools: remove sscanf extension %as Arnaldo Carvalho de Melo
@ 2012-09-24 15:59 ` Arnaldo Carvalho de Melo
2012-09-24 15:59 ` [PATCH 19/30] tools lib traceevent: Make sure that arg->op.right is set properly Arnaldo Carvalho de Melo
` (11 subsequent siblings)
29 siblings, 0 replies; 41+ messages in thread
From: Arnaldo Carvalho de Melo @ 2012-09-24 15:59 UTC (permalink / raw)
To: Ingo Molnar
Cc: linux-kernel, Namhyung Kim, Namhyung Kim, Frederic Weisbecker,
Peter Zijlstra, Steven Rostedt, Arnaldo Carvalho de Melo
From: Namhyung Kim <namhyung.kim@lge.com>
free_token() under out_free should be called with 'token' and no need
to set *tok to NULL since it's set already.
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Steven Rostedt <rostedt@goodmis.org>
Link: http://lkml.kernel.org/r/1348037924-17568-2-git-send-email-namhyung@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
tools/lib/traceevent/event-parse.c | 3 +--
1 files changed, 1 insertions(+), 2 deletions(-)
diff --git a/tools/lib/traceevent/event-parse.c b/tools/lib/traceevent/event-parse.c
index 77ebeb8..6270ee2 100644
--- a/tools/lib/traceevent/event-parse.c
+++ b/tools/lib/traceevent/event-parse.c
@@ -1595,8 +1595,7 @@ process_array(struct event_format *event, struct print_arg *top, char **tok)
return type;
out_free:
- free_token(*tok);
- *tok = NULL;
+ free_token(token);
free_arg(arg);
return EVENT_ERROR;
}
--
1.7.1
^ permalink raw reply related [flat|nested] 41+ messages in thread
* [PATCH 19/30] tools lib traceevent: Make sure that arg->op.right is set properly
2012-09-24 15:59 [GIT PULL 00/30] perf/core improvements and fixes Arnaldo Carvalho de Melo
` (17 preceding siblings ...)
2012-09-24 15:59 ` [PATCH 18/30] tools lib traceevent: Fix error path on process_array() Arnaldo Carvalho de Melo
@ 2012-09-24 15:59 ` Arnaldo Carvalho de Melo
2012-09-24 15:59 ` [PATCH 20/30] tools lib traceevent: Free field if an error occurs on process_fields Arnaldo Carvalho de Melo
` (10 subsequent siblings)
29 siblings, 0 replies; 41+ messages in thread
From: Arnaldo Carvalho de Melo @ 2012-09-24 15:59 UTC (permalink / raw)
To: Ingo Molnar
Cc: linux-kernel, Namhyung Kim, Namhyung Kim, Frederic Weisbecker,
Peter Zijlstra, Steven Rostedt, Arnaldo Carvalho de Melo
From: Namhyung Kim <namhyung.kim@lge.com>
When process_op failed, @arg will be freed on a caller with type of
PRINT_OP. Thus free_arg() will try to free ->op.right field which can
have stale value if something bad happens in the middle.
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Steven Rostedt <rostedt@goodmis.org>
Link: http://lkml.kernel.org/r/1348037924-17568-3-git-send-email-namhyung@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
tools/lib/traceevent/event-parse.c | 3 +++
1 files changed, 3 insertions(+), 0 deletions(-)
diff --git a/tools/lib/traceevent/event-parse.c b/tools/lib/traceevent/event-parse.c
index 6270ee2..27088c5 100644
--- a/tools/lib/traceevent/event-parse.c
+++ b/tools/lib/traceevent/event-parse.c
@@ -1719,6 +1719,7 @@ process_op(struct event_format *event, struct print_arg *arg, char **tok)
arg->op.left = left;
arg->op.prio = 0;
+ /* it will set arg->op.right */
type = process_cond(event, arg, tok);
} else if (strcmp(token, ">>") == 0 ||
@@ -1745,6 +1746,7 @@ process_op(struct event_format *event, struct print_arg *arg, char **tok)
arg->type = PRINT_OP;
arg->op.op = token;
arg->op.left = left;
+ arg->op.right = NULL;
if (set_op_prio(arg) == -1) {
event->flags |= EVENT_FL_FAILED;
@@ -1792,6 +1794,7 @@ process_op(struct event_format *event, struct print_arg *arg, char **tok)
arg->op.prio = 0;
+ /* it will set arg->op.right */
type = process_array(event, arg, tok);
} else {
--
1.7.1
^ permalink raw reply related [flat|nested] 41+ messages in thread
* [PATCH 20/30] tools lib traceevent: Free field if an error occurs on process_fields
2012-09-24 15:59 [GIT PULL 00/30] perf/core improvements and fixes Arnaldo Carvalho de Melo
` (18 preceding siblings ...)
2012-09-24 15:59 ` [PATCH 19/30] tools lib traceevent: Make sure that arg->op.right is set properly Arnaldo Carvalho de Melo
@ 2012-09-24 15:59 ` Arnaldo Carvalho de Melo
2012-09-24 15:59 ` [PATCH 21/30] tools lib traceevent: Free field if an error occurs on process_flags/symbols Arnaldo Carvalho de Melo
` (9 subsequent siblings)
29 siblings, 0 replies; 41+ messages in thread
From: Arnaldo Carvalho de Melo @ 2012-09-24 15:59 UTC (permalink / raw)
To: Ingo Molnar
Cc: linux-kernel, Namhyung Kim, Namhyung Kim, Frederic Weisbecker,
Peter Zijlstra, Steven Rostedt, Arnaldo Carvalho de Melo
From: Namhyung Kim <namhyung.kim@lge.com>
The field should be freed on error paths.
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Steven Rostedt <rostedt@goodmis.org>
Link: http://lkml.kernel.org/r/1348037924-17568-4-git-send-email-namhyung@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
tools/lib/traceevent/event-parse.c | 12 +++++++-----
1 files changed, 7 insertions(+), 5 deletions(-)
diff --git a/tools/lib/traceevent/event-parse.c b/tools/lib/traceevent/event-parse.c
index 27088c5..a776ed5 100644
--- a/tools/lib/traceevent/event-parse.c
+++ b/tools/lib/traceevent/event-parse.c
@@ -2186,10 +2186,10 @@ process_fields(struct event_format *event, struct print_flag_sym **list, char **
value = arg_eval(arg);
if (value == NULL)
- goto out_free;
+ goto out_free_field;
field->value = strdup(value);
if (field->value == NULL)
- goto out_free;
+ goto out_free_field;
free_arg(arg);
arg = alloc_arg();
@@ -2197,14 +2197,14 @@ process_fields(struct event_format *event, struct print_flag_sym **list, char **
free_token(token);
type = process_arg(event, arg, &token);
if (test_type_token(type, token, EVENT_OP, "}"))
- goto out_free;
+ goto out_free_field;
value = arg_eval(arg);
if (value == NULL)
- goto out_free;
+ goto out_free_field;
field->str = strdup(value);
if (field->str == NULL)
- goto out_free;
+ goto out_free_field;
free_arg(arg);
arg = NULL;
@@ -2218,6 +2218,8 @@ process_fields(struct event_format *event, struct print_flag_sym **list, char **
*tok = token;
return type;
+out_free_field:
+ free_flag_sym(field);
out_free:
free_arg(arg);
free_token(token);
--
1.7.1
^ permalink raw reply related [flat|nested] 41+ messages in thread
* [PATCH 21/30] tools lib traceevent: Free field if an error occurs on process_flags/symbols
2012-09-24 15:59 [GIT PULL 00/30] perf/core improvements and fixes Arnaldo Carvalho de Melo
` (19 preceding siblings ...)
2012-09-24 15:59 ` [PATCH 20/30] tools lib traceevent: Free field if an error occurs on process_fields Arnaldo Carvalho de Melo
@ 2012-09-24 15:59 ` Arnaldo Carvalho de Melo
2012-09-24 15:59 ` [PATCH 22/30] perf tools: bfd.h/libbfd detection fails with recent binutils Arnaldo Carvalho de Melo
` (8 subsequent siblings)
29 siblings, 0 replies; 41+ messages in thread
From: Arnaldo Carvalho de Melo @ 2012-09-24 15:59 UTC (permalink / raw)
To: Ingo Molnar
Cc: linux-kernel, Namhyung Kim, Namhyung Kim, Frederic Weisbecker,
Peter Zijlstra, Steven Rostedt, Arnaldo Carvalho de Melo
From: Namhyung Kim <namhyung.kim@lge.com>
The field should be freed on error paths.
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Steven Rostedt <rostedt@goodmis.org>
Link: http://lkml.kernel.org/r/1348037924-17568-5-git-send-email-namhyung@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
tools/lib/traceevent/event-parse.c | 12 ++++++++----
1 files changed, 8 insertions(+), 4 deletions(-)
diff --git a/tools/lib/traceevent/event-parse.c b/tools/lib/traceevent/event-parse.c
index a776ed5..acf4038 100644
--- a/tools/lib/traceevent/event-parse.c
+++ b/tools/lib/traceevent/event-parse.c
@@ -2247,7 +2247,7 @@ process_flags(struct event_format *event, struct print_arg *arg, char **tok)
type = process_op(event, field, &token);
if (test_type_token(type, token, EVENT_DELIM, ","))
- goto out_free;
+ goto out_free_field;
free_token(token);
arg->flags.field = field;
@@ -2269,7 +2269,9 @@ process_flags(struct event_format *event, struct print_arg *arg, char **tok)
type = read_token_item(tok);
return type;
- out_free:
+out_free_field:
+ free_arg(field);
+out_free:
free_token(token);
*tok = NULL;
return EVENT_ERROR;
@@ -2289,7 +2291,7 @@ process_symbols(struct event_format *event, struct print_arg *arg, char **tok)
type = process_arg(event, field, &token);
if (test_type_token(type, token, EVENT_DELIM, ","))
- goto out_free;
+ goto out_free_field;
arg->symbol.field = field;
@@ -2301,7 +2303,9 @@ process_symbols(struct event_format *event, struct print_arg *arg, char **tok)
type = read_token_item(tok);
return type;
- out_free:
+out_free_field:
+ free_arg(field);
+out_free:
free_token(token);
*tok = NULL;
return EVENT_ERROR;
--
1.7.1
^ permalink raw reply related [flat|nested] 41+ messages in thread
* [PATCH 22/30] perf tools: bfd.h/libbfd detection fails with recent binutils
2012-09-24 15:59 [GIT PULL 00/30] perf/core improvements and fixes Arnaldo Carvalho de Melo
` (20 preceding siblings ...)
2012-09-24 15:59 ` [PATCH 21/30] tools lib traceevent: Free field if an error occurs on process_flags/symbols Arnaldo Carvalho de Melo
@ 2012-09-24 15:59 ` Arnaldo Carvalho de Melo
2012-09-24 23:58 ` Mike Frysinger
2012-09-24 15:59 ` [PATCH 23/30] tools lib traceevent: Use asprintf were applicable Arnaldo Carvalho de Melo
` (7 subsequent siblings)
29 siblings, 1 reply; 41+ messages in thread
From: Arnaldo Carvalho de Melo @ 2012-09-24 15:59 UTC (permalink / raw)
To: Ingo Molnar
Cc: linux-kernel, Markus Trippelsdorf, Ingo Molnar, Mike Frysinger,
Paul Mackerras, Arnaldo Carvalho de Melo
From: Markus Trippelsdorf <markus@trippelsdorf.de>
With recent binutils I get:
perf % make
Makefile:668: No bfd.h/libbfd found, install binutils-dev[el]/zlib-static to gain symbol demanglin
That happens because bfd.h now contains:
I've reopened a bug in the hope that this check will be deleted:
http://sourceware.org/bugzilla/show_bug.cgi?id=14243
But in the meantime, the following patch fixes the problem
Signed-off-by: Markus Trippelsdorf <markus@trippelsdorf.de>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Mike Frysinger <vapier@gentoo.org>
Cc: Paul Mackerras <paulus@samba.org>
Link: http://lkml.kernel.org/r/20120919072902.GA262@x4
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
tools/perf/Makefile | 2 +-
tools/perf/util/symbol.h | 1 +
2 files changed, 2 insertions(+), 1 deletions(-)
diff --git a/tools/perf/Makefile b/tools/perf/Makefile
index 3ae6a59..251dcd7 100644
--- a/tools/perf/Makefile
+++ b/tools/perf/Makefile
@@ -715,7 +715,7 @@ else
EXTLIBS += -liberty
BASIC_CFLAGS += -DHAVE_CPLUS_DEMANGLE
else
- FLAGS_BFD=$(ALL_CFLAGS) $(ALL_LDFLAGS) $(EXTLIBS) -lbfd
+ FLAGS_BFD=$(ALL_CFLAGS) $(ALL_LDFLAGS) $(EXTLIBS) -DPACKAGE='perf' -lbfd
has_bfd := $(call try-cc,$(SOURCE_BFD),$(FLAGS_BFD))
ifeq ($(has_bfd),y)
EXTLIBS += -lbfd
diff --git a/tools/perf/util/symbol.h b/tools/perf/util/symbol.h
index 4ff45e3..b441b07 100644
--- a/tools/perf/util/symbol.h
+++ b/tools/perf/util/symbol.h
@@ -34,6 +34,7 @@ static inline char *bfd_demangle(void __maybe_unused *v,
return NULL;
}
#else
+#define PACKAGE 'perf'
#include <bfd.h>
#endif
#endif
--
1.7.1
^ permalink raw reply related [flat|nested] 41+ messages in thread
* [PATCH 23/30] tools lib traceevent: Use asprintf were applicable
2012-09-24 15:59 [GIT PULL 00/30] perf/core improvements and fixes Arnaldo Carvalho de Melo
` (21 preceding siblings ...)
2012-09-24 15:59 ` [PATCH 22/30] perf tools: bfd.h/libbfd detection fails with recent binutils Arnaldo Carvalho de Melo
@ 2012-09-24 15:59 ` Arnaldo Carvalho de Melo
2012-09-24 15:59 ` [PATCH 24/30] tools lib traceevent: Use calloc " Arnaldo Carvalho de Melo
` (6 subsequent siblings)
29 siblings, 0 replies; 41+ messages in thread
From: Arnaldo Carvalho de Melo @ 2012-09-24 15:59 UTC (permalink / raw)
To: Ingo Molnar
Cc: linux-kernel, Arnaldo Carvalho de Melo, David Ahern,
Frederic Weisbecker, Jiri Olsa, Mike Galbraith, Namhyung Kim,
Paul Mackerras, Peter Zijlstra, Stephane Eranian, Steven Rostedt
From: Arnaldo Carvalho de Melo <acme@redhat.com>
Replacing the equivalent open coded malloc + sprintf bits.
Reviewed-by: Namhyung Kim <namhyung@kernel.org>
Cc: David Ahern <dsahern@gmail.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Namhyung Kim <namhyung@gmail.com>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Cc: Steven Rostedt <rostedt@goodmis.org>
Link: http://lkml.kernel.org/n/tip-ghokwtdw2hgmmmn7oa9s03r4@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
tools/lib/traceevent/event-parse.c | 58 +++++++++++++++++++----------------
1 files changed, 31 insertions(+), 27 deletions(-)
diff --git a/tools/lib/traceevent/event-parse.c b/tools/lib/traceevent/event-parse.c
index acf4038..2e05d56 100644
--- a/tools/lib/traceevent/event-parse.c
+++ b/tools/lib/traceevent/event-parse.c
@@ -827,9 +827,9 @@ static enum event_type __read_token(char **tok)
switch (type) {
case EVENT_NEWLINE:
case EVENT_DELIM:
- *tok = malloc_or_die(2);
- (*tok)[0] = ch;
- (*tok)[1] = 0;
+ if (asprintf(tok, "%c", ch) < 0)
+ return EVENT_ERROR;
+
return type;
case EVENT_OP:
@@ -2777,10 +2777,8 @@ static int event_read_print(struct event_format *event)
if (type == EVENT_DQUOTE) {
char *cat;
- cat = malloc_or_die(strlen(event->print_fmt.format) +
- strlen(token) + 1);
- strcpy(cat, event->print_fmt.format);
- strcat(cat, token);
+ if (asprintf(&cat, "%s%s", event->print_fmt.format, token) < 0)
+ goto fail;
free_token(token);
free_token(event->print_fmt.format);
event->print_fmt.format = NULL;
@@ -3524,6 +3522,18 @@ process_defined_func(struct trace_seq *s, void *data, int size,
return ret;
}
+static void free_args(struct print_arg *args)
+{
+ struct print_arg *next;
+
+ while (args) {
+ next = args->next;
+
+ free_arg(args);
+ args = next;
+ }
+}
+
static struct print_arg *make_bprint_args(char *fmt, void *data, int size, struct event_format *event)
{
struct pevent *pevent = event->pevent;
@@ -3559,8 +3569,9 @@ static struct print_arg *make_bprint_args(char *fmt, void *data, int size, struc
next = &arg->next;
arg->type = PRINT_ATOM;
- arg->atom.atom = malloc_or_die(32);
- sprintf(arg->atom.atom, "%lld", ip);
+
+ if (asprintf(&arg->atom.atom, "%lld", ip) < 0)
+ goto out_free;
/* skip the first "%pf : " */
for (ptr = fmt + 6, bptr = data + field->offset;
@@ -3617,8 +3628,10 @@ static struct print_arg *make_bprint_args(char *fmt, void *data, int size, struc
arg = alloc_arg();
arg->next = NULL;
arg->type = PRINT_ATOM;
- arg->atom.atom = malloc_or_die(32);
- sprintf(arg->atom.atom, "%lld", val);
+ if (asprintf(&arg->atom.atom, "%lld", val) < 0) {
+ free(arg);
+ goto out_free;
+ }
*next = arg;
next = &arg->next;
/*
@@ -3646,18 +3659,10 @@ static struct print_arg *make_bprint_args(char *fmt, void *data, int size, struc
}
return args;
-}
-
-static void free_args(struct print_arg *args)
-{
- struct print_arg *next;
-
- while (args) {
- next = args->next;
- free_arg(args);
- args = next;
- }
+out_free:
+ free_args(args);
+ return NULL;
}
static char *
@@ -3684,9 +3689,8 @@ get_bprint_format(void *data, int size __maybe_unused,
printk = find_printk(pevent, addr);
if (!printk) {
- format = malloc_or_die(45);
- sprintf(format, "%%pf : (NO FORMAT FOUND at %llx)\n",
- addr);
+ if (asprintf(&format, "%%pf : (NO FORMAT FOUND at %llx)\n", addr) < 0)
+ return NULL;
return format;
}
@@ -3694,8 +3698,8 @@ get_bprint_format(void *data, int size __maybe_unused,
/* Remove any quotes. */
if (*p == '"')
p++;
- format = malloc_or_die(strlen(p) + 10);
- sprintf(format, "%s : %s", "%pf", p);
+ if (asprintf(&format, "%s : %s", "%pf", p) < 0)
+ return NULL;
/* remove ending quotes and new line since we will add one too */
p = format + strlen(format) - 1;
if (*p == '"')
--
1.7.1
^ permalink raw reply related [flat|nested] 41+ messages in thread
* [PATCH 24/30] tools lib traceevent: Use calloc were applicable
2012-09-24 15:59 [GIT PULL 00/30] perf/core improvements and fixes Arnaldo Carvalho de Melo
` (22 preceding siblings ...)
2012-09-24 15:59 ` [PATCH 23/30] tools lib traceevent: Use asprintf were applicable Arnaldo Carvalho de Melo
@ 2012-09-24 15:59 ` Arnaldo Carvalho de Melo
2012-09-24 15:59 ` [PATCH 25/30] tools lib traceevent: Fix afterlife gotos Arnaldo Carvalho de Melo
` (5 subsequent siblings)
29 siblings, 0 replies; 41+ messages in thread
From: Arnaldo Carvalho de Melo @ 2012-09-24 15:59 UTC (permalink / raw)
To: Ingo Molnar
Cc: linux-kernel, Arnaldo Carvalho de Melo, David Ahern,
Frederic Weisbecker, Jiri Olsa, Mike Galbraith, Namhyung Kim,
Paul Mackerras, Peter Zijlstra, Stephane Eranian, Steven Rostedt
From: Arnaldo Carvalho de Melo <acme@redhat.com>
Replacing the equivalent open coded malloc + memset bits.
Reviewed-by: Namhyung Kim <namhyung@kernel.org>
Cc: David Ahern <dsahern@gmail.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Namhyung Kim <namhyung@gmail.com>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Cc: Steven Rostedt <rostedt@goodmis.org>
Link: http://lkml.kernel.org/n/tip-598fjtjbzal4wxh7fp0yv0q1@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
tools/lib/traceevent/event-parse.c | 44 +++++++++++------------------------
1 files changed, 14 insertions(+), 30 deletions(-)
diff --git a/tools/lib/traceevent/event-parse.c b/tools/lib/traceevent/event-parse.c
index 2e05d56..2aeae55 100644
--- a/tools/lib/traceevent/event-parse.c
+++ b/tools/lib/traceevent/event-parse.c
@@ -117,14 +117,7 @@ void breakpoint(void)
struct print_arg *alloc_arg(void)
{
- struct print_arg *arg;
-
- arg = malloc_or_die(sizeof(*arg));
- if (!arg)
- return NULL;
- memset(arg, 0, sizeof(*arg));
-
- return arg;
+ return calloc(1, sizeof(struct print_arg));
}
struct cmdline {
@@ -619,14 +612,7 @@ void pevent_print_printk(struct pevent *pevent)
static struct event_format *alloc_event(void)
{
- struct event_format *event;
-
- event = malloc(sizeof(*event));
- if (!event)
- return NULL;
- memset(event, 0, sizeof(*event));
-
- return event;
+ return calloc(1, sizeof(struct event_format));
}
static void add_event(struct pevent *pevent, struct event_format *event)
@@ -1240,8 +1226,10 @@ static int event_read_fields(struct event_format *event, struct format_field **f
last_token = token;
- field = malloc_or_die(sizeof(*field));
- memset(field, 0, sizeof(*field));
+ field = calloc(1, sizeof(*field));
+ if (!field)
+ goto fail;
+
field->event = event;
/* read the rest of the type */
@@ -2181,8 +2169,9 @@ process_fields(struct event_format *event, struct print_flag_sym **list, char **
if (test_type_token(type, token, EVENT_DELIM, ","))
goto out_free;
- field = malloc_or_die(sizeof(*field));
- memset(field, 0, sizeof(*field));
+ field = calloc(1, sizeof(*field));
+ if (!field)
+ goto out_free;
value = arg_eval(arg);
if (value == NULL)
@@ -5106,12 +5095,11 @@ int pevent_register_print_function(struct pevent *pevent,
remove_func_handler(pevent, name);
}
- func_handle = malloc(sizeof(*func_handle));
+ func_handle = calloc(1, sizeof(*func_handle));
if (!func_handle) {
do_warning("Failed to allocate function handler");
return PEVENT_ERRNO__MEM_ALLOC_FAILED;
}
- memset(func_handle, 0, sizeof(*func_handle));
func_handle->ret_type = ret_type;
func_handle->name = strdup(name);
@@ -5210,13 +5198,12 @@ int pevent_register_event_handler(struct pevent *pevent,
not_found:
/* Save for later use. */
- handle = malloc(sizeof(*handle));
+ handle = calloc(1, sizeof(*handle));
if (!handle) {
do_warning("Failed to allocate event handler");
return PEVENT_ERRNO__MEM_ALLOC_FAILED;
}
- memset(handle, 0, sizeof(*handle));
handle->id = id;
if (event_name)
handle->event_name = strdup(event_name);
@@ -5245,13 +5232,10 @@ int pevent_register_event_handler(struct pevent *pevent,
*/
struct pevent *pevent_alloc(void)
{
- struct pevent *pevent;
+ struct pevent *pevent = calloc(1, sizeof(*pevent));
- pevent = malloc(sizeof(*pevent));
- if (!pevent)
- return NULL;
- memset(pevent, 0, sizeof(*pevent));
- pevent->ref_count = 1;
+ if (pevent)
+ pevent->ref_count = 1;
return pevent;
}
--
1.7.1
^ permalink raw reply related [flat|nested] 41+ messages in thread
* [PATCH 25/30] tools lib traceevent: Fix afterlife gotos
2012-09-24 15:59 [GIT PULL 00/30] perf/core improvements and fixes Arnaldo Carvalho de Melo
` (23 preceding siblings ...)
2012-09-24 15:59 ` [PATCH 24/30] tools lib traceevent: Use calloc " Arnaldo Carvalho de Melo
@ 2012-09-24 15:59 ` Arnaldo Carvalho de Melo
2012-09-24 15:59 ` [PATCH 26/30] tools lib traceevent: Remove some die() calls Arnaldo Carvalho de Melo
` (4 subsequent siblings)
29 siblings, 0 replies; 41+ messages in thread
From: Arnaldo Carvalho de Melo @ 2012-09-24 15:59 UTC (permalink / raw)
To: Ingo Molnar
Cc: linux-kernel, Arnaldo Carvalho de Melo, David Ahern,
Frederic Weisbecker, Jiri Olsa, Mike Galbraith, Namhyung Kim,
Paul Mackerras, Peter Zijlstra, Stephane Eranian, Steven Rostedt
From: Arnaldo Carvalho de Melo <acme@redhat.com>
Instead of dying, just use do_warning and let the goto that is there to
take place.
Reviewed-by: Namhyung Kim <namhyung@kernel.org>
Cc: David Ahern <dsahern@gmail.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Namhyung Kim <namhyung@gmail.com>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Cc: Steven Rostedt <rostedt@goodmis.org>
Link: http://lkml.kernel.org/n/tip-aoaus46ngnt9oc2pt7ckot5d@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
tools/lib/traceevent/event-parse.c | 6 +++---
1 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/tools/lib/traceevent/event-parse.c b/tools/lib/traceevent/event-parse.c
index 2aeae55..2091991 100644
--- a/tools/lib/traceevent/event-parse.c
+++ b/tools/lib/traceevent/event-parse.c
@@ -1270,7 +1270,7 @@ static int event_read_fields(struct event_format *event, struct format_field **f
}
if (!field->type) {
- die("no type found");
+ do_warning("%s: no type found", __func__);
goto fail;
}
field->name = last_token;
@@ -1317,7 +1317,7 @@ static int event_read_fields(struct event_format *event, struct format_field **f
free_token(token);
type = read_token(&token);
if (type == EVENT_NONE) {
- die("failed to find token");
+ do_warning("failed to find token");
goto fail;
}
}
@@ -1669,7 +1669,7 @@ process_op(struct event_format *event, struct print_arg *arg, char **tok)
if (arg->type == PRINT_OP && !arg->op.left) {
/* handle single op */
if (token[1]) {
- die("bad op token %s", token);
+ do_warning("bad op token %s", token);
goto out_free;
}
switch (token[0]) {
--
1.7.1
^ permalink raw reply related [flat|nested] 41+ messages in thread
* [PATCH 26/30] tools lib traceevent: Remove some die() calls
2012-09-24 15:59 [GIT PULL 00/30] perf/core improvements and fixes Arnaldo Carvalho de Melo
` (24 preceding siblings ...)
2012-09-24 15:59 ` [PATCH 25/30] tools lib traceevent: Fix afterlife gotos Arnaldo Carvalho de Melo
@ 2012-09-24 15:59 ` Arnaldo Carvalho de Melo
2012-09-24 15:59 ` [PATCH 27/30] tools lib traceevent: Carve out events format parsing routine Arnaldo Carvalho de Melo
` (3 subsequent siblings)
29 siblings, 0 replies; 41+ messages in thread
From: Arnaldo Carvalho de Melo @ 2012-09-24 15:59 UTC (permalink / raw)
To: Ingo Molnar
Cc: linux-kernel, Arnaldo Carvalho de Melo, David Ahern,
Frederic Weisbecker, Jiri Olsa, Mike Galbraith, Namhyung Kim,
Paul Mackerras, Peter Zijlstra, Stephane Eranian, Steven Rostedt
From: Arnaldo Carvalho de Melo <acme@redhat.com>
Cleaned event-parse.c this time, just propagate the errors and in handle
them the call sites.
Reviewed-by: Namhyung Kim <namhyung@kernel.org>
Cc: David Ahern <dsahern@gmail.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Namhyung Kim <namhyung@gmail.com>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Cc: Steven Rostedt <rostedt@goodmis.org>
Link: http://lkml.kernel.org/n/tip-9ebpr2vgfk2qs2841i99sa8y@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
tools/lib/traceevent/event-parse.c | 249 +++++++++++++++++++++++++-----------
1 files changed, 175 insertions(+), 74 deletions(-)
diff --git a/tools/lib/traceevent/event-parse.c b/tools/lib/traceevent/event-parse.c
index 2091991..b3bc130 100644
--- a/tools/lib/traceevent/event-parse.c
+++ b/tools/lib/traceevent/event-parse.c
@@ -31,6 +31,7 @@
#include <ctype.h>
#include <errno.h>
#include <stdint.h>
+#include <limits.h>
#include "event-parse.h"
#include "event-utils.h"
@@ -151,7 +152,9 @@ static int cmdline_init(struct pevent *pevent)
struct cmdline *cmdlines;
int i;
- cmdlines = malloc_or_die(sizeof(*cmdlines) * pevent->cmdline_count);
+ cmdlines = malloc(sizeof(*cmdlines) * pevent->cmdline_count);
+ if (!cmdlines)
+ return -1;
i = 0;
while (cmdlist) {
@@ -179,8 +182,8 @@ static char *find_cmdline(struct pevent *pevent, int pid)
if (!pid)
return "<idle>";
- if (!pevent->cmdlines)
- cmdline_init(pevent);
+ if (!pevent->cmdlines && cmdline_init(pevent))
+ return "<not enough memory for cmdlines!>";
key.pid = pid;
@@ -208,8 +211,8 @@ int pevent_pid_is_registered(struct pevent *pevent, int pid)
if (!pid)
return 1;
- if (!pevent->cmdlines)
- cmdline_init(pevent);
+ if (!pevent->cmdlines && cmdline_init(pevent))
+ return 0;
key.pid = pid;
@@ -251,10 +254,14 @@ static int add_new_comm(struct pevent *pevent, const char *comm, int pid)
return -1;
}
- cmdlines[pevent->cmdline_count].pid = pid;
cmdlines[pevent->cmdline_count].comm = strdup(comm);
- if (!cmdlines[pevent->cmdline_count].comm)
- die("malloc comm");
+ if (!cmdlines[pevent->cmdline_count].comm) {
+ free(cmdlines);
+ errno = ENOMEM;
+ return -1;
+ }
+
+ cmdlines[pevent->cmdline_count].pid = pid;
if (cmdlines[pevent->cmdline_count].comm)
pevent->cmdline_count++;
@@ -281,10 +288,15 @@ int pevent_register_comm(struct pevent *pevent, const char *comm, int pid)
if (pevent->cmdlines)
return add_new_comm(pevent, comm, pid);
- item = malloc_or_die(sizeof(*item));
+ item = malloc(sizeof(*item));
+ if (!item)
+ return -1;
+
item->comm = strdup(comm);
- if (!item->comm)
- die("malloc comm");
+ if (!item->comm) {
+ free(item);
+ return -1;
+ }
item->pid = pid;
item->next = pevent->cmdlist;
@@ -348,7 +360,10 @@ static int func_map_init(struct pevent *pevent)
struct func_map *func_map;
int i;
- func_map = malloc_or_die(sizeof(*func_map) * (pevent->func_count + 1));
+ func_map = malloc(sizeof(*func_map) * (pevent->func_count + 1));
+ if (!func_map)
+ return -1;
+
funclist = pevent->funclist;
i = 0;
@@ -448,25 +463,36 @@ pevent_find_function_address(struct pevent *pevent, unsigned long long addr)
int pevent_register_function(struct pevent *pevent, char *func,
unsigned long long addr, char *mod)
{
- struct func_list *item;
+ struct func_list *item = malloc(sizeof(*item));
- item = malloc_or_die(sizeof(*item));
+ if (!item)
+ return -1;
item->next = pevent->funclist;
item->func = strdup(func);
- if (mod)
+ if (!item->func)
+ goto out_free;
+
+ if (mod) {
item->mod = strdup(mod);
- else
+ if (!item->mod)
+ goto out_free_func;
+ } else
item->mod = NULL;
item->addr = addr;
- if (!item->func || (mod && !item->mod))
- die("malloc func");
-
pevent->funclist = item;
pevent->func_count++;
return 0;
+
+out_free_func:
+ free(item->func);
+ item->func = NULL;
+out_free:
+ free(item);
+ errno = ENOMEM;
+ return -1;
}
/**
@@ -517,14 +543,16 @@ static int printk_cmp(const void *a, const void *b)
return 0;
}
-static void printk_map_init(struct pevent *pevent)
+static int printk_map_init(struct pevent *pevent)
{
struct printk_list *printklist;
struct printk_list *item;
struct printk_map *printk_map;
int i;
- printk_map = malloc_or_die(sizeof(*printk_map) * (pevent->printk_count + 1));
+ printk_map = malloc(sizeof(*printk_map) * (pevent->printk_count + 1));
+ if (!printk_map)
+ return -1;
printklist = pevent->printklist;
@@ -542,6 +570,8 @@ static void printk_map_init(struct pevent *pevent)
pevent->printk_map = printk_map;
pevent->printklist = NULL;
+
+ return 0;
}
static struct printk_map *
@@ -550,8 +580,8 @@ find_printk(struct pevent *pevent, unsigned long long addr)
struct printk_map *printk;
struct printk_map key;
- if (!pevent->printk_map)
- printk_map_init(pevent);
+ if (!pevent->printk_map && printk_map_init(pevent))
+ return NULL;
key.addr = addr;
@@ -573,21 +603,27 @@ find_printk(struct pevent *pevent, unsigned long long addr)
int pevent_register_print_string(struct pevent *pevent, char *fmt,
unsigned long long addr)
{
- struct printk_list *item;
+ struct printk_list *item = malloc(sizeof(*item));
- item = malloc_or_die(sizeof(*item));
+ if (!item)
+ return -1;
item->next = pevent->printklist;
- item->printk = strdup(fmt);
item->addr = addr;
+ item->printk = strdup(fmt);
if (!item->printk)
- die("malloc fmt");
+ goto out_free;
pevent->printklist = item;
pevent->printk_count++;
return 0;
+
+out_free:
+ free(item);
+ errno = ENOMEM;
+ return -1;
}
/**
@@ -615,14 +651,15 @@ static struct event_format *alloc_event(void)
return calloc(1, sizeof(struct event_format));
}
-static void add_event(struct pevent *pevent, struct event_format *event)
+static int add_event(struct pevent *pevent, struct event_format *event)
{
int i;
+ struct event_format **events = realloc(pevent->events, sizeof(event) *
+ (pevent->nr_events + 1));
+ if (!events)
+ return -1;
- pevent->events = realloc(pevent->events, sizeof(event) *
- (pevent->nr_events + 1));
- if (!pevent->events)
- die("Can not allocate events");
+ pevent->events = events;
for (i = 0; i < pevent->nr_events; i++) {
if (pevent->events[i]->id > event->id)
@@ -637,6 +674,8 @@ static void add_event(struct pevent *pevent, struct event_format *event)
pevent->nr_events++;
event->pevent = pevent;
+
+ return 0;
}
static int event_item_type(enum event_type type)
@@ -1751,8 +1790,10 @@ process_op(struct event_format *event, struct print_arg *arg, char **tok)
type == EVENT_DELIM && (strcmp(token, ")") == 0)) {
char *new_atom;
- if (left->type != PRINT_ATOM)
- die("bad pointer type");
+ if (left->type != PRINT_ATOM) {
+ do_warning("bad pointer type");
+ goto out_free;
+ }
new_atom = realloc(left->atom.atom,
strlen(left->atom.atom) + 3);
if (!new_atom)
@@ -1870,7 +1911,11 @@ eval_type_str(unsigned long long val, const char *type, int pointer)
return val;
}
- ref = malloc_or_die(len);
+ ref = malloc(len);
+ if (!ref) {
+ do_warning("%s: not enough memory!", __func__);
+ return val;
+ }
memcpy(ref, type, len);
/* chop off the " *" */
@@ -1947,8 +1992,10 @@ eval_type_str(unsigned long long val, const char *type, int pointer)
static unsigned long long
eval_type(unsigned long long val, struct print_arg *arg, int pointer)
{
- if (arg->type != PRINT_TYPE)
- die("expected type argument");
+ if (arg->type != PRINT_TYPE) {
+ do_warning("expected type argument");
+ return 0;
+ }
return eval_type_str(val, arg->typecast.type, pointer);
}
@@ -2133,7 +2180,7 @@ static char *arg_eval (struct print_arg *arg)
case PRINT_STRING:
case PRINT_BSTRING:
default:
- die("invalid eval type %d", arg->type);
+ do_warning("invalid eval type %d", arg->type);
break;
}
@@ -2431,8 +2478,10 @@ process_paren(struct event_format *event, struct print_arg *arg, char **tok)
/* make this a typecast and contine */
/* prevous must be an atom */
- if (arg->type != PRINT_ATOM)
- die("previous needed to be PRINT_ATOM");
+ if (arg->type != PRINT_ATOM) {
+ do_warning("previous needed to be PRINT_ATOM");
+ goto out_free;
+ }
item_arg = alloc_arg();
@@ -2674,7 +2723,8 @@ process_arg_token(struct event_format *event, struct print_arg *arg,
case EVENT_ERROR ... EVENT_NEWLINE:
default:
- die("unexpected type %d", type);
+ do_warning("unexpected type %d", type);
+ return EVENT_ERROR;
}
*tok = token;
@@ -2921,8 +2971,10 @@ static int get_common_info(struct pevent *pevent,
* All events should have the same common elements.
* Pick any event to find where the type is;
*/
- if (!pevent->events)
- die("no event_list!");
+ if (!pevent->events) {
+ do_warning("no event_list!");
+ return -1;
+ }
event = pevent->events[0];
field = pevent_find_common_field(event, type);
@@ -3080,7 +3132,8 @@ eval_num_arg(void *data, int size, struct event_format *event, struct print_arg
if (!arg->field.field) {
arg->field.field = pevent_find_any_field(event, arg->field.name);
if (!arg->field.field)
- die("field %s not found", arg->field.name);
+ goto out_warning_field;
+
}
/* must be a number */
val = pevent_read_number(pevent, data + arg->field.field->offset,
@@ -3141,8 +3194,10 @@ eval_num_arg(void *data, int size, struct event_format *event, struct print_arg
if (!larg->field.field) {
larg->field.field =
pevent_find_any_field(event, larg->field.name);
- if (!larg->field.field)
- die("field %s not found", larg->field.name);
+ if (!larg->field.field) {
+ arg = larg;
+ goto out_warning_field;
+ }
}
field_size = larg->field.field->elementsize;
offset = larg->field.field->offset +
@@ -3178,7 +3233,7 @@ eval_num_arg(void *data, int size, struct event_format *event, struct print_arg
val = left != right;
break;
default:
- die("unknown op '%s'", arg->op.op);
+ goto out_warning_op;
}
break;
case '~':
@@ -3208,7 +3263,7 @@ eval_num_arg(void *data, int size, struct event_format *event, struct print_arg
val = left <= right;
break;
default:
- die("unknown op '%s'", arg->op.op);
+ goto out_warning_op;
}
break;
case '>':
@@ -3223,12 +3278,13 @@ eval_num_arg(void *data, int size, struct event_format *event, struct print_arg
val = left >= right;
break;
default:
- die("unknown op '%s'", arg->op.op);
+ goto out_warning_op;
}
break;
case '=':
if (arg->op.op[1] != '=')
- die("unknown op '%s'", arg->op.op);
+ goto out_warning_op;
+
val = left == right;
break;
case '-':
@@ -3244,13 +3300,21 @@ eval_num_arg(void *data, int size, struct event_format *event, struct print_arg
val = left * right;
break;
default:
- die("unknown op '%s'", arg->op.op);
+ goto out_warning_op;
}
break;
default: /* not sure what to do there */
return 0;
}
return val;
+
+out_warning_op:
+ do_warning("%s: unknown op '%s'", __func__, arg->op.op);
+ return 0;
+
+out_warning_field:
+ do_warning("%s: field %s not found", __func__, arg->field.name);
+ return 0;
}
struct flag {
@@ -3327,8 +3391,10 @@ static void print_str_arg(struct trace_seq *s, void *data, int size,
field = arg->field.field;
if (!field) {
field = pevent_find_any_field(event, arg->field.name);
- if (!field)
- die("field %s not found", arg->field.name);
+ if (!field) {
+ str = arg->field.name;
+ goto out_warning_field;
+ }
arg->field.field = field;
}
/* Zero sized fields, mean the rest of the data */
@@ -3345,7 +3411,11 @@ static void print_str_arg(struct trace_seq *s, void *data, int size,
trace_seq_printf(s, "%lx", addr);
break;
}
- str = malloc_or_die(len + 1);
+ str = malloc(len + 1);
+ if (!str) {
+ do_warning("%s: not enough memory!", __func__);
+ return;
+ }
memcpy(str, data + field->offset, len);
str[len] = 0;
print_str_to_seq(s, format, len_arg, str);
@@ -3385,7 +3455,7 @@ static void print_str_arg(struct trace_seq *s, void *data, int size,
str = arg->hex.field->field.name;
field = pevent_find_any_field(event, str);
if (!field)
- die("field %s not found", str);
+ goto out_warning_field;
arg->hex.field->field.field = field;
}
hex = data + field->offset;
@@ -3437,6 +3507,11 @@ static void print_str_arg(struct trace_seq *s, void *data, int size,
/* well... */
break;
}
+
+ return;
+
+out_warning_field:
+ do_warning("%s: field %s not found", __func__, arg->field.name);
}
static unsigned long long
@@ -3463,7 +3538,11 @@ process_defined_func(struct trace_seq *s, void *data, int size,
farg = arg->func.args;
param = func_handle->params;
- args = malloc_or_die(sizeof(*args) * func_handle->nr_args);
+ ret = ULLONG_MAX;
+ args = malloc(sizeof(*args) * func_handle->nr_args);
+ if (!args)
+ goto out;
+
for (i = 0; i < func_handle->nr_args; i++) {
switch (param->type) {
case PEVENT_FUNC_ARG_INT:
@@ -3475,12 +3554,18 @@ process_defined_func(struct trace_seq *s, void *data, int size,
trace_seq_init(&str);
print_str_arg(&str, data, size, event, "%s", -1, farg);
trace_seq_terminate(&str);
- string = malloc_or_die(sizeof(*string));
+ string = malloc(sizeof(*string));
+ if (!string) {
+ do_warning("%s(%d): malloc str", __func__, __LINE__);
+ goto out_free;
+ }
string->next = strings;
string->str = strdup(str.buffer);
- if (!string->str)
- die("malloc str");
-
+ if (!string->str) {
+ free(string);
+ do_warning("%s(%d): malloc str", __func__, __LINE__);
+ goto out_free;
+ }
args[i] = (uintptr_t)string->str;
strings = string;
trace_seq_destroy(&str);
@@ -3490,14 +3575,15 @@ process_defined_func(struct trace_seq *s, void *data, int size,
* Something went totally wrong, this is not
* an input error, something in this code broke.
*/
- die("Unexpected end of arguments\n");
- break;
+ do_warning("Unexpected end of arguments\n");
+ goto out_free;
}
farg = farg->next;
param = param->next;
}
ret = (*func_handle->func)(s, args);
+out_free:
free(args);
while (strings) {
string = strings;
@@ -3538,11 +3624,15 @@ static struct print_arg *make_bprint_args(char *fmt, void *data, int size, struc
if (!field) {
field = pevent_find_field(event, "buf");
- if (!field)
- die("can't find buffer field for binary printk");
+ if (!field) {
+ do_warning("can't find buffer field for binary printk");
+ return NULL;
+ }
ip_field = pevent_find_field(event, "ip");
- if (!ip_field)
- die("can't find ip field for binary printk");
+ if (!ip_field) {
+ do_warning("can't find ip field for binary printk");
+ return NULL;
+ }
pevent->bprint_buf_field = field;
pevent->bprint_ip_field = ip_field;
}
@@ -3637,7 +3727,7 @@ static struct print_arg *make_bprint_args(char *fmt, void *data, int size, struc
arg->type = PRINT_BSTRING;
arg->string.string = strdup(bptr);
if (!arg->string.string)
- break;
+ goto out_free;
bptr += strlen(bptr) + 1;
*next = arg;
next = &arg->next;
@@ -3669,8 +3759,10 @@ get_bprint_format(void *data, int size __maybe_unused,
if (!field) {
field = pevent_find_field(event, "fmt");
- if (!field)
- die("can't find format field for binary printk");
+ if (!field) {
+ do_warning("can't find format field for binary printk");
+ return NULL;
+ }
pevent->bprint_fmt_field = field;
}
@@ -3723,8 +3815,11 @@ static void print_mac_arg(struct trace_seq *s, int mac, void *data, int size,
if (!arg->field.field) {
arg->field.field =
pevent_find_any_field(event, arg->field.name);
- if (!arg->field.field)
- die("field %s not found", arg->field.name);
+ if (!arg->field.field) {
+ do_warning("%s: field %s not found",
+ __func__, arg->field.name);
+ return;
+ }
}
if (arg->field.field->size != 6) {
trace_seq_printf(s, "INVALIDMAC");
@@ -4380,7 +4475,10 @@ get_event_fields(const char *type, const char *name,
struct format_field *field;
int i = 0;
- fields = malloc_or_die(sizeof(*fields) * (count + 1));
+ fields = malloc(sizeof(*fields) * (count + 1));
+ if (!fields)
+ return NULL;
+
for (field = list; field; field = field->next) {
fields[i++] = field;
if (i == count + 1) {
@@ -4775,7 +4873,8 @@ enum pevent_errno pevent_parse_event(struct pevent *pevent, const char *buf,
}
show_warning = 1;
- add_event(pevent, event);
+ if (add_event(pevent, event))
+ goto event_alloc_failed;
if (!ret && (event->flags & EVENT_FL_ISFTRACE)) {
struct format_field *field;
@@ -4808,7 +4907,9 @@ enum pevent_errno pevent_parse_event(struct pevent *pevent, const char *buf,
event_parse_failed:
event->flags |= EVENT_FL_FAILED;
/* still add it even if it failed */
- add_event(pevent, event);
+ if (add_event(pevent, event))
+ goto event_alloc_failed;
+
return ret;
event_alloc_failed:
--
1.7.1
^ permalink raw reply related [flat|nested] 41+ messages in thread
* [PATCH 27/30] tools lib traceevent: Carve out events format parsing routine
2012-09-24 15:59 [GIT PULL 00/30] perf/core improvements and fixes Arnaldo Carvalho de Melo
` (25 preceding siblings ...)
2012-09-24 15:59 ` [PATCH 26/30] tools lib traceevent: Remove some die() calls Arnaldo Carvalho de Melo
@ 2012-09-24 15:59 ` Arnaldo Carvalho de Melo
2012-09-25 4:15 ` Namhyung Kim
2012-09-24 15:59 ` [PATCH 28/30] perf evsel: Provide a new constructor for tracepoints Arnaldo Carvalho de Melo
` (2 subsequent siblings)
29 siblings, 1 reply; 41+ messages in thread
From: Arnaldo Carvalho de Melo @ 2012-09-24 15:59 UTC (permalink / raw)
To: Ingo Molnar
Cc: linux-kernel, Arnaldo Carvalho de Melo, David Ahern,
Frederic Weisbecker, Jiri Olsa, Mike Galbraith, Namhyung Kim,
Paul Mackerras, Peter Zijlstra, Stephane Eranian, Steven Rostedt
From: Arnaldo Carvalho de Melo <acme@redhat.com>
The pevent_parse_event() routine will parse a events/sys/tp/format file
and add an event_format instance to the pevent struct.
This patch introduces a pevent_parse_format() routine with just the bits
needed to parse the event/sys/tp/format file and just return the
event_format instance, useful for when all we want is to parse the
format file, without requiring the pevent struct.
Acked-by: Steven Rostedt <rostedt@goodmis.org>
Cc: David Ahern <dsahern@gmail.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Namhyung Kim <namhyung@gmail.com>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Cc: Steven Rostedt <rostedt@goodmis.org>
Link: http://lkml.kernel.org/n/tip-lge0afl47arh86om0m6a5bqr@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
tools/lib/traceevent/event-parse.c | 96 +++++++++++++++++++++++++++---------
tools/lib/traceevent/event-parse.h | 3 +
2 files changed, 75 insertions(+), 24 deletions(-)
diff --git a/tools/lib/traceevent/event-parse.c b/tools/lib/traceevent/event-parse.c
index b3bc130..1fa71ca 100644
--- a/tools/lib/traceevent/event-parse.c
+++ b/tools/lib/traceevent/event-parse.c
@@ -4794,8 +4794,7 @@ static int find_event_handle(struct pevent *pevent, struct event_format *event)
}
/**
- * pevent_parse_event - parse the event format
- * @pevent: the handle to the pevent
+ * __pevent_parse_format - parse the event format
* @buf: the buffer storing the event format string
* @size: the size of @buf
* @sys: the system the event belongs to
@@ -4807,15 +4806,16 @@ static int find_event_handle(struct pevent *pevent, struct event_format *event)
*
* /sys/kernel/debug/tracing/events/.../.../format
*/
-enum pevent_errno pevent_parse_event(struct pevent *pevent, const char *buf,
- unsigned long size, const char *sys)
+enum pevent_errno __pevent_parse_format(struct event_format **eventp,
+ struct pevent *pevent, const char *buf,
+ unsigned long size, const char *sys)
{
struct event_format *event;
int ret;
init_input_buf(buf, size);
- event = alloc_event();
+ *eventp = event = alloc_event();
if (!event)
return PEVENT_ERRNO__MEM_ALLOC_FAILED;
@@ -4849,9 +4849,6 @@ enum pevent_errno pevent_parse_event(struct pevent *pevent, const char *buf,
goto event_alloc_failed;
}
- /* Add pevent to event so that it can be referenced */
- event->pevent = pevent;
-
ret = event_read_format(event);
if (ret < 0) {
ret = PEVENT_ERRNO__READ_FORMAT_FAILED;
@@ -4862,19 +4859,16 @@ enum pevent_errno pevent_parse_event(struct pevent *pevent, const char *buf,
* If the event has an override, don't print warnings if the event
* print format fails to parse.
*/
- if (find_event_handle(pevent, event))
+ if (pevent && find_event_handle(pevent, event))
show_warning = 0;
ret = event_read_print(event);
+ show_warning = 1;
+
if (ret < 0) {
- show_warning = 1;
ret = PEVENT_ERRNO__READ_PRINT_FAILED;
goto event_parse_failed;
}
- show_warning = 1;
-
- if (add_event(pevent, event))
- goto event_alloc_failed;
if (!ret && (event->flags & EVENT_FL_ISFTRACE)) {
struct format_field *field;
@@ -4898,24 +4892,78 @@ enum pevent_errno pevent_parse_event(struct pevent *pevent, const char *buf,
return 0;
}
-#define PRINT_ARGS 0
- if (PRINT_ARGS && event->print_fmt.args)
- print_args(event->print_fmt.args);
-
return 0;
event_parse_failed:
event->flags |= EVENT_FL_FAILED;
- /* still add it even if it failed */
- if (add_event(pevent, event))
- goto event_alloc_failed;
-
return ret;
event_alloc_failed:
free(event->system);
free(event->name);
free(event);
+ *eventp = NULL;
+ return ret;
+}
+
+/**
+ * pevent_parse_format - parse the event format
+ * @buf: the buffer storing the event format string
+ * @size: the size of @buf
+ * @sys: the system the event belongs to
+ *
+ * This parses the event format and creates an event structure
+ * to quickly parse raw data for a given event.
+ *
+ * These files currently come from:
+ *
+ * /sys/kernel/debug/tracing/events/.../.../format
+ */
+enum pevent_errno pevent_parse_format(struct event_format **eventp, const char *buf,
+ unsigned long size, const char *sys)
+{
+ return __pevent_parse_format(eventp, NULL, buf, size, sys);
+}
+
+/**
+ * pevent_parse_event - parse the event format
+ * @pevent: the handle to the pevent
+ * @buf: the buffer storing the event format string
+ * @size: the size of @buf
+ * @sys: the system the event belongs to
+ *
+ * This parses the event format and creates an event structure
+ * to quickly parse raw data for a given event.
+ *
+ * These files currently come from:
+ *
+ * /sys/kernel/debug/tracing/events/.../.../format
+ */
+enum pevent_errno pevent_parse_event(struct pevent *pevent, const char *buf,
+ unsigned long size, const char *sys)
+{
+ struct event_format *event = NULL;
+ int ret = __pevent_parse_format(&event, pevent, buf, size, sys);
+
+ if (event == NULL)
+ return ret;
+
+ /* Add pevent to event so that it can be referenced */
+ event->pevent = pevent;
+
+ if (add_event(pevent, event))
+ goto event_add_failed;
+
+#define PRINT_ARGS 0
+ if (PRINT_ARGS && event->print_fmt.args)
+ print_args(event->print_fmt.args);
+
+ return 0;
+
+event_add_failed:
+ free(event->system);
+ free(event->name);
+ free(event);
return ret;
}
@@ -5365,7 +5413,7 @@ static void free_formats(struct format *format)
free_format_fields(format->fields);
}
-static void free_event(struct event_format *event)
+void pevent_free_format(struct event_format *event)
{
free(event->name);
free(event->system);
@@ -5451,7 +5499,7 @@ void pevent_free(struct pevent *pevent)
}
for (i = 0; i < pevent->nr_events; i++)
- free_event(pevent->events[i]);
+ pevent_free_format(pevent->events[i]);
while (pevent->handlers) {
handle = pevent->handlers;
diff --git a/tools/lib/traceevent/event-parse.h b/tools/lib/traceevent/event-parse.h
index a4bbe24..24a4bba 100644
--- a/tools/lib/traceevent/event-parse.h
+++ b/tools/lib/traceevent/event-parse.h
@@ -540,6 +540,9 @@ int pevent_parse_header_page(struct pevent *pevent, char *buf, unsigned long siz
enum pevent_errno pevent_parse_event(struct pevent *pevent, const char *buf,
unsigned long size, const char *sys);
+enum pevent_errno pevent_parse_format(struct event_format **eventp, const char *buf,
+ unsigned long size, const char *sys);
+void pevent_free_format(struct event_format *event);
void *pevent_get_field_raw(struct trace_seq *s, struct event_format *event,
const char *name, struct pevent_record *record,
--
1.7.1
^ permalink raw reply related [flat|nested] 41+ messages in thread
* [PATCH 28/30] perf evsel: Provide a new constructor for tracepoints
2012-09-24 15:59 [GIT PULL 00/30] perf/core improvements and fixes Arnaldo Carvalho de Melo
` (26 preceding siblings ...)
2012-09-24 15:59 ` [PATCH 27/30] tools lib traceevent: Carve out events format parsing routine Arnaldo Carvalho de Melo
@ 2012-09-24 15:59 ` Arnaldo Carvalho de Melo
2012-09-25 4:26 ` Namhyung Kim
2012-09-24 15:59 ` [PATCH 29/30] perf test: Add test for the sched tracepoint format fields Arnaldo Carvalho de Melo
2012-09-24 15:59 ` [PATCH 30/30] tools lib traceevent: Handle alloc_arg failure Arnaldo Carvalho de Melo
29 siblings, 1 reply; 41+ messages in thread
From: Arnaldo Carvalho de Melo @ 2012-09-24 15:59 UTC (permalink / raw)
To: Ingo Molnar
Cc: linux-kernel, Arnaldo Carvalho de Melo, David Ahern,
Frederic Weisbecker, Jiri Olsa, Mike Galbraith, Namhyung Kim,
Paul Mackerras, Peter Zijlstra, Stephane Eranian, Steven Rostedt
From: Arnaldo Carvalho de Melo <acme@redhat.com>
The existing constructor receives a perf_event_attr filled with the
event type and the config.
To reduce the boilerplate for tracepoints, provide a new constructor,
perf_evsel__newtp() that receives the tracepoint name and will open
the debugfs file, call into libtraceevent new pevent_parse_format file
to fill its ->tp_format member, so that users can then just call
perf_evsel__field() to access its fields.
Cc: David Ahern <dsahern@gmail.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Namhyung Kim <namhyung@gmail.com>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Cc: Steven Rostedt <rostedt@goodmis.org>
Link: http://lkml.kernel.org/n/tip-6du8dl1hz0y5l4cybodye7hn@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
tools/perf/util/evsel.c | 88 +++++++++++++++++++++++++++++++++++++++++++---
tools/perf/util/evsel.h | 5 +++
2 files changed, 87 insertions(+), 6 deletions(-)
diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c
index 1506ba0..00936ad 100644
--- a/tools/perf/util/evsel.c
+++ b/tools/perf/util/evsel.c
@@ -10,6 +10,7 @@
#include <byteswap.h>
#include <linux/bitops.h>
#include "asm/bug.h"
+#include "debugfs.h"
#include "event-parse.h"
#include "evsel.h"
#include "evlist.h"
@@ -69,6 +70,72 @@ struct perf_evsel *perf_evsel__new(struct perf_event_attr *attr, int idx)
return evsel;
}
+static struct event_format *event_format__new(const char *sys, const char *name)
+{
+ int fd, n;
+ char *filename;
+ void *bf = NULL, *nbf;
+ size_t size = 0, alloc_size = 0;
+ struct event_format *format = NULL;
+
+ if (asprintf(&filename, "%s/%s/%s/format", tracing_events_path, sys, name) < 0)
+ goto out;
+
+ fd = open(filename, O_RDONLY);
+ if (fd < 0)
+ goto out_free_filename;
+
+ do {
+ if (size == alloc_size) {
+ alloc_size += BUFSIZ;
+ nbf = realloc(bf, alloc_size);
+ if (nbf == NULL)
+ goto out_free_bf;
+ bf = nbf;
+ }
+
+ n = read(fd, bf + size, BUFSIZ);
+ if (n < 0)
+ goto out_free_bf;
+ size += n;
+ } while (n > 0);
+
+ pevent_parse_format(&format, bf, size, sys);
+
+out_free_bf:
+ free(bf);
+ close(fd);
+out_free_filename:
+ free(filename);
+out:
+ return format;
+}
+
+struct perf_evsel *perf_evsel__newtp(const char *sys, const char *name, int idx)
+{
+ struct perf_evsel *evsel = zalloc(sizeof(*evsel));
+
+ if (evsel != NULL) {
+ struct perf_event_attr attr = {
+ .type = PERF_TYPE_TRACEPOINT,
+ };
+
+ evsel->tp_format = event_format__new(sys, name);
+ if (evsel->tp_format == NULL)
+ goto out_free;
+
+ attr.config = evsel->tp_format->id;
+ perf_evsel__init(evsel, &attr, idx);
+ evsel->name = evsel->tp_format->name;
+ }
+
+ return evsel;
+
+out_free:
+ free(evsel);
+ return NULL;
+}
+
const char *perf_evsel__hw_names[PERF_COUNT_HW_MAX] = {
"cycles",
"instructions",
@@ -495,6 +562,10 @@ void perf_evsel__delete(struct perf_evsel *evsel)
perf_evsel__exit(evsel);
close_cgroup(evsel->cgrp);
free(evsel->group_name);
+ if (evsel->tp_format && evsel->name == evsel->tp_format->name) {
+ evsel->name = NULL;
+ pevent_free_format(evsel->tp_format);
+ }
free(evsel->name);
free(evsel);
}
@@ -1002,14 +1073,19 @@ int perf_event__synthesize_sample(union perf_event *event, u64 type,
return 0;
}
+struct format_field *perf_evsel__field(struct perf_evsel *evsel, const char *name)
+{
+ return pevent_find_field(evsel->tp_format, name);
+}
+
char *perf_evsel__strval(struct perf_evsel *evsel, struct perf_sample *sample,
const char *name)
{
- struct format_field *field = pevent_find_field(evsel->tp_format, name);
+ struct format_field *field = perf_evsel__field(evsel, name);
int offset;
- if (!field)
- return NULL;
+ if (!field)
+ return NULL;
offset = field->offset;
@@ -1024,11 +1100,11 @@ char *perf_evsel__strval(struct perf_evsel *evsel, struct perf_sample *sample,
u64 perf_evsel__intval(struct perf_evsel *evsel, struct perf_sample *sample,
const char *name)
{
- struct format_field *field = pevent_find_field(evsel->tp_format, name);
+ struct format_field *field = perf_evsel__field(evsel, name);
u64 val;
- if (!field)
- return 0;
+ if (!field)
+ return 0;
val = pevent_read_number(evsel->tp_format->pevent,
sample->raw_data + field->offset, field->size);
diff --git a/tools/perf/util/evsel.h b/tools/perf/util/evsel.h
index 93876ba..bb445d1 100644
--- a/tools/perf/util/evsel.h
+++ b/tools/perf/util/evsel.h
@@ -81,6 +81,7 @@ struct perf_evlist;
struct perf_record_opts;
struct perf_evsel *perf_evsel__new(struct perf_event_attr *attr, int idx);
+struct perf_evsel *perf_evsel__newtp(const char *sys, const char *name, int idx);
void perf_evsel__init(struct perf_evsel *evsel,
struct perf_event_attr *attr, int idx);
void perf_evsel__exit(struct perf_evsel *evsel);
@@ -128,6 +129,10 @@ char *perf_evsel__strval(struct perf_evsel *evsel, struct perf_sample *sample,
u64 perf_evsel__intval(struct perf_evsel *evsel, struct perf_sample *sample,
const char *name);
+struct format_field;
+
+struct format_field *perf_evsel__field(struct perf_evsel *evsel, const char *name);
+
#define perf_evsel__match(evsel, t, c) \
(evsel->attr.type == PERF_TYPE_##t && \
evsel->attr.config == PERF_COUNT_##c)
--
1.7.1
^ permalink raw reply related [flat|nested] 41+ messages in thread
* [PATCH 29/30] perf test: Add test for the sched tracepoint format fields
2012-09-24 15:59 [GIT PULL 00/30] perf/core improvements and fixes Arnaldo Carvalho de Melo
` (27 preceding siblings ...)
2012-09-24 15:59 ` [PATCH 28/30] perf evsel: Provide a new constructor for tracepoints Arnaldo Carvalho de Melo
@ 2012-09-24 15:59 ` Arnaldo Carvalho de Melo
2012-09-25 4:31 ` Namhyung Kim
2012-09-24 15:59 ` [PATCH 30/30] tools lib traceevent: Handle alloc_arg failure Arnaldo Carvalho de Melo
29 siblings, 1 reply; 41+ messages in thread
From: Arnaldo Carvalho de Melo @ 2012-09-24 15:59 UTC (permalink / raw)
To: Ingo Molnar
Cc: linux-kernel, Arnaldo Carvalho de Melo, David Ahern,
Frederic Weisbecker, Jiri Olsa, Mike Galbraith, Namhyung Kim,
Paul Mackerras, Peter Zijlstra, Stephane Eranian
From: Arnaldo Carvalho de Melo <acme@redhat.com>
So that we make sure the routines that do event format parsing are
working on at least two well know scheduler tracepoints.
Cc: David Ahern <dsahern@gmail.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Namhyung Kim <namhyung@gmail.com>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Link: http://lkml.kernel.org/n/tip-g3rm9b3wtim4djx3z8dkftrj@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
tools/perf/builtin-test.c | 86 +++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 86 insertions(+), 0 deletions(-)
diff --git a/tools/perf/builtin-test.c b/tools/perf/builtin-test.c
index 4aed155..32caf13 100644
--- a/tools/perf/builtin-test.c
+++ b/tools/perf/builtin-test.c
@@ -14,6 +14,7 @@
#include "util/symbol.h"
#include "util/thread_map.h"
#include "util/pmu.h"
+#include "event-parse.h"
#include "../../include/linux/hw_breakpoint.h"
#include <sys/mman.h>
@@ -1207,6 +1208,87 @@ static int perf_evsel__roundtrip_name_test(void)
return ret;
}
+static int perf_evsel__test_field(struct perf_evsel *evsel, const char *name,
+ int size, bool should_be_signed)
+{
+ struct format_field *field = perf_evsel__field(evsel, name);
+ int is_signed;
+ int ret = 0;
+
+ if (field == NULL) {
+ pr_debug("%s: \"%s\" field not found!\n", evsel->name, name);
+ return -1;
+ }
+
+ is_signed = !!(field->flags | FIELD_IS_SIGNED);
+ if (should_be_signed && !is_signed) {
+ pr_debug("%s: \"%s\" signedness(%d) is wrong, should be %d\n",
+ evsel->name, name, is_signed, should_be_signed);
+ ret = -1;
+ }
+
+ if (field->size != size) {
+ pr_debug("%s: \"%s\" size (%d) should be %d!\n",
+ evsel->name, name, field->size, size);
+ ret = -1;
+ }
+
+ return 0;
+}
+
+static int perf_evsel__tp_sched_test(void)
+{
+ struct perf_evsel *evsel = perf_evsel__newtp("sched", "sched_switch", 0);
+ int ret = 0;
+
+ if (evsel == NULL) {
+ pr_debug("perf_evsel__new\n");
+ return -1;
+ }
+
+ if (perf_evsel__test_field(evsel, "prev_comm", 16, true))
+ ret = -1;
+
+ if (perf_evsel__test_field(evsel, "prev_pid", 4, true))
+ ret = -1;
+
+ if (perf_evsel__test_field(evsel, "prev_prio", 4, true))
+ ret = -1;
+
+ if (perf_evsel__test_field(evsel, "prev_state", 8, true))
+ ret = -1;
+
+ if (perf_evsel__test_field(evsel, "next_comm", 16, true))
+ ret = -1;
+
+ if (perf_evsel__test_field(evsel, "next_pid", 4, true))
+ ret = -1;
+
+ if (perf_evsel__test_field(evsel, "next_prio", 4, true))
+ ret = -1;
+
+ perf_evsel__delete(evsel);
+
+ evsel = perf_evsel__newtp("sched", "sched_wakeup", 0);
+
+ if (perf_evsel__test_field(evsel, "comm", 16, true))
+ ret = -1;
+
+ if (perf_evsel__test_field(evsel, "pid", 4, true))
+ ret = -1;
+
+ if (perf_evsel__test_field(evsel, "prio", 4, true))
+ ret = -1;
+
+ if (perf_evsel__test_field(evsel, "success", 4, true))
+ ret = -1;
+
+ if (perf_evsel__test_field(evsel, "target_cpu", 4, true))
+ ret = -1;
+
+ return 0;
+}
+
static struct test {
const char *desc;
int (*func)(void);
@@ -1254,6 +1336,10 @@ static struct test {
.func = perf_evsel__roundtrip_name_test,
},
{
+ .desc = "Check parsing of sched tracepoints fields",
+ .func = perf_evsel__tp_sched_test,
+ },
+ {
.func = NULL,
},
};
--
1.7.1
^ permalink raw reply related [flat|nested] 41+ messages in thread
* [PATCH 30/30] tools lib traceevent: Handle alloc_arg failure
2012-09-24 15:59 [GIT PULL 00/30] perf/core improvements and fixes Arnaldo Carvalho de Melo
` (28 preceding siblings ...)
2012-09-24 15:59 ` [PATCH 29/30] perf test: Add test for the sched tracepoint format fields Arnaldo Carvalho de Melo
@ 2012-09-24 15:59 ` Arnaldo Carvalho de Melo
29 siblings, 0 replies; 41+ messages in thread
From: Arnaldo Carvalho de Melo @ 2012-09-24 15:59 UTC (permalink / raw)
To: Ingo Molnar
Cc: linux-kernel, Namhyung Kim, David Ahern, Frederic Weisbecker,
Jiri Olsa, Mike Galbraith, Namhyung Kim, Paul Mackerras,
Peter Zijlstra, Stephane Eranian, Steven Rostedt,
Arnaldo Carvalho de Melo
From: Namhyung Kim <namhyung@kernel.org>
Now alloc_arg returns NULL if memory allocation failed, it should be
handled on callsites properly.
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
Cc: David Ahern <dsahern@gmail.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Namhyung Kim <namhyung.kim@lge.com>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Stephane Eranian <eranian@google.com>
Cc: Steven Rostedt <rostedt@goodmis.org>
Link: http://lkml.kernel.org/r/87k3vpzbqo.fsf_-_@sejong.aot.lge.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
tools/lib/traceevent/event-parse.c | 97 +++++++++++++++++++++++++++++++++++-
1 files changed, 95 insertions(+), 2 deletions(-)
diff --git a/tools/lib/traceevent/event-parse.c b/tools/lib/traceevent/event-parse.c
index 1fa71ca..17c9221 100644
--- a/tools/lib/traceevent/event-parse.c
+++ b/tools/lib/traceevent/event-parse.c
@@ -1565,6 +1565,14 @@ process_cond(struct event_format *event, struct print_arg *top, char **tok)
left = alloc_arg();
right = alloc_arg();
+ if (!arg || !left || !right) {
+ do_warning("%s: not enough memory!", __func__);
+ /* arg will be freed at out_free */
+ free_arg(left);
+ free_arg(right);
+ goto out_free;
+ }
+
arg->type = PRINT_OP;
arg->op.left = left;
arg->op.right = right;
@@ -1607,6 +1615,12 @@ process_array(struct event_format *event, struct print_arg *top, char **tok)
char *token = NULL;
arg = alloc_arg();
+ if (!arg) {
+ do_warning("%s: not enough memory!", __func__);
+ /* '*tok' is set to top->op.op. No need to free. */
+ *tok = NULL;
+ return EVENT_ERROR;
+ }
*tok = NULL;
type = process_arg(event, arg, &token);
@@ -1725,10 +1739,16 @@ process_op(struct event_format *event, struct print_arg *arg, char **tok)
/* make an empty left */
left = alloc_arg();
+ if (!left)
+ goto out_warn_free;
+
left->type = PRINT_NULL;
arg->op.left = left;
right = alloc_arg();
+ if (!right)
+ goto out_warn_free;
+
arg->op.right = right;
/* do not free the token, it belongs to an op */
@@ -1738,6 +1758,9 @@ process_op(struct event_format *event, struct print_arg *arg, char **tok)
} else if (strcmp(token, "?") == 0) {
left = alloc_arg();
+ if (!left)
+ goto out_warn_free;
+
/* copy the top arg to the left */
*left = *arg;
@@ -1766,6 +1789,8 @@ process_op(struct event_format *event, struct print_arg *arg, char **tok)
strcmp(token, "!=") == 0) {
left = alloc_arg();
+ if (!left)
+ goto out_warn_free;
/* copy the top arg to the left */
*left = *arg;
@@ -1797,7 +1822,7 @@ process_op(struct event_format *event, struct print_arg *arg, char **tok)
new_atom = realloc(left->atom.atom,
strlen(left->atom.atom) + 3);
if (!new_atom)
- goto out_free;
+ goto out_warn_free;
left->atom.atom = new_atom;
strcat(left->atom.atom, " *");
@@ -1809,12 +1834,18 @@ process_op(struct event_format *event, struct print_arg *arg, char **tok)
}
right = alloc_arg();
+ if (!right)
+ goto out_warn_free;
+
type = process_arg_token(event, right, tok, type);
arg->op.right = right;
} else if (strcmp(token, "[") == 0) {
left = alloc_arg();
+ if (!left)
+ goto out_warn_free;
+
*left = *arg;
arg->type = PRINT_OP;
@@ -1847,7 +1878,9 @@ process_op(struct event_format *event, struct print_arg *arg, char **tok)
return type;
- out_free:
+out_warn_free:
+ do_warning("%s: not enough memory!", __func__);
+out_free:
free_token(token);
*tok = NULL;
return EVENT_ERROR;
@@ -2203,6 +2236,8 @@ process_fields(struct event_format *event, struct print_flag_sym **list, char **
break;
arg = alloc_arg();
+ if (!arg)
+ goto out_free;
free_token(token);
type = process_arg(event, arg, &token);
@@ -2229,6 +2264,8 @@ process_fields(struct event_format *event, struct print_flag_sym **list, char **
free_arg(arg);
arg = alloc_arg();
+ if (!arg)
+ goto out_free;
free_token(token);
type = process_arg(event, arg, &token);
@@ -2275,6 +2312,10 @@ process_flags(struct event_format *event, struct print_arg *arg, char **tok)
arg->type = PRINT_FLAGS;
field = alloc_arg();
+ if (!field) {
+ do_warning("%s: not enough memory!", __func__);
+ goto out_free;
+ }
type = process_arg(event, field, &token);
@@ -2324,6 +2365,10 @@ process_symbols(struct event_format *event, struct print_arg *arg, char **tok)
arg->type = PRINT_SYMBOL;
field = alloc_arg();
+ if (!field) {
+ do_warning("%s: not enough memory!", __func__);
+ goto out_free;
+ }
type = process_arg(event, field, &token);
if (test_type_token(type, token, EVENT_DELIM, ","))
@@ -2358,6 +2403,11 @@ process_hex(struct event_format *event, struct print_arg *arg, char **tok)
arg->type = PRINT_HEX;
field = alloc_arg();
+ if (!field) {
+ do_warning("%s: not enough memory!", __func__);
+ goto out_free;
+ }
+
type = process_arg(event, field, &token);
if (test_type_token(type, token, EVENT_DELIM, ","))
@@ -2368,6 +2418,12 @@ process_hex(struct event_format *event, struct print_arg *arg, char **tok)
free_token(token);
field = alloc_arg();
+ if (!field) {
+ do_warning("%s: not enough memory!", __func__);
+ *tok = NULL;
+ return EVENT_ERROR;
+ }
+
type = process_arg(event, field, &token);
if (test_type_token(type, token, EVENT_DELIM, ")"))
@@ -2425,6 +2481,12 @@ process_dynamic_array(struct event_format *event, struct print_arg *arg, char **
free_token(token);
arg = alloc_arg();
+ if (!field) {
+ do_warning("%s: not enough memory!", __func__);
+ *tok = NULL;
+ return EVENT_ERROR;
+ }
+
type = process_arg(event, arg, &token);
if (type == EVENT_ERROR)
goto out_free_arg;
@@ -2484,6 +2546,10 @@ process_paren(struct event_format *event, struct print_arg *arg, char **tok)
}
item_arg = alloc_arg();
+ if (!item_arg) {
+ do_warning("%s: not enough memory!", __func__);
+ goto out_free;
+ }
arg->type = PRINT_TYPE;
arg->typecast.type = arg->atom.atom;
@@ -2579,6 +2645,11 @@ process_func_handler(struct event_format *event, struct pevent_function_handler
next_arg = &(arg->func.args);
for (i = 0; i < func->nr_args; i++) {
farg = alloc_arg();
+ if (!farg) {
+ do_warning("%s: not enough memory!", __func__);
+ return EVENT_ERROR;
+ }
+
type = process_arg(event, farg, &token);
if (i < (func->nr_args - 1))
test = ",";
@@ -2745,6 +2816,10 @@ static int event_read_print_args(struct event_format *event, struct print_arg **
}
arg = alloc_arg();
+ if (!arg) {
+ do_warning("%s: not enough memory!", __func__);
+ return -1;
+ }
type = process_arg(event, arg, &token);
@@ -3643,6 +3718,10 @@ static struct print_arg *make_bprint_args(char *fmt, void *data, int size, struc
* The first arg is the IP pointer.
*/
args = alloc_arg();
+ if (!args) {
+ do_warning("%s(%d): not enough memory!", __func__, __LINE__);
+ return NULL;
+ }
arg = args;
arg->next = NULL;
next = &arg->next;
@@ -3705,6 +3784,11 @@ static struct print_arg *make_bprint_args(char *fmt, void *data, int size, struc
val = pevent_read_number(pevent, bptr, vsize);
bptr += vsize;
arg = alloc_arg();
+ if (!arg) {
+ do_warning("%s(%d): not enough memory!",
+ __func__, __LINE__);
+ goto out_free;
+ }
arg->next = NULL;
arg->type = PRINT_ATOM;
if (asprintf(&arg->atom.atom, "%lld", val) < 0) {
@@ -3723,6 +3807,11 @@ static struct print_arg *make_bprint_args(char *fmt, void *data, int size, struc
break;
case 's':
arg = alloc_arg();
+ if (!arg) {
+ do_warning("%s(%d): not enough memory!",
+ __func__, __LINE__);
+ goto out_free;
+ }
arg->next = NULL;
arg->type = PRINT_BSTRING;
arg->string.string = strdup(bptr);
@@ -4878,6 +4967,10 @@ enum pevent_errno __pevent_parse_format(struct event_format **eventp,
list = &event->print_fmt.args;
for (field = event->format.fields; field; field = field->next) {
arg = alloc_arg();
+ if (!arg) {
+ event->flags |= EVENT_FL_FAILED;
+ return PEVENT_ERRNO__OLD_FTRACE_ARG_FAILED;
+ }
arg->type = PRINT_FIELD;
arg->field.name = strdup(field->name);
if (!arg->field.name) {
--
1.7.1
^ permalink raw reply related [flat|nested] 41+ messages in thread
* Re: [PATCH 22/30] perf tools: bfd.h/libbfd detection fails with recent binutils
2012-09-24 15:59 ` [PATCH 22/30] perf tools: bfd.h/libbfd detection fails with recent binutils Arnaldo Carvalho de Melo
@ 2012-09-24 23:58 ` Mike Frysinger
2012-09-25 6:47 ` Markus Trippelsdorf
0 siblings, 1 reply; 41+ messages in thread
From: Mike Frysinger @ 2012-09-24 23:58 UTC (permalink / raw)
To: Arnaldo Carvalho de Melo
Cc: Ingo Molnar, linux-kernel, Markus Trippelsdorf, Ingo Molnar,
Paul Mackerras, Arnaldo Carvalho de Melo
[-- Attachment #1: Type: Text/Plain, Size: 656 bytes --]
On Monday 24 September 2012 11:59:36 Arnaldo Carvalho de Melo wrote:
> --- a/tools/perf/Makefile
> +++ b/tools/perf/Makefile
>
> - FLAGS_BFD=$(ALL_CFLAGS) $(ALL_LDFLAGS) $(EXTLIBS) -lbfd
> + FLAGS_BFD=$(ALL_CFLAGS) $(ALL_LDFLAGS) $(EXTLIBS) -DPACKAGE='perf' -
in this case, if you were to expand PACKAGE, you'd get back the symbol perf
(which most likely will be an error, but maybe it won't). i think this should
be instead:
-DPACKAGE='"perf"'
> --- a/tools/perf/util/symbol.h
> +++ b/tools/perf/util/symbol.h
>
> +#define PACKAGE 'perf'
this isn't valid C anywhere. pretty sure this should be:
#define PACKAGE "perf"
-mike
[-- Attachment #2: This is a digitally signed message part. --]
[-- Type: application/pgp-signature, Size: 836 bytes --]
^ permalink raw reply [flat|nested] 41+ messages in thread
* Re: [PATCH 27/30] tools lib traceevent: Carve out events format parsing routine
2012-09-24 15:59 ` [PATCH 27/30] tools lib traceevent: Carve out events format parsing routine Arnaldo Carvalho de Melo
@ 2012-09-25 4:15 ` Namhyung Kim
2012-09-25 11:12 ` Arnaldo Carvalho de Melo
0 siblings, 1 reply; 41+ messages in thread
From: Namhyung Kim @ 2012-09-25 4:15 UTC (permalink / raw)
To: Arnaldo Carvalho de Melo
Cc: Ingo Molnar, linux-kernel, Arnaldo Carvalho de Melo, David Ahern,
Frederic Weisbecker, Jiri Olsa, Mike Galbraith, Paul Mackerras,
Peter Zijlstra, Stephane Eranian, Steven Rostedt
On Mon, 24 Sep 2012 12:59:41 -0300, Arnaldo Carvalho de Melo wrote:
> From: Arnaldo Carvalho de Melo <acme@redhat.com>
>
> The pevent_parse_event() routine will parse a events/sys/tp/format file
> and add an event_format instance to the pevent struct.
>
> This patch introduces a pevent_parse_format() routine with just the bits
> needed to parse the event/sys/tp/format file and just return the
> event_format instance, useful for when all we want is to parse the
> format file, without requiring the pevent struct.
[snip]
> +enum pevent_errno pevent_parse_event(struct pevent *pevent, const char *buf,
> + unsigned long size, const char *sys)
> +{
> + struct event_format *event = NULL;
> + int ret = __pevent_parse_format(&event, pevent, buf, size, sys);
> +
> + if (event == NULL)
> + return ret;
> +
> + /* Add pevent to event so that it can be referenced */
> + event->pevent = pevent;
> +
> + if (add_event(pevent, event))
> + goto event_add_failed;
It seems we should set the 'ret' to a proper pevent_errno -
PEVENT_ERRNO__MEM_ALLOC_FAILED.
> +
> +#define PRINT_ARGS 0
> + if (PRINT_ARGS && event->print_fmt.args)
> + print_args(event->print_fmt.args);
> +
> + return 0;
> +
> +event_add_failed:
> + free(event->system);
> + free(event->name);
> + free(event);
At this point, the 'event' also has fields and format information and
they all need to be freed. Looks like calling pevent_free_format()
would be the right thing IMHO.
Thanks,
Namhyung
> return ret;
> }
^ permalink raw reply [flat|nested] 41+ messages in thread
* Re: [PATCH 28/30] perf evsel: Provide a new constructor for tracepoints
2012-09-24 15:59 ` [PATCH 28/30] perf evsel: Provide a new constructor for tracepoints Arnaldo Carvalho de Melo
@ 2012-09-25 4:26 ` Namhyung Kim
2012-09-25 11:28 ` Arnaldo Carvalho de Melo
0 siblings, 1 reply; 41+ messages in thread
From: Namhyung Kim @ 2012-09-25 4:26 UTC (permalink / raw)
To: Arnaldo Carvalho de Melo
Cc: Ingo Molnar, linux-kernel, Arnaldo Carvalho de Melo, David Ahern,
Frederic Weisbecker, Jiri Olsa, Mike Galbraith, Paul Mackerras,
Peter Zijlstra, Stephane Eranian, Steven Rostedt
On Mon, 24 Sep 2012 12:59:42 -0300, Arnaldo Carvalho de Melo wrote:
> From: Arnaldo Carvalho de Melo <acme@redhat.com>
>
> The existing constructor receives a perf_event_attr filled with the
> event type and the config.
>
> To reduce the boilerplate for tracepoints, provide a new constructor,
> perf_evsel__newtp() that receives the tracepoint name and will open
> the debugfs file, call into libtraceevent new pevent_parse_format file
> to fill its ->tp_format member, so that users can then just call
> perf_evsel__field() to access its fields.
[snip]
> +static struct event_format *event_format__new(const char *sys, const char *name)
> +{
> + int fd, n;
> + char *filename;
> + void *bf = NULL, *nbf;
> + size_t size = 0, alloc_size = 0;
> + struct event_format *format = NULL;
> +
> + if (asprintf(&filename, "%s/%s/%s/format", tracing_events_path, sys, name) < 0)
> + goto out;
> +
> + fd = open(filename, O_RDONLY);
> + if (fd < 0)
> + goto out_free_filename;
> +
> + do {
> + if (size == alloc_size) {
> + alloc_size += BUFSIZ;
> + nbf = realloc(bf, alloc_size);
> + if (nbf == NULL)
> + goto out_free_bf;
> + bf = nbf;
> + }
> +
> + n = read(fd, bf + size, BUFSIZ);
Wouldn't it be better doing s/BUFSIZ/alloc_size - size/ ? Although
there'll be no partial reading issue when working on debugfs I guess.
Thanks,
Namhyung
> + if (n < 0)
> + goto out_free_bf;
> + size += n;
> + } while (n > 0);
> +
> + pevent_parse_format(&format, bf, size, sys);
> +
> +out_free_bf:
> + free(bf);
> + close(fd);
> +out_free_filename:
> + free(filename);
> +out:
> + return format;
> +}
^ permalink raw reply [flat|nested] 41+ messages in thread
* Re: [PATCH 29/30] perf test: Add test for the sched tracepoint format fields
2012-09-24 15:59 ` [PATCH 29/30] perf test: Add test for the sched tracepoint format fields Arnaldo Carvalho de Melo
@ 2012-09-25 4:31 ` Namhyung Kim
0 siblings, 0 replies; 41+ messages in thread
From: Namhyung Kim @ 2012-09-25 4:31 UTC (permalink / raw)
To: Arnaldo Carvalho de Melo
Cc: Ingo Molnar, linux-kernel, Arnaldo Carvalho de Melo, David Ahern,
Frederic Weisbecker, Jiri Olsa, Mike Galbraith, Paul Mackerras,
Peter Zijlstra, Stephane Eranian
On Mon, 24 Sep 2012 12:59:43 -0300, Arnaldo Carvalho de Melo wrote:
> From: Arnaldo Carvalho de Melo <acme@redhat.com>
>
> So that we make sure the routines that do event format parsing are
> working on at least two well know scheduler tracepoints.
It caused a build error and I posted a fix, please see:
https://lkml.org/lkml/2012/9/24/689
Thanks,
Namhyung
^ permalink raw reply [flat|nested] 41+ messages in thread
* Re: [PATCH 22/30] perf tools: bfd.h/libbfd detection fails with recent binutils
2012-09-24 23:58 ` Mike Frysinger
@ 2012-09-25 6:47 ` Markus Trippelsdorf
2012-09-25 16:40 ` Mike Frysinger
0 siblings, 1 reply; 41+ messages in thread
From: Markus Trippelsdorf @ 2012-09-25 6:47 UTC (permalink / raw)
To: Mike Frysinger
Cc: Arnaldo Carvalho de Melo, Ingo Molnar, linux-kernel, Ingo Molnar,
Paul Mackerras, Arnaldo Carvalho de Melo
On 2012.09.24 at 19:58 -0400, Mike Frysinger wrote:
> On Monday 24 September 2012 11:59:36 Arnaldo Carvalho de Melo wrote:
> > --- a/tools/perf/Makefile
> > +++ b/tools/perf/Makefile
> >
> > - FLAGS_BFD=$(ALL_CFLAGS) $(ALL_LDFLAGS) $(EXTLIBS) -lbfd
> > + FLAGS_BFD=$(ALL_CFLAGS) $(ALL_LDFLAGS) $(EXTLIBS) -DPACKAGE='perf' -
>
> in this case, if you were to expand PACKAGE, you'd get back the symbol perf
> (which most likely will be an error, but maybe it won't). i think this should
> be instead:
> -DPACKAGE='"perf"'
>
> > --- a/tools/perf/util/symbol.h
> > +++ b/tools/perf/util/symbol.h
> >
> > +#define PACKAGE 'perf'
>
> this isn't valid C anywhere. pretty sure this should be:
> #define PACKAGE "perf"
The only thing that's really important is that PACKAGE isn't NULL,
because it's just a workaround for this brilliant gem from bfd.h:
35 /* PR 14072: Ensure that config.h is included first. */
36 #if !defined PACKAGE && !defined PACKAGE_VERSION
37 #error config.h must be included before this header
38 #endif
So if you feel strongly about it, feel free to post a patch that just
sets PACKAGE to 1. This would avoid all possible ambiguity.
--
Markus
^ permalink raw reply [flat|nested] 41+ messages in thread
* Re: [PATCH 27/30] tools lib traceevent: Carve out events format parsing routine
2012-09-25 4:15 ` Namhyung Kim
@ 2012-09-25 11:12 ` Arnaldo Carvalho de Melo
2012-09-25 12:25 ` [PATCH] tools lib traceevent: Fix error path on pevent_parse_event Namhyung Kim
0 siblings, 1 reply; 41+ messages in thread
From: Arnaldo Carvalho de Melo @ 2012-09-25 11:12 UTC (permalink / raw)
To: Namhyung Kim
Cc: Ingo Molnar, linux-kernel, David Ahern, Frederic Weisbecker,
Jiri Olsa, Mike Galbraith, Paul Mackerras, Peter Zijlstra,
Stephane Eranian, Steven Rostedt
Em Tue, Sep 25, 2012 at 01:15:05PM +0900, Namhyung Kim escreveu:
> On Mon, 24 Sep 2012 12:59:41 -0300, Arnaldo Carvalho de Melo wrote:
> > + if (add_event(pevent, event))
> > + goto event_add_failed;
> It seems we should set the 'ret' to a proper pevent_errno -
> PEVENT_ERRNO__MEM_ALLOC_FAILED.
> > +event_add_failed:
> > + free(event->system);
> > + free(event->name);
> > + free(event);
>
> At this point, the 'event' also has fields and format information and
> they all need to be freed. Looks like calling pevent_free_format()
> would be the right thing IMHO.
Right, care to send a patch?
This patch even exported pevent_free_format, used in the next patch in
this series, should've used it here :-\
- Arnaldo
^ permalink raw reply [flat|nested] 41+ messages in thread
* Re: [PATCH 28/30] perf evsel: Provide a new constructor for tracepoints
2012-09-25 4:26 ` Namhyung Kim
@ 2012-09-25 11:28 ` Arnaldo Carvalho de Melo
0 siblings, 0 replies; 41+ messages in thread
From: Arnaldo Carvalho de Melo @ 2012-09-25 11:28 UTC (permalink / raw)
To: Namhyung Kim
Cc: Ingo Molnar, linux-kernel, David Ahern, Frederic Weisbecker,
Jiri Olsa, Mike Galbraith, Paul Mackerras, Peter Zijlstra,
Stephane Eranian, Steven Rostedt
Em Tue, Sep 25, 2012 at 01:26:46PM +0900, Namhyung Kim escreveu:
> On Mon, 24 Sep 2012 12:59:42 -0300, Arnaldo Carvalho de Melo wrote:
> > + if (size == alloc_size) {
> > + alloc_size += BUFSIZ;
> > + nbf = realloc(bf, alloc_size);
> > + if (nbf == NULL)
> > + goto out_free_bf;
> > + bf = nbf;
> > + }
> > +
> > + n = read(fd, bf + size, BUFSIZ);
>
> Wouldn't it be better doing s/BUFSIZ/alloc_size - size/ ? Although
> there'll be no partial reading issue when working on debugfs I guess.
Yeah, don't know if that is worth it :-\
- Arnaldo
^ permalink raw reply [flat|nested] 41+ messages in thread
* [PATCH] tools lib traceevent: Fix error path on pevent_parse_event
2012-09-25 11:12 ` Arnaldo Carvalho de Melo
@ 2012-09-25 12:25 ` Namhyung Kim
2012-09-27 5:51 ` [tip:perf/core] " tip-bot for Namhyung Kim
0 siblings, 1 reply; 41+ messages in thread
From: Namhyung Kim @ 2012-09-25 12:25 UTC (permalink / raw)
To: Arnaldo Carvalho de Melo; +Cc: Ingo Molnar, Peter Zijlstra, LKML
If __pevent_parse_format() succeeded but add_event() failed, 'ret' didn't
have a proper error code. Set it to PEVENT_ERRNO__MEM_ALLOC_FAILED.
In addition, at that point 'event' also has fields and format information
and they all need to be freed. Call pevent_free_format() to handle it.
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
---
tools/lib/traceevent/event-parse.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/tools/lib/traceevent/event-parse.c b/tools/lib/traceevent/event-parse.c
index 17c922145e88..47264b4652b9 100644
--- a/tools/lib/traceevent/event-parse.c
+++ b/tools/lib/traceevent/event-parse.c
@@ -5044,8 +5044,10 @@ enum pevent_errno pevent_parse_event(struct pevent *pevent, const char *buf,
/* Add pevent to event so that it can be referenced */
event->pevent = pevent;
- if (add_event(pevent, event))
+ if (add_event(pevent, event)) {
+ ret = PEVENT_ERRNO__MEM_ALLOC_FAILED;
goto event_add_failed;
+ }
#define PRINT_ARGS 0
if (PRINT_ARGS && event->print_fmt.args)
@@ -5054,9 +5056,7 @@ enum pevent_errno pevent_parse_event(struct pevent *pevent, const char *buf,
return 0;
event_add_failed:
- free(event->system);
- free(event->name);
- free(event);
+ pevent_free_format(event);
return ret;
}
--
1.7.9.2
^ permalink raw reply related [flat|nested] 41+ messages in thread
* Re: [PATCH 22/30] perf tools: bfd.h/libbfd detection fails with recent binutils
2012-09-25 6:47 ` Markus Trippelsdorf
@ 2012-09-25 16:40 ` Mike Frysinger
0 siblings, 0 replies; 41+ messages in thread
From: Mike Frysinger @ 2012-09-25 16:40 UTC (permalink / raw)
To: Markus Trippelsdorf
Cc: Arnaldo Carvalho de Melo, Ingo Molnar, linux-kernel, Ingo Molnar,
Paul Mackerras, Arnaldo Carvalho de Melo
[-- Attachment #1: Type: Text/Plain, Size: 1356 bytes --]
On Tuesday 25 September 2012 02:47:28 Markus Trippelsdorf wrote:
> On 2012.09.24 at 19:58 -0400, Mike Frysinger wrote:
> > On Monday 24 September 2012 11:59:36 Arnaldo Carvalho de Melo wrote:
> > > --- a/tools/perf/Makefile
> > > +++ b/tools/perf/Makefile
> > >
> > > - FLAGS_BFD=$(ALL_CFLAGS) $(ALL_LDFLAGS) $(EXTLIBS) -lbfd
> > > + FLAGS_BFD=$(ALL_CFLAGS) $(ALL_LDFLAGS) $(EXTLIBS) -
DPACKAGE='perf' -
> >
> > in this case, if you were to expand PACKAGE, you'd get back the symbol
> > perf (which most likely will be an error, but maybe it won't). i think
> > this should
> >
> > be instead:
> > -DPACKAGE='"perf"'
> >
> > > --- a/tools/perf/util/symbol.h
> > > +++ b/tools/perf/util/symbol.h
> > >
> > > +#define PACKAGE 'perf'
> >
> > this isn't valid C anywhere. pretty sure this should be:
> > #define PACKAGE "perf"
>
> The only thing that's really important is that PACKAGE isn't NULL,
you mean "isn't defined". i'm aware of that, but i'm trying to make you future
proof in case PACKAGE gets expanded somewhere.
> So if you feel strongly about it, feel free to post a patch that just
> sets PACKAGE to 1. This would avoid all possible ambiguity.
no it wouldn't. this define, in the context of binutils (and really any
autotools project), should be a string. anything else is invalid.
-mike
[-- Attachment #2: This is a digitally signed message part. --]
[-- Type: application/pgp-signature, Size: 836 bytes --]
^ permalink raw reply [flat|nested] 41+ messages in thread
* [tip:perf/core] tools lib traceevent: Fix error path on pevent_parse_event
2012-09-25 12:25 ` [PATCH] tools lib traceevent: Fix error path on pevent_parse_event Namhyung Kim
@ 2012-09-27 5:51 ` tip-bot for Namhyung Kim
0 siblings, 0 replies; 41+ messages in thread
From: tip-bot for Namhyung Kim @ 2012-09-27 5:51 UTC (permalink / raw)
To: linux-tip-commits; +Cc: acme, linux-kernel, hpa, mingo, peterz, tglx, namhyung
Commit-ID: f1b2256d66fe8d613b9afcc1c16079362f9fc05c
Gitweb: http://git.kernel.org/tip/f1b2256d66fe8d613b9afcc1c16079362f9fc05c
Author: Namhyung Kim <namhyung@kernel.org>
AuthorDate: Tue, 25 Sep 2012 21:25:19 +0900
Committer: Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Tue, 25 Sep 2012 09:53:53 -0300
tools lib traceevent: Fix error path on pevent_parse_event
If __pevent_parse_format() succeeded but add_event() failed, 'ret' didn't
have a proper error code. Set it to PEVENT_ERRNO__MEM_ALLOC_FAILED.
In addition, at that point 'event' also has fields and format
information and they all need to be freed. Call pevent_free_format() to
handle it.
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: http://lkml.kernel.org/r/1348575919-4954-1-git-send-email-namhyung@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
tools/lib/traceevent/event-parse.c | 8 ++++----
1 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/tools/lib/traceevent/event-parse.c b/tools/lib/traceevent/event-parse.c
index 17c9221..47264b4 100644
--- a/tools/lib/traceevent/event-parse.c
+++ b/tools/lib/traceevent/event-parse.c
@@ -5044,8 +5044,10 @@ enum pevent_errno pevent_parse_event(struct pevent *pevent, const char *buf,
/* Add pevent to event so that it can be referenced */
event->pevent = pevent;
- if (add_event(pevent, event))
+ if (add_event(pevent, event)) {
+ ret = PEVENT_ERRNO__MEM_ALLOC_FAILED;
goto event_add_failed;
+ }
#define PRINT_ARGS 0
if (PRINT_ARGS && event->print_fmt.args)
@@ -5054,9 +5056,7 @@ enum pevent_errno pevent_parse_event(struct pevent *pevent, const char *buf,
return 0;
event_add_failed:
- free(event->system);
- free(event->name);
- free(event);
+ pevent_free_format(event);
return ret;
}
^ permalink raw reply related [flat|nested] 41+ messages in thread
end of thread, other threads:[~2012-09-27 5:51 UTC | newest]
Thread overview: 41+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-09-24 15:59 [GIT PULL 00/30] perf/core improvements and fixes Arnaldo Carvalho de Melo
2012-09-24 15:59 ` [PATCH 01/30] perf tools: Fix a compiling error in trace-event-perl.c for 32 bits machine Arnaldo Carvalho de Melo
2012-09-24 15:59 ` [PATCH 02/30] perf tools: Fix a compiling error in util/map.c Arnaldo Carvalho de Melo
2012-09-24 15:59 ` [PATCH 03/30] perf record: Print event causing perf_event_open() to fail Arnaldo Carvalho de Melo
2012-09-24 15:59 ` [PATCH 04/30] perf tools: Fix parallel build Arnaldo Carvalho de Melo
2012-09-24 15:59 ` [PATCH 05/30] KVM: x86: Export svm/vmx exit code and vector code to userspace Arnaldo Carvalho de Melo
2012-09-24 15:59 ` [PATCH 06/30] perf kvm: Events analysis tool Arnaldo Carvalho de Melo
2012-09-24 15:59 ` [PATCH 07/30] perf kvm: Use perf_evsel__intval Arnaldo Carvalho de Melo
2012-09-24 15:59 ` [PATCH 08/30] perf kmem: Use perf_evsel__intval and perf_session__set_tracepoints_handlers Arnaldo Carvalho de Melo
2012-09-24 15:59 ` [PATCH 09/30] perf lock: " Arnaldo Carvalho de Melo
2012-09-24 15:59 ` [PATCH 10/30] perf timechart: Use zalloc and fix a couple leaks Arnaldo Carvalho de Melo
2012-09-24 15:59 ` [PATCH 11/30] perf header: Add struct perf_session_env Arnaldo Carvalho de Melo
2012-09-24 15:59 ` [PATCH 12/30] perf header: Add ->process callbacks to most of features Arnaldo Carvalho de Melo
2012-09-24 15:59 ` [PATCH 13/30] perf header: Use pre-processed session env when printing Arnaldo Carvalho de Melo
2012-09-24 15:59 ` [PATCH 14/30] perf header: Remove unused @feat arg from ->process callback Arnaldo Carvalho de Melo
2012-09-24 15:59 ` [PATCH 15/30] perf kvm: Use perf_session_env for reading cpuid Arnaldo Carvalho de Melo
2012-09-24 15:59 ` [PATCH 16/30] perf header: Remove perf_header__read_feature Arnaldo Carvalho de Melo
2012-09-24 15:59 ` [PATCH 17/30] perf tools: remove sscanf extension %as Arnaldo Carvalho de Melo
2012-09-24 15:59 ` [PATCH 18/30] tools lib traceevent: Fix error path on process_array() Arnaldo Carvalho de Melo
2012-09-24 15:59 ` [PATCH 19/30] tools lib traceevent: Make sure that arg->op.right is set properly Arnaldo Carvalho de Melo
2012-09-24 15:59 ` [PATCH 20/30] tools lib traceevent: Free field if an error occurs on process_fields Arnaldo Carvalho de Melo
2012-09-24 15:59 ` [PATCH 21/30] tools lib traceevent: Free field if an error occurs on process_flags/symbols Arnaldo Carvalho de Melo
2012-09-24 15:59 ` [PATCH 22/30] perf tools: bfd.h/libbfd detection fails with recent binutils Arnaldo Carvalho de Melo
2012-09-24 23:58 ` Mike Frysinger
2012-09-25 6:47 ` Markus Trippelsdorf
2012-09-25 16:40 ` Mike Frysinger
2012-09-24 15:59 ` [PATCH 23/30] tools lib traceevent: Use asprintf were applicable Arnaldo Carvalho de Melo
2012-09-24 15:59 ` [PATCH 24/30] tools lib traceevent: Use calloc " Arnaldo Carvalho de Melo
2012-09-24 15:59 ` [PATCH 25/30] tools lib traceevent: Fix afterlife gotos Arnaldo Carvalho de Melo
2012-09-24 15:59 ` [PATCH 26/30] tools lib traceevent: Remove some die() calls Arnaldo Carvalho de Melo
2012-09-24 15:59 ` [PATCH 27/30] tools lib traceevent: Carve out events format parsing routine Arnaldo Carvalho de Melo
2012-09-25 4:15 ` Namhyung Kim
2012-09-25 11:12 ` Arnaldo Carvalho de Melo
2012-09-25 12:25 ` [PATCH] tools lib traceevent: Fix error path on pevent_parse_event Namhyung Kim
2012-09-27 5:51 ` [tip:perf/core] " tip-bot for Namhyung Kim
2012-09-24 15:59 ` [PATCH 28/30] perf evsel: Provide a new constructor for tracepoints Arnaldo Carvalho de Melo
2012-09-25 4:26 ` Namhyung Kim
2012-09-25 11:28 ` Arnaldo Carvalho de Melo
2012-09-24 15:59 ` [PATCH 29/30] perf test: Add test for the sched tracepoint format fields Arnaldo Carvalho de Melo
2012-09-25 4:31 ` Namhyung Kim
2012-09-24 15:59 ` [PATCH 30/30] tools lib traceevent: Handle alloc_arg failure Arnaldo Carvalho de Melo
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).