[tip:x86/early-printk] x86/earlyprintk: Add a force option for pciserial device

2018-10-02 Thread tip-bot for Feng Tang
Commit-ID:  d2266bbfa9e3e32e3b642965088ca461bd24a94f
Gitweb: https://git.kernel.org/tip/d2266bbfa9e3e32e3b642965088ca461bd24a94f
Author: Feng Tang 
AuthorDate: Wed, 3 Oct 2018 00:49:21 +0800
Committer:  Borislav Petkov 
CommitDate: Tue, 2 Oct 2018 21:02:47 +0200

x86/earlyprintk: Add a force option for pciserial device

The "pciserial" earlyprintk variant helps much on many modern x86
platforms, but unfortunately there are still some platforms with PCI
UART devices which have the wrong PCI class code. In that case, the
current class code check does not allow for them to be used for logging.

Add a sub-option "force" which overrides the class code check and thus
the use of such device can be enforced.

 [ bp: massage formulations. ]

Suggested-by: Borislav Petkov 
Signed-off-by: Feng Tang 
Signed-off-by: Borislav Petkov 
Cc: "H. Peter Anvin" 
Cc: "Stuart R . Anderson" 
Cc: Bjorn Helgaas 
Cc: David Rientjes 
Cc: Feng Tang 
Cc: Frederic Weisbecker 
Cc: Greg Kroah-Hartman 
Cc: H Peter Anvin 
Cc: Ingo Molnar 
Cc: Jiri Kosina 
Cc: Jonathan Corbet 
Cc: Kai-Heng Feng 
Cc: Kate Stewart 
Cc: Konrad Rzeszutek Wilk 
Cc: Peter Zijlstra 
Cc: Philippe Ombredanne 
Cc: Thomas Gleixner 
Cc: Thymo van Beers 
Cc: a...@linux.intel.com
Cc: linux-...@vger.kernel.org
Link: http://lkml.kernel.org/r/20181002164921.25833-1-feng.t...@intel.com
---
 Documentation/admin-guide/kernel-parameters.txt |  6 -
 arch/x86/kernel/early_printk.c  | 29 -
 2 files changed, 24 insertions(+), 11 deletions(-)

