x86 insn decoder bugfixes
Subsystems (3)
cover x86 insn decoder bugfixes
Hi Ingo,
Here are bugfixes and some enhances of x86-insn decoder and perf-probe.
- x86 insn decoder supports AVX and FMA.
- perf-probe syntax change.
- perf-probe supports function-relative line number.
- minor bugfixes.
New perf-probe syntax is below:
perf probe 'PROBE'
or
perf probe --add 'PROBE'
where, PROBE is
<source>:<line-number>
or
<function>[:<rel-lineno>|+<byte-offset>|%return][@<source>]
e.g.
perf probe 'schedule:10@kernel/sched.c'
puts a probe at 10th line from entry line of schedule() function in kernel/sched.c." and
perf probe 'vmalloc%return'
puts a return probe at the returning of vmalloc.
TODO:
- Support --line option to show which lines user can probe.
- Support lazy string matching.
Thank you,
---
Masami Hiramatsu (10):
perf/probes: Support function entry relative line number perf/probes: Change probepoint syntax of perf-probe perf/probes: Change command-line option of perf-probe perf/probes: Exit searching after finding target function
kprobe-tracer: Compare both of event-name and event-group to find probe
x86: Add Intel FMA instructions to x86 opcode map
x86: AVX instruction set decoder support
x86: Add pclmulq to x86 opcode map
x86: Merge INAT_REXPFX into INAT_PFX_*
x86: Fix SSE opcode map bug
arch/x86/include/asm/inat.h | 68 ++++- arch/x86/include/asm/insn.h | 43 +++ arch/x86/lib/inat.c | 12 + arch/x86/lib/insn.c | 54 ++++ arch/x86/lib/x86-opcode-map.txt | 464 +++++++++++++++++++--------------- arch/x86/tools/gen-insn-attr-x86.awk | 100 +++++-- kernel/trace/trace_kprobe.c | 8 - tools/perf/builtin-probe.c | 201 +++++++++------ tools/perf/util/probe-finder.c | 93 +++++-- tools/perf/util/probe-finder.h | 4 10 files changed, 695 insertions(+), 352 deletions(-)
Signature · 6 lines
Masami Hiramatsu Software Engineer Hitachi Computer Products (America), Inc. Software Solutions Division e-mail: [email protected]
PATCH 1/10 x86: Fix SSE opcode map bug
Fix superscripts position because some superscripts of SSE opcode are not put in correct position.
---
arch/x86/lib/x86-opcode-map.txt | 10 +++++----- 1 files changed, 5 insertions(+), 5 deletions(-)
arch/x86/lib/x86-opcode-map.txt +5 -5
@@ -401,9 +401,9 @@ Referrer: 2-byte escape 62: punpckldq Pq,Qd | punpckldq Vdq,Wdq (66) 63: packsswb Pq,Qq | packsswb Vdq,Wdq (66) 64: pcmpgtb Pq,Qq | pcmpgtb Vdq,Wdq (66) -65: pcmpgtw Pq,Qq | pcmpgtw(66) Vdq,Wdq +65: pcmpgtw Pq,Qq | pcmpgtw Vdq,Wdq (66) 66: pcmpgtd Pq,Qq | pcmpgtd Vdq,Wdq (66) -67: packuswb Pq,Qq | packuswb(66) Vdq,Wdq +67: packuswb Pq,Qq | packuswb Vdq,Wdq (66) 68: punpckhbw Pq,Qd | punpckhbw Vdq,Wdq (66) 69: punpckhwd Pq,Qd | punpckhwd Vdq,Wdq (66) 6a: punpckhdq Pq,Qd | punpckhdq Vdq,Wdq (66)
@@ -425,8 +425,8 @@ Referrer: 2-byte escape 79: VMWRITE Gd/q,Ed/q 7a: 7b: -7c: haddps(F2) Vps,Wps | haddpd(66) Vpd,Wpd -7d: hsubps(F2) Vps,Wps | hsubpd(66) Vpd,Wpd +7c: haddps Vps,Wps (F2) | haddpd Vpd,Wpd (66) +7d: hsubps Vps,Wps (F2) | hsubpd Vpd,Wpd (66) 7e: movd/q Ed/q,Pd | movd/q Ed/q,Vdq (66) | movq Vq,Wq (F3) 7f: movq Qq,Pq | movdqa Wdq,Vdq (66) | movdqu Wdq,Vdq (F3) # 0x0f 0x80-0x8f
@@ -574,7 +574,7 @@ Referrer: 3-byte escape 1 01: phaddw Pq,Qq | phaddw Vdq,Wdq (66) 02: phaddd Pq,Qq | phaddd Vdq,Wdq (66) 03: phaddsw Pq,Qq | phaddsw Vdq,Wdq (66) -04: pmaddubsw Pq,Qq | pmaddubsw (66)Vdq,Wdq +04: pmaddubsw Pq,Qq | pmaddubsw Vdq,Wdq (66) 05: phsubw Pq,Qq | phsubw Vdq,Wdq (66) 06: phsubd Pq,Qq | phsubd Vdq,Wdq (66) 07: phsubsw Pq,Qq | phsubsw Vdq,Wdq (66)
Signature · 7 lines
Masami Hiramatsu Software Engineer Hitachi Computer Products (America), Inc. Software Solutions Division e-mail: [email protected]
[tip:perf/probes] x86: Fix SSE opcode map bug
Commit-ID: 7f387d3f2421781610588faa2f49ae5f1737b137 Gitweb: http://git.kernel.org/tip/7f387d3f2421781610588faa2f49ae5f1737b137 Author: Masami Hiramatsu <[email protected]> AuthorDate: Tue, 27 Oct 2009 16:42:04 -0400 Committer: Ingo Molnar <[email protected]> CommitDate: Thu, 29 Oct 2009 08:47:45 +0100
x86: Fix SSE opcode map bug
Fix superscripts position because some superscripts of SSE opcode are not put in correct position.
LKML-Reference: <20091027204204.30545.97296.stgit@harusame>
--- arch/x86/lib/x86-opcode-map.txt | 10 +++++----- 1 files changed, 5 insertions(+), 5 deletions(-)
arch/x86/lib/x86-opcode-map.txt +5 -5
@@ -401,9 +401,9 @@ Referrer: 2-byte escape 62: punpckldq Pq,Qd | punpckldq Vdq,Wdq (66) 63: packsswb Pq,Qq | packsswb Vdq,Wdq (66) 64: pcmpgtb Pq,Qq | pcmpgtb Vdq,Wdq (66) -65: pcmpgtw Pq,Qq | pcmpgtw(66) Vdq,Wdq +65: pcmpgtw Pq,Qq | pcmpgtw Vdq,Wdq (66) 66: pcmpgtd Pq,Qq | pcmpgtd Vdq,Wdq (66) -67: packuswb Pq,Qq | packuswb(66) Vdq,Wdq +67: packuswb Pq,Qq | packuswb Vdq,Wdq (66) 68: punpckhbw Pq,Qd | punpckhbw Vdq,Wdq (66) 69: punpckhwd Pq,Qd | punpckhwd Vdq,Wdq (66) 6a: punpckhdq Pq,Qd | punpckhdq Vdq,Wdq (66)
@@ -425,8 +425,8 @@ Referrer: 2-byte escape 79: VMWRITE Gd/q,Ed/q 7a: 7b: -7c: haddps(F2) Vps,Wps | haddpd(66) Vpd,Wpd -7d: hsubps(F2) Vps,Wps | hsubpd(66) Vpd,Wpd +7c: haddps Vps,Wps (F2) | haddpd Vpd,Wpd (66) +7d: hsubps Vps,Wps (F2) | hsubpd Vpd,Wpd (66) 7e: movd/q Ed/q,Pd | movd/q Ed/q,Vdq (66) | movq Vq,Wq (F3) 7f: movq Qq,Pq | movdqa Wdq,Vdq (66) | movdqu Wdq,Vdq (F3) # 0x0f 0x80-0x8f
@@ -574,7 +574,7 @@ Referrer: 3-byte escape 1 01: phaddw Pq,Qq | phaddw Vdq,Wdq (66) 02: phaddd Pq,Qq | phaddd Vdq,Wdq (66) 03: phaddsw Pq,Qq | phaddsw Vdq,Wdq (66) -04: pmaddubsw Pq,Qq | pmaddubsw (66)Vdq,Wdq +04: pmaddubsw Pq,Qq | pmaddubsw Vdq,Wdq (66) 05: phsubw Pq,Qq | phsubw Vdq,Wdq (66) 06: phsubd Pq,Qq | phsubd Vdq,Wdq (66) 07: phsubsw Pq,Qq | phsubsw Vdq,Wdq (66)
PATCH 2/10 x86: Merge INAT_REXPFX into INAT_PFX_*
In reply to Masami HiramatsuMerge INAT_REXPFX into INAT_PFX_* macro and rename it to INAT_PFX_REX.
---
arch/x86/include/asm/inat.h | 36 +++++++++++++++++++--------------- arch/x86/lib/insn.c | 2 +- arch/x86/tools/gen-insn-attr-x86.awk | 6 +++--- 3 files changed, 24 insertions(+), 20 deletions(-)
arch/x86/include/asm/inat.h +20 -16
@@ -30,10 +30,11 @@#define INAT_OPCODE_TABLE_SIZE 256#define INAT_GROUP_TABLE_SIZE 8 -/* Legacy instruction prefixes */ +/* Legacy last prefixes */ #define INAT_PFX_OPNDSZ 1/* 0x66 */ /* LPFX1 */ #define INAT_PFX_REPNE 2/* 0xF2 */ /* LPFX2 */ #define INAT_PFX_REPE 3/* 0xF3 */ /* LPFX3 */ +/* Other Legacy prefixes */ #define INAT_PFX_LOCK 4/* 0xF0 */ #define INAT_PFX_CS 5/* 0x2E */ #define INAT_PFX_DS 6/* 0x3E */
@@ -42,8 +43,11 @@#define INAT_PFX_GS 9/* 0x65 */ #define INAT_PFX_SS 10/* 0x36 */ #define INAT_PFX_ADDRSZ 11/* 0x67 */ +/* x86-64 REX prefix */ +#define INAT_PFX_REX 12/* 0x4X */ -#define INAT_LPREFIX_MAX 3 +#define INAT_LSTPFX_MAX 3 +#define INAT_LGCPFX_MAX 11/* Immediate size */ #define INAT_IMM_BYTE 1
@@ -75,12 +79,11 @@#define INAT_IMM_MASK (((1 << INAT_IMM_BITS) - 1) << INAT_IMM_OFFS)/* Flags */ #define INAT_FLAG_OFFS (INAT_IMM_OFFS + INAT_IMM_BITS) -#define INAT_REXPFX (1 << INAT_FLAG_OFFS) -#define INAT_MODRM (1 << (INAT_FLAG_OFFS + 1)) -#define INAT_FORCE64 (1 << (INAT_FLAG_OFFS + 2)) -#define INAT_SCNDIMM (1 << (INAT_FLAG_OFFS + 3)) -#define INAT_MOFFSET (1 << (INAT_FLAG_OFFS + 4)) -#define INAT_VARIANT (1 << (INAT_FLAG_OFFS + 5)) +#define INAT_MODRM (1 << (INAT_FLAG_OFFS)) +#define INAT_FORCE64 (1 << (INAT_FLAG_OFFS + 1)) +#define INAT_SCNDIMM (1 << (INAT_FLAG_OFFS + 2)) +#define INAT_MOFFSET (1 << (INAT_FLAG_OFFS + 3)) +#define INAT_VARIANT (1 << (INAT_FLAG_OFFS + 4))/* Attribute making macros for attribute tables */ #define INAT_MAKE_PREFIX (pfx) (pfx << INAT_PFX_OFFS)#define INAT_MAKE_ESCAPE (esc) (esc << INAT_ESC_OFFS)
@@ -97,9 +100,10 @@ extern insn_attr_t inat_get_group_attribute(insn_byte_t modrm, insn_attr_t esc_attr);/* Attribute checking functions */ -static inline int inat_is_prefix (insn_attr_t attr) +static inline int inat_is_legacy_prefix (insn_attr_t attr) { -return attr &INAT_PFX_MASK ; + attr &=INAT_PFX_MASK ; +return attr && attr <=INAT_LGCPFX_MAX ; }static inline int inat_is_address_size_prefix (insn_attr_t attr)
@@ -112,9 +116,14 @@ static inline int inat_is_operand_size_prefix(insn_attr_t attr)return (attr &INAT_PFX_MASK ) ==INAT_PFX_OPNDSZ ; } +static inline int inat_is_rex_prefix (insn_attr_t attr) +{ +return (attr &INAT_PFX_MASK ) ==INAT_PFX_REX ; +} +static inline int inat_last_prefix_id (insn_attr_t attr) { -if ((attr &INAT_PFX_MASK ) >INAT_LPREFIX_MAX ) +if ((attr &INAT_PFX_MASK ) >INAT_LSTPFX_MAX )return 0 ;else return attr &INAT_PFX_MASK ;
@@ -155,11 +164,6 @@ static inline int inat_immediate_size(insn_attr_t attr)return (attr &INAT_IMM_MASK ) >>INAT_IMM_OFFS ; } -static inline int inat_is_rex_prefix (insn_attr_t attr) -{ -return attr &INAT_REXPFX ; -} -static inline int inat_has_modrm (insn_attr_t attr) {return attr &INAT_MODRM ;
arch/x86/lib/insn.c +1 -1
@@ -69,7 +69,7 @@ void insn_get_prefixes(struct insn *insn) lb =0 ; b =peek_next (insn_byte_t, insn); attr =inat_get_opcode_attribute (b); -while (inat_is_prefix (attr)) { +while (inat_is_legacy_prefix (attr)) {/* Skip if same prefix */ for (i =0 ; i < nb; i++)if (prefixes->bytes[i] == b)
arch/x86/tools/gen-insn-attr-x86.awk +3 -3
@@ -278,7 +278,7 @@ function convert_operands(opnd, i,imm,mod) # check REX prefix if (match(opcode, rex_expr)) - flags = add_flags(flags, "INAT_REXPFX") + flags = add_flags(flags, "INAT_MAKE_PREFIX(INAT_PFX_REX)") # check coprocessor escape : TODO if (match(opcode, fpu_expr))
@@ -316,7 +316,7 @@ END { # print escape opcode map's array print "/* Escape opcode map array */" print "const insn_attr_t const *inat_escape_tables[INAT_ESC_MAX + 1]" \ - "[INAT_LPREFIX_MAX + 1] = {" + "[INAT_LSTPFX_MAX + 1] = {" for (i = 0; i < geid; i++) for (j = 0; j < max_lprefix; j++) if (etable[i,j])
@@ -325,7 +325,7 @@ END { # print group opcode map's array print "/* Group opcode map array */" print "const insn_attr_t const *inat_group_tables[INAT_GRP_MAX + 1]"\ - "[INAT_LPREFIX_MAX + 1] = {" + "[INAT_LSTPFX_MAX + 1] = {" for (i = 0; i < ggid; i++) for (j = 0; j < max_lprefix; j++) if (gtable[i,j])
Signature · 7 lines
Masami Hiramatsu Software Engineer Hitachi Computer Products (America), Inc. Software Solutions Division e-mail: [email protected]
[tip:perf/probes] x86: Merge INAT_REXPFX into INAT_PFX_*
Commit-ID: 04d46c1b13b02e1e5c24eb270a01cf3f94ee4d04 Gitweb: http://git.kernel.org/tip/04d46c1b13b02e1e5c24eb270a01cf3f94ee4d04 Author: Masami Hiramatsu <[email protected]> AuthorDate: Tue, 27 Oct 2009 16:42:11 -0400 Committer: Ingo Molnar <[email protected]> CommitDate: Thu, 29 Oct 2009 08:47:45 +0100
x86: Merge INAT_REXPFX into INAT_PFX_*
Merge INAT_REXPFX into INAT_PFX_* macro and rename it to INAT_PFX_REX.
LKML-Reference: <20091027204211.30545.58090.stgit@harusame>
--- arch/x86/include/asm/inat.h | 36 ++++++++++++++++++--------------- arch/x86/lib/insn.c | 2 +- arch/x86/tools/gen-insn-attr-x86.awk | 6 ++-- 3 files changed, 24 insertions(+), 20 deletions(-)
arch/x86/include/asm/inat.h +20 -16
@@ -30,10 +30,11 @@#define INAT_OPCODE_TABLE_SIZE 256#define INAT_GROUP_TABLE_SIZE 8 -/* Legacy instruction prefixes */ +/* Legacy last prefixes */ #define INAT_PFX_OPNDSZ 1/* 0x66 */ /* LPFX1 */ #define INAT_PFX_REPNE 2/* 0xF2 */ /* LPFX2 */ #define INAT_PFX_REPE 3/* 0xF3 */ /* LPFX3 */ +/* Other Legacy prefixes */ #define INAT_PFX_LOCK 4/* 0xF0 */ #define INAT_PFX_CS 5/* 0x2E */ #define INAT_PFX_DS 6/* 0x3E */
@@ -42,8 +43,11 @@#define INAT_PFX_GS 9/* 0x65 */ #define INAT_PFX_SS 10/* 0x36 */ #define INAT_PFX_ADDRSZ 11/* 0x67 */ +/* x86-64 REX prefix */ +#define INAT_PFX_REX 12/* 0x4X */ -#define INAT_LPREFIX_MAX 3 +#define INAT_LSTPFX_MAX 3 +#define INAT_LGCPFX_MAX 11/* Immediate size */ #define INAT_IMM_BYTE 1
@@ -75,12 +79,11 @@#define INAT_IMM_MASK (((1 << INAT_IMM_BITS) - 1) << INAT_IMM_OFFS)/* Flags */ #define INAT_FLAG_OFFS (INAT_IMM_OFFS + INAT_IMM_BITS) -#define INAT_REXPFX (1 << INAT_FLAG_OFFS) -#define INAT_MODRM (1 << (INAT_FLAG_OFFS + 1)) -#define INAT_FORCE64 (1 << (INAT_FLAG_OFFS + 2)) -#define INAT_SCNDIMM (1 << (INAT_FLAG_OFFS + 3)) -#define INAT_MOFFSET (1 << (INAT_FLAG_OFFS + 4)) -#define INAT_VARIANT (1 << (INAT_FLAG_OFFS + 5)) +#define INAT_MODRM (1 << (INAT_FLAG_OFFS)) +#define INAT_FORCE64 (1 << (INAT_FLAG_OFFS + 1)) +#define INAT_SCNDIMM (1 << (INAT_FLAG_OFFS + 2)) +#define INAT_MOFFSET (1 << (INAT_FLAG_OFFS + 3)) +#define INAT_VARIANT (1 << (INAT_FLAG_OFFS + 4))/* Attribute making macros for attribute tables */ #define INAT_MAKE_PREFIX (pfx) (pfx << INAT_PFX_OFFS)#define INAT_MAKE_ESCAPE (esc) (esc << INAT_ESC_OFFS)
@@ -97,9 +100,10 @@ extern insn_attr_t inat_get_group_attribute(insn_byte_t modrm, insn_attr_t esc_attr);/* Attribute checking functions */ -static inline int inat_is_prefix (insn_attr_t attr) +static inline int inat_is_legacy_prefix (insn_attr_t attr) { -return attr &INAT_PFX_MASK ; + attr &=INAT_PFX_MASK ; +return attr && attr <=INAT_LGCPFX_MAX ; }static inline int inat_is_address_size_prefix (insn_attr_t attr)
@@ -112,9 +116,14 @@ static inline int inat_is_operand_size_prefix(insn_attr_t attr)return (attr &INAT_PFX_MASK ) ==INAT_PFX_OPNDSZ ; } +static inline int inat_is_rex_prefix (insn_attr_t attr) +{ +return (attr &INAT_PFX_MASK ) ==INAT_PFX_REX ; +} +static inline int inat_last_prefix_id (insn_attr_t attr) { -if ((attr &INAT_PFX_MASK ) >INAT_LPREFIX_MAX ) +if ((attr &INAT_PFX_MASK ) >INAT_LSTPFX_MAX )return 0 ;else return attr &INAT_PFX_MASK ;
@@ -155,11 +164,6 @@ static inline int inat_immediate_size(insn_attr_t attr)return (attr &INAT_IMM_MASK ) >>INAT_IMM_OFFS ; } -static inline int inat_is_rex_prefix (insn_attr_t attr) -{ -return attr &INAT_REXPFX ; -} -static inline int inat_has_modrm (insn_attr_t attr) {return attr &INAT_MODRM ;
arch/x86/lib/insn.c +1 -1
@@ -69,7 +69,7 @@ void insn_get_prefixes(struct insn *insn) lb =0 ; b =peek_next (insn_byte_t, insn); attr =inat_get_opcode_attribute (b); -while (inat_is_prefix (attr)) { +while (inat_is_legacy_prefix (attr)) {/* Skip if same prefix */ for (i =0 ; i < nb; i++)if (prefixes->bytes[i] == b)
arch/x86/tools/gen-insn-attr-x86.awk +3 -3
@@ -278,7 +278,7 @@ function convert_operands(opnd, i,imm,mod) # check REX prefix if (match(opcode, rex_expr)) - flags = add_flags(flags, "INAT_REXPFX") + flags = add_flags(flags, "INAT_MAKE_PREFIX(INAT_PFX_REX)") # check coprocessor escape : TODO if (match(opcode, fpu_expr))
@@ -316,7 +316,7 @@ END { # print escape opcode map's array print "/* Escape opcode map array */" print "const insn_attr_t const *inat_escape_tables[INAT_ESC_MAX + 1]" \ - "[INAT_LPREFIX_MAX + 1] = {" + "[INAT_LSTPFX_MAX + 1] = {" for (i = 0; i < geid; i++) for (j = 0; j < max_lprefix; j++) if (etable[i,j])
@@ -325,7 +325,7 @@ END { # print group opcode map's array print "/* Group opcode map array */" print "const insn_attr_t const *inat_group_tables[INAT_GRP_MAX + 1]"\ - "[INAT_LPREFIX_MAX + 1] = {" + "[INAT_LSTPFX_MAX + 1] = {" for (i = 0; i < ggid; i++) for (j = 0; j < max_lprefix; j++) if (gtable[i,j])
PATCH 3/10 x86: Add pclmulq to x86 opcode map
In reply to Masami HiramatsuAdd pclmulq opcode to x86 opcode map.
---
arch/x86/lib/x86-opcode-map.txt | 1 + 1 files changed, 1 insertions(+), 0 deletions(-)
arch/x86/lib/x86-opcode-map.txt +1 -0
@@ -672,6 +672,7 @@ Referrer: 3-byte escape 2 40: dpps Vdq,Wdq,Ib (66) 41: dppd Vdq,Wdq,Ib (66) 42: mpsadbw Vdq,Wdq,Ib (66) +44: pclmulq Vdq,Wdq,Ib (66) 60: pcmpestrm Vdq,Wdq,Ib (66) 61: pcmpestri Vdq,Wdq,Ib (66) 62: pcmpistrm Vdq,Wdq,Ib (66)
Signature · 7 lines
Masami Hiramatsu Software Engineer Hitachi Computer Products (America), Inc. Software Solutions Division e-mail: [email protected]
[tip:perf/probes] x86: Add pclmulq to x86 opcode map
Commit-ID: 82cb57028c864822c5a260f806d051e2ce28c86a Gitweb: http://git.kernel.org/tip/82cb57028c864822c5a260f806d051e2ce28c86a Author: Masami Hiramatsu <[email protected]> AuthorDate: Tue, 27 Oct 2009 16:42:19 -0400 Committer: Ingo Molnar <[email protected]> CommitDate: Thu, 29 Oct 2009 08:47:46 +0100
x86: Add pclmulq to x86 opcode map
Add pclmulq opcode to x86 opcode map.
LKML-Reference: <20091027204219.30545.82039.stgit@harusame>
--- arch/x86/lib/x86-opcode-map.txt | 1 + 1 files changed, 1 insertions(+), 0 deletions(-)
arch/x86/lib/x86-opcode-map.txt +1 -0
@@ -672,6 +672,7 @@ Referrer: 3-byte escape 2 40: dpps Vdq,Wdq,Ib (66) 41: dppd Vdq,Wdq,Ib (66) 42: mpsadbw Vdq,Wdq,Ib (66) +44: pclmulq Vdq,Wdq,Ib (66) 60: pcmpestrm Vdq,Wdq,Ib (66) 61: pcmpestri Vdq,Wdq,Ib (66) 62: pcmpistrm Vdq,Wdq,Ib (66)
PATCH 4/10 x86: AVX instruction set decoder support
In reply to Masami HiramatsuAdd Intel AVX(Advanced Vector Extensions) instruction set support to x86 instruction decoder. This adds insn.vex_prefix field for storing VEX prefixes, and introduces some original tags for expressing opcodes attributes.
---
arch/x86/include/asm/inat.h | 32 ++- arch/x86/include/asm/insn.h | 43 +++ arch/x86/lib/inat.c | 12 + arch/x86/lib/insn.c | 52 ++++ arch/x86/lib/x86-opcode-map.txt | 431 ++++++++++++++++++---------------- arch/x86/tools/gen-insn-attr-x86.awk | 94 ++++++- 6 files changed, 431 insertions(+), 233 deletions(-)
arch/x86/include/asm/inat.h +30 -2
@@ -32,8 +32,8 @@/* Legacy last prefixes */ #define INAT_PFX_OPNDSZ 1/* 0x66 */ /* LPFX1 */ -#define INAT_PFX_REPNE 2/* 0xF2 */ /* LPFX2 */ -#define INAT_PFX_REPE 3/* 0xF3 */ /* LPFX3 */ +#define INAT_PFX_REPE 2/* 0xF3 */ /* LPFX2 */ +#define INAT_PFX_REPNE 3/* 0xF2 */ /* LPFX3 */ /* Other Legacy prefixes */ #define INAT_PFX_LOCK 4/* 0xF0 */ #define INAT_PFX_CS 5/* 0x2E */
@@ -45,6 +45,9 @@#define INAT_PFX_ADDRSZ 11/* 0x67 */ /* x86-64 REX prefix */ #define INAT_PFX_REX 12/* 0x4X */ +/* AVX VEX prefixes */ +#define INAT_PFX_VEX2 13/* 2-bytes VEX prefix */ +#define INAT_PFX_VEX3 14/* 3-bytes VEX prefix */ #define INAT_LSTPFX_MAX 3#define INAT_LGCPFX_MAX 11
@@ -84,6 +87,8 @@#define INAT_SCNDIMM (1 << (INAT_FLAG_OFFS + 2))#define INAT_MOFFSET (1 << (INAT_FLAG_OFFS + 3))#define INAT_VARIANT (1 << (INAT_FLAG_OFFS + 4)) +#define INAT_VEXOK (1 << (INAT_FLAG_OFFS + 5)) +#define INAT_VEXONLY (1 << (INAT_FLAG_OFFS + 6))/* Attribute making macros for attribute tables */ #define INAT_MAKE_PREFIX (pfx) (pfx << INAT_PFX_OFFS)#define INAT_MAKE_ESCAPE (esc) (esc << INAT_ESC_OFFS)
@@ -98,6 +103,9 @@ extern insn_attr_t inat_get_escape_attribute(insn_byte_t opcode,extern insn_attr_t inat_get_group_attribute (insn_byte_t modrm,insn_byte_t last_pfx,insn_attr_t esc_attr); +extern insn_attr_t inat_get_avx_attribute (insn_byte_t opcode, +insn_byte_t vex_m, +insn_byte_t vex_pp);/* Attribute checking functions */ static inline int inat_is_legacy_prefix (insn_attr_t attr)
@@ -129,6 +137,17 @@ static inline int inat_last_prefix_id(insn_attr_t attr)return attr &INAT_PFX_MASK ; } +static inline int inat_is_vex_prefix (insn_attr_t attr) +{ + attr &=INAT_PFX_MASK ; +return attr ==INAT_PFX_VEX2 || attr ==INAT_PFX_VEX3 ; +} + +static inline int inat_is_vex3_prefix (insn_attr_t attr) +{ +return (attr &INAT_PFX_MASK ) ==INAT_PFX_VEX3 ; +} +static inline int inat_is_escape (insn_attr_t attr) {return attr &INAT_ESC_MASK ;
@@ -189,4 +208,13 @@ static inline int inat_has_variant(insn_attr_t attr) return attr & INAT_VARIANT; } +static inline int inat_accept_vex (insn_attr_t attr) +{ +return attr &INAT_VEXOK ; +} + +static inline int inat_must_vex (insn_attr_t attr) +{ +return attr &INAT_VEXONLY ; +}#endif
arch/x86/include/asm/insn.h +42 -1
69 lines not on this page · raw message
arch/x86/lib/inat.c +12 -0
@@ -76,3 +76,15 @@ insn_attr_t inat_get_group_attribute(insn_byte_t modrm, insn_byte_t last_pfx,inat_group_common_attribute (grp_attr); } +insn_attr_t inat_get_avx_attribute (insn_byte_t opcode,insn_byte_t vex_m, +insn_byte_t vex_p) +{ +const insn_attr_t *table; +if (vex_m >X86_VEX_M_MAX || vex_p >INAT_LSTPFX_MAX ) +return 0 ; + table = inat_avx_tables[vex_m][vex_p]; +if (!table) +return 0 ; +return table[opcode]; +} +
arch/x86/lib/insn.c +52 -0
82 lines not on this page · raw message
arch/x86/lib/x86-opcode-map.txt +225 -206
547 lines not on this page · raw message
arch/x86/tools/gen-insn-attr-x86.awk +70 -24
179 lines not on this page · raw message
Signature · 7 lines
Masami Hiramatsu Software Engineer Hitachi Computer Products (America), Inc. Software Solutions Division e-mail: [email protected]
[tip:perf/probes] x86: AVX instruction set decoder support
Commit-ID: e0e492e99b372c6990a5daca9e4683c341f1330e Gitweb: http://git.kernel.org/tip/e0e492e99b372c6990a5daca9e4683c341f1330e Author: Masami Hiramatsu <[email protected]> AuthorDate: Tue, 27 Oct 2009 16:42:27 -0400 Committer: Ingo Molnar <[email protected]> CommitDate: Thu, 29 Oct 2009 08:47:46 +0100
x86: AVX instruction set decoder support
Add Intel AVX(Advanced Vector Extensions) instruction set support to x86 instruction decoder. This adds insn.vex_prefix field for storing VEX prefixes, and introduces some original tags for expressing opcodes attributes.
LKML-Reference: <20091027204226.30545.23451.stgit@harusame>
--- arch/x86/include/asm/inat.h | 32 +++- arch/x86/include/asm/insn.h | 43 ++++- arch/x86/lib/inat.c | 12 + arch/x86/lib/insn.c | 52 ++++ arch/x86/lib/x86-opcode-map.txt | 431 ++++++++++++++++++---------------- arch/x86/tools/gen-insn-attr-x86.awk | 94 ++++++-- 6 files changed, 431 insertions(+), 233 deletions(-)
arch/x86/include/asm/inat.h +30 -2
@@ -32,8 +32,8 @@/* Legacy last prefixes */ #define INAT_PFX_OPNDSZ 1/* 0x66 */ /* LPFX1 */ -#define INAT_PFX_REPNE 2/* 0xF2 */ /* LPFX2 */ -#define INAT_PFX_REPE 3/* 0xF3 */ /* LPFX3 */ +#define INAT_PFX_REPE 2/* 0xF3 */ /* LPFX2 */ +#define INAT_PFX_REPNE 3/* 0xF2 */ /* LPFX3 */ /* Other Legacy prefixes */ #define INAT_PFX_LOCK 4/* 0xF0 */ #define INAT_PFX_CS 5/* 0x2E */
@@ -45,6 +45,9 @@#define INAT_PFX_ADDRSZ 11/* 0x67 */ /* x86-64 REX prefix */ #define INAT_PFX_REX 12/* 0x4X */ +/* AVX VEX prefixes */ +#define INAT_PFX_VEX2 13/* 2-bytes VEX prefix */ +#define INAT_PFX_VEX3 14/* 3-bytes VEX prefix */ #define INAT_LSTPFX_MAX 3#define INAT_LGCPFX_MAX 11
@@ -84,6 +87,8 @@#define INAT_SCNDIMM (1 << (INAT_FLAG_OFFS + 2))#define INAT_MOFFSET (1 << (INAT_FLAG_OFFS + 3))#define INAT_VARIANT (1 << (INAT_FLAG_OFFS + 4)) +#define INAT_VEXOK (1 << (INAT_FLAG_OFFS + 5)) +#define INAT_VEXONLY (1 << (INAT_FLAG_OFFS + 6))/* Attribute making macros for attribute tables */ #define INAT_MAKE_PREFIX (pfx) (pfx << INAT_PFX_OFFS)#define INAT_MAKE_ESCAPE (esc) (esc << INAT_ESC_OFFS)
@@ -98,6 +103,9 @@ extern insn_attr_t inat_get_escape_attribute(insn_byte_t opcode,extern insn_attr_t inat_get_group_attribute (insn_byte_t modrm,insn_byte_t last_pfx,insn_attr_t esc_attr); +extern insn_attr_t inat_get_avx_attribute (insn_byte_t opcode, +insn_byte_t vex_m, +insn_byte_t vex_pp);/* Attribute checking functions */ static inline int inat_is_legacy_prefix (insn_attr_t attr)
@@ -129,6 +137,17 @@ static inline int inat_last_prefix_id(insn_attr_t attr)return attr &INAT_PFX_MASK ; } +static inline int inat_is_vex_prefix (insn_attr_t attr) +{ + attr &=INAT_PFX_MASK ; +return attr ==INAT_PFX_VEX2 || attr ==INAT_PFX_VEX3 ; +} + +static inline int inat_is_vex3_prefix (insn_attr_t attr) +{ +return (attr &INAT_PFX_MASK ) ==INAT_PFX_VEX3 ; +} +static inline int inat_is_escape (insn_attr_t attr) {return attr &INAT_ESC_MASK ;
@@ -189,4 +208,13 @@ static inline int inat_has_variant(insn_attr_t attr) return attr & INAT_VARIANT; } +static inline int inat_accept_vex (insn_attr_t attr) +{ +return attr &INAT_VEXOK ; +} + +static inline int inat_must_vex (insn_attr_t attr) +{ +return attr &INAT_VEXONLY ; +}#endif
arch/x86/include/asm/insn.h +42 -1
69 lines not on this page · raw message
arch/x86/lib/inat.c +12 -0
@@ -76,3 +76,15 @@ insn_attr_t inat_get_group_attribute(insn_byte_t modrm, insn_byte_t last_pfx,inat_group_common_attribute (grp_attr); } +insn_attr_t inat_get_avx_attribute (insn_byte_t opcode,insn_byte_t vex_m, +insn_byte_t vex_p) +{ +const insn_attr_t *table; +if (vex_m >X86_VEX_M_MAX || vex_p >INAT_LSTPFX_MAX ) +return 0 ; + table = inat_avx_tables[vex_m][vex_p]; +if (!table) +return 0 ; +return table[opcode]; +} +
arch/x86/lib/insn.c +52 -0
82 lines not on this page · raw message
arch/x86/lib/x86-opcode-map.txt +225 -206
547 lines not on this page · raw message
arch/x86/tools/gen-insn-attr-x86.awk +70 -24
179 lines not on this page · raw message
PATCH 5/10 x86: Add Intel FMA instructions to x86 opcode map
In reply to Masami HiramatsuAdd Intel FMA(FUSED-MULTIPLY-ADD) instructions to x86 opcode map for x86 instruction decoder.
---
arch/x86/lib/x86-opcode-map.txt | 34 +++++++++++++++++++++++++++++++++- 1 files changed, 33 insertions(+), 1 deletions(-)
arch/x86/lib/x86-opcode-map.txt +33 -1
@@ -647,11 +647,43 @@ AVXcode: 2 3d: pmaxsd Vdq,Wdq (66),(VEX),(o128) 3e: pmaxuw Vdq,Wdq (66),(VEX),(o128) 3f: pmaxud Vdq,Wdq (66),(VEX),(o128) -# 0x0f 0x38 0x4f-0xff +# 0x0f 0x38 0x40-0x8f 40: pmulld Vdq,Wdq (66),(VEX),(o128) 41: phminposuw Vdq,Wdq (66),(VEX),(o128) 80: INVEPT Gd/q,Mdq (66) 81: INVPID Gd/q,Mdq (66) +# 0x0f 0x38 0x90-0xbf (FMA) +96: vfmaddsub132pd/ps /r (66),(VEX) +97: vfmsubadd132pd/ps /r (66),(VEX) +98: vfmadd132pd/ps /r (66),(VEX) +99: vfmadd132sd/ss /r (66),(VEX),(o128) +9a: vfmsub132pd/ps /r (66),(VEX) +9b: vfmsub132sd/ss /r (66),(VEX),(o128) +9c: vfnmadd132pd/ps /r (66),(VEX) +9d: vfnmadd132sd/ss /r (66),(VEX),(o128) +9e: vfnmsub132pd/ps /r (66),(VEX) +9f: vfnmsub132sd/ss /r (66),(VEX),(o128) +a6: vfmaddsub213pd/ps /r (66),(VEX) +a7: vfmsubadd213pd/ps /r (66),(VEX) +a8: vfmadd213pd/ps /r (66),(VEX) +a9: vfmadd213sd/ss /r (66),(VEX),(o128) +aa: vfmsub213pd/ps /r (66),(VEX) +ab: vfmsub213sd/ss /r (66),(VEX),(o128) +ac: vfnmadd213pd/ps /r (66),(VEX) +ad: vfnmadd213sd/ss /r (66),(VEX),(o128) +ae: vfnmsub213pd/ps /r (66),(VEX) +af: vfnmsub213sd/ss /r (66),(VEX),(o128) +b6: vfmaddsub231pd/ps /r (66),(VEX) +b7: vfmsubadd231pd/ps /r (66),(VEX) +b8: vfmadd231pd/ps /r (66),(VEX) +b9: vfmadd231sd/ss /r (66),(VEX),(o128) +ba: vfmsub231pd/ps /r (66),(VEX) +bb: vfmsub231sd/ss /r (66),(VEX),(o128) +bc: vfnmadd231pd/ps /r (66),(VEX) +bd: vfnmadd231sd/ss /r (66),(VEX),(o128) +be: vfnmsub231pd/ps /r (66),(VEX) +bf: vfnmsub231sd/ss /r (66),(VEX),(o128) +# 0x0f 0x38 0xc0-0xff db: aesimc Vdq,Wdq (66),(VEX),(o128) dc: aesenc Vdq,Wdq (66),(VEX),(o128) dd: aesenclast Vdq,Wdq (66),(VEX),(o128)
Signature · 7 lines
Masami Hiramatsu Software Engineer Hitachi Computer Products (America), Inc. Software Solutions Division e-mail: [email protected]
[tip:perf/probes] x86: Add Intel FMA instructions to x86 opcode map
Commit-ID: 3f7e454af1dd8b9cea410d9380d3f71477e94f2b Gitweb: http://git.kernel.org/tip/3f7e454af1dd8b9cea410d9380d3f71477e94f2b Author: Masami Hiramatsu <[email protected]> AuthorDate: Tue, 27 Oct 2009 16:42:35 -0400 Committer: Ingo Molnar <[email protected]> CommitDate: Thu, 29 Oct 2009 08:47:47 +0100
x86: Add Intel FMA instructions to x86 opcode map
Add Intel FMA(FUSED-MULTIPLY-ADD) instructions to x86 opcode map for x86 instruction decoder.
LKML-Reference: <20091027204235.30545.33997.stgit@harusame>
--- arch/x86/lib/x86-opcode-map.txt | 34 +++++++++++++++++++++++++++++++++- 1 files changed, 33 insertions(+), 1 deletions(-)
arch/x86/lib/x86-opcode-map.txt +33 -1
@@ -647,11 +647,43 @@ AVXcode: 2 3d: pmaxsd Vdq,Wdq (66),(VEX),(o128) 3e: pmaxuw Vdq,Wdq (66),(VEX),(o128) 3f: pmaxud Vdq,Wdq (66),(VEX),(o128) -# 0x0f 0x38 0x4f-0xff +# 0x0f 0x38 0x40-0x8f 40: pmulld Vdq,Wdq (66),(VEX),(o128) 41: phminposuw Vdq,Wdq (66),(VEX),(o128) 80: INVEPT Gd/q,Mdq (66) 81: INVPID Gd/q,Mdq (66) +# 0x0f 0x38 0x90-0xbf (FMA) +96: vfmaddsub132pd/ps /r (66),(VEX) +97: vfmsubadd132pd/ps /r (66),(VEX) +98: vfmadd132pd/ps /r (66),(VEX) +99: vfmadd132sd/ss /r (66),(VEX),(o128) +9a: vfmsub132pd/ps /r (66),(VEX) +9b: vfmsub132sd/ss /r (66),(VEX),(o128) +9c: vfnmadd132pd/ps /r (66),(VEX) +9d: vfnmadd132sd/ss /r (66),(VEX),(o128) +9e: vfnmsub132pd/ps /r (66),(VEX) +9f: vfnmsub132sd/ss /r (66),(VEX),(o128) +a6: vfmaddsub213pd/ps /r (66),(VEX) +a7: vfmsubadd213pd/ps /r (66),(VEX) +a8: vfmadd213pd/ps /r (66),(VEX) +a9: vfmadd213sd/ss /r (66),(VEX),(o128) +aa: vfmsub213pd/ps /r (66),(VEX) +ab: vfmsub213sd/ss /r (66),(VEX),(o128) +ac: vfnmadd213pd/ps /r (66),(VEX) +ad: vfnmadd213sd/ss /r (66),(VEX),(o128) +ae: vfnmsub213pd/ps /r (66),(VEX) +af: vfnmsub213sd/ss /r (66),(VEX),(o128) +b6: vfmaddsub231pd/ps /r (66),(VEX) +b7: vfmsubadd231pd/ps /r (66),(VEX) +b8: vfmadd231pd/ps /r (66),(VEX) +b9: vfmadd231sd/ss /r (66),(VEX),(o128) +ba: vfmsub231pd/ps /r (66),(VEX) +bb: vfmsub231sd/ss /r (66),(VEX),(o128) +bc: vfnmadd231pd/ps /r (66),(VEX) +bd: vfnmadd231sd/ss /r (66),(VEX),(o128) +be: vfnmsub231pd/ps /r (66),(VEX) +bf: vfnmsub231sd/ss /r (66),(VEX),(o128) +# 0x0f 0x38 0xc0-0xff db: aesimc Vdq,Wdq (66),(VEX),(o128) dc: aesenc Vdq,Wdq (66),(VEX),(o128) dd: aesenclast Vdq,Wdq (66),(VEX),(o128)
PATCH 6/10 kprobe-tracer: Compare both of event-name and event-group to find probe
In reply to Masami HiramatsuFix find_probe_event() to compare both of event-name and event-group. Without this fix, kprobe-tracer overwrites existing same event-name probe even if its group-name is different.
---
kernel/trace/trace_kprobe.c | 8 +++++--- 1 files changed, 5 insertions(+), 3 deletions(-)
kernel/trace/trace_kprobe.c +5 -3
@@ -353,12 +353,14 @@ static void free_trace_probe(struct trace_probe *tp)kfree (tp); } -static struct trace_probe *find_probe_event (const char *event) +static struct trace_probe *find_probe_event (const char *event, +const char *group) {struct trace_probe *tp;list_for_each_entry (tp, &probe_list, list) -if (!strcmp (tp->call.name, event)) +if (strcmp (tp->call.name, event) ==0 && +strcmp (tp->call.system, group) ==0 )return tp;return NULL ; }
@@ -383,7 +385,7 @@ static int register_trace_probe(struct trace_probe *tp)mutex_lock (&probe_lock);/* register as an event */ - old_tp =find_probe_event (tp->call.name); + old_tp =find_probe_event (tp->call.name, tp->call.system);if (old_tp) {/* delete old event */ unregister_trace_probe (old_tp);
Signature · 7 lines
Masami Hiramatsu Software Engineer Hitachi Computer Products (America), Inc. Software Solutions Division e-mail: [email protected]
[tip:perf/probes] kprobe-tracer: Compare both of event-name and event-group to find probe
Commit-ID: dd004c475cd15a5749b04b0283d41ffdfa57d658 Gitweb: http://git.kernel.org/tip/dd004c475cd15a5749b04b0283d41ffdfa57d658 Author: Masami Hiramatsu <[email protected]> AuthorDate: Tue, 27 Oct 2009 16:42:44 -0400 Committer: Ingo Molnar <[email protected]> CommitDate: Thu, 29 Oct 2009 08:47:47 +0100
kprobe-tracer: Compare both of event-name and event-group to find probe
Fix find_probe_event() to compare both of event-name and event-group. Without this fix, kprobe-tracer overwrites existing same event-name probe even if its group-name is different.
LKML-Reference: <20091027204244.30545.27516.stgit@harusame>
--- kernel/trace/trace_kprobe.c | 8 +++++--- 1 files changed, 5 insertions(+), 3 deletions(-)
kernel/trace/trace_kprobe.c +5 -3
@@ -353,12 +353,14 @@ static void free_trace_probe(struct trace_probe *tp)kfree (tp); } -static struct trace_probe *find_probe_event (const char *event) +static struct trace_probe *find_probe_event (const char *event, +const char *group) {struct trace_probe *tp;list_for_each_entry (tp, &probe_list, list) -if (!strcmp (tp->call.name, event)) +if (strcmp (tp->call.name, event) ==0 && +strcmp (tp->call.system, group) ==0 )return tp;return NULL ; }
@@ -383,7 +385,7 @@ static int register_trace_probe(struct trace_probe *tp)mutex_lock (&probe_lock);/* register as an event */ - old_tp =find_probe_event (tp->call.name); + old_tp =find_probe_event (tp->call.name, tp->call.system);if (old_tp) {/* delete old event */ unregister_trace_probe (old_tp);
PATCH 7/10 perf/probes: Exit searching after finding target function
In reply to Masami HiramatsuExit searching after finding real (not-inlined) function, because there should be no same symbol in that CU.
---
tools/perf/util/probe-finder.c | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-)
tools/perf/util/probe-finder.c +2 -2
@@ -585,14 +585,14 @@ static int probefunc_callback(struct die_link *dlink, void *data)DIE_IF (ret !=DW_DLV_OK );pr_debug ("inline definition offset %lld\n" , pf->inl_offs); -return 0 ; +return 0 ;/* Continue to search */ }/* Get probe address */ pf->addr =die_get_entrypc (dlink->die); pf->addr += pp->offset;/* TODO: Check the address in this function */ show_probepoint (dlink->die, pp->offset, pf); -/* Continue to search */ +return 1 ;/* Exit; no same symbol in this CU. */ } }else if (tag == DW_TAG_inlined_subroutine && pf->inl_offs) {if (die_get_abstract_origin (dlink->die) == pf->inl_offs) {
Signature · 7 lines
Masami Hiramatsu Software Engineer Hitachi Computer Products (America), Inc. Software Solutions Division e-mail: [email protected]
[tip:perf/probes] perf/probes: Exit searching after finding target function
Commit-ID: 8030c5f5a57e018fcdeb1f395d7adc123b48ced6 Gitweb: http://git.kernel.org/tip/8030c5f5a57e018fcdeb1f395d7adc123b48ced6 Author: Masami Hiramatsu <[email protected]> AuthorDate: Tue, 27 Oct 2009 16:42:53 -0400 Committer: Ingo Molnar <[email protected]> CommitDate: Thu, 29 Oct 2009 08:47:48 +0100
perf/probes: Exit searching after finding target function
Exit searching after finding real (not-inlined) function, because there should be no same symbol in that CU.
LKML-Reference: <20091027204252.30545.19251.stgit@harusame>
--- tools/perf/util/probe-finder.c | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-)
tools/perf/util/probe-finder.c +2 -2
@@ -585,14 +585,14 @@ static int probefunc_callback(struct die_link *dlink, void *data)DIE_IF (ret !=DW_DLV_OK );pr_debug ("inline definition offset %lld\n" , pf->inl_offs); -return 0 ; +return 0 ;/* Continue to search */ }/* Get probe address */ pf->addr =die_get_entrypc (dlink->die); pf->addr += pp->offset;/* TODO: Check the address in this function */ show_probepoint (dlink->die, pp->offset, pf); -/* Continue to search */ +return 1 ;/* Exit; no same symbol in this CU. */ } }else if (tag == DW_TAG_inlined_subroutine && pf->inl_offs) {if (die_get_abstract_origin (dlink->die) == pf->inl_offs) {
PATCH 8/10 perf/probes: Change command-line option of perf-probe
In reply to Masami HiramatsuChange command-line option from -P to --add, and accepting probes without --add too.
perf probe --add "probe-define"
or, just
perf probe "probe-define"
---
tools/perf/builtin-probe.c | 28 ++++++++++++++++++---------- 1 files changed, 18 insertions(+), 10 deletions(-)
tools/perf/builtin-probe.c +18 -10
@@ -65,8 +65,8 @@ static struct { #define semantic_error(msg ...) die("Semantic error :" msg) -static int parse_probepoint (const struct option *opt__used , -const char *str,int unset__used ) +/* Parse a probe point. Note that any error must die. */ +static void parse_probepoint (const char *str) {char *argv[MAX_PROBE_ARGS +2 ];/* Event + probe + args */ int argc, i;
@@ -75,9 +75,6 @@ static int parse_probepoint(const struct option *opt __used,char **event = &session.events[session.nr_probe];int retp =0 ; -if (!str)/* The end of probe points */ -return 0 ; -pr_debug ("probe-definition(%d): %s\n" , session.nr_probe, str);if (++session.nr_probe ==MAX_PROBES )semantic_error ("Too many probes" );
@@ -176,6 +173,13 @@ static int parse_probepoint(const struct option *opt __used, }pr_debug ("%d arguments\n" , pp->nr_args); +} + +static int opt_add_probepoint (const struct option *opt__used , +const char *str,int unset__used ) +{ +if (str) +parse_probepoint (str);return 0 ; }
@@ -211,7 +215,8 @@ static int open_default_vmlinux(void)#endif static const char *const probe_usage[] = { -"perf probe [<options>] -P 'PROBEDEF' [-P 'PROBEDEF' ...]" , +"perf probe [<options>] 'PROBEDEF' ['PROBEDEF' ...]" , +"perf probe [<options>] --add 'PROBEDEF' [--add 'PROBEDEF' ...]" ,NULL };
@@ -222,7 +227,7 @@ static const struct option options[] = {OPT_STRING ('k' ,"vmlinux" , &session.vmlinux,"file" ,"vmlinux/module pathname" ), #endif - OPT_CALLBACK('P', "probe", NULL, + OPT_CALLBACK('a', "add", NULL, #ifdef NO_LIBDWARF "p|r:[GRP/]NAME FUNC[+OFFS] [ARG ...]", #else
@@ -243,7 +248,7 @@ static const struct option options[] = { "\t\tARG:\tProbe argument (local variable name or\n" #endif "\t\t\tkprobe-tracer argument format is supported.)\n", - parse_probepoint), + opt_add_probepoint),OPT_END () };
@@ -296,8 +301,11 @@ int cmd_probe(int argc, const char **argv, const char *prefix __used)char buf[MAX_CMDLEN ]; argc =parse_options (argc, argv, options, probe_usage, -PARSE_OPT_STOP_AT_NON_OPTION ); -if (argc || session.nr_probe ==0 ) +PARSE_OPT_STOP_AT_NON_OPTION ); +for (i =0 ; i < argc; i++) +parse_probe_event (argv[i]); + +if (session.nr_probe ==0 )usage_with_options (probe_usage, options);#ifdef NO_LIBDWARF
Signature · 7 lines
Masami Hiramatsu Software Engineer Hitachi Computer Products (America), Inc. Software Solutions Division e-mail: [email protected]
[tip:perf/probes] perf/probes: Improve command-line option of perf-probe
Commit-ID: 46ab49267d338eb5056d0077e16346509b9e9284 Gitweb: http://git.kernel.org/tip/46ab49267d338eb5056d0077e16346509b9e9284 Author: Masami Hiramatsu <[email protected]> AuthorDate: Tue, 27 Oct 2009 16:43:02 -0400 Committer: Ingo Molnar <[email protected]> CommitDate: Thu, 29 Oct 2009 08:47:48 +0100
perf/probes: Improve command-line option of perf-probe
Change command-line option from -P to --add, and accepting probes without --add too.
perf probe --add "probe-define"
or, just:
perf probe "probe-define"
LKML-Reference: <20091027204301.30545.48600.stgit@harusame>
--- tools/perf/builtin-probe.c | 28 ++++++++++++++++++---------- 1 files changed, 18 insertions(+), 10 deletions(-)
tools/perf/builtin-probe.c +18 -10
@@ -65,8 +65,8 @@ static struct { #define semantic_error(msg ...) die("Semantic error :" msg) -static int parse_probepoint (const struct option *opt__used , -const char *str,int unset__used ) +/* Parse a probe point. Note that any error must die. */ +static void parse_probepoint (const char *str) {char *argv[MAX_PROBE_ARGS +2 ];/* Event + probe + args */ int argc, i;
@@ -75,9 +75,6 @@ static int parse_probepoint(const struct option *opt __used,char **event = &session.events[session.nr_probe];int retp =0 ; -if (!str)/* The end of probe points */ -return 0 ; -pr_debug ("probe-definition(%d): %s\n" , session.nr_probe, str);if (++session.nr_probe ==MAX_PROBES )semantic_error ("Too many probes" );
@@ -176,6 +173,13 @@ static int parse_probepoint(const struct option *opt __used, }pr_debug ("%d arguments\n" , pp->nr_args); +} + +static int opt_add_probepoint (const struct option *opt__used , +const char *str,int unset__used ) +{ +if (str) +parse_probepoint (str);return 0 ; }
@@ -211,7 +215,8 @@ static int open_default_vmlinux(void)#endif static const char *const probe_usage[] = { -"perf probe [<options>] -P 'PROBEDEF' [-P 'PROBEDEF' ...]" , +"perf probe [<options>] 'PROBEDEF' ['PROBEDEF' ...]" , +"perf probe [<options>] --add 'PROBEDEF' [--add 'PROBEDEF' ...]" ,NULL };
@@ -222,7 +227,7 @@ static const struct option options[] = {OPT_STRING ('k' ,"vmlinux" , &session.vmlinux,"file" ,"vmlinux/module pathname" ), #endif - OPT_CALLBACK('P', "probe", NULL, + OPT_CALLBACK('a', "add", NULL, #ifdef NO_LIBDWARF "p|r:[GRP/]NAME FUNC[+OFFS] [ARG ...]", #else
@@ -243,7 +248,7 @@ static const struct option options[] = { "\t\tARG:\tProbe argument (local variable name or\n" #endif "\t\t\tkprobe-tracer argument format is supported.)\n", - parse_probepoint), + opt_add_probepoint),OPT_END () };
@@ -296,8 +301,11 @@ int cmd_probe(int argc, const char **argv, const char *prefix __used)char buf[MAX_CMDLEN ]; argc =parse_options (argc, argv, options, probe_usage, -PARSE_OPT_STOP_AT_NON_OPTION ); -if (argc || session.nr_probe ==0 ) +PARSE_OPT_STOP_AT_NON_OPTION ); +for (i =0 ; i < argc; i++) +parse_probe_event (argv[i]); + +if (session.nr_probe ==0 )usage_with_options (probe_usage, options);#ifdef NO_LIBDWARF
PATCH 9/10 perf/probes: Change probepoint syntax of perf-probe
In reply to Masami HiramatsuThis changes probe point syntax of perf-probe as below
<SRC>[:ABS_LN] [ARGS]
or
<FUNC>[+OFFS|%return][@SRC] [ARGS]
And event name and event group name are automatically generated based on probe-symbol and offset as below.
perfprobes/SYMBOL_OFFSET[_NUM]
Where SYMBOL is the probing symbol and OFFSET is
the byte offset from the symbol.
---
tools/perf/builtin-probe.c | 181 +++++++++++++++++++++++++--------------- tools/perf/util/probe-finder.c | 10 ++ tools/perf/util/probe-finder.h | 2 3 files changed, 123 insertions(+), 70 deletions(-)
tools/perf/builtin-probe.c +111 -70
@@ -52,6 +52,7 @@ const char *default_search_path[NR_SEARCH_PATH] = {#define MAX_PATH_LEN 256#define MAX_PROBES 128#define MAX_PROBE_ARGS 128 +#define PERFPROBE_GROUP "perfprobe"/* Session management structure */ static struct {
@@ -60,20 +61,100 @@ static struct {int need_dwarf;int nr_probe;struct probe_point probes[MAX_PROBES ]; -char *events[MAX_PROBES ]; } session; #define semantic_error(msg ...) die("Semantic error :" msg) -/* Parse a probe point. Note that any error must die. */ -static void parse_probepoint (const char *str) +/* Parse probe point. Return 1 if return probe */ +static void parse_probe_point (char *arg,struct probe_point *pp) +{ +char *ptr, *tmp; +char c, nc; +/* +* <Syntax> +* perf probe SRC:LN +* perf probe FUNC[+OFFS|%return][@SRC] +*/ + + ptr =strpbrk (arg,":+@%" ); +if (ptr) { + nc = *ptr; + *ptr++ ='\0' ; + } + +/* Check arg is function or file and copy it */ +if (strchr (arg,'.' ))/* File */ + pp->file =strdup (arg); +else /* Function */ + pp->function =strdup (arg); +DIE_IF (pp->file ==NULL && pp->function ==NULL ); + +/* Parse other options */ +while (ptr) { + arg = ptr; + c = nc; + ptr =strpbrk (arg,":+@%" ); +if (ptr) { + nc = *ptr; + *ptr++ ='\0' ; + } +switch (c) { +case ':' :/* Line number */ + pp->line =strtoul (arg, &tmp,0 ); +if (*tmp !='\0' ) +semantic_error ("There is non-digit charactor" +" in line number." ); +break ; +case '+' :/* Byte offset from a symbol */ + pp->offset =strtoul (arg, &tmp,0 ); +if (*tmp !='\0' ) +semantic_error ("There is non-digit charactor" +" in offset." ); +break ; +case '@' :/* File name */ +if (pp->file) +semantic_error ("SRC@SRC is not allowed." ); + pp->file =strdup (arg); +DIE_IF (pp->file ==NULL ); +if (ptr) +semantic_error ("@SRC must be the last " +"option." ); +break ; +case '%' :/* Probe places */ +if (strcmp (arg,"return" ) ==0 ) { + pp->retprobe =1 ; + }else /* Others not supported yet */ +semantic_error ("%%%s is not supported." , arg); +break ; +default : +DIE_IF ("Program has a bug." ); +break ; + } + } + +/* Exclusion check */ +if (pp->line && pp->function) +semantic_error ("Function-relative line number is not" +" supported yet." ); +if (!pp->line && pp->file && !pp->function) +semantic_error ("File always requires line number." ); +if (pp->offset && !pp->function) +semantic_error ("Offset requires an entry function." ); +if (pp->retprobe && !pp->function) +semantic_error ("Return probe requires an entry function." ); +if (pp->offset && pp->retprobe) +semantic_error ("Offset can't be used with return probe." ); + +pr_debug ("symbol:%s file:%s line:%d offset:%d, return:%d\n" , + pp->function, pp->file, pp->line, pp->offset, pp->retprobe); +} + +/* Parse an event definition. Note that any error must die. */ +static void parse_probe_event (const char *str) {char *argv[MAX_PROBE_ARGS +2 ];/* Event + probe + args */ int argc, i; -char *arg, *ptr;struct probe_point *pp = &session.probes[session.nr_probe]; -char **event = &session.events[session.nr_probe]; -int retp =0 ;pr_debug ("probe-definition(%d): %s\n" , session.nr_probe, str);if (++session.nr_probe ==MAX_PROBES )
@@ -103,70 +184,28 @@ static void parse_probepoint(const char *str)pr_debug ("argv[%d]=%s\n" , argc, argv[argc -1 ]); } }while (*str !='\0' ); -if (argc <2 ) -semantic_error ("Need event-name and probe-point at least." ); - -/* Parse the event name */ -if (argv[0 ][0 ] =='r' ) - retp =1 ; -else if (argv[0 ][0 ] !='p' ) -semantic_error ("You must specify 'p'(kprobe) or" -" 'r'(kretprobe) first." ); -/* TODO: check event name */ - *event = argv[0 ]; +if (!argc) +semantic_error ("An empty argument." );/* Parse probe point */ - arg = argv[1 ]; -if (arg[0 ] =='@' ) { -/* Source Line */ - arg++; - ptr =strchr (arg,':' ); -if (!ptr || !isdigit (ptr[1 ])) -semantic_error ("Line number is required." ); - *ptr++ ='\0' ; -if (strlen (arg) ==0 ) -semantic_error ("No file name." ); - pp->file =strdup (arg); - pp->line =atoi (ptr); -if (!pp->file || !pp->line) -semantic_error ("Failed to parse line." ); -pr_debug ("file:%s line:%d\n" , pp->file, pp->line); - }else { -/* Function name */ - ptr =strchr (arg,'+' ); -if (ptr) { -if (!isdigit (ptr[1 ])) -semantic_error ("Offset is required." ); - *ptr++ ='\0' ; - pp->offset =atoi (ptr); - }else - ptr = arg; - ptr =strchr (ptr,'@' ); -if (ptr) { - *ptr++ ='\0' ; - pp->file =strdup (ptr); - } - pp->function =strdup (arg); -pr_debug ("symbol:%s file:%s offset:%d\n" , - pp->function, pp->file, pp->offset); - } -free (argv[1 ]); +parse_probe_point (argv[0 ], pp); +free (argv[0 ]);if (pp->file) session.need_dwarf =1 ;/* Copy arguments */ - pp->nr_args = argc -2 ; + pp->nr_args = argc -1 ;if (pp->nr_args >0 ) { pp->args = (char **)malloc (sizeof (char *) * pp->nr_args);if (!pp->args)die ("malloc" ); -memcpy (pp->args, &argv[2 ],sizeof (char *) * pp->nr_args); +memcpy (pp->args, &argv[1 ],sizeof (char *) * pp->nr_args); }/* Ensure return probe has no C argument */ for (i =0 ; i < pp->nr_args; i++)if (is_c_varname (pp->args[i])) { -if (retp) +if (pp->retprobe)semantic_error ("You can't specify local" " variable for kretprobe" ); session.need_dwarf =1 ;
@@ -175,11 +214,11 @@ static void parse_probepoint(const char *str)pr_debug ("%d arguments\n" , pp->nr_args); } -static int opt_add_probepoint (const struct option *opt__used , +static int opt_add_probe_event (const struct option *opt__used ,const char *str,int unset__used ) {if (str) -parse_probepoint (str); +parse_probe_event (str);return 0 ; }
@@ -229,17 +268,16 @@ static const struct option options[] = {#endif OPT_CALLBACK('a', "add", NULL, #ifdef NO_LIBDWARF - "p|r:[GRP/]NAME FUNC[+OFFS] [ARG ...]", + "FUNC[+OFFS|%return] [ARG ...]", #else - "p|r:[GRP/]NAME FUNC[+OFFS][@SRC]|@SRC:LINE [ARG ...]", + "FUNC[+OFFS|%return][@SRC]|SRC:LINE [ARG ...]", #endif "probe point definition, where\n" - "\t\tp:\tkprobe probe\n" - "\t\tr:\tkretprobe probe\n" "\t\tGRP:\tGroup name (optional)\n" "\t\tNAME:\tEvent name\n" "\t\tFUNC:\tFunction name\n" "\t\tOFFS:\tOffset from function entry (in byte)\n" + "\t\t%return:\tPut the probe at function return\n" #ifdef NO_LIBDWARF "\t\tARG:\tProbe argument (only \n" #else
@@ -248,7 +286,7 @@ static const struct option options[] = { "\t\tARG:\tProbe argument (local variable name or\n" #endif "\t\t\tkprobe-tracer argument format is supported.)\n", - opt_add_probepoint), + opt_add_probe_event),OPT_END () };
@@ -266,7 +304,7 @@ static int write_new_event(int fd, const char *buf)#define MAX_CMDLEN 256 -static int synthesize_probepoint (struct probe_point *pp) +static int synthesize_probe_event (struct probe_point *pp) {char *buf;int i, len, ret;
@@ -316,12 +354,12 @@ int cmd_probe(int argc, const char **argv, const char *prefix __used)/* Synthesize probes without dwarf */ for (j =0 ; j < session.nr_probe; j++) {#ifndef NO_LIBDWARF -if (session.events[j][0 ] !='r' ) { +if (!session.probes[j].retprobe) { session.need_dwarf =1 ;continue ; }#endif - ret =synthesize_probepoint (&session.probes[j]); + ret =synthesize_probe_event (&session.probes[j]);if (ret == -E2BIG )semantic_error ("probe point is too long." );else if (ret <0 )
@@ -349,7 +387,6 @@ int cmd_probe(int argc, const char **argv, const char *prefix __used) ret =find_probepoint (fd, pp);if (ret <=0 )die ("No probe point found.\n" ); -pr_debug ("probe event %s found\n" , session.events[j]); }close (fd);
@@ -364,13 +401,17 @@ setup_probes:for (j =0 ; j < session.nr_probe; j++) { pp = &session.probes[j];if (pp->found ==1 ) { -snprintf (buf,MAX_CMDLEN ,"%s %s\n" , - session.events[j], pp->probes[0 ]); +snprintf (buf,MAX_CMDLEN ,"%c:%s/%s_%x %s\n" , + pp->retprobe ?'r' :'p' ,PERFPROBE_GROUP , + pp->function, pp->offset, pp->probes[0 ]);write_new_event (fd, buf); }else for (i =0 ; i < pp->found; i++) { -snprintf (buf,MAX_CMDLEN ,"%s%d %s\n" , - session.events[j], i, pp->probes[i]); +snprintf (buf,MAX_CMDLEN ,"%c:%s/%s_%x_%d %s\n" , + pp->retprobe ?'r' :'p' , +PERFPROBE_GROUP , + pp->function, pp->offset, i, + pp->probes[0 ]);write_new_event (fd, buf); } }
tools/perf/util/probe-finder.c +10 -0
@@ -483,10 +483,20 @@ static void show_probepoint(Dwarf_Die sp_die, Dwarf_Signed offs,if (ret ==DW_DLV_OK ) { ret =snprintf (tmp,MAX_PROBE_BUFFER ,"%s+%u" , name, (unsigned int )offs); +/* Copy the function name if possible */ +if (!pp->function) { + pp->function =strdup (name); + pp->offset = offs; + }dwarf_dealloc (__dw_debug, name,DW_DLA_STRING ); }else {/* This function has no name. */ ret =snprintf (tmp,MAX_PROBE_BUFFER ,"0x%llx" , pf->addr); +if (!pp->function) { +/* TODO: Use _stext */ + pp->function =strdup ("" ); + pp->offset = (int )pf->addr; + } }DIE_IF (ret <0 );DIE_IF (ret >=MAX_PROBE_BUFFER );
tools/perf/util/probe-finder.h +2 -0
@@ -22,6 +22,8 @@ struct probe_point {int nr_args;/* Number of arguments */ char **args;/* Arguments */ +int retprobe;/* Return probe */ +/* Output */ int found;/* Number of found probe points */ char *probes[MAX_PROBES ];/* Output buffers (will be allocated)*/
Signature · 7 lines
Masami Hiramatsu Software Engineer Hitachi Computer Products (America), Inc. Software Solutions Division e-mail: [email protected]
[tip:perf/probes] perf/probes: Improve probe point syntax of perf-probe
Commit-ID: 253977b0d87fbb793f12b1661a763ae264028ccf Gitweb: http://git.kernel.org/tip/253977b0d87fbb793f12b1661a763ae264028ccf Author: Masami Hiramatsu <[email protected]> AuthorDate: Tue, 27 Oct 2009 16:43:10 -0400 Committer: Ingo Molnar <[email protected]> CommitDate: Thu, 29 Oct 2009 08:47:49 +0100
perf/probes: Improve probe point syntax of perf-probe
This changes probe point syntax of perf-probe as below
<SRC>[:ABS_LN] [ARGS]
or
<FUNC>[+OFFS|%return][@SRC] [ARGS]
And event name and event group name are automatically generated based on probe-symbol and offset as below.
perfprobes/SYMBOL_OFFSET[_NUM]
Where SYMBOL is the probing symbol and OFFSET is the byte offset from the symbol.
LKML-Reference: <20091027204310.30545.84984.stgit@harusame>
--- tools/perf/builtin-probe.c | 181 ++++++++++++++++++++++++--------------- tools/perf/util/probe-finder.c | 10 ++ tools/perf/util/probe-finder.h | 2 + 3 files changed, 123 insertions(+), 70 deletions(-)
tools/perf/builtin-probe.c +111 -70
@@ -52,6 +52,7 @@ const char *default_search_path[NR_SEARCH_PATH] = {#define MAX_PATH_LEN 256#define MAX_PROBES 128#define MAX_PROBE_ARGS 128 +#define PERFPROBE_GROUP "perfprobe"/* Session management structure */ static struct {
@@ -60,20 +61,100 @@ static struct {int need_dwarf;int nr_probe;struct probe_point probes[MAX_PROBES ]; -char *events[MAX_PROBES ]; } session; #define semantic_error(msg ...) die("Semantic error :" msg) -/* Parse a probe point. Note that any error must die. */ -static void parse_probepoint (const char *str) +/* Parse probe point. Return 1 if return probe */ +static void parse_probe_point (char *arg,struct probe_point *pp) +{ +char *ptr, *tmp; +char c, nc; +/* +* <Syntax> +* perf probe SRC:LN +* perf probe FUNC[+OFFS|%return][@SRC] +*/ + + ptr =strpbrk (arg,":+@%" ); +if (ptr) { + nc = *ptr; + *ptr++ ='\0' ; + } + +/* Check arg is function or file and copy it */ +if (strchr (arg,'.' ))/* File */ + pp->file =strdup (arg); +else /* Function */ + pp->function =strdup (arg); +DIE_IF (pp->file ==NULL && pp->function ==NULL ); + +/* Parse other options */ +while (ptr) { + arg = ptr; + c = nc; + ptr =strpbrk (arg,":+@%" ); +if (ptr) { + nc = *ptr; + *ptr++ ='\0' ; + } +switch (c) { +case ':' :/* Line number */ + pp->line =strtoul (arg, &tmp,0 ); +if (*tmp !='\0' ) +semantic_error ("There is non-digit charactor" +" in line number." ); +break ; +case '+' :/* Byte offset from a symbol */ + pp->offset =strtoul (arg, &tmp,0 ); +if (*tmp !='\0' ) +semantic_error ("There is non-digit charactor" +" in offset." ); +break ; +case '@' :/* File name */ +if (pp->file) +semantic_error ("SRC@SRC is not allowed." ); + pp->file =strdup (arg); +DIE_IF (pp->file ==NULL ); +if (ptr) +semantic_error ("@SRC must be the last " +"option." ); +break ; +case '%' :/* Probe places */ +if (strcmp (arg,"return" ) ==0 ) { + pp->retprobe =1 ; + }else /* Others not supported yet */ +semantic_error ("%%%s is not supported." , arg); +break ; +default : +DIE_IF ("Program has a bug." ); +break ; + } + } + +/* Exclusion check */ +if (pp->line && pp->function) +semantic_error ("Function-relative line number is not" +" supported yet." ); +if (!pp->line && pp->file && !pp->function) +semantic_error ("File always requires line number." ); +if (pp->offset && !pp->function) +semantic_error ("Offset requires an entry function." ); +if (pp->retprobe && !pp->function) +semantic_error ("Return probe requires an entry function." ); +if (pp->offset && pp->retprobe) +semantic_error ("Offset can't be used with return probe." ); + +pr_debug ("symbol:%s file:%s line:%d offset:%d, return:%d\n" , + pp->function, pp->file, pp->line, pp->offset, pp->retprobe); +} + +/* Parse an event definition. Note that any error must die. */ +static void parse_probe_event (const char *str) {char *argv[MAX_PROBE_ARGS +2 ];/* Event + probe + args */ int argc, i; -char *arg, *ptr;struct probe_point *pp = &session.probes[session.nr_probe]; -char **event = &session.events[session.nr_probe]; -int retp =0 ;pr_debug ("probe-definition(%d): %s\n" , session.nr_probe, str);if (++session.nr_probe ==MAX_PROBES )
@@ -103,70 +184,28 @@ static void parse_probepoint(const char *str)pr_debug ("argv[%d]=%s\n" , argc, argv[argc -1 ]); } }while (*str !='\0' ); -if (argc <2 ) -semantic_error ("Need event-name and probe-point at least." ); - -/* Parse the event name */ -if (argv[0 ][0 ] =='r' ) - retp =1 ; -else if (argv[0 ][0 ] !='p' ) -semantic_error ("You must specify 'p'(kprobe) or" -" 'r'(kretprobe) first." ); -/* TODO: check event name */ - *event = argv[0 ]; +if (!argc) +semantic_error ("An empty argument." );/* Parse probe point */ - arg = argv[1 ]; -if (arg[0 ] =='@' ) { -/* Source Line */ - arg++; - ptr =strchr (arg,':' ); -if (!ptr || !isdigit (ptr[1 ])) -semantic_error ("Line number is required." ); - *ptr++ ='\0' ; -if (strlen (arg) ==0 ) -semantic_error ("No file name." ); - pp->file =strdup (arg); - pp->line =atoi (ptr); -if (!pp->file || !pp->line) -semantic_error ("Failed to parse line." ); -pr_debug ("file:%s line:%d\n" , pp->file, pp->line); - }else { -/* Function name */ - ptr =strchr (arg,'+' ); -if (ptr) { -if (!isdigit (ptr[1 ])) -semantic_error ("Offset is required." ); - *ptr++ ='\0' ; - pp->offset =atoi (ptr); - }else - ptr = arg; - ptr =strchr (ptr,'@' ); -if (ptr) { - *ptr++ ='\0' ; - pp->file =strdup (ptr); - } - pp->function =strdup (arg); -pr_debug ("symbol:%s file:%s offset:%d\n" , - pp->function, pp->file, pp->offset); - } -free (argv[1 ]); +parse_probe_point (argv[0 ], pp); +free (argv[0 ]);if (pp->file) session.need_dwarf =1 ;/* Copy arguments */ - pp->nr_args = argc -2 ; + pp->nr_args = argc -1 ;if (pp->nr_args >0 ) { pp->args = (char **)malloc (sizeof (char *) * pp->nr_args);if (!pp->args)die ("malloc" ); -memcpy (pp->args, &argv[2 ],sizeof (char *) * pp->nr_args); +memcpy (pp->args, &argv[1 ],sizeof (char *) * pp->nr_args); }/* Ensure return probe has no C argument */ for (i =0 ; i < pp->nr_args; i++)if (is_c_varname (pp->args[i])) { -if (retp) +if (pp->retprobe)semantic_error ("You can't specify local" " variable for kretprobe" ); session.need_dwarf =1 ;
@@ -175,11 +214,11 @@ static void parse_probepoint(const char *str)pr_debug ("%d arguments\n" , pp->nr_args); } -static int opt_add_probepoint (const struct option *opt__used , +static int opt_add_probe_event (const struct option *opt__used ,const char *str,int unset__used ) {if (str) -parse_probepoint (str); +parse_probe_event (str);return 0 ; }
@@ -229,17 +268,16 @@ static const struct option options[] = {#endif OPT_CALLBACK('a', "add", NULL, #ifdef NO_LIBDWARF - "p|r:[GRP/]NAME FUNC[+OFFS] [ARG ...]", + "FUNC[+OFFS|%return] [ARG ...]", #else - "p|r:[GRP/]NAME FUNC[+OFFS][@SRC]|@SRC:LINE [ARG ...]", + "FUNC[+OFFS|%return][@SRC]|SRC:LINE [ARG ...]", #endif "probe point definition, where\n" - "\t\tp:\tkprobe probe\n" - "\t\tr:\tkretprobe probe\n" "\t\tGRP:\tGroup name (optional)\n" "\t\tNAME:\tEvent name\n" "\t\tFUNC:\tFunction name\n" "\t\tOFFS:\tOffset from function entry (in byte)\n" + "\t\t%return:\tPut the probe at function return\n" #ifdef NO_LIBDWARF "\t\tARG:\tProbe argument (only \n" #else
@@ -248,7 +286,7 @@ static const struct option options[] = { "\t\tARG:\tProbe argument (local variable name or\n" #endif "\t\t\tkprobe-tracer argument format is supported.)\n", - opt_add_probepoint), + opt_add_probe_event),OPT_END () };
@@ -266,7 +304,7 @@ static int write_new_event(int fd, const char *buf)#define MAX_CMDLEN 256 -static int synthesize_probepoint (struct probe_point *pp) +static int synthesize_probe_event (struct probe_point *pp) {char *buf;int i, len, ret;
@@ -316,12 +354,12 @@ int cmd_probe(int argc, const char **argv, const char *prefix __used)/* Synthesize probes without dwarf */ for (j =0 ; j < session.nr_probe; j++) {#ifndef NO_LIBDWARF -if (session.events[j][0 ] !='r' ) { +if (!session.probes[j].retprobe) { session.need_dwarf =1 ;continue ; }#endif - ret =synthesize_probepoint (&session.probes[j]); + ret =synthesize_probe_event (&session.probes[j]);if (ret == -E2BIG )semantic_error ("probe point is too long." );else if (ret <0 )
@@ -349,7 +387,6 @@ int cmd_probe(int argc, const char **argv, const char *prefix __used) ret =find_probepoint (fd, pp);if (ret <=0 )die ("No probe point found.\n" ); -pr_debug ("probe event %s found\n" , session.events[j]); }close (fd);
@@ -364,13 +401,17 @@ setup_probes:for (j =0 ; j < session.nr_probe; j++) { pp = &session.probes[j];if (pp->found ==1 ) { -snprintf (buf,MAX_CMDLEN ,"%s %s\n" , - session.events[j], pp->probes[0 ]); +snprintf (buf,MAX_CMDLEN ,"%c:%s/%s_%x %s\n" , + pp->retprobe ?'r' :'p' ,PERFPROBE_GROUP , + pp->function, pp->offset, pp->probes[0 ]);write_new_event (fd, buf); }else for (i =0 ; i < pp->found; i++) { -snprintf (buf,MAX_CMDLEN ,"%s%d %s\n" , - session.events[j], i, pp->probes[i]); +snprintf (buf,MAX_CMDLEN ,"%c:%s/%s_%x_%d %s\n" , + pp->retprobe ?'r' :'p' , +PERFPROBE_GROUP , + pp->function, pp->offset, i, + pp->probes[0 ]);write_new_event (fd, buf); } }
tools/perf/util/probe-finder.c +10 -0
@@ -483,10 +483,20 @@ static void show_probepoint(Dwarf_Die sp_die, Dwarf_Signed offs,if (ret ==DW_DLV_OK ) { ret =snprintf (tmp,MAX_PROBE_BUFFER ,"%s+%u" , name, (unsigned int )offs); +/* Copy the function name if possible */ +if (!pp->function) { + pp->function =strdup (name); + pp->offset = offs; + }dwarf_dealloc (__dw_debug, name,DW_DLA_STRING ); }else {/* This function has no name. */ ret =snprintf (tmp,MAX_PROBE_BUFFER ,"0x%llx" , pf->addr); +if (!pp->function) { +/* TODO: Use _stext */ + pp->function =strdup ("" ); + pp->offset = (int )pf->addr; + } }DIE_IF (ret <0 );DIE_IF (ret >=MAX_PROBE_BUFFER );
tools/perf/util/probe-finder.h +2 -0
@@ -22,6 +22,8 @@ struct probe_point {int nr_args;/* Number of arguments */ char **args;/* Arguments */ +int retprobe;/* Return probe */ +/* Output */ int found;/* Number of found probe points */ char *probes[MAX_PROBES ];/* Output buffers (will be allocated)*/
PATCH 10/10 perf/probes: Support function entry relative line number
In reply to Masami HiramatsuAdd function-entry relative line number specifying support to perf-probe. This allows users to define probes by line number from entry of the function.
e.g.
perf probe schedule:16
---
tools/perf/builtin-probe.c | 14 ++++--- tools/perf/util/probe-finder.c | 79 +++++++++++++++++++++++++++++++--------- tools/perf/util/probe-finder.h | 2 + 3 files changed, 70 insertions(+), 25 deletions(-)
tools/perf/builtin-probe.c +7 -7
@@ -133,17 +133,16 @@ static void parse_probe_point(char *arg, struct probe_point *pp) }/* Exclusion check */ -if (pp->line && pp->function) -semantic_error ("Function-relative line number is not" -" supported yet." ); +if (pp->line && pp->offset) +semantic_error ("Offset can't be used with line number." );if (!pp->line && pp->file && !pp->function)semantic_error ("File always requires line number." );if (pp->offset && !pp->function)semantic_error ("Offset requires an entry function." );if (pp->retprobe && !pp->function)semantic_error ("Return probe requires an entry function." ); -if (pp->offset && pp->retprobe) -semantic_error ("Offset can't be used with return probe." ); +if ((pp->offset || pp->line) && pp->retprobe) +semantic_error ("Offset/Line can't be used with return probe." );pr_debug ("symbol:%s file:%s line:%d offset:%d, return:%d\n" , pp->function, pp->file, pp->line, pp->offset, pp->retprobe);
@@ -270,7 +269,7 @@ static const struct option options[] = {#ifdef NO_LIBDWARF "FUNC[+OFFS|%return] [ARG ...]" , #else -"FUNC[+OFFS|%return][@SRC]|SRC:LINE [ARG ...]" , +"FUNC[+OFFS|%return|:RLN][@SRC]|SRC:ALN [ARG ...]" , #endif"probe point definition, where\n" "\t\tGRP:\tGroup name (optional)\n"
@@ -282,7 +281,8 @@ static const struct option options[] = {"\t\tARG:\tProbe argument (only \n" #else"\t\tSRC:\tSource code path\n" -"\t\tLINE:\tLine number\n" +"\t\tRLN:\tRelative line number from function entry.\n" +"\t\tALN:\tAbsolute line number in file.\n" "\t\tARG:\tProbe argument (local variable name or\n"#endif "\t\t\tkprobe-tracer argument format is supported.)\n",
tools/perf/util/probe-finder.c +61 -18
159 lines not on this page · raw message
tools/perf/util/probe-finder.h +2 -0
@@ -41,7 +41,9 @@ struct probe_finder {/* For function searching */ Dwarf_Addr addr;/* Address */ Dwarf_Unsigned fno;/* File number */ +Dwarf_Unsigned lno;/* Line number */ Dwarf_Off inl_offs;/* Inline offset */ +Dwarf_Die cu_die;/* Current CU */ /* For variable searching */ Dwarf_Addr cu_base;/* Current CU base address */
Signature · 7 lines
Masami Hiramatsu Software Engineer Hitachi Computer Products (America), Inc. Software Solutions Division e-mail: [email protected]
[tip:perf/probes] perf/probes: Support function entry relative line number
Commit-ID: b0ef07324310d66f660a311d4a8d669eda74f801 Gitweb: http://git.kernel.org/tip/b0ef07324310d66f660a311d4a8d669eda74f801 Author: Masami Hiramatsu <[email protected]> AuthorDate: Tue, 27 Oct 2009 16:43:19 -0400 Committer: Ingo Molnar <[email protected]> CommitDate: Thu, 29 Oct 2009 08:47:49 +0100
perf/probes: Support function entry relative line number
Add function-entry relative line number specifying support to perf-probe. This allows users to define probes by line number from entry of the function.
e.g.
perf probe schedule:16
LKML-Reference: <20091027204319.30545.30678.stgit@harusame>
--- tools/perf/builtin-probe.c | 14 ++++---- tools/perf/util/probe-finder.c | 79 +++++++++++++++++++++++++++++++--------- tools/perf/util/probe-finder.h | 2 + 3 files changed, 70 insertions(+), 25 deletions(-)
tools/perf/builtin-probe.c +7 -7
@@ -133,17 +133,16 @@ static void parse_probe_point(char *arg, struct probe_point *pp) }/* Exclusion check */ -if (pp->line && pp->function) -semantic_error ("Function-relative line number is not" -" supported yet." ); +if (pp->line && pp->offset) +semantic_error ("Offset can't be used with line number." );if (!pp->line && pp->file && !pp->function)semantic_error ("File always requires line number." );if (pp->offset && !pp->function)semantic_error ("Offset requires an entry function." );if (pp->retprobe && !pp->function)semantic_error ("Return probe requires an entry function." ); -if (pp->offset && pp->retprobe) -semantic_error ("Offset can't be used with return probe." ); +if ((pp->offset || pp->line) && pp->retprobe) +semantic_error ("Offset/Line can't be used with return probe." );pr_debug ("symbol:%s file:%s line:%d offset:%d, return:%d\n" , pp->function, pp->file, pp->line, pp->offset, pp->retprobe);
@@ -270,7 +269,7 @@ static const struct option options[] = {#ifdef NO_LIBDWARF "FUNC[+OFFS|%return] [ARG ...]" , #else -"FUNC[+OFFS|%return][@SRC]|SRC:LINE [ARG ...]" , +"FUNC[+OFFS|%return|:RLN][@SRC]|SRC:ALN [ARG ...]" , #endif"probe point definition, where\n" "\t\tGRP:\tGroup name (optional)\n"
@@ -282,7 +281,8 @@ static const struct option options[] = {"\t\tARG:\tProbe argument (only \n" #else"\t\tSRC:\tSource code path\n" -"\t\tLINE:\tLine number\n" +"\t\tRLN:\tRelative line number from function entry.\n" +"\t\tALN:\tAbsolute line number in file.\n" "\t\tARG:\tProbe argument (local variable name or\n"#endif "\t\t\tkprobe-tracer argument format is supported.)\n",
tools/perf/util/probe-finder.c +61 -18
159 lines not on this page · raw message
tools/perf/util/probe-finder.h +2 -0
@@ -41,7 +41,9 @@ struct probe_finder {/* For function searching */ Dwarf_Addr addr;/* Address */ Dwarf_Unsigned fno;/* File number */ +Dwarf_Unsigned lno;/* Line number */ Dwarf_Off inl_offs;/* Inline offset */ +Dwarf_Die cu_die;/* Current CU */ /* For variable searching */ Dwarf_Addr cu_base;/* Current CU base address */
Quoted 31 lines · Masami Hiramatsu
Hi Ingo,
Here are bugfixes and some enhances of x86-insn decoder and perf-probe.
- x86 insn decoder supports AVX and FMA.
- perf-probe syntax change.
- perf-probe supports function-relative line number.
- minor bugfixes.New perf-probe syntax is below:
perf probe 'PROBE'
or
perf probe --add 'PROBE'where, PROBE is
<source>:<line-number>
or
<function>[:<rel-lineno>|+<byte-offset>|%return][@<source>]
e.g.
perf probe 'schedule:10@kernel/sched.c'
puts a probe at 10th line from entry line of
schedule()function inkernel/sched.c." and
Quoted 7 lines
perf probe 'vmalloc%return'
puts a return probe at the returning of vmalloc.
TODO:
- Support --line option to show which lines user can probe.
- Support lazy string matching.
Ok, i like these fixes and improvements - thanks Masami!
One detail i noticed is that we are still not very smart about finding our vmlinux file. I booted the kernel on a box and it gave:
aldebaran:~/linux/linux> perf probe schedule
Fatal: vmlinux/module file open
aldebaran:~/linux/linux> ls -l vmlinux
-rwxrwxr-x 1 mingo mingo 21589717 2009-10-29 09:04 vmlinux
Firstly, it should print something more meaningful, such as:
aldebaran:~/linux/linux> perf probe schedule
Fatal: Could not open vmlinux/module file
Secondly, we should look beyond these places:
25806 open("/lib/modules/2.6.32-rc5-tip-01760-g2c4b5e0-dirty/build/vmlinux", O_RDONLY) = -1 ENOENT (No such file or directory) 25806 open("/usr/lib/debug/lib/modules/2.6.32-rc5-tip-01760-g2c4b5e0-dirty/vmlinux", O_RDONLY) = -1 ENOENT (No such file or directory) 25806 open("/boot/vmlinux-debug-2.6.32-rc5-tip-01760-g2c4b5e0-dirty", O_RDONLY) = -1 ENOENT (No such file or directory) 25806 write(2, " Fatal: vmlinux/module file open"..., 34) = 34
25806 exit_group(128) = ?
and look into the current directory as well.
Thirdly, i think we should expose the build-id of the kernel and the path to the vmlinux (and modules) via /proc/build-id or so. That way tooling can find the vmlinux file and can validate that it matches the kernel's signature. (maybe include a file date as well - that's a faster check than a full build-id checksum, especially for large kernels)
Another problem i noticed is that a vmlinux without DEBUG_INFO will fail in this way:
aldebaran:~/linux/linux> perf probe schedule
Fatal: Failed to call dwarf_init(). Maybe, not a dwarf file.
this is not meaningful to a user. A more usable message would be:
aldebaran:~/linux/linux> perf probe schedule
Fatal: Have not found dwarf info in the vmlinux - please rebuild with CONFIG_DEBUG_INFO
but ... we should really not force DEBUG_INFO for a simple probe that is based on an ELF symbol. We already parse ELF symbols so 'perf probe schedule' should be able to figure out where to put the probe point.
Not forcing debuginfo for simple usecases is extremely important for usability.
And once i had these fixed, i got:
aldebaran:~/linux/linux> perf probe schedule
Fatal: kprobe_events open
Which is not a meaningful error message either. This error occured due to CONFIG_KPROBE_TRACER not being enabled.
What we want here is two fold:
- enable kprobes event support when perf events is enabled and kprobes is enabled. We dont want another config option for it.
- and we need to improve error messages so that users can figure out what is the problem.
Once i had this third roadblock out of the way i noticed that the _real_ reason for the error was that i was not root and had no privilege to insert a kprobe.
Once root, the probe worked well:
# perf probe schedule Adding new event: p:perfprobe/schedule_0 schedule+0
And it seems to be precise:
aldebaran:/home/mingo> perf stat -e perfprobe:__switch_to_0 -e cs -a ./hackbench 1
Time: 0.018
Performance counter stats for './hackbench 1':
7358 perfprobe:__switch_to_0 # 0.000 M/sec
7364 context-switches # 0.000 M/sec0.119152919 seconds time elapsed
(The difference of 6 context-switches should be investigated i suspect.)
Btw., very small nit, it would be better to put that sentence into past tense:
# perf probe schedule Added new event: p:perfprobe/schedule_0 schedule+0
To make sure the user knows that the action has been pursued already.
I'd expect the typical user give up much sooner than i did so we really need to address these usability details - emit useful error messages and be more successful in getting the user what he wants.
But the basic UI is already pretty promising!
A few further (and very small) UI tweaks i'd suggest:
Firstly, could we please make the first probe inserted named plain after the symbol it specifies, with no _0 postfix? I.e. instead of:
7358 perfprobe:__switch_to_0 # 0.000 M/sec
we'd get:
7358 perfprobe:__switch_to # 0.000 M/sec
Subsequent probes for the same symbol can be named _1, _2 - but the first symbol should not have this needless post-fix.
Secondly, i think we should remove the 'perf' bit from the probe name. I.e. instead of:
7358 perfprobe:__switch_to # 0.000 M/sec
we should do:
7358 probe:__switch_to # 0.000 M/sec
as that's really what the user cares about. The user already knows that we are in perf - no need to repeat that in every event specification.
Thanks,
Ingo
Em Thu, Oct 29, 2009 at 09:53:48AM +0100, Ingo Molnar escreveu:
Quoted 5 lines
Thirdly, i think we should expose the build-id of the kernel and the path to the vmlinux (and modules) via
/proc/build-idor so. That way tooling can find the vmlinux file and can validate that it matches the kernel's signature. (maybe include a file date as well - that's a faster check than a full build-id checksum, especially for large kernels)
Yeah, build-id need to be a first class citizen, being always available for checking that the DSO in disk matches the one being currently used by some app.
Right now I got myself staring at these messages in a perf top session:
No symbols found in /usr/lib/libvte.so.9.6.0 (deleted), maybe install a debug package?
No symbols found in /lib/libgobject-2.0.so.0.2000.5.#prelink#.MDypV3 (deleted), maybe install a debug package? No symbols found in /usr/lib/libpixman-1.so.0.14.0 (deleted), maybe install a debug package?
No symbols found in /usr/lib/libgdk-x11-2.0.so.0.1600.6.#prelink#.4CriMV (deleted), maybe install a debug package? No symbols found in /lib/libgthread-2.0.so.0.2000.5.#prelink#.0ooYbx (deleted), maybe install a debug package? No symbols found in /usr/lib/libX11.so.6.2.0 (deleted), maybe install a debug package?
No symbols found in /usr/lib/libxcb.so.1.1.0 (deleted), maybe install a debug package?
Well, I did a 'yum upgrade' and there are some binaries still running that hold reference counts to those DSOs, but there is not anymore any place I can look for its buildid to get the right symtab.
Corner case, yeah, but it would be nice to be able to query for its buildid and then get the right symtab.
But as we don't have that, I'll just look for (deleted) at the end of the DSO name and emit a more friendly warning...
- Arnaldo
Quoted 36 lines · Ingo Molnar
Quoted 33 lines · Masami Hiramatsu
Hi Ingo,
Here are bugfixes and some enhances of x86-insn decoder and perf-probe.
- x86 insn decoder supports AVX and FMA.
- perf-probe syntax change.
- perf-probe supports function-relative line number.
- minor bugfixes.New perf-probe syntax is below:
perf probe 'PROBE'
or
perf probe --add 'PROBE'where, PROBE is
<source>:<line-number>or
<function>[:<rel-lineno>|+<byte-offset>|%return][@<source>]e.g.
perf probe 'schedule:10@kernel/sched.c'
puts a probe at 10th line from entry line of
schedule()function inkernel/sched.c." andperf probe 'vmalloc%return'
Quoted 7 lines
Quoted 5 lines
puts a return probe at the returning of vmalloc.
TODO:
- Support --line option to show which lines user can probe.
- Support lazy string matching.Ok, i like these fixes and improvements - thanks Masami!
Thanks!
Quoted 8 lines
One detail i noticed is that we are still not very smart about finding our vmlinux file. I booted the kernel on a box and it gave:
aldebaran:~/linux/linux> perf probe schedule
Fatal: vmlinux/module file open
aldebaran:~/linux/linux> ls -l vmlinux -rwxrwxr-x 1 mingo mingo 21589717 2009-10-29 09:04 vmlinux
Quoted 4 lines
Firstly, it should print something more meaningful, such as:
aldebaran:~/linux/linux> perf probe schedule
Fatal: Could not open vmlinux/module file
Oops, yes, it should be. since previously I used perror() for error message, all die() messages in perf probe should be changed to show actual error message.
Quoted 9 lines
Secondly, we should look beyond these places:
25806
open("/lib/modules/2.6.32-rc5-tip-01760-g2c4b5e0-dirty/build/vmlinux", O_RDONLY)= -1 ENOENT (No such file or directory) 25806open("/usr/lib/debug/lib/modules/2.6.32-rc5-tip-01760-g2c4b5e0-dirty/vmlinux", O_RDONLY)= -1 ENOENT (No such file or directory) 25806open("/boot/vmlinux-debug-2.6.32-rc5-tip-01760-g2c4b5e0-dirty", O_RDONLY)= -1 ENOENT (No such file or directory) 25806write(2, " Fatal: vmlinux/module file open"..., 34)= 34
25806exit_group(128)= ?and look into the current directory as well.
I think that perf-probe has -k option for that purpose, doesn't it? :-) Did you move your vmlinux from build dir to current dir?
I assume people usually just installs kernel and runs perf tools, and they might not tend to copy vmlinux to current dir, just IMHO. But anyway, if other perf commands already search vmlinux in current dir, I'm OK for adding it on the list.
Quoted 5 lines
Thirdly, i think we should expose the build-id of the kernel and the path to the vmlinux (and modules) via
/proc/build-idor so. That way tooling can find the vmlinux file and can validate that it matches the kernel's signature. (maybe include a file date as well - that's a faster check than a full build-id checksum, especially for large kernels)
That's a good idea!
I think we can expose build-id via /sys/modules/*/build-id.
Quoted 5 lines
Another problem i noticed is that a vmlinux without
DEBUG_INFOwill fail in this way:aldebaran:~/linux/linux> perf probe schedule
Fatal: Failed to calldwarf_init(). Maybe, not a dwarf file.
Ah, really? I think I broke need_dwarf logic somehow...
Quoted 4 lines
this is not meaningful to a user. A more usable message would be:
aldebaran:~/linux/linux> perf probe schedule
Fatal: Have not found dwarf info in the vmlinux - please rebuild withCONFIG_DEBUG_INFO
Sure.
Quoted 4 lines
but ... we should really not force
DEBUG_INFOfor a simple probe that is based on an ELF symbol. We already parse ELF symbols so 'perf probe schedule' should be able to figure out where to put the probe point.
Agreed, I'll figure out how perf-probe can use ELF symbols too.
Quoted 2 lines
Not forcing debuginfo for simple usecases is extremely important for usability.
Yeah, it should not.
Quoted 6 lines
And once i had these fixed, i got:
aldebaran:~/linux/linux> perf probe schedule
Fatal:kprobe_eventsopen
Quoted 7 lines
Which is not a meaningful error message either. This error occured due to
CONFIG_KPROBE_TRACERnot being enabled.What we want here is two fold:
- enable kprobes event support when perf events is enabled and kprobes is enabled. We dont want another config option for it.
Sure, at least that combination should enable kprobe-tracer forcibly.
Quoted 2 lines
- and we need to improve error messages so that users can figure out what is the problem.
Sure.
Quoted 14 lines
Once i had this third roadblock out of the way i noticed that the _real_ reason for the error was that i was not root and had no privilege to insert a kprobe.
Once root, the probe worked well:
# perf probe schedule Adding new event: p:perfprobe/schedule_0 schedule+0And it seems to be precise:
aldebaran:/home/mingo> perf stat -e perfprobe:__switch_to_0 -e cs -a ./hackbench 1
Time: 0.018
Quoted 8 lines
Performance counter stats for './hackbench 1':
7358 perfprobe:__switch_to_0 # 0.000 M/sec 7364 context-switches # 0.000 M/sec0.119152919 seconds time elapsed(The difference of 6 context-switches should be investigated i suspect.)
Maybe, because of enabling/disabling timings difference.
Quoted 7 lines
Btw., very small nit, it would be better to put that sentence into past tense:
# perf probe schedule Added new event: p:perfprobe/schedule_0 schedule+0To make sure the user knows that the action has been pursued already.
OK.
Quoted 11 lines
I'd expect the typical user give up much sooner than i did so we really need to address these usability details - emit useful error messages and be more successful in getting the user what he wants.
But the basic UI is already pretty promising!
A few further (and very small) UI tweaks i'd suggest:
Firstly, could we please make the first probe inserted named plain after the symbol it specifies, with no _0 postfix? I.e. instead of:
Quoted 8 lines
7358 perfprobe:__switch_to_0 # 0.000 M/secwe'd get:
7358 perfprobe:__switch_to # 0.000 M/secSubsequent probes for the same symbol can be named _1, _2 - but the first symbol should not have this needless post-fix.
Ah, this prefix means the offset from the symbol. Of course we can remove it if the offset == 0. Or, would you think make the postfix sequence number of probes on the same symbol?
Quoted 11 lines
Secondly, i think we should remove the 'perf' bit from the probe name. I.e. instead of:
7358 perfprobe:__switch_to # 0.000 M/secwe should do:
7358 probe:__switch_to # 0.000 M/secas that's really what the user cares about. The user already knows that we are in perf - no need to repeat that in every event specification.
Yeah, that's fine to me.
Thank you,
Signature · 7 lines
Masami Hiramatsu Software Engineer Hitachi Computer Products (America), Inc. Software Solutions Division e-mail: [email protected]
Quoted 8 lines · Masami Hiramatsu
Quoted 5 lines · Ingo Molnar
Another problem i noticed is that a vmlinux without
DEBUG_INFOwill fail in this way:aldebaran:~/linux/linux> perf probe schedule
Fatal: Failed to calldwarf_init(). Maybe, not a dwarf file.Ah, really? I think I broke
need_dwarflogic somehow...
Hmm, I've found that is for searching (implicitly) inlined symbols, this means "the behavior is by (bad) design" :-(
I think it should be search the symbol in Elf (or kallsyms) first, and only if it fails, use Dwarf for searching the symbol again.
Or, it may be enough that just trying to setup probe and if it fails use Dwarf. This way doesn't require any vmlinux access.
Thank you,
Signature · 7 lines
Masami Hiramatsu Software Engineer Hitachi Computer Products (America), Inc. Software Solutions Division e-mail: [email protected]
Quoted 10 lines · Masami Hiramatsu
Quoted 8 lines · Masami Hiramatsu
Quoted 5 lines · Ingo Molnar
Another problem i noticed is that a vmlinux without
DEBUG_INFOwill fail in this way:aldebaran:~/linux/linux> perf probe schedule
Fatal: Failed to calldwarf_init(). Maybe, not a dwarf file.Ah, really? I think I broke
need_dwarflogic somehow...
Quoted 8 lines
Hmm, I've found that is for searching (implicitly) inlined symbols, this means "the behavior is by (bad) design" :-(
I think it should be search the symbol in Elf (or kallsyms) first, and only if it fails, use Dwarf for searching the symbol again.
Or, it may be enough that just trying to setup probe and if it fails use Dwarf. This way doesn't require any vmlinux access.
Just beware that functions can exist in the symbol table and as inlines at the same time. For example, we've seen compat_sys_recvmsg get inlined into compat_sys_socketcall, while it's still compiled as a standalone function too. So if you have the dwarf, you should still try to see if inlined versions exist.
Josh
Quoted 17 lines · Josh Stone
Quoted 16 lines · Masami Hiramatsu
Quoted 8 lines · Masami Hiramatsu
Quoted 5 lines · Ingo Molnar
Another problem i noticed is that a vmlinux without
DEBUG_INFOwill fail in this way:aldebaran:~/linux/linux> perf probe schedule
Fatal: Failed to calldwarf_init(). Maybe, not a dwarf file.Ah, really? I think I broke
need_dwarflogic somehow...Hmm, I've found that is for searching (implicitly) inlined symbols, this means "the behavior is by (bad) design" :-(
I think it should be search the symbol in Elf (or kallsyms) first, and only if it fails, use Dwarf for searching the symbol again.
Quoted 8 lines
Quoted 2 lines
Or, it may be enough that just trying to setup probe and if it fails use Dwarf. This way doesn't require any vmlinux access.
Just beware that functions can exist in the symbol table and as inlines at the same time. For example, we've seen
compat_sys_recvmsgget inlined intocompat_sys_socketcall, while it's still compiled as a standalone function too. So if you have the dwarf, you should still try to see if inlined versions exist.
Right, by default, perf-probe should see Dwarf since some static functions may implicitly compiled as inline, and it is hard to request user checking whether the symbol is inlined or not.
So, this means current design is not so bad, but practically, we'd better provide an option which ignores inline functions. e.g. exported functions will be always not-inlined.
Thank you,
Signature · 7 lines
Masami Hiramatsu Software Engineer Hitachi Computer Products (America), Inc. Software Solutions Division e-mail: [email protected]
Re: [PATCH -tip perf/probes 00/10] x86 insn decoder bugfixes and perf-probe syntax changes
In reply to Masami HiramatsuQuoted 7 lines · Masami Hiramatsu
Quoted 4 lines · Ingo Molnar
What we want here is two fold:
- enable kprobes event support when perf events is enabled and kprobes is enabled. We dont want another config option for it.
Sure, at least that combination should enable kprobe-tracer forcibly.
Hmm, someone may not want to enables kprobe-tracer. Perhaps, "default y if (EVENT_PROFILE)" is enough, isn't it?
Quoted 9 lines
Quoted 9 lines
A few further (and very small) UI tweaks i'd suggest:
Firstly, could we please make the first probe inserted named plain after the symbol it specifies, with no _0 postfix? I.e. instead of:
7358 perfprobe:__switch_to_0 # 0.000 M/secwe'd get:
Quoted 8 lines
Quoted 4 lines
7358 perfprobe:__switch_to # 0.000 M/secSubsequent probes for the same symbol can be named _1, _2 - but the first symbol should not have this needless post-fix.
Ah, this prefix means the offset from the symbol. Of course we can remove it if the offset == 0. Or, would you think make the postfix sequence number of probes on the same symbol?
If so, we'd better have --list option before that and check the postfix is already used, since we may not want to overwrite existing probes, right?
Thank you,
Signature · 7 lines
Masami Hiramatsu Software Engineer Hitachi Computer Products (America), Inc. Software Solutions Division e-mail: [email protected]
Re: [PATCH -tip perf/probes 00/10] x86 insn decoder bugfixes and perf-probe syntax changes
Quoted 4 lines · Masami Hiramatsu
Quoted 3 lines · Masami Hiramatsu
Quoted 2 lines · Ingo Molnar
What we want here is two fold:
Quoted 8 lines
Quoted 4 lines
Quoted 2 lines
- enable kprobes event support when perf events is enabled and kprobes is enabled. We dont want another config option for it.
Sure, at least that combination should enable kprobe-tracer forcibly.
Hmm, someone may not want to enables kprobe-tracer. Perhaps, "default y if (
EVENT_PROFILE)" is enough, isn't it?
I guess it should be sufficient yeah. We want to strongly recommend the kprobe events if we have enabled perf, but we don't want to force it.
Also in this case we need a verbose runtime report of the lack of this tracer in debugfs from perf probe if needed.
Re: [PATCH -tip perf/probes 00/10] x86 insn decoder bugfixes and perf-probe syntax changes
Quoted 15 lines · Frederic Weisbecker
Quoted 4 lines · Masami Hiramatsu
Quoted 3 lines · Masami Hiramatsu
Quoted 2 lines · Ingo Molnar
What we want here is two fold:
Quoted 8 lines
Quoted 4 lines
Quoted 2 lines
- enable kprobes event support when perf events is enabled and kprobes is enabled. We dont want another config option for it.
Sure, at least that combination should enable kprobe-tracer forcibly.
Hmm, someone may not want to enables kprobe-tracer. Perhaps, "default y if (
EVENT_PROFILE)" is enough, isn't it?
Quoted 6 lines
I guess it should be sufficient yeah. We want to strongly recommend the kprobe events if we have enabled perf, but we don't want to force it.
Also in this case we need a verbose runtime report of the lack of this tracer in debugfs from perf probe if needed.
Sure, error message should be changed as warning user to enable CONFIG_KPROBE_TRACER :-)
Thank you,
Signature · 7 lines
Masami Hiramatsu Software Engineer Hitachi Computer Products (America), Inc. Software Solutions Division e-mail: [email protected]
Re: [PATCH -tip perf/probes 00/10] x86 insn decoder bugfixes and perf-probe syntax changes
In reply to Masami HiramatsuQuoted 11 lines · Masami Hiramatsu
Quoted 7 lines · Masami Hiramatsu
Quoted 4 lines · Ingo Molnar
What we want here is two fold:
- enable kprobes event support when perf events is enabled and kprobes is enabled. We dont want another config option for it.
Sure, at least that combination should enable kprobe-tracer forcibly.
Hmm, someone may not want to enables kprobe-tracer. Perhaps, "default y if (
EVENT_PROFILE)" is enough, isn't it?
Oops, this causes recursive dependency error :-(
kernel/trace/Kconfig:90:error: found recursive dependency: TRACING -> EVENT_TRACING -> EVENT_PROFILE -> KPROBE_TRACER -> GENERIC_TRACER -> TRACING
At this time, this kind of weak dependency may not supported by Kbuild yet.
Thank you,
Signature · 7 lines
Masami Hiramatsu Software Engineer Hitachi Computer Products (America), Inc. Software Solutions Division e-mail: [email protected]
Re: [PATCH -tip perf/probes 00/10] x86 insn decoder bugfixes and perf-probe syntax changes
Quoted 10 lines · Masami Hiramatsu
Quoted 9 lines · Masami Hiramatsu
Quoted 7 lines · Masami Hiramatsu
Quoted 4 lines · Ingo Molnar
What we want here is two fold:
- enable kprobes event support when perf events is enabled and kprobes is enabled. We dont want another config option for it.
Sure, at least that combination should enable kprobe-tracer forcibly.
Quoted 7 lines
Quoted 2 lines
Hmm, someone may not want to enables kprobe-tracer. Perhaps, "default y if (
EVENT_PROFILE)" is enough, isn't it?Oops, this causes recursive dependency error :-(
kernel/trace/Kconfig:90:error: found recursive dependency: TRACING ->
EVENT_TRACING->EVENT_PROFILE->KPROBE_TRACER->GENERIC_TRACER-> TRACING
This dependency problem can be resolved by simply making it 'default y'
- the option itself depends on KPROBES already, which is default-off - so no need to also make it depend on EVENT_PROFILE.
btw., it would be nice to re-name it to 'KPROBE_EVENTS'. If the probe point is used as a count - like in the __switch_to example i cited - there's no tracing going on at all.
Ingo
Re: [PATCH -tip perf/probes 00/10] x86 insn decoder bugfixes and perf-probe syntax changes
Quoted 14 lines · Ingo Molnar
Quoted 13 lines · Masami Hiramatsu
Quoted 11 lines · Masami Hiramatsu
Quoted 7 lines · Masami Hiramatsu
Quoted 4 lines · Ingo Molnar
What we want here is two fold:
- enable kprobes event support when perf events is enabled and kprobes is enabled. We dont want another config option for it.
Sure, at least that combination should enable kprobe-tracer forcibly.
Hmm, someone may not want to enables kprobe-tracer. Perhaps, "default y if (
EVENT_PROFILE)" is enough, isn't it?
Quoted 8 lines
Quoted 4 lines
Oops, this causes recursive dependency error :-(
kernel/trace/Kconfig:90:error: found recursive dependency: TRACING ->
EVENT_TRACING->EVENT_PROFILE->KPROBE_TRACER->GENERIC_TRACER-> TRACINGThis dependency problem can be resolved by simply making it 'default y'
- the option itself depends on KPROBES already, which is default-off - so no need to also make it depend onEVENT_PROFILE.
OK,
Quoted 3 lines
btw., it would be nice to re-name it to '
KPROBE_EVENTS'. If the probe point is used as a count - like in the__switch_toexample i cited - there's no tracing going on at all.
Sure, it's not a tracer anyway :-)
Thank you,
Signature · 7 lines
Masami Hiramatsu Software Engineer Hitachi Computer Products (America), Inc. Software Solutions Division e-mail: [email protected]
Hi -
Quoted 3 lines · Ingo Molnar
[...]
Thirdly, i think we should expose the build-id of the kernel and the path to the vmlinux (and modules) via/proc/build-idor so. [...]
See "/sys/kernel/notes" and "/sys/module/*/notes".
- FChE
Quoted 5 lines
Thirdly, i think we should expose the build-id of the kernel and the path to the vmlinux (and modules) via
/proc/build-idor so. That way tooling can find the vmlinux file and can validate that it matches the kernel's signature. (maybe include a file date as well - that's a faster check than a full build-id checksum, especially for large kernels)
You seem to be confused about what build IDs are. There is no "checksum validation". Once the bits are stored there is no calculation ever done again, only exact comparison with an expected build ID bitstring. The size of an object file is immaterial.
As Frank mentioned, the kernel's and modules' allocated ELF notes (and thus build IDs) are already exposed in /sys. Tools like "eu-unstrip -nk" use this information today.
Thanks,
Roland
Quoted 7 lines · Roland McGrath
Quoted 6 lines
Thirdly, i think we should expose the build-id of the kernel and the path to the vmlinux (and modules) via
/proc/build-idor so. That way tooling can find the vmlinux file and can validate that it matches the kernel's signature. (maybe include a file date as well - that's a faster check than a full build-id checksum, especially for large kernels)
Quoted 8 lines
You seem to be confused about what build IDs are. There is no "checksum validation". Once the bits are stored there is no calculation ever done again, only exact comparison with an expected build ID bitstring. The size of an object file is immaterial.
As Frank mentioned, the kernel's and modules' allocated ELF notes (and thus build IDs) are already exposed in /sys. Tools like "eu-unstrip -nk" use this information today.
Ah, i didnt realize we link with --build-id already, unconditonally, since v2.6.23 (if ld supports it):
| | From 18991197b4b588255ccabf472ebc84db7b66a19c Mon Sep 17 00:00:00 2001 | From: Roland McGrath <[email protected]> | Date: Thu, 19 Jul 2007 01:48:40 -0700 | Subject: [PATCH] Use --build-id ld option | | This change passes the --build-id when linking the kernel and when | linking modules, if ld supports it. This is a new GNU ld option that | synthesizes an ELF note section inside the read-only data. The note in | this section contains unique identifying bits called the "build ID", | which are generated so as to be different for any two linked ELF files | that aren't identical. |
So we have an SHA1 build-id already on the vmlinux and on modules, and it's exposed in /sys/*/*/notes. Just have to make use of it in tools/perf too.
The other useful addition i mentioned isnt implemented yet: to emit an ELF note of the absolute path of the output directory the kernel was built in as well. This information is not available right now, and it would be a place to look in to search for the vmlinux and the modules.
What do you think? Also, if we do this, is there a standard way to name it , or should i just pick a suitably new, Linux-specific name for that?
Thanks,
Ingo
Using build-ids in perf tools was Re: [PATCH -tip perf/probes 00/10] x86 insn decoder bugfixes
Em Tue, Nov 03, 2009 at 08:24:39AM +0100, Ingo Molnar escreveu:
Quoted 8 lines · Roland McGrath
Quoted 3 lines
As Frank mentioned, the kernel's and modules' allocated ELF notes (and thus build IDs) are already exposed in /sys. Tools like "eu-unstrip -nk" use this information today.
Ah, i didnt realize we link with --build-id already, unconditonally, since v2.6.23 (if ld supports it):
Quoted 6 lines
| From
18991197b4b588255ccabf472ebc84db7b66a19cMon Sep 17 00:00:00 2001 | Subject: [PATCH] Use --build-id ld optionSo we have an SHA1 build-id already on the vmlinux and on modules, and it's exposed in
/sys/*/*/notes. Just have to make use of it intools/perftoo.
I wasn't aware this was done upstream, ass-umed that it was only on kernel specfiles, will cook up a patch for consideration.
- Arnaldo