diff --git a/Documentation/admin-guide/kernel-parameters.txt 
b/Documentation/admin-guide/kernel-parameters.txt
index 92eb1f42240d..34e6800dea0e 100644
--- a/Documentation/admin-guide/kernel-parameters.txt
+++ b/Documentation/admin-guide/kernel-parameters.txt
@@ -1063,7 +1063,7 @@
earlyprintk=serial[,0x...[,baudrate]]
earlyprintk=ttySn[,baudrate]
earlyprintk=dbgp[debugController#]
-   earlyprintk=pciserial,bus:device.function[,baudrate]
+   
earlyprintk=pciserial[,force],bus:device.function[,baudrate]
earlyprintk=xdbc[xhciController#]
 
earlyprintk is useful when the kernel crashes before
@@ -1095,6 +1095,10 @@
 
The sclp output can only be used on s390.
 
+   The optional "force" to "pciserial" enables use of a
+   PCI device even when its classcode is not of the
+   UART class.
+
edac_report=[HW,EDAC] Control how to report EDAC event
Format: {"on" | "off" | "force"}
on: enable EDAC to report H/W event. May be overridden
diff --git a/arch/x86/kernel/early_printk.c b/arch/x86/kernel/early_printk.c
index 5e801c8c8ce7..374a52fa5296 100644
--- a/arch/x86/kernel/early_printk.c
+++ b/arch/x86/kernel/early_printk.c
@@ -213,8 +213,9 @@ static unsigned int mem32_serial_in(unsigned long addr, int 
offset)
  * early_pci_serial_init()
  *
  * This function is invoked when the early_printk param starts with "pciserial"
- * The rest of the param should be ",B:D.F,baud" where B, D & F describe the
- * location of a PCI device that must be a UART device.
+ * The rest of the param should be "[force],B:D.F,baud", where B, D & F 
describe
+ * the location of a PCI device that must be a UART device. "force" is optional
+ * and overrides the use of an UART device with a wrong PCI class code.
  */
 static __init void early_pci_serial_init(char *s)
 {
@@ -224,17 +225,23 @@ static __init void early_pci_serial_init(char *s)
u32 classcode, bar0;
u16 cmdreg;
char *e;
+   int force = 0;
 
-
-   /*
-* First, part the param to get the BDF values
-*/
if (*s == ',')
++s;
 
if (*s == 0)
return;
 
+   /* Force the use of an UART device with wrong class code */
+   if (!strncmp(s, "force,", 6)) {
+   force = 1;
+   s += 6;
+   }
+
+   /*
+* Part the param to get the BDF values
+*/
bus = (u8)simple_strtoul(s, , 16);
s = e;
if (*s != ':')
@@ -253,7 +260,7 @@ static __init void early_pci_serial_init(char *s)
s++;
 
/*
-* Second, find the device from the BDF
+* Find the device from the BDF
 */
cmdreg = read_pci_config(bus, slot, func, PCI_COMMAND);
classcode = read_pci_config(bus, slot, func, PCI_CLASS_REVISION);
@@ -264,8 +271,10 @@ static __init void early_pci_serial_init(char *s)
 */
if (((classcode >> 16 != PCI_CLASS_COMMUNICATION_MODEM) &&
 (classcode >> 16 != PCI_CLASS_COMMUNICATION_SERIAL)) ||
-  (((classcode >> 8) & 0xff) != 0x02)) /* 16550 I/F at BAR0 */
-   return;
+  (((classcode >> 8) & 0xff) != 0x02)) /* 16550 I/F at BAR0 */ {
+ 

[tip:x86/early-printk] x86/earlyprintk: Add a force option for pciserial device

2018-10-02 Thread tip-bot for Feng Tang
Commit-ID:  d2266bbfa9e3e32e3b642965088ca461bd24a94f
Gitweb: https://git.kernel.org/tip/d2266bbfa9e3e32e3b642965088ca461bd24a94f
Author: Feng Tang 
AuthorDate: Wed, 3 Oct 2018 00:49:21 +0800
Committer:  Borislav Petkov 
CommitDate: Tue, 2 Oct 2018 21:02:47 +0200

x86/earlyprintk: Add a force option for pciserial device

The "pciserial" earlyprintk variant helps much on many modern x86
platforms, but unfortunately there are still some platforms with PCI
UART devices which have the wrong PCI class code. In that case, the
current class code check does not allow for them to be used for logging.

Add a sub-option "force" which overrides the class code check and thus
the use of such device can be enforced.

 [ bp: massage formulations. ]

Suggested-by: Borislav Petkov 
Signed-off-by: Feng Tang 
Signed-off-by: Borislav Petkov 
Cc: "H. Peter Anvin" 
Cc: "Stuart R . Anderson" 
Cc: Bjorn Helgaas 
Cc: David Rientjes 
Cc: Feng Tang 
Cc: Frederic Weisbecker 
Cc: Greg Kroah-Hartman 
Cc: H Peter Anvin 
Cc: Ingo Molnar 
Cc: Jiri Kosina 
Cc: Jonathan Corbet 
Cc: Kai-Heng Feng 
Cc: Kate Stewart 
Cc: Konrad Rzeszutek Wilk 
Cc: Peter Zijlstra 
Cc: Philippe Ombredanne 
Cc: Thomas Gleixner 
Cc: Thymo van Beers 
Cc: a...@linux.intel.com
Cc: linux-...@vger.kernel.org
Link: http://lkml.kernel.org/r/20181002164921.25833-1-feng.t...@intel.com
---
 Documentation/admin-guide/kernel-parameters.txt |  6 -
 arch/x86/kernel/early_printk.c  | 29 -
 2 files changed, 24 insertions(+), 11 deletions(-)

diff --git a/Documentation/admin-guide/kernel-parameters.txt 
b/Documentation/admin-guide/kernel-parameters.txt
index 92eb1f42240d..34e6800dea0e 100644
--- a/Documentation/admin-guide/kernel-parameters.txt
+++ b/Documentation/admin-guide/kernel-parameters.txt
@@ -1063,7 +1063,7 @@
earlyprintk=serial[,0x...[,baudrate]]
earlyprintk=ttySn[,baudrate]
earlyprintk=dbgp[debugController#]
-   earlyprintk=pciserial,bus:device.function[,baudrate]
+   
earlyprintk=pciserial[,force],bus:device.function[,baudrate]
earlyprintk=xdbc[xhciController#]
 
earlyprintk is useful when the kernel crashes before
@@ -1095,6 +1095,10 @@
 
The sclp output can only be used on s390.
 
+   The optional "force" to "pciserial" enables use of a
+   PCI device even when its classcode is not of the
+   UART class.
+
edac_report=[HW,EDAC] Control how to report EDAC event
Format: {"on" | "off" | "force"}
on: enable EDAC to report H/W event. May be overridden
diff --git a/arch/x86/kernel/early_printk.c b/arch/x86/kernel/early_printk.c
index 5e801c8c8ce7..374a52fa5296 100644
--- a/arch/x86/kernel/early_printk.c
+++ b/arch/x86/kernel/early_printk.c
@@ -213,8 +213,9 @@ static unsigned int mem32_serial_in(unsigned long addr, int 
offset)
  * early_pci_serial_init()
  *
  * This function is invoked when the early_printk param starts with "pciserial"
- * The rest of the param should be ",B:D.F,baud" where B, D & F describe the
- * location of a PCI device that must be a UART device.
+ * The rest of the param should be "[force],B:D.F,baud", where B, D & F 
describe
+ * the location of a PCI device that must be a UART device. "force" is optional
+ * and overrides the use of an UART device with a wrong PCI class code.
  */
 static __init void early_pci_serial_init(char *s)
 {
@@ -224,17 +225,23 @@ static __init void early_pci_serial_init(char *s)
u32 classcode, bar0;
u16 cmdreg;
char *e;
+   int force = 0;
 
-
-   /*
-* First, part the param to get the BDF values
-*/
if (*s == ',')
++s;
 
if (*s == 0)
return;
 
+   /* Force the use of an UART device with wrong class code */
+   if (!strncmp(s, "force,", 6)) {
+   force = 1;
+   s += 6;
+   }
+
+   /*
+* Part the param to get the BDF values
+*/
bus = (u8)simple_strtoul(s, , 16);
s = e;
if (*s != ':')
@@ -253,7 +260,7 @@ static __init void early_pci_serial_init(char *s)
s++;
 
/*
-* Second, find the device from the BDF
+* Find the device from the BDF
 */
cmdreg = read_pci_config(bus, slot, func, PCI_COMMAND);
classcode = read_pci_config(bus, slot, func, PCI_CLASS_REVISION);
@@ -264,8 +271,10 @@ static __init void early_pci_serial_init(char *s)
 */
if (((classcode >> 16 != PCI_CLASS_COMMUNICATION_MODEM) &&
 (classcode >> 16 != PCI_CLASS_COMMUNICATION_SERIAL)) ||
-  (((classcode >> 8) & 0xff) != 0x02)) /* 16550 I/F at BAR0 */
-   return;
+  (((classcode >> 8) & 0xff) != 0x02)) /* 16550 I/F at BAR0 */ {
+ 

[tip:x86/early-printk] x86/earlyprintk: Add a force option for pciserial device

2018-10-02 Thread tip-bot for Feng Tang
Commit-ID:  fa7948a6413c63128335aa871fade8df55ac61e2
Gitweb: https://git.kernel.org/tip/fa7948a6413c63128335aa871fade8df55ac61e2
Author: Feng Tang 
AuthorDate: Wed, 3 Oct 2018 00:49:21 +0800
Committer:  Borislav Petkov 
CommitDate: Tue, 2 Oct 2018 20:40:27 +0200

x86/earlyprintk: Add a force option for pciserial device

The "pciserial" earlyprintk variant helps much on many modern x86
platforms, but unfortunately there are still some platforms with PCI
UART devices which have the wrong PCI class code. In that case, the
current class code check does not allow for them to be used for logging.

Add a sub-option "force" which overrides the class code check and thus
the use of such device can be enforced.

 [ bp: massage formulations. ]

Suggested-by: Borislav Petkov 
Signed-off-by: Feng Tang 
Cc: "H. Peter Anvin" 
Cc: "Stuart R . Anderson" 
Cc: Bjorn Helgaas 
Cc: David Rientjes 
Cc: Feng Tang 
Cc: Frederic Weisbecker 
Cc: Greg Kroah-Hartman 
Cc: H Peter Anvin 
Cc: Ingo Molnar 
Cc: Jiri Kosina 
Cc: Jonathan Corbet 
Cc: Kai-Heng Feng 
Cc: Kate Stewart 
Cc: Konrad Rzeszutek Wilk 
Cc: Peter Zijlstra 
Cc: Philippe Ombredanne 
Cc: Thomas Gleixner 
Cc: Thymo van Beers 
Cc: a...@linux.intel.com
Cc: linux-...@vger.kernel.org
Link: http://lkml.kernel.org/r/20181002164921.25833-1-feng.t...@intel.com
---
 Documentation/admin-guide/kernel-parameters.txt |  6 -
 arch/x86/kernel/early_printk.c  | 29 -
 2 files changed, 24 insertions(+), 11 deletions(-)

diff --git a/Documentation/admin-guide/kernel-parameters.txt 
b/Documentation/admin-guide/kernel-parameters.txt
index 92eb1f42240d..34e6800dea0e 100644
--- a/Documentation/admin-guide/kernel-parameters.txt
+++ b/Documentation/admin-guide/kernel-parameters.txt
@@ -1063,7 +1063,7 @@
earlyprintk=serial[,0x...[,baudrate]]
earlyprintk=ttySn[,baudrate]
earlyprintk=dbgp[debugController#]
-   earlyprintk=pciserial,bus:device.function[,baudrate]
+   
earlyprintk=pciserial[,force],bus:device.function[,baudrate]
earlyprintk=xdbc[xhciController#]
 
earlyprintk is useful when the kernel crashes before
@@ -1095,6 +1095,10 @@
 
The sclp output can only be used on s390.
 
+   The optional "force" to "pciserial" enables use of a
+   PCI device even when its classcode is not of the
+   UART class.
+
edac_report=[HW,EDAC] Control how to report EDAC event
Format: {"on" | "off" | "force"}
on: enable EDAC to report H/W event. May be overridden
diff --git a/arch/x86/kernel/early_printk.c b/arch/x86/kernel/early_printk.c
index 5e801c8c8ce7..374a52fa5296 100644
--- a/arch/x86/kernel/early_printk.c
+++ b/arch/x86/kernel/early_printk.c
@@ -213,8 +213,9 @@ static unsigned int mem32_serial_in(unsigned long addr, int 
offset)
  * early_pci_serial_init()
  *
  * This function is invoked when the early_printk param starts with "pciserial"
- * The rest of the param should be ",B:D.F,baud" where B, D & F describe the
- * location of a PCI device that must be a UART device.
+ * The rest of the param should be "[force],B:D.F,baud", where B, D & F 
describe
+ * the location of a PCI device that must be a UART device. "force" is optional
+ * and overrides the use of an UART device with a wrong PCI class code.
  */
 static __init void early_pci_serial_init(char *s)
 {
@@ -224,17 +225,23 @@ static __init void early_pci_serial_init(char *s)
u32 classcode, bar0;
u16 cmdreg;
char *e;
+   int force = 0;
 
-
-   /*
-* First, part the param to get the BDF values
-*/
if (*s == ',')
++s;
 
if (*s == 0)
return;
 
+   /* Force the use of an UART device with wrong class code */
+   if (!strncmp(s, "force,", 6)) {
+   force = 1;
+   s += 6;
+   }
+
+   /*
+* Part the param to get the BDF values
+*/
bus = (u8)simple_strtoul(s, , 16);
s = e;
if (*s != ':')
@@ -253,7 +260,7 @@ static __init void early_pci_serial_init(char *s)
s++;
 
/*
-* Second, find the device from the BDF
+* Find the device from the BDF
 */
cmdreg = read_pci_config(bus, slot, func, PCI_COMMAND);
classcode = read_pci_config(bus, slot, func, PCI_CLASS_REVISION);
@@ -264,8 +271,10 @@ static __init void early_pci_serial_init(char *s)
 */
if (((classcode >> 16 != PCI_CLASS_COMMUNICATION_MODEM) &&
 (classcode >> 16 != PCI_CLASS_COMMUNICATION_SERIAL)) ||
-  (((classcode >> 8) & 0xff) != 0x02)) /* 16550 I/F at BAR0 */
-   return;
+  (((classcode >> 8) & 0xff) != 0x02)) /* 16550 I/F at BAR0 */ {
+   if (!force)
+ 

[tip:x86/early-printk] x86/earlyprintk: Add a force option for pciserial device

2018-10-02 Thread tip-bot for Feng Tang
Commit-ID:  fa7948a6413c63128335aa871fade8df55ac61e2
Gitweb: https://git.kernel.org/tip/fa7948a6413c63128335aa871fade8df55ac61e2
Author: Feng Tang 
AuthorDate: Wed, 3 Oct 2018 00:49:21 +0800
Committer:  Borislav Petkov 
CommitDate: Tue, 2 Oct 2018 20:40:27 +0200

x86/earlyprintk: Add a force option for pciserial device

The "pciserial" earlyprintk variant helps much on many modern x86
platforms, but unfortunately there are still some platforms with PCI
UART devices which have the wrong PCI class code. In that case, the
current class code check does not allow for them to be used for logging.

Add a sub-option "force" which overrides the class code check and thus
the use of such device can be enforced.

 [ bp: massage formulations. ]

Suggested-by: Borislav Petkov 
Signed-off-by: Feng Tang 
Cc: "H. Peter Anvin" 
Cc: "Stuart R . Anderson" 
Cc: Bjorn Helgaas 
Cc: David Rientjes 
Cc: Feng Tang 
Cc: Frederic Weisbecker 
Cc: Greg Kroah-Hartman 
Cc: H Peter Anvin 
Cc: Ingo Molnar 
Cc: Jiri Kosina 
Cc: Jonathan Corbet 
Cc: Kai-Heng Feng 
Cc: Kate Stewart 
Cc: Konrad Rzeszutek Wilk 
Cc: Peter Zijlstra 
Cc: Philippe Ombredanne 
Cc: Thomas Gleixner 
Cc: Thymo van Beers 
Cc: a...@linux.intel.com
Cc: linux-...@vger.kernel.org
Link: http://lkml.kernel.org/r/20181002164921.25833-1-feng.t...@intel.com
---
 Documentation/admin-guide/kernel-parameters.txt |  6 -
 arch/x86/kernel/early_printk.c  | 29 -
 2 files changed, 24 insertions(+), 11 deletions(-)

diff --git a/Documentation/admin-guide/kernel-parameters.txt 
b/Documentation/admin-guide/kernel-parameters.txt
index 92eb1f42240d..34e6800dea0e 100644
--- a/Documentation/admin-guide/kernel-parameters.txt
+++ b/Documentation/admin-guide/kernel-parameters.txt
@@ -1063,7 +1063,7 @@
earlyprintk=serial[,0x...[,baudrate]]
earlyprintk=ttySn[,baudrate]
earlyprintk=dbgp[debugController#]
-   earlyprintk=pciserial,bus:device.function[,baudrate]
+   
earlyprintk=pciserial[,force],bus:device.function[,baudrate]
earlyprintk=xdbc[xhciController#]
 
earlyprintk is useful when the kernel crashes before
@@ -1095,6 +1095,10 @@
 
The sclp output can only be used on s390.
 
+   The optional "force" to "pciserial" enables use of a
+   PCI device even when its classcode is not of the
+   UART class.
+
edac_report=[HW,EDAC] Control how to report EDAC event
Format: {"on" | "off" | "force"}
on: enable EDAC to report H/W event. May be overridden
diff --git a/arch/x86/kernel/early_printk.c b/arch/x86/kernel/early_printk.c
index 5e801c8c8ce7..374a52fa5296 100644
--- a/arch/x86/kernel/early_printk.c
+++ b/arch/x86/kernel/early_printk.c
@@ -213,8 +213,9 @@ static unsigned int mem32_serial_in(unsigned long addr, int 
offset)
  * early_pci_serial_init()
  *
  * This function is invoked when the early_printk param starts with "pciserial"
- * The rest of the param should be ",B:D.F,baud" where B, D & F describe the
- * location of a PCI device that must be a UART device.
+ * The rest of the param should be "[force],B:D.F,baud", where B, D & F 
describe
+ * the location of a PCI device that must be a UART device. "force" is optional
+ * and overrides the use of an UART device with a wrong PCI class code.
  */
 static __init void early_pci_serial_init(char *s)
 {
@@ -224,17 +225,23 @@ static __init void early_pci_serial_init(char *s)
u32 classcode, bar0;
u16 cmdreg;
char *e;
+   int force = 0;
 
-
-   /*
-* First, part the param to get the BDF values
-*/
if (*s == ',')
++s;
 
if (*s == 0)
return;
 
+   /* Force the use of an UART device with wrong class code */
+   if (!strncmp(s, "force,", 6)) {
+   force = 1;
+   s += 6;
+   }
+
+   /*
+* Part the param to get the BDF values
+*/
bus = (u8)simple_strtoul(s, , 16);
s = e;
if (*s != ':')
@@ -253,7 +260,7 @@ static __init void early_pci_serial_init(char *s)
s++;
 
/*
-* Second, find the device from the BDF
+* Find the device from the BDF
 */
cmdreg = read_pci_config(bus, slot, func, PCI_COMMAND);
classcode = read_pci_config(bus, slot, func, PCI_CLASS_REVISION);
@@ -264,8 +271,10 @@ static __init void early_pci_serial_init(char *s)
 */
if (((classcode >> 16 != PCI_CLASS_COMMUNICATION_MODEM) &&
 (classcode >> 16 != PCI_CLASS_COMMUNICATION_SERIAL)) ||
-  (((classcode >> 8) & 0xff) != 0x02)) /* 16550 I/F at BAR0 */
-   return;
+  (((classcode >> 8) & 0xff) != 0x02)) /* 16550 I/F at BAR0 */ {
+   if (!force)
+ 

[tip:x86/urgent] x86/mm: Expand static page table for fixmap space

2018-09-20 Thread tip-bot for Feng Tang
Commit-ID:  05ab1d8a4b36ee912b7087c6da127439ed0a903e
Gitweb: https://git.kernel.org/tip/05ab1d8a4b36ee912b7087c6da127439ed0a903e
Author: Feng Tang 
AuthorDate: Thu, 20 Sep 2018 10:58:28 +0800
Committer:  Thomas Gleixner 
CommitDate: Thu, 20 Sep 2018 23:17:22 +0200

x86/mm: Expand static page table for fixmap space

We met a kernel panic when enabling earlycon, which is due to the fixmap
address of earlycon is not statically setup.

Currently the static fixmap setup in head_64.S only covers 2M virtual
address space, while it actually could be in 4M space with different
kernel configurations, e.g. when VSYSCALL emulation is disabled.

So increase the static space to 4M for now by defining FIXMAP_PMD_NUM to 2,
and add a build time check to ensure that the fixmap is covered by the
initial static page tables.

Fixes: 1ad83c858c7d ("x86_64,vsyscall: Make vsyscall emulation configurable")
Suggested-by: Thomas Gleixner 
Signed-off-by: Feng Tang 
Signed-off-by: Thomas Gleixner 
Tested-by: kernel test robot 
Reviewed-by: Juergen Gross  (Xen parts)
Cc: H Peter Anvin 
Cc: Peter Zijlstra 
Cc: Michal Hocko 
Cc: Yinghai Lu 
Cc: Dave Hansen 
Cc: Andi Kleen 
Cc: Andy Lutomirsky 
Cc: sta...@vger.kernel.org
Link: https://lkml.kernel.org/r/20180920025828.23699-1-feng.t...@intel.com
---
 arch/x86/include/asm/fixmap.h | 10 ++
 arch/x86/include/asm/pgtable_64.h |  3 ++-
 arch/x86/kernel/head64.c  |  4 +++-
 arch/x86/kernel/head_64.S | 16 
 arch/x86/mm/pgtable.c |  9 +
 arch/x86/xen/mmu_pv.c |  8 ++--
 6 files changed, 42 insertions(+), 8 deletions(-)

diff --git a/arch/x86/include/asm/fixmap.h b/arch/x86/include/asm/fixmap.h
index e203169931c7..6390bd8c141b 100644
--- a/arch/x86/include/asm/fixmap.h
+++ b/arch/x86/include/asm/fixmap.h
@@ -14,6 +14,16 @@
 #ifndef _ASM_X86_FIXMAP_H
 #define _ASM_X86_FIXMAP_H
 
+/*
+ * Exposed to assembly code for setting up initial page tables. Cannot be
+ * calculated in assembly code (fixmap entries are an enum), but is sanity
+ * checked in the actual fixmap C code to make sure that the fixmap is
+ * covered fully.
+ */
+#define FIXMAP_PMD_NUM 2
+/* fixmap starts downwards from the 507th entry in level2_fixmap_pgt */
+#define FIXMAP_PMD_TOP 507
+
 #ifndef __ASSEMBLY__
 #include 
 #include 
diff --git a/arch/x86/include/asm/pgtable_64.h 
b/arch/x86/include/asm/pgtable_64.h
index ce2b59047cb8..9c85b54bf03c 100644
--- a/arch/x86/include/asm/pgtable_64.h
+++ b/arch/x86/include/asm/pgtable_64.h
@@ -14,6 +14,7 @@
 #include 
 #include 
 #include 
+#include 
 
 extern p4d_t level4_kernel_pgt[512];
 extern p4d_t level4_ident_pgt[512];
@@ -22,7 +23,7 @@ extern pud_t level3_ident_pgt[512];
 extern pmd_t level2_kernel_pgt[512];
 extern pmd_t level2_fixmap_pgt[512];
 extern pmd_t level2_ident_pgt[512];
-extern pte_t level1_fixmap_pgt[512];
+extern pte_t level1_fixmap_pgt[512 * FIXMAP_PMD_NUM];
 extern pgd_t init_top_pgt[];
 
 #define swapper_pg_dir init_top_pgt
diff --git a/arch/x86/kernel/head64.c b/arch/x86/kernel/head64.c
index c16af27eb23f..ddee1f0870c4 100644
--- a/arch/x86/kernel/head64.c
+++ b/arch/x86/kernel/head64.c
@@ -35,6 +35,7 @@
 #include 
 #include 
 #include 
+#include 
 
 /*
  * Manage page tables very early on.
@@ -166,7 +167,8 @@ unsigned long __head __startup_64(unsigned long physaddr,
pud[511] += load_delta;
 
pmd = fixup_pointer(level2_fixmap_pgt, physaddr);
-   pmd[506] += load_delta;
+   for (i = FIXMAP_PMD_TOP; i > FIXMAP_PMD_TOP - FIXMAP_PMD_NUM; i--)
+   pmd[i] += load_delta;
 
/*
 * Set up the identity mapping for the switchover.  These
diff --git a/arch/x86/kernel/head_64.S b/arch/x86/kernel/head_64.S
index 15ebc2fc166e..a3618cf04cf6 100644
--- a/arch/x86/kernel/head_64.S
+++ b/arch/x86/kernel/head_64.S
@@ -24,6 +24,7 @@
 #include "../entry/calling.h"
 #include 
 #include 
+#include 
 
 #ifdef CONFIG_PARAVIRT
 #include 
@@ -445,13 +446,20 @@ NEXT_PAGE(level2_kernel_pgt)
KERNEL_IMAGE_SIZE/PMD_SIZE)
 
 NEXT_PAGE(level2_fixmap_pgt)
-   .fill   506,8,0
-   .quad   level1_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE_NOENC
-   /* 8MB reserved for vsyscalls + a 2MB hole = 4 + 1 entries */
-   .fill   5,8,0
+   .fill   (512 - 4 - FIXMAP_PMD_NUM),8,0
+   pgtno = 0
+   .rept (FIXMAP_PMD_NUM)
+   .quad level1_fixmap_pgt + (pgtno << PAGE_SHIFT) - __START_KERNEL_map \
+   + _PAGE_TABLE_NOENC;
+   pgtno = pgtno + 1
+   .endr
+   /* 6 MB reserved space + a 2MB hole */
+   .fill   4,8,0
 
 NEXT_PAGE(level1_fixmap_pgt)
+   .rept (FIXMAP_PMD_NUM)
.fill   512,8,0
+   .endr
 
 #undef PMDS
 
diff --git a/arch/x86/mm/pgtable.c b/arch/x86/mm/pgtable.c
index ae394552fb94..089e78c4effd 100644
--- a/arch/x86/mm/pgtable.c
+++ b/arch/x86/mm/pgtable.c
@@ -637,6 +637,15 @@ void __native_set_fixmap(enum fixed_addresses idx, pte_t 
pte)
 {
unsigned long address = 

[tip:x86/urgent] x86/mm: Expand static page table for fixmap space

2018-09-20 Thread tip-bot for Feng Tang
Commit-ID:  05ab1d8a4b36ee912b7087c6da127439ed0a903e
Gitweb: https://git.kernel.org/tip/05ab1d8a4b36ee912b7087c6da127439ed0a903e
Author: Feng Tang 
AuthorDate: Thu, 20 Sep 2018 10:58:28 +0800
Committer:  Thomas Gleixner 
CommitDate: Thu, 20 Sep 2018 23:17:22 +0200

x86/mm: Expand static page table for fixmap space

We met a kernel panic when enabling earlycon, which is due to the fixmap
address of earlycon is not statically setup.

Currently the static fixmap setup in head_64.S only covers 2M virtual
address space, while it actually could be in 4M space with different
kernel configurations, e.g. when VSYSCALL emulation is disabled.

So increase the static space to 4M for now by defining FIXMAP_PMD_NUM to 2,
and add a build time check to ensure that the fixmap is covered by the
initial static page tables.

Fixes: 1ad83c858c7d ("x86_64,vsyscall: Make vsyscall emulation configurable")
Suggested-by: Thomas Gleixner 
Signed-off-by: Feng Tang 
Signed-off-by: Thomas Gleixner 
Tested-by: kernel test robot 
Reviewed-by: Juergen Gross  (Xen parts)
Cc: H Peter Anvin 
Cc: Peter Zijlstra 
Cc: Michal Hocko 
Cc: Yinghai Lu 
Cc: Dave Hansen 
Cc: Andi Kleen 
Cc: Andy Lutomirsky 
Cc: sta...@vger.kernel.org
Link: https://lkml.kernel.org/r/20180920025828.23699-1-feng.t...@intel.com
---
 arch/x86/include/asm/fixmap.h | 10 ++
 arch/x86/include/asm/pgtable_64.h |  3 ++-
 arch/x86/kernel/head64.c  |  4 +++-
 arch/x86/kernel/head_64.S | 16 
 arch/x86/mm/pgtable.c |  9 +
 arch/x86/xen/mmu_pv.c |  8 ++--
 6 files changed, 42 insertions(+), 8 deletions(-)

diff --git a/arch/x86/include/asm/fixmap.h b/arch/x86/include/asm/fixmap.h
index e203169931c7..6390bd8c141b 100644
--- a/arch/x86/include/asm/fixmap.h
+++ b/arch/x86/include/asm/fixmap.h
@@ -14,6 +14,16 @@
 #ifndef _ASM_X86_FIXMAP_H
 #define _ASM_X86_FIXMAP_H
 
+/*
+ * Exposed to assembly code for setting up initial page tables. Cannot be
+ * calculated in assembly code (fixmap entries are an enum), but is sanity
+ * checked in the actual fixmap C code to make sure that the fixmap is
+ * covered fully.
+ */
+#define FIXMAP_PMD_NUM 2
+/* fixmap starts downwards from the 507th entry in level2_fixmap_pgt */
+#define FIXMAP_PMD_TOP 507
+
 #ifndef __ASSEMBLY__
 #include 
 #include 
diff --git a/arch/x86/include/asm/pgtable_64.h 
b/arch/x86/include/asm/pgtable_64.h
index ce2b59047cb8..9c85b54bf03c 100644
--- a/arch/x86/include/asm/pgtable_64.h
+++ b/arch/x86/include/asm/pgtable_64.h
@@ -14,6 +14,7 @@
 #include 
 #include 
 #include 
+#include 
 
 extern p4d_t level4_kernel_pgt[512];
 extern p4d_t level4_ident_pgt[512];
@@ -22,7 +23,7 @@ extern pud_t level3_ident_pgt[512];
 extern pmd_t level2_kernel_pgt[512];
 extern pmd_t level2_fixmap_pgt[512];
 extern pmd_t level2_ident_pgt[512];
-extern pte_t level1_fixmap_pgt[512];
+extern pte_t level1_fixmap_pgt[512 * FIXMAP_PMD_NUM];
 extern pgd_t init_top_pgt[];
 
 #define swapper_pg_dir init_top_pgt
diff --git a/arch/x86/kernel/head64.c b/arch/x86/kernel/head64.c
index c16af27eb23f..ddee1f0870c4 100644
--- a/arch/x86/kernel/head64.c
+++ b/arch/x86/kernel/head64.c
@@ -35,6 +35,7 @@
 #include 
 #include 
 #include 
+#include 
 
 /*
  * Manage page tables very early on.
@@ -166,7 +167,8 @@ unsigned long __head __startup_64(unsigned long physaddr,
pud[511] += load_delta;
 
pmd = fixup_pointer(level2_fixmap_pgt, physaddr);
-   pmd[506] += load_delta;
+   for (i = FIXMAP_PMD_TOP; i > FIXMAP_PMD_TOP - FIXMAP_PMD_NUM; i--)
+   pmd[i] += load_delta;
 
/*
 * Set up the identity mapping for the switchover.  These
diff --git a/arch/x86/kernel/head_64.S b/arch/x86/kernel/head_64.S
index 15ebc2fc166e..a3618cf04cf6 100644
--- a/arch/x86/kernel/head_64.S
+++ b/arch/x86/kernel/head_64.S
@@ -24,6 +24,7 @@
 #include "../entry/calling.h"
 #include 
 #include 
+#include 
 
 #ifdef CONFIG_PARAVIRT
 #include 
@@ -445,13 +446,20 @@ NEXT_PAGE(level2_kernel_pgt)
KERNEL_IMAGE_SIZE/PMD_SIZE)
 
 NEXT_PAGE(level2_fixmap_pgt)
-   .fill   506,8,0
-   .quad   level1_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE_NOENC
-   /* 8MB reserved for vsyscalls + a 2MB hole = 4 + 1 entries */
-   .fill   5,8,0
+   .fill   (512 - 4 - FIXMAP_PMD_NUM),8,0
+   pgtno = 0
+   .rept (FIXMAP_PMD_NUM)
+   .quad level1_fixmap_pgt + (pgtno << PAGE_SHIFT) - __START_KERNEL_map \
+   + _PAGE_TABLE_NOENC;
+   pgtno = pgtno + 1
+   .endr
+   /* 6 MB reserved space + a 2MB hole */
+   .fill   4,8,0
 
 NEXT_PAGE(level1_fixmap_pgt)
+   .rept (FIXMAP_PMD_NUM)
.fill   512,8,0
+   .endr
 
 #undef PMDS
 
diff --git a/arch/x86/mm/pgtable.c b/arch/x86/mm/pgtable.c
index ae394552fb94..089e78c4effd 100644
--- a/arch/x86/mm/pgtable.c
+++ b/arch/x86/mm/pgtable.c
@@ -637,6 +637,15 @@ void __native_set_fixmap(enum fixed_addresses idx, pte_t 
pte)
 {
unsigned long address = 

[tip:x86/urgent] x86/mm: Expand static page table for fixmap space

2018-09-18 Thread tip-bot for Feng Tang
Commit-ID:  31217900acbaf66249b8befd06c975aa897b4deb
Gitweb: https://git.kernel.org/tip/31217900acbaf66249b8befd06c975aa897b4deb
Author: Feng Tang 
AuthorDate: Mon, 17 Sep 2018 17:14:23 +0800
Committer:  Thomas Gleixner 
CommitDate: Wed, 19 Sep 2018 00:09:10 +0200

x86/mm: Expand static page table for fixmap space

We met a kernel panic when enabling earlycon, which is due to the fixmap
address of earlycon is not statically setup.

Currently the static fixmap setup in head_64.S only covers 2M virtual
address space, while it acutually could be in 4M space with different
kernel configurations.

So increase the static space to 4M for now by defining FIXMAP_PMD_NUM to 2,
and add a build time check to ensure that the fixmap is covered by the
intial static page tables.

[ tglx: s/PTRS_PER_PMD/PTRS_PER_PTE/ and add the missing brackets ]

Suggested-by: Thomas Gleixner 
Signed-off-by: Feng Tang 
Signed-off-by: Thomas Gleixner 
Reviewed-by: Juergen Gross  (Xen parts)
Cc: H Peter Anvin 
Cc: Peter Zijlstra 
Cc: Michal Hocko 
Cc: Yinghai Lu 
Cc: Dave Hansen 
Cc: Andi Kleen 
Link: https://lkml.kernel.org/r/20180917091423.16069-1-feng.t...@intel.com

---
 arch/x86/include/asm/fixmap.h |  8 
 arch/x86/include/asm/pgtable_64.h |  3 ++-
 arch/x86/kernel/head_64.S | 16 
 arch/x86/mm/pgtable.c |  9 +
 arch/x86/xen/mmu_pv.c |  8 ++--
 5 files changed, 37 insertions(+), 7 deletions(-)

diff --git a/arch/x86/include/asm/fixmap.h b/arch/x86/include/asm/fixmap.h
index e203169931c7..01e8da740293 100644
--- a/arch/x86/include/asm/fixmap.h
+++ b/arch/x86/include/asm/fixmap.h
@@ -14,6 +14,14 @@
 #ifndef _ASM_X86_FIXMAP_H
 #define _ASM_X86_FIXMAP_H
 
+/*
+ * Exposed to assembly code for setting up initial page tables. Cannot be
+ * calculated in assembly code (fixmap entries are an enum), but is sanity
+ * checked in the actual fixmap C code to make sure that the fixmap is
+ * covered fully.
+ */
+#define FIXMAP_PMD_NUM 2
+
 #ifndef __ASSEMBLY__
 #include 
 #include 
diff --git a/arch/x86/include/asm/pgtable_64.h 
b/arch/x86/include/asm/pgtable_64.h
index ce2b59047cb8..9c85b54bf03c 100644
--- a/arch/x86/include/asm/pgtable_64.h
+++ b/arch/x86/include/asm/pgtable_64.h
@@ -14,6 +14,7 @@
 #include 
 #include 
 #include 
+#include 
 
 extern p4d_t level4_kernel_pgt[512];
 extern p4d_t level4_ident_pgt[512];
@@ -22,7 +23,7 @@ extern pud_t level3_ident_pgt[512];
 extern pmd_t level2_kernel_pgt[512];
 extern pmd_t level2_fixmap_pgt[512];
 extern pmd_t level2_ident_pgt[512];
-extern pte_t level1_fixmap_pgt[512];
+extern pte_t level1_fixmap_pgt[512 * FIXMAP_PMD_NUM];
 extern pgd_t init_top_pgt[];
 
 #define swapper_pg_dir init_top_pgt
diff --git a/arch/x86/kernel/head_64.S b/arch/x86/kernel/head_64.S
index 15ebc2fc166e..a3618cf04cf6 100644
--- a/arch/x86/kernel/head_64.S
+++ b/arch/x86/kernel/head_64.S
@@ -24,6 +24,7 @@
 #include "../entry/calling.h"
 #include 
 #include 
+#include 
 
 #ifdef CONFIG_PARAVIRT
 #include 
@@ -445,13 +446,20 @@ NEXT_PAGE(level2_kernel_pgt)
KERNEL_IMAGE_SIZE/PMD_SIZE)
 
 NEXT_PAGE(level2_fixmap_pgt)
-   .fill   506,8,0
-   .quad   level1_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE_NOENC
-   /* 8MB reserved for vsyscalls + a 2MB hole = 4 + 1 entries */
-   .fill   5,8,0
+   .fill   (512 - 4 - FIXMAP_PMD_NUM),8,0
+   pgtno = 0
+   .rept (FIXMAP_PMD_NUM)
+   .quad level1_fixmap_pgt + (pgtno << PAGE_SHIFT) - __START_KERNEL_map \
+   + _PAGE_TABLE_NOENC;
+   pgtno = pgtno + 1
+   .endr
+   /* 6 MB reserved space + a 2MB hole */
+   .fill   4,8,0
 
 NEXT_PAGE(level1_fixmap_pgt)
+   .rept (FIXMAP_PMD_NUM)
.fill   512,8,0
+   .endr
 
 #undef PMDS
 
diff --git a/arch/x86/mm/pgtable.c b/arch/x86/mm/pgtable.c
index ae394552fb94..089e78c4effd 100644
--- a/arch/x86/mm/pgtable.c
+++ b/arch/x86/mm/pgtable.c
@@ -637,6 +637,15 @@ void __native_set_fixmap(enum fixed_addresses idx, pte_t 
pte)
 {
unsigned long address = __fix_to_virt(idx);
 
+#ifdef CONFIG_X86_64
+   /*
+   * Ensure that the static initial page tables are covering the
+   * fixmap completely.
+   */
+   BUILD_BUG_ON(__end_of_permanent_fixed_addresses >
+(FIXMAP_PMD_NUM * PTRS_PER_PTE));
+#endif
+
if (idx >= __end_of_fixed_addresses) {
BUG();
return;
diff --git a/arch/x86/xen/mmu_pv.c b/arch/x86/xen/mmu_pv.c
index 2fe5c9b1816b..dd461c0167ef 100644
--- a/arch/x86/xen/mmu_pv.c
+++ b/arch/x86/xen/mmu_pv.c
@@ -1907,7 +1907,7 @@ void __init xen_setup_kernel_pagetable(pgd_t *pgd, 
unsigned long max_pfn)
/* L3_k[511] -> level2_fixmap_pgt */
convert_pfn_mfn(level3_kernel_pgt);
 
-   /* L3_k[511][506] -> level1_fixmap_pgt */
+   /* L3_k[511][508-FIXMAP_PMD_NUM ... 507] -> level1_fixmap_pgt */
convert_pfn_mfn(level2_fixmap_pgt);
 
/* We get [511][511] and have Xen's version of 

[tip:x86/urgent] x86/mm: Expand static page table for fixmap space

2018-09-18 Thread tip-bot for Feng Tang
Commit-ID:  31217900acbaf66249b8befd06c975aa897b4deb
Gitweb: https://git.kernel.org/tip/31217900acbaf66249b8befd06c975aa897b4deb
Author: Feng Tang 
AuthorDate: Mon, 17 Sep 2018 17:14:23 +0800
Committer:  Thomas Gleixner 
CommitDate: Wed, 19 Sep 2018 00:09:10 +0200

x86/mm: Expand static page table for fixmap space

We met a kernel panic when enabling earlycon, which is due to the fixmap
address of earlycon is not statically setup.

Currently the static fixmap setup in head_64.S only covers 2M virtual
address space, while it acutually could be in 4M space with different
kernel configurations.

So increase the static space to 4M for now by defining FIXMAP_PMD_NUM to 2,
and add a build time check to ensure that the fixmap is covered by the
intial static page tables.

[ tglx: s/PTRS_PER_PMD/PTRS_PER_PTE/ and add the missing brackets ]

Suggested-by: Thomas Gleixner 
Signed-off-by: Feng Tang 
Signed-off-by: Thomas Gleixner 
Reviewed-by: Juergen Gross  (Xen parts)
Cc: H Peter Anvin 
Cc: Peter Zijlstra 
Cc: Michal Hocko 
Cc: Yinghai Lu 
Cc: Dave Hansen 
Cc: Andi Kleen 
Link: https://lkml.kernel.org/r/20180917091423.16069-1-feng.t...@intel.com

---
 arch/x86/include/asm/fixmap.h |  8 
 arch/x86/include/asm/pgtable_64.h |  3 ++-
 arch/x86/kernel/head_64.S | 16 
 arch/x86/mm/pgtable.c |  9 +
 arch/x86/xen/mmu_pv.c |  8 ++--
 5 files changed, 37 insertions(+), 7 deletions(-)

diff --git a/arch/x86/include/asm/fixmap.h b/arch/x86/include/asm/fixmap.h
index e203169931c7..01e8da740293 100644
--- a/arch/x86/include/asm/fixmap.h
+++ b/arch/x86/include/asm/fixmap.h
@@ -14,6 +14,14 @@
 #ifndef _ASM_X86_FIXMAP_H
 #define _ASM_X86_FIXMAP_H
 
+/*
+ * Exposed to assembly code for setting up initial page tables. Cannot be
+ * calculated in assembly code (fixmap entries are an enum), but is sanity
+ * checked in the actual fixmap C code to make sure that the fixmap is
+ * covered fully.
+ */
+#define FIXMAP_PMD_NUM 2
+
 #ifndef __ASSEMBLY__
 #include 
 #include 
diff --git a/arch/x86/include/asm/pgtable_64.h 
b/arch/x86/include/asm/pgtable_64.h
index ce2b59047cb8..9c85b54bf03c 100644
--- a/arch/x86/include/asm/pgtable_64.h
+++ b/arch/x86/include/asm/pgtable_64.h
@@ -14,6 +14,7 @@
 #include 
 #include 
 #include 
+#include 
 
 extern p4d_t level4_kernel_pgt[512];
 extern p4d_t level4_ident_pgt[512];
@@ -22,7 +23,7 @@ extern pud_t level3_ident_pgt[512];
 extern pmd_t level2_kernel_pgt[512];
 extern pmd_t level2_fixmap_pgt[512];
 extern pmd_t level2_ident_pgt[512];
-extern pte_t level1_fixmap_pgt[512];
+extern pte_t level1_fixmap_pgt[512 * FIXMAP_PMD_NUM];
 extern pgd_t init_top_pgt[];
 
 #define swapper_pg_dir init_top_pgt
diff --git a/arch/x86/kernel/head_64.S b/arch/x86/kernel/head_64.S
index 15ebc2fc166e..a3618cf04cf6 100644
--- a/arch/x86/kernel/head_64.S
+++ b/arch/x86/kernel/head_64.S
@@ -24,6 +24,7 @@
 #include "../entry/calling.h"
 #include 
 #include 
+#include 
 
 #ifdef CONFIG_PARAVIRT
 #include 
@@ -445,13 +446,20 @@ NEXT_PAGE(level2_kernel_pgt)
KERNEL_IMAGE_SIZE/PMD_SIZE)
 
 NEXT_PAGE(level2_fixmap_pgt)
-   .fill   506,8,0
-   .quad   level1_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE_NOENC
-   /* 8MB reserved for vsyscalls + a 2MB hole = 4 + 1 entries */
-   .fill   5,8,0
+   .fill   (512 - 4 - FIXMAP_PMD_NUM),8,0
+   pgtno = 0
+   .rept (FIXMAP_PMD_NUM)
+   .quad level1_fixmap_pgt + (pgtno << PAGE_SHIFT) - __START_KERNEL_map \
+   + _PAGE_TABLE_NOENC;
+   pgtno = pgtno + 1
+   .endr
+   /* 6 MB reserved space + a 2MB hole */
+   .fill   4,8,0
 
 NEXT_PAGE(level1_fixmap_pgt)
+   .rept (FIXMAP_PMD_NUM)
.fill   512,8,0
+   .endr
 
 #undef PMDS
 
diff --git a/arch/x86/mm/pgtable.c b/arch/x86/mm/pgtable.c
index ae394552fb94..089e78c4effd 100644
--- a/arch/x86/mm/pgtable.c
+++ b/arch/x86/mm/pgtable.c
@@ -637,6 +637,15 @@ void __native_set_fixmap(enum fixed_addresses idx, pte_t 
pte)
 {
unsigned long address = __fix_to_virt(idx);
 
+#ifdef CONFIG_X86_64
+   /*
+   * Ensure that the static initial page tables are covering the
+   * fixmap completely.
+   */
+   BUILD_BUG_ON(__end_of_permanent_fixed_addresses >
+(FIXMAP_PMD_NUM * PTRS_PER_PTE));
+#endif
+
if (idx >= __end_of_fixed_addresses) {
BUG();
return;
diff --git a/arch/x86/xen/mmu_pv.c b/arch/x86/xen/mmu_pv.c
index 2fe5c9b1816b..dd461c0167ef 100644
--- a/arch/x86/xen/mmu_pv.c
+++ b/arch/x86/xen/mmu_pv.c
@@ -1907,7 +1907,7 @@ void __init xen_setup_kernel_pagetable(pgd_t *pgd, 
unsigned long max_pfn)
/* L3_k[511] -> level2_fixmap_pgt */
convert_pfn_mfn(level3_kernel_pgt);
 
-   /* L3_k[511][506] -> level1_fixmap_pgt */
+   /* L3_k[511][508-FIXMAP_PMD_NUM ... 507] -> level1_fixmap_pgt */
convert_pfn_mfn(level2_fixmap_pgt);
 
/* We get [511][511] and have Xen's version of 

[tip:x86/platform] x86/platform/intel/baytrail: Add comments about why we disabled HPET on Baytrail

2015-06-18 Thread tip-bot for Feng Tang
Commit-ID:  b58d930750135d6c5b8e5aa084c0e9303c78c286
Gitweb: http://git.kernel.org/tip/b58d930750135d6c5b8e5aa084c0e9303c78c286
Author: Feng Tang 
AuthorDate: Mon, 15 Jun 2015 17:40:01 +0800
Committer:  Ingo Molnar 
CommitDate: Thu, 18 Jun 2015 10:57:38 +0200

x86/platform/intel/baytrail: Add comments about why we disabled HPET on Baytrail

This question has been asked many times, and finally I found the
official document which explains the problem of HPET on Baytrail,
that it will halt in deep idle states.

Signed-off-by: Feng Tang 
Cc: Andrew Morton 
Cc: Andy Lutomirski 
Cc: Borislav Petkov 
Cc: Brian Gerst 
Cc: Denys Vlasenko 
Cc: H. Peter Anvin 
Cc: Linus Torvalds 
Cc: Oleg Nesterov 
Cc: Peter Zijlstra 
Cc: Thomas Gleixner 
Cc: john.stu...@linaro.org
Cc: len.br...@intel.com
Cc: matthew@intel.com
Link: 
http://lkml.kernel.org/r/1434361201-31743-1-git-send-email-feng.t...@intel.com
[ Prettified things a bit. ]
Signed-off-by: Ingo Molnar 
---
 arch/x86/kernel/early-quirks.c | 8 ++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/arch/x86/kernel/early-quirks.c b/arch/x86/kernel/early-quirks.c
index fe9f0b7..5cb9a4d 100644
--- a/arch/x86/kernel/early-quirks.c
+++ b/arch/x86/kernel/early-quirks.c
@@ -627,8 +627,12 @@ static struct chipset early_qrk[] __initdata = {
{ PCI_VENDOR_ID_INTEL, PCI_ANY_ID, PCI_CLASS_DISPLAY_VGA, PCI_ANY_ID,
  QFLAG_APPLY_ONCE, intel_graphics_stolen },
/*
-* HPET on current version of Baytrail platform has accuracy
-* problems, disable it for now:
+* HPET on the current version of the Baytrail platform has accuracy
+* problems: it will halt in deep idle state - so we disable it.
+*
+* More details can be found in section 18.10.1.3 of the datasheet:
+*
+*
http://www.intel.com/content/dam/www/public/us/en/documents/datasheets/atom-z8000-datasheet-vol-1.pdf
 */
{ PCI_VENDOR_ID_INTEL, 0x0f00,
PCI_CLASS_BRIDGE_HOST, PCI_ANY_ID, 0, force_disable_hpet},
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[tip:x86/platform] x86/platform/intel/baytrail: Add comments about why we disabled HPET on Baytrail

2015-06-18 Thread tip-bot for Feng Tang
Commit-ID:  b58d930750135d6c5b8e5aa084c0e9303c78c286
Gitweb: http://git.kernel.org/tip/b58d930750135d6c5b8e5aa084c0e9303c78c286
Author: Feng Tang feng.t...@intel.com
AuthorDate: Mon, 15 Jun 2015 17:40:01 +0800
Committer:  Ingo Molnar mi...@kernel.org
CommitDate: Thu, 18 Jun 2015 10:57:38 +0200

x86/platform/intel/baytrail: Add comments about why we disabled HPET on Baytrail

This question has been asked many times, and finally I found the
official document which explains the problem of HPET on Baytrail,
that it will halt in deep idle states.

Signed-off-by: Feng Tang feng.t...@intel.com
Cc: Andrew Morton a...@linux-foundation.org
Cc: Andy Lutomirski l...@amacapital.net
Cc: Borislav Petkov b...@alien8.de
Cc: Brian Gerst brge...@gmail.com
Cc: Denys Vlasenko dvlas...@redhat.com
Cc: H. Peter Anvin h...@zytor.com
Cc: Linus Torvalds torva...@linux-foundation.org
Cc: Oleg Nesterov o...@redhat.com
Cc: Peter Zijlstra pet...@infradead.org
Cc: Thomas Gleixner t...@linutronix.de
Cc: john.stu...@linaro.org
Cc: len.br...@intel.com
Cc: matthew@intel.com
Link: 
http://lkml.kernel.org/r/1434361201-31743-1-git-send-email-feng.t...@intel.com
[ Prettified things a bit. ]
Signed-off-by: Ingo Molnar mi...@kernel.org
---
 arch/x86/kernel/early-quirks.c | 8 ++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/arch/x86/kernel/early-quirks.c b/arch/x86/kernel/early-quirks.c
index fe9f0b7..5cb9a4d 100644
--- a/arch/x86/kernel/early-quirks.c
+++ b/arch/x86/kernel/early-quirks.c
@@ -627,8 +627,12 @@ static struct chipset early_qrk[] __initdata = {
{ PCI_VENDOR_ID_INTEL, PCI_ANY_ID, PCI_CLASS_DISPLAY_VGA, PCI_ANY_ID,
  QFLAG_APPLY_ONCE, intel_graphics_stolen },
/*
-* HPET on current version of Baytrail platform has accuracy
-* problems, disable it for now:
+* HPET on the current version of the Baytrail platform has accuracy
+* problems: it will halt in deep idle state - so we disable it.
+*
+* More details can be found in section 18.10.1.3 of the datasheet:
+*
+*
http://www.intel.com/content/dam/www/public/us/en/documents/datasheets/atom-z8000-datasheet-vol-1.pdf
 */
{ PCI_VENDOR_ID_INTEL, 0x0f00,
PCI_CLASS_BRIDGE_HOST, PCI_ANY_ID, 0, force_disable_hpet},
--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[tip:x86/urgent] x86/intel: Add quirk to disable HPET for the Baytrail platform

2014-05-08 Thread tip-bot for Feng Tang
Commit-ID:  62187910b0fc7a75cfec9c30fda58ce2f39d689b
Gitweb: http://git.kernel.org/tip/62187910b0fc7a75cfec9c30fda58ce2f39d689b
Author: Feng Tang 
AuthorDate: Thu, 24 Apr 2014 16:18:18 +0800
Committer:  Ingo Molnar 
CommitDate: Thu, 8 May 2014 08:15:34 +0200

x86/intel: Add quirk to disable HPET for the Baytrail platform

HPET on current Baytrail platform has accuracy problem to be
used as reliable clocksource/clockevent, so add a early quirk to
disable it.

Signed-off-by: Feng Tang 
Cc: Clemens Ladisch 
Cc: John Stultz 
Cc: Linus Torvalds 
Link: 
http://lkml.kernel.org/r/1398327498-13163-2-git-send-email-feng.t...@intel.com
Signed-off-by: Ingo Molnar 
---
 arch/x86/kernel/early-quirks.c | 16 
 1 file changed, 16 insertions(+)

diff --git a/arch/x86/kernel/early-quirks.c b/arch/x86/kernel/early-quirks.c
index 6e2537c..6cda0ba 100644
--- a/arch/x86/kernel/early-quirks.c
+++ b/arch/x86/kernel/early-quirks.c
@@ -17,6 +17,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -530,6 +531,15 @@ static void __init intel_graphics_stolen(int num, int 
slot, int func)
}
 }
 
+static void __init force_disable_hpet(int num, int slot, int func)
+{
+#ifdef CONFIG_HPET_TIMER
+   boot_hpet_disable = 1;
+   pr_info("x86/hpet: Will disable the HPET for this platform because it's 
not reliable\n");
+#endif
+}
+
+
 #define QFLAG_APPLY_ONCE   0x1
 #define QFLAG_APPLIED  0x2
 #define QFLAG_DONE (QFLAG_APPLY_ONCE|QFLAG_APPLIED)
@@ -567,6 +577,12 @@ static struct chipset early_qrk[] __initdata = {
  PCI_BASE_CLASS_BRIDGE, 0, intel_remapping_check },
{ PCI_VENDOR_ID_INTEL, PCI_ANY_ID, PCI_CLASS_DISPLAY_VGA, PCI_ANY_ID,
  QFLAG_APPLY_ONCE, intel_graphics_stolen },
+   /*
+* HPET on current version of Baytrail platform has accuracy
+* problems, disable it for now:
+*/
+   { PCI_VENDOR_ID_INTEL, 0x0f00,
+   PCI_CLASS_BRIDGE_HOST, PCI_ANY_ID, 0, force_disable_hpet},
{}
 };
 
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[tip:x86/urgent] x86/hpet: Make boot_hpet_disable extern

2014-05-08 Thread tip-bot for Feng Tang
Commit-ID:  f10f383d8414bfe3357e24432ed8a26eeb58ffb8
Gitweb: http://git.kernel.org/tip/f10f383d8414bfe3357e24432ed8a26eeb58ffb8
Author: Feng Tang 
AuthorDate: Thu, 24 Apr 2014 16:18:17 +0800
Committer:  Ingo Molnar 
CommitDate: Thu, 8 May 2014 08:15:34 +0200

x86/hpet: Make boot_hpet_disable extern

HPET on some platform has accuracy problem. Making
"boot_hpet_disable" extern so that we can runtime disable
the HPET timer by using quirk to check the platform.

Signed-off-by: Feng Tang 
Cc: Clemens Ladisch 
Cc: John Stultz 
Cc: Linus Torvalds 
Link: 
http://lkml.kernel.org/r/1398327498-13163-1-git-send-email-feng.t...@intel.com
Signed-off-by: Ingo Molnar 
---
 arch/x86/include/asm/hpet.h | 1 +
 arch/x86/kernel/hpet.c  | 2 +-
 2 files changed, 2 insertions(+), 1 deletion(-)

diff --git a/arch/x86/include/asm/hpet.h b/arch/x86/include/asm/hpet.h
index b18df57..36f7125 100644
--- a/arch/x86/include/asm/hpet.h
+++ b/arch/x86/include/asm/hpet.h
@@ -63,6 +63,7 @@
 /* hpet memory map physical address */
 extern unsigned long hpet_address;
 extern unsigned long force_hpet_address;
+extern int boot_hpet_disable;
 extern u8 hpet_blockid;
 extern int hpet_force_user;
 extern u8 hpet_msi_disable;
diff --git a/arch/x86/kernel/hpet.c b/arch/x86/kernel/hpet.c
index 8d80ae0..4177bfb 100644
--- a/arch/x86/kernel/hpet.c
+++ b/arch/x86/kernel/hpet.c
@@ -88,7 +88,7 @@ static inline void hpet_clear_mapping(void)
 /*
  * HPET command line enable / disable
  */
-static int boot_hpet_disable;
+int boot_hpet_disable;
 int hpet_force_user;
 static int hpet_verbose;
 
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[tip:x86/urgent] x86/hpet: Make boot_hpet_disable extern

2014-05-08 Thread tip-bot for Feng Tang
Commit-ID:  f10f383d8414bfe3357e24432ed8a26eeb58ffb8
Gitweb: http://git.kernel.org/tip/f10f383d8414bfe3357e24432ed8a26eeb58ffb8
Author: Feng Tang feng.t...@intel.com
AuthorDate: Thu, 24 Apr 2014 16:18:17 +0800
Committer:  Ingo Molnar mi...@kernel.org
CommitDate: Thu, 8 May 2014 08:15:34 +0200

x86/hpet: Make boot_hpet_disable extern

HPET on some platform has accuracy problem. Making
boot_hpet_disable extern so that we can runtime disable
the HPET timer by using quirk to check the platform.

Signed-off-by: Feng Tang feng.t...@intel.com
Cc: Clemens Ladisch clem...@ladisch.de
Cc: John Stultz john.stu...@linaro.org
Cc: Linus Torvalds torva...@linux-foundation.org
Link: 
http://lkml.kernel.org/r/1398327498-13163-1-git-send-email-feng.t...@intel.com
Signed-off-by: Ingo Molnar mi...@kernel.org
---
 arch/x86/include/asm/hpet.h | 1 +
 arch/x86/kernel/hpet.c  | 2 +-
 2 files changed, 2 insertions(+), 1 deletion(-)

diff --git a/arch/x86/include/asm/hpet.h b/arch/x86/include/asm/hpet.h
index b18df57..36f7125 100644
--- a/arch/x86/include/asm/hpet.h
+++ b/arch/x86/include/asm/hpet.h
@@ -63,6 +63,7 @@
 /* hpet memory map physical address */
 extern unsigned long hpet_address;
 extern unsigned long force_hpet_address;
+extern int boot_hpet_disable;
 extern u8 hpet_blockid;
 extern int hpet_force_user;
 extern u8 hpet_msi_disable;
diff --git a/arch/x86/kernel/hpet.c b/arch/x86/kernel/hpet.c
index 8d80ae0..4177bfb 100644
--- a/arch/x86/kernel/hpet.c
+++ b/arch/x86/kernel/hpet.c
@@ -88,7 +88,7 @@ static inline void hpet_clear_mapping(void)
 /*
  * HPET command line enable / disable
  */
-static int boot_hpet_disable;
+int boot_hpet_disable;
 int hpet_force_user;
 static int hpet_verbose;
 
--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[tip:x86/urgent] x86/intel: Add quirk to disable HPET for the Baytrail platform

2014-05-08 Thread tip-bot for Feng Tang
Commit-ID:  62187910b0fc7a75cfec9c30fda58ce2f39d689b
Gitweb: http://git.kernel.org/tip/62187910b0fc7a75cfec9c30fda58ce2f39d689b
Author: Feng Tang feng.t...@intel.com
AuthorDate: Thu, 24 Apr 2014 16:18:18 +0800
Committer:  Ingo Molnar mi...@kernel.org
CommitDate: Thu, 8 May 2014 08:15:34 +0200

x86/intel: Add quirk to disable HPET for the Baytrail platform

HPET on current Baytrail platform has accuracy problem to be
used as reliable clocksource/clockevent, so add a early quirk to
disable it.

Signed-off-by: Feng Tang feng.t...@intel.com
Cc: Clemens Ladisch clem...@ladisch.de
Cc: John Stultz john.stu...@linaro.org
Cc: Linus Torvalds torva...@linux-foundation.org
Link: 
http://lkml.kernel.org/r/1398327498-13163-2-git-send-email-feng.t...@intel.com
Signed-off-by: Ingo Molnar mi...@kernel.org
---
 arch/x86/kernel/early-quirks.c | 16 
 1 file changed, 16 insertions(+)

diff --git a/arch/x86/kernel/early-quirks.c b/arch/x86/kernel/early-quirks.c
index 6e2537c..6cda0ba 100644
--- a/arch/x86/kernel/early-quirks.c
+++ b/arch/x86/kernel/early-quirks.c
@@ -17,6 +17,7 @@
 #include asm/dma.h
 #include asm/io_apic.h
 #include asm/apic.h
+#include asm/hpet.h
 #include asm/iommu.h
 #include asm/gart.h
 #include asm/irq_remapping.h
@@ -530,6 +531,15 @@ static void __init intel_graphics_stolen(int num, int 
slot, int func)
}
 }
 
+static void __init force_disable_hpet(int num, int slot, int func)
+{
+#ifdef CONFIG_HPET_TIMER
+   boot_hpet_disable = 1;
+   pr_info(x86/hpet: Will disable the HPET for this platform because it's 
not reliable\n);
+#endif
+}
+
+
 #define QFLAG_APPLY_ONCE   0x1
 #define QFLAG_APPLIED  0x2
 #define QFLAG_DONE (QFLAG_APPLY_ONCE|QFLAG_APPLIED)
@@ -567,6 +577,12 @@ static struct chipset early_qrk[] __initdata = {
  PCI_BASE_CLASS_BRIDGE, 0, intel_remapping_check },
{ PCI_VENDOR_ID_INTEL, PCI_ANY_ID, PCI_CLASS_DISPLAY_VGA, PCI_ANY_ID,
  QFLAG_APPLY_ONCE, intel_graphics_stolen },
+   /*
+* HPET on current version of Baytrail platform has accuracy
+* problems, disable it for now:
+*/
+   { PCI_VENDOR_ID_INTEL, 0x0f00,
+   PCI_CLASS_BRIDGE_HOST, PCI_ANY_ID, 0, force_disable_hpet},
{}
 };
 
--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[tip:perf/core] perf report: Enable the runtime switching of perf data file

2013-02-06 Thread tip-bot for Feng Tang
Commit-ID:  ad0de0971b7f7097bd9be1ab4ad2a64db500adbf
Gitweb: http://git.kernel.org/tip/ad0de0971b7f7097bd9be1ab4ad2a64db500adbf
Author: Feng Tang 
AuthorDate: Sun, 3 Feb 2013 14:38:21 +0800
Committer:  Arnaldo Carvalho de Melo 
CommitDate: Wed, 6 Feb 2013 18:09:25 -0300

perf report: Enable the runtime switching of perf data file

This is for tui browser only. This patch will check the returned key of
tui hists browser, if it's K_SWITH_INPUT_DATA, then recreate a session
for the new selected data file.

V2: Move the setup_brower() before the "repeat" jump point.

Signed-off-by: Feng Tang 
Cc: Andi Kleen 
Cc: Ingo Molnar 
Cc: Namhyung Kim 
Cc: Peter Zijlstra 
Link: 
http://lkml.kernel.org/r/1359873501-24541-2-git-send-email-feng.t...@intel.com
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/builtin-report.c | 38 +++---
 1 file changed, 27 insertions(+), 11 deletions(-)

diff --git a/tools/perf/builtin-report.c b/tools/perf/builtin-report.c
index 0d22187..91555d4 100644
--- a/tools/perf/builtin-report.c
+++ b/tools/perf/builtin-report.c
@@ -468,9 +468,17 @@ static int __cmd_report(struct perf_report *rep)
 
if (use_browser > 0) {
if (use_browser == 1) {
-   perf_evlist__tui_browse_hists(session->evlist, help,
- NULL,
- >header.env);
+   ret = perf_evlist__tui_browse_hists(session->evlist,
+   help,
+   NULL,
+   >header.env);
+   /*
+* Usually "ret" is the last pressed key, and we only
+* care if the key notifies us to switch data file.
+*/
+   if (ret != K_SWITCH_INPUT_DATA)
+   ret = 0;
+
} else if (use_browser == 2) {
perf_evlist__gtk_browse_hists(session->evlist, help,
  NULL);
@@ -708,6 +716,16 @@ int cmd_report(int argc, const char **argv, const char 
*prefix __maybe_unused)
else
input_name = "perf.data";
}
+
+   if (strcmp(input_name, "-") != 0)
+   setup_browser(true);
+   else {
+   use_browser = 0;
+   perf_hpp__column_enable(PERF_HPP__OVERHEAD);
+   perf_hpp__init();
+   }
+
+repeat:
session = perf_session__new(input_name, O_RDONLY,
report.force, false, );
if (session == NULL)
@@ -733,14 +751,6 @@ int cmd_report(int argc, const char **argv, const char 
*prefix __maybe_unused)
 
}
 
-   if (strcmp(input_name, "-") != 0)
-   setup_browser(true);
-   else {
-   use_browser = 0;
-   perf_hpp__column_enable(PERF_HPP__OVERHEAD);
-   perf_hpp__init();
-   }
-
setup_sorting(report_usage, options);
 
/*
@@ -809,6 +819,12 @@ int cmd_report(int argc, const char **argv, const char 
*prefix __maybe_unused)
}
 
ret = __cmd_report();
+   if (ret == K_SWITCH_INPUT_DATA) {
+   perf_session__delete(session);
+   goto repeat;
+   } else
+   ret = 0;
+
 error:
perf_session__delete(session);
return ret;
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[tip:perf/core] perf hists browser: Add option for runtime switching perf data file

2013-02-06 Thread tip-bot for Feng Tang
Commit-ID:  341487ab561f3937a5283dd77c5660b1ee3b1f9e
Gitweb: http://git.kernel.org/tip/341487ab561f3937a5283dd77c5660b1ee3b1f9e
Author: Feng Tang 
AuthorDate: Sun, 3 Feb 2013 14:38:20 +0800
Committer:  Arnaldo Carvalho de Melo 
CommitDate: Wed, 6 Feb 2013 18:09:24 -0300

perf hists browser: Add option for runtime switching perf data file

Based on perf report/top/scripts browser integration idea from acme.

This will enable user to runtime switch the data file, when this option
is selected, it will popup all the legal data files in current working
directory, and the filename selected by user is saved in the global
variable "input_name", and a new key 'K_SWITCH_INPUT_DATA' will be
passed back to the built-in command which will perform the switch.

This initial version only enables it for 'perf report'.

v2: rebase to latest 'perf/core' branch (6e1d4dd) of acme's perf tree

Signed-off-by: Feng Tang 
Cc: Andi Kleen 
Cc: Ingo Molnar 
Cc: Namhyung Kim 
Cc: Peter Zijlstra 
Link: 
http://lkml.kernel.org/r/1359873501-24541-1-git-send-email-feng.t...@intel.com
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/ui/browsers/hists.c | 112 -
 tools/perf/ui/keysyms.h|   1 +
 2 files changed, 112 insertions(+), 1 deletion(-)

diff --git a/tools/perf/ui/browsers/hists.c b/tools/perf/ui/browsers/hists.c
index 20ccd57..aa22704 100644
--- a/tools/perf/ui/browsers/hists.c
+++ b/tools/perf/ui/browsers/hists.c
@@ -1241,6 +1241,96 @@ static inline bool is_report_browser(void *timer)
return timer == NULL;
 }
 
+/*
+ * Only runtime switching of perf data file will make "input_name" point
+ * to a malloced buffer. So add "is_input_name_malloced" flag to decide
+ * whether we need to call free() for current "input_name" during the switch.
+ */
+static bool is_input_name_malloced = false;
+
+static int switch_data_file(void)
+{
+   char *pwd, *options[32], *abs_path[32], *tmp;
+   DIR *pwd_dir;
+   int nr_options = 0, choice = -1, ret = -1;
+   struct dirent *dent;
+
+   pwd = getenv("PWD");
+   if (!pwd)
+   return ret;
+
+   pwd_dir = opendir(pwd);
+   if (!pwd_dir)
+   return ret;
+
+   memset(options, 0, sizeof(options));
+   memset(options, 0, sizeof(abs_path));
+
+   while ((dent = readdir(pwd_dir))) {
+   char path[PATH_MAX];
+   u64 magic;
+   char *name = dent->d_name;
+   FILE *file;
+
+   if (!(dent->d_type == DT_REG))
+   continue;
+
+   snprintf(path, sizeof(path), "%s/%s", pwd, name);
+
+   file = fopen(path, "r");
+   if (!file)
+   continue;
+
+   if (fread(, 1, 8, file) < 8)
+   goto close_file_and_continue;
+
+   if (is_perf_magic(magic)) {
+   options[nr_options] = strdup(name);
+   if (!options[nr_options])
+   goto close_file_and_continue;
+
+   abs_path[nr_options] = strdup(path);
+   if (!abs_path[nr_options]) {
+   free(options[nr_options]);
+   ui__warning("Can't search all data files due to 
memory shortage.\n");
+   fclose(file);
+   break;
+   }
+
+   nr_options++;
+   }
+
+close_file_and_continue:
+   fclose(file);
+   if (nr_options >= 32) {
+   ui__warning("Too many perf data files in PWD!\n"
+   "Only the first 32 files will be 
listed.\n");
+   break;
+   }
+   }
+   closedir(pwd_dir);
+
+   if (nr_options) {
+   choice = ui__popup_menu(nr_options, options);
+   if (choice < nr_options && choice >= 0) {
+   tmp = strdup(abs_path[choice]);
+   if (tmp) {
+   if (is_input_name_malloced)
+   free((void *)input_name);
+   input_name = tmp;
+   is_input_name_malloced = true;
+   ret = 0;
+   } else
+   ui__warning("Data switch failed due to memory 
shortage!\n");
+   }
+   }
+
+   free_popup_options(options, nr_options);
+   free_popup_options(abs_path, nr_options);
+   return ret;
+}
+
+
 static int perf_evsel__hists_browse(struct perf_evsel *evsel, int nr_events,
const char *helpline, const char *ev_name,
bool left_exits,
@@ -1275,7 +1365,8 @@ static int perf_evsel__hists_browse(struct perf_evsel 
*evsel, int nr_events,
int choice = 0,
   

[tip:perf/core] perf hists browser: Add option for runtime switching perf data file

2013-02-06 Thread tip-bot for Feng Tang
Commit-ID:  341487ab561f3937a5283dd77c5660b1ee3b1f9e
Gitweb: http://git.kernel.org/tip/341487ab561f3937a5283dd77c5660b1ee3b1f9e
Author: Feng Tang feng.t...@intel.com
AuthorDate: Sun, 3 Feb 2013 14:38:20 +0800
Committer:  Arnaldo Carvalho de Melo a...@redhat.com
CommitDate: Wed, 6 Feb 2013 18:09:24 -0300

perf hists browser: Add option for runtime switching perf data file

Based on perf report/top/scripts browser integration idea from acme.

This will enable user to runtime switch the data file, when this option
is selected, it will popup all the legal data files in current working
directory, and the filename selected by user is saved in the global
variable input_name, and a new key 'K_SWITCH_INPUT_DATA' will be
passed back to the built-in command which will perform the switch.

This initial version only enables it for 'perf report'.

v2: rebase to latest 'perf/core' branch (6e1d4dd) of acme's perf tree

Signed-off-by: Feng Tang feng.t...@intel.com
Cc: Andi Kleen a...@firstfloor.org
Cc: Ingo Molnar mi...@elte.hu
Cc: Namhyung Kim namhy...@kernel.org
Cc: Peter Zijlstra pet...@infradead.org
Link: 
http://lkml.kernel.org/r/1359873501-24541-1-git-send-email-feng.t...@intel.com
Signed-off-by: Arnaldo Carvalho de Melo a...@redhat.com
---
 tools/perf/ui/browsers/hists.c | 112 -
 tools/perf/ui/keysyms.h|   1 +
 2 files changed, 112 insertions(+), 1 deletion(-)

diff --git a/tools/perf/ui/browsers/hists.c b/tools/perf/ui/browsers/hists.c
index 20ccd57..aa22704 100644
--- a/tools/perf/ui/browsers/hists.c
+++ b/tools/perf/ui/browsers/hists.c
@@ -1241,6 +1241,96 @@ static inline bool is_report_browser(void *timer)
return timer == NULL;
 }
 
+/*
+ * Only runtime switching of perf data file will make input_name point
+ * to a malloced buffer. So add is_input_name_malloced flag to decide
+ * whether we need to call free() for current input_name during the switch.
+ */
+static bool is_input_name_malloced = false;
+
+static int switch_data_file(void)
+{
+   char *pwd, *options[32], *abs_path[32], *tmp;
+   DIR *pwd_dir;
+   int nr_options = 0, choice = -1, ret = -1;
+   struct dirent *dent;
+
+   pwd = getenv(PWD);
+   if (!pwd)
+   return ret;
+
+   pwd_dir = opendir(pwd);
+   if (!pwd_dir)
+   return ret;
+
+   memset(options, 0, sizeof(options));
+   memset(options, 0, sizeof(abs_path));
+
+   while ((dent = readdir(pwd_dir))) {
+   char path[PATH_MAX];
+   u64 magic;
+   char *name = dent-d_name;
+   FILE *file;
+
+   if (!(dent-d_type == DT_REG))
+   continue;
+
+   snprintf(path, sizeof(path), %s/%s, pwd, name);
+
+   file = fopen(path, r);
+   if (!file)
+   continue;
+
+   if (fread(magic, 1, 8, file)  8)
+   goto close_file_and_continue;
+
+   if (is_perf_magic(magic)) {
+   options[nr_options] = strdup(name);
+   if (!options[nr_options])
+   goto close_file_and_continue;
+
+   abs_path[nr_options] = strdup(path);
+   if (!abs_path[nr_options]) {
+   free(options[nr_options]);
+   ui__warning(Can't search all data files due to 
memory shortage.\n);
+   fclose(file);
+   break;
+   }
+
+   nr_options++;
+   }
+
+close_file_and_continue:
+   fclose(file);
+   if (nr_options = 32) {
+   ui__warning(Too many perf data files in PWD!\n
+   Only the first 32 files will be 
listed.\n);
+   break;
+   }
+   }
+   closedir(pwd_dir);
+
+   if (nr_options) {
+   choice = ui__popup_menu(nr_options, options);
+   if (choice  nr_options  choice = 0) {
+   tmp = strdup(abs_path[choice]);
+   if (tmp) {
+   if (is_input_name_malloced)
+   free((void *)input_name);
+   input_name = tmp;
+   is_input_name_malloced = true;
+   ret = 0;
+   } else
+   ui__warning(Data switch failed due to memory 
shortage!\n);
+   }
+   }
+
+   free_popup_options(options, nr_options);
+   free_popup_options(abs_path, nr_options);
+   return ret;
+}
+
+
 static int perf_evsel__hists_browse(struct perf_evsel *evsel, int nr_events,
const char *helpline, const char *ev_name,
bool left_exits,
@@ -1275,7 +1365,8 

[tip:perf/core] perf report: Enable the runtime switching of perf data file

2013-02-06 Thread tip-bot for Feng Tang
Commit-ID:  ad0de0971b7f7097bd9be1ab4ad2a64db500adbf
Gitweb: http://git.kernel.org/tip/ad0de0971b7f7097bd9be1ab4ad2a64db500adbf
Author: Feng Tang feng.t...@intel.com
AuthorDate: Sun, 3 Feb 2013 14:38:21 +0800
Committer:  Arnaldo Carvalho de Melo a...@redhat.com
CommitDate: Wed, 6 Feb 2013 18:09:25 -0300

perf report: Enable the runtime switching of perf data file

This is for tui browser only. This patch will check the returned key of
tui hists browser, if it's K_SWITH_INPUT_DATA, then recreate a session
for the new selected data file.

V2: Move the setup_brower() before the repeat jump point.

Signed-off-by: Feng Tang feng.t...@intel.com
Cc: Andi Kleen a...@firstfloor.org
Cc: Ingo Molnar mi...@elte.hu
Cc: Namhyung Kim namhy...@kernel.org
Cc: Peter Zijlstra pet...@infradead.org
Link: 
http://lkml.kernel.org/r/1359873501-24541-2-git-send-email-feng.t...@intel.com
Signed-off-by: Arnaldo Carvalho de Melo a...@redhat.com
---
 tools/perf/builtin-report.c | 38 +++---
 1 file changed, 27 insertions(+), 11 deletions(-)

diff --git a/tools/perf/builtin-report.c b/tools/perf/builtin-report.c
index 0d22187..91555d4 100644
--- a/tools/perf/builtin-report.c
+++ b/tools/perf/builtin-report.c
@@ -468,9 +468,17 @@ static int __cmd_report(struct perf_report *rep)
 
if (use_browser  0) {
if (use_browser == 1) {
-   perf_evlist__tui_browse_hists(session-evlist, help,
- NULL,
- session-header.env);
+   ret = perf_evlist__tui_browse_hists(session-evlist,
+   help,
+   NULL,
+   session-header.env);
+   /*
+* Usually ret is the last pressed key, and we only
+* care if the key notifies us to switch data file.
+*/
+   if (ret != K_SWITCH_INPUT_DATA)
+   ret = 0;
+
} else if (use_browser == 2) {
perf_evlist__gtk_browse_hists(session-evlist, help,
  NULL);
@@ -708,6 +716,16 @@ int cmd_report(int argc, const char **argv, const char 
*prefix __maybe_unused)
else
input_name = perf.data;
}
+
+   if (strcmp(input_name, -) != 0)
+   setup_browser(true);
+   else {
+   use_browser = 0;
+   perf_hpp__column_enable(PERF_HPP__OVERHEAD);
+   perf_hpp__init();
+   }
+
+repeat:
session = perf_session__new(input_name, O_RDONLY,
report.force, false, report.tool);
if (session == NULL)
@@ -733,14 +751,6 @@ int cmd_report(int argc, const char **argv, const char 
*prefix __maybe_unused)
 
}
 
-   if (strcmp(input_name, -) != 0)
-   setup_browser(true);
-   else {
-   use_browser = 0;
-   perf_hpp__column_enable(PERF_HPP__OVERHEAD);
-   perf_hpp__init();
-   }
-
setup_sorting(report_usage, options);
 
/*
@@ -809,6 +819,12 @@ int cmd_report(int argc, const char **argv, const char 
*prefix __maybe_unused)
}
 
ret = __cmd_report(report);
+   if (ret == K_SWITCH_INPUT_DATA) {
+   perf_session__delete(session);
+   goto repeat;
+   } else
+   ret = 0;
+
 error:
perf_session__delete(session);
return ret;
--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[tip:perf/core] perf browser: Don't show scripts menu for ' perf top'

2012-11-13 Thread tip-bot for Feng Tang
Commit-ID:  c77d8d7030128e61e206658815b96a6befed9d06
Gitweb: http://git.kernel.org/tip/c77d8d7030128e61e206658815b96a6befed9d06
Author: Feng Tang 
AuthorDate: Thu, 1 Nov 2012 00:00:55 +0800
Committer:  Arnaldo Carvalho de Melo 
CommitDate: Wed, 31 Oct 2012 16:14:19 -0200

perf browser: Don't show scripts menu for 'perf top'

As 'perf top' has no data files to run scripts against. Also add a
is_report_browser() helper function to judge whether the running browser
is for 'perf report'.

Signed-off-by: Feng Tang 
Cc: Andi Kleen 
Cc: Ingo Molnar 
Cc: Namhyung Kim 
Cc: Peter Zijlstra 
Link: 
http://lkml.kernel.org/r/1351699257-5102-1-git-send-email-feng.t...@intel.com
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/ui/browsers/hists.c |   12 ++--
 1 files changed, 10 insertions(+), 2 deletions(-)

diff --git a/tools/perf/ui/browsers/hists.c b/tools/perf/ui/browsers/hists.c
index fe62284..082078a 100644
--- a/tools/perf/ui/browsers/hists.c
+++ b/tools/perf/ui/browsers/hists.c
@@ -1127,6 +1127,12 @@ static inline void free_popup_options(char **options, 
int n)
}
 }
 
+/* Check whether the browser is for 'top' or 'report' */
+static inline bool is_report_browser(void *timer)
+{
+   return timer == NULL;
+}
+
 static int perf_evsel__hists_browse(struct perf_evsel *evsel, int nr_events,
const char *helpline, const char *ev_name,
bool left_exits,
@@ -1214,7 +1220,9 @@ static int perf_evsel__hists_browse(struct perf_evsel 
*evsel, int nr_events,
}
continue;
case 'r':
-   goto do_scripts;
+   if (is_report_browser(timer))
+   goto do_scripts;
+   continue;
case K_F1:
case 'h':
case '?':
@@ -1233,7 +1241,7 @@ static int perf_evsel__hists_browse(struct perf_evsel 
*evsel, int nr_events,
"E Expand all callchains\n"
"d Zoom into current DSO\n"
"t Zoom into current 
Thread\n"
-   "r Run available scripts\n"
+   "r Run available 
scripts('perf report' only)\n"
"P Print histograms to 
perf.hist.N\n"
"V Verbose (DSO names in 
callchains, etc)\n"
"/ Filter symbol by name");
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[tip:perf/core] perf browser: Don't show scripts menu for ' perf top'

2012-11-13 Thread tip-bot for Feng Tang
Commit-ID:  c77d8d7030128e61e206658815b96a6befed9d06
Gitweb: http://git.kernel.org/tip/c77d8d7030128e61e206658815b96a6befed9d06
Author: Feng Tang feng.t...@intel.com
AuthorDate: Thu, 1 Nov 2012 00:00:55 +0800
Committer:  Arnaldo Carvalho de Melo a...@redhat.com
CommitDate: Wed, 31 Oct 2012 16:14:19 -0200

perf browser: Don't show scripts menu for 'perf top'

As 'perf top' has no data files to run scripts against. Also add a
is_report_browser() helper function to judge whether the running browser
is for 'perf report'.

Signed-off-by: Feng Tang feng.t...@intel.com
Cc: Andi Kleen a...@firstfloor.org
Cc: Ingo Molnar mi...@elte.hu
Cc: Namhyung Kim namhy...@kernel.org
Cc: Peter Zijlstra pet...@infradead.org
Link: 
http://lkml.kernel.org/r/1351699257-5102-1-git-send-email-feng.t...@intel.com
Signed-off-by: Arnaldo Carvalho de Melo a...@redhat.com
---
 tools/perf/ui/browsers/hists.c |   12 ++--
 1 files changed, 10 insertions(+), 2 deletions(-)

diff --git a/tools/perf/ui/browsers/hists.c b/tools/perf/ui/browsers/hists.c
index fe62284..082078a 100644
--- a/tools/perf/ui/browsers/hists.c
+++ b/tools/perf/ui/browsers/hists.c
@@ -1127,6 +1127,12 @@ static inline void free_popup_options(char **options, 
int n)
}
 }
 
+/* Check whether the browser is for 'top' or 'report' */
+static inline bool is_report_browser(void *timer)
+{
+   return timer == NULL;
+}
+
 static int perf_evsel__hists_browse(struct perf_evsel *evsel, int nr_events,
const char *helpline, const char *ev_name,
bool left_exits,
@@ -1214,7 +1220,9 @@ static int perf_evsel__hists_browse(struct perf_evsel 
*evsel, int nr_events,
}
continue;
case 'r':
-   goto do_scripts;
+   if (is_report_browser(timer))
+   goto do_scripts;
+   continue;
case K_F1:
case 'h':
case '?':
@@ -1233,7 +1241,7 @@ static int perf_evsel__hists_browse(struct perf_evsel 
*evsel, int nr_events,
E Expand all callchains\n
d Zoom into current DSO\n
t Zoom into current 
Thread\n
-   r Run available scripts\n
+   r Run available 
scripts('perf report' only)\n
P Print histograms to 
perf.hist.N\n
V Verbose (DSO names in 
callchains, etc)\n
/ Filter symbol by name);
--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[tip:perf/core] perf header: Add is_perf_magic() func

2012-10-30 Thread tip-bot for Feng Tang
Commit-ID:  e84ba4e26833991d1c1c15a592b1474ee2b6dfdb
Gitweb: http://git.kernel.org/tip/e84ba4e26833991d1c1c15a592b1474ee2b6dfdb
Author: Feng Tang 
AuthorDate: Tue, 30 Oct 2012 11:56:07 +0800
Committer:  Arnaldo Carvalho de Melo 
CommitDate: Mon, 29 Oct 2012 11:56:59 -0200

perf header: Add is_perf_magic() func

With this function, other modules can basically check whether a file is
a legal perf data file by checking its first 8 bytes against all
possible perf magic numbers.

Change the function name from check_perf_magic to more meaningful
is_perf_magic as suggested by acme.

Signed-off-by: Feng Tang 
Cc: Andi Kleen 
Cc: Ingo Molnar 
Cc: Namhyung Kim 
Cc: Peter Zijlstra 
Link: 
http://lkml.kernel.org/r/1351569369-26732-7-git-send-email-feng.t...@intel.com
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/util/header.c |   10 ++
 tools/perf/util/header.h |1 +
 2 files changed, 11 insertions(+), 0 deletions(-)

diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c
index 514ed1b..195a47a 100644
--- a/tools/perf/util/header.c
+++ b/tools/perf/util/header.c
@@ -2341,6 +2341,16 @@ static int try_all_pipe_abis(uint64_t hdr_sz, struct 
perf_header *ph)
return -1;
 }
 
+bool is_perf_magic(u64 magic)
+{
+   if (!memcmp(, __perf_magic1, sizeof(magic))
+   || magic == __perf_magic2
+   || magic == __perf_magic2_sw)
+   return true;
+
+   return false;
+}
+
 static int check_magic_endian(u64 magic, uint64_t hdr_sz,
  bool is_pipe, struct perf_header *ph)
 {
diff --git a/tools/perf/util/header.h b/tools/perf/util/header.h
index 879d215..5f1cd68 100644
--- a/tools/perf/util/header.h
+++ b/tools/perf/util/header.h
@@ -154,6 +154,7 @@ int perf_event__synthesize_build_id(struct perf_tool *tool,
 int perf_event__process_build_id(struct perf_tool *tool,
 union perf_event *event,
 struct perf_session *session);
+bool is_perf_magic(u64 magic);
 
 /*
  * arch specific callback
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[tip:perf/core] perf hists browser: Integrate script browser into main hists browser

2012-10-30 Thread tip-bot for Feng Tang
Commit-ID:  cdbab7c201ab38f7b8d248ebf289025381166526
Gitweb: http://git.kernel.org/tip/cdbab7c201ab38f7b8d248ebf289025381166526
Author: Feng Tang 
AuthorDate: Tue, 30 Oct 2012 11:56:06 +0800
Committer:  Arnaldo Carvalho de Melo 
CommitDate: Mon, 29 Oct 2012 11:56:19 -0200

perf hists browser: Integrate script browser into main hists browser

Integrate the script browser into "perf report" framework, users can use
function key 'r' or the drop down menu to list all perf scripts and
select one of them, just like they did for the annotation.

Signed-off-by: Feng Tang 
Cc: Andi Kleen 
Cc: Ingo Molnar 
Cc: Namhyung Kim 
Cc: Peter Zijlstra 
Link: 
http://lkml.kernel.org/r/1351569369-26732-6-git-send-email-feng.t...@intel.com
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/ui/browsers/hists.c |   38 ++
 1 files changed, 38 insertions(+), 0 deletions(-)

diff --git a/tools/perf/ui/browsers/hists.c b/tools/perf/ui/browsers/hists.c
index ef2f93c..fe62284 100644
--- a/tools/perf/ui/browsers/hists.c
+++ b/tools/perf/ui/browsers/hists.c
@@ -1141,6 +1141,7 @@ static int perf_evsel__hists_browse(struct perf_evsel 
*evsel, int nr_events,
int nr_options = 0;
int key = -1;
char buf[64];
+   char script_opt[64];
 
if (browser == NULL)
return -1;
@@ -1159,6 +1160,7 @@ static int perf_evsel__hists_browse(struct perf_evsel 
*evsel, int nr_events,
int choice = 0,
annotate = -2, zoom_dso = -2, zoom_thread = -2,
annotate_f = -2, annotate_t = -2, browse_map = -2;
+   int scripts_comm = -2, scripts_symbol = -2, scripts_all = -2;
 
nr_options = 0;
 
@@ -1211,6 +1213,8 @@ static int perf_evsel__hists_browse(struct perf_evsel 
*evsel, int nr_events,
hist_browser__reset(browser);
}
continue;
+   case 'r':
+   goto do_scripts;
case K_F1:
case 'h':
case '?':
@@ -1229,6 +1233,7 @@ static int perf_evsel__hists_browse(struct perf_evsel 
*evsel, int nr_events,
"E Expand all callchains\n"
"d Zoom into current DSO\n"
"t Zoom into current 
Thread\n"
+   "r Run available scripts\n"
"P Print histograms to 
perf.hist.N\n"
"V Verbose (DSO names in 
callchains, etc)\n"
"/ Filter symbol by name");
@@ -1317,6 +1322,25 @@ static int perf_evsel__hists_browse(struct perf_evsel 
*evsel, int nr_events,
browser->selection->map != NULL &&
asprintf([nr_options], "Browse map details") > 0)
browse_map = nr_options++;
+
+   /* perf script support */
+   if (browser->he_selection) {
+   struct symbol *sym;
+
+   if (asprintf([nr_options], "Run scripts for 
samples of thread [%s]",
+   browser->he_selection->thread->comm) > 0)
+   scripts_comm = nr_options++;
+
+   sym = browser->he_selection->ms.sym;
+   if (sym && sym->namelen &&
+   asprintf([nr_options], "Run scripts for 
samples of symbol [%s]",
+   sym->name) > 0)
+   scripts_symbol = nr_options++;
+   }
+
+   if (asprintf([nr_options], "Run scripts for all 
samples") > 0)
+   scripts_all = nr_options++;
+
 add_exit_option:
options[nr_options++] = (char *)"Exit";
 retry_popup_menu:
@@ -1411,6 +1435,20 @@ zoom_out_thread:
hists__filter_by_thread(hists);
hist_browser__reset(browser);
}
+   /* perf scripts support */
+   else if (choice == scripts_all || choice == scripts_comm ||
+   choice == scripts_symbol) {
+do_scripts:
+   memset(script_opt, 0, 64);
+
+   if (choice == scripts_comm)
+   sprintf(script_opt, " -c %s ", 
browser->he_selection->thread->comm);
+
+   if (choice == scripts_symbol)
+   sprintf(script_opt, " -S %s ", 
browser->he_selection->ms.sym->name);
+
+   script_browse(script_opt);
+   }
}
 out_free_stack:
pstack__delete(fstack);
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to 

[tip:perf/core] perf annotate browser: Integrate script browser into annotation browser

2012-10-30 Thread tip-bot for Feng Tang
Commit-ID:  79ee47faa77706f568f0329b7475c123b67a3b4a
Gitweb: http://git.kernel.org/tip/79ee47faa77706f568f0329b7475c123b67a3b4a
Author: Feng Tang 
AuthorDate: Tue, 30 Oct 2012 11:56:05 +0800
Committer:  Arnaldo Carvalho de Melo 
CommitDate: Mon, 29 Oct 2012 11:54:45 -0200

perf annotate browser: Integrate script browser into annotation browser

Integrate the script browser into annotation, users can press function
key 'r' to list all perf scripts and select one of them to run that
script, the output will be shown in a separate browser.

Signed-off-by: Feng Tang 
Cc: Andi Kleen 
Cc: Ingo Molnar 
Cc: Namhyung Kim 
Cc: Peter Zijlstra 
Link: 
http://lkml.kernel.org/r/1351569369-26732-5-git-send-email-feng.t...@intel.com
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/ui/browsers/annotate.c |6 ++
 1 files changed, 6 insertions(+), 0 deletions(-)

diff --git a/tools/perf/ui/browsers/annotate.c 
b/tools/perf/ui/browsers/annotate.c
index 8f8cd2d..28f8aab 100644
--- a/tools/perf/ui/browsers/annotate.c
+++ b/tools/perf/ui/browsers/annotate.c
@@ -676,8 +676,14 @@ static int annotate_browser__run(struct annotate_browser 
*browser, int evidx,
"o Toggle disassembler output/simplified view\n"
"s Toggle source code view\n"
"/ Search string\n"
+   "r Run available scripts\n"
"? Search previous string\n");
continue;
+   case 'r':
+   {
+   script_browse(NULL);
+   continue;
+   }
case 'H':
nd = browser->curr_hot;
break;
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[tip:perf/core] perf scripts browser: Add a browser for perf script

2012-10-30 Thread tip-bot for Feng Tang
Commit-ID:  66517826664fa910d4bc5f32a5abff6bcd8657c5
Gitweb: http://git.kernel.org/tip/66517826664fa910d4bc5f32a5abff6bcd8657c5
Author: Feng Tang 
AuthorDate: Tue, 30 Oct 2012 11:56:04 +0800
Committer:  Arnaldo Carvalho de Melo 
CommitDate: Mon, 29 Oct 2012 11:52:53 -0200

perf scripts browser: Add a browser for perf script

Create a script browser, so that user can check all the available
scripts for current perf data file and run them inside the main perf
report or annotation browsers, for all perf samples or for samples
belong to one thread/symbol.

Please be noted: current script browser is only for report use, and
doesn't cover the record phase, IOW it must run against one existing
perf data file.

The work flow is, users can use function key to list all the available
scripts for current perf data file in system and chose one, which will
be executed with popen("perf script -s xxx.xx",) and all the output
lines are put into one ui browser, pressing 'q' or left arrow key will
make it return to previous browser.

Signed-off-by: Feng Tang 
Cc: Andi Kleen 
Cc: Ingo Molnar 
Cc: Namhyung Kim 
Cc: Peter Zijlstra 
Link: 
http://lkml.kernel.org/r/1351569369-26732-4-git-send-email-feng.t...@intel.com
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/Makefile  |4 +
 tools/perf/ui/browsers/scripts.c |  189 ++
 tools/perf/util/hist.h   |7 ++
 3 files changed, 200 insertions(+), 0 deletions(-)

diff --git a/tools/perf/Makefile b/tools/perf/Makefile
index ec63d53..7e25f59 100644
--- a/tools/perf/Makefile
+++ b/tools/perf/Makefile
@@ -593,6 +593,7 @@ ifndef NO_NEWT
LIB_OBJS += $(OUTPUT)ui/browsers/annotate.o
LIB_OBJS += $(OUTPUT)ui/browsers/hists.o
LIB_OBJS += $(OUTPUT)ui/browsers/map.o
+   LIB_OBJS += $(OUTPUT)ui/browsers/scripts.o
LIB_OBJS += $(OUTPUT)ui/progress.o
LIB_OBJS += $(OUTPUT)ui/util.o
LIB_OBJS += $(OUTPUT)ui/tui/setup.o
@@ -909,6 +910,9 @@ $(OUTPUT)ui/browsers/hists.o: ui/browsers/hists.c 
$(OUTPUT)PERF-CFLAGS
 $(OUTPUT)ui/browsers/map.o: ui/browsers/map.c $(OUTPUT)PERF-CFLAGS
$(QUIET_CC)$(CC) -o $@ -c $(ALL_CFLAGS) -DENABLE_SLFUTURE_CONST $<
 
+$(OUTPUT)ui/browsers/scripts.o: ui/browsers/scripts.c $(OUTPUT)PERF-CFLAGS
+   $(QUIET_CC)$(CC) -o $@ -c $(ALL_CFLAGS) -DENABLE_SLFUTURE_CONST $<
+
 $(OUTPUT)util/rbtree.o: ../../lib/rbtree.c $(OUTPUT)PERF-CFLAGS
$(QUIET_CC)$(CC) -o $@ -c $(ALL_CFLAGS) -Wno-unused-parameter 
-DETC_PERFCONFIG='"$(ETC_PERFCONFIG_SQ)"' $<
 
diff --git a/tools/perf/ui/browsers/scripts.c b/tools/perf/ui/browsers/scripts.c
new file mode 100644
index 000..cbbd44b
--- /dev/null
+++ b/tools/perf/ui/browsers/scripts.c
@@ -0,0 +1,189 @@
+#include 
+#include 
+#include 
+#include 
+#include 
+#include "../../util/sort.h"
+#include "../../util/util.h"
+#include "../../util/hist.h"
+#include "../../util/debug.h"
+#include "../../util/symbol.h"
+#include "../browser.h"
+#include "../helpline.h"
+#include "../libslang.h"
+
+/* 2048 lines should be enough for a script output */
+#define MAX_LINES  2048
+
+/* 160 bytes for one output line */
+#define AVERAGE_LINE_LEN   160
+
+struct script_line {
+   struct list_head node;
+   char line[AVERAGE_LINE_LEN];
+};
+
+struct perf_script_browser {
+   struct ui_browser b;
+   struct list_head entries;
+   const char *script_name;
+   int nr_lines;
+};
+
+#define SCRIPT_NAMELEN 128
+#define SCRIPT_MAX_NO  64
+/*
+ * Usually the full path for a script is:
+ * /home/username/libexec/perf-core/scripts/python/xxx.py
+ * /home/username/libexec/perf-core/scripts/perl/xxx.pl
+ * So 256 should be long enough to contain the full path.
+ */
+#define SCRIPT_FULLPATH_LEN256
+
+/*
+ * When success, will copy the full path of the selected script
+ * into  the buffer pointed by script_name, and return 0.
+ * Return -1 on failure.
+ */
+static int list_scripts(char *script_name)
+{
+   char *buf, *names[SCRIPT_MAX_NO], *paths[SCRIPT_MAX_NO];
+   int i, num, choice, ret = -1;
+
+   /* Preset the script name to SCRIPT_NAMELEN */
+   buf = malloc(SCRIPT_MAX_NO * (SCRIPT_NAMELEN + SCRIPT_FULLPATH_LEN));
+   if (!buf)
+   return ret;
+
+   for (i = 0; i < SCRIPT_MAX_NO; i++) {
+   names[i] = buf + i * (SCRIPT_NAMELEN + SCRIPT_FULLPATH_LEN);
+   paths[i] = names[i] + SCRIPT_NAMELEN;
+   }
+
+   num = find_scripts(names, paths);
+   if (num > 0) {
+   choice = ui__popup_menu(num, names);
+   if (choice < num && choice >= 0) {
+   strcpy(script_name, paths[choice]);
+   ret = 0;
+   }
+   }
+
+   free(buf);
+   return ret;
+}
+
+static void script_browser__write(struct ui_browser *browser,
+  void *entry, int row)
+{
+   struct 

[tip:perf/core] perf script: Add more filter to find_scripts()

2012-10-30 Thread tip-bot for Feng Tang
Commit-ID:  49e639e256ea18fb92f609dd6be09883cd9d05aa
Gitweb: http://git.kernel.org/tip/49e639e256ea18fb92f609dd6be09883cd9d05aa
Author: Feng Tang 
AuthorDate: Tue, 30 Oct 2012 11:56:03 +0800
Committer:  Arnaldo Carvalho de Melo 
CommitDate: Mon, 29 Oct 2012 11:46:23 -0200

perf script: Add more filter to find_scripts()

As suggested by Arnaldo, many scripts have their own usages and need
capture specific events or tracepoints, so only those scripts whose
target events match the events in current perf data file should be
listed in the script browser menu.

This patch will add the event match checking, by opening "xxx-record"
script to cherry pick out all events name and comparing them with
those inside the perf data file.

Signed-off-by: Feng Tang 
Cc: Andi Kleen 
Cc: Ingo Molnar 
Cc: Namhyung Kim 
Cc: Peter Zijlstra 
Link: 
http://lkml.kernel.org/r/1351569369-26732-3-git-send-email-feng.t...@intel.com
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/builtin-script.c |   82 +--
 1 files changed, 79 insertions(+), 3 deletions(-)

diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c
index 7c6e4b2..b363e7b 100644
--- a/tools/perf/builtin-script.c
+++ b/tools/perf/builtin-script.c
@@ -1030,6 +1030,68 @@ static int list_available_scripts(const struct option 
*opt __maybe_unused,
 }
 
 /*
+ * Some scripts specify the required events in their "xxx-record" file,
+ * this function will check if the events in perf.data match those
+ * mentioned in the "xxx-record".
+ *
+ * Fixme: All existing "xxx-record" are all in good formats "-e event ",
+ * which is covered well now. And new parsing code should be added to
+ * cover the future complexing formats like event groups etc.
+ */
+static int check_ev_match(char *dir_name, char *scriptname,
+   struct perf_session *session)
+{
+   char filename[MAXPATHLEN], evname[128];
+   char line[BUFSIZ], *p;
+   struct perf_evsel *pos;
+   int match, len;
+   FILE *fp;
+
+   sprintf(filename, "%s/bin/%s-record", dir_name, scriptname);
+
+   fp = fopen(filename, "r");
+   if (!fp)
+   return -1;
+
+   while (fgets(line, sizeof(line), fp)) {
+   p = ltrim(line);
+   if (*p == '#')
+   continue;
+
+   while (strlen(p)) {
+   p = strstr(p, "-e");
+   if (!p)
+   break;
+
+   p += 2;
+   p = ltrim(p);
+   len = strcspn(p, " \t");
+   if (!len)
+   break;
+
+   snprintf(evname, len + 1, "%s", p);
+
+   match = 0;
+   list_for_each_entry(pos,
+   >evlist->entries, node) {
+   if (!strcmp(perf_evsel__name(pos), evname)) {
+   match = 1;
+   break;
+   }
+   }
+
+   if (!match) {
+   fclose(fp);
+   return -1;
+   }
+   }
+   }
+
+   fclose(fp);
+   return 0;
+}
+
+/*
  * Return -1 if none is found, otherwise the actual scripts number.
  *
  * Currently the only user of this function is the script browser, which
@@ -1039,17 +1101,23 @@ static int list_available_scripts(const struct option 
*opt __maybe_unused,
 int find_scripts(char **scripts_array, char **scripts_path_array)
 {
struct dirent *script_next, *lang_next, script_dirent, lang_dirent;
-   char scripts_path[MAXPATHLEN];
+   char scripts_path[MAXPATHLEN], lang_path[MAXPATHLEN];
DIR *scripts_dir, *lang_dir;
-   char lang_path[MAXPATHLEN];
+   struct perf_session *session;
char *temp;
int i = 0;
 
+   session = perf_session__new(input_name, O_RDONLY, 0, false, NULL);
+   if (!session)
+   return -1;
+
snprintf(scripts_path, MAXPATHLEN, "%s/scripts", perf_exec_path());
 
scripts_dir = opendir(scripts_path);
-   if (!scripts_dir)
+   if (!scripts_dir) {
+   perf_session__delete(session);
return -1;
+   }
 
for_each_lang(scripts_path, scripts_dir, lang_dirent, lang_next) {
snprintf(lang_path, MAXPATHLEN, "%s/%s", scripts_path,
@@ -1077,10 +1145,18 @@ int find_scripts(char **scripts_array, char 
**scripts_path_array)
snprintf(scripts_array[i],
(temp - script_dirent.d_name) + 1,
"%s", script_dirent.d_name);
+
+   if (check_ev_match(lang_path,
+   scripts_array[i], session))
+   continue;
+
   

[tip:perf/core] perf tools: Add a global variable " const char *input_name"

2012-10-30 Thread tip-bot for Feng Tang
Commit-ID:  70cb4e963f77dae90ae2aa3dd9385a43737c469f
Gitweb: http://git.kernel.org/tip/70cb4e963f77dae90ae2aa3dd9385a43737c469f
Author: Feng Tang 
AuthorDate: Tue, 30 Oct 2012 11:56:02 +0800
Committer:  Arnaldo Carvalho de Melo 
CommitDate: Mon, 29 Oct 2012 11:45:34 -0200

perf tools: Add a global variable "const char *input_name"

Currently many perf commands annotate/evlist/report/script/lock etc all
support "-i" option to chose a specific perf data, and all of them
create a local "input_name" to save the file name for that perf data.

Since most of these commands need it, we can add a global variable for
it, also it can some other benefits:

1. When calling script browser inside hists/annotation browser, it needs
to know the perf data file name to run that script.

2. For further feature like runtime switching to another perf data file,
this variable can also help.

Signed-off-by: Feng Tang 
Cc: Andi Kleen 
Cc: Ingo Molnar 
Cc: Namhyung Kim 
Cc: Peter Zijlstra 
Link: 
http://lkml.kernel.org/r/1351569369-26732-2-git-send-email-feng.t...@intel.com
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/builtin-annotate.c |5 ++---
 tools/perf/builtin-buildid-list.c |6 ++
 tools/perf/builtin-evlist.c   |5 ++---
 tools/perf/builtin-kmem.c |5 ++---
 tools/perf/builtin-lock.c |2 --
 tools/perf/builtin-report.c   |   13 ++---
 tools/perf/builtin-sched.c|5 ++---
 tools/perf/builtin-script.c   |1 -
 tools/perf/builtin-timechart.c|5 ++---
 tools/perf/perf.c |1 +
 tools/perf/perf.h |1 +
 11 files changed, 20 insertions(+), 29 deletions(-)

diff --git a/tools/perf/builtin-annotate.c b/tools/perf/builtin-annotate.c
index c4bb645..cb23476 100644
--- a/tools/perf/builtin-annotate.c
+++ b/tools/perf/builtin-annotate.c
@@ -34,7 +34,6 @@
 
 struct perf_annotate {
struct perf_tool tool;
-   char const *input_name;
bool   force, use_tui, use_stdio;
bool   full_paths;
bool   print_line;
@@ -175,7 +174,7 @@ static int __cmd_annotate(struct perf_annotate *ann)
struct perf_evsel *pos;
u64 total_nr_samples;
 
-   session = perf_session__new(ann->input_name, O_RDONLY,
+   session = perf_session__new(input_name, O_RDONLY,
ann->force, false, >tool);
if (session == NULL)
return -ENOMEM;
@@ -260,7 +259,7 @@ int cmd_annotate(int argc, const char **argv, const char 
*prefix __maybe_unused)
},
};
const struct option options[] = {
-   OPT_STRING('i', "input", _name, "file",
+   OPT_STRING('i', "input", _name, "file",
"input file name"),
OPT_STRING('d', "dsos", _conf.dso_list_str, "dso[,dso...]",
   "only consider symbols in these dsos"),
diff --git a/tools/perf/builtin-buildid-list.c 
b/tools/perf/builtin-buildid-list.c
index a0e94ff..a82d99f 100644
--- a/tools/perf/builtin-buildid-list.c
+++ b/tools/perf/builtin-buildid-list.c
@@ -44,8 +44,7 @@ static int filename__fprintf_build_id(const char *name, FILE 
*fp)
return fprintf(fp, "%s\n", sbuild_id);
 }
 
-static int perf_session__list_build_ids(const char *input_name,
-   bool force, bool with_hits)
+static int perf_session__list_build_ids(bool force, bool with_hits)
 {
struct perf_session *session;
 
@@ -81,7 +80,6 @@ int cmd_buildid_list(int argc, const char **argv,
bool show_kernel = false;
bool with_hits = false;
bool force = false;
-   const char *input_name = NULL;
const struct option options[] = {
OPT_BOOLEAN('H', "with-hits", _hits, "Show only DSOs with hits"),
OPT_STRING('i', "input", _name, "file", "input file name"),
@@ -101,5 +99,5 @@ int cmd_buildid_list(int argc, const char **argv,
if (show_kernel)
return sysfs__fprintf_build_id(stdout);
 
-   return perf_session__list_build_ids(input_name, force, with_hits);
+   return perf_session__list_build_ids(force, with_hits);
 }
diff --git a/tools/perf/builtin-evlist.c b/tools/perf/builtin-evlist.c
index 997afb8..c20f1dc 100644
--- a/tools/perf/builtin-evlist.c
+++ b/tools/perf/builtin-evlist.c
@@ -48,12 +48,12 @@ static int __if_print(bool *first, const char *field, u64 
value)
 
 #define if_print(field) __if_print(, #field, pos->attr.field)
 
-static int __cmd_evlist(const char *input_name, struct perf_attr_details 
*details)
+static int __cmd_evlist(const char *file_name, struct perf_attr_details 
*details)
 {
struct perf_session *session;
struct perf_evsel *pos;
 
-   session = perf_session__new(input_name, O_RDONLY, 0, false, NULL);
+   session = perf_session__new(file_name, O_RDONLY, 0, false, NULL);
if (session == NULL)
return -ENOMEM;
 
@@ -111,7 +111,6 @@ static int __cmd_evlist(const char 

[tip:perf/core] perf tools: Add a global variable const char *input_name

2012-10-30 Thread tip-bot for Feng Tang
Commit-ID:  70cb4e963f77dae90ae2aa3dd9385a43737c469f
Gitweb: http://git.kernel.org/tip/70cb4e963f77dae90ae2aa3dd9385a43737c469f
Author: Feng Tang feng.t...@intel.com
AuthorDate: Tue, 30 Oct 2012 11:56:02 +0800
Committer:  Arnaldo Carvalho de Melo a...@redhat.com
CommitDate: Mon, 29 Oct 2012 11:45:34 -0200

perf tools: Add a global variable const char *input_name

Currently many perf commands annotate/evlist/report/script/lock etc all
support -i option to chose a specific perf data, and all of them
create a local input_name to save the file name for that perf data.

Since most of these commands need it, we can add a global variable for
it, also it can some other benefits:

1. When calling script browser inside hists/annotation browser, it needs
to know the perf data file name to run that script.

2. For further feature like runtime switching to another perf data file,
this variable can also help.

Signed-off-by: Feng Tang feng.t...@intel.com
Cc: Andi Kleen a...@firstfloor.org
Cc: Ingo Molnar mi...@elte.hu
Cc: Namhyung Kim namhy...@kernel.org
Cc: Peter Zijlstra pet...@infradead.org
Link: 
http://lkml.kernel.org/r/1351569369-26732-2-git-send-email-feng.t...@intel.com
Signed-off-by: Arnaldo Carvalho de Melo a...@redhat.com
---
 tools/perf/builtin-annotate.c |5 ++---
 tools/perf/builtin-buildid-list.c |6 ++
 tools/perf/builtin-evlist.c   |5 ++---
 tools/perf/builtin-kmem.c |5 ++---
 tools/perf/builtin-lock.c |2 --
 tools/perf/builtin-report.c   |   13 ++---
 tools/perf/builtin-sched.c|5 ++---
 tools/perf/builtin-script.c   |1 -
 tools/perf/builtin-timechart.c|5 ++---
 tools/perf/perf.c |1 +
 tools/perf/perf.h |1 +
 11 files changed, 20 insertions(+), 29 deletions(-)

diff --git a/tools/perf/builtin-annotate.c b/tools/perf/builtin-annotate.c
index c4bb645..cb23476 100644
--- a/tools/perf/builtin-annotate.c
+++ b/tools/perf/builtin-annotate.c
@@ -34,7 +34,6 @@
 
 struct perf_annotate {
struct perf_tool tool;
-   char const *input_name;
bool   force, use_tui, use_stdio;
bool   full_paths;
bool   print_line;
@@ -175,7 +174,7 @@ static int __cmd_annotate(struct perf_annotate *ann)
struct perf_evsel *pos;
u64 total_nr_samples;
 
-   session = perf_session__new(ann-input_name, O_RDONLY,
+   session = perf_session__new(input_name, O_RDONLY,
ann-force, false, ann-tool);
if (session == NULL)
return -ENOMEM;
@@ -260,7 +259,7 @@ int cmd_annotate(int argc, const char **argv, const char 
*prefix __maybe_unused)
},
};
const struct option options[] = {
-   OPT_STRING('i', input, annotate.input_name, file,
+   OPT_STRING('i', input, input_name, file,
input file name),
OPT_STRING('d', dsos, symbol_conf.dso_list_str, dso[,dso...],
   only consider symbols in these dsos),
diff --git a/tools/perf/builtin-buildid-list.c 
b/tools/perf/builtin-buildid-list.c
index a0e94ff..a82d99f 100644
--- a/tools/perf/builtin-buildid-list.c
+++ b/tools/perf/builtin-buildid-list.c
@@ -44,8 +44,7 @@ static int filename__fprintf_build_id(const char *name, FILE 
*fp)
return fprintf(fp, %s\n, sbuild_id);
 }
 
-static int perf_session__list_build_ids(const char *input_name,
-   bool force, bool with_hits)
+static int perf_session__list_build_ids(bool force, bool with_hits)
 {
struct perf_session *session;
 
@@ -81,7 +80,6 @@ int cmd_buildid_list(int argc, const char **argv,
bool show_kernel = false;
bool with_hits = false;
bool force = false;
-   const char *input_name = NULL;
const struct option options[] = {
OPT_BOOLEAN('H', with-hits, with_hits, Show only DSOs with hits),
OPT_STRING('i', input, input_name, file, input file name),
@@ -101,5 +99,5 @@ int cmd_buildid_list(int argc, const char **argv,
if (show_kernel)
return sysfs__fprintf_build_id(stdout);
 
-   return perf_session__list_build_ids(input_name, force, with_hits);
+   return perf_session__list_build_ids(force, with_hits);
 }
diff --git a/tools/perf/builtin-evlist.c b/tools/perf/builtin-evlist.c
index 997afb8..c20f1dc 100644
--- a/tools/perf/builtin-evlist.c
+++ b/tools/perf/builtin-evlist.c
@@ -48,12 +48,12 @@ static int __if_print(bool *first, const char *field, u64 
value)
 
 #define if_print(field) __if_print(first, #field, pos-attr.field)
 
-static int __cmd_evlist(const char *input_name, struct perf_attr_details 
*details)
+static int __cmd_evlist(const char *file_name, struct perf_attr_details 
*details)
 {
struct perf_session *session;
struct perf_evsel *pos;
 
-   session = perf_session__new(input_name, O_RDONLY, 0, false, NULL);
+   session = perf_session__new(file_name, 

[tip:perf/core] perf script: Add more filter to find_scripts()

2012-10-30 Thread tip-bot for Feng Tang
Commit-ID:  49e639e256ea18fb92f609dd6be09883cd9d05aa
Gitweb: http://git.kernel.org/tip/49e639e256ea18fb92f609dd6be09883cd9d05aa
Author: Feng Tang feng.t...@intel.com
AuthorDate: Tue, 30 Oct 2012 11:56:03 +0800
Committer:  Arnaldo Carvalho de Melo a...@redhat.com
CommitDate: Mon, 29 Oct 2012 11:46:23 -0200

perf script: Add more filter to find_scripts()

As suggested by Arnaldo, many scripts have their own usages and need
capture specific events or tracepoints, so only those scripts whose
target events match the events in current perf data file should be
listed in the script browser menu.

This patch will add the event match checking, by opening xxx-record
script to cherry pick out all events name and comparing them with
those inside the perf data file.

Signed-off-by: Feng Tang feng.t...@intel.com
Cc: Andi Kleen a...@firstfloor.org
Cc: Ingo Molnar mi...@elte.hu
Cc: Namhyung Kim namhy...@kernel.org
Cc: Peter Zijlstra pet...@infradead.org
Link: 
http://lkml.kernel.org/r/1351569369-26732-3-git-send-email-feng.t...@intel.com
Signed-off-by: Arnaldo Carvalho de Melo a...@redhat.com
---
 tools/perf/builtin-script.c |   82 +--
 1 files changed, 79 insertions(+), 3 deletions(-)

diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c
index 7c6e4b2..b363e7b 100644
--- a/tools/perf/builtin-script.c
+++ b/tools/perf/builtin-script.c
@@ -1030,6 +1030,68 @@ static int list_available_scripts(const struct option 
*opt __maybe_unused,
 }
 
 /*
+ * Some scripts specify the required events in their xxx-record file,
+ * this function will check if the events in perf.data match those
+ * mentioned in the xxx-record.
+ *
+ * Fixme: All existing xxx-record are all in good formats -e event ,
+ * which is covered well now. And new parsing code should be added to
+ * cover the future complexing formats like event groups etc.
+ */
+static int check_ev_match(char *dir_name, char *scriptname,
+   struct perf_session *session)
+{
+   char filename[MAXPATHLEN], evname[128];
+   char line[BUFSIZ], *p;
+   struct perf_evsel *pos;
+   int match, len;
+   FILE *fp;
+
+   sprintf(filename, %s/bin/%s-record, dir_name, scriptname);
+
+   fp = fopen(filename, r);
+   if (!fp)
+   return -1;
+
+   while (fgets(line, sizeof(line), fp)) {
+   p = ltrim(line);
+   if (*p == '#')
+   continue;
+
+   while (strlen(p)) {
+   p = strstr(p, -e);
+   if (!p)
+   break;
+
+   p += 2;
+   p = ltrim(p);
+   len = strcspn(p,  \t);
+   if (!len)
+   break;
+
+   snprintf(evname, len + 1, %s, p);
+
+   match = 0;
+   list_for_each_entry(pos,
+   session-evlist-entries, node) {
+   if (!strcmp(perf_evsel__name(pos), evname)) {
+   match = 1;
+   break;
+   }
+   }
+
+   if (!match) {
+   fclose(fp);
+   return -1;
+   }
+   }
+   }
+
+   fclose(fp);
+   return 0;
+}
+
+/*
  * Return -1 if none is found, otherwise the actual scripts number.
  *
  * Currently the only user of this function is the script browser, which
@@ -1039,17 +1101,23 @@ static int list_available_scripts(const struct option 
*opt __maybe_unused,
 int find_scripts(char **scripts_array, char **scripts_path_array)
 {
struct dirent *script_next, *lang_next, script_dirent, lang_dirent;
-   char scripts_path[MAXPATHLEN];
+   char scripts_path[MAXPATHLEN], lang_path[MAXPATHLEN];
DIR *scripts_dir, *lang_dir;
-   char lang_path[MAXPATHLEN];
+   struct perf_session *session;
char *temp;
int i = 0;
 
+   session = perf_session__new(input_name, O_RDONLY, 0, false, NULL);
+   if (!session)
+   return -1;
+
snprintf(scripts_path, MAXPATHLEN, %s/scripts, perf_exec_path());
 
scripts_dir = opendir(scripts_path);
-   if (!scripts_dir)
+   if (!scripts_dir) {
+   perf_session__delete(session);
return -1;
+   }
 
for_each_lang(scripts_path, scripts_dir, lang_dirent, lang_next) {
snprintf(lang_path, MAXPATHLEN, %s/%s, scripts_path,
@@ -1077,10 +1145,18 @@ int find_scripts(char **scripts_array, char 
**scripts_path_array)
snprintf(scripts_array[i],
(temp - script_dirent.d_name) + 1,
%s, script_dirent.d_name);
+
+   if (check_ev_match(lang_path,
+   

[tip:perf/core] perf scripts browser: Add a browser for perf script

2012-10-30 Thread tip-bot for Feng Tang
Commit-ID:  66517826664fa910d4bc5f32a5abff6bcd8657c5
Gitweb: http://git.kernel.org/tip/66517826664fa910d4bc5f32a5abff6bcd8657c5
Author: Feng Tang feng.t...@intel.com
AuthorDate: Tue, 30 Oct 2012 11:56:04 +0800
Committer:  Arnaldo Carvalho de Melo a...@redhat.com
CommitDate: Mon, 29 Oct 2012 11:52:53 -0200

perf scripts browser: Add a browser for perf script

Create a script browser, so that user can check all the available
scripts for current perf data file and run them inside the main perf
report or annotation browsers, for all perf samples or for samples
belong to one thread/symbol.

Please be noted: current script browser is only for report use, and
doesn't cover the record phase, IOW it must run against one existing
perf data file.

The work flow is, users can use function key to list all the available
scripts for current perf data file in system and chose one, which will
be executed with popen(perf script -s xxx.xx,) and all the output
lines are put into one ui browser, pressing 'q' or left arrow key will
make it return to previous browser.

Signed-off-by: Feng Tang feng.t...@intel.com
Cc: Andi Kleen a...@firstfloor.org
Cc: Ingo Molnar mi...@elte.hu
Cc: Namhyung Kim namhy...@kernel.org
Cc: Peter Zijlstra pet...@infradead.org
Link: 
http://lkml.kernel.org/r/1351569369-26732-4-git-send-email-feng.t...@intel.com
Signed-off-by: Arnaldo Carvalho de Melo a...@redhat.com
---
 tools/perf/Makefile  |4 +
 tools/perf/ui/browsers/scripts.c |  189 ++
 tools/perf/util/hist.h   |7 ++
 3 files changed, 200 insertions(+), 0 deletions(-)

diff --git a/tools/perf/Makefile b/tools/perf/Makefile
index ec63d53..7e25f59 100644
--- a/tools/perf/Makefile
+++ b/tools/perf/Makefile
@@ -593,6 +593,7 @@ ifndef NO_NEWT
LIB_OBJS += $(OUTPUT)ui/browsers/annotate.o
LIB_OBJS += $(OUTPUT)ui/browsers/hists.o
LIB_OBJS += $(OUTPUT)ui/browsers/map.o
+   LIB_OBJS += $(OUTPUT)ui/browsers/scripts.o
LIB_OBJS += $(OUTPUT)ui/progress.o
LIB_OBJS += $(OUTPUT)ui/util.o
LIB_OBJS += $(OUTPUT)ui/tui/setup.o
@@ -909,6 +910,9 @@ $(OUTPUT)ui/browsers/hists.o: ui/browsers/hists.c 
$(OUTPUT)PERF-CFLAGS
 $(OUTPUT)ui/browsers/map.o: ui/browsers/map.c $(OUTPUT)PERF-CFLAGS
$(QUIET_CC)$(CC) -o $@ -c $(ALL_CFLAGS) -DENABLE_SLFUTURE_CONST $
 
+$(OUTPUT)ui/browsers/scripts.o: ui/browsers/scripts.c $(OUTPUT)PERF-CFLAGS
+   $(QUIET_CC)$(CC) -o $@ -c $(ALL_CFLAGS) -DENABLE_SLFUTURE_CONST $
+
 $(OUTPUT)util/rbtree.o: ../../lib/rbtree.c $(OUTPUT)PERF-CFLAGS
$(QUIET_CC)$(CC) -o $@ -c $(ALL_CFLAGS) -Wno-unused-parameter 
-DETC_PERFCONFIG='$(ETC_PERFCONFIG_SQ)' $
 
diff --git a/tools/perf/ui/browsers/scripts.c b/tools/perf/ui/browsers/scripts.c
new file mode 100644
index 000..cbbd44b
--- /dev/null
+++ b/tools/perf/ui/browsers/scripts.c
@@ -0,0 +1,189 @@
+#include elf.h
+#include newt.h
+#include inttypes.h
+#include sys/ttydefaults.h
+#include string.h
+#include ../../util/sort.h
+#include ../../util/util.h
+#include ../../util/hist.h
+#include ../../util/debug.h
+#include ../../util/symbol.h
+#include ../browser.h
+#include ../helpline.h
+#include ../libslang.h
+
+/* 2048 lines should be enough for a script output */
+#define MAX_LINES  2048
+
+/* 160 bytes for one output line */
+#define AVERAGE_LINE_LEN   160
+
+struct script_line {
+   struct list_head node;
+   char line[AVERAGE_LINE_LEN];
+};
+
+struct perf_script_browser {
+   struct ui_browser b;
+   struct list_head entries;
+   const char *script_name;
+   int nr_lines;
+};
+
+#define SCRIPT_NAMELEN 128
+#define SCRIPT_MAX_NO  64
+/*
+ * Usually the full path for a script is:
+ * /home/username/libexec/perf-core/scripts/python/xxx.py
+ * /home/username/libexec/perf-core/scripts/perl/xxx.pl
+ * So 256 should be long enough to contain the full path.
+ */
+#define SCRIPT_FULLPATH_LEN256
+
+/*
+ * When success, will copy the full path of the selected script
+ * into  the buffer pointed by script_name, and return 0.
+ * Return -1 on failure.
+ */
+static int list_scripts(char *script_name)
+{
+   char *buf, *names[SCRIPT_MAX_NO], *paths[SCRIPT_MAX_NO];
+   int i, num, choice, ret = -1;
+
+   /* Preset the script name to SCRIPT_NAMELEN */
+   buf = malloc(SCRIPT_MAX_NO * (SCRIPT_NAMELEN + SCRIPT_FULLPATH_LEN));
+   if (!buf)
+   return ret;
+
+   for (i = 0; i  SCRIPT_MAX_NO; i++) {
+   names[i] = buf + i * (SCRIPT_NAMELEN + SCRIPT_FULLPATH_LEN);
+   paths[i] = names[i] + SCRIPT_NAMELEN;
+   }
+
+   num = find_scripts(names, paths);
+   if (num  0) {
+   choice = ui__popup_menu(num, names);
+   if (choice  num  choice = 0) {
+   strcpy(script_name, paths[choice]);
+   ret = 0;
+   }
+   }
+
+   free(buf);
+   

[tip:perf/core] perf annotate browser: Integrate script browser into annotation browser

2012-10-30 Thread tip-bot for Feng Tang
Commit-ID:  79ee47faa77706f568f0329b7475c123b67a3b4a
Gitweb: http://git.kernel.org/tip/79ee47faa77706f568f0329b7475c123b67a3b4a
Author: Feng Tang feng.t...@intel.com
AuthorDate: Tue, 30 Oct 2012 11:56:05 +0800
Committer:  Arnaldo Carvalho de Melo a...@redhat.com
CommitDate: Mon, 29 Oct 2012 11:54:45 -0200

perf annotate browser: Integrate script browser into annotation browser

Integrate the script browser into annotation, users can press function
key 'r' to list all perf scripts and select one of them to run that
script, the output will be shown in a separate browser.

Signed-off-by: Feng Tang feng.t...@intel.com
Cc: Andi Kleen a...@firstfloor.org
Cc: Ingo Molnar mi...@elte.hu
Cc: Namhyung Kim namhy...@kernel.org
Cc: Peter Zijlstra pet...@infradead.org
Link: 
http://lkml.kernel.org/r/1351569369-26732-5-git-send-email-feng.t...@intel.com
Signed-off-by: Arnaldo Carvalho de Melo a...@redhat.com
---
 tools/perf/ui/browsers/annotate.c |6 ++
 1 files changed, 6 insertions(+), 0 deletions(-)

diff --git a/tools/perf/ui/browsers/annotate.c 
b/tools/perf/ui/browsers/annotate.c
index 8f8cd2d..28f8aab 100644
--- a/tools/perf/ui/browsers/annotate.c
+++ b/tools/perf/ui/browsers/annotate.c
@@ -676,8 +676,14 @@ static int annotate_browser__run(struct annotate_browser 
*browser, int evidx,
o Toggle disassembler output/simplified view\n
s Toggle source code view\n
/ Search string\n
+   r Run available scripts\n
? Search previous string\n);
continue;
+   case 'r':
+   {
+   script_browse(NULL);
+   continue;
+   }
case 'H':
nd = browser-curr_hot;
break;
--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[tip:perf/core] perf hists browser: Integrate script browser into main hists browser

2012-10-30 Thread tip-bot for Feng Tang
Commit-ID:  cdbab7c201ab38f7b8d248ebf289025381166526
Gitweb: http://git.kernel.org/tip/cdbab7c201ab38f7b8d248ebf289025381166526
Author: Feng Tang feng.t...@intel.com
AuthorDate: Tue, 30 Oct 2012 11:56:06 +0800
Committer:  Arnaldo Carvalho de Melo a...@redhat.com
CommitDate: Mon, 29 Oct 2012 11:56:19 -0200

perf hists browser: Integrate script browser into main hists browser

Integrate the script browser into perf report framework, users can use
function key 'r' or the drop down menu to list all perf scripts and
select one of them, just like they did for the annotation.

Signed-off-by: Feng Tang feng.t...@intel.com
Cc: Andi Kleen a...@firstfloor.org
Cc: Ingo Molnar mi...@elte.hu
Cc: Namhyung Kim namhy...@kernel.org
Cc: Peter Zijlstra pet...@infradead.org
Link: 
http://lkml.kernel.org/r/1351569369-26732-6-git-send-email-feng.t...@intel.com
Signed-off-by: Arnaldo Carvalho de Melo a...@redhat.com
---
 tools/perf/ui/browsers/hists.c |   38 ++
 1 files changed, 38 insertions(+), 0 deletions(-)

diff --git a/tools/perf/ui/browsers/hists.c b/tools/perf/ui/browsers/hists.c
index ef2f93c..fe62284 100644
--- a/tools/perf/ui/browsers/hists.c
+++ b/tools/perf/ui/browsers/hists.c
@@ -1141,6 +1141,7 @@ static int perf_evsel__hists_browse(struct perf_evsel 
*evsel, int nr_events,
int nr_options = 0;
int key = -1;
char buf[64];
+   char script_opt[64];
 
if (browser == NULL)
return -1;
@@ -1159,6 +1160,7 @@ static int perf_evsel__hists_browse(struct perf_evsel 
*evsel, int nr_events,
int choice = 0,
annotate = -2, zoom_dso = -2, zoom_thread = -2,
annotate_f = -2, annotate_t = -2, browse_map = -2;
+   int scripts_comm = -2, scripts_symbol = -2, scripts_all = -2;
 
nr_options = 0;
 
@@ -1211,6 +1213,8 @@ static int perf_evsel__hists_browse(struct perf_evsel 
*evsel, int nr_events,
hist_browser__reset(browser);
}
continue;
+   case 'r':
+   goto do_scripts;
case K_F1:
case 'h':
case '?':
@@ -1229,6 +1233,7 @@ static int perf_evsel__hists_browse(struct perf_evsel 
*evsel, int nr_events,
E Expand all callchains\n
d Zoom into current DSO\n
t Zoom into current 
Thread\n
+   r Run available scripts\n
P Print histograms to 
perf.hist.N\n
V Verbose (DSO names in 
callchains, etc)\n
/ Filter symbol by name);
@@ -1317,6 +1322,25 @@ static int perf_evsel__hists_browse(struct perf_evsel 
*evsel, int nr_events,
browser-selection-map != NULL 
asprintf(options[nr_options], Browse map details)  0)
browse_map = nr_options++;
+
+   /* perf script support */
+   if (browser-he_selection) {
+   struct symbol *sym;
+
+   if (asprintf(options[nr_options], Run scripts for 
samples of thread [%s],
+   browser-he_selection-thread-comm)  0)
+   scripts_comm = nr_options++;
+
+   sym = browser-he_selection-ms.sym;
+   if (sym  sym-namelen 
+   asprintf(options[nr_options], Run scripts for 
samples of symbol [%s],
+   sym-name)  0)
+   scripts_symbol = nr_options++;
+   }
+
+   if (asprintf(options[nr_options], Run scripts for all 
samples)  0)
+   scripts_all = nr_options++;
+
 add_exit_option:
options[nr_options++] = (char *)Exit;
 retry_popup_menu:
@@ -1411,6 +1435,20 @@ zoom_out_thread:
hists__filter_by_thread(hists);
hist_browser__reset(browser);
}
+   /* perf scripts support */
+   else if (choice == scripts_all || choice == scripts_comm ||
+   choice == scripts_symbol) {
+do_scripts:
+   memset(script_opt, 0, 64);
+
+   if (choice == scripts_comm)
+   sprintf(script_opt,  -c %s , 
browser-he_selection-thread-comm);
+
+   if (choice == scripts_symbol)
+   sprintf(script_opt,  -S %s , 
browser-he_selection-ms.sym-name);
+
+   script_browse(script_opt);
+   }
}
 out_free_stack:
pstack__delete(fstack);
--
To 

[tip:perf/core] perf header: Add is_perf_magic() func

2012-10-30 Thread tip-bot for Feng Tang
Commit-ID:  e84ba4e26833991d1c1c15a592b1474ee2b6dfdb
Gitweb: http://git.kernel.org/tip/e84ba4e26833991d1c1c15a592b1474ee2b6dfdb
Author: Feng Tang feng.t...@intel.com
AuthorDate: Tue, 30 Oct 2012 11:56:07 +0800
Committer:  Arnaldo Carvalho de Melo a...@redhat.com
CommitDate: Mon, 29 Oct 2012 11:56:59 -0200

perf header: Add is_perf_magic() func

With this function, other modules can basically check whether a file is
a legal perf data file by checking its first 8 bytes against all
possible perf magic numbers.

Change the function name from check_perf_magic to more meaningful
is_perf_magic as suggested by acme.

Signed-off-by: Feng Tang feng.t...@intel.com
Cc: Andi Kleen a...@firstfloor.org
Cc: Ingo Molnar mi...@elte.hu
Cc: Namhyung Kim namhy...@kernel.org
Cc: Peter Zijlstra pet...@infradead.org
Link: 
http://lkml.kernel.org/r/1351569369-26732-7-git-send-email-feng.t...@intel.com
Signed-off-by: Arnaldo Carvalho de Melo a...@redhat.com
---
 tools/perf/util/header.c |   10 ++
 tools/perf/util/header.h |1 +
 2 files changed, 11 insertions(+), 0 deletions(-)

diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c
index 514ed1b..195a47a 100644
--- a/tools/perf/util/header.c
+++ b/tools/perf/util/header.c
@@ -2341,6 +2341,16 @@ static int try_all_pipe_abis(uint64_t hdr_sz, struct 
perf_header *ph)
return -1;
 }
 
+bool is_perf_magic(u64 magic)
+{
+   if (!memcmp(magic, __perf_magic1, sizeof(magic))
+   || magic == __perf_magic2
+   || magic == __perf_magic2_sw)
+   return true;
+
+   return false;
+}
+
 static int check_magic_endian(u64 magic, uint64_t hdr_sz,
  bool is_pipe, struct perf_header *ph)
 {
diff --git a/tools/perf/util/header.h b/tools/perf/util/header.h
index 879d215..5f1cd68 100644
--- a/tools/perf/util/header.h
+++ b/tools/perf/util/header.h
@@ -154,6 +154,7 @@ int perf_event__synthesize_build_id(struct perf_tool *tool,
 int perf_event__process_build_id(struct perf_tool *tool,
 union perf_event *event,
 struct perf_session *session);
+bool is_perf_magic(u64 magic);
 
 /*
  * arch specific callback
--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[tip:perf/core] perf tools: Fix a compiling error in util/map.c

2012-09-26 Thread tip-bot for Feng Tang
Commit-ID:  8f28f19a87cb48d13570ba774a3e85776eb36bb4
Gitweb: http://git.kernel.org/tip/8f28f19a87cb48d13570ba774a3e85776eb36bb4
Author: Feng Tang 
AuthorDate: Mon, 27 Aug 2012 15:38:26 +0800
Committer:  Arnaldo Carvalho de Melo 
CommitDate: Thu, 20 Sep 2012 08:36:34 -0300

perf tools: Fix a compiling error in util/map.c

This patch fix a compile warning taken as error:

CC util/map.o
cc1: warnings being treated as errors
util/map.c: In function ‘map__fprintf_dsoname’:
util/map.c:240: error: ‘dsoname’ may be used uninitialized in this 
function
make: *** [util/map.o] Error 1

Signed-off-by: Feng Tang 
Cc: David Ahern 
Cc: Ingo Molnar 
Cc: Namhyung Kim 
Cc: Peter Zijlstra 
Link: 
http://lkml.kernel.org/r/1346053107-11946-3-git-send-email-feng.t...@intel.com
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/util/map.c |5 ++---
 1 files changed, 2 insertions(+), 3 deletions(-)

diff --git a/tools/perf/util/map.c b/tools/perf/util/map.c
index b442ee4..ead5316 100644
--- a/tools/perf/util/map.c
+++ b/tools/perf/util/map.c
@@ -243,15 +243,14 @@ size_t map__fprintf(struct map *self, FILE *fp)
 
 size_t map__fprintf_dsoname(struct map *map, FILE *fp)
 {
-   const char *dsoname;
+   const char *dsoname = "[unknown]";
 
if (map && map->dso && (map->dso->name || map->dso->long_name)) {
if (symbol_conf.show_kernel_path && map->dso->long_name)
dsoname = map->dso->long_name;
else if (map->dso->name)
dsoname = map->dso->name;
-   } else
-   dsoname = "[unknown]";
+   }
 
return fprintf(fp, "%s", dsoname);
 }
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[tip:perf/core] perf tools: Fix a compiling error in trace-event-perl.c for 32 bits machine

2012-09-26 Thread tip-bot for Feng Tang
Commit-ID:  b1ab1bd1921536c2a97adb888effeff4370a3246
Gitweb: http://git.kernel.org/tip/b1ab1bd1921536c2a97adb888effeff4370a3246
Author: Feng Tang 
AuthorDate: Thu, 20 Sep 2012 08:30:21 -0300
Committer:  Arnaldo Carvalho de Melo 
CommitDate: Thu, 20 Sep 2012 08:30:21 -0300

perf tools: Fix a compiling error in trace-event-perl.c for 32 bits machine

On my x86_32 mahcine, there is a compile error:

CC util/scripting-engines/trace-event-perl.o
cc1: warnings being treated as errors
util/scripting-engines/trace-event-perl.c: In function
perl_process_tracepoint:
util/scripting-engines/trace-event-perl.c:285: error: format
expects type 'int', but argument 2 has type '__u64'
make: *** [util/scripting-engines/trace-event-perl.o] Error 1

Fix it by using the "%PRIu64" for __u64.

v2: use PRIu64 as suggested by Arnaldo.

Signed-off-by: Feng Tang 
Cc: David Ahern 
Cc: Namhyung Kim 
Cc: Peter Zijlstra 
Link: http://lkml.kernel.org/r/20120828101730.6b2fd97e@feng-i7
Signed-off-by: Arnaldo Carvalho de Melo 
---
 .../perf/util/scripting-engines/trace-event-perl.c |2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/tools/perf/util/scripting-engines/trace-event-perl.c 
b/tools/perf/util/scripting-engines/trace-event-perl.c
index ffde3e4..f80605e 100644
--- a/tools/perf/util/scripting-engines/trace-event-perl.c
+++ b/tools/perf/util/scripting-engines/trace-event-perl.c
@@ -282,7 +282,7 @@ static void perl_process_tracepoint(union perf_event 
*perf_event __maybe_unused,
 
event = find_cache_event(evsel);
if (!event)
-   die("ug! no event found for type %d", evsel->attr.config);
+   die("ug! no event found for type %" PRIu64, evsel->attr.config);
 
pid = raw_field_value(event, "common_pid", data);
 
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[tip:perf/core] perf tools: Fix a compiling error in trace-event-perl.c for 32 bits machine

2012-09-26 Thread tip-bot for Feng Tang
Commit-ID:  b1ab1bd1921536c2a97adb888effeff4370a3246
Gitweb: http://git.kernel.org/tip/b1ab1bd1921536c2a97adb888effeff4370a3246
Author: Feng Tang feng.t...@intel.com
AuthorDate: Thu, 20 Sep 2012 08:30:21 -0300
Committer:  Arnaldo Carvalho de Melo a...@redhat.com
CommitDate: Thu, 20 Sep 2012 08:30:21 -0300

perf tools: Fix a compiling error in trace-event-perl.c for 32 bits machine

On my x86_32 mahcine, there is a compile error:

CC util/scripting-engines/trace-event-perl.o
cc1: warnings being treated as errors
util/scripting-engines/trace-event-perl.c: In function
perl_process_tracepoint:
util/scripting-engines/trace-event-perl.c:285: error: format
expects type 'int', but argument 2 has type '__u64'
make: *** [util/scripting-engines/trace-event-perl.o] Error 1

Fix it by using the %PRIu64 for __u64.

v2: use PRIu64 as suggested by Arnaldo.

Signed-off-by: Feng Tang feng.t...@intel.com
Cc: David Ahern dsah...@gmail.com
Cc: Namhyung Kim namhy...@kernel.org
Cc: Peter Zijlstra a.p.zijls...@chello.nl
Link: http://lkml.kernel.org/r/20120828101730.6b2fd97e@feng-i7
Signed-off-by: Arnaldo Carvalho de Melo a...@redhat.com
---
 .../perf/util/scripting-engines/trace-event-perl.c |2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/tools/perf/util/scripting-engines/trace-event-perl.c 
b/tools/perf/util/scripting-engines/trace-event-perl.c
index ffde3e4..f80605e 100644
--- a/tools/perf/util/scripting-engines/trace-event-perl.c
+++ b/tools/perf/util/scripting-engines/trace-event-perl.c
@@ -282,7 +282,7 @@ static void perl_process_tracepoint(union perf_event 
*perf_event __maybe_unused,
 
event = find_cache_event(evsel);
if (!event)
-   die(ug! no event found for type %d, evsel-attr.config);
+   die(ug! no event found for type % PRIu64, evsel-attr.config);
 
pid = raw_field_value(event, common_pid, data);
 
--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[tip:perf/core] perf tools: Fix a compiling error in util/map.c

2012-09-26 Thread tip-bot for Feng Tang
Commit-ID:  8f28f19a87cb48d13570ba774a3e85776eb36bb4
Gitweb: http://git.kernel.org/tip/8f28f19a87cb48d13570ba774a3e85776eb36bb4
Author: Feng Tang feng.t...@intel.com
AuthorDate: Mon, 27 Aug 2012 15:38:26 +0800
Committer:  Arnaldo Carvalho de Melo a...@redhat.com
CommitDate: Thu, 20 Sep 2012 08:36:34 -0300

perf tools: Fix a compiling error in util/map.c

This patch fix a compile warning taken as error:

CC util/map.o
cc1: warnings being treated as errors
util/map.c: In function ‘map__fprintf_dsoname’:
util/map.c:240: error: ‘dsoname’ may be used uninitialized in this 
function
make: *** [util/map.o] Error 1

Signed-off-by: Feng Tang feng.t...@intel.com
Cc: David Ahern dsah...@gmail.com
Cc: Ingo Molnar mi...@elte.hu
Cc: Namhyung Kim namhy...@kernel.org
Cc: Peter Zijlstra a.p.zijls...@chello.nl
Link: 
http://lkml.kernel.org/r/1346053107-11946-3-git-send-email-feng.t...@intel.com
Signed-off-by: Arnaldo Carvalho de Melo a...@redhat.com
---
 tools/perf/util/map.c |5 ++---
 1 files changed, 2 insertions(+), 3 deletions(-)

diff --git a/tools/perf/util/map.c b/tools/perf/util/map.c
index b442ee4..ead5316 100644
--- a/tools/perf/util/map.c
+++ b/tools/perf/util/map.c
@@ -243,15 +243,14 @@ size_t map__fprintf(struct map *self, FILE *fp)
 
 size_t map__fprintf_dsoname(struct map *map, FILE *fp)
 {
-   const char *dsoname;
+   const char *dsoname = [unknown];
 
if (map  map-dso  (map-dso-name || map-dso-long_name)) {
if (symbol_conf.show_kernel_path  map-dso-long_name)
dsoname = map-dso-long_name;
else if (map-dso-name)
dsoname = map-dso-name;
-   } else
-   dsoname = [unknown];
+   }
 
return fprintf(fp, %s, dsoname);
 }
--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[tip:perf/core] perf scripts: Export a find_scripts() function

2012-09-19 Thread tip-bot for Feng Tang
Commit-ID:  e5f3705e62b03251797a5173024184bfc223599d
Gitweb: http://git.kernel.org/tip/e5f3705e62b03251797a5173024184bfc223599d
Author: Feng Tang 
AuthorDate: Fri, 7 Sep 2012 16:42:26 +0800
Committer:  Arnaldo Carvalho de Melo 
CommitDate: Mon, 17 Sep 2012 13:11:26 -0300

perf scripts: Export a find_scripts() function

So that other perf commands/browser has a way to dig out the available
scripts info in system, this is a preparation for the script browser.

Signed-off-by: Feng Tang 
Cc: Andi Kleen 
Cc: David Ahern 
Cc: Ingo Molnar 
Cc: Namhyung Kim 
Cc: Peter Zijlstra 
Link: 
http://lkml.kernel.org/r/1347007349-3102-5-git-send-email-feng.t...@intel.com
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/builtin-script.c |   55 +++
 tools/perf/builtin.h|1 +
 2 files changed, 56 insertions(+), 0 deletions(-)

diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c
index 76577e6..1be843a 100644
--- a/tools/perf/builtin-script.c
+++ b/tools/perf/builtin-script.c
@@ -1032,6 +1032,61 @@ static int list_available_scripts(const struct option 
*opt __maybe_unused,
exit(0);
 }
 
+/*
+ * Return -1 if none is found, otherwise the actual scripts number.
+ *
+ * Currently the only user of this function is the script browser, which
+ * will list all statically runnable scripts, select one, execute it and
+ * show the output in a perf browser.
+ */
+int find_scripts(char **scripts_array, char **scripts_path_array)
+{
+   struct dirent *script_next, *lang_next, script_dirent, lang_dirent;
+   char scripts_path[MAXPATHLEN];
+   DIR *scripts_dir, *lang_dir;
+   char lang_path[MAXPATHLEN];
+   char *temp;
+   int i = 0;
+
+   snprintf(scripts_path, MAXPATHLEN, "%s/scripts", perf_exec_path());
+
+   scripts_dir = opendir(scripts_path);
+   if (!scripts_dir)
+   return -1;
+
+   for_each_lang(scripts_path, scripts_dir, lang_dirent, lang_next) {
+   snprintf(lang_path, MAXPATHLEN, "%s/%s", scripts_path,
+lang_dirent.d_name);
+#ifdef NO_LIBPERL
+   if (strstr(lang_path, "perl"))
+   continue;
+#endif
+#ifdef NO_LIBPYTHON
+   if (strstr(lang_path, "python"))
+   continue;
+#endif
+
+   lang_dir = opendir(lang_path);
+   if (!lang_dir)
+   continue;
+
+   for_each_script(lang_path, lang_dir, script_dirent, 
script_next) {
+   /* Skip those real time scripts: xxxtop.p[yl] */
+   if (strstr(script_dirent.d_name, "top."))
+   continue;
+   sprintf(scripts_path_array[i], "%s/%s", lang_path,
+   script_dirent.d_name);
+   temp = strchr(script_dirent.d_name, '.');
+   snprintf(scripts_array[i],
+   (temp - script_dirent.d_name) + 1,
+   "%s", script_dirent.d_name);
+   i++;
+   }
+   }
+
+   return i;
+}
+
 static char *get_script_path(const char *script_root, const char *suffix)
 {
struct dirent *script_next, *lang_next, script_dirent, lang_dirent;
diff --git a/tools/perf/builtin.h b/tools/perf/builtin.h
index b382bd5..3ea74ed 100644
--- a/tools/perf/builtin.h
+++ b/tools/perf/builtin.h
@@ -36,4 +36,5 @@ extern int cmd_kvm(int argc, const char **argv, const char 
*prefix);
 extern int cmd_test(int argc, const char **argv, const char *prefix);
 extern int cmd_inject(int argc, const char **argv, const char *prefix);
 
+extern int find_scripts(char **scripts_array, char **scripts_path_array);
 #endif
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[tip:perf/core] perf scripts: Add event_analyzing_sample-record/ report

2012-09-19 Thread tip-bot for Feng Tang
Commit-ID:  59cbea229473350168930941986ebe5bf685cc23
Gitweb: http://git.kernel.org/tip/59cbea229473350168930941986ebe5bf685cc23
Author: Feng Tang 
AuthorDate: Fri, 7 Sep 2012 16:42:25 +0800
Committer:  Arnaldo Carvalho de Melo 
CommitDate: Mon, 17 Sep 2012 13:11:15 -0300

perf scripts: Add event_analyzing_sample-record/report

So that event_analyzing_sample.py can be shown by "perf script -l"

Signed-off-by: Feng Tang 
Cc: Andi Kleen 
Cc: David Ahern 
Cc: Ingo Molnar 
Cc: Namhyung Kim 
Cc: Peter Zijlstra 
Link: 
http://lkml.kernel.org/r/1347007349-3102-4-git-send-email-feng.t...@intel.com
Signed-off-by: Arnaldo Carvalho de Melo 
---
 .../python/bin/event_analyzing_sample-record   |8 
 .../python/bin/event_analyzing_sample-report   |3 +++
 2 files changed, 11 insertions(+), 0 deletions(-)

diff --git a/tools/perf/scripts/python/bin/event_analyzing_sample-record 
b/tools/perf/scripts/python/bin/event_analyzing_sample-record
new file mode 100644
index 000..5ce652d
--- /dev/null
+++ b/tools/perf/scripts/python/bin/event_analyzing_sample-record
@@ -0,0 +1,8 @@
+#!/bin/bash
+
+#
+# event_analyzing_sample.py can cover all type of perf samples including
+# the tracepoints, so no special record requirements, just record what
+# you want to analyze.
+#
+perf record $@
diff --git a/tools/perf/scripts/python/bin/event_analyzing_sample-report 
b/tools/perf/scripts/python/bin/event_analyzing_sample-report
new file mode 100644
index 000..0941fc9
--- /dev/null
+++ b/tools/perf/scripts/python/bin/event_analyzing_sample-report
@@ -0,0 +1,3 @@
+#!/bin/bash
+# description: analyze all perf samples
+perf script $@ -s "$PERF_EXEC_PATH"/scripts/python/event_analyzing_sample.py
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[tip:perf/core] perf scripts: Add --symbols option to handle specific symbols

2012-09-19 Thread tip-bot for Feng Tang
Commit-ID:  36385be55da10b3271407c45c3a62d9af3db666e
Gitweb: http://git.kernel.org/tip/36385be55da10b3271407c45c3a62d9af3db666e
Author: Feng Tang 
AuthorDate: Fri, 7 Sep 2012 16:42:24 +0800
Committer:  Arnaldo Carvalho de Melo 
CommitDate: Mon, 17 Sep 2012 13:11:06 -0300

perf scripts: Add --symbols option to handle specific symbols

Since perf script no longer only handle the trace points, we can add the
symbol filter option so that scripts can handle specified samples.

Signed-off-by: Feng Tang 
Cc: Andi Kleen 
Cc: David Ahern 
Cc: Ingo Molnar 
Cc: Namhyung Kim 
Cc: Peter Zijlstra 
Link: 
http://lkml.kernel.org/r/1347007349-3102-3-git-send-email-feng.t...@intel.com
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/builtin-script.c |3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)

diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c
index 6d98a83..76577e6 100644
--- a/tools/perf/builtin-script.c
+++ b/tools/perf/builtin-script.c
@@ -14,6 +14,7 @@
 #include "util/util.h"
 #include "util/evlist.h"
 #include "util/evsel.h"
+#include "util/sort.h"
 #include 
 
 static char const  *script_name;
@@ -1143,6 +1144,8 @@ static const struct option options[] = {
 parse_output_fields),
OPT_BOOLEAN('a', "all-cpus", _wide,
 "system-wide collection from all CPUs"),
+   OPT_STRING('S', "symbols", _conf.sym_list_str, 
"symbol[,symbol...]",
+  "only consider these symbols"),
OPT_STRING('C', "cpu", _list, "cpu", "list of cpus to profile"),
OPT_STRING('c', "comms", _conf.comm_list_str, "comm[,comm...]",
   "only display events for these comms"),
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[tip:perf/core] perf symbols: Filter samples with unresolved symbol when "--symbols" option is used

2012-09-19 Thread tip-bot for Feng Tang
Commit-ID:  1500b93b61fc70a1176871b64f1c8ae3bd4da9dd
Gitweb: http://git.kernel.org/tip/1500b93b61fc70a1176871b64f1c8ae3bd4da9dd
Author: Feng Tang 
AuthorDate: Fri, 7 Sep 2012 16:42:23 +0800
Committer:  Arnaldo Carvalho de Melo 
CommitDate: Mon, 17 Sep 2012 13:10:57 -0300

perf symbols: Filter samples with unresolved symbol when "--symbols" option is 
used

Report/top commands support to only handle specific symbols with
"--symbols" option, but current code will keep those samples whose
symbol can't be resolved, which should actually be filtered.

If we run following commands:
$perf record -a tree
$perf report --symbols intel_idle -n
the output will be:

Without the patch:
==
46.27%156 sshd  [unknown]
26.05% 48  swapper  [kernel.kallsyms]
17.26% 38 tree  libc-2.12.1.so
 7.69% 17 tree  tree
 2.73%  6 tree  ld-2.12.1.so

With the patch:
===
   100.00% 48  swapper  [kernel.kallsyms]

Signed-off-by: Feng Tang 
Cc: Andi Kleen 
Cc: David Ahern 
Cc: Ingo Molnar 
Cc: Namhyung Kim 
Cc: Peter Zijlstra 
Link: 
http://lkml.kernel.org/r/1347007349-3102-2-git-send-email-feng.t...@intel.com
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/util/event.c |5 +++--
 1 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/tools/perf/util/event.c b/tools/perf/util/event.c
index 8202f5c..6715b19 100644
--- a/tools/perf/util/event.c
+++ b/tools/perf/util/event.c
@@ -904,8 +904,9 @@ int perf_event__preprocess_sample(const union perf_event 
*event,
al->sym = map__find_symbol(al->map, al->addr, filter);
}
 
-   if (symbol_conf.sym_list && al->sym &&
-   !strlist__has_entry(symbol_conf.sym_list, al->sym->name))
+   if (symbol_conf.sym_list &&
+   (!al->sym || !strlist__has_entry(symbol_conf.sym_list,
+   al->sym->name)))
goto out_filtered;
 
return 0;
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[tip:perf/core] perf symbols: Filter samples with unresolved symbol when --symbols option is used

2012-09-19 Thread tip-bot for Feng Tang
Commit-ID:  1500b93b61fc70a1176871b64f1c8ae3bd4da9dd
Gitweb: http://git.kernel.org/tip/1500b93b61fc70a1176871b64f1c8ae3bd4da9dd
Author: Feng Tang feng.t...@intel.com
AuthorDate: Fri, 7 Sep 2012 16:42:23 +0800
Committer:  Arnaldo Carvalho de Melo a...@redhat.com
CommitDate: Mon, 17 Sep 2012 13:10:57 -0300

perf symbols: Filter samples with unresolved symbol when --symbols option is 
used

Report/top commands support to only handle specific symbols with
--symbols option, but current code will keep those samples whose
symbol can't be resolved, which should actually be filtered.

If we run following commands:
$perf record -a tree
$perf report --symbols intel_idle -n
the output will be:

Without the patch:
==
46.27%156 sshd  [unknown]
26.05% 48  swapper  [kernel.kallsyms]
17.26% 38 tree  libc-2.12.1.so
 7.69% 17 tree  tree
 2.73%  6 tree  ld-2.12.1.so

With the patch:
===
   100.00% 48  swapper  [kernel.kallsyms]

Signed-off-by: Feng Tang feng.t...@intel.com
Cc: Andi Kleen a...@firstfloor.org
Cc: David Ahern dsah...@gmail.com
Cc: Ingo Molnar mi...@elte.hu
Cc: Namhyung Kim namhy...@kernel.org
Cc: Peter Zijlstra a.p.zijls...@chello.nl
Link: 
http://lkml.kernel.org/r/1347007349-3102-2-git-send-email-feng.t...@intel.com
Signed-off-by: Arnaldo Carvalho de Melo a...@redhat.com
---
 tools/perf/util/event.c |5 +++--
 1 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/tools/perf/util/event.c b/tools/perf/util/event.c
index 8202f5c..6715b19 100644
--- a/tools/perf/util/event.c
+++ b/tools/perf/util/event.c
@@ -904,8 +904,9 @@ int perf_event__preprocess_sample(const union perf_event 
*event,
al-sym = map__find_symbol(al-map, al-addr, filter);
}
 
-   if (symbol_conf.sym_list  al-sym 
-   !strlist__has_entry(symbol_conf.sym_list, al-sym-name))
+   if (symbol_conf.sym_list 
+   (!al-sym || !strlist__has_entry(symbol_conf.sym_list,
+   al-sym-name)))
goto out_filtered;
 
return 0;
--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[tip:perf/core] perf scripts: Add --symbols option to handle specific symbols

2012-09-19 Thread tip-bot for Feng Tang
Commit-ID:  36385be55da10b3271407c45c3a62d9af3db666e
Gitweb: http://git.kernel.org/tip/36385be55da10b3271407c45c3a62d9af3db666e
Author: Feng Tang feng.t...@intel.com
AuthorDate: Fri, 7 Sep 2012 16:42:24 +0800
Committer:  Arnaldo Carvalho de Melo a...@redhat.com
CommitDate: Mon, 17 Sep 2012 13:11:06 -0300

perf scripts: Add --symbols option to handle specific symbols

Since perf script no longer only handle the trace points, we can add the
symbol filter option so that scripts can handle specified samples.

Signed-off-by: Feng Tang feng.t...@intel.com
Cc: Andi Kleen a...@firstfloor.org
Cc: David Ahern dsah...@gmail.com
Cc: Ingo Molnar mi...@kernel.org
Cc: Namhyung Kim namhy...@kernel.org
Cc: Peter Zijlstra a.p.zijls...@chello.nl
Link: 
http://lkml.kernel.org/r/1347007349-3102-3-git-send-email-feng.t...@intel.com
Signed-off-by: Arnaldo Carvalho de Melo a...@redhat.com
---
 tools/perf/builtin-script.c |3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)

diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c
index 6d98a83..76577e6 100644
--- a/tools/perf/builtin-script.c
+++ b/tools/perf/builtin-script.c
@@ -14,6 +14,7 @@
 #include util/util.h
 #include util/evlist.h
 #include util/evsel.h
+#include util/sort.h
 #include linux/bitmap.h
 
 static char const  *script_name;
@@ -1143,6 +1144,8 @@ static const struct option options[] = {
 parse_output_fields),
OPT_BOOLEAN('a', all-cpus, system_wide,
 system-wide collection from all CPUs),
+   OPT_STRING('S', symbols, symbol_conf.sym_list_str, 
symbol[,symbol...],
+  only consider these symbols),
OPT_STRING('C', cpu, cpu_list, cpu, list of cpus to profile),
OPT_STRING('c', comms, symbol_conf.comm_list_str, comm[,comm...],
   only display events for these comms),
--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[tip:perf/core] perf scripts: Add event_analyzing_sample-record/ report

2012-09-19 Thread tip-bot for Feng Tang
Commit-ID:  59cbea229473350168930941986ebe5bf685cc23
Gitweb: http://git.kernel.org/tip/59cbea229473350168930941986ebe5bf685cc23
Author: Feng Tang feng.t...@intel.com
AuthorDate: Fri, 7 Sep 2012 16:42:25 +0800
Committer:  Arnaldo Carvalho de Melo a...@redhat.com
CommitDate: Mon, 17 Sep 2012 13:11:15 -0300

perf scripts: Add event_analyzing_sample-record/report

So that event_analyzing_sample.py can be shown by perf script -l

Signed-off-by: Feng Tang feng.t...@intel.com
Cc: Andi Kleen a...@firstfloor.org
Cc: David Ahern dsah...@gmail.com
Cc: Ingo Molnar mi...@elte.hu
Cc: Namhyung Kim namhy...@kernel.org
Cc: Peter Zijlstra a.p.zijls...@chello.nl
Link: 
http://lkml.kernel.org/r/1347007349-3102-4-git-send-email-feng.t...@intel.com
Signed-off-by: Arnaldo Carvalho de Melo a...@redhat.com
---
 .../python/bin/event_analyzing_sample-record   |8 
 .../python/bin/event_analyzing_sample-report   |3 +++
 2 files changed, 11 insertions(+), 0 deletions(-)

diff --git a/tools/perf/scripts/python/bin/event_analyzing_sample-record 
b/tools/perf/scripts/python/bin/event_analyzing_sample-record
new file mode 100644
index 000..5ce652d
--- /dev/null
+++ b/tools/perf/scripts/python/bin/event_analyzing_sample-record
@@ -0,0 +1,8 @@
+#!/bin/bash
+
+#
+# event_analyzing_sample.py can cover all type of perf samples including
+# the tracepoints, so no special record requirements, just record what
+# you want to analyze.
+#
+perf record $@
diff --git a/tools/perf/scripts/python/bin/event_analyzing_sample-report 
b/tools/perf/scripts/python/bin/event_analyzing_sample-report
new file mode 100644
index 000..0941fc9
--- /dev/null
+++ b/tools/perf/scripts/python/bin/event_analyzing_sample-report
@@ -0,0 +1,3 @@
+#!/bin/bash
+# description: analyze all perf samples
+perf script $@ -s $PERF_EXEC_PATH/scripts/python/event_analyzing_sample.py
--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[tip:perf/core] perf scripts: Export a find_scripts() function

2012-09-19 Thread tip-bot for Feng Tang
Commit-ID:  e5f3705e62b03251797a5173024184bfc223599d
Gitweb: http://git.kernel.org/tip/e5f3705e62b03251797a5173024184bfc223599d
Author: Feng Tang feng.t...@intel.com
AuthorDate: Fri, 7 Sep 2012 16:42:26 +0800
Committer:  Arnaldo Carvalho de Melo a...@redhat.com
CommitDate: Mon, 17 Sep 2012 13:11:26 -0300

perf scripts: Export a find_scripts() function

So that other perf commands/browser has a way to dig out the available
scripts info in system, this is a preparation for the script browser.

Signed-off-by: Feng Tang feng.t...@intel.com
Cc: Andi Kleen a...@firstfloor.org
Cc: David Ahern dsah...@gmail.com
Cc: Ingo Molnar mi...@elte.hu
Cc: Namhyung Kim namhy...@kernel.org
Cc: Peter Zijlstra a.p.zijls...@chello.nl
Link: 
http://lkml.kernel.org/r/1347007349-3102-5-git-send-email-feng.t...@intel.com
Signed-off-by: Arnaldo Carvalho de Melo a...@redhat.com
---
 tools/perf/builtin-script.c |   55 +++
 tools/perf/builtin.h|1 +
 2 files changed, 56 insertions(+), 0 deletions(-)

diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c
index 76577e6..1be843a 100644
--- a/tools/perf/builtin-script.c
+++ b/tools/perf/builtin-script.c
@@ -1032,6 +1032,61 @@ static int list_available_scripts(const struct option 
*opt __maybe_unused,
exit(0);
 }
 
+/*
+ * Return -1 if none is found, otherwise the actual scripts number.
+ *
+ * Currently the only user of this function is the script browser, which
+ * will list all statically runnable scripts, select one, execute it and
+ * show the output in a perf browser.
+ */
+int find_scripts(char **scripts_array, char **scripts_path_array)
+{
+   struct dirent *script_next, *lang_next, script_dirent, lang_dirent;
+   char scripts_path[MAXPATHLEN];
+   DIR *scripts_dir, *lang_dir;
+   char lang_path[MAXPATHLEN];
+   char *temp;
+   int i = 0;
+
+   snprintf(scripts_path, MAXPATHLEN, %s/scripts, perf_exec_path());
+
+   scripts_dir = opendir(scripts_path);
+   if (!scripts_dir)
+   return -1;
+
+   for_each_lang(scripts_path, scripts_dir, lang_dirent, lang_next) {
+   snprintf(lang_path, MAXPATHLEN, %s/%s, scripts_path,
+lang_dirent.d_name);
+#ifdef NO_LIBPERL
+   if (strstr(lang_path, perl))
+   continue;
+#endif
+#ifdef NO_LIBPYTHON
+   if (strstr(lang_path, python))
+   continue;
+#endif
+
+   lang_dir = opendir(lang_path);
+   if (!lang_dir)
+   continue;
+
+   for_each_script(lang_path, lang_dir, script_dirent, 
script_next) {
+   /* Skip those real time scripts: xxxtop.p[yl] */
+   if (strstr(script_dirent.d_name, top.))
+   continue;
+   sprintf(scripts_path_array[i], %s/%s, lang_path,
+   script_dirent.d_name);
+   temp = strchr(script_dirent.d_name, '.');
+   snprintf(scripts_array[i],
+   (temp - script_dirent.d_name) + 1,
+   %s, script_dirent.d_name);
+   i++;
+   }
+   }
+
+   return i;
+}
+
 static char *get_script_path(const char *script_root, const char *suffix)
 {
struct dirent *script_next, *lang_next, script_dirent, lang_dirent;
diff --git a/tools/perf/builtin.h b/tools/perf/builtin.h
index b382bd5..3ea74ed 100644
--- a/tools/perf/builtin.h
+++ b/tools/perf/builtin.h
@@ -36,4 +36,5 @@ extern int cmd_kvm(int argc, const char **argv, const char 
*prefix);
 extern int cmd_test(int argc, const char **argv, const char *prefix);
 extern int cmd_inject(int argc, const char **argv, const char *prefix);
 
+extern int find_scripts(char **scripts_array, char **scripts_path_array);
 #endif
--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[tip:perf/core] perf script python: Correct handler check and spelling errors

2012-08-21 Thread tip-bot for Feng Tang
Commit-ID:  87b6a3ad40ba304ec468b972e979e7e410852476
Gitweb: http://git.kernel.org/tip/87b6a3ad40ba304ec468b972e979e7e410852476
Author: Feng Tang 
AuthorDate: Thu, 9 Aug 2012 13:46:13 +0800
Committer:  Arnaldo Carvalho de Melo 
CommitDate: Thu, 9 Aug 2012 13:26:19 -0300

perf script python: Correct handler check and spelling errors

Correct the checking for handler returned by PyDict_GetItemString(),
also fix some spelling error and remove some data code in
event_analyzing_sample.py, as suggested by Namhyung Kim.

v2: restore back the wrongly removed trace_unhandled() func

Signed-off-by: Feng Tang 
Acked-by: Namhyung Kim 
Cc: Andi Kleen 
Cc: David Ahern 
Cc: Ingo Molnar 
Cc: Namhyung Kim 
Cc: Peter Zijlstra 
Cc: Robert Richter 
Cc: Stephane Eranian 
Link: http://lkml.kernel.org/r/20120809134613.067104c4@feng-i7
Signed-off-by: Arnaldo Carvalho de Melo 
---
 .../Perf-Trace-Util/lib/Perf/Trace/EventClass.py   |4 +-
 .../perf/scripts/python/event_analyzing_sample.py  |   30 ---
 .../util/scripting-engines/trace-event-python.c|8 ++---
 3 files changed, 18 insertions(+), 24 deletions(-)

diff --git 
a/tools/perf/scripts/python/Perf-Trace-Util/lib/Perf/Trace/EventClass.py 
b/tools/perf/scripts/python/Perf-Trace-Util/lib/Perf/Trace/EventClass.py
index 6372431..9e098579 100755
--- a/tools/perf/scripts/python/Perf-Trace-Util/lib/Perf/Trace/EventClass.py
+++ b/tools/perf/scripts/python/Perf-Trace-Util/lib/Perf/Trace/EventClass.py
@@ -1,12 +1,12 @@
 # EventClass.py
 #
-# This is a libray defining some events typs classes, which could
+# This is a library defining some events types classes, which could
 # be used by other scripts to analyzing the perf samples.
 #
 # Currently there are just a few classes defined for examples,
 # PerfEvent is the base class for all perf event sample, PebsEvent
 # is a HW base Intel x86 PEBS event, and user could add more SW/HW
-# event classes based on requriements.
+# event classes based on requirements.
 
 import struct
 
diff --git a/tools/perf/scripts/python/event_analyzing_sample.py 
b/tools/perf/scripts/python/event_analyzing_sample.py
index 46f05aa..163c39f 100644
--- a/tools/perf/scripts/python/event_analyzing_sample.py
+++ b/tools/perf/scripts/python/event_analyzing_sample.py
@@ -1,15 +1,15 @@
-# process_event.py: general event handler in python
+# event_analyzing_sample.py: general event handler in python
 #
-# Current perf report is alreay very powerful with the anotation integrated,
+# Current perf report is already very powerful with the annotation integrated,
 # and this script is not trying to be as powerful as perf report, but
 # providing end user/developer a flexible way to analyze the events other
 # than trace points.
 #
 # The 2 database related functions in this script just show how to gather
 # the basic information, and users can modify and write their own functions
-# according to their specific requirment.
+# according to their specific requirement.
 #
-# The first sample "show_general_events" just does a baisc grouping for all
+# The first function "show_general_events" just does a basic grouping for all
 # generic events with the help of sqlite, and the 2nd one "show_pebs_ll" is
 # for a x86 HW PMU event: PEBS with load latency data.
 #
@@ -85,7 +85,7 @@ def process_event(param_dict):
 else:
 symbol = "Unknown_symbol"
 
-# Creat the event object and insert it to the right table in database
+# Create the event object and insert it to the right table in database
 event = create_event(name, comm, dso, symbol, raw_buf)
 insert_db(event)
 
@@ -109,7 +109,7 @@ def trace_end():
 
 #
 # As the event number may be very big, so we can't use linear way
-# to show the histgram in real number, but use a log2 algorithm.
+# to show the histogram in real number, but use a log2 algorithm.
 #
 
 def num2sym(num):
@@ -130,18 +130,18 @@ def show_general_events():
 
  # Group by thread
 commq = con.execute("select comm, count(comm) from gen_events group by 
comm order by -count(comm)")
-print "\n%16s %8s %16s\n%s" % ("comm", "number", "histgram", "="*42)
+print "\n%16s %8s %16s\n%s" % ("comm", "number", "histogram", "="*42)
 for row in commq:
  print "%16s %8d %s" % (row[0], row[1], num2sym(row[1]))
 
 # Group by symbol
-print "\n%32s %8s %16s\n%s" % ("symbol", "number", "histgram", "="*58)
+print "\n%32s %8s %16s\n%s" % ("symbol", "number", "histogram", "="*58)
 symbolq = con.execute("select symbol, count(symbol) from gen_events 
group by symbol order by -count(symbol)")
 for row in symbolq:
  print "%32s %8d %s" % (row[0], row[1], num2sym(row[1]))
 
 # Group by dso
-print "\n%40s %8s %16s\n%s" % ("dso", "number", "histgram", "="*74)
+print "\n%40s %8s %16s\n%s" % ("dso", "number", "histogram", "="*74)
 dsoq = con.execute("select dso, count(dso) 

[tip:perf/core] perf scripts python: Add event_analyzing_sample. py as a sample for general event handling

2012-08-21 Thread tip-bot for Feng Tang
Commit-ID:  0076d546b4f9b5c15121c6959d108a83fe43fa9a
Gitweb: http://git.kernel.org/tip/0076d546b4f9b5c15121c6959d108a83fe43fa9a
Author: Feng Tang 
AuthorDate: Wed, 8 Aug 2012 17:57:55 +0800
Committer:  Arnaldo Carvalho de Melo 
CommitDate: Wed, 8 Aug 2012 12:55:38 -0300

perf scripts python: Add event_analyzing_sample.py as a sample for general 
event handling

Currently only trace point events are supported in perf/python script,
the first 3 patches of this serie add the support for all types of
events. This script is just a simple sample to show how to gather the
basic information of the events and analyze them.

This script will create one object for each event sample and insert them
into a table in a database, then leverage the simple SQL commands to
sort/group them. User can modify or write their brand new functions
according to their specific requirment.

Here is the sample of how to use the script:

 $ perf record -a tree
 $ perf script -s process_event.py

There is 100 records in gen_events table
Statistics about the general events grouped by thread/symbol/dso:

comm   number histgram
==
 swapper   56 ##
tree   20 #
perf   10 
sshd8 
 kworker/7:24 ###
 ksoftirqd/71 #
 plugin-containe1 #

  symbol   number histgram
==
   native_write_msr_safe   40 ##
  __lock_acquire8 
 ftrace_graph_caller4 ###
   prepare_ftrace_return4 ###
  intel_idle3 ##
  native_sched_clock3 ##
  Unknown_symbol2 ##
  do_softirq2 ##
lock_release2 ##
   lock_release_holdtime2 ##
   trace_graph_entry2 ##
_IO_putc1 #
  __d_lookup_rcu1 #
  __do_fault1 #
  __schedule1 #
  _raw_spin_lock1 #
   delay_tsc1 #
 generic_exec_single1 #
generic_fillattr1 #

 dso   number histgram
==
   [kernel.kallsyms]   95 ###
 /lib/libc-2.12.1.so5 ###

Signed-off-by: Feng Tang 
Cc: Andi Kleen 
Cc: David Ahern 
Cc: Ingo Molnar 
Cc: Peter Zijlstra 
Cc: Robert Richter 
Cc: Stephane Eranian 
Link: 
http://lkml.kernel.org/r/1344419875-21665-6-git-send-email-feng.t...@intel.com
Signed-off-by: Arnaldo Carvalho de Melo 
---
 .../perf/scripts/python/event_analyzing_sample.py  |  193 
 1 files changed, 193 insertions(+), 0 deletions(-)

diff --git a/tools/perf/scripts/python/event_analyzing_sample.py 
b/tools/perf/scripts/python/event_analyzing_sample.py
new file mode 100644
index 000..46f05aa
--- /dev/null
+++ b/tools/perf/scripts/python/event_analyzing_sample.py
@@ -0,0 +1,193 @@
+# process_event.py: general event handler in python
+#
+# Current perf report is alreay very powerful with the anotation integrated,
+# and this script is not trying to be as powerful as perf report, but
+# providing end user/developer a flexible way to analyze the events other
+# than trace points.
+#
+# The 2 database related functions in this script just show how to gather
+# the basic information, and users can modify and write their own functions
+# according to their specific requirment.
+#
+# The first sample "show_general_events" just does a baisc grouping for all
+# generic events with the help of sqlite, and the 2nd one "show_pebs_ll" is
+# for a x86 HW PMU event: PEBS with load latency data.
+#
+
+import os
+import sys
+import math
+import struct
+import sqlite3
+
+sys.path.append(os.environ['PERF_EXEC_PATH'] + \
+'/scripts/python/Perf-Trace-Util/lib/Perf/Trace')
+
+from perf_trace_context import *
+from EventClass import *
+
+#
+# If the perf.data has a big number of samples, then the insert operation
+# will be very time consuming (about 10+ minutes for 1 samples) if the
+# .db database is on disk. Move the .db file to RAM based FS to speedup
+# the handling, which will cut the time down to several seconds.
+#
+con = sqlite3.connect("/dev/shm/perf.db")
+con.isolation_level = None
+
+def trace_begin():
+   print "In trace_begin:\n"
+
+#
+# Will create several tables at the start, pebs_ll is for PEBS data 
with
+# load latency info, while gen_events is for general event.
+#
+con.execute("""
+create table 

[tip:perf/core] perf scripts python: Add a python library EventClass.py

2012-08-21 Thread tip-bot for Feng Tang
Commit-ID:  02f1c33f7d630183518ea42d45a6acf275541b08
Gitweb: http://git.kernel.org/tip/02f1c33f7d630183518ea42d45a6acf275541b08
Author: Feng Tang 
AuthorDate: Wed, 8 Aug 2012 17:57:54 +0800
Committer:  Arnaldo Carvalho de Melo 
CommitDate: Wed, 8 Aug 2012 12:53:08 -0300

perf scripts python: Add a python library EventClass.py

This library defines several class types for perf events which could
help to better analyze the event samples. Currently there are just a few
classes, PerfEvent is the base class for all perf events,  PebsEvent is
a HW base Intel x86 PEBS event, and user could add more SW/HW event
classes based on requriements.

Signed-off-by: Feng Tang 
Cc: Andi Kleen 
Cc: David Ahern 
Cc: Ingo Molnar 
Cc: Peter Zijlstra 
Cc: Robert Richter 
Cc: Stephane Eranian 
Link: 
http://lkml.kernel.org/r/1344419875-21665-5-git-send-email-feng.t...@intel.com
Signed-off-by: Arnaldo Carvalho de Melo 
---
 .../Perf-Trace-Util/lib/Perf/Trace/EventClass.py   |   94 
 1 files changed, 94 insertions(+), 0 deletions(-)

diff --git 
a/tools/perf/scripts/python/Perf-Trace-Util/lib/Perf/Trace/EventClass.py 
b/tools/perf/scripts/python/Perf-Trace-Util/lib/Perf/Trace/EventClass.py
new file mode 100755
index 000..6372431
--- /dev/null
+++ b/tools/perf/scripts/python/Perf-Trace-Util/lib/Perf/Trace/EventClass.py
@@ -0,0 +1,94 @@
+# EventClass.py
+#
+# This is a libray defining some events typs classes, which could
+# be used by other scripts to analyzing the perf samples.
+#
+# Currently there are just a few classes defined for examples,
+# PerfEvent is the base class for all perf event sample, PebsEvent
+# is a HW base Intel x86 PEBS event, and user could add more SW/HW
+# event classes based on requriements.
+
+import struct
+
+# Event types, user could add more here
+EVTYPE_GENERIC  = 0
+EVTYPE_PEBS = 1 # Basic PEBS event
+EVTYPE_PEBS_LL  = 2 # PEBS event with load latency info
+EVTYPE_IBS  = 3
+
+#
+# Currently we don't have good way to tell the event type, but by
+# the size of raw buffer, raw PEBS event with load latency data's
+# size is 176 bytes, while the pure PEBS event's size is 144 bytes.
+#
+def create_event(name, comm, dso, symbol, raw_buf):
+if (len(raw_buf) == 144):
+event = PebsEvent(name, comm, dso, symbol, raw_buf)
+elif (len(raw_buf) == 176):
+event = PebsNHM(name, comm, dso, symbol, raw_buf)
+else:
+event = PerfEvent(name, comm, dso, symbol, raw_buf)
+
+return event
+
+class PerfEvent(object):
+event_num = 0
+def __init__(self, name, comm, dso, symbol, raw_buf, 
ev_type=EVTYPE_GENERIC):
+self.name   = name
+self.comm   = comm
+self.dso= dso
+self.symbol = symbol
+self.raw_buf= raw_buf
+self.ev_type= ev_type
+PerfEvent.event_num += 1
+
+def show(self):
+print "PMU event: name=%12s, symbol=%24s, comm=%8s, dso=%12s" 
% (self.name, self.symbol, self.comm, self.dso)
+
+#
+# Basic Intel PEBS (Precise Event-based Sampling) event, whose raw buffer
+# contains the context info when that event happened: the EFLAGS and
+# linear IP info, as well as all the registers.
+#
+class PebsEvent(PerfEvent):
+pebs_num = 0
+def __init__(self, name, comm, dso, symbol, raw_buf, 
ev_type=EVTYPE_PEBS):
+tmp_buf=raw_buf[0:80]
+flags, ip, ax, bx, cx, dx, si, di, bp, sp = 
struct.unpack('QQ', tmp_buf)
+self.flags = flags
+self.ip= ip
+self.ax= ax
+self.bx= bx
+self.cx= cx
+self.dx= dx
+self.si= si
+self.di= di
+self.bp= bp
+self.sp= sp
+
+PerfEvent.__init__(self, name, comm, dso, symbol, raw_buf, 
ev_type)
+PebsEvent.pebs_num += 1
+del tmp_buf
+
+#
+# Intel Nehalem and Westmere support PEBS plus Load Latency info which lie
+# in the four 64 bit words write after the PEBS data:
+#   Status: records the IA32_PERF_GLOBAL_STATUS register value
+#   DLA:Data Linear Address (EIP)
+#   DSE:Data Source Encoding, where the latency happens, hit or miss
+#   in L1/L2/L3 or IO operations
+#   LAT:the actual latency in cycles
+#
+class PebsNHM(PebsEvent):
+pebs_nhm_num = 0
+def __init__(self, name, comm, dso, symbol, raw_buf, 
ev_type=EVTYPE_PEBS_LL):
+tmp_buf=raw_buf[144:176]
+status, dla, dse, lat = struct.unpack('', tmp_buf)
+self.status = status
+self.dla = dla
+self.dse = dse
+self.lat = lat
+
+PebsEvent.__init__(self, name, comm, dso, symbol, raw_buf, 
ev_type)
+

[tip:perf/core] perf scripts python: Pass event/thread/ dso name and symbol info to event handler in python

2012-08-21 Thread tip-bot for Feng Tang
Commit-ID:  fd6b858a1e110c76e701cd9972a284ed2a7bcc33
Gitweb: http://git.kernel.org/tip/fd6b858a1e110c76e701cd9972a284ed2a7bcc33
Author: Feng Tang 
AuthorDate: Wed, 8 Aug 2012 17:57:53 +0800
Committer:  Arnaldo Carvalho de Melo 
CommitDate: Wed, 8 Aug 2012 12:48:02 -0300

perf scripts python: Pass event/thread/dso name and symbol info to event 
handler in python

Also as suggested by Arnaldo, pack all these parameters to a dictionary,
which is more expandable for adding new parameters while keeping the
compatibility for old scripts.

Signed-off-by: Feng Tang 
Cc: Andi Kleen 
Cc: David Ahern 
Cc: Ingo Molnar 
Cc: Peter Zijlstra 
Cc: Robert Richter 
Cc: Stephane Eranian 
Link: 
http://lkml.kernel.org/r/1344419875-21665-4-git-send-email-feng.t...@intel.com
Signed-off-by: Arnaldo Carvalho de Melo 
---
 .../util/scripting-engines/trace-event-python.c|   35 ---
 1 files changed, 29 insertions(+), 6 deletions(-)

diff --git a/tools/perf/util/scripting-engines/trace-event-python.c 
b/tools/perf/util/scripting-engines/trace-event-python.c
index 24711b3..7e3f576 100644
--- a/tools/perf/util/scripting-engines/trace-event-python.c
+++ b/tools/perf/util/scripting-engines/trace-event-python.c
@@ -345,15 +345,23 @@ static void python_process_general_event(union perf_event 
*perf_event __unused,
 struct machine *machine __unused,
 struct addr_location *al __unused)
 {
-   PyObject *handler, *retval, *t;
+   PyObject *handler, *retval, *t, *dict;
static char handler_name[64];
unsigned n = 0;
-   void *data = sample->raw_data;
+   struct thread *thread = al->thread;
 
+   /*
+* Use the MAX_FIELDS to make the function expandable, though
+* currently there is only one itme for the tuple.
+*/
t = PyTuple_New(MAX_FIELDS);
if (!t)
Py_FatalError("couldn't create Python tuple");
 
+   dict = PyDict_New();
+   if (!dict)
+   Py_FatalError("couldn't create Python dictionary");
+
snprintf(handler_name, sizeof(handler_name), "%s", "process_event");
 
handler = PyDict_GetItemString(main_dict, handler_name);
@@ -362,11 +370,25 @@ static void python_process_general_event(union perf_event 
*perf_event __unused,
goto exit;
}
 
-   /* Pass 4 parameters: event_attr, perf_sample, raw data, thread name */
-   PyTuple_SetItem(t, n++, PyString_FromStringAndSize((void 
*)>attr, sizeof(evsel->attr)));
-   PyTuple_SetItem(t, n++, PyString_FromStringAndSize((void *)sample, 
sizeof(*sample)));
-   PyTuple_SetItem(t, n++, PyString_FromStringAndSize(data, 
sample->raw_size));
+   PyDict_SetItemString(dict, "ev_name", 
PyString_FromString(perf_evsel__name(evsel)));
+   PyDict_SetItemString(dict, "attr", PyString_FromStringAndSize(
+   (const char *)>attr, sizeof(evsel->attr)));
+   PyDict_SetItemString(dict, "sample", PyString_FromStringAndSize(
+   (const char *)sample, sizeof(*sample)));
+   PyDict_SetItemString(dict, "raw_buf", PyString_FromStringAndSize(
+   (const char *)sample->raw_data, sample->raw_size));
+   PyDict_SetItemString(dict, "comm",
+   PyString_FromString(thread->comm));
+   if (al->map) {
+   PyDict_SetItemString(dict, "dso",
+   PyString_FromString(al->map->dso->name));
+   }
+   if (al->sym) {
+   PyDict_SetItemString(dict, "symbol",
+   PyString_FromString(al->sym->name));
+   }
 
+   PyTuple_SetItem(t, n++, dict);
if (_PyTuple_Resize(, n) == -1)
Py_FatalError("error resizing Python tuple");
 
@@ -374,6 +396,7 @@ static void python_process_general_event(union perf_event 
*perf_event __unused,
if (retval == NULL)
handler_call_die(handler_name);
 exit:
+   Py_DECREF(dict);
Py_DECREF(t);
 }
 
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[tip:perf/core] perf script: Replace "struct thread" with " struct addr_location" as a parameter for "process_event()"

2012-08-21 Thread tip-bot for Feng Tang
Commit-ID:  73994dc158a24df4af77d0a76c9702f120f7a6ad
Gitweb: http://git.kernel.org/tip/73994dc158a24df4af77d0a76c9702f120f7a6ad
Author: Feng Tang 
AuthorDate: Wed, 8 Aug 2012 17:57:52 +0800
Committer:  Arnaldo Carvalho de Melo 
CommitDate: Wed, 8 Aug 2012 12:46:40 -0300

perf script: Replace "struct thread" with "struct addr_location" as a parameter 
for "process_event()"

Both perl and python script start processing events other than trace
points, and it's useful to pass the resolved symbol and the dso info to
the event handler in script for better analysis and statistics.

Struct thread is already a member of struct addr_location, using
addr_location will keep the thread info, while providing additional
symbol and dso info if exist, so that the script itself doesn't need to
bother to do the symbol resolving and dso searching work.

Tested-by: David Ahern 
Signed-off-by: Feng Tang 
Acked-by: David Ahern 
Cc: Andi Kleen 
Cc: David Ahern 
Cc: Ingo Molnar 
Cc: Peter Zijlstra 
Cc: Robert Richter 
Cc: Stephane Eranian 
Link: 
http://lkml.kernel.org/r/1344419875-21665-3-git-send-email-feng.t...@intel.com
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/builtin-script.c|5 +++--
 .../perf/util/scripting-engines/trace-event-perl.c |   11 ++-
 .../util/scripting-engines/trace-event-python.c|   13 +++--
 tools/perf/util/trace-event-scripting.c|2 +-
 tools/perf/util/trace-event.h  |5 +++--
 5 files changed, 20 insertions(+), 16 deletions(-)

diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c
index 6425612..30a9cb8 100644
--- a/tools/perf/builtin-script.c
+++ b/tools/perf/builtin-script.c
@@ -396,9 +396,10 @@ static void print_sample_bts(union perf_event *event,
 
 static void process_event(union perf_event *event, struct perf_sample *sample,
  struct perf_evsel *evsel, struct machine *machine,
- struct thread *thread)
+ struct addr_location *al)
 {
struct perf_event_attr *attr = >attr;
+   struct thread *thread = al->thread;
 
if (output[attr->type].fields == 0)
return;
@@ -511,7 +512,7 @@ static int process_sample_event(struct perf_tool *tool 
__used,
if (cpu_list && !test_bit(sample->cpu, cpu_bitmap))
return 0;
 
-   scripting_ops->process_event(event, sample, evsel, machine, thread);
+   scripting_ops->process_event(event, sample, evsel, machine, );
 
evsel->hists.stats.total_period += sample->period;
return 0;
diff --git a/tools/perf/util/scripting-engines/trace-event-perl.c 
b/tools/perf/util/scripting-engines/trace-event-perl.c
index 52580d0..d280010 100644
--- a/tools/perf/util/scripting-engines/trace-event-perl.c
+++ b/tools/perf/util/scripting-engines/trace-event-perl.c
@@ -261,7 +261,7 @@ static void perl_process_tracepoint(union perf_event 
*perf_event __unused,
struct perf_sample *sample,
struct perf_evsel *evsel,
struct machine *machine __unused,
-   struct thread *thread)
+   struct addr_location *al)
 {
struct format_field *field;
static char handler[256];
@@ -272,6 +272,7 @@ static void perl_process_tracepoint(union perf_event 
*perf_event __unused,
int cpu = sample->cpu;
void *data = sample->raw_data;
unsigned long long nsecs = sample->time;
+   struct thread *thread = al->thread;
char *comm = thread->comm;
 
dSP;
@@ -349,7 +350,7 @@ static void perl_process_event_generic(union perf_event 
*event,
   struct perf_sample *sample,
   struct perf_evsel *evsel,
   struct machine *machine __unused,
-  struct thread *thread __unused)
+  struct addr_location *al __unused)
 {
dSP;
 
@@ -375,10 +376,10 @@ static void perl_process_event(union perf_event *event,
   struct perf_sample *sample,
   struct perf_evsel *evsel,
   struct machine *machine,
-  struct thread *thread)
+  struct addr_location *al)
 {
-   perl_process_tracepoint(event, sample, evsel, machine, thread);
-   perl_process_event_generic(event, sample, evsel, machine, thread);
+   perl_process_tracepoint(event, sample, evsel, machine, al);
+   perl_process_event_generic(event, sample, evsel, machine, al);
 }
 
 static void run_start_sub(void)
diff --git a/tools/perf/util/scripting-engines/trace-event-python.c 
b/tools/perf/util/scripting-engines/trace-event-python.c
index b9010d8..24711b3 100644
--- 

[tip:perf/core] perf script: Add general python handler to process non-tracepoint events

2012-08-21 Thread tip-bot for Feng Tang
Commit-ID:  6a6daec2ae9f097703c1da4925367f1c198c9492
Gitweb: http://git.kernel.org/tip/6a6daec2ae9f097703c1da4925367f1c198c9492
Author: Feng Tang 
AuthorDate: Wed, 8 Aug 2012 17:57:51 +0800
Committer:  Arnaldo Carvalho de Melo 
CommitDate: Wed, 8 Aug 2012 12:45:33 -0300

perf script: Add general python handler to process non-tracepoint events

This patch just follows Robert Richter's idea and the commit 37a058ea0
"perf script: Add generic perl handler to process events"
to similarly add a python handler for general events other than tracepoints.

For non-tracepoint events, this patch will try to find a function named
"process_event" in the python script, and pass the event attribute,
perf_sample, raw_data in format of raw string. And the python script can
use "struct" module's unpack function to disasemble the needed info and process.

Signed-off-by: Feng Tang 
Cc: Andi Kleen 
Cc: David Ahern 
Cc: Ingo Molnar 
Cc: Peter Zijlstra 
Cc: Robert Richter 
Cc: Stephane Eranian 
Link: 
http://lkml.kernel.org/r/1344419875-21665-2-git-send-email-feng.t...@intel.com
[ committer note: Fixed up wrt da37896, i.e. pevent parm in script event 
handlers ]
Signed-off-by: Arnaldo Carvalho de Melo 
---
 .../util/scripting-engines/trace-event-python.c|   59 +++-
 1 files changed, 58 insertions(+), 1 deletions(-)

diff --git a/tools/perf/util/scripting-engines/trace-event-python.c 
b/tools/perf/util/scripting-engines/trace-event-python.c
index df7d33d..b9010d8 100644
--- a/tools/perf/util/scripting-engines/trace-event-python.c
+++ b/tools/perf/util/scripting-engines/trace-event-python.c
@@ -32,6 +32,7 @@
 #include "../event.h"
 #include "../thread.h"
 #include "../trace-event.h"
+#include "../evsel.h"
 
 PyMODINIT_FUNC initperf_trace_context(void);
 
@@ -220,7 +221,7 @@ static inline struct event_format *find_cache_event(struct 
perf_evsel *evsel)
return event;
 }
 
-static void python_process_event(union perf_event *perf_event __unused,
+static void python_process_tracepoint(union perf_event *perf_event __unused,
 struct perf_sample *sample,
 struct perf_evsel *evsel,
 struct machine *machine __unused,
@@ -337,6 +338,62 @@ static void python_process_event(union perf_event 
*perf_event __unused,
Py_DECREF(t);
 }
 
+static void python_process_general_event(union perf_event *perf_event __unused,
+struct perf_sample *sample,
+struct perf_evsel *evsel,
+struct machine *machine __unused,
+struct thread *thread __unused)
+{
+   PyObject *handler, *retval, *t;
+   static char handler_name[64];
+   unsigned n = 0;
+   void *data = sample->raw_data;
+
+   t = PyTuple_New(MAX_FIELDS);
+   if (!t)
+   Py_FatalError("couldn't create Python tuple");
+
+   snprintf(handler_name, sizeof(handler_name), "%s", "process_event");
+
+   handler = PyDict_GetItemString(main_dict, handler_name);
+   if (handler && !PyCallable_Check(handler)) {
+   handler = NULL;
+   goto exit;
+   }
+
+   /* Pass 3 parameters: event_attr, perf_sample, raw data */
+   PyTuple_SetItem(t, n++, PyString_FromStringAndSize((void 
*)>attr, sizeof(evsel->attr)));
+   PyTuple_SetItem(t, n++, PyString_FromStringAndSize((void *)sample, 
sizeof(*sample)));
+   PyTuple_SetItem(t, n++, PyString_FromStringAndSize(data, 
sample->raw_size));
+
+   if (_PyTuple_Resize(, n) == -1)
+   Py_FatalError("error resizing Python tuple");
+
+   retval = PyObject_CallObject(handler, t);
+   if (retval == NULL)
+   handler_call_die(handler_name);
+exit:
+   Py_DECREF(t);
+}
+
+static void python_process_event(union perf_event *perf_event,
+struct perf_sample *sample,
+struct perf_evsel *evsel,
+struct machine *machine,
+struct thread *thread)
+{
+   switch (evsel->attr.type) {
+   case PERF_TYPE_TRACEPOINT:
+   python_process_tracepoint(perf_event, sample, evsel,
+ machine, thread);
+   break;
+   /* Reserve for future process_hw/sw/raw APIs */
+   default:
+   python_process_general_event(perf_event, sample, evsel,
+machine, thread);
+   }
+}
+
 static int run_start_sub(void)
 {
PyObject *handler, *retval;
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[tip:perf/core] perf script: Add general python handler to process non-tracepoint events

2012-08-21 Thread tip-bot for Feng Tang
Commit-ID:  6a6daec2ae9f097703c1da4925367f1c198c9492
Gitweb: http://git.kernel.org/tip/6a6daec2ae9f097703c1da4925367f1c198c9492
Author: Feng Tang feng.t...@intel.com
AuthorDate: Wed, 8 Aug 2012 17:57:51 +0800
Committer:  Arnaldo Carvalho de Melo a...@redhat.com
CommitDate: Wed, 8 Aug 2012 12:45:33 -0300

perf script: Add general python handler to process non-tracepoint events

This patch just follows Robert Richter's idea and the commit 37a058ea0
perf script: Add generic perl handler to process events
to similarly add a python handler for general events other than tracepoints.

For non-tracepoint events, this patch will try to find a function named
process_event in the python script, and pass the event attribute,
perf_sample, raw_data in format of raw string. And the python script can
use struct module's unpack function to disasemble the needed info and process.

Signed-off-by: Feng Tang feng.t...@intel.com
Cc: Andi Kleen a...@firstfloor.org
Cc: David Ahern dsah...@gmail.com
Cc: Ingo Molnar mi...@elte.hu
Cc: Peter Zijlstra pet...@infradead.org
Cc: Robert Richter robert.rich...@amd.com
Cc: Stephane Eranian eran...@google.com
Link: 
http://lkml.kernel.org/r/1344419875-21665-2-git-send-email-feng.t...@intel.com
[ committer note: Fixed up wrt da37896, i.e. pevent parm in script event 
handlers ]
Signed-off-by: Arnaldo Carvalho de Melo a...@redhat.com
---
 .../util/scripting-engines/trace-event-python.c|   59 +++-
 1 files changed, 58 insertions(+), 1 deletions(-)

diff --git a/tools/perf/util/scripting-engines/trace-event-python.c 
b/tools/perf/util/scripting-engines/trace-event-python.c
index df7d33d..b9010d8 100644
--- a/tools/perf/util/scripting-engines/trace-event-python.c
+++ b/tools/perf/util/scripting-engines/trace-event-python.c
@@ -32,6 +32,7 @@
 #include ../event.h
 #include ../thread.h
 #include ../trace-event.h
+#include ../evsel.h
 
 PyMODINIT_FUNC initperf_trace_context(void);
 
@@ -220,7 +221,7 @@ static inline struct event_format *find_cache_event(struct 
perf_evsel *evsel)
return event;
 }
 
-static void python_process_event(union perf_event *perf_event __unused,
+static void python_process_tracepoint(union perf_event *perf_event __unused,
 struct perf_sample *sample,
 struct perf_evsel *evsel,
 struct machine *machine __unused,
@@ -337,6 +338,62 @@ static void python_process_event(union perf_event 
*perf_event __unused,
Py_DECREF(t);
 }
 
+static void python_process_general_event(union perf_event *perf_event __unused,
+struct perf_sample *sample,
+struct perf_evsel *evsel,
+struct machine *machine __unused,
+struct thread *thread __unused)
+{
+   PyObject *handler, *retval, *t;
+   static char handler_name[64];
+   unsigned n = 0;
+   void *data = sample-raw_data;
+
+   t = PyTuple_New(MAX_FIELDS);
+   if (!t)
+   Py_FatalError(couldn't create Python tuple);
+
+   snprintf(handler_name, sizeof(handler_name), %s, process_event);
+
+   handler = PyDict_GetItemString(main_dict, handler_name);
+   if (handler  !PyCallable_Check(handler)) {
+   handler = NULL;
+   goto exit;
+   }
+
+   /* Pass 3 parameters: event_attr, perf_sample, raw data */
+   PyTuple_SetItem(t, n++, PyString_FromStringAndSize((void 
*)evsel-attr, sizeof(evsel-attr)));
+   PyTuple_SetItem(t, n++, PyString_FromStringAndSize((void *)sample, 
sizeof(*sample)));
+   PyTuple_SetItem(t, n++, PyString_FromStringAndSize(data, 
sample-raw_size));
+
+   if (_PyTuple_Resize(t, n) == -1)
+   Py_FatalError(error resizing Python tuple);
+
+   retval = PyObject_CallObject(handler, t);
+   if (retval == NULL)
+   handler_call_die(handler_name);
+exit:
+   Py_DECREF(t);
+}
+
+static void python_process_event(union perf_event *perf_event,
+struct perf_sample *sample,
+struct perf_evsel *evsel,
+struct machine *machine,
+struct thread *thread)
+{
+   switch (evsel-attr.type) {
+   case PERF_TYPE_TRACEPOINT:
+   python_process_tracepoint(perf_event, sample, evsel,
+ machine, thread);
+   break;
+   /* Reserve for future process_hw/sw/raw APIs */
+   default:
+   python_process_general_event(perf_event, sample, evsel,
+machine, thread);
+   }
+}
+
 static int run_start_sub(void)
 {
PyObject *handler, *retval;
--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More 

[tip:perf/core] perf script: Replace struct thread with struct addr_location as a parameter for process_event()

2012-08-21 Thread tip-bot for Feng Tang
Commit-ID:  73994dc158a24df4af77d0a76c9702f120f7a6ad
Gitweb: http://git.kernel.org/tip/73994dc158a24df4af77d0a76c9702f120f7a6ad
Author: Feng Tang feng.t...@intel.com
AuthorDate: Wed, 8 Aug 2012 17:57:52 +0800
Committer:  Arnaldo Carvalho de Melo a...@redhat.com
CommitDate: Wed, 8 Aug 2012 12:46:40 -0300

perf script: Replace struct thread with struct addr_location as a parameter 
for process_event()

Both perl and python script start processing events other than trace
points, and it's useful to pass the resolved symbol and the dso info to
the event handler in script for better analysis and statistics.

Struct thread is already a member of struct addr_location, using
addr_location will keep the thread info, while providing additional
symbol and dso info if exist, so that the script itself doesn't need to
bother to do the symbol resolving and dso searching work.

Tested-by: David Ahern dsah...@gmail.com
Signed-off-by: Feng Tang feng.t...@intel.com
Acked-by: David Ahern dsah...@gmail.com
Cc: Andi Kleen a...@firstfloor.org
Cc: David Ahern dsah...@gmail.com
Cc: Ingo Molnar mi...@elte.hu
Cc: Peter Zijlstra pet...@infradead.org
Cc: Robert Richter robert.rich...@amd.com
Cc: Stephane Eranian eran...@google.com
Link: 
http://lkml.kernel.org/r/1344419875-21665-3-git-send-email-feng.t...@intel.com
Signed-off-by: Arnaldo Carvalho de Melo a...@redhat.com
---
 tools/perf/builtin-script.c|5 +++--
 .../perf/util/scripting-engines/trace-event-perl.c |   11 ++-
 .../util/scripting-engines/trace-event-python.c|   13 +++--
 tools/perf/util/trace-event-scripting.c|2 +-
 tools/perf/util/trace-event.h  |5 +++--
 5 files changed, 20 insertions(+), 16 deletions(-)

diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c
index 6425612..30a9cb8 100644
--- a/tools/perf/builtin-script.c
+++ b/tools/perf/builtin-script.c
@@ -396,9 +396,10 @@ static void print_sample_bts(union perf_event *event,
 
 static void process_event(union perf_event *event, struct perf_sample *sample,
  struct perf_evsel *evsel, struct machine *machine,
- struct thread *thread)
+ struct addr_location *al)
 {
struct perf_event_attr *attr = evsel-attr;
+   struct thread *thread = al-thread;
 
if (output[attr-type].fields == 0)
return;
@@ -511,7 +512,7 @@ static int process_sample_event(struct perf_tool *tool 
__used,
if (cpu_list  !test_bit(sample-cpu, cpu_bitmap))
return 0;
 
-   scripting_ops-process_event(event, sample, evsel, machine, thread);
+   scripting_ops-process_event(event, sample, evsel, machine, al);
 
evsel-hists.stats.total_period += sample-period;
return 0;
diff --git a/tools/perf/util/scripting-engines/trace-event-perl.c 
b/tools/perf/util/scripting-engines/trace-event-perl.c
index 52580d0..d280010 100644
--- a/tools/perf/util/scripting-engines/trace-event-perl.c
+++ b/tools/perf/util/scripting-engines/trace-event-perl.c
@@ -261,7 +261,7 @@ static void perl_process_tracepoint(union perf_event 
*perf_event __unused,
struct perf_sample *sample,
struct perf_evsel *evsel,
struct machine *machine __unused,
-   struct thread *thread)
+   struct addr_location *al)
 {
struct format_field *field;
static char handler[256];
@@ -272,6 +272,7 @@ static void perl_process_tracepoint(union perf_event 
*perf_event __unused,
int cpu = sample-cpu;
void *data = sample-raw_data;
unsigned long long nsecs = sample-time;
+   struct thread *thread = al-thread;
char *comm = thread-comm;
 
dSP;
@@ -349,7 +350,7 @@ static void perl_process_event_generic(union perf_event 
*event,
   struct perf_sample *sample,
   struct perf_evsel *evsel,
   struct machine *machine __unused,
-  struct thread *thread __unused)
+  struct addr_location *al __unused)
 {
dSP;
 
@@ -375,10 +376,10 @@ static void perl_process_event(union perf_event *event,
   struct perf_sample *sample,
   struct perf_evsel *evsel,
   struct machine *machine,
-  struct thread *thread)
+  struct addr_location *al)
 {
-   perl_process_tracepoint(event, sample, evsel, machine, thread);
-   perl_process_event_generic(event, sample, evsel, machine, thread);
+   perl_process_tracepoint(event, sample, evsel, machine, al);
+   perl_process_event_generic(event, sample, evsel, machine, al);
 }
 
 

[tip:perf/core] perf scripts python: Pass event/thread/ dso name and symbol info to event handler in python

2012-08-21 Thread tip-bot for Feng Tang
Commit-ID:  fd6b858a1e110c76e701cd9972a284ed2a7bcc33
Gitweb: http://git.kernel.org/tip/fd6b858a1e110c76e701cd9972a284ed2a7bcc33
Author: Feng Tang feng.t...@intel.com
AuthorDate: Wed, 8 Aug 2012 17:57:53 +0800
Committer:  Arnaldo Carvalho de Melo a...@redhat.com
CommitDate: Wed, 8 Aug 2012 12:48:02 -0300

perf scripts python: Pass event/thread/dso name and symbol info to event 
handler in python

Also as suggested by Arnaldo, pack all these parameters to a dictionary,
which is more expandable for adding new parameters while keeping the
compatibility for old scripts.

Signed-off-by: Feng Tang feng.t...@intel.com
Cc: Andi Kleen a...@firstfloor.org
Cc: David Ahern dsah...@gmail.com
Cc: Ingo Molnar mi...@elte.hu
Cc: Peter Zijlstra pet...@infradead.org
Cc: Robert Richter robert.rich...@amd.com
Cc: Stephane Eranian eran...@google.com
Link: 
http://lkml.kernel.org/r/1344419875-21665-4-git-send-email-feng.t...@intel.com
Signed-off-by: Arnaldo Carvalho de Melo a...@redhat.com
---
 .../util/scripting-engines/trace-event-python.c|   35 ---
 1 files changed, 29 insertions(+), 6 deletions(-)

diff --git a/tools/perf/util/scripting-engines/trace-event-python.c 
b/tools/perf/util/scripting-engines/trace-event-python.c
index 24711b3..7e3f576 100644
--- a/tools/perf/util/scripting-engines/trace-event-python.c
+++ b/tools/perf/util/scripting-engines/trace-event-python.c
@@ -345,15 +345,23 @@ static void python_process_general_event(union perf_event 
*perf_event __unused,
 struct machine *machine __unused,
 struct addr_location *al __unused)
 {
-   PyObject *handler, *retval, *t;
+   PyObject *handler, *retval, *t, *dict;
static char handler_name[64];
unsigned n = 0;
-   void *data = sample-raw_data;
+   struct thread *thread = al-thread;
 
+   /*
+* Use the MAX_FIELDS to make the function expandable, though
+* currently there is only one itme for the tuple.
+*/
t = PyTuple_New(MAX_FIELDS);
if (!t)
Py_FatalError(couldn't create Python tuple);
 
+   dict = PyDict_New();
+   if (!dict)
+   Py_FatalError(couldn't create Python dictionary);
+
snprintf(handler_name, sizeof(handler_name), %s, process_event);
 
handler = PyDict_GetItemString(main_dict, handler_name);
@@ -362,11 +370,25 @@ static void python_process_general_event(union perf_event 
*perf_event __unused,
goto exit;
}
 
-   /* Pass 4 parameters: event_attr, perf_sample, raw data, thread name */
-   PyTuple_SetItem(t, n++, PyString_FromStringAndSize((void 
*)evsel-attr, sizeof(evsel-attr)));
-   PyTuple_SetItem(t, n++, PyString_FromStringAndSize((void *)sample, 
sizeof(*sample)));
-   PyTuple_SetItem(t, n++, PyString_FromStringAndSize(data, 
sample-raw_size));
+   PyDict_SetItemString(dict, ev_name, 
PyString_FromString(perf_evsel__name(evsel)));
+   PyDict_SetItemString(dict, attr, PyString_FromStringAndSize(
+   (const char *)evsel-attr, sizeof(evsel-attr)));
+   PyDict_SetItemString(dict, sample, PyString_FromStringAndSize(
+   (const char *)sample, sizeof(*sample)));
+   PyDict_SetItemString(dict, raw_buf, PyString_FromStringAndSize(
+   (const char *)sample-raw_data, sample-raw_size));
+   PyDict_SetItemString(dict, comm,
+   PyString_FromString(thread-comm));
+   if (al-map) {
+   PyDict_SetItemString(dict, dso,
+   PyString_FromString(al-map-dso-name));
+   }
+   if (al-sym) {
+   PyDict_SetItemString(dict, symbol,
+   PyString_FromString(al-sym-name));
+   }
 
+   PyTuple_SetItem(t, n++, dict);
if (_PyTuple_Resize(t, n) == -1)
Py_FatalError(error resizing Python tuple);
 
@@ -374,6 +396,7 @@ static void python_process_general_event(union perf_event 
*perf_event __unused,
if (retval == NULL)
handler_call_die(handler_name);
 exit:
+   Py_DECREF(dict);
Py_DECREF(t);
 }
 
--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[tip:perf/core] perf scripts python: Add a python library EventClass.py

2012-08-21 Thread tip-bot for Feng Tang
Commit-ID:  02f1c33f7d630183518ea42d45a6acf275541b08
Gitweb: http://git.kernel.org/tip/02f1c33f7d630183518ea42d45a6acf275541b08
Author: Feng Tang feng.t...@intel.com
AuthorDate: Wed, 8 Aug 2012 17:57:54 +0800
Committer:  Arnaldo Carvalho de Melo a...@redhat.com
CommitDate: Wed, 8 Aug 2012 12:53:08 -0300

perf scripts python: Add a python library EventClass.py

This library defines several class types for perf events which could
help to better analyze the event samples. Currently there are just a few
classes, PerfEvent is the base class for all perf events,  PebsEvent is
a HW base Intel x86 PEBS event, and user could add more SW/HW event
classes based on requriements.

Signed-off-by: Feng Tang feng.t...@intel.com
Cc: Andi Kleen a...@firstfloor.org
Cc: David Ahern dsah...@gmail.com
Cc: Ingo Molnar mi...@elte.hu
Cc: Peter Zijlstra pet...@infradead.org
Cc: Robert Richter robert.rich...@amd.com
Cc: Stephane Eranian eran...@google.com
Link: 
http://lkml.kernel.org/r/1344419875-21665-5-git-send-email-feng.t...@intel.com
Signed-off-by: Arnaldo Carvalho de Melo a...@redhat.com
---
 .../Perf-Trace-Util/lib/Perf/Trace/EventClass.py   |   94 
 1 files changed, 94 insertions(+), 0 deletions(-)

diff --git 
a/tools/perf/scripts/python/Perf-Trace-Util/lib/Perf/Trace/EventClass.py 
b/tools/perf/scripts/python/Perf-Trace-Util/lib/Perf/Trace/EventClass.py
new file mode 100755
index 000..6372431
--- /dev/null
+++ b/tools/perf/scripts/python/Perf-Trace-Util/lib/Perf/Trace/EventClass.py
@@ -0,0 +1,94 @@
+# EventClass.py
+#
+# This is a libray defining some events typs classes, which could
+# be used by other scripts to analyzing the perf samples.
+#
+# Currently there are just a few classes defined for examples,
+# PerfEvent is the base class for all perf event sample, PebsEvent
+# is a HW base Intel x86 PEBS event, and user could add more SW/HW
+# event classes based on requriements.
+
+import struct
+
+# Event types, user could add more here
+EVTYPE_GENERIC  = 0
+EVTYPE_PEBS = 1 # Basic PEBS event
+EVTYPE_PEBS_LL  = 2 # PEBS event with load latency info
+EVTYPE_IBS  = 3
+
+#
+# Currently we don't have good way to tell the event type, but by
+# the size of raw buffer, raw PEBS event with load latency data's
+# size is 176 bytes, while the pure PEBS event's size is 144 bytes.
+#
+def create_event(name, comm, dso, symbol, raw_buf):
+if (len(raw_buf) == 144):
+event = PebsEvent(name, comm, dso, symbol, raw_buf)
+elif (len(raw_buf) == 176):
+event = PebsNHM(name, comm, dso, symbol, raw_buf)
+else:
+event = PerfEvent(name, comm, dso, symbol, raw_buf)
+
+return event
+
+class PerfEvent(object):
+event_num = 0
+def __init__(self, name, comm, dso, symbol, raw_buf, 
ev_type=EVTYPE_GENERIC):
+self.name   = name
+self.comm   = comm
+self.dso= dso
+self.symbol = symbol
+self.raw_buf= raw_buf
+self.ev_type= ev_type
+PerfEvent.event_num += 1
+
+def show(self):
+print PMU event: name=%12s, symbol=%24s, comm=%8s, dso=%12s 
% (self.name, self.symbol, self.comm, self.dso)
+
+#
+# Basic Intel PEBS (Precise Event-based Sampling) event, whose raw buffer
+# contains the context info when that event happened: the EFLAGS and
+# linear IP info, as well as all the registers.
+#
+class PebsEvent(PerfEvent):
+pebs_num = 0
+def __init__(self, name, comm, dso, symbol, raw_buf, 
ev_type=EVTYPE_PEBS):
+tmp_buf=raw_buf[0:80]
+flags, ip, ax, bx, cx, dx, si, di, bp, sp = 
struct.unpack('QQ', tmp_buf)
+self.flags = flags
+self.ip= ip
+self.ax= ax
+self.bx= bx
+self.cx= cx
+self.dx= dx
+self.si= si
+self.di= di
+self.bp= bp
+self.sp= sp
+
+PerfEvent.__init__(self, name, comm, dso, symbol, raw_buf, 
ev_type)
+PebsEvent.pebs_num += 1
+del tmp_buf
+
+#
+# Intel Nehalem and Westmere support PEBS plus Load Latency info which lie
+# in the four 64 bit words write after the PEBS data:
+#   Status: records the IA32_PERF_GLOBAL_STATUS register value
+#   DLA:Data Linear Address (EIP)
+#   DSE:Data Source Encoding, where the latency happens, hit or miss
+#   in L1/L2/L3 or IO operations
+#   LAT:the actual latency in cycles
+#
+class PebsNHM(PebsEvent):
+pebs_nhm_num = 0
+def __init__(self, name, comm, dso, symbol, raw_buf, 
ev_type=EVTYPE_PEBS_LL):
+tmp_buf=raw_buf[144:176]
+status, dla, dse, lat = struct.unpack('', tmp_buf)
+self.status = status
+

[tip:perf/core] perf scripts python: Add event_analyzing_sample. py as a sample for general event handling

2012-08-21 Thread tip-bot for Feng Tang
Commit-ID:  0076d546b4f9b5c15121c6959d108a83fe43fa9a
Gitweb: http://git.kernel.org/tip/0076d546b4f9b5c15121c6959d108a83fe43fa9a
Author: Feng Tang feng.t...@intel.com
AuthorDate: Wed, 8 Aug 2012 17:57:55 +0800
Committer:  Arnaldo Carvalho de Melo a...@redhat.com
CommitDate: Wed, 8 Aug 2012 12:55:38 -0300

perf scripts python: Add event_analyzing_sample.py as a sample for general 
event handling

Currently only trace point events are supported in perf/python script,
the first 3 patches of this serie add the support for all types of
events. This script is just a simple sample to show how to gather the
basic information of the events and analyze them.

This script will create one object for each event sample and insert them
into a table in a database, then leverage the simple SQL commands to
sort/group them. User can modify or write their brand new functions
according to their specific requirment.

Here is the sample of how to use the script:

 $ perf record -a tree
 $ perf script -s process_event.py

There is 100 records in gen_events table
Statistics about the general events grouped by thread/symbol/dso:

comm   number histgram
==
 swapper   56 ##
tree   20 #
perf   10 
sshd8 
 kworker/7:24 ###
 ksoftirqd/71 #
 plugin-containe1 #

  symbol   number histgram
==
   native_write_msr_safe   40 ##
  __lock_acquire8 
 ftrace_graph_caller4 ###
   prepare_ftrace_return4 ###
  intel_idle3 ##
  native_sched_clock3 ##
  Unknown_symbol2 ##
  do_softirq2 ##
lock_release2 ##
   lock_release_holdtime2 ##
   trace_graph_entry2 ##
_IO_putc1 #
  __d_lookup_rcu1 #
  __do_fault1 #
  __schedule1 #
  _raw_spin_lock1 #
   delay_tsc1 #
 generic_exec_single1 #
generic_fillattr1 #

 dso   number histgram
==
   [kernel.kallsyms]   95 ###
 /lib/libc-2.12.1.so5 ###

Signed-off-by: Feng Tang feng.t...@intel.com
Cc: Andi Kleen a...@firstfloor.org
Cc: David Ahern dsah...@gmail.com
Cc: Ingo Molnar mi...@elte.hu
Cc: Peter Zijlstra pet...@infradead.org
Cc: Robert Richter robert.rich...@amd.com
Cc: Stephane Eranian eran...@google.com
Link: 
http://lkml.kernel.org/r/1344419875-21665-6-git-send-email-feng.t...@intel.com
Signed-off-by: Arnaldo Carvalho de Melo a...@redhat.com
---
 .../perf/scripts/python/event_analyzing_sample.py  |  193 
 1 files changed, 193 insertions(+), 0 deletions(-)

diff --git a/tools/perf/scripts/python/event_analyzing_sample.py 
b/tools/perf/scripts/python/event_analyzing_sample.py
new file mode 100644
index 000..46f05aa
--- /dev/null
+++ b/tools/perf/scripts/python/event_analyzing_sample.py
@@ -0,0 +1,193 @@
+# process_event.py: general event handler in python
+#
+# Current perf report is alreay very powerful with the anotation integrated,
+# and this script is not trying to be as powerful as perf report, but
+# providing end user/developer a flexible way to analyze the events other
+# than trace points.
+#
+# The 2 database related functions in this script just show how to gather
+# the basic information, and users can modify and write their own functions
+# according to their specific requirment.
+#
+# The first sample show_general_events just does a baisc grouping for all
+# generic events with the help of sqlite, and the 2nd one show_pebs_ll is
+# for a x86 HW PMU event: PEBS with load latency data.
+#
+
+import os
+import sys
+import math
+import struct
+import sqlite3
+
+sys.path.append(os.environ['PERF_EXEC_PATH'] + \
+'/scripts/python/Perf-Trace-Util/lib/Perf/Trace')
+
+from perf_trace_context import *
+from EventClass import *
+
+#
+# If the perf.data has a big number of samples, then the insert operation
+# will be very time consuming (about 10+ minutes for 1 samples) if the
+# .db database is on disk. Move the .db file to RAM based FS to speedup
+# the handling, which will cut the time down to several seconds.
+#
+con = sqlite3.connect(/dev/shm/perf.db)
+con.isolation_level = None
+
+def trace_begin():
+   print In trace_begin:\n
+
+#
+# Will create several tables at the 

[tip:perf/core] perf script python: Correct handler check and spelling errors

2012-08-21 Thread tip-bot for Feng Tang
Commit-ID:  87b6a3ad40ba304ec468b972e979e7e410852476
Gitweb: http://git.kernel.org/tip/87b6a3ad40ba304ec468b972e979e7e410852476
Author: Feng Tang feng.t...@intel.com
AuthorDate: Thu, 9 Aug 2012 13:46:13 +0800
Committer:  Arnaldo Carvalho de Melo a...@redhat.com
CommitDate: Thu, 9 Aug 2012 13:26:19 -0300

perf script python: Correct handler check and spelling errors

Correct the checking for handler returned by PyDict_GetItemString(),
also fix some spelling error and remove some data code in
event_analyzing_sample.py, as suggested by Namhyung Kim.

v2: restore back the wrongly removed trace_unhandled() func

Signed-off-by: Feng Tang feng.t...@intel.com
Acked-by: Namhyung Kim namhy...@kernel.org
Cc: Andi Kleen a...@firstfloor.org
Cc: David Ahern dsah...@gmail.com
Cc: Ingo Molnar mi...@kernel.org
Cc: Namhyung Kim namhy...@kernel.org
Cc: Peter Zijlstra pet...@infradead.org
Cc: Robert Richter robert.rich...@amd.com
Cc: Stephane Eranian eran...@google.com
Link: http://lkml.kernel.org/r/20120809134613.067104c4@feng-i7
Signed-off-by: Arnaldo Carvalho de Melo a...@redhat.com
---
 .../Perf-Trace-Util/lib/Perf/Trace/EventClass.py   |4 +-
 .../perf/scripts/python/event_analyzing_sample.py  |   30 ---
 .../util/scripting-engines/trace-event-python.c|8 ++---
 3 files changed, 18 insertions(+), 24 deletions(-)

diff --git 
a/tools/perf/scripts/python/Perf-Trace-Util/lib/Perf/Trace/EventClass.py 
b/tools/perf/scripts/python/Perf-Trace-Util/lib/Perf/Trace/EventClass.py
index 6372431..9e098579 100755
--- a/tools/perf/scripts/python/Perf-Trace-Util/lib/Perf/Trace/EventClass.py
+++ b/tools/perf/scripts/python/Perf-Trace-Util/lib/Perf/Trace/EventClass.py
@@ -1,12 +1,12 @@
 # EventClass.py
 #
-# This is a libray defining some events typs classes, which could
+# This is a library defining some events types classes, which could
 # be used by other scripts to analyzing the perf samples.
 #
 # Currently there are just a few classes defined for examples,
 # PerfEvent is the base class for all perf event sample, PebsEvent
 # is a HW base Intel x86 PEBS event, and user could add more SW/HW
-# event classes based on requriements.
+# event classes based on requirements.
 
 import struct
 
diff --git a/tools/perf/scripts/python/event_analyzing_sample.py 
b/tools/perf/scripts/python/event_analyzing_sample.py
index 46f05aa..163c39f 100644
--- a/tools/perf/scripts/python/event_analyzing_sample.py
+++ b/tools/perf/scripts/python/event_analyzing_sample.py
@@ -1,15 +1,15 @@
-# process_event.py: general event handler in python
+# event_analyzing_sample.py: general event handler in python
 #
-# Current perf report is alreay very powerful with the anotation integrated,
+# Current perf report is already very powerful with the annotation integrated,
 # and this script is not trying to be as powerful as perf report, but
 # providing end user/developer a flexible way to analyze the events other
 # than trace points.
 #
 # The 2 database related functions in this script just show how to gather
 # the basic information, and users can modify and write their own functions
-# according to their specific requirment.
+# according to their specific requirement.
 #
-# The first sample show_general_events just does a baisc grouping for all
+# The first function show_general_events just does a basic grouping for all
 # generic events with the help of sqlite, and the 2nd one show_pebs_ll is
 # for a x86 HW PMU event: PEBS with load latency data.
 #
@@ -85,7 +85,7 @@ def process_event(param_dict):
 else:
 symbol = Unknown_symbol
 
-# Creat the event object and insert it to the right table in database
+# Create the event object and insert it to the right table in database
 event = create_event(name, comm, dso, symbol, raw_buf)
 insert_db(event)
 
@@ -109,7 +109,7 @@ def trace_end():
 
 #
 # As the event number may be very big, so we can't use linear way
-# to show the histgram in real number, but use a log2 algorithm.
+# to show the histogram in real number, but use a log2 algorithm.
 #
 
 def num2sym(num):
@@ -130,18 +130,18 @@ def show_general_events():
 
  # Group by thread
 commq = con.execute(select comm, count(comm) from gen_events group by 
comm order by -count(comm))
-print \n%16s %8s %16s\n%s % (comm, number, histgram, =*42)
+print \n%16s %8s %16s\n%s % (comm, number, histogram, =*42)
 for row in commq:
  print %16s %8d %s % (row[0], row[1], num2sym(row[1]))
 
 # Group by symbol
-print \n%32s %8s %16s\n%s % (symbol, number, histgram, =*58)
+print \n%32s %8s %16s\n%s % (symbol, number, histogram, =*58)
 symbolq = con.execute(select symbol, count(symbol) from gen_events 
group by symbol order by -count(symbol))
 for row in symbolq:
  print %32s %8d %s % (row[0], row[1], num2sym(row[1]))
 
 # Group by dso
-print \n%40s %8s %16s\n%s % (dso,