[PATCH 20/25] serial: sh-sci: Add support for optional BRG on (H)SCIF

2015-11-19 Thread Geert Uytterhoeven
Add support for the Baud Rate Generator for External Clock (BRG), as
found on some SCIF and HSCIF variants, which can improve baud rate range
and accuracy.

Signed-off-by: Geert Uytterhoeven 
---
 drivers/tty/serial/sh-sci.c | 82 ++---
 1 file changed, 77 insertions(+), 5 deletions(-)

diff --git a/drivers/tty/serial/sh-sci.c b/drivers/tty/serial/sh-sci.c
index f88aac684ed1e3b6..6b8f1675b9f6fadb 100644
--- a/drivers/tty/serial/sh-sci.c
+++ b/drivers/tty/serial/sh-sci.c
@@ -80,6 +80,8 @@ enum {
 enum SCI_CLKS {
SCI_FCK,/* Functional Clock */
SCI_SCK,/* Optional External Clock */
+   SCI_INT_CLK,/* Optional BRG Internal Clock Source */
+   SCI_SCIF_CLK,   /* Optional BRG External Clock Source */
SCI_NUM_CLKS
 };
 
@@ -1955,6 +1957,40 @@ static int sci_sck_calc(struct sci_port *s, unsigned int 
bps,
return min_err;
 }
 
+static int sci_brg_calc(struct sci_port *s, unsigned int bps,
+   unsigned long freq, unsigned int *dlr,
+   unsigned int *srr)
+{
+   unsigned int min_sr, max_sr, sr, dl;
+   int err, min_err = INT_MAX;
+
+   if (s->sampling_rate) {
+   /* SCIF has a fixed sampling rate */
+   min_sr = max_sr = s->sampling_rate / 2;
+   } else {
+   /* HSCIF has a variable 1/(8..32) sampling rate */
+   min_sr = 8;
+   max_sr = 32;
+   }
+
+   for (sr = max_sr; sr >= min_sr; sr--) {
+   dl = DIV_ROUND_CLOSEST(freq, sr * bps);
+   dl = clamp(dl, 1U, 65535U);
+
+   err = DIV_ROUND_CLOSEST(freq, sr * dl) - bps;
+   if (abs(err) >= abs(min_err))
+   continue;
+
+   min_err = err;
+   *dlr = dl;
+   *srr = sr - 1;
+   }
+
+   dev_dbg(s->port.dev, "BRG: %u%+d bps using DL %u SR %u\n", bps,
+   min_err, *dlr, *srr + 1);
+   return min_err;
+}
+
 /* calculate sample rate, BRR, and clock select */
 static int sci_scbrr_calc(struct sci_port *s, unsigned int bps,
  unsigned int *brr, unsigned int *srr,
@@ -2036,8 +2072,8 @@ static void sci_set_termios(struct uart_port *port, 
struct ktermios *termios,
struct ktermios *old)
 {
unsigned int baud, smr_val = 0, scr_val = 0, i;
-   unsigned int brr = 255, cks = 0, srr = 15, sccks = 0;
-   unsigned int brr1 = 255, cks1 = 0, srr1 = 15;
+   unsigned int brr = 255, cks = 0, srr = 15, dl = 0, sccks = 0;
+   unsigned int brr1 = 255, cks1 = 0, srr1 = 15, dl1 = 0;
struct sci_port *s = to_sci_port(port);
const struct plat_sci_reg *reg;
int min_err = INT_MAX, err;
@@ -2089,6 +2125,38 @@ static void sci_set_termios(struct uart_port *port, 
struct ktermios *termios,
}
}
 
+   /* Optional BRG External Clock Source */
+   if (s->clk_rates[SCI_SCIF_CLK] && sci_getreg(port, SCDL)->size) {
+   err = sci_brg_calc(s, baud, s->clk_rates[SCI_SCIF_CLK], ,
+  );
+   if (abs(err) < abs(min_err)) {
+   best_clk = SCI_SCIF_CLK;
+   scr_val = SCSCR_CKE1;
+   sccks = 0;
+   min_err = err;
+   dl = dl1;
+   srr = srr1;
+   if (!err)
+   goto done;
+   }
+   }
+
+   /* Optional BRG Internal Clock Source */
+   if (s->clk_rates[SCI_INT_CLK] && sci_getreg(port, SCDL)->size) {
+   err = sci_brg_calc(s, baud, s->clk_rates[SCI_INT_CLK], ,
+  );
+   if (abs(err) < abs(min_err)) {
+   best_clk = SCI_INT_CLK;
+   scr_val = SCSCR_CKE1;
+   sccks = SCCKS_XIN;
+   min_err = err;
+   dl = dl1;
+   srr = srr1;
+   if (!min_err)
+   goto done;
+   }
+   }
+
/* Functional Clock and standard Bit Rate Register */
err = sci_scbrr_calc(s, baud, , , );
if (abs(err) < abs(min_err)) {
@@ -2108,8 +2176,10 @@ done:
sci_port_enable(s);
 
/* Program the optional External Baud Rate Generator (BRG) first */
-   if (best_clk >= 0 && sci_getreg(port, SCCKS)->size)
+   if (best_clk >= 0 && sci_getreg(port, SCCKS)->size) {
+   serial_port_out(port, SCDL, dl);
serial_port_out(port, SCCKS, sccks);
+   }
 
sci_reset(port);
 
@@ -2118,8 +2188,8 @@ done:
if (best_clk >= 0) {
smr_val |= cks;
dev_dbg(port->dev,
-"SCR 0x%x SMR 0x%x BRR %u CKS 0x%x SRR %u\n",
-scr_val, smr_val, brr, 

[PATCH 06/25] serial: sh-sci: Don't overwrite clock selection in serial_console_write()

2015-11-19 Thread Geert Uytterhoeven
Blindly writing the default configuration value into the SCSCR register
may change the clock selection bits, breaking the serial console if the
current driver settings differ from the default settings.

Keep the current clock selection bits to prevent this from happening
on e.g. r8a7791/koelsch when support for the BRG will be added.

Signed-off-by: Geert Uytterhoeven 
---
 drivers/tty/serial/sh-sci.c | 8 +---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/drivers/tty/serial/sh-sci.c b/drivers/tty/serial/sh-sci.c
index 7c7dfbce54ed9c19..cba51da604253db6 100644
--- a/drivers/tty/serial/sh-sci.c
+++ b/drivers/tty/serial/sh-sci.c
@@ -2415,7 +2415,7 @@ static void serial_console_write(struct console *co, 
const char *s,
 {
struct sci_port *sci_port = _ports[co->index];
struct uart_port *port = _port->port;
-   unsigned short bits, ctrl;
+   unsigned short bits, ctrl, ctrl_temp;
unsigned long flags;
int locked = 1;
 
@@ -2427,9 +2427,11 @@ static void serial_console_write(struct console *co, 
const char *s,
else
spin_lock(>lock);
 
-   /* first save the SCSCR then disable the interrupts */
+   /* first save SCSCR then disable interrupts, keep clock source */
ctrl = serial_port_in(port, SCSCR);
-   serial_port_out(port, SCSCR, sci_port->cfg->scscr);
+   ctrl_temp = (sci_port->cfg->scscr & ~(SCSCR_CKE1 | SCSCR_CKE0)) |
+   (ctrl & (SCSCR_CKE1 | SCSCR_CKE0));
+   serial_port_out(port, SCSCR, ctrl_temp);
 
uart_console_write(port, s, count, serial_console_putchar);
 
-- 
1.9.1

--
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/


[PATCH 03/25] serial: sh-sci: Drop useless check for zero sampling_rate

2015-11-19 Thread Geert Uytterhoeven
sci_port.sampling_rate is always non-zero, except for HSCIF, which uses
sci_baud_calc_hscif() instead of sci_scbrr_calc().

Signed-off-by: Geert Uytterhoeven 
---
 drivers/tty/serial/sh-sci.c | 8 +---
 1 file changed, 1 insertion(+), 7 deletions(-)

diff --git a/drivers/tty/serial/sh-sci.c b/drivers/tty/serial/sh-sci.c
index bee5b7025adf45a2..ae136a1632e6298d 100644
--- a/drivers/tty/serial/sh-sci.c
+++ b/drivers/tty/serial/sh-sci.c
@@ -1863,13 +1863,7 @@ static void sci_shutdown(struct uart_port *port)
 static unsigned int sci_scbrr_calc(struct sci_port *s, unsigned int bps,
   unsigned long freq)
 {
-   if (s->sampling_rate)
-   return DIV_ROUND_CLOSEST(freq, s->sampling_rate * bps) - 1;
-
-   /* Warn, but use a safe default */
-   WARN_ON(1);
-
-   return ((freq + 16 * bps) / (32 * bps) - 1);
+   return DIV_ROUND_CLOSEST(freq, s->sampling_rate * bps) - 1;
 }
 
 /* calculate frame length from SMR */
-- 
1.9.1

--
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/


[PATCH 16/25] serial: sh-sci: Correct SCIF type on RZ/A1H

2015-11-19 Thread Geert Uytterhoeven
The "renesas,scif" compatible value is currently used for the SCIF
variant in all Renesas SoCs of the R-Car and RZ families.  However, the
variant used in the RZ family is not the common "SH-4(A)" variant, but
the "SH-2(A) with FIFO data count register" variant, as it has the
"Serial Extension Mode Register" (SCEMR), just like on sh7203, sh7263,
sh7264, and sh7269.

Use the (already documented) SoC-specific "renesas,scif-r7s72100"
compatible value to differentiate.  The "renesas,scif" compatible value
can still be used as a common denominator for SCIF variants with the
"SH-4(A)" register layout (i.e. ignoring the SCEMR register).
Note that currently both variants are treated the same, but this may
change if support for the SCEMR register is ever added.

Signed-off-by: Geert Uytterhoeven 
---
 drivers/tty/serial/sh-sci.c | 6 ++
 1 file changed, 6 insertions(+)

diff --git a/drivers/tty/serial/sh-sci.c b/drivers/tty/serial/sh-sci.c
index 41351ae055de661f..b0127f38af744fcf 100644
--- a/drivers/tty/serial/sh-sci.c
+++ b/drivers/tty/serial/sh-sci.c
@@ -2601,6 +2601,12 @@ static int sci_remove(struct platform_device *dev)
 #define SCI_OF_REGTYPE(data)   ((unsigned long)(data) & 0x)
 
 static const struct of_device_id of_sci_match[] = {
+   /* SoC-specific types */
+   {
+   .compatible = "renesas,scif-r7s72100",
+   .data = SCI_OF_DATA(PORT_SCIF, SCIx_SH2_SCIF_FIFODATA_REGTYPE),
+   },
+   /* Generic types */
{
.compatible = "renesas,scif",
.data = SCI_OF_DATA(PORT_SCIF, SCIx_SH4_SCIF_REGTYPE),
-- 
1.9.1

--
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/


[PATCH 17/25] serial: sh-sci: Correct SCIF type on R-Car for BRG

2015-11-19 Thread Geert Uytterhoeven
The "renesas,scif" compatible value is currently used for the SCIF
variant in all Renesas SoCs of the R-Car family.  However, the variant
used in the R-Car family is not the common "SH-4(A)" variant, but a
derivative with added "Baud Rate Generator for External Clock" (BRG),
which is also present in sh7734.

Use the (already documented) SoC-specific SCIF compatible values for all
supported R-Car Gen1, Gen2, and Gen3 SoCs to differentiate.  The
"renesas,scif" compatible value can still be used as a common
denominator for SCIF variants with the "SH-4(A)" register layout (i.e.
ignoring the "Serial Extension Mode Register" (SCEMR) and the new
BRG-specific registers).

Signed-off-by: Geert Uytterhoeven 
---
 drivers/tty/serial/sh-sci.c | 24 
 1 file changed, 24 insertions(+)

diff --git a/drivers/tty/serial/sh-sci.c b/drivers/tty/serial/sh-sci.c
index b0127f38af744fcf..726c96d5a511c222 100644
--- a/drivers/tty/serial/sh-sci.c
+++ b/drivers/tty/serial/sh-sci.c
@@ -2605,6 +2605,30 @@ static const struct of_device_id of_sci_match[] = {
{
.compatible = "renesas,scif-r7s72100",
.data = SCI_OF_DATA(PORT_SCIF, SCIx_SH2_SCIF_FIFODATA_REGTYPE),
+   }, {
+   .compatible = "renesas,scif-r8a7778",
+   .data = SCI_OF_DATA(PORT_SCIF, SCIx_SH4_SCIF_BRG_REGTYPE),
+   }, {
+   .compatible = "renesas,scif-r8a7779",
+   .data = SCI_OF_DATA(PORT_SCIF, SCIx_SH4_SCIF_BRG_REGTYPE),
+   }, {
+   .compatible = "renesas,scif-r8a7790",
+   .data = SCI_OF_DATA(PORT_SCIF, SCIx_SH4_SCIF_BRG_REGTYPE),
+   }, {
+   .compatible = "renesas,scif-r8a7791",
+   .data = SCI_OF_DATA(PORT_SCIF, SCIx_SH4_SCIF_BRG_REGTYPE),
+   }, {
+   .compatible = "renesas,scif-r8a7792",
+   .data = SCI_OF_DATA(PORT_SCIF, SCIx_SH4_SCIF_BRG_REGTYPE),
+   }, {
+   .compatible = "renesas,scif-r8a7793",
+   .data = SCI_OF_DATA(PORT_SCIF, SCIx_SH4_SCIF_BRG_REGTYPE),
+   }, {
+   .compatible = "renesas,scif-r8a7794",
+   .data = SCI_OF_DATA(PORT_SCIF, SCIx_SH4_SCIF_BRG_REGTYPE),
+   }, {
+   .compatible = "renesas,scif-r8a7795",
+   .data = SCI_OF_DATA(PORT_SCIF, SCIx_SH4_SCIF_BRG_REGTYPE),
},
/* Generic types */
{
-- 
1.9.1

--
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/


[PATCH 19/25] serial: sh-sci: Add support for optional external (H)SCK input

2015-11-19 Thread Geert Uytterhoeven
Add support for using the SCIx clock pin "(H)SCK" as an external clock
input on (H)SCI(F).

Note that this feature is not yet supported on the select SCIFA variants
that also have it (e.g. sh7723, sh7724, and r8a7740).

On (H)SCIF variants with an External Baud Rate Generator (BRG), the
BRG Clock Select Register must be configured for the external clock.

Signed-off-by: Geert Uytterhoeven 
---
 drivers/tty/serial/sh-sci.c | 63 ++---
 1 file changed, 60 insertions(+), 3 deletions(-)

diff --git a/drivers/tty/serial/sh-sci.c b/drivers/tty/serial/sh-sci.c
index 12800e52f41953dc..f88aac684ed1e3b6 100644
--- a/drivers/tty/serial/sh-sci.c
+++ b/drivers/tty/serial/sh-sci.c
@@ -79,6 +79,7 @@ enum {
 
 enum SCI_CLKS {
SCI_FCK,/* Functional Clock */
+   SCI_SCK,/* Optional External Clock */
SCI_NUM_CLKS
 };
 
@@ -1924,6 +1925,36 @@ static void sci_shutdown(struct uart_port *port)
sci_free_irq(s);
 }
 
+static int sci_sck_calc(struct sci_port *s, unsigned int bps,
+   unsigned int *srr)
+{
+   unsigned long freq = s->clk_rates[SCI_SCK];
+   unsigned int min_sr, max_sr, sr;
+   int err, min_err = INT_MAX;
+
+   if (s->sampling_rate) {
+   /* SCI(F) has a fixed sampling rate */
+   min_sr = max_sr = s->sampling_rate / 2;
+   } else {
+   /* HSCIF has a variable 1/(8..32) sampling rate */
+   min_sr = 8;
+   max_sr = 32;
+   }
+
+   for (sr = max_sr; sr >= min_sr; sr--) {
+   err = DIV_ROUND_CLOSEST(freq, sr) - bps;
+   if (abs(err) >= abs(min_err))
+   continue;
+
+   min_err = err;
+   *srr = sr - 1;
+   }
+
+   dev_dbg(s->port.dev, "SCK: %u%+d bps using SR %u\n", bps, min_err,
+   *srr + 1);
+   return min_err;
+}
+
 /* calculate sample rate, BRR, and clock select */
 static int sci_scbrr_calc(struct sci_port *s, unsigned int bps,
  unsigned int *brr, unsigned int *srr,
@@ -2005,7 +2036,7 @@ static void sci_set_termios(struct uart_port *port, 
struct ktermios *termios,
struct ktermios *old)
 {
unsigned int baud, smr_val = 0, scr_val = 0, i;
-   unsigned int brr = 255, cks = 0, srr = 15;
+   unsigned int brr = 255, cks = 0, srr = 15, sccks = 0;
unsigned int brr1 = 255, cks1 = 0, srr1 = 15;
struct sci_port *s = to_sci_port(port);
const struct plat_sci_reg *reg;
@@ -2043,10 +2074,26 @@ static void sci_set_termios(struct uart_port *port, 
struct ktermios *termios,
if (!baud)
goto done;
 
+   /* Optional External Clock */
+   if (s->clk_rates[SCI_SCK] && port->type != PORT_SCIFA &&
+   port->type != PORT_SCIFB) {
+   err = sci_sck_calc(s, baud, );
+   if (abs(err) < abs(min_err)) {
+   best_clk = SCI_SCK;
+   scr_val = SCSCR_CKE1;
+   sccks = SCCKS_CKS;
+   min_err = err;
+   srr = srr1;
+   if (!err)
+   goto done;
+   }
+   }
+
/* Functional Clock and standard Bit Rate Register */
err = sci_scbrr_calc(s, baud, , , );
if (abs(err) < abs(min_err)) {
best_clk = SCI_FCK;
+   scr_val = 0;
min_err = err;
brr = brr1;
srr = srr1;
@@ -2060,14 +2107,20 @@ done:
 
sci_port_enable(s);
 
+   /* Program the optional External Baud Rate Generator (BRG) first */
+   if (best_clk >= 0 && sci_getreg(port, SCCKS)->size)
+   serial_port_out(port, SCCKS, sccks);
+
sci_reset(port);
 
uart_update_timeout(port, termios->c_cflag, baud);
 
if (best_clk >= 0) {
smr_val |= cks;
-   dev_dbg(port->dev, "SMR 0x%x BRR %u SRR %u\n", smr_val, brr,
-   srr);
+   dev_dbg(port->dev,
+"SCR 0x%x SMR 0x%x BRR %u CKS 0x%x SRR %u\n",
+scr_val, smr_val, brr, sccks, srr);
+   serial_port_out(port, SCSCR, scr_val);
serial_port_out(port, SCSMR, smr_val);
serial_port_out(port, SCBRR, brr);
if (sci_getreg(port, HSSRR)->size)
@@ -2303,10 +2356,14 @@ static int sci_init_clocks(struct sci_port *sci_port, 
struct device *dev)
 {
const char *clk_names[] = {
[SCI_FCK] = "fck",
+   [SCI_SCK] = "sck",
};
struct clk *clk;
unsigned int i;
 
+   if (sci_port->cfg->type == PORT_HSCIF)
+   clk_names[SCI_SCK] = "hsck";
+
for (i = 0; i < SCI_NUM_CLKS; i++) {
clk = devm_clk_get(dev, clk_names[i]);
if (PTR_ERR(clk) == -EPROBE_DEFER)
-- 
1.9.1

--

[PATCH 05/25] serial: sh-sci: Drop unused frame_len parameter for sci_baud_calc_hscif()

2015-11-19 Thread Geert Uytterhoeven
As F is assumed to be zero in the receive margin formula, frame_len is
not used. Remove it, together with the sci_baud_calc_frame_len() helper
function.

Signed-off-by: Geert Uytterhoeven 
---
 drivers/tty/serial/sh-sci.c | 24 +++-
 1 file changed, 3 insertions(+), 21 deletions(-)

diff --git a/drivers/tty/serial/sh-sci.c b/drivers/tty/serial/sh-sci.c
index 676f9d1354943a1b..7c7dfbce54ed9c19 100644
--- a/drivers/tty/serial/sh-sci.c
+++ b/drivers/tty/serial/sh-sci.c
@@ -1866,26 +1866,9 @@ static unsigned int sci_scbrr_calc(struct sci_port *s, 
unsigned int bps,
return DIV_ROUND_CLOSEST(freq, s->sampling_rate * bps) - 1;
 }
 
-/* calculate frame length from SMR */
-static int sci_baud_calc_frame_len(unsigned int smr_val)
-{
-   int len = 10;
-
-   if (smr_val & SCSMR_CHR)
-   len--;
-   if (smr_val & SCSMR_PE)
-   len++;
-   if (smr_val & SCSMR_STOP)
-   len++;
-
-   return len;
-}
-
-
 /* calculate sample rate, BRR, and clock select for HSCIF */
-static void sci_baud_calc_hscif(unsigned int bps, unsigned long freq,
-   int *brr, unsigned int *srr,
-   unsigned int *cks, int frame_len)
+static void sci_baud_calc_hscif(unsigned int bps, unsigned long freq, int *brr,
+   unsigned int *srr, unsigned int *cks)
 {
int sr, c, br, err, recv_margin;
int min_err = 1000; /* 100% */
@@ -1987,9 +1970,8 @@ static void sci_set_termios(struct uart_port *port, 
struct ktermios *termios,
baud = uart_get_baud_rate(port, termios, old, 0, max_baud);
if (likely(baud && port->uartclk)) {
if (s->cfg->type == PORT_HSCIF) {
-   int frame_len = sci_baud_calc_frame_len(smr_val);
sci_baud_calc_hscif(baud, port->uartclk, , ,
-   , frame_len);
+   );
} else {
t = sci_scbrr_calc(s, baud, port->uartclk);
for (cks = 0; t >= 256 && cks <= 3; cks++)
-- 
1.9.1

--
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/


[PATCH 14/25] serial: sh-sci: Add BRG register definitions

2015-11-19 Thread Geert Uytterhoeven
Add register definitions for the Baud Rate Generator for External Clock
(BRG), as found in some SCIF and in HSCIF, including a new regtype for
the "SH-4(A)"-derived SCIF variant with BRG.

Signed-off-by: Geert Uytterhoeven 
---
 drivers/tty/serial/sh-sci.c | 46 +
 drivers/tty/serial/sh-sci.h |  5 +
 include/linux/serial_sci.h  |  1 +
 3 files changed, 52 insertions(+)

diff --git a/drivers/tty/serial/sh-sci.c b/drivers/tty/serial/sh-sci.c
index d82735dd62ae38d8..76738c9918885764 100644
--- a/drivers/tty/serial/sh-sci.c
+++ b/drivers/tty/serial/sh-sci.c
@@ -161,6 +161,8 @@ static const struct plat_sci_reg 
sci_regmap[SCIx_NR_REGTYPES][SCIx_NR_REGS] = {
[HSSRR] = sci_reg_invalid,
[SCPCR] = sci_reg_invalid,
[SCPDR] = sci_reg_invalid,
+   [SCDL]  = sci_reg_invalid,
+   [SCCKS] = sci_reg_invalid,
},
 
/*
@@ -183,6 +185,8 @@ static const struct plat_sci_reg 
sci_regmap[SCIx_NR_REGTYPES][SCIx_NR_REGS] = {
[HSSRR] = sci_reg_invalid,
[SCPCR] = sci_reg_invalid,
[SCPDR] = sci_reg_invalid,
+   [SCDL]  = sci_reg_invalid,
+   [SCCKS] = sci_reg_invalid,
},
 
/*
@@ -204,6 +208,8 @@ static const struct plat_sci_reg 
sci_regmap[SCIx_NR_REGTYPES][SCIx_NR_REGS] = {
[HSSRR] = sci_reg_invalid,
[SCPCR] = { 0x30, 16 },
[SCPDR] = { 0x34, 16 },
+   [SCDL]  = sci_reg_invalid,
+   [SCCKS] = sci_reg_invalid,
},
 
/*
@@ -225,6 +231,8 @@ static const struct plat_sci_reg 
sci_regmap[SCIx_NR_REGTYPES][SCIx_NR_REGS] = {
[HSSRR] = sci_reg_invalid,
[SCPCR] = { 0x30, 16 },
[SCPDR] = { 0x34, 16 },
+   [SCDL]  = sci_reg_invalid,
+   [SCCKS] = sci_reg_invalid,
},
 
/*
@@ -247,6 +255,8 @@ static const struct plat_sci_reg 
sci_regmap[SCIx_NR_REGTYPES][SCIx_NR_REGS] = {
[HSSRR] = sci_reg_invalid,
[SCPCR] = sci_reg_invalid,
[SCPDR] = sci_reg_invalid,
+   [SCDL]  = sci_reg_invalid,
+   [SCCKS] = sci_reg_invalid,
},
 
/*
@@ -268,6 +278,8 @@ static const struct plat_sci_reg 
sci_regmap[SCIx_NR_REGTYPES][SCIx_NR_REGS] = {
[HSSRR] = sci_reg_invalid,
[SCPCR] = sci_reg_invalid,
[SCPDR] = sci_reg_invalid,
+   [SCDL]  = sci_reg_invalid,
+   [SCCKS] = sci_reg_invalid,
},
 
/*
@@ -289,6 +301,32 @@ static const struct plat_sci_reg 
sci_regmap[SCIx_NR_REGTYPES][SCIx_NR_REGS] = {
[HSSRR] = sci_reg_invalid,
[SCPCR] = sci_reg_invalid,
[SCPDR] = sci_reg_invalid,
+   [SCDL]  = sci_reg_invalid,
+   [SCCKS] = sci_reg_invalid,
+   },
+
+   /*
+* Common SCIF definitions for ports with a Baud Rate Generator for
+* External Clock (BRG).
+*/
+   [SCIx_SH4_SCIF_BRG_REGTYPE] = {
+   [SCSMR] = { 0x00, 16 },
+   [SCBRR] = { 0x04,  8 },
+   [SCSCR] = { 0x08, 16 },
+   [SCxTDR]= { 0x0c,  8 },
+   [SCxSR] = { 0x10, 16 },
+   [SCxRDR]= { 0x14,  8 },
+   [SCFCR] = { 0x18, 16 },
+   [SCFDR] = { 0x1c, 16 },
+   [SCTFDR]= sci_reg_invalid,
+   [SCRFDR]= sci_reg_invalid,
+   [SCSPTR]= { 0x20, 16 },
+   [SCLSR] = { 0x24, 16 },
+   [HSSRR] = sci_reg_invalid,
+   [SCPCR] = sci_reg_invalid,
+   [SCPDR] = sci_reg_invalid,
+   [SCDL]  = { 0x30, 16 },
+   [SCCKS] = { 0x34, 16 },
},
 
/*
@@ -310,6 +348,8 @@ static const struct plat_sci_reg 
sci_regmap[SCIx_NR_REGTYPES][SCIx_NR_REGS] = {
[HSSRR] = { 0x40, 16 },
[SCPCR] = sci_reg_invalid,
[SCPDR] = sci_reg_invalid,
+   [SCDL]  = { 0x30, 16 },
+   [SCCKS] = { 0x34, 16 },
},
 
/*
@@ -332,6 +372,8 @@ static const struct plat_sci_reg 
sci_regmap[SCIx_NR_REGTYPES][SCIx_NR_REGS] = {
[HSSRR] = sci_reg_invalid,
[SCPCR] = sci_reg_invalid,
[SCPDR] = sci_reg_invalid,
+   [SCDL]  = sci_reg_invalid,
+   [SCCKS] = sci_reg_invalid,

[PATCH 07/25] serial: sh-sci: Convert from clk_get() to devm_clk_get()

2015-11-19 Thread Geert Uytterhoeven
Transfer clock cleanup handling to the core device management code.

Signed-off-by: Geert Uytterhoeven 
---
 drivers/tty/serial/sh-sci.c | 8 +++-
 1 file changed, 3 insertions(+), 5 deletions(-)

diff --git a/drivers/tty/serial/sh-sci.c b/drivers/tty/serial/sh-sci.c
index cba51da604253db6..9442961a198378c7 100644
--- a/drivers/tty/serial/sh-sci.c
+++ b/drivers/tty/serial/sh-sci.c
@@ -2216,7 +2216,7 @@ static struct uart_ops sci_uart_ops = {
 static int sci_init_clocks(struct sci_port *sci_port, struct device *dev)
 {
/* Get the SCI functional clock. It's called "fck" on ARM. */
-   sci_port->fclk = clk_get(dev, "fck");
+   sci_port->fclk = devm_clk_get(dev, "fck");
if (PTR_ERR(sci_port->fclk) == -EPROBE_DEFER)
return -EPROBE_DEFER;
if (!IS_ERR(sci_port->fclk))
@@ -2226,7 +2226,7 @@ static int sci_init_clocks(struct sci_port *sci_port, 
struct device *dev)
 * But it used to be called "sci_ick", and we need to maintain DT
 * backward compatibility.
 */
-   sci_port->fclk = clk_get(dev, "sci_ick");
+   sci_port->fclk = devm_clk_get(dev, "sci_ick");
if (PTR_ERR(sci_port->fclk) == -EPROBE_DEFER)
return -EPROBE_DEFER;
if (!IS_ERR(sci_port->fclk))
@@ -2236,7 +2236,7 @@ static int sci_init_clocks(struct sci_port *sci_port, 
struct device *dev)
 * Not all SH platforms declare a clock lookup entry for SCI devices,
 * in which case we need to get the global "peripheral_clk" clock.
 */
-   sci_port->fclk = clk_get(dev, "peripheral_clk");
+   sci_port->fclk = devm_clk_get(dev, "peripheral_clk");
if (!IS_ERR(sci_port->fclk))
return 0;
 
@@ -2395,8 +2395,6 @@ static int sci_init_single(struct platform_device *dev,
 
 static void sci_cleanup_single(struct sci_port *port)
 {
-   clk_put(port->fclk);
-
pm_runtime_disable(port->port.dev);
 }
 
-- 
1.9.1

--
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/


[PATCH 24/25] arm64: renesas: salvator-x dts: Enable SCIF_CLK frequency and pins

2015-11-19 Thread Geert Uytterhoeven
Add and enable the external crystal for the SCIF_CLK and its pinctrl, to
be used by the Baud Rate Generator for External Clock (BRG) on (H)SCIF.

This increases the range and accuracy of supported baud rates:
  - SCIF:
  - Supports now 50, 230400, 460800, 50, and 921600 bps,
  - Perfect match for standard 50-460800, and 9216000 bps.
  - HSCIF:
  - Supports now 50, 75, and 110 bps,
  - Perfect match for standard 50-460800, and 9216000 bps.

Signed-off-by: Geert Uytterhoeven 
---
 arch/arm64/boot/dts/renesas/r8a7795-salvator-x.dts | 12 
 1 file changed, 12 insertions(+)

diff --git a/arch/arm64/boot/dts/renesas/r8a7795-salvator-x.dts 
b/arch/arm64/boot/dts/renesas/r8a7795-salvator-x.dts
index afbd5256806e7014..0b38fecb1c5d75e9 100644
--- a/arch/arm64/boot/dts/renesas/r8a7795-salvator-x.dts
+++ b/arch/arm64/boot/dts/renesas/r8a7795-salvator-x.dts
@@ -127,6 +127,9 @@
 };
 
  {
+   pinctrl-0 = <_clk_pins>;
+   pinctrl-names = "default";
+
scif1_pins: scif1 {
renesas,groups = "scif1_data_a", "scif1_ctrl";
renesas,function = "scif1";
@@ -135,6 +138,10 @@
renesas,groups = "scif2_data_a";
renesas,function = "scif2";
};
+   scif_clk_pins: scif_clk {
+   renesas,groups = "scif_clk_a";
+   renesas,function = "scif_clk";
+   };
 
i2c2_pins: i2c2 {
renesas,groups = "i2c2_a";
@@ -172,6 +179,11 @@
status = "okay";
 };
 
+_clk {
+   clock-frequency = <14745600>;
+   status = "okay";
+};
+
 _sound {
pinctrl-0 = <_pins _clk_pins>;
pinctrl-names = "default";
-- 
1.9.1

--
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/


[PATCH 21/25] ARM: shmobile: r8a7791 dtsi: Add BRG support for (H)SCIF

2015-11-19 Thread Geert Uytterhoeven
Add the device node for the external SCIF_CLK.
The presence of the SCIF_CLK crystal and its clock frequency depends on
the actual board.

Add the two optional clock sources (ZS_CLK and SCIF_CLK for the internal
resp. external clock) for the Baud Rate Generator for External Clock
(BRG) to all SCIF and HSCIF device nodes.

This increases the range and accuracy of supported baud rates on
(H)SCIF.

Signed-off-by: Geert Uytterhoeven 
---
 arch/arm/boot/dts/r8a7791.dtsi | 54 --
 1 file changed, 36 insertions(+), 18 deletions(-)

diff --git a/arch/arm/boot/dts/r8a7791.dtsi b/arch/arm/boot/dts/r8a7791.dtsi
index 684120a0a479a8d0..20f0cacd3a79095b 100644
--- a/arch/arm/boot/dts/r8a7791.dtsi
+++ b/arch/arm/boot/dts/r8a7791.dtsi
@@ -670,8 +670,9 @@
compatible = "renesas,scif-r8a7791", "renesas,scif";
reg = <0 0xe6e6 0 64>;
interrupts = <0 152 IRQ_TYPE_LEVEL_HIGH>;
-   clocks = <_clks R8A7791_CLK_SCIF0>;
-   clock-names = "fck";
+   clocks = <_clks R8A7791_CLK_SCIF0>, <_clk>,
+<_clk>;
+   clock-names = "fck", "int_clk", "scif_clk";
dmas = < 0x29>, < 0x2a>;
dma-names = "tx", "rx";
power-domains = <_clocks>;
@@ -682,8 +683,9 @@
compatible = "renesas,scif-r8a7791", "renesas,scif";
reg = <0 0xe6e68000 0 64>;
interrupts = <0 153 IRQ_TYPE_LEVEL_HIGH>;
-   clocks = <_clks R8A7791_CLK_SCIF1>;
-   clock-names = "fck";
+   clocks = <_clks R8A7791_CLK_SCIF1>, <_clk>,
+<_clk>;
+   clock-names = "fck", "int_clk", "scif_clk";
dmas = < 0x2d>, < 0x2e>;
dma-names = "tx", "rx";
power-domains = <_clocks>;
@@ -694,8 +696,9 @@
compatible = "renesas,scif-r8a7791", "renesas,scif";
reg = <0 0xe6e58000 0 64>;
interrupts = <0 22 IRQ_TYPE_LEVEL_HIGH>;
-   clocks = <_clks R8A7791_CLK_SCIF2>;
-   clock-names = "fck";
+   clocks = <_clks R8A7791_CLK_SCIF2>, <_clk>,
+<_clk>;
+   clock-names = "fck", "int_clk", "scif_clk";
dmas = < 0x2b>, < 0x2c>;
dma-names = "tx", "rx";
power-domains = <_clocks>;
@@ -706,8 +709,9 @@
compatible = "renesas,scif-r8a7791", "renesas,scif";
reg = <0 0xe6ea8000 0 64>;
interrupts = <0 23 IRQ_TYPE_LEVEL_HIGH>;
-   clocks = <_clks R8A7791_CLK_SCIF3>;
-   clock-names = "fck";
+   clocks = <_clks R8A7791_CLK_SCIF3>, <_clk>,
+<_clk>;
+   clock-names = "fck", "int_clk", "scif_clk";
dmas = < 0x2f>, < 0x30>;
dma-names = "tx", "rx";
power-domains = <_clocks>;
@@ -718,8 +722,9 @@
compatible = "renesas,scif-r8a7791", "renesas,scif";
reg = <0 0xe6ee 0 64>;
interrupts = <0 24 IRQ_TYPE_LEVEL_HIGH>;
-   clocks = <_clks R8A7791_CLK_SCIF4>;
-   clock-names = "fck";
+   clocks = <_clks R8A7791_CLK_SCIF4>, <_clk>,
+<_clk>;
+   clock-names = "fck", "int_clk", "scif_clk";
dmas = < 0xfb>, < 0xfc>;
dma-names = "tx", "rx";
power-domains = <_clocks>;
@@ -730,8 +735,9 @@
compatible = "renesas,scif-r8a7791", "renesas,scif";
reg = <0 0xe6ee8000 0 64>;
interrupts = <0 25 IRQ_TYPE_LEVEL_HIGH>;
-   clocks = <_clks R8A7791_CLK_SCIF5>;
-   clock-names = "fck";
+   clocks = <_clks R8A7791_CLK_SCIF5>, <_clk>,
+<_clk>;
+   clock-names = "fck", "int_clk", "scif_clk";
dmas = < 0xfd>, < 0xfe>;
dma-names = "tx", "rx";
power-domains = <_clocks>;
@@ -742,8 +748,9 @@
compatible = "renesas,hscif-r8a7791", "renesas,hscif";
reg = <0 0xe62c 0 96>;
interrupts = <0 154 IRQ_TYPE_LEVEL_HIGH>;
-   clocks = <_clks R8A7791_CLK_HSCIF0>;
-   clock-names = "fck";
+   clocks = <_clks R8A7791_CLK_HSCIF0>, <_clk>,
+<_clk>;
+   clock-names = "fck", "int_clk", "scif_clk";
dmas = < 0x39>, < 0x3a>;
dma-names = "tx", "rx";
power-domains = <_clocks>;
@@ -754,8 +761,9 @@
compatible = "renesas,hscif-r8a7791", "renesas,hscif";
reg = <0 0xe62c8000 0 96>;
interrupts = <0 155 IRQ_TYPE_LEVEL_HIGH>;
-   clocks = <_clks R8A7791_CLK_HSCIF1>;
-   clock-names = "fck";
+   clocks = <_clks R8A7791_CLK_HSCIF1>, 

[PATCH 22/25] ARM: shmobile: koelsch dts: Enable SCIF_CLK frequency and pins

2015-11-19 Thread Geert Uytterhoeven
Add and enable the external crystal for the SCIF_CLK and its pinctrl, to
be used by the Baud Rate Generator for External Clock (BRG) on (H)SCIF.

This increases the range and accuracy of supported baud rates:
  - SCIF:
  - Supports now 50, 75, 110, 1152000, 150, 200, and
400 bps,
  - Perfect match for standard 50-460800, and 9216000 bps.
  - More accurate 576000 bps.
  - HSCIF:
  - Supports now 50, 75, 110, 134, 150, and 200 bps,
  - Perfect match for standard 50-460800, and 9216000 bps.
  - More accurate 576000, 1152000, 300, 350, and 400
bps.

Signed-off-by: Geert Uytterhoeven 
---
 arch/arm/boot/dts/r8a7791-koelsch.dts | 13 +
 1 file changed, 13 insertions(+)

diff --git a/arch/arm/boot/dts/r8a7791-koelsch.dts 
b/arch/arm/boot/dts/r8a7791-koelsch.dts
index da263dbb126db78c..9c3bc94791fc932a 100644
--- a/arch/arm/boot/dts/r8a7791-koelsch.dts
+++ b/arch/arm/boot/dts/r8a7791-koelsch.dts
@@ -320,6 +320,9 @@
 };
 
  {
+   pinctrl-0 = <_clk_pins>;
+   pinctrl-names = "default";
+
i2c2_pins: i2c2 {
renesas,groups = "i2c2";
renesas,function = "i2c2";
@@ -340,6 +343,11 @@
renesas,function = "scif1";
};
 
+   scif_clk_pins: scif_clk {
+   renesas,groups = "scif_clk";
+   renesas,function = "scif_clk";
+   };
+
ether_pins: ether {
renesas,groups = "eth_link", "eth_mdio", "eth_rmii";
renesas,function = "eth";
@@ -440,6 +448,11 @@
status = "okay";
 };
 
+_clk {
+   clock-frequency = <14745600>;
+   status = "okay";
+};
+
  {
pinctrl-0 = <_pins>;
pinctrl-names = "default";
-- 
1.9.1

--
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/


[PATCH 18/25] serial: sh-sci: Prepare for multiple clocks and baud rate generators

2015-11-19 Thread Geert Uytterhoeven
Refactor the clock and baud rate parameter code to ease adding support
for multiple clocks and baud rate generators later.
sci_scbrr_calc() now returns the bit rate error, so it can be compared
to the bit rate error for other baud rate generators.

Signed-off-by: Geert Uytterhoeven 
---
 drivers/tty/serial/sh-sci.c | 176 ++--
 1 file changed, 120 insertions(+), 56 deletions(-)

diff --git a/drivers/tty/serial/sh-sci.c b/drivers/tty/serial/sh-sci.c
index 726c96d5a511c222..12800e52f41953dc 100644
--- a/drivers/tty/serial/sh-sci.c
+++ b/drivers/tty/serial/sh-sci.c
@@ -2,6 +2,7 @@
  * SuperH on-chip serial module support.  (SCI with no FIFO / with FIFO)
  *
  *  Copyright (C) 2002 - 2011  Paul Mundt
+ *  Copyright (C) 2015 Glider bvba
  *  Modified to support SH7720 SCIF. Markus Brunner, Mark Jonas (Jul 2007).
  *
  * based off of the old drivers/char/sh-sci.c by:
@@ -76,6 +77,11 @@ enum {
((port)->irqs[SCIx_ERI_IRQ] &&  \
 ((port)->irqs[SCIx_RXI_IRQ] < 0))
 
+enum SCI_CLKS {
+   SCI_FCK,/* Functional Clock */
+   SCI_NUM_CLKS
+};
+
 struct sci_port {
struct uart_portport;
 
@@ -92,8 +98,9 @@ struct sci_port {
struct timer_list   break_timer;
int break_flag;
 
-   /* Function clock */
-   struct clk  *fclk;
+   /* Clocks */
+   struct clk  *clks[SCI_NUM_CLKS];
+   unsigned long   clk_rates[SCI_NUM_CLKS];
 
int irqs[SCIx_NR_IRQS];
char*irqstr[SCIx_NR_IRQS];
@@ -496,17 +503,24 @@ static int sci_probe_regmap(struct plat_sci_port *cfg)
 
 static void sci_port_enable(struct sci_port *sci_port)
 {
+   unsigned int i;
+
if (!sci_port->port.dev)
return;
 
pm_runtime_get_sync(sci_port->port.dev);
 
-   clk_prepare_enable(sci_port->fclk);
-   sci_port->port.uartclk = clk_get_rate(sci_port->fclk);
+   for (i = 0; i < SCI_NUM_CLKS; i++) {
+   clk_prepare_enable(sci_port->clks[i]);
+   sci_port->clk_rates[i] = clk_get_rate(sci_port->clks[i]);
+   }
+   sci_port->port.uartclk = sci_port->clk_rates[SCI_FCK];
 }
 
 static void sci_port_disable(struct sci_port *sci_port)
 {
+   unsigned int i;
+
if (!sci_port->port.dev)
return;
 
@@ -518,7 +532,8 @@ static void sci_port_disable(struct sci_port *sci_port)
del_timer_sync(_port->break_timer);
sci_port->break_flag = 0;
 
-   clk_disable_unprepare(sci_port->fclk);
+   for (i = SCI_NUM_CLKS; i-- > 0; )
+   clk_disable_unprepare(sci_port->clks[i]);
 
pm_runtime_put_sync(sci_port->port.dev);
 }
@@ -1657,6 +1672,7 @@ static int sci_notifier(struct notifier_block *self,
 {
struct sci_port *sci_port;
unsigned long flags;
+   unsigned int i;
 
sci_port = container_of(self, struct sci_port, freq_transition);
 
@@ -1664,7 +1680,9 @@ static int sci_notifier(struct notifier_block *self,
struct uart_port *port = _port->port;
 
spin_lock_irqsave(>lock, flags);
-   port->uartclk = clk_get_rate(sci_port->fclk);
+   for (i = 0; i < SCI_NUM_CLKS; i++)
+   sci_port->clk_rates[i] =
+   clk_get_rate(sci_port->clks[i]);
spin_unlock_irqrestore(>lock, flags);
}
 
@@ -1907,11 +1925,12 @@ static void sci_shutdown(struct uart_port *port)
 }
 
 /* calculate sample rate, BRR, and clock select */
-static void sci_scbrr_calc(struct sci_port *s, unsigned int bps,
-  unsigned long freq, int *brr, unsigned int *srr,
-  unsigned int *cks)
+static int sci_scbrr_calc(struct sci_port *s, unsigned int bps,
+ unsigned int *brr, unsigned int *srr,
+ unsigned int *cks)
 {
unsigned int min_sr, max_sr, shift, sr, br, a, b, c;
+   unsigned long freq = s->clk_rates[SCI_FCK];
int err, min_err = INT_MAX;
 
if (s->sampling_rate) {
@@ -1963,6 +1982,7 @@ static void sci_scbrr_calc(struct sci_port *s, unsigned 
int bps,
 
dev_dbg(s->port.dev, "BRR: %u%+d bps using N %u SR %u cks %u\n", bps,
min_err, *brr, *srr + 1, *cks);
+   return min_err;
 }
 
 static void sci_reset(struct uart_port *port)
@@ -1984,11 +2004,14 @@ static void sci_reset(struct uart_port *port)
 static void sci_set_termios(struct uart_port *port, struct ktermios *termios,
struct ktermios *old)
 {
+   unsigned int baud, smr_val = 0, scr_val = 0, i;
+   unsigned int brr = 255, cks = 0, srr = 15;
+   unsigned int brr1 = 255, cks1 = 0, srr1 = 15;
struct sci_port *s = to_sci_port(port);
const struct plat_sci_reg *reg;
-   unsigned int baud, smr_val = 0, max_baud, cks = 0;
-   int t = -1;
-   unsigned int srr = 

[PATCH 23/25] arm64: renesas: r8a7795 dtsi: Add BRG support for (H)SCIF

2015-11-19 Thread Geert Uytterhoeven
Add the device node for the external SCIF_CLK.
The presence of the SCIF_CLK crystal and its clock frequency depend on
the actual board.

Add the two optional clock sources (ZS_CLK and SCIF_CLK for the internal
resp. external clock) for the Baud Rate Generator for External Clock
(BRG) to all SCIF and HSCIF device nodes.

This increases the range and accuracy of supported baud rates on
(H)SCIF.

Signed-off-by: Geert Uytterhoeven 
---
 arch/arm64/boot/dts/renesas/r8a7795.dtsi | 74 ++--
 1 file changed, 52 insertions(+), 22 deletions(-)

diff --git a/arch/arm64/boot/dts/renesas/r8a7795.dtsi 
b/arch/arm64/boot/dts/renesas/r8a7795.dtsi
index 53a2a8fb42b7480c..25900761cfde201e 100644
--- a/arch/arm64/boot/dts/renesas/r8a7795.dtsi
+++ b/arch/arm64/boot/dts/renesas/r8a7795.dtsi
@@ -84,6 +84,14 @@
status = "disabled";
};
 
+   /* External SCIF clock - to be overridden by boards that provide it */
+   scif_clk: scif {
+   compatible = "fixed-clock";
+   #clock-cells = <0>;
+   clock-frequency = <0>;
+   status = "disabled";
+   };
+
soc {
compatible = "simple-bus";
interrupt-parent = <>;
@@ -362,8 +370,10 @@
compatible = "renesas,hscif-r8a7795", "renesas,hscif";
reg = <0 0xe654 0 96>;
interrupts = ;
-   clocks = < CPG_MOD 520>;
-   clock-names = "fck";
+   clocks = < CPG_MOD 520>,
+< CPG_CORE R8A7795_CLK_S3D1>,
+<_clk>;
+   clock-names = "fck", "int_clk", "scif_clk";
dmas = < 0x31>, < 0x30>;
dma-names = "tx", "rx";
power-domains = <>;
@@ -374,8 +384,10 @@
compatible = "renesas,hscif-r8a7795", "renesas,hscif";
reg = <0 0xe655 0 96>;
interrupts = ;
-   clocks = < CPG_MOD 519>;
-   clock-names = "fck";
+   clocks = < CPG_MOD 519>,
+< CPG_CORE R8A7795_CLK_S3D1>,
+<_clk>;
+   clock-names = "fck", "int_clk", "scif_clk";
dmas = < 0x33>, < 0x32>;
dma-names = "tx", "rx";
power-domains = <>;
@@ -386,8 +398,10 @@
compatible = "renesas,hscif-r8a7795", "renesas,hscif";
reg = <0 0xe656 0 96>;
interrupts = ;
-   clocks = < CPG_MOD 518>;
-   clock-names = "fck";
+   clocks = < CPG_MOD 518>,
+< CPG_CORE R8A7795_CLK_S3D1>,
+<_clk>;
+   clock-names = "fck", "int_clk", "scif_clk";
dmas = < 0x35>, < 0x34>;
dma-names = "tx", "rx";
power-domains = <>;
@@ -398,8 +412,10 @@
compatible = "renesas,hscif-r8a7795", "renesas,hscif";
reg = <0 0xe66a 0 96>;
interrupts = ;
-   clocks = < CPG_MOD 517>;
-   clock-names = "fck";
+   clocks = < CPG_MOD 517>,
+< CPG_CORE R8A7795_CLK_S3D1>,
+<_clk>;
+   clock-names = "fck", "int_clk", "scif_clk";
dmas = < 0x37>, < 0x36>;
dma-names = "tx", "rx";
power-domains = <>;
@@ -410,8 +426,10 @@
compatible = "renesas,hscif-r8a7795", "renesas,hscif";
reg = <0 0xe66b 0 96>;
interrupts = ;
-   clocks = < CPG_MOD 516>;
-   clock-names = "fck";
+   clocks = < CPG_MOD 516>,
+< CPG_CORE R8A7795_CLK_S3D1>,
+<_clk>;
+   clock-names = "fck", "int_clk", "scif_clk";
dmas = < 0x39>, < 0x38>;
dma-names = "tx", "rx";
power-domains = <>;
@@ -422,8 +440,10 @@
compatible = "renesas,scif-r8a7795", "renesas,scif";
reg = <0 0xe6e6 0 64>;
interrupts = ;
-   clocks = < CPG_MOD 207>;
-   clock-names = "fck";
+   clocks = < CPG_MOD 207>,
+< CPG_CORE R8A7795_CLK_S3D1>,
+<_clk>;
+   clock-names = "fck", "int_clk", "scif_clk";

[PATCH 04/25] serial: sh-sci: Grammar s/Get ... for/Get ... from/

2015-11-19 Thread Geert Uytterhoeven
Signed-off-by: Geert Uytterhoeven 
---
 drivers/tty/serial/sh-sci.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/tty/serial/sh-sci.c b/drivers/tty/serial/sh-sci.c
index ae136a1632e6298d..676f9d1354943a1b 100644
--- a/drivers/tty/serial/sh-sci.c
+++ b/drivers/tty/serial/sh-sci.c
@@ -2640,7 +2640,7 @@ sci_parse_dt(struct platform_device *pdev, unsigned int 
*dev_id)
if (!p)
return NULL;
 
-   /* Get the line number for the aliases node. */
+   /* Get the line number from the aliases node. */
id = of_alias_get_id(np, "serial");
if (id < 0) {
dev_err(>dev, "failed to get alias id (%d)\n", id);
-- 
1.9.1

--
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/


[PATCH 25/25] sh: sh7734: Correct SCIF type for BRG

2015-11-19 Thread Geert Uytterhoeven
The SCIF variant in the sh7734 SoC is not the common "SH-4(A)" variant,
but a derivative with added "Baud Rate Generator for External Clock"
(BRG). Correct the regtype value in platform data to fix this.

Signed-off-by: Geert Uytterhoeven 
---
Untested due to lack of hardware and platform clock support.
---
 arch/sh/kernel/cpu/sh4a/setup-sh7734.c | 12 ++--
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/arch/sh/kernel/cpu/sh4a/setup-sh7734.c 
b/arch/sh/kernel/cpu/sh4a/setup-sh7734.c
index f617bcb734dfeb76..69b8a50310d9a23f 100644
--- a/arch/sh/kernel/cpu/sh4a/setup-sh7734.c
+++ b/arch/sh/kernel/cpu/sh4a/setup-sh7734.c
@@ -28,7 +28,7 @@ static struct plat_sci_port scif0_platform_data = {
.flags  = UPF_BOOT_AUTOCONF,
.scscr  = SCSCR_RE | SCSCR_TE | SCSCR_REIE,
.type   = PORT_SCIF,
-   .regtype= SCIx_SH4_SCIF_REGTYPE,
+   .regtype= SCIx_SH4_SCIF_BRG_REGTYPE,
 };
 
 static struct resource scif0_resources[] = {
@@ -50,7 +50,7 @@ static struct plat_sci_port scif1_platform_data = {
.flags  = UPF_BOOT_AUTOCONF,
.scscr  = SCSCR_RE | SCSCR_TE | SCSCR_REIE,
.type   = PORT_SCIF,
-   .regtype= SCIx_SH4_SCIF_REGTYPE,
+   .regtype= SCIx_SH4_SCIF_BRG_REGTYPE,
 };
 
 static struct resource scif1_resources[] = {
@@ -72,7 +72,7 @@ static struct plat_sci_port scif2_platform_data = {
.flags  = UPF_BOOT_AUTOCONF,
.scscr  = SCSCR_RE | SCSCR_TE | SCSCR_REIE,
.type   = PORT_SCIF,
-   .regtype= SCIx_SH4_SCIF_REGTYPE,
+   .regtype= SCIx_SH4_SCIF_BRG_REGTYPE,
 };
 
 static struct resource scif2_resources[] = {
@@ -94,7 +94,7 @@ static struct plat_sci_port scif3_platform_data = {
.flags  = UPF_BOOT_AUTOCONF,
.scscr  = SCSCR_RE | SCSCR_TE | SCSCR_REIE | SCSCR_TOIE,
.type   = PORT_SCIF,
-   .regtype= SCIx_SH4_SCIF_REGTYPE,
+   .regtype= SCIx_SH4_SCIF_BRG_REGTYPE,
 };
 
 static struct resource scif3_resources[] = {
@@ -116,7 +116,7 @@ static struct plat_sci_port scif4_platform_data = {
.flags  = UPF_BOOT_AUTOCONF,
.scscr  = SCSCR_RE | SCSCR_TE | SCSCR_REIE,
.type   = PORT_SCIF,
-   .regtype= SCIx_SH4_SCIF_REGTYPE,
+   .regtype= SCIx_SH4_SCIF_BRG_REGTYPE,
 };
 
 static struct resource scif4_resources[] = {
@@ -138,7 +138,7 @@ static struct plat_sci_port scif5_platform_data = {
.flags  = UPF_BOOT_AUTOCONF,
.scscr  = SCSCR_RE | SCSCR_TE | SCSCR_REIE,
.type   = PORT_SCIF,
-   .regtype= SCIx_SH4_SCIF_REGTYPE,
+   .regtype= SCIx_SH4_SCIF_BRG_REGTYPE,
 };
 
 static struct resource scif5_resources[] = {
-- 
1.9.1

--
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/


[PATCH 08/25] serial: sh-sci: Make unsigned values in sci_baud_calc_hscif() unsigned

2015-11-19 Thread Geert Uytterhoeven
Move the -1 offset of br to the assignment to *brr, so br cannot become
negative anymore, and update the clamp() call. Now all unsigned values
in sci_baud_calc_hscif() can become unsigned.

Signed-off-by: Geert Uytterhoeven 
---
 drivers/tty/serial/sh-sci.c | 11 ++-
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/drivers/tty/serial/sh-sci.c b/drivers/tty/serial/sh-sci.c
index 9442961a198378c7..fba1e1eea15dc3a1 100644
--- a/drivers/tty/serial/sh-sci.c
+++ b/drivers/tty/serial/sh-sci.c
@@ -1870,7 +1870,8 @@ static unsigned int sci_scbrr_calc(struct sci_port *s, 
unsigned int bps,
 static void sci_baud_calc_hscif(unsigned int bps, unsigned long freq, int *brr,
unsigned int *srr, unsigned int *cks)
 {
-   int sr, c, br, err, recv_margin;
+   unsigned int sr, br, c;
+   int err, recv_margin;
int min_err = 1000; /* 100% */
int recv_max_margin = 0;
 
@@ -1880,9 +1881,9 @@ static void sci_baud_calc_hscif(unsigned int bps, 
unsigned long freq, int *brr,
for (c = 0; c <= 3; c++) {
/* integerized formulas from HSCIF documentation */
br = DIV_ROUND_CLOSEST(freq, (sr *
- (1 << (2 * c + 1)) * bps)) - 1;
-   br = clamp(br, 0, 255);
-   err = DIV_ROUND_CLOSEST(freq, ((br + 1) * bps * sr *
+ (1 << (2 * c + 1)) * bps));
+   br = clamp(br, 1U, 256U);
+   err = DIV_ROUND_CLOSEST(freq, (br * bps * sr *
   (1 << (2 * c + 1)) / 1000)) -
   1000;
/* Calc recv margin
@@ -1908,7 +1909,7 @@ static void sci_baud_calc_hscif(unsigned int bps, 
unsigned long freq, int *brr,
else
continue;
 
-   *brr = br;
+   *brr = br - 1;
*srr = sr - 1;
*cks = c;
}
-- 
1.9.1

--
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/


[PATCH 09/25] serial: sh-sci: Avoid overflow in sci_baud_calc_hscif()

2015-11-19 Thread Geert Uytterhoeven
If bps >= 1048576, the multiplication of "(sr * (1 << (2 * c + 1))" and
"bps" will overflow, and both br and err will contain bogus values.
Skip the current and all higher clock select predividers when overflow
is detected.  Simplify the calculations using intermediates while we're
at it.

Signed-off-by: Geert Uytterhoeven 
---
 drivers/tty/serial/sh-sci.c | 14 --
 1 file changed, 8 insertions(+), 6 deletions(-)

diff --git a/drivers/tty/serial/sh-sci.c b/drivers/tty/serial/sh-sci.c
index fba1e1eea15dc3a1..97a0f8ef5adc55a2 100644
--- a/drivers/tty/serial/sh-sci.c
+++ b/drivers/tty/serial/sh-sci.c
@@ -1870,7 +1870,7 @@ static unsigned int sci_scbrr_calc(struct sci_port *s, 
unsigned int bps,
 static void sci_baud_calc_hscif(unsigned int bps, unsigned long freq, int *brr,
unsigned int *srr, unsigned int *cks)
 {
-   unsigned int sr, br, c;
+   unsigned int sr, br, a, b, c;
int err, recv_margin;
int min_err = 1000; /* 100% */
int recv_max_margin = 0;
@@ -1880,12 +1880,14 @@ static void sci_baud_calc_hscif(unsigned int bps, 
unsigned long freq, int *brr,
for (sr = 8; sr <= 32; sr++) {
for (c = 0; c <= 3; c++) {
/* integerized formulas from HSCIF documentation */
-   br = DIV_ROUND_CLOSEST(freq, (sr *
- (1 << (2 * c + 1)) * bps));
+   a = sr * (1 << (2 * c + 1));
+   if (bps > UINT_MAX / a)
+   break;
+
+   b = a * bps;
+   br = DIV_ROUND_CLOSEST(freq, b);
br = clamp(br, 1U, 256U);
-   err = DIV_ROUND_CLOSEST(freq, (br * bps * sr *
-  (1 << (2 * c + 1)) / 1000)) -
-  1000;
+   err = DIV_ROUND_CLOSEST(freq, (br * b) / 1000) - 1000;
/* Calc recv margin
 * M: Receive margin (%)
 * N: Ratio of bit rate to clock (N = sampling rate)
-- 
1.9.1

--
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/


Re: [kbuild-all] [patch -mm] mm, vmalloc: remove VM_VPAGES

2015-11-19 Thread Johannes Weiner
Hi Fengguang,

On Thu, Nov 19, 2015 at 08:35:46PM +0800, Fengguang Wu wrote:
> 
> git://git.cmpxchg.org/linux-mmotm.git
> 
> I'll teach the robot to use it instead of linux-next for [-mm] patches.

Yup, that seems like a more suitable base.

But you might even consider putting them on top of linux-mmots.git,
which is released more frequently than mmotm. Not sure what other MM
hackers do, but I tend to develop against mmots, and there could be
occasional breakage when dependencies haven't yet trickled into mmotm.
--
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/


[PATCH 15/25] serial: sh-sci: Replace struct sci_port_info by type/regtype encoding

2015-11-19 Thread Geert Uytterhoeven
Store the encoded port and register types directly in of_device_id.data,
instead of using a pointer to a structure.
This saves memory and simplifies the source code, especially when adding
more compatible entries later.

Signed-off-by: Geert Uytterhoeven 
---
 drivers/tty/serial/sh-sci.c | 40 +++-
 1 file changed, 11 insertions(+), 29 deletions(-)

diff --git a/drivers/tty/serial/sh-sci.c b/drivers/tty/serial/sh-sci.c
index 76738c9918885764..41351ae055de661f 100644
--- a/drivers/tty/serial/sh-sci.c
+++ b/drivers/tty/serial/sh-sci.c
@@ -2595,42 +2595,27 @@ static int sci_remove(struct platform_device *dev)
return 0;
 }
 
-struct sci_port_info {
-   unsigned int type;
-   unsigned int regtype;
-};
+
+#define SCI_OF_DATA(type, regtype) (void *)((type) << 16 | (regtype))
+#define SCI_OF_TYPE(data)  ((unsigned long)(data) >> 16)
+#define SCI_OF_REGTYPE(data)   ((unsigned long)(data) & 0x)
 
 static const struct of_device_id of_sci_match[] = {
{
.compatible = "renesas,scif",
-   .data = &(const struct sci_port_info) {
-   .type = PORT_SCIF,
-   .regtype = SCIx_SH4_SCIF_REGTYPE,
-   },
+   .data = SCI_OF_DATA(PORT_SCIF, SCIx_SH4_SCIF_REGTYPE),
}, {
.compatible = "renesas,scifa",
-   .data = &(const struct sci_port_info) {
-   .type = PORT_SCIFA,
-   .regtype = SCIx_SCIFA_REGTYPE,
-   },
+   .data = SCI_OF_DATA(PORT_SCIFA, SCIx_SCIFA_REGTYPE),
}, {
.compatible = "renesas,scifb",
-   .data = &(const struct sci_port_info) {
-   .type = PORT_SCIFB,
-   .regtype = SCIx_SCIFB_REGTYPE,
-   },
+   .data = SCI_OF_DATA(PORT_SCIFB, SCIx_SCIFB_REGTYPE),
}, {
.compatible = "renesas,hscif",
-   .data = &(const struct sci_port_info) {
-   .type = PORT_HSCIF,
-   .regtype = SCIx_HSCIF_REGTYPE,
-   },
+   .data = SCI_OF_DATA(PORT_HSCIF, SCIx_HSCIF_REGTYPE),
}, {
.compatible = "renesas,sci",
-   .data = &(const struct sci_port_info) {
-   .type = PORT_SCI,
-   .regtype = SCIx_SCI_REGTYPE,
-   },
+   .data = SCI_OF_DATA(PORT_SCI, SCIx_SCI_REGTYPE),
}, {
/* Terminator */
},
@@ -2642,7 +2627,6 @@ sci_parse_dt(struct platform_device *pdev, unsigned int 
*dev_id)
 {
struct device_node *np = pdev->dev.of_node;
const struct of_device_id *match;
-   const struct sci_port_info *info;
struct plat_sci_port *p;
int id;
 
@@ -2653,8 +2637,6 @@ sci_parse_dt(struct platform_device *pdev, unsigned int 
*dev_id)
if (!match)
return NULL;
 
-   info = match->data;
-
p = devm_kzalloc(>dev, sizeof(struct plat_sci_port), GFP_KERNEL);
if (!p)
return NULL;
@@ -2669,8 +2651,8 @@ sci_parse_dt(struct platform_device *pdev, unsigned int 
*dev_id)
*dev_id = id;
 
p->flags = UPF_IOREMAP | UPF_BOOT_AUTOCONF;
-   p->type = info->type;
-   p->regtype = info->regtype;
+   p->type = SCI_OF_TYPE(match->data);
+   p->regtype = SCI_OF_REGTYPE(match->data);
p->scscr = SCSCR_RE | SCSCR_TE;
 
return p;
-- 
1.9.1

--
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/


Re: [Patch-V2 1/6] INPUT: xpad: Add minimal support for Logitech G920 Wheel

2015-11-19 Thread Simon Wood
On Thu, November 19, 2015 11:31 am, Dmitry Torokhov wrote:
> On Thu, Nov 19, 2015 at 02:50:51PM +0100, Jiri Kosina wrote:
>
>> On Thu, 12 Nov 2015, Simon Wood wrote:
>>
>>
>>> When plugged in the Logitech G920 wheel starts with USBID 046d:c261
>>> and behaviors as a vendor specific class. If a 'magic' byte sequence is
>>> sent the wheel will detach and reconnect as a HID device with the
>>> USBID 046d:c262.
>>>
>>>
>>> Signed-off-by: Simon Wood 
>>>
>>
>> Adding Dmitry to CC.
>>
>>
>> Dmitry, I am planning to take this through my tree together with the
>> rest of the actual HID support for that device if you Ack this.
>
> Hmm, I have an incoming series for xbox that night clash with this... If
> you'll put it in a clean branch off 4.3 I'd pull it and then get more
> changes on top.
>
> Can we also change the subject as it is not about adding a minimal
> support. Something like "Input: xpad - switch Logitech G920 Wheel into HID
> mode"

Will spin a 'v3' with this and Benjamin's suggestion.

Cheers,
Simon.

--
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/


[PATCH 2/2] irqchip: add support for Sigma Designs SMP86xx interrupt controller

2015-11-19 Thread Mans Rullgard
This adds support for the secondary interrupt controller used in Sigma
Designs SMP86xx and SMP87xx chips.

Signed-off-by: Mans Rullgard 
---
 drivers/irqchip/Kconfig  |   5 +
 drivers/irqchip/Makefile |   1 +
 drivers/irqchip/irq-tangox.c | 232 +++
 3 files changed, 238 insertions(+)
 create mode 100644 drivers/irqchip/irq-tangox.c

diff --git a/drivers/irqchip/Kconfig b/drivers/irqchip/Kconfig
index 4d7294e..baf3345 100644
--- a/drivers/irqchip/Kconfig
+++ b/drivers/irqchip/Kconfig
@@ -193,3 +193,8 @@ config IRQ_MXS
def_bool y if MACH_ASM9260 || ARCH_MXS
select IRQ_DOMAIN
select STMP_DEVICE
+
+config TANGOX_IRQ
+   bool
+   select IRQ_DOMAIN
+   select GENERIC_IRQ_CHIP
diff --git a/drivers/irqchip/Makefile b/drivers/irqchip/Makefile
index 177f78f..763715c 100644
--- a/drivers/irqchip/Makefile
+++ b/drivers/irqchip/Makefile
@@ -55,3 +55,4 @@ obj-$(CONFIG_RENESAS_H8S_INTC)+= 
irq-renesas-h8s.o
 obj-$(CONFIG_ARCH_SA1100)  += irq-sa11x0.o
 obj-$(CONFIG_INGENIC_IRQ)  += irq-ingenic.o
 obj-$(CONFIG_IMX_GPCV2)+= irq-imx-gpcv2.o
+obj-$(CONFIG_TANGOX_IRQ)   += irq-tangox.o
diff --git a/drivers/irqchip/irq-tangox.c b/drivers/irqchip/irq-tangox.c
new file mode 100644
index 000..630e2b5
--- /dev/null
+++ b/drivers/irqchip/irq-tangox.c
@@ -0,0 +1,232 @@
+/*
+ * Copyright (C) 2014 Mans Rullgard 
+ *
+ * This program is free software; you can redistribute  it and/or modify it
+ * under  the terms of  the GNU General  Public License as published by the
+ * Free Software Foundation;  either version 2 of the  License, or (at your
+ * option) any later version.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#define IRQ0_CTL_BASE  0x
+#define IRQ1_CTL_BASE  0x0100
+#define EDGE_CTL_BASE  0x0200
+#define IRQ2_CTL_BASE  0x0300
+
+#define IRQ_CTL_HI 0x18
+#define EDGE_CTL_HI0x20
+
+#define IRQ_STATUS 0x00
+#define IRQ_RAWSTAT0x04
+#define IRQ_EN_SET 0x08
+#define IRQ_EN_CLR 0x0c
+#define IRQ_SOFT_SET   0x10
+#define IRQ_SOFT_CLR   0x14
+
+#define EDGE_STATUS0x00
+#define EDGE_RAWSTAT   0x04
+#define EDGE_CFG_RISE  0x08
+#define EDGE_CFG_FALL  0x0c
+#define EDGE_CFG_RISE_SET  0x10
+#define EDGE_CFG_RISE_CLR  0x14
+#define EDGE_CFG_FALL_SET  0x18
+#define EDGE_CFG_FALL_CLR  0x1c
+
+struct tangox_irq_chip {
+   void __iomem *base;
+   unsigned long ctl;
+};
+
+static inline u32 intc_readl(struct tangox_irq_chip *chip, int reg)
+{
+   return readl_relaxed(chip->base + reg);
+}
+
+static inline void intc_writel(struct tangox_irq_chip *chip, int reg, u32 val)
+{
+   writel_relaxed(val, chip->base + reg);
+}
+
+static void tangox_dispatch_irqs(struct irq_domain *dom, unsigned int status,
+int base)
+{
+   unsigned int hwirq;
+   unsigned int virq;
+
+   while (status) {
+   hwirq = __ffs(status);
+   virq = irq_find_mapping(dom, base + hwirq);
+   generic_handle_irq(virq);
+   status &= ~BIT(hwirq);
+   }
+}
+
+static void tangox_irq_handler(struct irq_desc *desc)
+{
+   struct irq_domain *dom = irq_desc_get_handler_data(desc);
+   struct irq_chip *host_chip = irq_desc_get_chip(desc);
+   struct tangox_irq_chip *chip = dom->host_data;
+   unsigned int status_lo, status_hi;
+
+   chained_irq_enter(host_chip, desc);
+
+   status_lo = intc_readl(chip, chip->ctl + IRQ_STATUS);
+   status_hi = intc_readl(chip, chip->ctl + IRQ_CTL_HI + IRQ_STATUS);
+
+   tangox_dispatch_irqs(dom, status_lo, 0);
+   tangox_dispatch_irqs(dom, status_hi, 32);
+
+   chained_irq_exit(host_chip, desc);
+}
+
+static int tangox_irq_set_type(struct irq_data *d, unsigned int flow_type)
+{
+   struct irq_chip_generic *gc = irq_data_get_irq_chip_data(d);
+   struct tangox_irq_chip *chip = gc->domain->host_data;
+   struct irq_chip_regs *regs = >chip_types[0].regs;
+
+   switch (flow_type & IRQ_TYPE_SENSE_MASK) {
+   case IRQ_TYPE_EDGE_RISING:
+   intc_writel(chip, regs->type + EDGE_CFG_RISE_SET, d->mask);
+   intc_writel(chip, regs->type + EDGE_CFG_FALL_CLR, d->mask);
+   break;
+
+   case IRQ_TYPE_EDGE_FALLING:
+   intc_writel(chip, regs->type + EDGE_CFG_RISE_CLR, d->mask);
+   intc_writel(chip, regs->type + EDGE_CFG_FALL_SET, d->mask);
+   break;
+
+   case IRQ_TYPE_LEVEL_HIGH:
+   intc_writel(chip, regs->type + EDGE_CFG_RISE_CLR, d->mask);
+   intc_writel(chip, regs->type + EDGE_CFG_FALL_CLR, d->mask);
+   break;
+
+   case IRQ_TYPE_LEVEL_LOW:
+   intc_writel(chip, 

[PATCH 1/2] devicetree: add binding for Sigma Designs SMP86xx interrupt controller

2015-11-19 Thread Mans Rullgard
This adds a binding for the secondary interrupt controller in
Sigma Designs SMP86xx and SMP87xx chips.

Signed-off-by: Mans Rullgard 
---
 .../interrupt-controller/sigma,smp8642-intc.txt| 47 ++
 1 file changed, 47 insertions(+)
 create mode 100644 
Documentation/devicetree/bindings/interrupt-controller/sigma,smp8642-intc.txt

diff --git 
a/Documentation/devicetree/bindings/interrupt-controller/sigma,smp8642-intc.txt 
b/Documentation/devicetree/bindings/interrupt-controller/sigma,smp8642-intc.txt
new file mode 100644
index 000..f82cddf
--- /dev/null
+++ 
b/Documentation/devicetree/bindings/interrupt-controller/sigma,smp8642-intc.txt
@@ -0,0 +1,47 @@
+Sigma Designs SMP86xx/SMP87xx secondary interrupt controller
+
+Required properties:
+- compatible: should be "sigma,smp8642-intc"
+- reg: physical address of MMIO region
+- interrupt-parent: phandle of parent interrupt controller
+- interrupt-controller: boolean
+
+One child node per control block with properties:
+- sigma,reg-offset: offset of registers from main base address
+- interrupt-controller: boolean
+- #interrupt-cells: should be <2>, interrupt index and flags per interrupts.txt
+- interrupts: interrupt spec of primary interrupt controller
+- label: (optional) name for display purposes
+
+Example:
+
+intc: interrupt-controller@6e000 {
+   compatible = "sigma,smp8642-intc";
+   reg = <0x6e000 0x400>;
+   interrupt-parent = <>;
+   interrupt-controller;
+
+   irq0: irq0 {
+   sigma,reg-offset = <0x000>;
+   interrupt-controller;
+   #interrupt-cells = <2>;
+   interrupts = ;
+   label = "IRQ0";
+   };
+
+   irq1: irq1 {
+   sigma,reg-offset = <0x100>;
+   interrupt-controller;
+   #interrupt-cells = <2>;
+   interrupts = ;
+   label = "IRQ1";
+   };
+
+   irq2: irq2 {
+   sigma,reg-offset = <0x300>;
+   interrupt-controller;
+   #interrupt-cells = <2>;
+   interrupts = ;
+   label = "IRQ2";
+   };
+};
-- 
2.6.3

--
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/


[PATCH 0/2] Support for Sigma Designs SMP86xx interrupt controller

2015-11-19 Thread Mans Rullgard
The Sigma Designs SMP86xx and SMP87xx chips use a secondary interrupt
controller with 64 inputs.  The inputs go to an edge/level detector,
the outputs of which are replicated to three mask blocks, each with a
separate primary IRQ.

These patches add a device tree binding and an irqchip driver for this
controller.

Mans Rullgard (2):
  devicetree: add binding for Sigma Designs SMP86xx interrupt controller
  irqchip: add support for Sigma Designs SMP86xx interrupt controller

 .../interrupt-controller/sigma,smp8642-intc.txt|  47 +
 drivers/irqchip/Kconfig|   5 +
 drivers/irqchip/Makefile   |   1 +
 drivers/irqchip/irq-tangox.c   | 232 +
 4 files changed, 285 insertions(+)
 create mode 100644 
Documentation/devicetree/bindings/interrupt-controller/sigma,smp8642-intc.txt
 create mode 100644 drivers/irqchip/irq-tangox.c

-- 
2.6.3

--
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/


Re: [PATCHv7] EDAC, altera: Add Altera L2 Cache and OCRAM EDAC Support

2015-11-19 Thread Borislav Petkov
On Tue, Oct 27, 2015 at 03:38:12PM -0500, dingu...@opensource.altera.com wrote:
> From: Thor Thayer 
> 
> Adding L2 Cache and On-Chip RAM EDAC support for the
> Altera SoCs using the EDAC device  model. The SDRAM
> controller is using the Memory Controller model.
> 
> Each type of ECC is individually configurable.
> 
> The SDRAM ECC is a separate Kconfig option because:
> 1) the SDRAM preparation can take almost 2 seconds on boot and some
> customers need a faster boot time.
> 2) the SDRAM has an ECC initialization dependency on the preloader
> which is outside the kernel. It is desirable to be able to turn the
> SDRAM on & off separately.
> 
> Signed-off-by: Thor Thayer 
> Signed-off-by: Dinh Nguyen 
> ---
> v7: s/of_get_named_gen_pool/of_gen_pool_get
> Remove #ifdef for EDAC_DEBUG
> Use -ENODEV instead of EPROBE_DEFER
> 
> v6: Convert to nested EDAC in device tree. Force L2 cache
> on for L2Cache ECC & remove L2 cache syscon for checking
> enable bit. Update year in header.
> 
> v5: No Change
> 
> v4: Change mask defines to use BIT().
> Fix comment style to agree with kernel coding style.
> Better printk description for read != write in trigger.
> Remove SysFS debugging message.
> Better dci->mod_name
> Move gen_pool pointer assignment to end of function.
> Invert logic to reduce indent in ocram depenency check.
> Change from dev_err() to edac_printk()
> Replace magic numbers with defines & comments.
> Improve error injection test.
> Change Makefile intermediary name to altr (from alt)
> 
> v3: Move OCRAM and L2 cache EDAC functions into altera_edac.c
> instead of separate files.
> 
> v2: Fix L2 dependency comments.
> ---
>  drivers/edac/Kconfig   |  16 ++
>  drivers/edac/Makefile  |   5 +-
>  drivers/edac/altera_edac.c | 488 
> -
>  3 files changed, 507 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/edac/Kconfig b/drivers/edac/Kconfig
> index ef25000..b80b4ad 100644
> --- a/drivers/edac/Kconfig
> +++ b/drivers/edac/Kconfig
> @@ -376,6 +376,22 @@ config EDAC_ALTERA_MC
> preloader must initialize the SDRAM before loading
> the kernel.
>  
> +config EDAC_ALTERA_L2C
> + bool "Altera L2 Cache EDAC"
> + depends on EDAC_MM_EDAC=y && ARCH_SOCFPGA
> + select CACHE_L2X0
> + help
> +   Support for error detection and correction on the
> +   Altera L2 cache Memory for Altera SoCs. This option
> +  requires L2 cache so it will force that selection.
> +
> +config EDAC_ALTERA_OCRAM
> + bool "Altera On-Chip RAM EDAC"
> + depends on EDAC_MM_EDAC=y && ARCH_SOCFPGA && SRAM && GENERIC_ALLOCATOR
> + help
> +   Support for error detection and correction on the
> +   Altera On-Chip RAM Memory for Altera SoCs.
> +
>  config EDAC_SYNOPSYS
>   tristate "Synopsys DDR Memory Controller"
>   depends on EDAC_MM_EDAC && ARCH_ZYNQ
> diff --git a/drivers/edac/Makefile b/drivers/edac/Makefile
> index dbf53e0..8f1c6fc 100644
> --- a/drivers/edac/Makefile
> +++ b/drivers/edac/Makefile
> @@ -67,6 +67,9 @@ obj-$(CONFIG_EDAC_OCTEON_L2C)   += 
> octeon_edac-l2c.o
>  obj-$(CONFIG_EDAC_OCTEON_LMC)+= octeon_edac-lmc.o
>  obj-$(CONFIG_EDAC_OCTEON_PCI)+= octeon_edac-pci.o
>  
> -obj-$(CONFIG_EDAC_ALTERA_MC) += altera_edac.o
> +altr_edac-y  := altera_edac.o
> +obj-$(CONFIG_EDAC_ALTERA_MC) += altr_edac.o
> +obj-$(CONFIG_EDAC_ALTERA_L2C)+= altr_edac.o
> +obj-$(CONFIG_EDAC_ALTERA_OCRAM)  += altr_edac.o

What are those supposed to accomplish?

>  obj-$(CONFIG_EDAC_SYNOPSYS)  += synopsys_edac.o
>  obj-$(CONFIG_EDAC_XGENE) += xgene_edac.o
> diff --git a/drivers/edac/altera_edac.c b/drivers/edac/altera_edac.c
> index 9296409..154ac8c 100644
> --- a/drivers/edac/altera_edac.c
> +++ b/drivers/edac/altera_edac.c
> @@ -17,8 +17,10 @@
>   * Adapted from the highbank_mc_edac driver.
>   */
>  
> +#include 
>  #include 
>  #include 
> +#include 
>  #include 
>  #include 
>  #include 
> @@ -34,6 +36,7 @@
>  
>  #define EDAC_MOD_STR "altera_edac"
>  #define EDAC_VERSION "1"
> +#define EDAC_DEVICE  "ALTR_MEM"

Let's simply call it "Altera" - it is more human-friendly.

>  static const struct altr_sdram_prv_data c5_data = {
>   .ecc_ctrl_offset= CV_CTLCFG_OFST,
> @@ -75,6 +78,33 @@ static const struct altr_sdram_prv_data a10_data = {
>   .ue_set_mask= A10_DIAGINT_TDERRA_MASK,
>  };
>  
> +/** EDAC Device Defines **/
> +
> +/* OCRAM ECC Management Group Defines */
> +#define ALTR_MAN_GRP_OCRAM_ECC_OFFSET   0x04
> +#define ALTR_OCR_ECC_EN_MASKBIT(0)
> +#define ALTR_OCR_ECC_INJS_MASK  BIT(1)
> +#define ALTR_OCR_ECC_INJD_MASK  BIT(2)
> +#define ALTR_OCR_ECC_SERR_MASK  BIT(3)
> +#define ALTR_OCR_ECC_DERR_MASK  

Re: [Patch-V2 1/6] INPUT: xpad: Add minimal support for Logitech G920 Wheel

2015-11-19 Thread Dmitry Torokhov
On Thu, Nov 19, 2015 at 02:50:51PM +0100, Jiri Kosina wrote:
> On Thu, 12 Nov 2015, Simon Wood wrote:
> 
> > When plugged in the Logitech G920 wheel starts with USBID 046d:c261
> > and behaviors as a vendor specific class. If a 'magic' byte sequence
> > is sent the wheel will detach and reconnect as a HID device with the
> > USBID 046d:c262.
> > 
> > Signed-off-by: Simon Wood 
> 
> Adding Dmitry to CC.
> 
> Dmitry, I am planning to take this through my tree together with the rest 
> of the actual HID support for that device if you Ack this.

Hmm, I have an incoming series for xbox that night clash with this... If
you'll put it in a clean branch off 4.3 I'd pull it and then get more
changes on top.

Can we also change the subject as it is not about adding a minimal
support. Something like "Input: xpad - switch Logitech G920 Wheel into
HID mode"

Otherwise:

Acked-by: Dmitry Torokhov 

Thanks.

-- 
Dmitry
--
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/


Re: [PATCH v3 2/2] ASoC: codecs: Add da7218 codec driver

2015-11-19 Thread kbuild test robot
Hi Adam,

[auto build test WARNING on: asoc/for-next]
[also build test WARNING on: v4.4-rc1 next-20151119]

url:
https://github.com/0day-ci/linux/commits/Adam-Thomson/ASoC-da7218-Add-bindings-documentation-for-DA7218-audio-codec/20151120-014315
base:   https://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git 
for-next
config: x86_64-allmodconfig (attached as .config)
reproduce:
# save the attached .config to linux build tree
make ARCH=x86_64 

All warnings (new ones prefixed by >>):

   sound/soc/codecs/da7218.c: In function 'da7218_of_get_id':
>> sound/soc/codecs/da7218.c:2261:10: warning: cast from pointer to integer of 
>> different size [-Wpointer-to-int-cast]
  return (int) id->data;
 ^

vim +2261 sound/soc/codecs/da7218.c

  2245  /*
  2246   * DT
  2247   */
  2248  
  2249  static const struct of_device_id da7218_of_match[] = {
  2250  { .compatible = "dlg,da7217", .data = (void *) DA7217_DEV_ID },
  2251  { .compatible = "dlg,da7218", .data = (void *) DA7218_DEV_ID },
  2252  { }
  2253  };
  2254  MODULE_DEVICE_TABLE(of, da7218_of_match);
  2255  
  2256  static inline int da7218_of_get_id(struct device *dev)
  2257  {
  2258  const struct of_device_id *id = 
of_match_device(da7218_of_match, dev);
  2259  
  2260  if (id)
> 2261  return (int) id->data;
  2262  else
  2263  return -EINVAL;
  2264  }
  2265  
  2266  static enum da7218_micbias_voltage
  2267  da7218_of_micbias_lvl(struct snd_soc_codec *codec, u32 val)
  2268  {
  2269  switch (val) {

---
0-DAY kernel test infrastructureOpen Source Technology Center
https://lists.01.org/pipermail/kbuild-all   Intel Corporation


.config.gz
Description: Binary data


Re: linux-next: manual merge of the audit tree with Linus' tree

2015-11-19 Thread Richard Guy Briggs
On 15/11/19, Paul Moore wrote:
> On Wed, Nov 18, 2015 at 8:06 PM, Stephen Rothwell  
> wrote:
> > Hi Paul,
> >
> > Today's linux-next merge of the audit tree got a conflict in:
> >
> >   kernel/audit.c
> >
> > between commit:
> >
> >   d0164adc89f6 ("mm, page_alloc: distinguish between being unable to sleep, 
> > unwilling to sleep and avoiding waking kswapd")
> >
> > from Linus' tree and commit:
> >
> >   14eeba1d242e ("audit: include auditd's threads in audit_log_start() wait 
> > exception")
> >
> > from the audit tree.
> >
> > I fixed it up (see below) and can carry the fix as necessary (no action
> > is required).
> 
> Thanks Stephen, I found the same thing yesterday while doing some
> testing; your patch looks good to me.

Stephen, your patch looks fine to me.  I had some minor concerns about
deeper issues as to whether the original intent of that part of the
audit subsystem was affected by this change, but that is WRT the
conflicting patch rather than your merge.  After poking around a bit, I
don't have any outstanding concerns.

> > diff --cc kernel/audit.c
> > index bc2ff61bc1d6,ca1b9cda2766..
> > --- a/kernel/audit.c
> > +++ b/kernel/audit.c
> > @@@ -1371,9 -1371,9 +1371,9 @@@ struct audit_buffer *audit_log_start(st
> > if (unlikely(audit_filter_type(type)))
> > return NULL;
> >
> >  -  if (gfp_mask & __GFP_WAIT) {
> >  +  if (gfp_mask & __GFP_DIRECT_RECLAIM) {
> > -   if (audit_pid && audit_pid == current->pid)
> > +   if (audit_pid && audit_pid == current->tgid)
> >  -  gfp_mask &= ~__GFP_WAIT;
> >  +  gfp_mask &= ~__GFP_DIRECT_RECLAIM;
> > else
> > reserve = 0;
> > }
> 
> paul moore

- RGB

--
Richard Guy Briggs 
Senior Software Engineer, Kernel Security, AMER ENG Base Operating Systems, Red 
Hat
Remote, Ottawa, Canada
Voice: +1.647.777.2635, Internal: (81) 32635, Alt: +1.613.693.0684x3545
--
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/


Re: [PATCH v11 4/8] Input: goodix - add power management support

2015-11-19 Thread Dmitry Torokhov
On Thu, Nov 19, 2015 at 02:26:37PM +0200, Irina Tirdea wrote:
> Implement suspend/resume for goodix driver.
> 
> The suspend and resume process uses the gpio pins.
> If the device ACPI/DT information does not declare gpio pins,
> suspend/resume will not be available for these devices.
> 
> This is based on Goodix datasheets for GT911 and GT9271
> and on Goodix driver gt9xx.c for Android (publicly available
> in Android kernel trees for various devices).
> 
> Signed-off-by: Octavian Purdila 
> Signed-off-by: Irina Tirdea 
> ---
>  drivers/input/touchscreen/goodix.c | 96 
> --
>  1 file changed, 91 insertions(+), 5 deletions(-)
> 
> diff --git a/drivers/input/touchscreen/goodix.c 
> b/drivers/input/touchscreen/goodix.c
> index 0911b0c9..0fd472d 100644
> --- a/drivers/input/touchscreen/goodix.c
> +++ b/drivers/input/touchscreen/goodix.c
> @@ -45,6 +45,7 @@ struct goodix_ts_data {
>   u16 version;
>   char *cfg_name;
>   struct completion firmware_loading_complete;
> + unsigned long irq_flags;
>  };
>  
>  #define GOODIX_GPIO_INT_NAME "irq"
> @@ -61,6 +62,9 @@ struct goodix_ts_data {
>  #define GOODIX_CONFIG_967_LENGTH 228
>  
>  /* Register defines */
> +#define GOODIX_REG_COMMAND   0x8040
> +#define GOODIX_CMD_SCREEN_OFF0x05
> +
>  #define GOODIX_READ_COOR_ADDR0x814E
>  #define GOODIX_REG_CONFIG_DATA   0x8047
>  #define GOODIX_REG_ID0x8140
> @@ -162,6 +166,11 @@ static int goodix_i2c_write(struct i2c_client *client, 
> u16 reg, const u8 *buf,
>   return ret < 0 ? ret : (ret != 1 ? -EIO : 0);
>  }
>  
> +static int goodix_i2c_write_u8(struct i2c_client *client, u16 reg, u8 value)
> +{
> + return goodix_i2c_write(client, reg, , sizeof(value));
> +}
> +
>  static int goodix_get_cfg_len(u16 id)
>  {
>   switch (id) {
> @@ -281,6 +290,18 @@ static irqreturn_t goodix_ts_irq_handler(int irq, void 
> *dev_id)
>   return IRQ_HANDLED;
>  }
>  
> +static void goodix_free_irq(struct goodix_ts_data *ts)
> +{
> + devm_free_irq(>client->dev, ts->client->irq, ts);
> +}
> +
> +static int goodix_request_irq(struct goodix_ts_data *ts)
> +{
> + return devm_request_threaded_irq(>client->dev, ts->client->irq,
> +  NULL, goodix_ts_irq_handler,
> +  ts->irq_flags, ts->client->name, ts);
> +}
> +
>  /**
>   * goodix_check_cfg - Checks if config fw is valid
>   *
> @@ -585,7 +606,6 @@ static int goodix_request_input_dev(struct goodix_ts_data 
> *ts)
>  static int goodix_configure_dev(struct goodix_ts_data *ts)
>  {
>   int error;
> - unsigned long irq_flags;
>  
>   goodix_read_config(ts);
>  
> @@ -593,10 +613,8 @@ static int goodix_configure_dev(struct goodix_ts_data 
> *ts)
>   if (error)
>   return error;
>  
> - irq_flags = goodix_irq_flags[ts->int_trigger_type] | IRQF_ONESHOT;
> - error = devm_request_threaded_irq(>client->dev, ts->client->irq,
> -   NULL, goodix_ts_irq_handler,
> -   irq_flags, ts->client->name, ts);
> + ts->irq_flags = goodix_irq_flags[ts->int_trigger_type] | IRQF_ONESHOT;
> + error = goodix_request_irq(ts);
>   if (error) {
>   dev_err(>client->dev, "request IRQ failed: %d\n", error);
>   return error;
> @@ -720,6 +738,73 @@ static int goodix_ts_remove(struct i2c_client *client)
>   return 0;
>  }
>  
> +static int __maybe_unused goodix_suspend(struct device *dev)
> +{
> + struct i2c_client *client = to_i2c_client(dev);
> + struct goodix_ts_data *ts = i2c_get_clientdata(client);
> + int error;
> +
> + /* We need gpio pins to suspend/resume */
> + if (!ts->gpiod_int || !ts->gpiod_rst)
> + return 0;
> +
> + wait_for_completion(>firmware_loading_complete);

This is not that nice as it may lead to angry splats from the PM core if
firmware loading takes too long and we start suspending before it
completes.

Rafael, if we issue pm_stay_awake() before requesting firmware and
pm_relax() once it is done, will this prevent the current suspend
timeouts?

Thanks.

-- 
Dmitry
--
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/


Re: [PATCH v11 3/8] Input: goodix - write configuration data to device

2015-11-19 Thread Dmitry Torokhov
On Thu, Nov 19, 2015 at 02:26:36PM +0200, Irina Tirdea wrote:
> + if (ts->gpiod_int && ts->gpiod_rst) {
> + /* update device config */
> + ts->cfg_name = kasprintf(GFP_KERNEL, "goodix_%d_cfg.bin",
> +  ts->id);

devm_kasprintf maybe (don't resubmit)?

Thanks.

-- 
Dmitry
--
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/


Re: [PATCH] SCSI-libfc: Delete an unnecessary check before the function call "kmem_cache_destroy"

2015-11-19 Thread Vasu Dev
On Mon, 2015-11-16 at 09:45 +0100, SF Markus Elfring wrote:
> From: Markus Elfring 
> Date: Mon, 16 Nov 2015 09:39:12 +0100
> 
> The kmem_cache_destroy() function tests whether its argument is NULL
> and then returns immediately. Thus the test around the call is not needed.
> 
> This issue was detected by using the Coccinelle software.
> 
> Signed-off-by: Markus Elfring 
> ---
>  drivers/scsi/libfc/fc_fcp.c | 3 +--
>  1 file changed, 1 insertion(+), 2 deletions(-)
> 
> diff --git a/drivers/scsi/libfc/fc_fcp.c b/drivers/scsi/libfc/fc_fcp.c
> index 5121272..d377514 100644
> --- a/drivers/scsi/libfc/fc_fcp.c
> +++ b/drivers/scsi/libfc/fc_fcp.c
> @@ -2216,8 +2216,7 @@ int fc_setup_fcp(void)
>  
>  void fc_destroy_fcp(void)
>  {
> - if (scsi_pkt_cachep)
> - kmem_cache_destroy(scsi_pkt_cachep);
> + kmem_cache_destroy(scsi_pkt_cachep);
>  }
>  
>  /**
Looks good.

Acked-by: Vasu Dev 

--
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/


Re: [PATCH v2 2/2] usb: dwc2: host: Clear interrupts before handling them

2015-11-19 Thread Felipe Balbi

Hi,

Doug Anderson  writes:
 isn't this a regression ? You're first clearing the interrupts and only
 then reading to check what's pending, however, what's pending has just
 been cleared. Seems like this should be:

 hprt0 = dwc2_readl(HPRT0);
 dwc2_writeal(PRTINT, GINTSTS);
>>>
>>> Actually, we could probably remove the setting of GINTSTS_PRTINT
>>> completely.  The docs I have say that the GINTSTS_PRTINT is read only
>>> and that:
>>>
 The core sets this bit to indicate a change in port status of one of the
 DWC_otg core ports in Host mode. The application must read the
 Host Port Control and Status (HPRT) register to determine the exact
 event that caused this interrupt. The application must clear the
 appropriate status bit in the Host Port Control and Status register to
 clear this bit.
>>>
>>> ...so writing PRTINT is probably useless, but John can confirm.
>>>
>>
>> Yup, it seems it can be removed.
>
> How do you guys want this handled?  Should I send up a new version of
> this patch?  ...or should I send a followon patch that does this
> removal?

I'll leave the final decision to John, but my opinion is that a new
version of the patch would be preferrable.

-- 
balbi


signature.asc
Description: PGP signature


[PATCH v3] pci: Limit VPD length for megaraid_sas adapter

2015-11-19 Thread Babu Moger
Reading or Writing of PCI VPD data causes system panic.
We saw this problem by running "lspci -vvv" in the beginning.
However this can be easily reproduced by running
 cat /sys/bus/devices/XX../vpd

VPD length has been set as 32768 by default. Accessing vpd
will trigger read/write of 32k. This causes problem as we
could read data beyond the VPD end tag. Behaviour is un-
predictable when this happens. I see some other adapter doing
similar quirks(commit bffadffd43d4 ("PCI: fix VPD limit quirk
for Broadcom 5708S"))

I see there is an attempt to fix this right way.
https://patchwork.ozlabs.org/patch/534843/ or
https://lkml.org/lkml/2015/10/23/97

Tried to fix it this way, but problem is I dont see the proper
start/end TAGs(at least for this adapter) at all. The data is
mostly junk or zeros. This patch fixes the issue by setting the
vpd length to 0x80.

Signed-off-by: Babu Moger 
Reviewed-by: Khalid Aziz 

Changes since v2 -> v3
Changed the vpd length from 0 to 0x80 which leaves the
option open for someone to read first few bytes.

Changes since v1 -> v2
Removed the changes in pci_id.h. Kept all the vendor
ids in quirks.c
---
 drivers/pci/quirks.c |   38 ++
 1 files changed, 38 insertions(+), 0 deletions(-)

diff --git a/drivers/pci/quirks.c b/drivers/pci/quirks.c
index b03373f..b8774e2 100644
--- a/drivers/pci/quirks.c
+++ b/drivers/pci/quirks.c
@@ -2123,6 +2123,44 @@ static void quirk_via_cx700_pci_parking_caching(struct 
pci_dev *dev)
 DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_VIA, 0x324e, 
quirk_via_cx700_pci_parking_caching);
 
 /*
+ * A read/write to sysfs entry ('/sys/bus/pci/devices//vpd')
+ * will dump 32k of data. The default length is set as 32768.
+ * Reading a full 32k will cause an access beyond the VPD end tag.
+ * The system behaviour at that point is mostly unpredictable.
+ * Also I dont believe vendors have implemented this VPD headers properly.
+ * Atleast I dont see it in following megaraid sas controller.
+ * That is why adding the quirk here.
+ */
+static void quirk_megaraid_sas_limit_vpd(struct pci_dev *dev)
+{
+   if (dev->vpd)
+   dev->vpd->len = 0x80;
+}
+
+DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_LSI_LOGIC, 0x0060,
+   quirk_megaraid_sas_limit_vpd);
+DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_LSI_LOGIC, 0x007c,
+   quirk_megaraid_sas_limit_vpd);
+DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_LSI_LOGIC, 0x0413,
+   quirk_megaraid_sas_limit_vpd);
+DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_LSI_LOGIC, 0x0078,
+   quirk_megaraid_sas_limit_vpd);
+DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_LSI_LOGIC, 0x0079,
+   quirk_megaraid_sas_limit_vpd);
+DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_LSI_LOGIC, 0x0073,
+   quirk_megaraid_sas_limit_vpd);
+DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_LSI_LOGIC, 0x0071,
+   quirk_megaraid_sas_limit_vpd);
+DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_LSI_LOGIC, 0x005b,
+   quirk_megaraid_sas_limit_vpd);
+DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_LSI_LOGIC, 0x002f,
+   quirk_megaraid_sas_limit_vpd);
+DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_LSI_LOGIC, 0x005d,
+   quirk_megaraid_sas_limit_vpd);
+DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_LSI_LOGIC, 0x005f,
+   quirk_megaraid_sas_limit_vpd);
+
+/*
  * For Broadcom 5706, 5708, 5709 rev. A nics, any read beyond the
  * VPD end tag will hang the device.  This problem was initially
  * observed when a vpd entry was created in sysfs
-- 
1.7.1

--
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/


Re: ptrace() hangs on attempt to seize/attach stopped & frozen task

2015-11-19 Thread Pedro Alves
On 11/19/2015 05:47 PM, Oleg Nesterov wrote:
> Thanks Pedro for your email,
> 

>>  918   /* We need to wait for SIGSTOP before being able to make the next
>>  919  ptrace call on this LWP.  */
>>  920   new_lwp->must_set_ptrace_flags = 1;
>>  921
>>  922   if (linux_proc_pid_is_stopped (lwpid))
> 
> This can't happen today. Starting from v3.0 at least.

Eh, interesting.  So right after PTRACE_ATTACH, we either observe
"running" or "ptrace-stopped", but never "job stopped".  Correct?

I've actually just now tried this:

diff --git c/gdb/linux-nat.c w/gdb/linux-nat.c
index 841ec39..42f2b0d 100644
--- c/gdb/linux-nat.c
+++ w/gdb/linux-nat.c
@@ -981,6 +981,7 @@ linux_nat_post_attach_wait (ptid_t ptid, int first, int 
*cloned,
   pid_t new_pid, pid = ptid_get_lwp (ptid);
   int status;

+#if 0
   if (linux_proc_pid_is_stopped (pid))
 {
   if (debug_linux_nat)
@@ -1006,6 +1007,7 @@ linux_nat_post_attach_wait (ptid_t ptid, int first, int 
*cloned,
 (or a higher priority signal, just like normal PTRACE_ATTACH).  */
   ptrace (PTRACE_CONT, pid, 0, 0);
 }
+#endif

   /* Make sure the initial process is stopped.  The user-level threads
  layer might want to poke around in the inferior, and that won't

and sure enough, gdb's test that covers that use case still
passes, on Fedora 20 (Linux 3.19.8).

And given that my Thunderbird crashed while writing this, I had sufficient
time to be sure that a full test run passes cleanly too.  :-P  :-)

>> But maybe not, if we're sure that
>> that when that happens, waitpid returns for the initial
>> PTRACE_ATTACH-induced SIGSTOP.
> 
> Yes. Just you can't assume that watpid(WNOHANG) will succeed. Is it OK?

Yes, assuming the ptracer is guaranteed to get a SIGCHLD to wake it up.

Thanks,
Pedro Alves
--
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/


[PATCH 26/37] perf tools: Fix __dsos__addnew to put dso after adding it to the list

2015-11-19 Thread Arnaldo Carvalho de Melo
From: Masami Hiramatsu 

__dsos__addnew should drop the constructor reference to dso after adding
it to the list, because __dsos__add() will get a reference that will be
kept while it is in the list.

This fixes DSO leaks when entries are removed to the list and the refcount
never gets to zero.

Refcnt debugger shows:
   [0] 
  Unreclaimed dso: 0x2fccab0
  Refcount +1 => 1 at
./perf(dso__new+0x1ff) [0x4a62df]
./perf(__dsos__addnew+0x29) [0x4a6e19]
./perf(dsos__findnew+0xd1) [0x4a7281]
./perf(machine__findnew_kernel+0x27) [0x4a5e17]
./perf() [0x4b8df2]
./perf(machine__create_kernel_maps+0x28) [0x4bb528]
./perf(machine__new_host+0xfa) [0x4bb84a]
./perf(init_probe_symbol_maps+0x93) [0x506713]
./perf() [0x455ffa]
./perf(cmd_probe+0x6c) [0x4566bc]
./perf() [0x47abc5]
./perf(main+0x610) [0x421f90]
/lib64/libc.so.6(__libc_start_main+0xf5) [0x7f46df132af5]
./perf() [0x4220a9]
  Refcount +1 => 2 at
./perf(__dsos__addnew+0xfb) [0x4a6eeb]
./perf(dsos__findnew+0xd1) [0x4a7281]
./perf(machine__findnew_kernel+0x27) [0x4a5e17]
./perf() [0x4b8df2]
./perf(machine__create_kernel_maps+0x28) [0x4bb528]
./perf(machine__new_host+0xfa) [0x4bb84a]
./perf(init_probe_symbol_maps+0x93) [0x506713]
./perf() [0x455ffa]
./perf(cmd_probe+0x6c) [0x4566bc]
./perf() [0x47abc5]
./perf(main+0x610) [0x421f90]
/lib64/libc.so.6(__libc_start_main+0xf5) [0x7f46df132af5]
./perf() [0x4220a9]
  Refcount +1 => 3 at
./perf(dsos__findnew+0x7e) [0x4a722e]
./perf(machine__findnew_kernel+0x27) [0x4a5e17]
./perf() [0x4b8df2]
./perf(machine__create_kernel_maps+0x28) [0x4bb528]
./perf(machine__new_host+0xfa) [0x4bb84a]
./perf(init_probe_symbol_maps+0x93) [0x506713]
./perf() [0x455ffa]
./perf(cmd_probe+0x6c) [0x4566bc]
./perf() [0x47abc5]
./perf(main+0x610) [0x421f90]
/lib64/libc.so.6(__libc_start_main+0xf5) [0x7f46df132af5]
./perf() [0x4220a9]
  [snip]

Signed-off-by: Masami Hiramatsu 
Cc: Adrian Hunter 
Cc: Jiri Olsa 
Cc: Namhyung Kim 
Cc: Peter Zijlstra 
Link: 
http://lkml.kernel.org/r/20151118064031.30709.81460.stgit@localhost.localdomain
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/util/dso.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/tools/perf/util/dso.c b/tools/perf/util/dso.c
index 425df5c86c9c..e8e9a9dbf5e3 100644
--- a/tools/perf/util/dso.c
+++ b/tools/perf/util/dso.c
@@ -1243,6 +1243,8 @@ struct dso *__dsos__addnew(struct dsos *dsos, const char 
*name)
if (dso != NULL) {
__dsos__add(dsos, dso);
dso__set_basename(dso);
+   /* Put dso here because __dsos_add already got it */
+   dso__put(dso);
}
return dso;
 }
-- 
2.1.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/


[PATCH 20/37] perf probe: Fix to free temporal Dwarf_Frame

2015-11-19 Thread Arnaldo Carvalho de Melo
From: Masami Hiramatsu 

Since dwarf_cfi_addrframe returns malloc'd Dwarf_Frame object, it has to
be freed after it is used.

Signed-off-by: Masami Hiramatsu 
Cc: Adrian Hunter 
Cc: Jiri Olsa 
Cc: Namhyung Kim 
Cc: Peter Zijlstra 
Link: 
http://lkml.kernel.org/r/20151118064011.30709.65674.stgit@localhost.localdomain
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/util/probe-finder.c | 9 ++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/tools/perf/util/probe-finder.c b/tools/perf/util/probe-finder.c
index 05012bb178d7..1cab05a3831e 100644
--- a/tools/perf/util/probe-finder.c
+++ b/tools/perf/util/probe-finder.c
@@ -683,21 +683,24 @@ static int call_probe_finder(Dwarf_Die *sc_die, struct 
probe_finder *pf)
ret = dwarf_getlocation_addr(_attr, pf->addr, >fb_ops, , 1);
if (ret <= 0 || nops == 0) {
pf->fb_ops = NULL;
+   ret = 0;
 #if _ELFUTILS_PREREQ(0, 142)
} else if (nops == 1 && pf->fb_ops[0].atom == DW_OP_call_frame_cfa &&
   pf->cfi != NULL) {
-   Dwarf_Frame *frame;
+   Dwarf_Frame *frame = NULL;
if (dwarf_cfi_addrframe(pf->cfi, pf->addr, ) != 0 ||
dwarf_frame_cfa(frame, >fb_ops, ) != 0) {
pr_warning("Failed to get call frame on 0x%jx\n",
   (uintmax_t)pf->addr);
-   return -ENOENT;
+   ret = -ENOENT;
}
+   free(frame);
 #endif
}
 
/* Call finder's callback handler */
-   ret = pf->callback(sc_die, pf);
+   if (ret >= 0)
+   ret = pf->callback(sc_die, pf);
 
/* *pf->fb_ops will be cached in libdw. Don't free it. */
pf->fb_ops = NULL;
-- 
2.1.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/


[PATCH 13/37] perf test: Test the BPF prologue adding infrastructure

2015-11-19 Thread Arnaldo Carvalho de Melo
From: Wang Nan 

This patch introduces a new BPF script to test the BPF prologue adding
routines. The new script probes at null_lseek, which is the function pointer
used when we try to lseek on '/dev/null'.

The null_lseek function is chosen because it is used by function pointers, so
we don't need to consider inlining and LTO.

By extracting file->f_mode, bpf-script-test-prologue.c should know whether the
file is writable or readonly. According to llseek_loop() and
bpf-script-test-prologue.c, one fourth of total lseeks should be collected.

Committer note:

Testing it:

  # perf test -v BPF
  
  Kernel build dir is set to /lib/modules/4.3.0+/build
  set env: KBUILD_DIR=/lib/modules/4.3.0+/build
  unset env: KBUILD_OPTS
  include option is set to  -nostdinc -isystem 
/usr/lib/gcc/x86_64-redhat-linux/4.9.2/include 
-I/home/git/linux/arch/x86/include -Iarch/x86/include/generated/uapi 
-Iarch/x86/include/generated  -I/home/git/linux/include -Iinclude 
-I/home/git/linux/arch/x86/include/uapi -Iarch/x86/include/generated/uapi 
-I/home/git/linux/include/uapi -Iinclude/generated/uapi -include 
/home/git/linux/include/linux/kconfig.h
  set env: NR_CPUS=4
  set env: LINUX_VERSION_CODE=0x40300
  set env: CLANG_EXEC=/usr/libexec/icecc/bin/clang
  set env: CLANG_OPTIONS=-xc
  set env: KERNEL_INC_OPTIONS= -nostdinc -isystem 
/usr/lib/gcc/x86_64-redhat-linux/4.9.2/include 
-I/home/git/linux/arch/x86/include -Iarch/x86/include/generated/uapi 
-Iarch/x86/include/generated  -I/home/git/linux/include -Iinclude 
-I/home/git/linux/arch/x86/include/uapi -Iarch/x86/include/generated/uapi 
-I/home/git/linux/include/uapi -Iinclude/generated/uapi -include 
/home/git/linux/include/linux/kconfig.h
  set env: WORKING_DIR=/lib/modules/4.3.0+/build
  set env: CLANG_SOURCE=-
  llvm compiling command template: echo '/*
   * bpf-script-test-prologue.c
   * Test BPF prologue
   */
  #ifndef LINUX_VERSION_CODE
  # error Need LINUX_VERSION_CODE
  # error Example: for 4.2 kernel, put 
'clang-opt="-DLINUX_VERSION_CODE=0x40200" into llvm section of ~/.perfconfig'
  #endif
  #define SEC(NAME) __attribute__((section(NAME), used))

  #include 

  #define FMODE_READ0x1
  #define FMODE_WRITE   0x2

  static void (*bpf_trace_printk)(const char *fmt, int fmt_size, ...) =
  (void *) 6;

  SEC("func=null_lseek file->f_mode offset orig")
  int bpf_func__null_lseek(void *ctx, int err, unsigned long f_mode,
   unsigned long offset, unsigned long orig)
  {
  if (err)
  return 0;
  if (f_mode & FMODE_WRITE)
  return 0;
  if (offset & 1)
  return 0;
  if (orig == SEEK_CUR)
  return 0;
  return 1;
  }

  char _license[] SEC("license") = "GPL";
  int _version SEC("version") = LINUX_VERSION_CODE;
  ' | $CLANG_EXEC -D__KERNEL__ -D__NR_CPUS__=$NR_CPUS 
-DLINUX_VERSION_CODE=$LINUX_VERSION_CODE $CLANG_OPTIONS $KERNEL_INC_OPTIONS 
-Wno-unused-value -Wno-pointer-sign -working-directory $WORKING_DIR -c 
"$CLANG_SOURCE" -target bpf -O2 -o -
  libbpf: loading object '[bpf_prologue_test]' from buffer
  libbpf: section .strtab, size 135, link 0, flags 0, type=3
  libbpf: section .text, size 0, link 0, flags 6, type=1
  libbpf: section .data, size 0, link 0, flags 3, type=1
  libbpf: section .bss, size 0, link 0, flags 3, type=8
  libbpf: section func=null_lseek file->f_mode offset orig, size 112, link 0, 
flags 6, type=1
  libbpf: found program func=null_lseek file->f_mode offset orig
  libbpf: section license, size 4, link 0, flags 3, type=1
  libbpf: license of [bpf_prologue_test] is GPL
  libbpf: section version, size 4, link 0, flags 3, type=1
  libbpf: kernel version of [bpf_prologue_test] is 40300
  libbpf: section .symtab, size 168, link 1, flags 0, type=2
  bpf: config program 'func=null_lseek file->f_mode offset orig'
  symbol:null_lseek file:(null) line:0 offset:0 return:0 lazy:(null)
  parsing arg: file->f_mode into file, f_mode(1)
  parsing arg: offset into offset
  parsing arg: orig into orig
  bpf: config 'func=null_lseek file->f_mode offset orig' is ok
  Looking at the vmlinux_path (7 entries long)
  Using /lib/modules/4.3.0+/build/vmlinux for symbols
  Open Debuginfo file: /lib/modules/4.3.0+/build/vmlinux
  Try to find probe point from debuginfo.
  Matched function: null_lseek
  Probe point found: null_lseek+0
  Searching 'file' variable in context.
  Converting variable file into trace event.
  converting f_mode in file
  f_mode type is unsigned int.
  Searching 'offset' variable in context.
  Converting variable offset into trace event.
  offset type is long long int.
  Searching 'orig' variable in context.
  Converting variable orig into trace event.
  orig type is int.
  Found 1 probe_trace_events.
  Opening /sys/kernel/debug/tracing//kprobe_events write=1
  Writing event: p:perf_bpf_probe/func _text+4840528 f_mode=+68(%di):u32 
offset=%si:s64 orig=%dx:s32
  libbpf: don't need create maps for 

[PATCH 12/37] perf bpf: Generate prologue for BPF programs

2015-11-19 Thread Arnaldo Carvalho de Melo
From: Wang Nan 

This patch generates a prologue for each 'struct probe_trace_event' for
fetching arguments for BPF programs.

After bpf__probe(), iterate over each program to check whether prologues are
required. If none of the 'struct perf_probe_event' programs will attach to have
at least one argument, simply skip preprocessor hooking. For those who a
prologue is required, call bpf__gen_prologue() and paste the original
instruction after the prologue.

Signed-off-by: Wang Nan 
Cc: Alexei Starovoitov 
Cc: Masami Hiramatsu 
Cc: Zefan Li 
Cc: pi3or...@163.com
Link: 
http://lkml.kernel.org/r/1447675815-166222-12-git-send-email-wangn...@huawei.com
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/util/bpf-loader.c | 120 ++-
 1 file changed, 119 insertions(+), 1 deletion(-)

diff --git a/tools/perf/util/bpf-loader.c b/tools/perf/util/bpf-loader.c
index bd14be438cda..190a1c7f0649 100644
--- a/tools/perf/util/bpf-loader.c
+++ b/tools/perf/util/bpf-loader.c
@@ -5,12 +5,15 @@
  * Copyright (C) 2015 Huawei Inc.
  */
 
+#include 
 #include 
 #include 
 #include 
 #include "perf.h"
 #include "debug.h"
 #include "bpf-loader.h"
+#include "bpf-prologue.h"
+#include "llvm-utils.h"
 #include "probe-event.h"
 #include "probe-finder.h" // for MAX_PROBES
 #include "llvm-utils.h"
@@ -33,6 +36,8 @@ DEFINE_PRINT_FN(debug, 1)
 
 struct bpf_prog_priv {
struct perf_probe_event pev;
+   bool need_prologue;
+   struct bpf_insn *insns_buf;
 };
 
 static bool libbpf_initialized;
@@ -107,6 +112,7 @@ bpf_prog_priv__clear(struct bpf_program *prog 
__maybe_unused,
struct bpf_prog_priv *priv = _priv;
 
cleanup_perf_probe_events(>pev, 1);
+   zfree(>insns_buf);
free(priv);
 }
 
@@ -365,6 +371,102 @@ static int bpf__prepare_probe(void)
return err;
 }
 
+static int
+preproc_gen_prologue(struct bpf_program *prog, int n,
+struct bpf_insn *orig_insns, int orig_insns_cnt,
+struct bpf_prog_prep_result *res)
+{
+   struct probe_trace_event *tev;
+   struct perf_probe_event *pev;
+   struct bpf_prog_priv *priv;
+   struct bpf_insn *buf;
+   size_t prologue_cnt = 0;
+   int err;
+
+   err = bpf_program__get_private(prog, (void **));
+   if (err || !priv)
+   goto errout;
+
+   pev = >pev;
+
+   if (n < 0 || n >= pev->ntevs)
+   goto errout;
+
+   tev = >tevs[n];
+
+   buf = priv->insns_buf;
+   err = bpf__gen_prologue(tev->args, tev->nargs,
+   buf, _cnt,
+   BPF_MAXINSNS - orig_insns_cnt);
+   if (err) {
+   const char *title;
+
+   title = bpf_program__title(prog, false);
+   if (!title)
+   title = "[unknown]";
+
+   pr_debug("Failed to generate prologue for program %s\n",
+title);
+   return err;
+   }
+
+   memcpy([prologue_cnt], orig_insns,
+  sizeof(struct bpf_insn) * orig_insns_cnt);
+
+   res->new_insn_ptr = buf;
+   res->new_insn_cnt = prologue_cnt + orig_insns_cnt;
+   res->pfd = NULL;
+   return 0;
+
+errout:
+   pr_debug("Internal error in preproc_gen_prologue\n");
+   return -BPF_LOADER_ERRNO__PROLOGUE;
+}
+
+static int hook_load_preprocessor(struct bpf_program *prog)
+{
+   struct perf_probe_event *pev;
+   struct bpf_prog_priv *priv;
+   bool need_prologue = false;
+   int err, i;
+
+   err = bpf_program__get_private(prog, (void **));
+   if (err || !priv) {
+   pr_debug("Internal error when hook preprocessor\n");
+   return -BPF_LOADER_ERRNO__INTERNAL;
+   }
+
+   pev = >pev;
+   for (i = 0; i < pev->ntevs; i++) {
+   struct probe_trace_event *tev = >tevs[i];
+
+   if (tev->nargs > 0) {
+   need_prologue = true;
+   break;
+   }
+   }
+
+   /*
+* Since all tevs don't have argument, we don't need generate
+* prologue.
+*/
+   if (!need_prologue) {
+   priv->need_prologue = false;
+   return 0;
+   }
+
+   priv->need_prologue = true;
+   priv->insns_buf = malloc(sizeof(struct bpf_insn) * BPF_MAXINSNS);
+   if (!priv->insns_buf) {
+   pr_debug("No enough memory: alloc insns_buf failed\n");
+   return -ENOMEM;
+   }
+
+   err = bpf_program__set_prep(prog, pev->ntevs,
+   preproc_gen_prologue);
+   return err;
+}
+
 int bpf__probe(struct bpf_object *obj)
 {
int err = 0;
@@ -399,6 +501,18 @@ int bpf__probe(struct bpf_object *obj)
pr_debug("bpf_probe: failed to apply perf probe 
events");
goto out;
}
+
+   /*
+* After probing, let's consider prologue, 

[PATCH 08/37] perf bpf: Allow BPF program attach to uprobe events

2015-11-19 Thread Arnaldo Carvalho de Melo
From: Wang Nan 

This patch adds a new syntax to the BPF object section name to support
probing at uprobe event. Now we can use BPF program like this:

  SEC(
  "exec=/lib64/libc.so.6;"
  "libcwrite=__write"
  )
  int libcwrite(void *ctx)
  {
  return 1;
  }

Where, in section name of a program, before the main config string, we
can use 'key=value' style options. Now the only option key is "exec",
for uprobes.

Signed-off-by: Wang Nan 
Cc: Alexei Starovoitov 
Cc: Masami Hiramatsu 
Cc: Zefan Li 
Cc: pi3or...@163.com
Link: 
http://lkml.kernel.org/r/1447675815-166222-4-git-send-email-wangn...@huawei.com
[ Changed the separator from \n to ; ]
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/util/bpf-loader.c | 120 ---
 tools/perf/util/bpf-loader.h |   1 +
 2 files changed, 115 insertions(+), 6 deletions(-)

diff --git a/tools/perf/util/bpf-loader.c b/tools/perf/util/bpf-loader.c
index 4c50411371db..84169d6f2585 100644
--- a/tools/perf/util/bpf-loader.c
+++ b/tools/perf/util/bpf-loader.c
@@ -110,6 +110,113 @@ bpf_prog_priv__clear(struct bpf_program *prog 
__maybe_unused,
 }
 
 static int
+config__exec(const char *value, struct perf_probe_event *pev)
+{
+   pev->uprobes = true;
+   pev->target = strdup(value);
+   if (!pev->target)
+   return -ENOMEM;
+   return 0;
+}
+
+static struct {
+   const char *key;
+   const char *usage;
+   const char *desc;
+   int (*func)(const char *, struct perf_probe_event *);
+} bpf_config_terms[] = {
+   {
+   .key= "exec",
+   .usage  = "exec=",
+   .desc   = "Set uprobe target",
+   .func   = config__exec,
+   },
+};
+
+static int
+do_config(const char *key, const char *value,
+ struct perf_probe_event *pev)
+{
+   unsigned int i;
+
+   pr_debug("config bpf program: %s=%s\n", key, value);
+   for (i = 0; i < ARRAY_SIZE(bpf_config_terms); i++)
+   if (strcmp(key, bpf_config_terms[i].key) == 0)
+   return bpf_config_terms[i].func(value, pev);
+
+   pr_debug("BPF: ERROR: invalid config option in object: %s=%s\n",
+key, value);
+
+   pr_debug("\nHint: Currently valid options are:\n");
+   for (i = 0; i < ARRAY_SIZE(bpf_config_terms); i++)
+   pr_debug("\t%s:\t%s\n", bpf_config_terms[i].usage,
+bpf_config_terms[i].desc);
+   pr_debug("\n");
+
+   return -BPF_LOADER_ERRNO__CONFIG_TERM;
+}
+
+static const char *
+parse_config_kvpair(const char *config_str, struct perf_probe_event *pev)
+{
+   char *text = strdup(config_str);
+   char *sep, *line;
+   const char *main_str = NULL;
+   int err = 0;
+
+   if (!text) {
+   pr_debug("No enough memory: dup config_str failed\n");
+   return ERR_PTR(-ENOMEM);
+   }
+
+   line = text;
+   while ((sep = strchr(line, ';'))) {
+   char *equ;
+
+   *sep = '\0';
+   equ = strchr(line, '=');
+   if (!equ) {
+   pr_warning("WARNING: invalid config in BPF object: 
%s\n",
+  line);
+   pr_warning("\tShould be 'key=value'.\n");
+   goto nextline;
+   }
+   *equ = '\0';
+
+   err = do_config(line, equ + 1, pev);
+   if (err)
+   break;
+nextline:
+   line = sep + 1;
+   }
+
+   if (!err)
+   main_str = config_str + (line - text);
+   free(text);
+
+   return err ? ERR_PTR(err) : main_str;
+}
+
+static int
+parse_config(const char *config_str, struct perf_probe_event *pev)
+{
+   int err;
+   const char *main_str = parse_config_kvpair(config_str, pev);
+
+   if (IS_ERR(main_str))
+   return PTR_ERR(main_str);
+
+   err = parse_perf_probe_command(main_str, pev);
+   if (err < 0) {
+   pr_debug("bpf: '%s' is not a valid config string\n",
+config_str);
+   /* parse failed, don't need clear pev. */
+   return -BPF_LOADER_ERRNO__CONFIG;
+   }
+   return 0;
+}
+
+static int
 config_bpf_program(struct bpf_program *prog)
 {
struct perf_probe_event *pev = NULL;
@@ -131,13 +238,9 @@ config_bpf_program(struct bpf_program *prog)
pev = >pev;
 
pr_debug("bpf: config program '%s'\n", config_str);
-   err = parse_perf_probe_command(config_str, pev);
-   if (err < 0) {
-   pr_debug("bpf: '%s' is not a valid config string\n",
-config_str);
-   err = -BPF_LOADER_ERRNO__CONFIG;
+   err = parse_config(config_str, pev);
+   if (err)
goto errout;
-   }
 
if (pev->group && strcmp(pev->group, PERF_BPF_PROBE_GROUP)) {
pr_debug("bpf: '%s': group for event is set and not '%s'.\n",

[PATCH 11/37] perf bpf: Add prologue for BPF programs for fetching arguments

2015-11-19 Thread Arnaldo Carvalho de Melo
From: He Kuang 

This patch generates a prologue for a BPF program which fetches arguments for
it.  With this patch, the program can have arguments as follow:

  SEC("lock_page=__lock_page page->flags")
  int lock_page(struct pt_regs *ctx, int err, unsigned long flags)
  {
 return 1;
  }

This patch passes at most 3 arguments from r3, r4 and r5. r1 is still the ctx
pointer. r2 is used to indicate if dereferencing was done successfully.

This patch uses r6 to hold ctx (struct pt_regs) and r7 to hold stack pointer
for result. Result of each arguments first store on stack:

 low address
 BPF_REG_FP - 24  ARG3
 BPF_REG_FP - 16  ARG2
 BPF_REG_FP - 8   ARG1
 BPF_REG_FP
 high address

Then loaded into r3, r4 and r5.

The output prologue for offn(...off2(off1(reg should be:

 r6 <- r1   // save ctx into a callee saved register
 r7 <- fp
 r7 <- r7 - stack_offset// pointer to result slot
 /* load r3 with the offset in pt_regs of 'reg' */
 (r7) <- r3 // make slot valid
 r3 <- r3 + off1// prepare to read unsafe pointer
 r2 <- 8
 r1 <- r7   // result put onto stack
 call probe_read// read unsafe pointer
 jnei r0, 0, err// error checking
 r3 <- (r7) // read result
 r3 <- r3 + off2// prepare to read unsafe pointer
 r2 <- 8
 r1 <- r7
 call probe_read
 jnei r0, 0, err
 ...
 /* load r2, r3, r4 from stack */
 goto success
err:
 r2 <- 1
 /* load r3, r4, r5 with 0 */
 goto usercode
success:
 r2 <- 0
usercode:
 r1 <- r6   // restore ctx
 // original user code

If all of arguments reside in register (dereferencing is not
required), gen_prologue_fastpath() will be used to create
fast prologue:

 r3 <- (r1 + offset of reg1)
 r4 <- (r1 + offset of reg2)
 r5 <- (r1 + offset of reg3)
 r2 <- 0

P.S.

eBPF calling convention is defined as:

* r0- return value from in-kernel function, and exit value
  for eBPF program
* r1 - r5   - arguments from eBPF program to in-kernel function
* r6 - r9   - callee saved registers that in-kernel function will
  preserve
* r10   - read-only frame pointer to access stack

Committer note:

At least testing if it builds and loads:

  # cat test_probe_arg.c
  struct pt_regs;

  __attribute__((section("lock_page=__lock_page page->flags"), used))
  int func(struct pt_regs *ctx, int err, unsigned long flags)
  {
return 1;
  }

  char _license[] __attribute__((section("license"), used)) = "GPL";
  int _version __attribute__((section("version"), used)) = 0x40300;
  # perf record -e ./test_probe_arg.c usleep 1
  [ perf record: Woken up 1 times to write data ]
  [ perf record: Captured and wrote 0.016 MB perf.data ]
  # perf evlist
  perf_bpf_probe:lock_page
  #

Signed-off-by: He Kuang 
Tested-by: Arnaldo Carvalho de Melo 
Cc: Alexei Starovoitov 
Cc: Masami Hiramatsu 
Cc: Wang Nan 
Cc: Zefan Li 
Cc: pi3or...@163.com
Link: 
http://lkml.kernel.org/r/1447675815-166222-11-git-send-email-wangn...@huawei.com
Signed-off-by: Wang Nan 
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/util/Build  |   1 +
 tools/perf/util/bpf-loader.c   |   3 +
 tools/perf/util/bpf-loader.h   |   3 +
 tools/perf/util/bpf-prologue.c | 455 +
 tools/perf/util/bpf-prologue.h |  34 +++
 5 files changed, 496 insertions(+)
 create mode 100644 tools/perf/util/bpf-prologue.c
 create mode 100644 tools/perf/util/bpf-prologue.h

diff --git a/tools/perf/util/Build b/tools/perf/util/Build
index e2316900f96f..0513dd525d87 100644
--- a/tools/perf/util/Build
+++ b/tools/perf/util/Build
@@ -89,6 +89,7 @@ libperf-y += parse-branch-options.o
 libperf-y += parse-regs-options.o
 
 libperf-$(CONFIG_LIBBPF) += bpf-loader.o
+libperf-$(CONFIG_BPF_PROLOGUE) += bpf-prologue.o
 libperf-$(CONFIG_LIBELF) += symbol-elf.o
 libperf-$(CONFIG_LIBELF) += probe-file.o
 libperf-$(CONFIG_LIBELF) += probe-event.o
diff --git a/tools/perf/util/bpf-loader.c b/tools/perf/util/bpf-loader.c
index 98f2e5d1a5be..bd14be438cda 100644
--- a/tools/perf/util/bpf-loader.c
+++ b/tools/perf/util/bpf-loader.c
@@ -509,6 +509,9 @@ static const char *bpf_loader_strerror_table[NR_ERRNO] = {
[ERRCODE_OFFSET(INTERNAL)]  = "BPF loader internal error",
[ERRCODE_OFFSET(COMPILE)]   = "Error when compiling BPF scriptlet",
[ERRCODE_OFFSET(CONFIG_TERM)]   = "Invalid config term in config 
string",
+   [ERRCODE_OFFSET(PROLOGUE)]  = "Failed to generate prologue",
+   [ERRCODE_OFFSET(PROLOGUE2BIG)]  = "Prologue too big for program",
+   [ERRCODE_OFFSET(PROLOGUEOOB)]   = "Offset out of bound for prologue",
 };
 
 static int
diff --git a/tools/perf/util/bpf-loader.h b/tools/perf/util/bpf-loader.h
index d19f5c5d6d74..a58740b0f31e 100644
--- a/tools/perf/util/bpf-loader.h
+++ b/tools/perf/util/bpf-loader.h

[PATCH 04/37] tools: Clone the kernel's strtobool function

2015-11-19 Thread Arnaldo Carvalho de Melo
From: Wang Nan 

Copying it to tools/lib/string.c, the counterpart to the kernel's
lib/string.c.

This is preparation for enhancing BPF program configuration, which will
allow config string like 'inlines=yes'.

Signed-off-by: Wang Nan 
Cc: Alexei Starovoitov 
Cc: Jonathan Cameron 
Cc: Masami Hiramatsu 
Cc: Zefan Li 
Cc: pi3or...@163.com
Link: 
http://lkml.kernel.org/r/1447675815-166222-6-git-send-email-wangn...@huawei.com
[ Copied it to tools/lib/string.c instead, to make it usable by other tools/ ]
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/include/linux/string.h |  2 ++
 tools/lib/string.c   | 43 +++
 2 files changed, 45 insertions(+)

diff --git a/tools/include/linux/string.h b/tools/include/linux/string.h
index f3a6db6ad732..2e2f736c039c 100644
--- a/tools/include/linux/string.h
+++ b/tools/include/linux/string.h
@@ -6,4 +6,6 @@
 
 void *memdup(const void *src, size_t len);
 
+int strtobool(const char *s, bool *res);
+
 #endif /* _LINUX_STRING_H_ */
diff --git a/tools/lib/string.c b/tools/lib/string.c
index ecfd43a9b24e..065e54f42d8f 100644
--- a/tools/lib/string.c
+++ b/tools/lib/string.c
@@ -1,5 +1,20 @@
+/*
+ *  linux/tools/lib/string.c
+ *
+ *  Copied from linux/lib/string.c, where it is:
+ *
+ *  Copyright (C) 1991, 1992  Linus Torvalds
+ *
+ *  More specifically, the first copied function was strtobool, which
+ *  was introduced by:
+ *
+ *  d0f1fed29e6e ("Add a strtobool function matching semantics of existing in 
kernel equivalents")
+ *  Author: Jonathan Cameron 
+ */
+
 #include 
 #include 
+#include 
 #include 
 
 /**
@@ -17,3 +32,31 @@ void *memdup(const void *src, size_t len)
 
return p;
 }
+
+/**
+ * strtobool - convert common user inputs into boolean values
+ * @s: input string
+ * @res: result
+ *
+ * This routine returns 0 iff the first character is one of 'Yy1Nn0'.
+ * Otherwise it will return -EINVAL.  Value pointed to by res is
+ * updated upon finding a match.
+ */
+int strtobool(const char *s, bool *res)
+{
+   switch (s[0]) {
+   case 'y':
+   case 'Y':
+   case '1':
+   *res = true;
+   break;
+   case 'n':
+   case 'N':
+   case '0':
+   *res = false;
+   break;
+   default:
+   return -EINVAL;
+   }
+   return 0;
+}
-- 
2.1.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/


[PATCH 14/37] perf test: Fix 'perf test BPF' when it fails to find a suitable vmlinux

2015-11-19 Thread Arnaldo Carvalho de Melo
From: Wang Nan 

Two bugs in 'perf test BPF' are found when testing BPF prologue without
vmlinux:

 # mv /lib/modules/4.3.0-rc4+/build/vmlinux{,.bak}
 # ./perf test BPF
 37: Test BPF filter :Failed to find the path for kernel: No such 
file or directory
 Ok

Test BPF should fail in this case.

After this patch:

 # ./perf test BPF
 37: Test BPF filter :Failed to find the path for kernel: No such 
file or directory
  FAILED!
 # mv /lib/modules/4.3.0-rc4+/build/vmlinux{.bak,}
 # ./perf test BPF
 37: Test BPF filter : Ok

Signed-off-by: Wang Nan 
Cc: Alexei Starovoitov 
Cc: Masami Hiramatsu 
Cc: Zefan Li 
Cc: pi3or...@163.com
Link: 
http://lkml.kernel.org/r/1447749170-175898-2-git-send-email-wangn...@huawei.com
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/tests/bpf.c | 7 ---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/tools/perf/tests/bpf.c b/tools/perf/tests/bpf.c
index d58442294e9e..232043cc232a 100644
--- a/tools/perf/tests/bpf.c
+++ b/tools/perf/tests/bpf.c
@@ -102,8 +102,7 @@ static int do_test(struct bpf_object *obj, int 
(*func)(void),
err = parse_events_load_bpf_obj(_evlist, _evlist.list, obj);
if (err || list_empty(_evlist.list)) {
pr_debug("Failed to add events selected by BPF\n");
-   if (!err)
-   return TEST_FAIL;
+   return TEST_FAIL;
}
 
snprintf(pid, sizeof(pid), "%d", getpid());
@@ -157,8 +156,10 @@ static int do_test(struct bpf_object *obj, int 
(*func)(void),
}
}
 
-   if (count != expect)
+   if (count != expect) {
pr_debug("BPF filter result incorrect\n");
+   goto out_delete_evlist;
+   }
 
ret = TEST_OK;
 
-- 
2.1.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/


[PATCH 25/37] perf tools: Fix to put new map after inserting to map_groups in dso__load_sym

2015-11-19 Thread Arnaldo Carvalho de Melo
From: Masami Hiramatsu 

Fix dso__load_sym to put the map object which is already
insterted to kmaps.

Refcnt debugger shows
   [0] 
  Unreclaimed map: 0x39113e0
  Refcount +1 => 1 at
./perf(map__new2+0xb5) [0x4be155]
./perf(dso__load_sym+0xee1) [0x503461]
./perf(dso__load_vmlinux+0xbf) [0x4aa6df]
./perf(dso__load_vmlinux_path+0x8c) [0x4aa83c]
./perf() [0x50528a]
./perf(convert_perf_probe_events+0xd79) [0x50ac29]
./perf() [0x45600f]
./perf(cmd_probe+0x6c) [0x4566bc]
./perf() [0x47abc5]
./perf(main+0x610) [0x421f90]
/lib64/libc.so.6(__libc_start_main+0xf5) [0x7f152368baf5]
./perf() [0x4220a9]
  Refcount +1 => 2 at
./perf(maps__insert+0x9a) [0x4bfffa]
./perf(dso__load_sym+0xf89) [0x503509]
./perf(dso__load_vmlinux+0xbf) [0x4aa6df]
./perf(dso__load_vmlinux_path+0x8c) [0x4aa83c]
./perf() [0x50528a]
./perf(convert_perf_probe_events+0xd79) [0x50ac29]
./perf() [0x45600f]
./perf(cmd_probe+0x6c) [0x4566bc]
./perf() [0x47abc5]
./perf(main+0x610) [0x421f90]
/lib64/libc.so.6(__libc_start_main+0xf5) [0x7f152368baf5]
./perf() [0x4220a9]
  Refcount -1 => 1 at
./perf(map_groups__exit+0x94) [0x4bed04]
./perf(machine__delete+0xb0) [0x4b9300]
./perf(exit_probe_symbol_maps+0x28) [0x506608]
./perf() [0x45628a]
./perf(cmd_probe+0x6c) [0x4566bc]
./perf() [0x47abc5]
./perf(main+0x610) [0x421f90]
/lib64/libc.so.6(__libc_start_main+0xf5) [0x7f152368baf5]
./perf() [0x4220a9]

This means that the dso__load_sym calls map__new2 and maps_insert, both
of them bump the map refcount, but map_groups__exit will drop just one
reference.

Fix it by dropping the refcount after inserting it into kmaps.

Signed-off-by: Masami Hiramatsu 
Cc: Adrian Hunter 
Cc: Jiri Olsa 
Cc: Namhyung Kim 
Cc: Peter Zijlstra 
Link: 
http://lkml.kernel.org/r/20151118064026.30709.50038.stgit@localhost.localdomain
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/util/symbol-elf.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/tools/perf/util/symbol-elf.c b/tools/perf/util/symbol-elf.c
index 475d88d0a1c9..53f19968bfa2 100644
--- a/tools/perf/util/symbol-elf.c
+++ b/tools/perf/util/symbol-elf.c
@@ -1042,6 +1042,8 @@ int dso__load_sym(struct dso *dso, struct map *map,
}
curr_dso->symtab_type = dso->symtab_type;
map_groups__insert(kmaps, curr_map);
+   /* kmaps already got it */
+   map__put(curr_map);
dsos__add(>groups->machine->dsos, 
curr_dso);
dso__set_loaded(curr_dso, map->type);
} else
-- 
2.1.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/


[PATCH 05/37] bpf tools: Load a program with different instances using preprocessor

2015-11-19 Thread Arnaldo Carvalho de Melo
From: Wang Nan 

This patch is a preparation for BPF prologue support which allows
generating a series of BPF bytecode for fetching kernel data before
calling program code. With the newly introduced multiple instances
support, perf is able to create different prologues for different kprobe
points.

Before this patch, a bpf_program can be loaded into kernel only once,
and get the only resulting fd. What this patch does is to allow creating
and loading different variants of one bpf_program, then fetching their
fds.

Here we describe the basic idea in this patch. The detailed description
of the newly introduced APIs can be found in comments in the patch body.

The key of this patch is the new mechanism in bpf_program__load().
Instead of loading BPF program into kernel directly, it calls a
'pre-processor' to generate program instances which would be finally
loaded into the kernel based on the original code. To enable the
generation of multiple instances, libbpf passes an index to the
pre-processor so it know which instance is being loaded.

Pre-processor should be called from libbpf's user (perf) using
bpf_program__set_prep(). The number of instances and the relationship
between indices and the target instance should be clear when calling
bpf_program__set_prep().

To retrieve a fd for a specific instance of a program,
bpf_program__nth_fd() is introduced. It returns the resulting fd
according to index.

Signed-off-by: He Kuang 
Cc: Alexei Starovoitov 
Cc: He Kuang 
Cc: Masami Hiramatsu 
Cc: Zefan Li 
Cc: pi3or...@163.com
Link: 
http://lkml.kernel.org/r/1447675815-166222-8-git-send-email-wangn...@huawei.com
Signed-off-by: Wang Nan 
[ Enclosed multi-line if/else blocks with {}, (*func_ptr)() -> func_ptr() ]
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/lib/bpf/libbpf.c | 146 ++---
 tools/lib/bpf/libbpf.h |  64 ++
 2 files changed, 201 insertions(+), 9 deletions(-)

diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
index e176bad19bcb..e3f4c3379f14 100644
--- a/tools/lib/bpf/libbpf.c
+++ b/tools/lib/bpf/libbpf.c
@@ -152,7 +152,11 @@ struct bpf_program {
} *reloc_desc;
int nr_reloc;
 
-   int fd;
+   struct {
+   int nr;
+   int *fds;
+   } instances;
+   bpf_program_prep_t preprocessor;
 
struct bpf_object *obj;
void *priv;
@@ -206,10 +210,25 @@ struct bpf_object {
 
 static void bpf_program__unload(struct bpf_program *prog)
 {
+   int i;
+
if (!prog)
return;
 
-   zclose(prog->fd);
+   /*
+* If the object is opened but the program was never loaded,
+* it is possible that prog->instances.nr == -1.
+*/
+   if (prog->instances.nr > 0) {
+   for (i = 0; i < prog->instances.nr; i++)
+   zclose(prog->instances.fds[i]);
+   } else if (prog->instances.nr != -1) {
+   pr_warning("Internal error: instances.nr is %d\n",
+  prog->instances.nr);
+   }
+
+   prog->instances.nr = -1;
+   zfree(>instances.fds);
 }
 
 static void bpf_program__exit(struct bpf_program *prog)
@@ -260,7 +279,8 @@ bpf_program__init(void *data, size_t size, char *name, int 
idx,
memcpy(prog->insns, data,
   prog->insns_cnt * sizeof(struct bpf_insn));
prog->idx = idx;
-   prog->fd = -1;
+   prog->instances.fds = NULL;
+   prog->instances.nr = -1;
 
return 0;
 errout:
@@ -860,13 +880,73 @@ static int
 bpf_program__load(struct bpf_program *prog,
  char *license, u32 kern_version)
 {
-   int err, fd;
+   int err = 0, fd, i;
 
-   err = load_program(prog->insns, prog->insns_cnt,
-  license, kern_version, );
-   if (!err)
-   prog->fd = fd;
+   if (prog->instances.nr < 0 || !prog->instances.fds) {
+   if (prog->preprocessor) {
+   pr_warning("Internal error: can't load program '%s'\n",
+  prog->section_name);
+   return -LIBBPF_ERRNO__INTERNAL;
+   }
 
+   prog->instances.fds = malloc(sizeof(int));
+   if (!prog->instances.fds) {
+   pr_warning("Not enough memory for BPF fds\n");
+   return -ENOMEM;
+   }
+   prog->instances.nr = 1;
+   prog->instances.fds[0] = -1;
+   }
+
+   if (!prog->preprocessor) {
+   if (prog->instances.nr != 1) {
+   pr_warning("Program '%s' is inconsistent: nr(%d) != 
1\n",
+  prog->section_name, prog->instances.nr);
+   }
+   err = load_program(prog->insns, prog->insns_cnt,
+  license, kern_version, );
+   if (!err)
+   prog->instances.fds[0] = fd;
+   goto 

[PATCH 23/37] perf machine: Fix to destroy kernel maps when machine exits

2015-11-19 Thread Arnaldo Carvalho de Melo
From: Masami Hiramatsu 

Actually machine__exit forgot to call machine__destroy_kernel_maps.

This fixes some memory leaks on map as below.

Without this fix.
  
  ./perf probe vfs_read
  Added new event:
probe:vfs_read   (on vfs_read)

  You can now use it in all perf tools, such as:

  perf record -e probe:vfs_read -aR sleep 1

  REFCNT: BUG: Unreclaimed objects found.
  REFCNT: Total 4 objects are not reclaimed.
 To see all backtraces, rerun with -v option
  
With this fix.
  
  ./perf probe vfs_read
  Added new event:
probe:vfs_read   (on vfs_read)

  You can now use it in all perf tools, such as:

  perf record -e probe:vfs_read -aR sleep 1

  REFCNT: BUG: Unreclaimed objects found.
  REFCNT: Total 2 objects are not reclaimed.
 To see all backtraces, rerun with -v option
  

Signed-off-by: Masami Hiramatsu 
Cc: Adrian Hunter 
Cc: Jiri Olsa 
Cc: Namhyung Kim 
Cc: Peter Zijlstra 
Link: 
http://lkml.kernel.org/r/20151118064024.30709.43577.stgit@localhost.localdomain
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/util/machine.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/tools/perf/util/machine.c b/tools/perf/util/machine.c
index e9e09bee221c..a358771fe9e3 100644
--- a/tools/perf/util/machine.c
+++ b/tools/perf/util/machine.c
@@ -122,6 +122,7 @@ void machine__delete_threads(struct machine *machine)
 
 void machine__exit(struct machine *machine)
 {
+   machine__destroy_kernel_maps(machine);
map_groups__exit(>kmaps);
dsos__exit(>dsos);
machine__exit_vdso(machine);
-- 
2.1.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/


Re: [PATCH 4/4] locking: Introduce smp_cond_acquire()

2015-11-19 Thread Will Deacon
On Wed, Nov 18, 2015 at 11:25:14AM +, Will Deacon wrote:
> On Tue, Nov 17, 2015 at 01:01:09PM -0800, Paul E. McKenney wrote:
> > On Tue, Nov 17, 2015 at 11:51:10AM +, Will Deacon wrote:
> > > On Mon, Nov 16, 2015 at 01:58:49PM -0800, Linus Torvalds wrote:
> > > > On Mon, Nov 16, 2015 at 8:24 AM, Will Deacon  
> > > > wrote:
> > > > >
> > > > > ... or we upgrade spin_unlock_wait to a LOCK operation, which might be
> > > > > slightly cheaper than spin_lock()+spin_unlock().
> > > > 
> > > > So traditionally the real concern has been the cacheline ping-pong
> > > > part of spin_unlock_wait(). I think adding a memory barrier (that
> > > > doesn't force any exclusive states, just ordering) to it is fine, but
> > > > I don't think we want to necessarily have it have to get the cacheline
> > > > into exclusive state.
> > > 
> > > The problem is, I don't think the memory-barrier buys you anything in
> > > the context of Boqun's example. In fact, he already had smp_mb() either
> > > side of the spin_unlock_wait() and its still broken on arm64 and ppc.
> > > 
> > > Paul is proposing adding a memory barrier after spin_lock() in the racing
> > > thread, but I personally think people will forget to add that.
> > 
> > A mechanical check would certainly make me feel better about it, so that
> > any lock that was passed to spin_unlock_wait() was required to have all
> > acquisitions followed by smp_mb__after_unlock_lock() or some such.
> > But I haven't yet given up on finding a better solution.
> 
> Right-o. I'll hack together the arm64 spin_unlock_wait fix, but hold off
> merging it for a few weeks in case we get struck by a sudden flash of
> inspiration.

For completeness, here's what I've currently got. I've failed to measure
any performance impact on my 8-core systems, but that's not surprising.

Will

--->8

>From da14adc1aef2f12b7a7def4d6b7dde254a91ebf1 Mon Sep 17 00:00:00 2001
From: Will Deacon 
Date: Thu, 19 Nov 2015 17:48:31 +
Subject: [PATCH] arm64: spinlock: serialise spin_unlock_wait against
 concurrent lockers

Boqun Feng reported a rather nasty ordering issue with spin_unlock_wait
on architectures implementing spin_lock with LL/SC sequences and acquire
semantics:

 | CPU 1   CPU 2 CPU 3
 | ==    ==
 |   spin_unlock();
 | spin_lock():
 |   r1 = *lock; // r1 == 0;
 | o = READ_ONCE(object); // reordered here
 | object = NULL;
 | smp_mb();
 | spin_unlock_wait();
 |   *lock = 1;
 | smp_mb();
 | o->dead = true;
 | if (o) // true
 |   BUG_ON(o->dead); // true!!

The crux of the problem is that spin_unlock_wait() can return on
CPU 1 whilst CPU 2 is in the process of taking the lock. This can be
resolved by upgrading spin_unlock_wait to a LOCK operation, forcing it
to serialise against a concurrent locker and giving it acquire semantics
in the process (although it is not at all clear whether this is needed -
different callers seem to assume different things about the barrier
semantics and architectures are similarly disjoint in their
implementations of the macro).

This patch implements spin_unlock_wait using an LL/SC sequence with
acquire semantics on arm64. For v8.1 systems with the LSE atomics, the
exclusive writeback is omitted, since the spin_lock operation is
indivisible and no intermediate state can be observed.

Signed-off-by: Will Deacon 
---
 arch/arm64/include/asm/spinlock.h | 24 ++--
 1 file changed, 22 insertions(+), 2 deletions(-)

diff --git a/arch/arm64/include/asm/spinlock.h 
b/arch/arm64/include/asm/spinlock.h
index c85e96d174a5..b531791a75ff 100644
--- a/arch/arm64/include/asm/spinlock.h
+++ b/arch/arm64/include/asm/spinlock.h
@@ -26,9 +26,29 @@
  * The memory barriers are implicit with the load-acquire and store-release
  * instructions.
  */
+static inline void arch_spin_unlock_wait(arch_spinlock_t *lock)
+{
+   unsigned int tmp;
+   arch_spinlock_t lockval;
 
-#define arch_spin_unlock_wait(lock) \
-   do { while (arch_spin_is_locked(lock)) cpu_relax(); } while (0)
+   asm volatile(
+"  sevl\n"
+"1:wfe\n"
+"2:ldaxr   %w0, %2\n"
+"  eor %w1, %w0, %w0, ror #16\n"
+"  cbnz%w1, 1b\n"
+   ARM64_LSE_ATOMIC_INSN(
+   /* LL/SC */
+"  stxr%w1, %w0, %2\n"
+   /* Serialise against any concurrent lockers */
+"  cbnz%w1, 2b\n",
+   /* LSE atomics */
+"  nop\n"
+"  nop\n")
+   : "=" (lockval), "=" (tmp), "+Q" (*lock)
+   :
+   : "memory");
+}
 
 #define arch_spin_lock_flags(lock, flags) arch_spin_lock(lock)
 
-- 
2.1.4

--
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  

[PATCH 28/37] perf machine: Fix machine__findnew_module_map to put dso

2015-11-19 Thread Arnaldo Carvalho de Melo
From: Masami Hiramatsu 

Fix machine__findnew_module_map to drop the reference to the dso because
it is already referenced by both machine__findnew_module_dso() and
map__new2().

Refcnt debugger shows:

   [1] 
  Unreclaimed dso: 0x1ffd980
  Refcount +1 => 1 at
./perf(dso__new+0x1ff) [0x4a62df]
./perf(__dsos__addnew+0x29) [0x4a6e19]
./perf() [0x4b8b91]
./perf(modules__parse+0xfc) [0x4a9d5c]
./perf() [0x4b8460]
./perf(machine__create_kernel_maps+0x150) [0x4bb550]
./perf(machine__new_host+0xfa) [0x4bb75a]
./perf(init_probe_symbol_maps+0x93) [0x506623]
./perf() [0x455ffa]
./perf(cmd_probe+0x6c) [0x4566bc]
./perf() [0x47abc5]
./perf(main+0x610) [0x421f90]
/lib64/libc.so.6(__libc_start_main+0xf5) [0x7f1345a8eaf5]
./perf() [0x4220a9]

This map_groups__insert(0x4b8b91) already gets a reference to the new
dso:

  
  eu-addr2line -e ./perf -f 0x4b8b91
  map_groups__insert inlined at util/machine.c:586 in
  machine__create_module
  util/map.h:207
  

So this dso refcnt will be released when map_groups gets released.

  [snip]
  Refcount +1 => 2 at
./perf(dso__get+0x34) [0x4a65f4]
./perf() [0x4b8b35]
./perf(modules__parse+0xfc) [0x4a9d5c]
./perf() [0x4b8460]
./perf(machine__create_kernel_maps+0x150) [0x4bb550]
./perf(machine__new_host+0xfa) [0x4bb75a]
./perf(init_probe_symbol_maps+0x93) [0x506623]
./perf() [0x455ffa]
./perf(cmd_probe+0x6c) [0x4566bc]
./perf() [0x47abc5]
./perf(main+0x610) [0x421f90]
/lib64/libc.so.6(__libc_start_main+0xf5) [0x7f1345a8eaf5]
./perf() [0x4220a9]

Here, machine__findnew_module_dso(0x4b8b35) gets the dso (and stores it
in a local variable):

  
  # eu-addr2line -e ./perf -f 0x4b8b35
  machine__findnew_module_dso inlined at util/machine.c:578 in
  machine__create_module
  util/machine.c:514
  

  Refcount +1 => 3 at
./perf(dso__get+0x34) [0x4a65f4]
./perf(map__new2+0x76) [0x4be1c6]
./perf() [0x4b8b4f]
./perf(modules__parse+0xfc) [0x4a9d5c]
./perf() [0x4b8460]
./perf(machine__create_kernel_maps+0x150) [0x4bb550]
./perf(machine__new_host+0xfa) [0x4bb75a]
./perf(init_probe_symbol_maps+0x93) [0x506623]
./perf() [0x455ffa]
./perf(cmd_probe+0x6c) [0x4566bc]
./perf() [0x47abc5]
./perf(main+0x610) [0x421f90]
/lib64/libc.so.6(__libc_start_main+0xf5) [0x7f1345a8eaf5]
./perf() [0x4220a9]

But also map__new2() gets the dso which will be put when the map is
released.

So, we have to drop the constructor reference obtained in
machine__findnew_module_dso().

Signed-off-by: Masami Hiramatsu 
Cc: Adrian Hunter 
Cc: Jiri Olsa 
Cc: Namhyung Kim 
Cc: Peter Zijlstra 
Link: 
http://lkml.kernel.org/r/20151118064035.30709.58824.stgit@localhost.localdomain
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/util/machine.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/tools/perf/util/machine.c b/tools/perf/util/machine.c
index 0b4a05c14204..7f5071a4d9aa 100644
--- a/tools/perf/util/machine.c
+++ b/tools/perf/util/machine.c
@@ -565,7 +565,7 @@ struct map *machine__findnew_module_map(struct machine 
*machine, u64 start,
const char *filename)
 {
struct map *map = NULL;
-   struct dso *dso;
+   struct dso *dso = NULL;
struct kmod_path m;
 
if (kmod_path__parse_name(, filename))
@@ -589,6 +589,8 @@ struct map *machine__findnew_module_map(struct machine 
*machine, u64 start,
/* Put the map here because map_groups__insert alread got it */
map__put(map);
 out:
+   /* put the dso here, corresponding to  machine__findnew_module_dso */
+   dso__put(dso);
free(m.name);
return map;
 }
-- 
2.1.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/


[PATCH 16/37] perf tests: Pass the subtest index to each test routine

2015-11-19 Thread Arnaldo Carvalho de Melo
From: Arnaldo Carvalho de Melo 

Some tests have sub-tests we want to run, so allow passing this.

Wang tried to avoid having to touch all tests, but then, having the
test.func in an anonymous union makes the build fail on older compilers,
like the one in RHEL6, where:

  test a = {
.func = foo,
  };

fails.

To fix it leave the func pointer in the main structure and pass the subtest
index to all tests, end result function is the same, but we have just one
function pointer, not two, with and without the subtest index as an argument.

Cc: Adrian Hunter 
Cc: David Ahern 
Cc: Jiri Olsa 
Cc: Namhyung Kim 
Cc: Wang Nan 
Link: http://lkml.kernel.org/n/tip-5genj0ficwdmelpoqlds0...@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/arch/x86/include/arch-tests.h |  8 +--
 tools/perf/arch/x86/tests/insn-x86.c |  2 +-
 tools/perf/arch/x86/tests/intel-cqm.c|  2 +-
 tools/perf/arch/x86/tests/perf-time-to-tsc.c |  2 +-
 tools/perf/arch/x86/tests/rdpmc.c|  2 +-
 tools/perf/tests/attr.c  |  2 +-
 tools/perf/tests/bp_signal.c |  2 +-
 tools/perf/tests/bp_signal_overflow.c|  2 +-
 tools/perf/tests/bpf.c   |  2 +-
 tools/perf/tests/builtin-test.c  |  6 +--
 tools/perf/tests/code-reading.c  |  2 +-
 tools/perf/tests/dso-data.c  |  6 +--
 tools/perf/tests/dwarf-unwind.c  |  2 +-
 tools/perf/tests/evsel-roundtrip-name.c  |  2 +-
 tools/perf/tests/evsel-tp-sched.c|  2 +-
 tools/perf/tests/fdarray.c   |  4 +-
 tools/perf/tests/hists_cumulate.c|  2 +-
 tools/perf/tests/hists_filter.c  |  2 +-
 tools/perf/tests/hists_link.c|  2 +-
 tools/perf/tests/hists_output.c  |  2 +-
 tools/perf/tests/keep-tracking.c |  2 +-
 tools/perf/tests/kmod-path.c |  2 +-
 tools/perf/tests/llvm.c  |  2 +-
 tools/perf/tests/mmap-basic.c|  2 +-
 tools/perf/tests/mmap-thread-lookup.c|  2 +-
 tools/perf/tests/openat-syscall-all-cpus.c   |  2 +-
 tools/perf/tests/openat-syscall-tp-fields.c  |  2 +-
 tools/perf/tests/openat-syscall.c|  2 +-
 tools/perf/tests/parse-events.c  |  2 +-
 tools/perf/tests/parse-no-sample-id-all.c|  2 +-
 tools/perf/tests/perf-record.c   |  2 +-
 tools/perf/tests/pmu.c   |  2 +-
 tools/perf/tests/python-use.c|  3 +-
 tools/perf/tests/sample-parsing.c|  2 +-
 tools/perf/tests/sw-clock.c  |  2 +-
 tools/perf/tests/switch-tracking.c   |  2 +-
 tools/perf/tests/task-exit.c |  2 +-
 tools/perf/tests/tests.h | 78 ++--
 tools/perf/tests/thread-map.c|  2 +-
 tools/perf/tests/thread-mg-share.c   |  2 +-
 tools/perf/tests/topology.c  |  2 +-
 tools/perf/tests/vmlinux-kallsyms.c  |  2 +-
 42 files changed, 89 insertions(+), 88 deletions(-)

diff --git a/tools/perf/arch/x86/include/arch-tests.h 
b/tools/perf/arch/x86/include/arch-tests.h
index 7ed00f4b0908..b48de2f5813c 100644
--- a/tools/perf/arch/x86/include/arch-tests.h
+++ b/tools/perf/arch/x86/include/arch-tests.h
@@ -2,10 +2,10 @@
 #define ARCH_TESTS_H
 
 /* Tests */
-int test__rdpmc(void);
-int test__perf_time_to_tsc(void);
-int test__insn_x86(void);
-int test__intel_cqm_count_nmi_context(void);
+int test__rdpmc(int subtest);
+int test__perf_time_to_tsc(int subtest);
+int test__insn_x86(int subtest);
+int test__intel_cqm_count_nmi_context(int subtest);
 
 #ifdef HAVE_DWARF_UNWIND_SUPPORT
 struct thread;
diff --git a/tools/perf/arch/x86/tests/insn-x86.c 
b/tools/perf/arch/x86/tests/insn-x86.c
index b6115dfd28f0..08d9b2bc185c 100644
--- a/tools/perf/arch/x86/tests/insn-x86.c
+++ b/tools/perf/arch/x86/tests/insn-x86.c
@@ -171,7 +171,7 @@ static int test_data_set(struct test_data *dat_set, int 
x86_64)
  * verbose (-v) option to see all the instructions and whether or not they
  * decoded successfuly.
  */
-int test__insn_x86(void)
+int test__insn_x86(int subtest __maybe_unused)
 {
int ret = 0;
 
diff --git a/tools/perf/arch/x86/tests/intel-cqm.c 
b/tools/perf/arch/x86/tests/intel-cqm.c
index d28c1b6a3b54..94e0cb7462f9 100644
--- a/tools/perf/arch/x86/tests/intel-cqm.c
+++ b/tools/perf/arch/x86/tests/intel-cqm.c
@@ -33,7 +33,7 @@ static pid_t spawn(void)
  * the last read counter value to avoid triggering a WARN_ON_ONCE() in
  * smp_call_function_many() caused by sending IPIs from NMI context.
  */
-int test__intel_cqm_count_nmi_context(void)
+int test__intel_cqm_count_nmi_context(int subtest __maybe_unused)
 {
struct perf_evlist *evlist = NULL;
struct perf_evsel *evsel = NULL;
diff --git a/tools/perf/arch/x86/tests/perf-time-to-tsc.c 
b/tools/perf/arch/x86/tests/perf-time-to-tsc.c
index 658cd200af74..a289aa8a083a 100644
--- 

[PATCH 22/37] perf machine: Fix machine__destroy_kernel_maps to drop vmlinux_maps references

2015-11-19 Thread Arnaldo Carvalho de Melo
From: Masami Hiramatsu 

Fix machine__destroy_kernel_maps() to drop vmlinux_maps references
before filling it with NULL.

Refcnt debugger shows
   [1] 
  Unreclaimed map: 0x36b1070
  Refcount +1 => 1 at
./perf(map__new2+0xb5) [0x4bdec5]
./perf(machine__create_kernel_maps+0x72) [0x4bb152]
./perf(machine__new_host+0xfa) [0x4bb41a]
./perf(init_probe_symbol_maps+0x93) [0x5062d3]
./perf() [0x455ffa]
./perf(cmd_probe+0x6c) [0x4566bc]
./perf() [0x47abc5]
./perf(main+0x610) [0x421f90]
/lib64/libc.so.6(__libc_start_main+0xf5) [0x7f1fc9fc4af5]
./perf() [0x4220a9]
  Refcount +1 => 2 at
./perf(maps__insert+0x9a) [0x4bfd6a]
./perf(machine__create_kernel_maps+0xc3) [0x4bb1a3]
./perf(machine__new_host+0xfa) [0x4bb41a]
./perf(init_probe_symbol_maps+0x93) [0x5062d3]
./perf() [0x455ffa]
./perf(cmd_probe+0x6c) [0x4566bc]
./perf() [0x47abc5]
./perf(main+0x610) [0x421f90]
/lib64/libc.so.6(__libc_start_main+0xf5) [0x7f1fc9fc4af5]
./perf() [0x4220a9]
  Refcount -1 => 1 at
./perf(map_groups__exit+0x94) [0x4bea74]
./perf(machine__delete+0x3d) [0x4b91fd]
./perf(exit_probe_symbol_maps+0x28) [0x506378]
./perf() [0x45628a]
./perf(cmd_probe+0x6c) [0x4566bc]
./perf() [0x47abc5]
./perf(main+0x610) [0x421f90]
/lib64/libc.so.6(__libc_start_main+0xf5) [0x7f1fc9fc4af5]
./perf() [0x4220a9]

map__new2() returns map with refcnt = 1, and also map_groups__insert
gets it again in__machine__create_kernel_maps().

machine__destroy_kernel_maps() calls map_groups__remove() to
decrement the refcnt, but before decrement it again (corresponding
to map__new2), it makes vmlinux_maps[type] = NULL. And this may
cause a refcnt leak.

Signed-off-by: Masami Hiramatsu 
Cc: Adrian Hunter 
Cc: Jiri Olsa 
Cc: Namhyung Kim 
Cc: Peter Zijlstra 
Link: 
http://lkml.kernel.org/r/20151118064022.30709.3897.stgit@localhost.localdomain
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/util/machine.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/tools/perf/util/machine.c b/tools/perf/util/machine.c
index 0487d7795f13..e9e09bee221c 100644
--- a/tools/perf/util/machine.c
+++ b/tools/perf/util/machine.c
@@ -790,6 +790,7 @@ void machine__destroy_kernel_maps(struct machine *machine)
kmap->ref_reloc_sym = NULL;
}
 
+   map__put(machine->vmlinux_maps[type]);
machine->vmlinux_maps[type] = NULL;
}
 }
-- 
2.1.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/


[PATCH 21/37] perf machine: Fix machine__findnew_module_map to put registered map

2015-11-19 Thread Arnaldo Carvalho de Melo
From: Masami Hiramatsu 

Fix machine object to drop the reference to the map object after it
inserted it into machine->kmaps.

refcnt debugger shows what happened:
  
   [2] 
  Unreclaimed map: 0x346f750
  Refcount +1 => 1 at
./perf(map__new2+0xb5) [0x4bdea5]
./perf() [0x4b8aaf]
./perf(modules__parse+0xfc) [0x4a9cbc]
./perf() [0x4b83c0]
./perf(machine__create_kernel_maps+0x148) [0x4bb208]
./perf(machine__new_host+0xfa) [0x4bb3fa]
./perf(init_probe_symbol_maps+0x93) [0x5062b3]
./perf() [0x455ffa]
./perf(cmd_probe+0x6c) [0x4566bc]
./perf() [0x47abc5]
./perf(main+0x610) [0x421f90]
/lib64/libc.so.6(__libc_start_main+0xf5) [0x7f5373899af5]
./perf() [0x4220a9]
  Refcount +1 => 2 at
./perf(maps__insert+0x9a) [0x4bfd4a]
./perf() [0x4b8acb]
./perf(modules__parse+0xfc) [0x4a9cbc]
./perf() [0x4b83c0]
./perf(machine__create_kernel_maps+0x148) [0x4bb208]
./perf(machine__new_host+0xfa) [0x4bb3fa]
./perf(init_probe_symbol_maps+0x93) [0x5062b3]
./perf() [0x455ffa]
./perf(cmd_probe+0x6c) [0x4566bc]
./perf() [0x47abc5]
./perf(main+0x610) [0x421f90]
/lib64/libc.so.6(__libc_start_main+0xf5) [0x7f5373899af5]
./perf() [0x4220a9]
  Refcount -1 => 1 at
./perf(map_groups__exit+0x94) [0x4bea54]
./perf(machine__delete+0x3d) [0x4b91ed]
./perf(exit_probe_symbol_maps+0x28) [0x506358]
./perf() [0x45628a]
./perf(cmd_probe+0x6c) [0x4566bc]
./perf() [0x47abc5]
./perf(main+0x610) [0x421f90]
/lib64/libc.so.6(__libc_start_main+0xf5) [0x7f5373899af5]
./perf() [0x4220a9]
  

This pattern clearly shows that the refcnt of the map is acquired twice
by map__new2 and maps__insert but released onlu once at
map_groups__exit, when we purge its maps rbtree.

Since maps__insert already reference counted the map, we have to drop
the constructor (map__new2) reference count right after inserting it.

These happened in machine__findnew_module_map, as below.

  
  # eu-addr2line -e ./perf -f 0x4b8aaf
  machine__findnew_module_map inlined at util/machine.c:1046
  in machine__create_module
  util/machine.c:582
  # eu-addr2line -e ./perf -f 0x4b8acb
  map_groups__insert inlined at util/machine.c:585
  in machine__create_module
  util/map.h:208
  

(note that both are at util/machine.c:58X which is
 machine__findnew_module_map)

Signed-off-by: Masami Hiramatsu 
Cc: Adrian Hunter 
Cc: Jiri Olsa 
Cc: Namhyung Kim 
Cc: Peter Zijlstra 
Link: 
http://lkml.kernel.org/r/20151118064020.30709.40499.stgit@localhost.localdomain
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/util/machine.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/tools/perf/util/machine.c b/tools/perf/util/machine.c
index 8b303ff20289..0487d7795f13 100644
--- a/tools/perf/util/machine.c
+++ b/tools/perf/util/machine.c
@@ -585,6 +585,8 @@ struct map *machine__findnew_module_map(struct machine 
*machine, u64 start,
 
map_groups__insert(>kmaps, map);
 
+   /* Put the map here because map_groups__insert alread got it */
+   map__put(map);
 out:
free(m.name);
return map;
-- 
2.1.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/


Re: [PATCH v5 0/4] mfd: sec: add S2MPS15 PMIC support

2015-11-19 Thread Alim Akhtar
Hi Lee,
Do I need to resend this series? This series still apply cleanly on
top of v4.4-rc1.
I can see 1/4 is already applied.

Thanks & Regards,
Alim

On Fri, Oct 30, 2015 at 11:55 AM, Alim Akhtar  wrote:
> Samsung's S2MPS15 PMIC is targetted to be used with Samsung's Exynos7 SoC.
> The S2MPS15 PMIC is similar in functionality to S2MPS11/14 PMIC. It contains
> 27 LDO and 10 Buck regulators, RTC, three 32.768 KHz clock outputs and allows
> programming these blocks via a I2C interface. This patch series adds initial
> support for LDO/Buck regulators of S2MPS15 PMIC.
>
> Changes since v4:
> * Dorpped Krzysztof reviewed-by and Lee Acked-by tags from patch 1/4,
>   because of the new changes to DT bindings. Seeking a fresh review/ack tags.
> * Removed samsung,s2mps15-clk compatible as we can reuse exsisting compatible 
> of s2mps13.
> * Added acked-by on patch 2/4
> * Modified rtc driver as s2mps15 differs from s2mps14/13 etc, addressed 
> Krzysztof
>   concerns on rtc patch.
>   There are some other improvement suggestion from Krzystof for the rtc, I 
> feel that can be done
>   as a sperate patch later.
>
> Changes since v3:
> * Changes regulator driver name from s2mps15-pmic -> s2mps15-regulator as 
> disscussed here [2]
> * Re-use the exsisting compatible/names for s2mps15 clock block.
>
> Changes since v2:
> * Addressed Lee Jones review comments.
>
> Changes since v1:
> * Added suggestion from Krzysztof [1].
> * Added s2mps15's 32.768 clocks support.
> * Added s2mps15's rtc support.
>
> V1 of these patches (with a lesser features) were posted a year back,
> since then there is not much progress on this, this is my attempt to
> move things forward.
>
> [1]-> https://lkml.org/lkml/2014/10/14/67
> [2]-> https://lkml.org/lkml/2015/10/28/417
>
> This series is based on linux-next-20151022.
> This is tested on exynos7-espresso board.
>
> Alim Akhtar (1):
>   drivers/rtc/rtc-s5m.c: add support for S2MPS15 RTC
>
> Thomas Abraham (3):
>   dt-bindings: mfd: s2mps11: add documentation for s2mps15 PMIC
>   mfd: sec: Add support for S2MPS15 PMIC
>   regulator: s2mps11: add support for S2MPS15 regulators
>
>  Documentation/devicetree/bindings/mfd/s2mps11.txt |   21 ++-
>  drivers/mfd/sec-core.c|   31 
>  drivers/mfd/sec-irq.c |8 ++
>  drivers/regulator/Kconfig |4 +-
>  drivers/regulator/s2mps11.c   |  135 +-
>  drivers/rtc/rtc-s5m.c |   37 -
>  include/linux/mfd/samsung/core.h  |1 +
>  include/linux/mfd/samsung/rtc.h   |2 +
>  include/linux/mfd/samsung/s2mps15.h   |  158 
> +
>  9 files changed, 383 insertions(+), 14 deletions(-)
>  create mode 100644 include/linux/mfd/samsung/s2mps15.h
>
> --
> 1.7.10.4
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-samsung-soc" 
> in
> the body of a message to majord...@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html



-- 
Regards,
Alim
--
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/


[PATCH 19/37] perf test: Mute test cases error messages if verbose == 0

2015-11-19 Thread Arnaldo Carvalho de Melo
From: Wang Nan 

Sometimes error messages in breaks the pretty output of 'perf test'.
For example:

  # mv /lib/modules/4.3.0-rc4+/build/vmlinux{,.bak}
  # perf test LLVM BPF
  35: Test LLVM searching and compiling:
  35.1: Basic BPF llvm compiling test  : Ok
  35.2: Test kbuild searching  : Ok
  35.3: Compile source for BPF prologue generation test: Ok
  37: Test BPF filter  :
  37.1: Test basic BPF filtering   : Ok
  37.2: Test BPF prologue generation   :Failed to find 
the path for kernel: No such file or directory FAILED!

This patch mute test cases thoroughly by redirect their stdout and
stderr to /dev/null when verbose == 0. After applying this patch:

  # ./perf test LLVM BPF
  35: Test LLVM searching and compiling:
  35.1: Basic BPF llvm compiling test  : Ok
  35.2: Test kbuild searching  : Ok
  35.3: Compile source for BPF prologue generation test: Ok
  37: Test BPF filter  :
  37.1: Test basic BPF filtering   : Ok
  37.2: Test BPF prologue generation   : FAILED!

  # ./perf test -v LLVM BPF
  35: Test LLVM searching and compiling:
  35.1: Basic BPF llvm compiling test  :
  --- start ---
  test child forked, pid 13183
  Kernel build dir is set to /lib/modules/4.3.0-rc4+/build
  set env: KBUILD_DIR=/lib/modules/4.3.0-rc4+/build
  ...
  bpf: config 'func=null_lseek file->f_mode offset orig' is ok
  Looking at the vmlinux_path (7 entries long)
  Failed to find the path for kernel: No such file or directory
  bpf_probe: failed to convert perf probe eventsFailed to add events selected 
by BPF
  test child finished with -1
   end 
  Test BPF filter subtest 1: FAILED!

Signed-off-by: Wang Nan 
Tested-by: Arnaldo Carvalho de Melo 
Cc: Alexei Starovoitov 
Cc: Masami Hiramatsu 
Cc: Zefan Li 
Cc: pi3or...@163.com
Link: 
http://lkml.kernel.org/r/1447749170-175898-6-git-send-email-wangn...@huawei.com
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/tests/builtin-test.c | 12 
 1 file changed, 12 insertions(+)

diff --git a/tools/perf/tests/builtin-test.c b/tools/perf/tests/builtin-test.c
index 146ae9821c00..2b1ade1aafc3 100644
--- a/tools/perf/tests/builtin-test.c
+++ b/tools/perf/tests/builtin-test.c
@@ -226,6 +226,18 @@ static int run_test(struct test *test, int subtest)
 
if (!child) {
pr_debug("test child forked, pid %d\n", getpid());
+   if (!verbose) {
+   int nullfd = open("/dev/null", O_WRONLY);
+   if (nullfd >= 0) {
+   close(STDERR_FILENO);
+   close(STDOUT_FILENO);
+
+   dup2(nullfd, STDOUT_FILENO);
+   dup2(STDOUT_FILENO, STDERR_FILENO);
+   close(nullfd);
+   }
+   }
+
err = test->func(subtest);
exit(err);
}
-- 
2.1.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/


[PATCH 18/37] perf test: Print result for each BPF subtest

2015-11-19 Thread Arnaldo Carvalho de Melo
From: Wang Nan 

This patch prints each sub-tests results for BPF testcases.

Before:

  # ./perf test BPF
  37: Test BPF filter  : Ok

After:

  # ./perf test BPF
  37: Test BPF filter  :
  37.1: Test basic BPF filtering   : Ok
  37.2: Test BPF prologue generation   : Ok

When a failure happens:

  # cat ~/.perfconfig
  [llvm]
  clang-path = "/bin/false"
  # ./perf test BPF
  37: Test BPF filter  :
  37.1: Test basic BPF filtering   : Skip
  37.2: Test BPF prologue generation   : Skip

Suggested-and-Tested-by: Arnaldo Carvalho de Melo 
Signed-off-by: Wang Nan 
Cc: Alexei Starovoitov 
Cc: Masami Hiramatsu 
Cc: Zefan Li 
Cc: pi3or...@163.com
Link: 
http://lkml.kernel.org/r/1447749170-175898-5-git-send-email-wangn...@huawei.com
[ Fixed up not to use .func in an anonymous union ]
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/tests/bpf.c  | 38 --
 tools/perf/tests/builtin-test.c |  5 +
 tools/perf/tests/tests.h|  2 ++
 3 files changed, 35 insertions(+), 10 deletions(-)

diff --git a/tools/perf/tests/bpf.c b/tools/perf/tests/bpf.c
index 4efdc1607754..33689a0cf821 100644
--- a/tools/perf/tests/bpf.c
+++ b/tools/perf/tests/bpf.c
@@ -215,28 +215,46 @@ out:
return ret;
 }
 
-int test__bpf(int subtest __maybe_unused)
+int test__bpf_subtest_get_nr(void)
+{
+   return (int)ARRAY_SIZE(bpf_testcase_table);
+}
+
+const char *test__bpf_subtest_get_desc(int i)
+{
+   if (i < 0 || i >= (int)ARRAY_SIZE(bpf_testcase_table))
+   return NULL;
+   return bpf_testcase_table[i].desc;
+}
+
+int test__bpf(int i)
 {
-   unsigned int i;
int err;
 
+   if (i < 0 || i >= (int)ARRAY_SIZE(bpf_testcase_table))
+   return TEST_FAIL;
+
if (geteuid() != 0) {
pr_debug("Only root can run BPF test\n");
return TEST_SKIP;
}
 
-   for (i = 0; i < ARRAY_SIZE(bpf_testcase_table); i++) {
-   err = __test__bpf(i);
+   err = __test__bpf(i);
+   return err;
+}
 
-   if (err != TEST_OK)
-   return err;
-   }
+#else
+int test__bpf_subtest_get_nr(void)
+{
+   return 0;
+}
 
-   return TEST_OK;
+const char *test__bpf_subtest_get_desc(int i __maybe_unused)
+{
+   return NULL;
 }
 
-#else
-int test__bpf(void)
+int test__bpf(int i __maybe_unused)
 {
pr_debug("Skip BPF test because BPF support is not compiled\n");
return TEST_SKIP;
diff --git a/tools/perf/tests/builtin-test.c b/tools/perf/tests/builtin-test.c
index 813660976217..146ae9821c00 100644
--- a/tools/perf/tests/builtin-test.c
+++ b/tools/perf/tests/builtin-test.c
@@ -173,6 +173,11 @@ static struct test generic_tests[] = {
{
.desc = "Test BPF filter",
.func = test__bpf,
+   .subtest = {
+   .skip_if_fail   = true,
+   .get_nr = test__bpf_subtest_get_nr,
+   .get_desc   = test__bpf_subtest_get_desc,
+   },
},
{
.func = NULL,
diff --git a/tools/perf/tests/tests.h b/tools/perf/tests/tests.h
index f92af527f080..a0733aaad081 100644
--- a/tools/perf/tests/tests.h
+++ b/tools/perf/tests/tests.h
@@ -76,6 +76,8 @@ int test__llvm(int subtest);
 const char *test__llvm_subtest_get_desc(int subtest);
 int test__llvm_subtest_get_nr(void);
 int test__bpf(int subtest);
+const char *test__bpf_subtest_get_desc(int subtest);
+int test__bpf_subtest_get_nr(void);
 int test_session_topology(int subtest);
 
 #if defined(__arm__) || defined(__aarch64__)
-- 
2.1.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/


[PATCH 27/37] perf tools: Fix machine__create_kernel_maps to put kernel dso refcount

2015-11-19 Thread Arnaldo Carvalho de Melo
From: Masami Hiramatsu 

Fix machine__create_kernel_maps() to put kernel dso because the dso has
been gotten via __machine__create_kernel_maps().

Refcnt debugger shows:
   [0] 
  Unreclaimed dso: 0x3036ab0
  Refcount +1 => 1 at
./perf(dso__new+0x1ff) [0x4a62df]
./perf(__dsos__addnew+0x29) [0x4a6e19]
./perf(dsos__findnew+0xd1) [0x4a7181]
./perf(machine__findnew_kernel+0x27) [0x4a5e17]
./perf() [0x4b8cf2]
./perf(machine__create_kernel_maps+0x28) [0x4bb428]
./perf(machine__new_host+0xfa) [0x4bb74a]
./perf(init_probe_symbol_maps+0x93) [0x506613]
./perf() [0x455ffa]
./perf(cmd_probe+0x6c) [0x4566bc]
./perf() [0x47abc5]
./perf(main+0x610) [0x421f90]
/lib64/libc.so.6(__libc_start_main+0xf5) [0x7ffa6809eaf5]
./perf() [0x4220a9]
  [snip]
  Refcount +1 => 2 at
./perf(dsos__findnew+0x7e) [0x4a712e]
./perf(machine__findnew_kernel+0x27) [0x4a5e17]
./perf() [0x4b8cf2]
./perf(machine__create_kernel_maps+0x28) [0x4bb428]
./perf(machine__new_host+0xfa) [0x4bb74a]
./perf(init_probe_symbol_maps+0x93) [0x506613]
./perf() [0x455ffa]
./perf(cmd_probe+0x6c) [0x4566bc]
./perf() [0x47abc5]
./perf(main+0x610) [0x421f90]
/lib64/libc.so.6(__libc_start_main+0xf5) [0x7ffa6809eaf5]
./perf() [0x4220a9]
  [snip]
  Refcount -1 => 1 at
./perf(dso__put+0x2f) [0x4a664f]
./perf(machine__delete+0xfe) [0x4b93ee]
./perf(exit_probe_symbol_maps+0x28) [0x5066b8]
./perf() [0x45628a]
./perf(cmd_probe+0x6c) [0x4566bc]
./perf() [0x47abc5]
./perf(main+0x610) [0x421f90]
/lib64/libc.so.6(__libc_start_main+0xf5) [0x7ffa6809eaf5]
./perf() [0x4220a9]

Actually, dsos__findnew gets the dso before returning it, so the dso
user (in this case machine__create_kernel_maps) has to put the dso after
used.

Signed-off-by: Masami Hiramatsu 
Cc: Adrian Hunter 
Cc: Jiri Olsa 
Cc: Namhyung Kim 
Cc: Peter Zijlstra 
Link: 
http://lkml.kernel.org/r/20151118064033.30709.98954.stgit@localhost.localdomain
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/util/machine.c | 9 ++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/tools/perf/util/machine.c b/tools/perf/util/machine.c
index a358771fe9e3..0b4a05c14204 100644
--- a/tools/perf/util/machine.c
+++ b/tools/perf/util/machine.c
@@ -1088,11 +1088,14 @@ int machine__create_kernel_maps(struct machine *machine)
struct dso *kernel = machine__get_kernel(machine);
const char *name;
u64 addr = machine__get_running_kernel_start(machine, );
-   if (!addr)
+   int ret;
+
+   if (!addr || kernel == NULL)
return -1;
 
-   if (kernel == NULL ||
-   __machine__create_kernel_maps(machine, kernel) < 0)
+   ret = __machine__create_kernel_maps(machine, kernel);
+   dso__put(kernel);
+   if (ret < 0)
return -1;
 
if (symbol_conf.use_modules && machine__create_modules(machine) < 0) {
-- 
2.1.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/


Re: [V2 PATCH] arm64: restore bogomips information in /proc/cpuinfo

2015-11-19 Thread Catalin Marinas
On Wed, Nov 18, 2015 at 10:48:55AM -0800, Yang Shi wrote:
> As what Pavel Machek reported [1], some userspace applications depend on
> bogomips showed by /proc/cpuinfo.
> 
> Although there is much less legacy impact on aarch64 than arm, but it does
> break libvirt.
> 
> Basically, this patch reverts commit 326b16db9f69fd0d279be873c6c00f88c0a4aad5
> ("arm64: delay: don't bother reporting bogomips in /proc/cpuinfo"), but with
> some tweak due to context change.
> 
> [1] https://lkml.org/lkml/2015/1/4/132
> 
> Acked-by: Will Deacon 
> Cc:  #3.12+
> Signed-off-by: Yang Shi 

Patch applied as a fix for stable, basically returning back to the
pre-3.12 behaviour. If there is a need for some more useful information
here, it can be done as an additional patch, though without cc: stable.

Thanks.

-- 
Catalin
--
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/


[PATCH 35/37] perf hists browser: Support folded callchains

2015-11-19 Thread Arnaldo Carvalho de Melo
From: Namhyung Kim 

The folded callchain mode prints all chains in a single line.

Currently perf report --tui doesn't support folded callchains.  Like
flat callchains, only leaf nodes are added to the final rbtree so it
should show entries in parent nodes.  To do that, add flat_val list to
struct callchain_node and show them along with the (normal) val list.

For example, folded callchain looks like below:

  $ perf report -g folded --tui
  Samples: 234  of event 'cycles:pp', Event count (approx.): 32605268
Overhead  Command  Shared Object Symbol
  -   39.93%  swapper  [kernel.vmlinux]  [k] intel_idle
 + 28.63% intel_idle; cpuidle_enter_state; cpuidle_enter; ...
 + 11.30% intel_idle; cpuidle_enter_state; cpuidle_enter; ...

Signed-off-by: Namhyung Kim 
Tested-by: Arnaldo Carvalho de Melo 
Tested-by: Brendan Gregg 
Cc: Andi Kleen 
Cc: David Ahern 
Cc: Frederic Weisbecker 
Cc: Jiri Olsa 
Cc: Kan Liang 
Cc: Peter Zijlstra 
Link: 
http://lkml.kernel.org/r/1447047946-1691-9-git-send-email-namhy...@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/ui/browsers/hists.c | 125 -
 1 file changed, 124 insertions(+), 1 deletion(-)

diff --git a/tools/perf/ui/browsers/hists.c b/tools/perf/ui/browsers/hists.c
index c44af461a68f..a211b7b6a81e 100644
--- a/tools/perf/ui/browsers/hists.c
+++ b/tools/perf/ui/browsers/hists.c
@@ -207,6 +207,11 @@ static int callchain_node__count_flat_rows(struct 
callchain_node *node)
return n;
 }
 
+static int callchain_node__count_folded_rows(struct callchain_node *node 
__maybe_unused)
+{
+   return 1;
+}
+
 static int callchain_node__count_rows(struct callchain_node *node)
 {
struct callchain_list *chain;
@@ -215,6 +220,8 @@ static int callchain_node__count_rows(struct callchain_node 
*node)
 
if (callchain_param.mode == CHAIN_FLAT)
return callchain_node__count_flat_rows(node);
+   else if (callchain_param.mode == CHAIN_FOLDED)
+   return callchain_node__count_folded_rows(node);
 
list_for_each_entry(chain, >val, list) {
++n;
@@ -311,7 +318,8 @@ static void callchain__init_have_children(struct rb_root 
*root)
for (nd = rb_first(root); nd; nd = rb_next(nd)) {
struct callchain_node *node = rb_entry(nd, struct 
callchain_node, rb_node);
callchain_node__init_have_children(node, has_sibling);
-   if (callchain_param.mode == CHAIN_FLAT)
+   if (callchain_param.mode == CHAIN_FLAT ||
+   callchain_param.mode == CHAIN_FOLDED)
callchain_node__make_parent_list(node);
}
 }
@@ -723,6 +731,116 @@ out:
return row - first_row;
 }
 
+static char *hist_browser__folded_callchain_str(struct hist_browser *browser,
+   struct callchain_list *chain,
+   char *value_str, char *old_str)
+{
+   char bf[1024];
+   const char *str;
+   char *new;
+
+   str = callchain_list__sym_name(chain, bf, sizeof(bf),
+  browser->show_dso);
+   if (old_str) {
+   if (asprintf(, "%s%s%s", old_str,
+symbol_conf.field_sep ?: ";", str) < 0)
+   new = NULL;
+   } else {
+   if (value_str) {
+   if (asprintf(, "%s %s", value_str, str) < 0)
+   new = NULL;
+   } else {
+   if (asprintf(, "%s", str) < 0)
+   new = NULL;
+   }
+   }
+   return new;
+}
+
+static int hist_browser__show_callchain_folded(struct hist_browser *browser,
+  struct rb_root *root,
+  unsigned short row, u64 total,
+  print_callchain_entry_fn print,
+  struct callchain_print_arg *arg,
+  check_output_full_fn 
is_output_full)
+{
+   struct rb_node *node;
+   int first_row = row, offset = LEVEL_OFFSET_STEP;
+   bool need_percent;
+
+   node = rb_first(root);
+   need_percent = node && rb_next(node);
+
+   while (node) {
+   struct callchain_node *child = rb_entry(node, struct 
callchain_node, rb_node);
+   struct rb_node *next = rb_next(node);
+   struct callchain_list *chain, *first_chain = NULL;
+   int first = true;
+   char *value_str = NULL, *value_str_alloc = NULL;
+   char *chain_str = NULL, *chain_str_alloc = NULL;
+
+   if (arg->row_offset != 0) {
+   arg->row_offset--;
+   goto next;
+   }
+
+   if (need_percent) {
+   char buf[64];
+
+ 

[PATCH 15/37] perf bpf: Use same BPF program if arguments are identical

2015-11-19 Thread Arnaldo Carvalho de Melo
From: Wang Nan 

This patch allows creating only one BPF program for different
'probe_trace_event'(tev) entries generated by one
'perf_probe_event'(pev) if their prologues are identical.

This is done by comparing the argument list of different tev instances,
and the maps type of prologue and tev using a mapping array. This patch
utilizes qsort to sort the tevs. After sorting, tevs with identical
argument lists will be grouped together.

Test result:

Sample BPF program:

  #define SEC(NAME) __attribute__((section(NAME), used))
  SEC("inlines=no;"
  "func=SyS_dup? oldfd")
  int func(void *ctx)
  {
  return 1;
  }

It would probe at SyS_dup2 and SyS_dup3, obtaining oldfd as its
argument.

The following cmdline shows a BPF program being loaded into the kernel
by perf:

 # perf record -e ./test_bpf_arg.c sleep 4 & sleep 1 && ls /proc/$!/fd/ -l | 
grep bpf-prog

Before this patch:

  # perf record -e ./test_bpf_arg.c sleep 4 & sleep 1 && ls /proc/$!/fd/ -l | 
grep bpf-prog
  [1] 24858
  lrwx-- 1 root root 64 Nov 14 04:09 3 -> anon_inode:bpf-prog
  lrwx-- 1 root root 64 Nov 14 04:09 4 -> anon_inode:bpf-prog
  ...

After this patch:

  # perf record -e ./test_bpf_arg.c sleep 4 & sleep 1 && ls /proc/$!/fd/ -l | 
grep bpf-prog
  [1] 25699
  lrwx-- 1 root root 64 Nov 14 04:10 3 -> anon_inode:bpf-prog
  ...

Signed-off-by: Wang Nan 
Cc: Alexei Starovoitov 
Cc: Masami Hiramatsu 
Cc: Zefan Li 
Cc: pi3or...@163.com
Link: 
http://lkml.kernel.org/r/1447749170-175898-3-git-send-email-wangn...@huawei.com
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/util/bpf-loader.c | 138 ---
 1 file changed, 131 insertions(+), 7 deletions(-)

diff --git a/tools/perf/util/bpf-loader.c b/tools/perf/util/bpf-loader.c
index 190a1c7f0649..36544e5ece43 100644
--- a/tools/perf/util/bpf-loader.c
+++ b/tools/perf/util/bpf-loader.c
@@ -38,6 +38,8 @@ struct bpf_prog_priv {
struct perf_probe_event pev;
bool need_prologue;
struct bpf_insn *insns_buf;
+   int nr_types;
+   int *type_mapping;
 };
 
 static bool libbpf_initialized;
@@ -113,6 +115,7 @@ bpf_prog_priv__clear(struct bpf_program *prog 
__maybe_unused,
 
cleanup_perf_probe_events(>pev, 1);
zfree(>insns_buf);
+   zfree(>type_mapping);
free(priv);
 }
 
@@ -381,7 +384,7 @@ preproc_gen_prologue(struct bpf_program *prog, int n,
struct bpf_prog_priv *priv;
struct bpf_insn *buf;
size_t prologue_cnt = 0;
-   int err;
+   int i, err;
 
err = bpf_program__get_private(prog, (void **));
if (err || !priv)
@@ -389,10 +392,21 @@ preproc_gen_prologue(struct bpf_program *prog, int n,
 
pev = >pev;
 
-   if (n < 0 || n >= pev->ntevs)
+   if (n < 0 || n >= priv->nr_types)
goto errout;
 
-   tev = >tevs[n];
+   /* Find a tev belongs to that type */
+   for (i = 0; i < pev->ntevs; i++) {
+   if (priv->type_mapping[i] == n)
+   break;
+   }
+
+   if (i >= pev->ntevs) {
+   pr_debug("Internal error: prologue type %d not found\n", n);
+   return -BPF_LOADER_ERRNO__PROLOGUE;
+   }
+
+   tev = >tevs[i];
 
buf = priv->insns_buf;
err = bpf__gen_prologue(tev->args, tev->nargs,
@@ -423,6 +437,101 @@ errout:
return -BPF_LOADER_ERRNO__PROLOGUE;
 }
 
+/*
+ * compare_tev_args is reflexive, transitive and antisymmetric.
+ * I can proof it but this margin is too narrow to contain.
+ */
+static int compare_tev_args(const void *ptev1, const void *ptev2)
+{
+   int i, ret;
+   const struct probe_trace_event *tev1 =
+   *(const struct probe_trace_event **)ptev1;
+   const struct probe_trace_event *tev2 =
+   *(const struct probe_trace_event **)ptev2;
+
+   ret = tev2->nargs - tev1->nargs;
+   if (ret)
+   return ret;
+
+   for (i = 0; i < tev1->nargs; i++) {
+   struct probe_trace_arg *arg1, *arg2;
+   struct probe_trace_arg_ref *ref1, *ref2;
+
+   arg1 = >args[i];
+   arg2 = >args[i];
+
+   ret = strcmp(arg1->value, arg2->value);
+   if (ret)
+   return ret;
+
+   ref1 = arg1->ref;
+   ref2 = arg2->ref;
+
+   while (ref1 && ref2) {
+   ret = ref2->offset - ref1->offset;
+   if (ret)
+   return ret;
+
+   ref1 = ref1->next;
+   ref2 = ref2->next;
+   }
+
+   if (ref1 || ref2)
+   return ref2 ? 1 : -1;
+   }
+
+   return 0;
+}
+
+/*
+ * Assign a type number to each tevs in a pev.
+ * mapping is an array with same slots as tevs in that pev.
+ * nr_types will be set to number of types.
+ */
+static int map_prologue(struct perf_probe_event *pev, int *mapping,
+ 

[PATCH 30/37] perf callchain: Abstract callchain print function

2015-11-19 Thread Arnaldo Carvalho de Melo
From: Namhyung Kim 

This is a preparation to support for printing other type of callchain
value like count or period.

Signed-off-by: Namhyung Kim 
Tested-by: Brendan Gregg 
Cc: Andi Kleen 
Cc: David Ahern 
Cc: Frederic Weisbecker 
Cc: Jiri Olsa 
Cc: Kan Liang 
Cc: Peter Zijlstra 
Link: 
http://lkml.kernel.org/r/1447047946-1691-4-git-send-email-namhy...@kernel.org
[ renamed new _sprintf_ operation to _scnprintf_ ]
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/ui/browsers/hists.c |  8 +---
 tools/perf/ui/gtk/hists.c  |  8 ++--
 tools/perf/ui/stdio/hist.c | 35 +--
 tools/perf/util/callchain.c| 29 +
 tools/perf/util/callchain.h|  4 
 5 files changed, 57 insertions(+), 27 deletions(-)

diff --git a/tools/perf/ui/browsers/hists.c b/tools/perf/ui/browsers/hists.c
index fa9eb92c9e24..0b18857a36e8 100644
--- a/tools/perf/ui/browsers/hists.c
+++ b/tools/perf/ui/browsers/hists.c
@@ -592,7 +592,6 @@ static int hist_browser__show_callchain(struct hist_browser 
*browser,
while (node) {
struct callchain_node *child = rb_entry(node, struct 
callchain_node, rb_node);
struct rb_node *next = rb_next(node);
-   u64 cumul = callchain_cumul_hits(child);
struct callchain_list *chain;
char folded_sign = ' ';
int first = true;
@@ -619,9 +618,12 @@ static int hist_browser__show_callchain(struct 
hist_browser *browser,
   browser->show_dso);
 
if (was_first && need_percent) {
-   double percent = cumul * 100.0 / total;
+   char buf[64];
 
-   if (asprintf(_str, "%2.2f%% %s", percent, 
str) < 0)
+   callchain_node__scnprintf_value(child, buf, 
sizeof(buf),
+   total);
+
+   if (asprintf(_str, "%s %s", buf, str) < 0)
str = "Not enough memory!";
else
str = alloc_str;
diff --git a/tools/perf/ui/gtk/hists.c b/tools/perf/ui/gtk/hists.c
index 4b3585eed1e8..cff7bb9d9632 100644
--- a/tools/perf/ui/gtk/hists.c
+++ b/tools/perf/ui/gtk/hists.c
@@ -100,14 +100,10 @@ static void perf_gtk__add_callchain(struct rb_root *root, 
GtkTreeStore *store,
struct callchain_list *chain;
GtkTreeIter iter, new_parent;
bool need_new_parent;
-   double percent;
-   u64 hits, child_total;
+   u64 child_total;
 
node = rb_entry(nd, struct callchain_node, rb_node);
 
-   hits = callchain_cumul_hits(node);
-   percent = 100.0 * hits / total;
-
new_parent = *parent;
need_new_parent = !has_single_node && (node->val_nr > 1);
 
@@ -116,7 +112,7 @@ static void perf_gtk__add_callchain(struct rb_root *root, 
GtkTreeStore *store,
 
gtk_tree_store_append(store, , _parent);
 
-   scnprintf(buf, sizeof(buf), "%5.2f%%", percent);
+   callchain_node__scnprintf_value(node, buf, sizeof(buf), 
total);
gtk_tree_store_set(store, , 0, buf, -1);
 
callchain_list__sym_name(chain, buf, sizeof(buf), 
false);
diff --git a/tools/perf/ui/stdio/hist.c b/tools/perf/ui/stdio/hist.c
index ea7984932d9a..f4de055cab9b 100644
--- a/tools/perf/ui/stdio/hist.c
+++ b/tools/perf/ui/stdio/hist.c
@@ -34,10 +34,10 @@ static size_t ipchain__fprintf_graph_line(FILE *fp, int 
depth, int depth_mask,
return ret;
 }
 
-static size_t ipchain__fprintf_graph(FILE *fp, struct callchain_list *chain,
+static size_t ipchain__fprintf_graph(FILE *fp, struct callchain_node *node,
+struct callchain_list *chain,
 int depth, int depth_mask, int period,
-u64 total_samples, u64 hits,
-int left_margin)
+u64 total_samples, int left_margin)
 {
int i;
size_t ret = 0;
@@ -50,10 +50,9 @@ static size_t ipchain__fprintf_graph(FILE *fp, struct 
callchain_list *chain,
else
ret += fprintf(fp, " ");
if (!period && i == depth - 1) {
-   double percent;
-
-   percent = hits * 100.0 / total_samples;
-   ret += percent_color_fprintf(fp, "--%2.2f%%-- ", 
percent);
+   ret += fprintf(fp, "--");
+   ret += callchain_node__fprintf_value(node, fp, 
total_samples);
+   ret += fprintf(fp, "--");
} else
  

[PATCH 17/37] perf test: Print result for each LLVM subtest

2015-11-19 Thread Arnaldo Carvalho de Melo
From: Wang Nan 

Currently 'perf test llvm' and 'perf test BPF' have multiple sub-tests,
but the result is provided in only one line:

  # perf test LLVM
  35: Test LLVM searching and compiling: Ok

This patch introduces sub-tests support, allowing 'perf test' to report
result for each sub-tests:

  # perf test LLVM
  35: Test LLVM searching and compiling:
  35.1: Basic BPF llvm compiling test  : Ok
  35.2: Test kbuild searching  : Ok
  35.3: Compile source for BPF prologue generation test: Ok

When a failure happens:

  # cat ~/.perfconfig
  [llvm]
   clang-path = "/bin/false"
  # perf test LLVM
  35: Test LLVM searching and compiling:
  35.1: Basic BPF llvm compiling test  : FAILED!
  35.2: Test kbuild searching  : Skip
  35.3: Compile source for BPF prologue generation test: Skip

And:

  # rm ~/.perfconfig
  # ./perf test LLVM
  35: Test LLVM searching and compiling:
  35.1: Basic BPF llvm compiling test  : Skip
  35.2: Test kbuild searching  : Skip
  35.3: Compile source for BPF prologue generation test: Skip

Skip by user:

  # ./perf test -s 1,`seq -s , 3 42`
   1: vmlinux symtab matches kallsyms  : Skip (user 
override)
   2: detect openat syscall event  : Ok
  ...
  35: Test LLVM searching and compiling: Skip (user 
override)
  ...

Suggested-and-Tested-by: Arnaldo Carvalho de Melo 
Signed-off-by: Wang Nan 
Cc: Alexei Starovoitov 
Cc: Masami Hiramatsu 
Cc: Zefan Li 
Cc: pi3or...@163.com
Link: 
http://lkml.kernel.org/r/1447749170-175898-4-git-send-email-wangn...@huawei.com
[ Changed so that func is not on an anonymous union ]
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/tests/builtin-test.c | 91 ++---
 tools/perf/tests/llvm.c | 65 ++---
 tools/perf/tests/tests.h|  9 
 3 files changed, 115 insertions(+), 50 deletions(-)

diff --git a/tools/perf/tests/builtin-test.c b/tools/perf/tests/builtin-test.c
index 9cf4892c061d..813660976217 100644
--- a/tools/perf/tests/builtin-test.c
+++ b/tools/perf/tests/builtin-test.c
@@ -160,6 +160,11 @@ static struct test generic_tests[] = {
{
.desc = "Test LLVM searching and compiling",
.func = test__llvm,
+   .subtest = {
+   .skip_if_fail   = true,
+   .get_nr = test__llvm_subtest_get_nr,
+   .get_desc   = test__llvm_subtest_get_desc,
+   },
},
{
.desc = "Test topology in session",
@@ -237,6 +242,40 @@ static int run_test(struct test *test, int subtest)
for (j = 0; j < ARRAY_SIZE(tests); j++) \
for (t = [j][0]; t->func; t++)
 
+static int test_and_print(struct test *t, bool force_skip, int subtest)
+{
+   int err;
+
+   if (!force_skip) {
+   pr_debug("\n--- start ---\n");
+   err = run_test(t, subtest);
+   pr_debug(" end \n");
+   } else {
+   pr_debug("\n--- force skipped ---\n");
+   err = TEST_SKIP;
+   }
+
+   if (!t->subtest.get_nr)
+   pr_debug("%s:", t->desc);
+   else
+   pr_debug("%s subtest %d:", t->desc, subtest);
+
+   switch (err) {
+   case TEST_OK:
+   pr_info(" Ok\n");
+   break;
+   case TEST_SKIP:
+   color_fprintf(stderr, PERF_COLOR_YELLOW, " Skip\n");
+   break;
+   case TEST_FAIL:
+   default:
+   color_fprintf(stderr, PERF_COLOR_RED, " FAILED!\n");
+   break;
+   }
+
+   return err;
+}
+
 static int __cmd_test(int argc, const char *argv[], struct intlist *skiplist)
 {
struct test *t;
@@ -264,21 +303,43 @@ static int __cmd_test(int argc, const char *argv[], 
struct intlist *skiplist)
continue;
}
 
-   pr_debug("\n--- start ---\n");
-   err = run_test(t, i);
-   pr_debug(" end \n%s:", t->desc);
-
-   switch (err) {
-   case TEST_OK:
-   pr_info(" Ok\n");
-   break;
-   case TEST_SKIP:
-   color_fprintf(stderr, PERF_COLOR_YELLOW, " Skip\n");
-   break;
-   case TEST_FAIL:
-   default:
-   color_fprintf(stderr, PERF_COLOR_RED, " FAILED!\n");
-   break;
+   if (!t->subtest.get_nr) {
+   test_and_print(t, false, -1);
+   } else {
+   int subn = t->subtest.get_nr();
+  

[PATCH 24/37] perf tools: Make perf_exec_path() always return malloc'd string

2015-11-19 Thread Arnaldo Carvalho de Melo
From: Masami Hiramatsu 

Since system_path() returns malloc'd string if given path is not an
absolute path, perf_exec_path() sometimes returns a static string and
sometimes returns a malloc'd string depending on the environment
variables or command options.

This may cause a memory leak because the caller can not unconditionally
free the returned string.

This fixes perf_exec_path() and system_path() to always return a
malloc'd string, so the caller can always free it.

Signed-off-by: Masami Hiramatsu 
Cc: Adrian Hunter 
Cc: Jiri Olsa 
Cc: Namhyung Kim 
Cc: Peter Zijlstra 
Link: 
http://lkml.kernel.org/r/20151119060453.14210.65666.stgit@localhost.localdomain
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/util/exec_cmd.c | 21 +++--
 tools/perf/util/exec_cmd.h |  5 +++--
 tools/perf/util/help.c |  6 --
 3 files changed, 18 insertions(+), 14 deletions(-)

diff --git a/tools/perf/util/exec_cmd.c b/tools/perf/util/exec_cmd.c
index 7adf4ad15d8f..1099e92f5ee1 100644
--- a/tools/perf/util/exec_cmd.c
+++ b/tools/perf/util/exec_cmd.c
@@ -9,17 +9,17 @@
 static const char *argv_exec_path;
 static const char *argv0_path;
 
-const char *system_path(const char *path)
+char *system_path(const char *path)
 {
static const char *prefix = PREFIX;
struct strbuf d = STRBUF_INIT;
 
if (is_absolute_path(path))
-   return path;
+   return strdup(path);
 
strbuf_addf(, "%s/%s", prefix, path);
path = strbuf_detach(, NULL);
-   return path;
+   return (char *)path;
 }
 
 const char *perf_extract_argv0_path(const char *argv0)
@@ -52,17 +52,16 @@ void perf_set_argv_exec_path(const char *exec_path)
 
 
 /* Returns the highest-priority, location to look for perf programs. */
-const char *perf_exec_path(void)
+char *perf_exec_path(void)
 {
-   const char *env;
+   char *env;
 
if (argv_exec_path)
-   return argv_exec_path;
+   return strdup(argv_exec_path);
 
env = getenv(EXEC_PATH_ENVIRONMENT);
-   if (env && *env) {
-   return env;
-   }
+   if (env && *env)
+   return strdup(env);
 
return system_path(PERF_EXEC_PATH);
 }
@@ -83,9 +82,11 @@ void setup_path(void)
 {
const char *old_path = getenv("PATH");
struct strbuf new_path = STRBUF_INIT;
+   char *tmp = perf_exec_path();
 
-   add_path(_path, perf_exec_path());
+   add_path(_path, tmp);
add_path(_path, argv0_path);
+   free(tmp);
 
if (old_path)
strbuf_addstr(_path, old_path);
diff --git a/tools/perf/util/exec_cmd.h b/tools/perf/util/exec_cmd.h
index bc4b915963f5..48b4175f1e11 100644
--- a/tools/perf/util/exec_cmd.h
+++ b/tools/perf/util/exec_cmd.h
@@ -3,10 +3,11 @@
 
 extern void perf_set_argv_exec_path(const char *exec_path);
 extern const char *perf_extract_argv0_path(const char *path);
-extern const char *perf_exec_path(void);
 extern void setup_path(void);
 extern int execv_perf_cmd(const char **argv); /* NULL terminated */
 extern int execl_perf_cmd(const char *cmd, ...);
-extern const char *system_path(const char *path);
+/* perf_exec_path and system_path return malloc'd string, caller must free it 
*/
+extern char *perf_exec_path(void);
+extern char *system_path(const char *path);
 
 #endif /* __PERF_EXEC_CMD_H */
diff --git a/tools/perf/util/help.c b/tools/perf/util/help.c
index 86c37c472263..fa1fc4acb8a4 100644
--- a/tools/perf/util/help.c
+++ b/tools/perf/util/help.c
@@ -159,7 +159,7 @@ void load_command_list(const char *prefix,
struct cmdnames *other_cmds)
 {
const char *env_path = getenv("PATH");
-   const char *exec_path = perf_exec_path();
+   char *exec_path = perf_exec_path();
 
if (exec_path) {
list_commands_in_dir(main_cmds, exec_path, prefix);
@@ -187,6 +187,7 @@ void load_command_list(const char *prefix,
  sizeof(*other_cmds->names), cmdname_compare);
uniq(other_cmds);
}
+   free(exec_path);
exclude_cmds(other_cmds, main_cmds);
 }
 
@@ -203,13 +204,14 @@ void list_commands(const char *title, struct cmdnames 
*main_cmds,
longest = other_cmds->names[i]->len;
 
if (main_cmds->cnt) {
-   const char *exec_path = perf_exec_path();
+   char *exec_path = perf_exec_path();
printf("available %s in '%s'\n", title, exec_path);
printf("");
mput_char('-', strlen(title) + strlen(exec_path));
putchar('\n');
pretty_print_string_list(main_cmds, longest);
putchar('\n');
+   free(exec_path);
}
 
if (other_cmds->cnt) {
-- 
2.1.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

[PATCH 33/37] perf hists browser: Factor out hist_browser__show_callchain_list()

2015-11-19 Thread Arnaldo Carvalho de Melo
From: Namhyung Kim 

This function is to print a single callchain list entry.  As this
function will be used by other function, factor out to a separate
function.

Signed-off-by: Namhyung Kim 
Cc: Andi Kleen 
Cc: Brendan Gregg 
Cc: David Ahern 
Cc: Frederic Weisbecker 
Cc: Jiri Olsa 
Cc: Kan Liang 
Cc: Peter Zijlstra 
Link: 
http://lkml.kernel.org/r/1447047946-1691-7-git-send-email-namhy...@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/ui/browsers/hists.c | 72 ++
 1 file changed, 45 insertions(+), 27 deletions(-)

diff --git a/tools/perf/ui/browsers/hists.c b/tools/perf/ui/browsers/hists.c
index 0b18857a36e8..0746d41d9efe 100644
--- a/tools/perf/ui/browsers/hists.c
+++ b/tools/perf/ui/browsers/hists.c
@@ -574,6 +574,44 @@ static bool hist_browser__check_dump_full(struct 
hist_browser *browser __maybe_u
 
 #define LEVEL_OFFSET_STEP 3
 
+static int hist_browser__show_callchain_list(struct hist_browser *browser,
+struct callchain_node *node,
+struct callchain_list *chain,
+unsigned short row, u64 total,
+bool need_percent, int offset,
+print_callchain_entry_fn print,
+struct callchain_print_arg *arg)
+{
+   char bf[1024], *alloc_str;
+   const char *str;
+
+   if (arg->row_offset != 0) {
+   arg->row_offset--;
+   return 0;
+   }
+
+   alloc_str = NULL;
+   str = callchain_list__sym_name(chain, bf, sizeof(bf),
+  browser->show_dso);
+
+   if (need_percent) {
+   char buf[64];
+
+   callchain_node__scnprintf_value(node, buf, sizeof(buf),
+   total);
+
+   if (asprintf(_str, "%s %s", buf, str) < 0)
+   str = "Not enough memory!";
+   else
+   str = alloc_str;
+   }
+
+   print(browser, chain, str, offset, row, arg);
+
+   free(alloc_str);
+   return 1;
+}
+
 static int hist_browser__show_callchain(struct hist_browser *browser,
struct rb_root *root, int level,
unsigned short row, u64 total,
@@ -598,8 +636,6 @@ static int hist_browser__show_callchain(struct hist_browser 
*browser,
int extra_offset = 0;
 
list_for_each_entry(chain, >val, list) {
-   char bf[1024], *alloc_str;
-   const char *str;
bool was_first = first;
 
if (first)
@@ -608,34 +644,16 @@ static int hist_browser__show_callchain(struct 
hist_browser *browser,
extra_offset = LEVEL_OFFSET_STEP;
 
folded_sign = callchain_list__folded(chain);
-   if (arg->row_offset != 0) {
-   arg->row_offset--;
-   goto do_next;
-   }
 
-   alloc_str = NULL;
-   str = callchain_list__sym_name(chain, bf, sizeof(bf),
-  browser->show_dso);
+   row += hist_browser__show_callchain_list(browser, child,
+   chain, row, total,
+   was_first && 
need_percent,
+   offset + extra_offset,
+   print, arg);
 
-   if (was_first && need_percent) {
-   char buf[64];
-
-   callchain_node__scnprintf_value(child, buf, 
sizeof(buf),
-   total);
-
-   if (asprintf(_str, "%s %s", buf, str) < 0)
-   str = "Not enough memory!";
-   else
-   str = alloc_str;
-   }
-
-   print(browser, chain, str, offset + extra_offset, row, 
arg);
-
-   free(alloc_str);
-
-   if (is_output_full(browser, ++row))
+   if (is_output_full(browser, row))
goto out;
-do_next:
+
if (folded_sign == '+')
break;
}
-- 
2.1.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  

[PATCH 32/37] perf report: Add callchain value option

2015-11-19 Thread Arnaldo Carvalho de Melo
From: Namhyung Kim 

Now -g/--call-graph option supports how to display callchain values.
Possible values are 'percent', 'period' and 'count'.  The percent is
same as before and it's the default behavior.  The period displays the
raw period value rather than the percentage.  The count displays the
number of occurrences.

  $ perf report --no-children --stdio -g percent
  ...
39.93%  swapper  [kernel.vmlinux]  [k] intel_idel
|
---intel_idle
   cpuidle_enter_state
   cpuidle_enter
   call_cpuidle
   cpu_startup_entry
   |
   |--28.63%-- start_secondary
   |
--11.30%-- rest_init

  $ perf report --no-children --show-total-period --stdio -g period
  ...
39.93%   13018705  swapper  [kernel.vmlinux]  [k] intel_idel
|
---intel_idle
   cpuidle_enter_state
   cpuidle_enter
   call_cpuidle
   cpu_startup_entry
   |
   |--9334403-- start_secondary
   |
--3684302-- rest_init

  $ perf report --no-children --show-nr-samples --stdio -g count
  ...
39.93% 80  swapper  [kernel.vmlinux]  [k] intel_idel
|
---intel_idle
   cpuidle_enter_state
   cpuidle_enter
   call_cpuidle
   cpu_startup_entry
   |
   |--57-- start_secondary
   |
--23-- rest_init

Signed-off-by: Namhyung Kim 
Acked-by: Brendan Gregg 
Cc: Andi Kleen 
Cc: David Ahern 
Cc: Frederic Weisbecker 
Cc: Jiri Olsa 
Cc: Kan Liang 
Cc: Peter Zijlstra 
Link: 
http://lkml.kernel.org/r/1447047946-1691-6-git-send-email-namhy...@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/Documentation/perf-report.txt | 13 ---
 tools/perf/builtin-report.c  |  4 +--
 tools/perf/ui/stdio/hist.c   | 10 +-
 tools/perf/util/callchain.c  | 62 +++-
 tools/perf/util/callchain.h  | 10 +-
 tools/perf/util/util.c   |  3 +-
 6 files changed, 84 insertions(+), 18 deletions(-)

diff --git a/tools/perf/Documentation/perf-report.txt 
b/tools/perf/Documentation/perf-report.txt
index f7d81aac9188..dab99ed2b339 100644
--- a/tools/perf/Documentation/perf-report.txt
+++ b/tools/perf/Documentation/perf-report.txt
@@ -170,11 +170,11 @@ OPTIONS
 Dump raw trace in ASCII.
 
 -g::
---call-graph=::
+--call-graph=::
 Display call chains using type, min percent threshold, print limit,
-   call order, sort key and branch.  Note that ordering of parameters is 
not
-   fixed so any parement can be given in an arbitraty order.  One exception
-   is the print_limit which should be preceded by threshold.
+   call order, sort key, optional branch and value.  Note that ordering of
+   parameters is not fixed so any parement can be given in an arbitraty 
order.
+   One exception is the print_limit which should be preceded by threshold.
 
print_type can be either:
- flat: single column, linear exposure of call chains.
@@ -205,6 +205,11 @@ OPTIONS
- branch: include last branch information in callgraph when available.
  Usually more convenient to use --branch-history for this.
 
+   value can be:
+   - percent: diplay overhead percent (default)
+   - period: display event period
+   - count: display event count
+
 --children::
Accumulate callchain of children to parent entry so that then can
show up in the output.  The output will have a new "Children" column
diff --git a/tools/perf/builtin-report.c b/tools/perf/builtin-report.c
index f256fac1e722..14428342b47b 100644
--- a/tools/perf/builtin-report.c
+++ b/tools/perf/builtin-report.c
@@ -625,7 +625,7 @@ parse_percent_limit(const struct option *opt, const char 
*str,
return 0;
 }
 
-#define CALLCHAIN_DEFAULT_OPT  "graph,0.5,caller,function"
+#define CALLCHAIN_DEFAULT_OPT  "graph,0.5,caller,function,percent"
 
 const char report_callchain_help[] = "Display call graph (stack 
chain/backtrace):\n\n"
 CALLCHAIN_REPORT_HELP
@@ -708,7 +708,7 @@ int cmd_report(int argc, const char **argv, const char 
*prefix __maybe_unused)
OPT_BOOLEAN('x', "exclude-other", _conf.exclude_other,
"Only display entries with parent-match"),
OPT_CALLBACK_DEFAULT('g', "call-graph", ,
-
"print_type,threshold[,print_limit],order,sort_key[,branch]",
+
"print_type,threshold[,print_limit],order,sort_key[,branch],value",
 report_callchain_help, _parse_callchain_opt,
 callchain_default_opt),
OPT_BOOLEAN(0, "children", _conf.cumulate_callchain,
diff --git a/tools/perf/ui/stdio/hist.c 

[PATCH 29/37] perf report: Support folded callchain mode on --stdio

2015-11-19 Thread Arnaldo Carvalho de Melo
From: Namhyung Kim 

Add new call chain option (-g) 'folded' to print callchains in a line.
The callchains are separated by semicolons, and preceded by (absolute)
percent values and a space.

For example, the following 20 lines can be printed in 3 lines with the
folded output mode:

  $ perf report -g flat --no-children | grep -v ^# | head -20
  60.48%  swapper  [kernel.vmlinux]  [k] intel_idle
  54.60%
 intel_idle
 cpuidle_enter_state
 cpuidle_enter
 call_cpuidle
 cpu_startup_entry
 start_secondary

  5.88%
 intel_idle
 cpuidle_enter_state
 cpuidle_enter
 call_cpuidle
 cpu_startup_entry
 rest_init
 start_kernel
 x86_64_start_reservations
 x86_64_start_kernel

  $ perf report -g folded --no-children | grep -v ^# | head -3
  60.48%  swapper  [kernel.vmlinux]  [k] intel_idle
  54.60% 
intel_idle;cpuidle_enter_state;cpuidle_enter;call_cpuidle;cpu_startup_entry;start_secondary
  5.88% 
intel_idle;cpuidle_enter_state;cpuidle_enter;call_cpuidle;cpu_startup_entry;rest_init;start_kernel;x86_64_start_reservations;x86_64_start_kernel

This mode is supported only for --stdio now and intended to be used by
some scripts like in FlameGraphs[1].  Support for other UI might be
added later.

[1] http://www.brendangregg.com/FlameGraphs/cpuflamegraphs.html

Requested-and-Tested-by: Brendan Gregg 
Signed-off-by: Namhyung Kim 
Tested-by: Arnaldo Carvalho de Melo 
Acked-by: Jiri Olsa 
Cc: Andi Kleen 
Cc: David Ahern 
Cc: Frederic Weisbecker 
Cc: Kan Liang 
Cc: Peter Zijlstra 
Link: 
http://lkml.kernel.org/r/1447047946-1691-2-git-send-email-namhy...@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/Documentation/perf-report.txt |  1 +
 tools/perf/ui/stdio/hist.c   | 55 
 tools/perf/util/callchain.c  |  6 
 tools/perf/util/callchain.h  |  5 +--
 4 files changed, 65 insertions(+), 2 deletions(-)

diff --git a/tools/perf/Documentation/perf-report.txt 
b/tools/perf/Documentation/perf-report.txt
index 5ce8da1e1256..f7d81aac9188 100644
--- a/tools/perf/Documentation/perf-report.txt
+++ b/tools/perf/Documentation/perf-report.txt
@@ -181,6 +181,7 @@ OPTIONS
- graph: use a graph tree, displaying absolute overhead rates. (default)
- fractal: like graph, but displays relative rates. Each branch of
 the tree is considered as a new profiled object.
+   - folded: call chains are displayed in a line, separated by semicolons
- none: disable call chain display.
 
threshold is a percentage value which specifies a minimum percent to be
diff --git a/tools/perf/ui/stdio/hist.c b/tools/perf/ui/stdio/hist.c
index dfcbc90146ef..ea7984932d9a 100644
--- a/tools/perf/ui/stdio/hist.c
+++ b/tools/perf/ui/stdio/hist.c
@@ -260,6 +260,58 @@ static size_t callchain__fprintf_flat(FILE *fp, struct 
rb_root *tree,
return ret;
 }
 
+static size_t __callchain__fprintf_folded(FILE *fp, struct callchain_node 
*node)
+{
+   const char *sep = symbol_conf.field_sep ?: ";";
+   struct callchain_list *chain;
+   size_t ret = 0;
+   char bf[1024];
+   bool first;
+
+   if (!node)
+   return 0;
+
+   ret += __callchain__fprintf_folded(fp, node->parent);
+
+   first = (ret == 0);
+   list_for_each_entry(chain, >val, list) {
+   if (chain->ip >= PERF_CONTEXT_MAX)
+   continue;
+   ret += fprintf(fp, "%s%s", first ? "" : sep,
+  callchain_list__sym_name(chain,
+   bf, sizeof(bf), false));
+   first = false;
+   }
+
+   return ret;
+}
+
+static size_t callchain__fprintf_folded(FILE *fp, struct rb_root *tree,
+   u64 total_samples)
+{
+   size_t ret = 0;
+   u32 entries_printed = 0;
+   struct callchain_node *chain;
+   struct rb_node *rb_node = rb_first(tree);
+
+   while (rb_node) {
+   double percent;
+
+   chain = rb_entry(rb_node, struct callchain_node, rb_node);
+   percent = chain->hit * 100.0 / total_samples;
+
+   ret += fprintf(fp, "%.2f%% ", percent);
+   ret += __callchain__fprintf_folded(fp, chain);
+   ret += fprintf(fp, "\n");
+   if (++entries_printed == callchain_param.print_limit)
+   break;
+
+   rb_node = rb_next(rb_node);
+   }
+
+   return ret;
+}
+
 static size_t hist_entry_callchain__fprintf(struct hist_entry *he,
u64 total_samples, int left_margin,
FILE *fp)
@@ -278,6 +330,9 @@ static size_t 

[PATCH 36/37] perf ui/gtk: Support flat callchains

2015-11-19 Thread Arnaldo Carvalho de Melo
From: Namhyung Kim 

The flat callchain mode is to print all chains in a simple flat
hierarchy so make it easy to see.

Currently perf report --gtk doesn't show flat callchains properly.  With
flat callchains, only leaf nodes are added to the final rbtree so it
should show entries in parent nodes.  To do that, add parent_val list to
struct callchain_node and show them along with the (normal) val list.

See the previous commit on TUI support for more information.

Signed-off-by: Namhyung Kim 
Tested-by: Brendan Gregg 
Cc: Andi Kleen 
Cc: David Ahern 
Cc: Frederic Weisbecker 
Cc: Jiri Olsa 
Cc: Kan Liang 
Cc: Pekka Enberg 
Cc: Peter Zijlstra 
Link: 
http://lkml.kernel.org/r/1447047946-1691-10-git-send-email-namhy...@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/ui/gtk/hists.c | 80 ---
 1 file changed, 76 insertions(+), 4 deletions(-)

diff --git a/tools/perf/ui/gtk/hists.c b/tools/perf/ui/gtk/hists.c
index cff7bb9d9632..0b24cd6d38a4 100644
--- a/tools/perf/ui/gtk/hists.c
+++ b/tools/perf/ui/gtk/hists.c
@@ -89,8 +89,71 @@ void perf_gtk__init_hpp(void)
perf_gtk__hpp_color_overhead_acc;
 }
 
-static void perf_gtk__add_callchain(struct rb_root *root, GtkTreeStore *store,
-   GtkTreeIter *parent, int col, u64 total)
+static void perf_gtk__add_callchain_flat(struct rb_root *root, GtkTreeStore 
*store,
+GtkTreeIter *parent, int col, u64 
total)
+{
+   struct rb_node *nd;
+   bool has_single_node = (rb_first(root) == rb_last(root));
+
+   for (nd = rb_first(root); nd; nd = rb_next(nd)) {
+   struct callchain_node *node;
+   struct callchain_list *chain;
+   GtkTreeIter iter, new_parent;
+   bool need_new_parent;
+
+   node = rb_entry(nd, struct callchain_node, rb_node);
+
+   new_parent = *parent;
+   need_new_parent = !has_single_node;
+
+   callchain_node__make_parent_list(node);
+
+   list_for_each_entry(chain, >parent_val, list) {
+   char buf[128];
+
+   gtk_tree_store_append(store, , _parent);
+
+   callchain_node__scnprintf_value(node, buf, sizeof(buf), 
total);
+   gtk_tree_store_set(store, , 0, buf, -1);
+
+   callchain_list__sym_name(chain, buf, sizeof(buf), 
false);
+   gtk_tree_store_set(store, , col, buf, -1);
+
+   if (need_new_parent) {
+   /*
+* Only show the top-most symbol in a callchain
+* if it's not the only callchain.
+*/
+   new_parent = iter;
+   need_new_parent = false;
+   }
+   }
+
+   list_for_each_entry(chain, >val, list) {
+   char buf[128];
+
+   gtk_tree_store_append(store, , _parent);
+
+   callchain_node__scnprintf_value(node, buf, sizeof(buf), 
total);
+   gtk_tree_store_set(store, , 0, buf, -1);
+
+   callchain_list__sym_name(chain, buf, sizeof(buf), 
false);
+   gtk_tree_store_set(store, , col, buf, -1);
+
+   if (need_new_parent) {
+   /*
+* Only show the top-most symbol in a callchain
+* if it's not the only callchain.
+*/
+   new_parent = iter;
+   need_new_parent = false;
+   }
+   }
+   }
+}
+
+static void perf_gtk__add_callchain_graph(struct rb_root *root, GtkTreeStore 
*store,
+ GtkTreeIter *parent, int col, u64 
total)
 {
struct rb_node *nd;
bool has_single_node = (rb_first(root) == rb_last(root));
@@ -134,11 +197,20 @@ static void perf_gtk__add_callchain(struct rb_root *root, 
GtkTreeStore *store,
child_total = total;
 
/* Now 'iter' contains info of the last callchain_list */
-   perf_gtk__add_callchain(>rb_root, store, , col,
-   child_total);
+   perf_gtk__add_callchain_graph(>rb_root, store, , col,
+ child_total);
}
 }
 
+static void perf_gtk__add_callchain(struct rb_root *root, GtkTreeStore *store,
+   GtkTreeIter *parent, int col, u64 total)
+{
+   if (callchain_param.mode == CHAIN_FLAT)
+   perf_gtk__add_callchain_flat(root, store, parent, col, total);
+   else
+   perf_gtk__add_callchain_graph(root, 

[PATCH 02/37] tools: Fix selftests_install Makefile rule

2015-11-19 Thread Arnaldo Carvalho de Melo
From: Kevin Hilman 

Fix copy/paste error in selftests_install rule which was copy-pasted
from the clean rule but not properly changed.

Signed-off-by: Kevin Hilman 
Cc: Bamvor Jian Zhang 
Cc: Jiri Olsa 
Cc: Jonathan Cameron 
Cc: Michael Ellerman 
Cc: Pali Rohar 
Cc: Pavel Machek 
Cc: Roberta Dobrescu 
Cc: Shuah Khan 
Cc: linaro-ker...@lists.linaro.org
Link: 
http://lkml.kernel.org/r/1447797261-1775-1-git-send-email-khil...@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/Makefile | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/Makefile b/tools/Makefile
index 7dc820a8c1f1..0ba0df3b516f 100644
--- a/tools/Makefile
+++ b/tools/Makefile
@@ -96,7 +96,7 @@ cgroup_install firewire_install hv_install lguest_install 
perf_install usb_insta
$(call descend,$(@:_install=),install)
 
 selftests_install:
-   $(call descend,testing/$(@:_clean=),install)
+   $(call descend,testing/$(@:_install=),install)
 
 turbostat_install x86_energy_perf_policy_install:
$(call descend,power/x86/$(@:_install=),install)
-- 
2.1.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/


[PATCH 37/37] perf ui/gtk: Support folded callchains

2015-11-19 Thread Arnaldo Carvalho de Melo
From: Namhyung Kim 

The folded callchain mode is to print all chains in a single line.
Currently perf report --gtk doesn't support folded callchains.  Like
flat callchains, only leaf nodes are added to the final rbtree so it
should show entries in parent nodes.

Signed-off-by: Namhyung Kim 
Tested-by: Arnaldo Carvalho de Melo 
Tested-by: Brendan Gregg 
Cc: Andi Kleen 
Cc: David Ahern 
Cc: Frederic Weisbecker 
Cc: Jiri Olsa 
Cc: Kan Liang 
Cc: Pekka Enberg 
Cc: Peter Zijlstra 
Link: 
http://lkml.kernel.org/r/1447047946-1691-11-git-send-email-namhy...@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/ui/gtk/hists.c | 62 +++
 1 file changed, 62 insertions(+)

diff --git a/tools/perf/ui/gtk/hists.c b/tools/perf/ui/gtk/hists.c
index 0b24cd6d38a4..467717276ab6 100644
--- a/tools/perf/ui/gtk/hists.c
+++ b/tools/perf/ui/gtk/hists.c
@@ -152,6 +152,66 @@ static void perf_gtk__add_callchain_flat(struct rb_root 
*root, GtkTreeStore *sto
}
 }
 
+static void perf_gtk__add_callchain_folded(struct rb_root *root, GtkTreeStore 
*store,
+  GtkTreeIter *parent, int col, u64 
total)
+{
+   struct rb_node *nd;
+
+   for (nd = rb_first(root); nd; nd = rb_next(nd)) {
+   struct callchain_node *node;
+   struct callchain_list *chain;
+   GtkTreeIter iter;
+   char buf[64];
+   char *str, *str_alloc = NULL;
+   bool first = true;
+
+   node = rb_entry(nd, struct callchain_node, rb_node);
+
+   callchain_node__make_parent_list(node);
+
+   list_for_each_entry(chain, >parent_val, list) {
+   char name[1024];
+
+   callchain_list__sym_name(chain, name, sizeof(name), 
false);
+
+   if (asprintf(, "%s%s%s",
+first ? "" : str_alloc,
+first ? "" : symbol_conf.field_sep ?: "; ",
+name) < 0)
+   return;
+
+   first = false;
+   free(str_alloc);
+   str_alloc = str;
+   }
+
+   list_for_each_entry(chain, >val, list) {
+   char name[1024];
+
+   callchain_list__sym_name(chain, name, sizeof(name), 
false);
+
+   if (asprintf(, "%s%s%s",
+first ? "" : str_alloc,
+first ? "" : symbol_conf.field_sep ?: "; ",
+name) < 0)
+   return;
+
+   first = false;
+   free(str_alloc);
+   str_alloc = str;
+   }
+
+   gtk_tree_store_append(store, , parent);
+
+   callchain_node__scnprintf_value(node, buf, sizeof(buf), total);
+   gtk_tree_store_set(store, , 0, buf, -1);
+
+   gtk_tree_store_set(store, , col, str, -1);
+
+   free(str_alloc);
+   }
+}
+
 static void perf_gtk__add_callchain_graph(struct rb_root *root, GtkTreeStore 
*store,
  GtkTreeIter *parent, int col, u64 
total)
 {
@@ -207,6 +267,8 @@ static void perf_gtk__add_callchain(struct rb_root *root, 
GtkTreeStore *store,
 {
if (callchain_param.mode == CHAIN_FLAT)
perf_gtk__add_callchain_flat(root, store, parent, col, total);
+   else if (callchain_param.mode == CHAIN_FOLDED)
+   perf_gtk__add_callchain_folded(root, store, parent, col, total);
else
perf_gtk__add_callchain_graph(root, store, parent, col, total);
 }
-- 
2.1.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/


[PATCH 34/37] perf hists browser: Support flat callchains

2015-11-19 Thread Arnaldo Carvalho de Melo
From: Namhyung Kim 

The flat callchain mode is to print all chains in a single, simple
hierarchy so make it easy to see.

Currently perf report --tui doesn't show flat callchains properly.  With
flat callchains, only leaf nodes are added to the final rbtree so it
should show entries in parent nodes.  To do that, add parent_val list to
struct callchain_node and show them along with the (normal) val list.

For example, consider following callchains with '-g graph'.

  $ perf report -g graph
  - 39.93%  swapper  [kernel.vmlinux]  [k] intel_idle
   intel_idle
   cpuidle_enter_state
   cpuidle_enter
   call_cpuidle
 - cpu_startup_entry
  28.63% start_secondary
- 11.30% rest_init
 start_kernel
 x86_64_start_reservations
 x86_64_start_kernel

Before:
  $ perf report -g flat
  - 39.93%  swapper  [kernel.vmlinux]  [k] intel_idle
   28.63% start_secondary
 - 11.30% rest_init
  start_kernel
  x86_64_start_reservations
  x86_64_start_kernel

After:
  $ perf report -g flat
  - 39.93%  swapper  [kernel.vmlinux]  [k] intel_idle
 - 28.63% intel_idle
  cpuidle_enter_state
  cpuidle_enter
  call_cpuidle
  cpu_startup_entry
  start_secondary
 - 11.30% intel_idle
  cpuidle_enter_state
  cpuidle_enter
  call_cpuidle
  cpu_startup_entry
  start_kernel
  x86_64_start_reservations
  x86_64_start_kernel

Signed-off-by: Namhyung Kim 
Tested-by: Arnaldo Carvalho de Melo 
Tested-by: Brendan Gregg 
Cc: Andi Kleen 
Cc: David Ahern 
Cc: Frederic Weisbecker 
Cc: Jiri Olsa 
Cc: Kan Liang 
Cc: Peter Zijlstra 
Link: 
http://lkml.kernel.org/r/1447047946-1691-8-git-send-email-namhy...@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/ui/browsers/hists.c | 122 -
 tools/perf/util/callchain.c|  44 +++
 tools/perf/util/callchain.h|   2 +
 3 files changed, 166 insertions(+), 2 deletions(-)

diff --git a/tools/perf/ui/browsers/hists.c b/tools/perf/ui/browsers/hists.c
index 0746d41d9efe..c44af461a68f 100644
--- a/tools/perf/ui/browsers/hists.c
+++ b/tools/perf/ui/browsers/hists.c
@@ -178,12 +178,44 @@ static int callchain_node__count_rows_rb_tree(struct 
callchain_node *node)
return n;
 }
 
+static int callchain_node__count_flat_rows(struct callchain_node *node)
+{
+   struct callchain_list *chain;
+   char folded_sign = 0;
+   int n = 0;
+
+   list_for_each_entry(chain, >parent_val, list) {
+   if (!folded_sign) {
+   /* only check first chain list entry */
+   folded_sign = callchain_list__folded(chain);
+   if (folded_sign == '+')
+   return 1;
+   }
+   n++;
+   }
+
+   list_for_each_entry(chain, >val, list) {
+   if (!folded_sign) {
+   /* node->parent_val list might be empty */
+   folded_sign = callchain_list__folded(chain);
+   if (folded_sign == '+')
+   return 1;
+   }
+   n++;
+   }
+
+   return n;
+}
+
 static int callchain_node__count_rows(struct callchain_node *node)
 {
struct callchain_list *chain;
bool unfolded = false;
int n = 0;
 
+   if (callchain_param.mode == CHAIN_FLAT)
+   return callchain_node__count_flat_rows(node);
+
list_for_each_entry(chain, >val, list) {
++n;
unfolded = chain->unfolded;
@@ -263,7 +295,7 @@ static void callchain_node__init_have_children(struct 
callchain_node *node,
chain = list_entry(node->val.next, struct callchain_list, list);
chain->has_children = has_sibling;
 
-   if (!list_empty(>val)) {
+   if (node->val.next != node->val.prev) {
chain = list_entry(node->val.prev, struct callchain_list, list);
chain->has_children = !RB_EMPTY_ROOT(>rb_root);
}
@@ -279,6 +311,8 @@ static void callchain__init_have_children(struct rb_root 
*root)
for (nd = rb_first(root); nd; nd = rb_next(nd)) {
struct callchain_node *node = rb_entry(nd, struct 
callchain_node, rb_node);
callchain_node__init_have_children(node, has_sibling);
+   if (callchain_param.mode == CHAIN_FLAT)
+   callchain_node__make_parent_list(node);
}
 }
 
@@ -612,6 +646,83 @@ static int hist_browser__show_callchain_list(struct 
hist_browser *browser,
return 1;
 }
 
+static int hist_browser__show_callchain_flat(struct hist_browser *browser,
+struct rb_root *root,
+unsigned short row, u64 total,
+print_callchain_entry_fn print,
+   

[PATCH 31/37] perf callchain: Add count fields to struct callchain_node

2015-11-19 Thread Arnaldo Carvalho de Melo
From: Namhyung Kim 

It's to track the count of occurrences of the callchains.

Signed-off-by: Namhyung Kim 
Acked-by: Brendan Gregg 
Acked-by: Jiri Olsa 
Cc: Andi Kleen 
Cc: David Ahern 
Cc: Frederic Weisbecker 
Cc: Kan Liang 
Cc: Peter Zijlstra 
Link: 
http://lkml.kernel.org/r/1447047946-1691-5-git-send-email-namhy...@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/util/callchain.c | 10 ++
 tools/perf/util/callchain.h |  7 +++
 2 files changed, 17 insertions(+)

diff --git a/tools/perf/util/callchain.c b/tools/perf/util/callchain.c
index b948bd068966..e390edd31504 100644
--- a/tools/perf/util/callchain.c
+++ b/tools/perf/util/callchain.c
@@ -437,6 +437,8 @@ add_child(struct callchain_node *parent,
 
new->children_hit = 0;
new->hit = period;
+   new->children_count = 0;
+   new->count = 1;
return new;
 }
 
@@ -484,6 +486,9 @@ split_add_child(struct callchain_node *parent,
parent->children_hit = callchain_cumul_hits(new);
new->val_nr = parent->val_nr - idx_local;
parent->val_nr = idx_local;
+   new->count = parent->count;
+   new->children_count = parent->children_count;
+   parent->children_count = callchain_cumul_counts(new);
 
/* create a new child for the new branch if any */
if (idx_total < cursor->nr) {
@@ -494,6 +499,8 @@ split_add_child(struct callchain_node *parent,
 
parent->hit = 0;
parent->children_hit += period;
+   parent->count = 0;
+   parent->children_count += 1;
 
node = callchain_cursor_current(cursor);
new = add_child(parent, cursor, period);
@@ -516,6 +523,7 @@ split_add_child(struct callchain_node *parent,
rb_insert_color(>rb_node_in, >rb_root_in);
} else {
parent->hit = period;
+   parent->count = 1;
}
 }
 
@@ -562,6 +570,7 @@ append_chain_children(struct callchain_node *root,
 
 inc_children_hit:
root->children_hit += period;
+   root->children_count++;
 }
 
 static int
@@ -614,6 +623,7 @@ append_chain(struct callchain_node *root,
/* we match 100% of the path, increment the hit */
if (matches == root->val_nr && cursor->pos == cursor->nr) {
root->hit += period;
+   root->count++;
return 0;
}
 
diff --git a/tools/perf/util/callchain.h b/tools/perf/util/callchain.h
index 060e636e33ab..cdb386d9ba02 100644
--- a/tools/perf/util/callchain.h
+++ b/tools/perf/util/callchain.h
@@ -60,6 +60,8 @@ struct callchain_node {
struct rb_root  rb_root_in; /* input tree of children */
struct rb_root  rb_root;/* sorted output tree of children */
unsigned intval_nr;
+   unsigned intcount;
+   unsigned intchildren_count;
u64 hit;
u64 children_hit;
 };
@@ -145,6 +147,11 @@ static inline u64 callchain_cumul_hits(struct 
callchain_node *node)
return node->hit + node->children_hit;
 }
 
+static inline unsigned callchain_cumul_counts(struct callchain_node *node)
+{
+   return node->count + node->children_count;
+}
+
 int callchain_register_param(struct callchain_param *param);
 int callchain_append(struct callchain_root *root,
 struct callchain_cursor *cursor,
-- 
2.1.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/


[PATCH 09/37] perf bpf: Allow attaching BPF programs to modules symbols

2015-11-19 Thread Arnaldo Carvalho de Melo
From: Wang Nan 

By extending the syntax of BPF object section names, this patch allows
users to attach BPF programs to symbols in modules. For example:

  SEC("module=i915;"
  "parse_cmds=i915_parse_cmds")
  int parse_cmds(void *ctx)
  {
  return 1;
  }

The implementation is very simple: like what 'perf probe' does, for module,
fill 'uprobe' field in 'struct perf_probe_event'. Other parts will be done
automatically.

Signed-off-by: Wang Nan 
Cc: Alexei Starovoitov 
Cc: Brendan Gregg 
Cc: Daniel Borkmann 
Cc: David Ahern 
Cc: He Kuang 
Cc: Jiri Olsa 
Cc: Kaixu Xia 
Cc: Masami Hiramatsu 
Cc: Namhyung Kim 
Cc: Peter Zijlstra 
Cc: Zefan Li 
Cc: pi3or...@163.com
Link: 
http://lkml.kernel.org/r/1447675815-166222-5-git-send-email-wangn...@huawei.com
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/util/bpf-loader.c | 16 
 1 file changed, 16 insertions(+)

diff --git a/tools/perf/util/bpf-loader.c b/tools/perf/util/bpf-loader.c
index 84169d6f2585..d0f02ed93804 100644
--- a/tools/perf/util/bpf-loader.c
+++ b/tools/perf/util/bpf-loader.c
@@ -119,6 +119,16 @@ config__exec(const char *value, struct perf_probe_event 
*pev)
return 0;
 }
 
+static int
+config__module(const char *value, struct perf_probe_event *pev)
+{
+   pev->uprobes = false;
+   pev->target = strdup(value);
+   if (!pev->target)
+   return -ENOMEM;
+   return 0;
+}
+
 static struct {
const char *key;
const char *usage;
@@ -131,6 +141,12 @@ static struct {
.desc   = "Set uprobe target",
.func   = config__exec,
},
+   {
+   .key= "module",
+   .usage  = "module=",
+   .desc   = "Set kprobe module",
+   .func   = config__module,
+   }
 };
 
 static int
-- 
2.1.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/


[PATCH v3] watchdog: add support for Sigma Designs SMP86xx/SMP87xx

2015-11-19 Thread Mans Rullgard
This adds support for the Sigma Designs SMP86xx/SMP87xx family built-in
watchdog.

Signed-off-by: Mans Rullgard 
---
Changes:
- deactivate initially if disable bit is set so as to avoid accidentally
  resetting if the counter is expired
---
 drivers/watchdog/Kconfig  |  10 ++
 drivers/watchdog/Makefile |   1 +
 drivers/watchdog/tangox_wdt.c | 222 ++
 3 files changed, 233 insertions(+)
 create mode 100644 drivers/watchdog/tangox_wdt.c

diff --git a/drivers/watchdog/Kconfig b/drivers/watchdog/Kconfig
index 7a8a6c6..f43ff7a 100644
--- a/drivers/watchdog/Kconfig
+++ b/drivers/watchdog/Kconfig
@@ -135,6 +135,16 @@ config MENF21BMC_WATCHDOG
  This driver can also be built as a module. If so the module
  will be called menf21bmc_wdt.
 
+config TANGOX_WATCHDOG
+   tristate "Sigma Designs SMP86xx/SMP87xx watchdog"
+   select WATCHDOG_CORE
+   depends on ARCH_TANGOX || COMPILE_TEST
+   help
+ Support for the watchdog in Sigma Designs SMP86xx (tango3)
+ and SMP87xx (tango4) family chips.
+
+ This driver can be built as a module. The module name is tangox_wdt.
+
 config WM831X_WATCHDOG
tristate "WM831x watchdog"
depends on MFD_WM831X
diff --git a/drivers/watchdog/Makefile b/drivers/watchdog/Makefile
index 53d4827..46cb387 100644
--- a/drivers/watchdog/Makefile
+++ b/drivers/watchdog/Makefile
@@ -187,6 +187,7 @@ obj-$(CONFIG_DA9055_WATCHDOG) += da9055_wdt.o
 obj-$(CONFIG_DA9062_WATCHDOG) += da9062_wdt.o
 obj-$(CONFIG_DA9063_WATCHDOG) += da9063_wdt.o
 obj-$(CONFIG_GPIO_WATCHDOG)+= gpio_wdt.o
+obj-$(CONFIG_TANGOX_WATCHDOG) += tangox_wdt.o
 obj-$(CONFIG_WM831X_WATCHDOG) += wm831x_wdt.o
 obj-$(CONFIG_WM8350_WATCHDOG) += wm8350_wdt.o
 obj-$(CONFIG_MAX63XX_WATCHDOG) += max63xx_wdt.o
diff --git a/drivers/watchdog/tangox_wdt.c b/drivers/watchdog/tangox_wdt.c
new file mode 100644
index 000..083d0f3
--- /dev/null
+++ b/drivers/watchdog/tangox_wdt.c
@@ -0,0 +1,222 @@
+/*
+ *  Copyright (C) 2015 Mans Rullgard 
+ *  SMP86xx/SMP87xx Watchdog driver
+ *
+ *  This program is free software; you can redistribute it and/or modify it
+ *  under  the terms of the GNU General  Public License as published by the
+ *  Free Software Foundation;  either version 2 of the License, or (at your
+ *  option) any later version.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#define DEFAULT_TIMEOUT 30
+
+static bool nowayout = WATCHDOG_NOWAYOUT;
+module_param(nowayout, bool, 0);
+MODULE_PARM_DESC(nowayout,
+"Watchdog cannot be stopped once started (default="
+__MODULE_STRING(WATCHDOG_NOWAYOUT) ")");
+
+static unsigned int timeout;
+module_param(timeout, int, 0);
+MODULE_PARM_DESC(timeout, "Watchdog timeout");
+
+/*
+ * Counter counts down from programmed value.  Reset asserts when
+ * the counter reaches 1.
+ */
+#define WD_COUNTER 0
+
+#define WD_CONFIG  4
+#define WD_CONFIG_XTAL_IN  BIT(0)
+#define WD_CONFIG_DISABLE  BIT(31)
+
+struct tangox_wdt_device {
+   struct watchdog_device wdt;
+   void __iomem *base;
+   unsigned long clk_rate;
+   struct clk *clk;
+   struct notifier_block restart;
+};
+
+static int tangox_wdt_set_timeout(struct watchdog_device *wdt,
+ unsigned int new_timeout)
+{
+   wdt->timeout = new_timeout;
+
+   return 0;
+}
+
+static int tangox_wdt_start(struct watchdog_device *wdt)
+{
+   struct tangox_wdt_device *dev = watchdog_get_drvdata(wdt);
+   u32 ticks;
+
+   ticks = 1 + wdt->timeout * dev->clk_rate;
+   writel(ticks, dev->base + WD_COUNTER);
+
+   return 0;
+}
+
+static int tangox_wdt_stop(struct watchdog_device *wdt)
+{
+   struct tangox_wdt_device *dev = watchdog_get_drvdata(wdt);
+
+   writel(0, dev->base + WD_COUNTER);
+
+   return 0;
+}
+
+static unsigned int tangox_wdt_get_timeleft(struct watchdog_device *wdt)
+{
+   struct tangox_wdt_device *dev = watchdog_get_drvdata(wdt);
+   u32 count;
+
+   count = readl(dev->base + WD_COUNTER);
+
+   if (!count)
+   return 0;
+
+   return (count - 1) / dev->clk_rate;
+}
+
+static const struct watchdog_info tangox_wdt_info = {
+   .options  = WDIOF_SETTIMEOUT | WDIOF_KEEPALIVEPING | WDIOF_MAGICCLOSE,
+   .identity = "tangox watchdog",
+};
+
+static const struct watchdog_ops tangox_wdt_ops = {
+   .start  = tangox_wdt_start,
+   .stop   = tangox_wdt_stop,
+   .set_timeout= tangox_wdt_set_timeout,
+   .get_timeleft   = tangox_wdt_get_timeleft,
+};
+
+static int tangox_wdt_restart(struct notifier_block *nb, unsigned long action,
+ void *data)
+{
+   struct tangox_wdt_device *dev =
+   container_of(nb, struct tangox_wdt_device, restart);
+
+   writel(1, dev->base + WD_COUNTER);
+
+   return NOTIFY_DONE;
+}

[PATCH 07/37] perf bpf: Compile dwarf-regs.c if CONFIG_BPF_PROLOGUE is on

2015-11-19 Thread Arnaldo Carvalho de Melo
From: Wang Nan 

regs_query_register_offset() in dwarf-regs.c is required by BPF
prologue.  This patch compiles it if CONFIG_BPF_PROLOGUE is on to avoid
build failure when CONFIG_BPF_PROLOGUE is on but CONFIG_DWARF is not
set.

Signed-off-by: He Kuang 
Acked-by: Masami Hiramatsu 
Cc: Alexei Starovoitov 
Cc: He Kuang 
Cc: Zefan Li 
Cc: pi3or...@163.com
Link: 
http://lkml.kernel.org/r/1447675815-166222-10-git-send-email-wangn...@huawei.com
Signed-off-by: Wang Nan 
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/arch/x86/util/Build | 1 +
 1 file changed, 1 insertion(+)

diff --git a/tools/perf/arch/x86/util/Build b/tools/perf/arch/x86/util/Build
index ff63649fa9ac..465970370f3e 100644
--- a/tools/perf/arch/x86/util/Build
+++ b/tools/perf/arch/x86/util/Build
@@ -5,6 +5,7 @@ libperf-y += kvm-stat.o
 libperf-y += perf_regs.o
 
 libperf-$(CONFIG_DWARF) += dwarf-regs.o
+libperf-$(CONFIG_BPF_PROLOGUE) += dwarf-regs.o
 
 libperf-$(CONFIG_LIBUNWIND)  += unwind-libunwind.o
 libperf-$(CONFIG_LIBDW_DWARF_UNWIND) += unwind-libdw.o
-- 
2.1.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/


[GIT PULL 00/37] perf/core improvements and fixes

2015-11-19 Thread Arnaldo Carvalho de Melo
Hi Ingo,

Please consider pulling, this was based on tip/perf/urgent and I did a
test merge of tip/perf/core with tip/perf/urgent and then with this branch,
haven't noticed problems,

Best regards,

- Arnaldo

The following changes since commit e15bf88a44d1fcb685754b2868b1cd28927af3aa:

  Merge tag 'perf-urgent-for-mingo' of 
git://git.kernel.org/pub/scm/linux/kernel/git/acme/linux into perf/urgent 
(2015-11-18 06:56:48 +0100)

are available in the git repository at:

  git://git.kernel.org/pub/scm/linux/kernel/git/acme/linux.git 
tags/perf-core-for-mingo

for you to fetch changes up to 2c6caff2b26fde8f3f87183f8c97f2cebfdbcb98:

  perf ui/gtk: Support folded callchains (2015-11-19 13:19:26 -0300)


perf/core improvements and fixes:

User visible:

- Allows BPF scriptlets specify arguments to be fetched using
  DWARF info, using a prologue generated at compile/build time (He Kuang, Wang 
Nan)

- Allow attaching BPF scriptlets to module symbols (Wang Nan)

- Allow attaching BPF scriptlets to userspace code using uprobe (Wang Nan)

- BPF programs now can specify 'perf probe' tunables via its section name,
  separating key=val values using semicolons (Wang Nan)

Testing some of these new BPF features:

Use case: get callchains when receiving SSL packets, filter then in the
  kernel, at arbitrary place.

  # cat ssl.bpf.c
  #define SEC(NAME) __attribute__((section(NAME), used))

  struct pt_regs;

  SEC("func=__inet_lookup_established hnum")
  int func(struct pt_regs *ctx, int err, unsigned short port)
  {
  return err == 0 && port == 443;
  }

  char _license[] SEC("license") = "GPL";
  int  _version   SEC("version") = LINUX_VERSION_CODE;
  #
  # perf record -a -g -e ssl.bpf.c
  ^C[ perf record: Woken up 1 times to write data ]
  [ perf record: Captured and wrote 0.787 MB perf.data (3 samples) ]
  # perf script | head -30
  swapper 0 [000] 58783.268118: perf_bpf_probe:func: (816a0f60) 
hnum=0x1bb
 8a0f61 __inet_lookup_established (/lib/modules/4.3.0+/build/vmlinux)
 896def ip_rcv_finish (/lib/modules/4.3.0+/build/vmlinux)
 8976c2 ip_rcv (/lib/modules/4.3.0+/build/vmlinux)
 855eba __netif_receive_skb_core (/lib/modules/4.3.0+/build/vmlinux)
 8565d8 __netif_receive_skb (/lib/modules/4.3.0+/build/vmlinux)
 8572a8 process_backlog (/lib/modules/4.3.0+/build/vmlinux)
 856b11 net_rx_action (/lib/modules/4.3.0+/build/vmlinux)
 2a284b __do_softirq (/lib/modules/4.3.0+/build/vmlinux)
 2a2ba3 irq_exit (/lib/modules/4.3.0+/build/vmlinux)
 96b7a4 do_IRQ (/lib/modules/4.3.0+/build/vmlinux)
 969807 ret_from_intr (/lib/modules/4.3.0+/build/vmlinux)
 2dede5 cpu_startup_entry (/lib/modules/4.3.0+/build/vmlinux)
 95d5bc rest_init (/lib/modules/4.3.0+/build/vmlinux)
1163ffa start_kernel ([kernel.vmlinux].init.text)
11634d7 x86_64_start_reservations ([kernel.vmlinux].init.text)
1163623 x86_64_start_kernel ([kernel.vmlinux].init.text)

  qemu-system-x86  9178 [003] 58785.792417: perf_bpf_probe:func: 
(816a0f60) hnum=0x1bb
 8a0f61 __inet_lookup_established (/lib/modules/4.3.0+/build/vmlinux)
 896def ip_rcv_finish (/lib/modules/4.3.0+/build/vmlinux)
 8976c2 ip_rcv (/lib/modules/4.3.0+/build/vmlinux)
 855eba __netif_receive_skb_core (/lib/modules/4.3.0+/build/vmlinux)
 8565d8 __netif_receive_skb (/lib/modules/4.3.0+/build/vmlinux)
 856660 netif_receive_skb_internal (/lib/modules/4.3.0+/build/vmlinux)
 8566ec netif_receive_skb_sk (/lib/modules/4.3.0+/build/vmlinux)
   430a br_handle_frame_finish ([bridge])
   48bc br_handle_frame ([bridge])
 855f44 __netif_receive_skb_core (/lib/modules/4.3.0+/build/vmlinux)
 8565d8 __netif_receive_skb (/lib/modules/4.3.0+/build/vmlinux)
  #

  Use 'perf probe' various options to list functions, see what variables can
  be collected at any given point, experiment first collecting without a filter,
  then filter, use it together with 'perf trace', 'perf top', with or without
  callchains, if it explodes, please tell us!

- Introduce a new callchain mode: "folded", that will list per line
  representations of all callchains for a give histogram entry, facilitating
  'perf report' output processing by other tools, such as Brendan Gregg's
  flamegraph tools (Namhyung Kim)

  E.g:

 # perf report | grep -v ^# | head
18.37% 0.00%  swapper  [kernel.kallsyms]   [k] cpu_startup_entry
|
---cpu_startup_entry
   |
   |--12.07%--start_secondary
   |
--6.30%--rest_init
  start_kernel
  x86_64_start_reservations
  x86_64_start_kernel
  #

 Becomes, in "folded" mode:

 # perf 

[PATCH 06/37] perf bpf: Add BPF_PROLOGUE config options for further patches

2015-11-19 Thread Arnaldo Carvalho de Melo
From: Wang Nan 

If both LIBBPF and DWARF are detected, it is possible to create prologue
for eBPF programs to help them access kernel data. HAVE_BPF_PROLOGUE and
CONFIG_BPF_PROLOGUE are added as flags for this feature.

PERF_HAVE_ARCH_REGS_QUERY_REGISTER_OFFSET is introduced in commit
63ab024a5b6f295ca17a293ad81b7c728f49a89a ("perf tools:
regs_query_register_offset() infrastructure"), which indicates that an
architecture supports converting name of a register to its offset in
'struct pt_regs'. Without this support, BPF_PROLOGUE should be turned
off.

Signed-off-by: Wang Nan 
Cc: Alexei Starovoitov 
Cc: Masami Hiramatsu 
Cc: Zefan Li 
Cc: pi3or...@163.com
Link: 
http://lkml.kernel.org/r/1447675815-166222-9-git-send-email-wangn...@huawei.com
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/config/Makefile | 12 
 1 file changed, 12 insertions(+)

diff --git a/tools/perf/config/Makefile b/tools/perf/config/Makefile
index de89ec574361..6eb9a956a408 100644
--- a/tools/perf/config/Makefile
+++ b/tools/perf/config/Makefile
@@ -318,6 +318,18 @@ ifndef NO_LIBELF
   CFLAGS += -DHAVE_LIBBPF_SUPPORT
   $(call detected,CONFIG_LIBBPF)
 endif
+
+ifndef NO_DWARF
+  ifdef PERF_HAVE_ARCH_REGS_QUERY_REGISTER_OFFSET
+CFLAGS += -DHAVE_BPF_PROLOGUE
+$(call detected,CONFIG_BPF_PROLOGUE)
+  else
+msg := $(warning BPF prologue is not supported by architecture 
$(ARCH), missing regs_query_register_offset());
+  endif
+else
+  msg := $(warning DWARF support is off, BPF prologue is disabled);
+endif
+
   endif # NO_LIBBPF
 endif # NO_LIBELF
 
-- 
2.1.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/


[PATCH 01/37] perf test: Fix build of BPF and LLVM on older glibc libraries

2015-11-19 Thread Arnaldo Carvalho de Melo
From: Arnaldo Carvalho de Melo 

  $ rpm -q glibc
  glibc-2.12-1.166.el6_7.1.x86_64


CC   /tmp/build/perf/tests/llvm.o
  cc1: warnings being treated as errors
  tests/llvm.c: In function ‘test_llvm__fetch_bpf_obj’:
  tests/llvm.c:53: error: declaration of ‘index’ shadows a global declaration
  /usr/include/string.h:489: error: shadowed declaration is here

CC   /tmp/build/perf/tests/bpf.o
  cc1: warnings being treated as errors
  tests/bpf.c: In function ‘__test__bpf’:
  tests/bpf.c:149: error: declaration of ‘index’ shadows a global declaration
  /usr/include/string.h:489: error: shadowed declaration is here


Cc: He Kuang 
Cc: Jiri Olsa 
Cc: Namhyung Kim 
Cc: pi3or...@163.com
Cc: Wang Nan 
Cc: Zefan Li 
Fixes: b31de018a628 ("perf test: Enhance the LLVM test: update basic BPF test 
program")
Fixes: ba1fae431e74 ("perf test: Add 'perf test BPF'")
Link: http://lkml.kernel.org/n/tip-akpo4r750oya2phxoh9e3...@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/tests/bpf.c  | 14 +++---
 tools/perf/tests/llvm.c |  8 
 2 files changed, 11 insertions(+), 11 deletions(-)

diff --git a/tools/perf/tests/bpf.c b/tools/perf/tests/bpf.c
index ec16f7812c8b..6ebfdee3e2c6 100644
--- a/tools/perf/tests/bpf.c
+++ b/tools/perf/tests/bpf.c
@@ -146,7 +146,7 @@ prepare_bpf(void *obj_buf, size_t obj_buf_sz, const char 
*name)
return obj;
 }
 
-static int __test__bpf(int index)
+static int __test__bpf(int idx)
 {
int ret;
void *obj_buf;
@@ -154,27 +154,27 @@ static int __test__bpf(int index)
struct bpf_object *obj;
 
ret = test_llvm__fetch_bpf_obj(_buf, _buf_sz,
-  bpf_testcase_table[index].prog_id,
+  bpf_testcase_table[idx].prog_id,
   true);
if (ret != TEST_OK || !obj_buf || !obj_buf_sz) {
pr_debug("Unable to get BPF object, %s\n",
-bpf_testcase_table[index].msg_compile_fail);
-   if (index == 0)
+bpf_testcase_table[idx].msg_compile_fail);
+   if (idx == 0)
return TEST_SKIP;
else
return TEST_FAIL;
}
 
obj = prepare_bpf(obj_buf, obj_buf_sz,
- bpf_testcase_table[index].name);
+ bpf_testcase_table[idx].name);
if (!obj) {
ret = TEST_FAIL;
goto out;
}
 
ret = do_test(obj,
- bpf_testcase_table[index].target_func,
- bpf_testcase_table[index].expect_result);
+ bpf_testcase_table[idx].target_func,
+ bpf_testcase_table[idx].expect_result);
 out:
bpf__clear();
return ret;
diff --git a/tools/perf/tests/llvm.c b/tools/perf/tests/llvm.c
index bc4cf507cde5..366e38ba8b49 100644
--- a/tools/perf/tests/llvm.c
+++ b/tools/perf/tests/llvm.c
@@ -50,7 +50,7 @@ static struct {
 int
 test_llvm__fetch_bpf_obj(void **p_obj_buf,
 size_t *p_obj_buf_sz,
-enum test_llvm__testcase index,
+enum test_llvm__testcase idx,
 bool force)
 {
const char *source;
@@ -59,11 +59,11 @@ test_llvm__fetch_bpf_obj(void **p_obj_buf,
char *tmpl_new = NULL, *clang_opt_new = NULL;
int err, old_verbose, ret = TEST_FAIL;
 
-   if (index >= __LLVM_TESTCASE_MAX)
+   if (idx >= __LLVM_TESTCASE_MAX)
return TEST_FAIL;
 
-   source = bpf_source_table[index].source;
-   desc = bpf_source_table[index].desc;
+   source = bpf_source_table[idx].source;
+   desc = bpf_source_table[idx].desc;
 
perf_config(perf_config_cb, NULL);
 
-- 
2.1.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/


[PATCH 10/37] perf bpf: Allow BPF program config probing options

2015-11-19 Thread Arnaldo Carvalho de Melo
From: Wang Nan 

By extending the syntax of BPF object section names, this patch allows users to
config probing options like what they can do in 'perf probe'.

The error message in 'perf probe' is also updated.

Test result:

For following BPF file test_probe_glob.c:

  # cat test_probe_glob.c
  __attribute__((section("inlines=no;func=SyS_dup?"), used))

  int func(void *ctx)
  {
  return 1;
  }

  char _license[] __attribute__((section("license"), used)) = "GPL";
  int _version __attribute__((section("version"), used)) = 0x40300;
  #
  # ./perf record  -e ./test_probe_glob.c ls /
  ...
  [ perf record: Woken up 1 times to write data ]
  [ perf record: Captured and wrote 0.013 MB perf.data ]
  # ./perf evlist
  perf_bpf_probe:func_1
  perf_bpf_probe:func

After changing "inlines=no" to "inlines=yes":

  # ./perf record  -e ./test_probe_glob.c ls /
  ...
  [ perf record: Woken up 2 times to write data ]
  [ perf record: Captured and wrote 0.013 MB perf.data ]
  # ./perf evlist
  perf_bpf_probe:func_3
  perf_bpf_probe:func_2
  perf_bpf_probe:func_1
  perf_bpf_probe:func

Then test 'force':

Use following program:

  # cat test_probe_force.c
  __attribute__((section("func=sys_write"), used))

  int funca(void *ctx)
  {
  return 1;
  }

  __attribute__((section("force=yes;func=sys_write"), used))

  int funcb(void *ctx)
  {
return 1;
  }

  char _license[] __attribute__((section("license"), used)) = "GPL";
  int _version __attribute__((section("version"), used)) = 0x40300;
  #

  # perf record -e ./test_probe_force.c usleep 1
  Error: event "func" already exists.
   Hint: Remove existing event by 'perf probe -d'
   or force duplicates by 'perf probe -f'
   or set 'force=yes' in BPF source.
  event syntax error: './test_probe_force.c'
   \___ Probe point exist. Try 'perf probe -d "*"' and set 
'force=yes'

  (add -v to see detail)
  ...

Then replace 'force=no' to 'force=yes':

  # vim test_probe_force.c
  # perf record -e ./test_probe_force.c usleep 1
  [ perf record: Woken up 1 times to write data ]
  [ perf record: Captured and wrote 0.017 MB perf.data ]
  # perf evlist
  perf_bpf_probe:func_1
  perf_bpf_probe:func
  #

Signed-off-by: Wang Nan 
Tested-by: Arnaldo Carvalho de Melo 
Cc: Alexei Starovoitov 
Cc: Masami Hiramatsu 
Cc: Zefan Li 
Cc: pi3or...@163.com
Link: 
http://lkml.kernel.org/r/1447675815-166222-7-git-send-email-wangn...@huawei.com
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/util/bpf-loader.c  | 53 +--
 tools/perf/util/probe-event.c |  7 --
 2 files changed, 56 insertions(+), 4 deletions(-)

diff --git a/tools/perf/util/bpf-loader.c b/tools/perf/util/bpf-loader.c
index d0f02ed93804..98f2e5d1a5be 100644
--- a/tools/perf/util/bpf-loader.c
+++ b/tools/perf/util/bpf-loader.c
@@ -7,6 +7,7 @@
 
 #include 
 #include 
+#include 
 #include "perf.h"
 #include "debug.h"
 #include "bpf-loader.h"
@@ -129,6 +130,38 @@ config__module(const char *value, struct perf_probe_event 
*pev)
return 0;
 }
 
+static int
+config__bool(const char *value,
+bool *pbool, bool invert)
+{
+   int err;
+   bool bool_value;
+
+   if (!pbool)
+   return -EINVAL;
+
+   err = strtobool(value, _value);
+   if (err)
+   return err;
+
+   *pbool = invert ? !bool_value : bool_value;
+   return 0;
+}
+
+static int
+config__inlines(const char *value,
+   struct perf_probe_event *pev __maybe_unused)
+{
+   return config__bool(value, _conf.no_inlines, true);
+}
+
+static int
+config__force(const char *value,
+ struct perf_probe_event *pev __maybe_unused)
+{
+   return config__bool(value, _conf.force_add, false);
+}
+
 static struct {
const char *key;
const char *usage;
@@ -146,7 +179,19 @@ static struct {
.usage  = "module=",
.desc   = "Set kprobe module",
.func   = config__module,
-   }
+   },
+   {
+   .key= "inlines",
+   .usage  = "inlines=[yes|no]",
+   .desc   = "Probe at inline symbol",
+   .func   = config__inlines,
+   },
+   {
+   .key= "force",
+   .usage  = "force=[yes|no]  ",
+   .desc   = "Forcibly add events with existing name",
+   .func   = config__force,
+   },
 };
 
 static int
@@ -240,6 +285,10 @@ config_bpf_program(struct bpf_program *prog)
const char *config_str;
int err;
 
+   /* Initialize per-program probing setting */
+   probe_conf.no_inlines = false;
+   probe_conf.force_add = false;
+
config_str = bpf_program__title(prog, false);
if (IS_ERR(config_str)) {
pr_debug("bpf: unable to get title for program\n");
@@ -544,7 +593,7 @@ int bpf__strerror_probe(struct bpf_object *obj 
__maybe_unused,
scnprintf(buf, size, "%s (add 

[PATCH 03/37] tools: Adopt memdup() from tools/perf, moving it to tools/lib/string.c

2015-11-19 Thread Arnaldo Carvalho de Melo
From: Arnaldo Carvalho de Melo 

That will contain more string functions with counterparts, sometimes
verbatim copies, in the kernel.

Acked-by: Wang Nan 
Cc: Adrian Hunter 
Cc: Alexey Dobriyan 
Cc: David Ahern 
Cc: Jiri Olsa 
Cc: Namhyung Kim 
Link: http://lkml.kernel.org/n/tip-rah6g97kn21vfgmlramor...@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/include/linux/string.h   |  9 +
 tools/lib/string.c | 19 +++
 tools/perf/MANIFEST|  2 ++
 tools/perf/util/Build  |  6 ++
 tools/perf/util/include/linux/string.h |  3 ---
 tools/perf/util/string.c   | 16 
 6 files changed, 36 insertions(+), 19 deletions(-)
 create mode 100644 tools/include/linux/string.h
 create mode 100644 tools/lib/string.c
 delete mode 100644 tools/perf/util/include/linux/string.h

diff --git a/tools/include/linux/string.h b/tools/include/linux/string.h
new file mode 100644
index ..f3a6db6ad732
--- /dev/null
+++ b/tools/include/linux/string.h
@@ -0,0 +1,9 @@
+#ifndef _TOOLS_LINUX_STRING_H_
+#define _TOOLS_LINUX_STRING_H_
+
+
+#include/* for size_t */
+
+void *memdup(const void *src, size_t len);
+
+#endif /* _LINUX_STRING_H_ */
diff --git a/tools/lib/string.c b/tools/lib/string.c
new file mode 100644
index ..ecfd43a9b24e
--- /dev/null
+++ b/tools/lib/string.c
@@ -0,0 +1,19 @@
+#include 
+#include 
+#include 
+
+/**
+ * memdup - duplicate region of memory
+ *
+ * @src: memory region to duplicate
+ * @len: memory region length
+ */
+void *memdup(const void *src, size_t len)
+{
+   void *p = malloc(len);
+
+   if (p)
+   memcpy(p, src, len);
+
+   return p;
+}
diff --git a/tools/perf/MANIFEST b/tools/perf/MANIFEST
index 39c38cb45b00..2562eac6451d 100644
--- a/tools/perf/MANIFEST
+++ b/tools/perf/MANIFEST
@@ -22,6 +22,7 @@ tools/lib/api
 tools/lib/bpf
 tools/lib/hweight.c
 tools/lib/rbtree.c
+tools/lib/string.c
 tools/lib/symbol/kallsyms.c
 tools/lib/symbol/kallsyms.h
 tools/lib/util/find_next_bit.c
@@ -50,6 +51,7 @@ tools/include/linux/log2.h
 tools/include/linux/poison.h
 tools/include/linux/rbtree.h
 tools/include/linux/rbtree_augmented.h
+tools/include/linux/string.h
 tools/include/linux/types.h
 tools/include/linux/err.h
 include/asm-generic/bitops/arch_hweight.h
diff --git a/tools/perf/util/Build b/tools/perf/util/Build
index 591b3fe3ed49..e2316900f96f 100644
--- a/tools/perf/util/Build
+++ b/tools/perf/util/Build
@@ -21,6 +21,7 @@ libperf-y += parse-events.o
 libperf-y += perf_regs.o
 libperf-y += path.o
 libperf-y += rbtree.o
+libperf-y += libstring.o
 libperf-y += bitmap.o
 libperf-y += hweight.o
 libperf-y += run-command.o
@@ -138,6 +139,7 @@ $(OUTPUT)util/pmu.o: $(OUTPUT)util/pmu-flex.c 
$(OUTPUT)util/pmu-bison.c
 
 CFLAGS_find_next_bit.o += -Wno-unused-parameter 
-DETC_PERFCONFIG="BUILD_STR($(ETC_PERFCONFIG_SQ))"
 CFLAGS_rbtree.o+= -Wno-unused-parameter 
-DETC_PERFCONFIG="BUILD_STR($(ETC_PERFCONFIG_SQ))"
+CFLAGS_libstring.o += -Wno-unused-parameter 
-DETC_PERFCONFIG="BUILD_STR($(ETC_PERFCONFIG_SQ))"
 CFLAGS_hweight.o   += -Wno-unused-parameter 
-DETC_PERFCONFIG="BUILD_STR($(ETC_PERFCONFIG_SQ))"
 CFLAGS_parse-events.o  += -Wno-redundant-decls
 
@@ -153,6 +155,10 @@ $(OUTPUT)util/rbtree.o: ../lib/rbtree.c FORCE
$(call rule_mkdir)
$(call if_changed_dep,cc_o_c)
 
+$(OUTPUT)util/libstring.o: ../lib/string.c FORCE
+   $(call rule_mkdir)
+   $(call if_changed_dep,cc_o_c)
+
 $(OUTPUT)util/hweight.o: ../lib/hweight.c FORCE
$(call rule_mkdir)
$(call if_changed_dep,cc_o_c)
diff --git a/tools/perf/util/include/linux/string.h 
b/tools/perf/util/include/linux/string.h
deleted file mode 100644
index 6f19c548ecc0..
--- a/tools/perf/util/include/linux/string.h
+++ /dev/null
@@ -1,3 +0,0 @@
-#include 
-
-void *memdup(const void *src, size_t len);
diff --git a/tools/perf/util/string.c b/tools/perf/util/string.c
index fc8781de62db..7f7e072be746 100644
--- a/tools/perf/util/string.c
+++ b/tools/perf/util/string.c
@@ -342,22 +342,6 @@ char *rtrim(char *s)
return s;
 }
 
-/**
- * memdup - duplicate region of memory
- * @src: memory region to duplicate
- * @len: memory region length
- */
-void *memdup(const void *src, size_t len)
-{
-   void *p;
-
-   p = malloc(len);
-   if (p)
-   memcpy(p, src, len);
-
-   return p;
-}
-
 char *asprintf_expr_inout_ints(const char *var, bool in, size_t nints, int 
*ints)
 {
/*
-- 
2.1.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/


Re: ptrace() hangs on attempt to seize/attach stopped & frozen task

2015-11-19 Thread Oleg Nesterov
Thanks Pedro for your email,

I'll recheck tomorrow, but at first glance:

On 11/19, Pedro Alves wrote:
>
> Both GDB and gdbserver have special processing for attaching to 
> already-stopped
> processes.

Yes, I am starting to recall that I have looked at this code years ago ;)

>  907 linux_attach_lwp (ptid_t ptid)
>  908 {
>  909   struct lwp_info *new_lwp;
>  910   int lwpid = ptid_get_lwp (ptid);
>  911
>  912   if (ptrace (PTRACE_ATTACH, lwpid, (PTRACE_TYPE_ARG3) 0, 
> (PTRACE_TYPE_ARG4) 0)
>  913   != 0)
>  914 return errno;
>  915
>  916   new_lwp = add_lwp (ptid);
>  917
>  918   /* We need to wait for SIGSTOP before being able to make the next
>  919  ptrace call on this LWP.  */
>  920   new_lwp->must_set_ptrace_flags = 1;
>  921
>  922   if (linux_proc_pid_is_stopped (lwpid))

This can't happen today. Starting from v3.0 at least.

> This queuing of a SIGSTOP + PTRACE_CONT was necessary because
> otherwise when gdb attaches to a job stopped process, gdb would hang in the 
> waitpid
> after PTRACE_ATTACH, waiting for the initial SIGSTOP which would never arrive.

Yes, because its exit code could be already cleared iirc. This was fixed
even before.

> If the proposed change makes it so that a new intermediate state can be 
> observed
> right after PTRACE_ATTACH, and so linux_proc_pid_is_stopped can return false,
> then there's potential for breakage.

See above,

> But maybe not, if we're sure that
> that when that happens, waitpid returns for the initial
> PTRACE_ATTACH-induced SIGSTOP.

Yes. Just you can't assume that watpid(WNOHANG) will succeed. Is it OK?

Oleg.

--
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/


Re: [PATCH 2/4] timer: relax tick stop in idle entry

2015-11-19 Thread Jacob Pan
On Mon, 16 Nov 2015 16:09:10 -0800
Jacob Pan  wrote:

> > > For the second case, which is much more rare, I think we do have
> > > next timer exactly one tick away. Just don't know why tick will
> > > continue into idle loop.
> > 
> > Well, it should not be hard to figure that out. There are not so
> > many checks involved when tick_nohz_irq_exit() is called.  
> Thanks for the tip, I found the cause is in 
> int idle_cpu(int cpu)
> {
>   if (rq->nr_running)
>   return 0;
> 
> Since we only take into account of cfs_rq runnable taking over
> cfs_rq->nr_running when forced_idle is set.
I am not sure what is the best solution. It seems I can add additional
checks like this.
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -3520,9 +3520,14 @@ int idle_cpu(int cpu)
if (rq->curr != rq->idle)
return 0;
 
-   if (rq->nr_running)
-   return 0;
-
+   if (rq->nr_running) {
+   /* if cfs_rq is in forced idle, nr_running could be
nonzero but still in idle */
+   if ((rq->nr_running != rq->cfs.h_nr_running) ||
+   cfs_rq_runnable(>cfs))
+   return 0;
+   }

To recap the problem statement.
1. When entering idle loop tick_nohz_stop_sched_tick() checks if the
next timer interrupt is exactly one tick away. if so, it will not stop
it to avoid threshing timer disable and enable.
2. so it relies on the next round tick_nohz_irq_exit() to have another
chance to stop the tick
3. with idle injection rq->nr_running could be nonzero when in idle
4. tick_nohz_irq_exit() will not be called if !idle_cpu()

However, idle_cpu() is used by many other callers, e.g. load balance.
Do we want to consider forced idle in those cases? Or we can forgo this
case and ignore it?

Jacob
--
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/


Re: [GIT PULL] at91: fixes for 4.4 #1

2015-11-19 Thread Nicolas Ferre
Le 19/11/2015 16:22, Arnd Bergmann a écrit :
> On Tuesday 17 November 2015 12:35:58 Nicolas Ferre wrote:
>> Arnd, Olof, Kevin,
>>
>> This is the first "fixes" pull-request for AT91. I tried to collect little
>> patches that didn't make it for -rc1.
>> It can be due to synchronization between trees like the addition of some
>> sama5d2 Xplained nodes (MFD tree) or the change of the watchdog compatible
>> string for sama5d4 (watchdog tree).
>> It can also be due to trivial cleanups that were spotted or submitted late 
>> like
>> the replacement of "wakeup" properties or removal of unneeded defconfig 
>> option.
>> The removal of some dead legacy DT properties or nodes is, in my opinion 
>> worth
>> it as well in order to prevent us from abusive cut'n paste.
>> NAND and ISI Atmel MAINTAINERS entries are also updated.
>>
>> Tell me if it's okay for you.
> 
> I'd be happier to get the patches late in the process and then push back
> myself than to get them as fixes, there was really no reason to wait
> for the merge window to end with the ones that you already had.

I thought than having a precise milestone as a base for this
pull-request would be preferred.

> None of the changes look too invasive for -rc2, so I'm taking it anyway,
> but please try to let us know what you have earlier next time, so we
> can get the first fixes into the merge window, or add them as late
> additions on the branches before sending the main pull requests.
> 
> Inter-tree dependencies should never be a reason to send stuff after
> -rc1, let's talk about that before the merge window if you know you
> have those.

Sure, the communication in advance with you would have make all this
easier, sorry for not having done this.

Thanks Arnd. Bye,
-- 
Nicolas Ferre
--
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/


RE: [PATCH 0/8] staging: comedi: some comedi_write() changes

2015-11-19 Thread Hartley Sweeten
On Wednesday, November 18, 2015 10:55 AM, Ian Abbott wrote:
> Tidy up the "write" file operation handler, `comedi_write()` a bit and
> improve the error handling.
>
> 1) staging: comedi: rearrange comedi_write() code
> 2) staging: comedi: do extra checks for becoming non-busy for "write"
> 3) staging: comedi: make some variables unsigned in comedi_write()
> 4) staging: comedi: avoid bad truncation of a size_t in comedi_write()
> 5) staging: comedi: allow buffer wraparound in comedi_write()
> 6) staging: comedi: return error on "write" if no command set up
> 7) staging: comedi: simplify returned errors for comedi_write()
> 8) staging: comedi: check for more errors for zero-length write
>
>  drivers/staging/comedi/comedi_fops.c | 124 
> ---
>  1 file changed, 56 insertions(+), 68 deletions(-)

Ian,

Other than the minor nit-pick in patch 1 about the 'count == 0'
when becoming non-busy (the same situation is in comedi_read),
this looks good to me. It also makes the 'write' look more like the
'read'.

Thanks,

Reviewed-by: H Hartley Sweeten 

--
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/


Re: [PATCH] staging: android: ion: Fixing NULL comparison style

2015-11-19 Thread Greg KH
On Thu, Nov 19, 2015 at 10:29:53PM +0530, Anjali Menon wrote:
> Using checkpatch.pl fixed the check.
> 
> CHECK: Comparison to NULL could be written "!data"
> 
> Signed-off-by: Anjali Menon 
> ---
>  drivers/staging/android/ion/compat_ion.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/staging/android/ion/compat_ion.c 
> b/drivers/staging/android/ion/compat_ion.c
> index a402fda..8a0df9c 100644
> --- a/drivers/staging/android/ion/compat_ion.c
> +++ b/drivers/staging/android/ion/compat_ion.c
> @@ -137,7 +137,7 @@ long compat_ion_ioctl(struct file *filp, unsigned int 
> cmd, unsigned long arg)
>  
>   data32 = compat_ptr(arg);
>   data = compat_alloc_user_space(sizeof(*data));
> - if (data == NULL)
> + if ("!data" == NULL)

I don't think you compiled this code :(
--
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/


RE: [PATCH 0/2] staging: comedi: s526: add counter register macros

2015-11-19 Thread Hartley Sweeten
On Thursday, November 19, 2015 7:49 AM, Ian Abbott wrote:
> Add macros to describe the counter mode and counter control/status
> registers.  In patch 1, the macros for the counter mode register replace
> the use of bitfield structure and union types.
>
> 1) staging: comedi: s526: replace counter mode bitfield struct
> 2) staging: comedi: s526: add macros for counter control reg values
>
>  drivers/staging/comedi/drivers/s526.c | 197 
> ++
>  1 file changed, 130 insertions(+), 67 deletions(-)

Thanks! This one has bugged me.

Reviewed-by: H Hartley Sweeten 

--
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/


Re: [PATCH v2 2/5] Documentation: devicetree: Add DT bindings to eeprom_93xx46 driver.

2015-11-19 Thread Cory Tusar
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

On 11/19/2015 09:59 AM, Rob Herring wrote:
> On Wed, Nov 18, 2015 at 10:29:38PM -0500, Cory Tusar wrote:
>> This commit documents bindings to be added to the eeprom_93xx46 driver
>> which will allow:
>>
>>   - Device word size and read-only attributes to be specified.
>>   - A device-specific compatible string for use with Atmel AT93C46D
>> EEPROMs.
>>   - Specifying a GPIO line to function as a 'select' or 'enable' signal
>> prior to accessing the EEPROM.
>>
>> Signed-off-by: Cory Tusar 
> 
> One nit, but:
> 
> Acked-by: Rob Herring 
> 
>> ---
>>  .../devicetree/bindings/misc/eeprom-93xx46.txt | 25 
>> ++
>>  1 file changed, 25 insertions(+)
>>
>> diff --git a/Documentation/devicetree/bindings/misc/eeprom-93xx46.txt 
>> b/Documentation/devicetree/bindings/misc/eeprom-93xx46.txt
>> new file mode 100644
>> index 000..8e116a1
>> --- /dev/null
>> +++ b/Documentation/devicetree/bindings/misc/eeprom-93xx46.txt
>> @@ -0,0 +1,25 @@
>> +EEPROMs (SPI) compatible with Microchip Technology 93xx46 family.
>> +
>> +Required properties:
>> +- compatible : shall be one of:
>> +"atmel,at93c46d"
>> +"eeprom-93xx46"
>> +- data-size : number of data bits per word (either 8 or 16)
>> +
>> +Optional properties:
>> +- read-only : parameter-less property which disables writes to the EEPROM
>> +- select-gpios : if present, specifies the GPIO that will be asserted prior 
>> to
>> +  each access to the EEPROM (e.g. for SPI bus multiplexing)
>> +
>> +Property rules described in 
>> Documentation/devicetree/bindings/spi/spi-bus.txt
>> +apply.  In particular, "reg" and "spi-max-frequency" properties must be 
>> given.
>> +
>> +Example:
>> +93c46c@0 {
> 
> This should be eeprom@0.

Easy enough.  Will fix for v3.  Thanks.

>> +compatible = "eeprom-93xx46";
>> +reg = <0>;
>> +spi-max-frequency = <100>;
>> +spi-cs-high;
>> +data-size = <8>;
>> +select-gpios = < 4 GPIO_ACTIVE_HIGH>;
>> +};
>> -- 
>> 2.4.10
>>


- -- 
Cory Tusar
Principal
PID 1 Solutions, Inc.


"There are two ways of constructing a software design.  One way is to
 make it so simple that there are obviously no deficiencies, and the
 other way is to make it so complicated that there are no obvious
 deficiencies."  --Sir Charles Anthony Richard Hoare

-BEGIN PGP SIGNATURE-
Version: GnuPG v2

iEYEARECAAYFAlZOB0oACgkQHT1tsfGwHJ9EigCfUGD754C+nIpu5/bvnprFt1gF
DDYAn1KkIYfk6Tp5X1eqfn2OirGHVLTe
=PLGL
-END PGP SIGNATURE-
--
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/


Re: [RFC] In-kernel fuzz testing for apps

2015-11-19 Thread Laura Abbott

On 11/18/2015 03:39 PM, Andrey Utkin wrote:

Me and my friend have once talked about careful application development,
which includes awareness about all possible error conditions.
So we have collected ideas about making kernel (or, in some cases, libc)
"hostile" to careless application, and we present it so that the idea
doesn't get lost, and maybe even gets real if somebody wants some
features from the list.

- (libc) crash instantly if memcpy detects regions overlapping;
- return EINTR as much as possible;
- send/recv/etc. returns EAGAIN on non-blocking sockets as much as possible;
- send/recv tend to result in short writes/reads, e.g. 1 byte at a time,
to break assumption about sending/receiving some "not-so-big" thing at once;
- let write return ENOSPC sometimes;
- scheduler behaves differently from common case (e.g. let it tend to
stop a thread at some syscalls);
- return allocation failures;
- make OOM killer manic!
- make clocks which are not monotonic to go backward frequently;
- pretend the time is 2038 year or later;
- (arguable) close syscall returns non-zero first time, or randomly;
- (arguable) special arch having NULL not all zero-bits. Actually I
don't believe it is feasible to make a lot of modern software to run in
such situation.

These horrific modes should be enabled per-process or per-executable-file.

Thanks for your time and for any kind comment.



Check out CONFIG_FAULT_INJECTION, lib/fault_inject.c . There are a few things
there already. You could expand on that for other functionality.

Thanks,
Laura
--
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/


Re: [PATCH 3/4] sched: introduce synchronized idle injection

2015-11-19 Thread Morten Rasmussen
On Wed, Nov 18, 2015 at 07:51:47AM -0800, Arjan van de Ven wrote:
> On 11/18/2015 7:44 AM, Morten Rasmussen wrote:
> >I would not necessarily want to punish all cpus
> >system-wide if we have local overheating in one corner. If would rather
> >have it apply to only the overheating socket in a multi-socket machine
> >and only the big cores in a big.LITTLE system.
> 
> most of the time thermal issues aren't inside the SOC, but on a system level
> due to cheap heat spreaders or outright lack of space due to thinness. But
> even if you have one part of the die too hot:
> 
> For core level idle injection, no need to synchronize that; the reason to 
> synchronize
> is generally that when ALL cores are idle, additional power savings kick in
> (like memory going to self refresh, fabrics power gating etc); those 
> additional
> power savings are what makes this more efficient than just voltage/frequency
> scaling at the bottom of that range...   not so much the fact that things are 
> just idle.

I could see this technique being useful within the SoC as well.
Synchronized idle injection on all cpus in a cluster would allow us to
reach cluster idle states where resources shared within the cluster can
be gated or powered off as well. But yes, shutting down everything is
more efficient if you are en serious trouble.

I was hoping this could be a good alternative to hotplugging cpus out
for thermal management in non-critical situations, but it isn't that
appealing if you have to throttle all the cpus. I would consider it an
emergency-only mechanism (as in emergency brake) that isn't really
suitable for normal thermal management. In which case: Does this sort of
mechanism belong in the scheduler code?
--
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/


Re: [PATCH v3 11/12] drm/panel: simple: Add boe,tv080wum-nl0 simple panel device tree binding

2015-11-19 Thread Rob Herring
On Thu, Nov 19, 2015 at 11:35:29AM +0800, Chris Zhong wrote:
> This binding specifies a set of common properties for display panels. It
> can be used as a basis by bindings for specific panels.
> Bindings for three specific panels are provided to show how the
> simple panel binding can be used.
> 
> Signed-off-by: Chris Zhong 

Acked-by: Rob Herring 

> 
> ---
> 
> Changes in v3:
> move boe,tv080wum-nl0.txt to bindings/display/panel/
> 
> Changes in v2:
> As Thierry.Reding comment, add a documentation for this panel.
> 
>  .../devicetree/bindings/display/panel/boe,tv080wum-nl0.txt | 7 
> +++
>  1 file changed, 7 insertions(+)
>  create mode 100644 
> Documentation/devicetree/bindings/display/panel/boe,tv080wum-nl0.txt
> 
> diff --git 
> a/Documentation/devicetree/bindings/display/panel/boe,tv080wum-nl0.txt 
> b/Documentation/devicetree/bindings/display/panel/boe,tv080wum-nl0.txt
> new file mode 100644
> index 000..50be5e2
> --- /dev/null
> +++ b/Documentation/devicetree/bindings/display/panel/boe,tv080wum-nl0.txt
> @@ -0,0 +1,7 @@
> +Boe Corporation 8.0" WUXGA TFT LCD panel
> +
> +Required properties:
> +- compatible: should be "boe,tv080wum-nl0"
> +
> +This binding is compatible with the simple-panel binding, which is specified
> +in simple-panel.txt in this directory.
> -- 
> 2.6.3
> 
--
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/


Re: [PATCH v3 08/12] Documentation: dt-bindings: Add bindings for rk3288 DW MIPI DSI driver

2015-11-19 Thread Rob Herring
On Thu, Nov 19, 2015 at 11:35:26AM +0800, Chris Zhong wrote:
> add device tree bindings for rk3288 specific Synopsys DW MIPI DSI driver
> 
> Signed-off-by: Chris Zhong 

Acked-by: Rob Herring 

> 
> ---
> 
> Changes in v3:
> move dw_mipi_dsi_rockchip.txt to bindings/display/rockchip/
> 
> Changes in v2: None
> 
>  .../display/rockchip/dw_mipi_dsi_rockchip.txt  | 56 
> ++
>  1 file changed, 56 insertions(+)
>  create mode 100644 
> Documentation/devicetree/bindings/display/rockchip/dw_mipi_dsi_rockchip.txt
> 
> diff --git 
> a/Documentation/devicetree/bindings/display/rockchip/dw_mipi_dsi_rockchip.txt 
> b/Documentation/devicetree/bindings/display/rockchip/dw_mipi_dsi_rockchip.txt
> new file mode 100644
> index 000..acd9ec9
> --- /dev/null
> +++ 
> b/Documentation/devicetree/bindings/display/rockchip/dw_mipi_dsi_rockchip.txt
> @@ -0,0 +1,56 @@
> +Rockchip specific extensions to the Synopsys Designware MIPI DSI
> +
> +
> +Required properties:
> +- compatible: "rockchip,rk3288-mipi-dsi", "snps,dw-mipi-dsi".
> +- rockchip,grf: this soc should set GRF regs to mux vopl/vopb.
> +- ports: contain a port node with endpoint definitions as defined in [1].
> +  For vopb,set the reg = <0> and set the reg = <1> for vopl.
> +
> +For more required properties, please refer to [2].
> +
> +[1] Documentation/devicetree/bindings/media/video-interfaces.txt
> +[2] Documentation/devicetree/bindings/display/bridge/dw_mipi_dsi.txt
> +
> +Example:
> + mipi_dsi: mipi@ff96 {
> + #address-cells = <1>;
> + #size-cells = <0>;
> + compatible = "rockchip,rk3288-mipi-dsi", "snps,dw-mipi-dsi";
> + reg = <0xff96 0x4000>;
> + interrupts = ;
> + clocks = < SCLK_MIPI_24M>, < PCLK_MIPI_DSI0>;
> + clock-names = "ref", "pclk";
> + rockchip,grf = <>;
> + status = "okay";
> +
> + ports {
> + #address-cells = <1>;
> + #size-cells = <0>;
> + reg = <1>;
> +
> + mipi_in: port {
> + #address-cells = <1>;
> + #size-cells = <0>;
> + mipi_in_vopb: endpoint@0 {
> + reg = <0>;
> + remote-endpoint = <_out_mipi>;
> + };
> + mipi_in_vopl: endpoint@1 {
> + reg = <1>;
> + remote-endpoint = <_out_mipi>;
> + };
> + };
> + };
> +
> + panel {
> + compatible ="boe,tv080wum-nl0";
> + reg = <0>;
> +
> + enable-gpios = < 3 GPIO_ACTIVE_HIGH>;
> + pinctrl-names = "default";
> + pinctrl-0 = <_en>;
> + backlight = <>;
> + status = "okay";
> + };
> + };
> -- 
> 2.6.3
> 
> --
> To unsubscribe from this list: send the line "unsubscribe devicetree" in
> the body of a message to majord...@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
--
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/


Re: [PATCH RESEND_2] scsi_sysfs: protect against double execution of __scsi_remove_device()

2015-11-19 Thread Martin K. Petersen
> "Vitaly" == Vitaly Kuznetsov  writes:

Vitaly> On some host errors storvsc module tries to remove sdev by
Vitaly> scheduling a job which does the following:

Applied to 4.4.

-- 
Martin K. Petersen  Oracle Linux Engineering
--
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/


Re: [PATCH v2 5/5] misc: eeprom_93xx46: Add support for a GPIO 'select' line.

2015-11-19 Thread Andrew Lunn
On Thu, Nov 19, 2015 at 06:52:57PM +0200, Vladimir Zapolskiy wrote:
> On 19.11.2015 16:18, Andrew Lunn wrote:
> >>>  #ifdef CONFIG_OF
> >>> +static void select_assert(void *context)
> >>> +{
> >>> + struct eeprom_93xx46_dev *edev = context;
> >>> +
> >>> + gpiod_set_value_cansleep(gpio_to_desc(edev->pdata->select_gpio), 1);
> >>
> >> I would suggest to use gpio_set_value()
> > 
> > Could you explain why?
> > 
> > Maybe this gpio is on an SPI GPIO expander?
> 
> My point is that gpio_*() interface, gpio_set_value() or
> gpio_set_value_cansleep(), might be preferred is this particular case.

Ah, O.K, yes, avoid the gpio_to_desc() call.

Agreed.

Andrew
--
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/


Re: [PATCH RESEND] arm64: berlin: add the pinctrl dependency for Marvell Berlin SoCs

2015-11-19 Thread Jisheng Zhang
On Tue, 17 Nov 2015 13:41:54 +
Catalin Marinas wrote:

> On Mon, Nov 16, 2015 at 06:36:10PM +0800, Jisheng Zhang wrote:
> > This is to add the pinctrl dependency for Marvell Berlin SoCs.
> > 
> > Signed-off-by: Jisheng Zhang 
> > Acked-by: Sebastian Hesselbarth 
> > Acked-by: Antoine Tenart 
> > Acked-by: Linus Walleij 
> > ---
> >  this small patch is missed:
> >  
> > http://lists.infradead.org/pipermail/linux-arm-kernel/2015-October/378638.html
> >  arch/arm64/Kconfig.platforms | 1 +
> >  1 file changed, 1 insertion(+)
> > 
> > diff --git a/arch/arm64/Kconfig.platforms b/arch/arm64/Kconfig.platforms
> > index 4043c35..905d308 100644
> > --- a/arch/arm64/Kconfig.platforms
> > +++ b/arch/arm64/Kconfig.platforms
> > @@ -9,6 +9,7 @@ config ARCH_BERLIN
> > bool "Marvell Berlin SoC Family"
> > select ARCH_REQUIRE_GPIOLIB
> > select DW_APB_ICTL
> > +   select PINCTRL
> > help
> >   This enables support for Marvell Berlin SoC Family  
> 
> Cc'ing arm-soc.
> 

Dear Sebastian,

when adding clk support for BG4CT, I found

http://lists.infradead.org/pipermail/linux-arm-kernel/2015-October/378634.html
and
http://lists.infradead.org/pipermail/linux-arm-kernel/2015-October/378635.html

are also missed in v4.4-rc1.

I know you are very busy but I dunno what's wrong. Can you please check?

Thanks in advance,
Jisheng
--
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/


RE: [PATCH 1/8] staging: comedi: rearrange comedi_write() code

2015-11-19 Thread Hartley Sweeten
On Wednesday, November 18, 2015 10:55 AM, Ian Abbott wrote:
> Rearrange the code in `comedi_write()` to reduce the amount of
> indentation.  The code never reiterates the `while` loop once `count`
> has become non-zero, so we can check that in the `while` condition to
> save an indentation level.  (Note that `nbytes` has been checked to be
> non-zero before entering the loop, so we can remove that check.)  Move
> the code that makes the subdevice "become non-busy" outside the `while`
> loop, using a new flag variable `become_nonbusy` to decide whether it
> needs to be done.  This simplifies the wait queue handling so there is a
> single place where the task is removed from the wait queue, and we can
> remove the `on_wait_queue` flag variable.
>
> Signed-off-by: Ian Abbott 
> ---
>  drivers/staging/comedi/comedi_fops.c | 71 
> +++-
>  1 file changed, 30 insertions(+), 41 deletions(-)

Ian,

Minor nit-pick...

[snip]

> -out:
> - if (on_wait_queue)
> - remove_wait_queue(>wait_head, );
> + remove_wait_queue(>wait_head, );
>   set_current_state(TASK_RUNNING);
> + if (become_nonbusy && count == 0) {

It looks like 'count' will always be 0 here.

Regards
Hartley

--
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/


[PATCH] mfd: wm8994: Ensure that the whole MFD is built into a single module

2015-11-19 Thread Charles Keepax
The MFD part of wm8994 consists of three files wm8994-core.c,
wm8994-irq.c and wm8994-regmap.c only wm8994-core.c has a
MODULE_DESCRIPTION / LICENSE. These were clearly intended to be built
as a single module, but currently are not. This will lead to a tainted
kernel when loading modules for wm8894-irq.c and wm8994-regmap.c because
are missing a license.

This patch fixes this issue by grouping the three files together into a
single module.

Reported-by: Peter Robinson 
Signed-off-by: Charles Keepax 
---
 drivers/mfd/Makefile |3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)

diff --git a/drivers/mfd/Makefile b/drivers/mfd/Makefile
index a8b76b8..99f93ab 100644
--- a/drivers/mfd/Makefile
+++ b/drivers/mfd/Makefile
@@ -61,7 +61,8 @@ wm8350-objs   := wm8350-core.o 
wm8350-regmap.o wm8350-gpio.o
 wm8350-objs+= wm8350-irq.o
 obj-$(CONFIG_MFD_WM8350)   += wm8350.o
 obj-$(CONFIG_MFD_WM8350_I2C)   += wm8350-i2c.o
-obj-$(CONFIG_MFD_WM8994)   += wm8994-core.o wm8994-irq.o wm8994-regmap.o
+wm8994-objs:= wm8994-core.o wm8994-irq.o wm8994-regmap.o
+obj-$(CONFIG_MFD_WM8994)   += wm8994.o
 
 obj-$(CONFIG_TPS6105X) += tps6105x.o
 obj-$(CONFIG_TPS65010) += tps65010.o
-- 
1.7.2.5

--
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/


[PATCH] staging: android: ion: Fixing NULL comparison style

2015-11-19 Thread Anjali Menon
Using checkpatch.pl fixed the check.

CHECK: Comparison to NULL could be written "!data"

Signed-off-by: Anjali Menon 
---
 drivers/staging/android/ion/compat_ion.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/staging/android/ion/compat_ion.c 
b/drivers/staging/android/ion/compat_ion.c
index a402fda..8a0df9c 100644
--- a/drivers/staging/android/ion/compat_ion.c
+++ b/drivers/staging/android/ion/compat_ion.c
@@ -137,7 +137,7 @@ long compat_ion_ioctl(struct file *filp, unsigned int cmd, 
unsigned long arg)
 
data32 = compat_ptr(arg);
data = compat_alloc_user_space(sizeof(*data));
-   if (data == NULL)
+   if ("!data" == NULL)
return -EFAULT;
 
err = compat_get_ion_allocation_data(data32, data);
@@ -156,7 +156,7 @@ long compat_ion_ioctl(struct file *filp, unsigned int cmd, 
unsigned long arg)
 
data32 = compat_ptr(arg);
data = compat_alloc_user_space(sizeof(*data));
-   if (data == NULL)
+   if ("!data" == NULL)
return -EFAULT;
 
err = compat_get_ion_handle_data(data32, data);
@@ -173,7 +173,7 @@ long compat_ion_ioctl(struct file *filp, unsigned int cmd, 
unsigned long arg)
 
data32 = compat_ptr(arg);
data = compat_alloc_user_space(sizeof(*data));
-   if (data == NULL)
+   if ("!data" == NULL)
return -EFAULT;
 
err = compat_get_ion_custom_data(data32, data);
-- 
1.9.1

--
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/


[PATCH v3] arm64: Add support for PTE contiguous bit.

2015-11-19 Thread David Woods
The arm64 MMU supports a Contiguous bit which is a hint that the TTE
is one of a set of contiguous entries which can be cached in a single
TLB entry.  Supporting this bit adds new intermediate huge page sizes.

The set of huge page sizes available depends on the base page size.
Without using contiguous pages the huge page sizes are as follows.

 4KB:   2MB  1GB
64KB: 512MB

With a 4KB granule, the contiguous bit groups together sets of 16 pages
and with a 64KB granule it groups sets of 32 pages.  This enables two new
huge page sizes in each case, so that the full set of available sizes
is as follows.

 4KB:  64KB   2MB  32MB  1GB
64KB:   2MB 512MB  16GB

If a 16KB granule is used then the contiguous bit groups 128 pages
at the PTE level and 32 pages at the PMD level.

If the base page size is set to 64KB then 2MB pages are enabled by
default.  It is possible in the future to make 2MB the default huge
page size for both 4KB and 64KB granules.

Signed-off-by: David Woods 
Reviewed-by: Chris Metcalf 
---

This patch should resolve the comments on v2 and is now based on on the 
arm64 next tree which includes 16K granule support.  I've added definitions 
which should enable 2M and 1G huge page sizes with a 16K granule.  
Unfortunately, the A53 model we have does not support 16K so I don't 
have a way to test this.

 arch/arm64/Kconfig |   3 -
 arch/arm64/include/asm/hugetlb.h   |  44 ++
 arch/arm64/include/asm/pgtable-hwdef.h |  18 ++-
 arch/arm64/include/asm/pgtable.h   |  10 +-
 arch/arm64/mm/hugetlbpage.c| 267 -
 include/linux/hugetlb.h|   2 -
 6 files changed, 306 insertions(+), 38 deletions(-)

diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig
index 40e1151..077bb7c 100644
--- a/arch/arm64/Kconfig
+++ b/arch/arm64/Kconfig
@@ -480,9 +480,6 @@ config HW_PERF_EVENTS
 config SYS_SUPPORTS_HUGETLBFS
def_bool y
 
-config ARCH_WANT_GENERAL_HUGETLB
-   def_bool y
-
 config ARCH_WANT_HUGE_PMD_SHARE
def_bool y if ARM64_4K_PAGES || (ARM64_16K_PAGES && !ARM64_VA_BITS_36)
 
diff --git a/arch/arm64/include/asm/hugetlb.h b/arch/arm64/include/asm/hugetlb.h
index bb4052e..bbc1e35 100644
--- a/arch/arm64/include/asm/hugetlb.h
+++ b/arch/arm64/include/asm/hugetlb.h
@@ -26,36 +26,7 @@ static inline pte_t huge_ptep_get(pte_t *ptep)
return *ptep;
 }
 
-static inline void set_huge_pte_at(struct mm_struct *mm, unsigned long addr,
-  pte_t *ptep, pte_t pte)
-{
-   set_pte_at(mm, addr, ptep, pte);
-}
-
-static inline void huge_ptep_clear_flush(struct vm_area_struct *vma,
-unsigned long addr, pte_t *ptep)
-{
-   ptep_clear_flush(vma, addr, ptep);
-}
-
-static inline void huge_ptep_set_wrprotect(struct mm_struct *mm,
-  unsigned long addr, pte_t *ptep)
-{
-   ptep_set_wrprotect(mm, addr, ptep);
-}
 
-static inline pte_t huge_ptep_get_and_clear(struct mm_struct *mm,
-   unsigned long addr, pte_t *ptep)
-{
-   return ptep_get_and_clear(mm, addr, ptep);
-}
-
-static inline int huge_ptep_set_access_flags(struct vm_area_struct *vma,
-unsigned long addr, pte_t *ptep,
-pte_t pte, int dirty)
-{
-   return ptep_set_access_flags(vma, addr, ptep, pte, dirty);
-}
 
 static inline void hugetlb_free_pgd_range(struct mmu_gather *tlb,
  unsigned long addr, unsigned long end,
@@ -97,4 +68,19 @@ static inline void arch_clear_hugepage_flags(struct page 
*page)
clear_bit(PG_dcache_clean, >flags);
 }
 
+extern pte_t arch_make_huge_pte(pte_t entry, struct vm_area_struct *vma,
+   struct page *page, int writable);
+#define arch_make_huge_pte arch_make_huge_pte
+extern void set_huge_pte_at(struct mm_struct *mm, unsigned long addr,
+   pte_t *ptep, pte_t pte);
+extern int huge_ptep_set_access_flags(struct vm_area_struct *vma,
+ unsigned long addr, pte_t *ptep,
+ pte_t pte, int dirty);
+extern pte_t huge_ptep_get_and_clear(struct mm_struct *mm,
+unsigned long addr, pte_t *ptep);
+extern void huge_ptep_set_wrprotect(struct mm_struct *mm,
+   unsigned long addr, pte_t *ptep);
+extern void huge_ptep_clear_flush(struct vm_area_struct *vma,
+ unsigned long addr, pte_t *ptep);
+
 #endif /* __ASM_HUGETLB_H */
diff --git a/arch/arm64/include/asm/pgtable-hwdef.h 
b/arch/arm64/include/asm/pgtable-hwdef.h
index d6739e8..5c25b83 100644
--- a/arch/arm64/include/asm/pgtable-hwdef.h
+++ b/arch/arm64/include/asm/pgtable-hwdef.h
@@ -90,7 +90,23 @@
 /*
  * Contiguous page definitions.
  */
-#define CONT_PTES  (_AC(1, UL) 

Re: [PATCH 1/2] ARM: hisi: do not export smp_operations structures

2015-11-19 Thread Wei Xu

Hi Masahiro,

On 15/11/2015 01:39, Masahiro Yamada wrote:
> These three structures are only defined and referenced in
> mach-hisi/platsmp.c.
> 
> Drop the declarations from the header and add static qualifier
> to the definitions.
> 
> Signed-off-by: Masahiro Yamada 
> ---

Thanks!
Acked-by: Wei Xu 

Best Regards,
Wei

--
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/


Re: [Intel-gfx] [PATCH 0/1] async: export current_is_async()

2015-11-19 Thread Daniel Vetter
On Thu, Nov 19, 2015 at 11:10:16AM -0500, Tejun Heo wrote:
> Hello, Lukas.
> 
> On Thu, Nov 19, 2015 at 04:31:11PM +0100, Lukas Wunner wrote:
> > Hi Tejun,
> > 
> > when you introduced current_is_async() with 84b233adcca3, was it a
> > deliberate decision not to export it? All other non-static functions
> > in async.c are exported as well.
> > 
> > I'm asking because I would like to use it in i915.ko.
> 
> There just was no module user at the time.  Please feel free to export
> it.

I take that as an ack to pull Lukas' export patch in through drm-intel
trees.

Thanks, Daniel
-- 
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
--
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/


Re: [PATCH v2 5/5] misc: eeprom_93xx46: Add support for a GPIO 'select' line.

2015-11-19 Thread Vladimir Zapolskiy
On 19.11.2015 16:18, Andrew Lunn wrote:
>>>  #ifdef CONFIG_OF
>>> +static void select_assert(void *context)
>>> +{
>>> +   struct eeprom_93xx46_dev *edev = context;
>>> +
>>> +   gpiod_set_value_cansleep(gpio_to_desc(edev->pdata->select_gpio), 1);
>>
>> I would suggest to use gpio_set_value()
> 
> Could you explain why?
> 
> Maybe this gpio is on an SPI GPIO expander?

My point is that gpio_*() interface, gpio_set_value() or
gpio_set_value_cansleep(), might be preferred is this particular case.

I know it is legacy, but in this case there is no difference, if the
target have gpiolib, and the interface is broken, if the target does not
have gpiolib.

> 
>>>  static const struct of_device_id eeprom_93xx46_of_table[] = {
>>> { .compatible = "eeprom-93xx46", },
>>> { .compatible = "atmel,at93c46d", .data = _at93c46d_data, },
>>> @@ -385,6 +402,15 @@ static int eeprom_93xx46_probe_dt(struct spi_device 
>>> *spi)
>>> if (of_property_read_bool(np, "read-only"))
>>> pd->flags |= EE_READONLY;
>>>  
>>> +   ret = of_get_named_gpio(np, "select-gpios", 0);
>>
>> gpios or gpio? I see only one requested gpio.
> 
> DT always uses the plural. Go read some bindins in 
> Documentation/devicetree/bindings/
> 

Ok.

--
With best wishes,
Vladimir
--
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/


Re: [PATCH 13/14] mm: memcontrol: account socket memory in unified hierarchy memory controller

2015-11-19 Thread Johannes Weiner
On Thu, Nov 19, 2015 at 02:50:24PM +0100, Michal Hocko wrote:
> On Wed 18-11-15 16:48:22, Johannes Weiner wrote:
> [...]
> > So I ran perf record -g -a netperf -t TCP_STREAM multiple times inside
> > a memory-controlled cgroup, but mostly mem_cgroup_charge_skmem() does
> > not show up in the profile at all. Once it was there with 0.00%.
> 
> OK, this sounds very good! This means that most workloads which are not
> focusing solely on the network traffic shouldn't even notice. I can
> imagine that workloads with high throughput demands would notice but I
> would also expect them to disable the feature.

Even for high throughput, the cost of this is a function of number of
packets sent. E.g. the 13MB/s over wifi showed the socket charging at
0.02%. But I just did an http transfer over 1Gbit ethernet at around
110MB/s, ten times the bandwidth, and the charge function is at 0.00%.

> Could you add this information to the changelog, please?

Sure, but which information exactly?

If we had found a realistic networking workload that is expected to be
containerized and had shown that load to be negatively affected by the
charging calls, that would have been worth bringing up in conjunction
with the boot-time flag. But what do we have to say here? People care
about cost. It seems unnecessary to point out the absence of it.
--
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/


Re: [PATCH 5/5] ARM: asm/div64.h: adjust to generic codde

2015-11-19 Thread Måns Rullgård
Nicolas Pitre  writes:

> On Thu, 19 Nov 2015, Måns Rullgård wrote:
>
>> Nicolas Pitre  writes:
>> 
>> > +static inline uint64_t __arch_xprod_64(uint64_t m, uint64_t n, bool bias)
>> > +{
>> > +  unsigned long long res;
>> > +  unsigned int tmp = 0;
>> > +
>> > +  if (!bias) {
>> > +  asm (   "umull  %Q0, %R0, %Q1, %Q2\n\t"
>> > +  "mov%Q0, #0"
>> > +  : "=" (res)
>> > +  : "r" (m), "r" (n)
>> > +  : "cc");
>> > +  } else if (!(m & ((1ULL << 63) | (1ULL << 31 {
>> > +  res = m;
>> > +  asm (   "umlal  %Q0, %R0, %Q1, %Q2\n\t"
>> > +  "mov%Q0, #0"
>> > +  : "+" (res)
>> > +  : "r" (m), "r" (n)
>> > +  : "cc");
>> > +  } else {
>> > +  asm (   "umull  %Q0, %R0, %Q2, %Q3\n\t"
>> > +  "cmn%Q0, %Q2\n\t"
>> > +  "adcs   %R0, %R0, %R2\n\t"
>> > +  "adc%Q0, %1, #0"
>> > +  : "=" (res), "+" (tmp)
>> > +  : "r" (m), "r" (n)
>> 
>> Why is tmp using a +r constraint here?  The register is not written, so
>> using an input-only operand could/should result in better code.  That is
>> also what the old code did.
>
> No, it is worse. gcc allocates two registers because, somehow, it 
> doesn't think that the first one still holds zero after the first usage.  
> This way usage of only one temporary register is forced throughout, 
> producing better code.

Makes sense.  Thanks for explaining.

-- 
Måns Rullgård
m...@mansr.com
--
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/


Re: ptrace() hangs on attempt to seize/attach stopped & frozen task

2015-11-19 Thread Pedro Alves
On 11/17/2015 07:34 PM, Oleg Nesterov wrote:
> On 11/16, Tejun Heo wrote:

>>> And perhaps we can simply remove this logic? I forgot why do we hide this
>>> STOPPED -> RUNNING -> TRACED transition from the attaching thread. But the
>>> vague feeling tells me that we discussed this before and perhaps it was me
>>> who suggested to avoid the user-visible change when you introduced this
>>> transition...
>>
>> Heh, it was too long ago for me to remember much. :)
> 
> Same here...
> 
>>> Anyway, now I do not understand why do we want to hide it. Lets consider
>>> the following "test-case",
>>>
>>> void test(int pid)
>>> {
>>> kill(pid, SIGSTOP);
>>> waitpid(pid, NULL, WSTOPPED);
>>>
>>> ptrace(PTRACE_ATTACH-OR-PTRACE_SEIZE, pid, 0,0);
>>>
>>> assert(ptrace(PTRACE_DETACH, pid, 0,0) == 0);
>>> }
>>>
>>> Yes, it will fail if we remove JOBCTL_TRAPPING. But it can equally fail
>>> if SIGCONT comes before ATTACH, so perhaps we do not really care?
>>>
>>> Jan, Pedro, do you think the patch below can break gdb somehow? With this
>>> patch you can never assume that waitpid(WNOHANG) or ptrace(WHATEVER) will
>>> succeed right after PTRACE_ATTACH/PTRACE_SEIZE, even if you know that the
>>> tracee was TASK_STOPPED before attach.

Not sure, because I don't think I fully understand that proposed change.

Both GDB and gdbserver have special processing for attaching to already-stopped
processes.  (and neither use PTRACE_SEIZE yet.)

Here's the gdbserver version:

 
https://sourceware.org/git/?p=binutils-gdb.git;a=blob;f=gdb/gdbserver/linux-low.c;h=41ab510fa4ac5654f101f08efb68e26b5bc5dbd7;hb=HEAD#l903

Copied here for convenience:

 907 linux_attach_lwp (ptid_t ptid)
 908 {
 909   struct lwp_info *new_lwp;
 910   int lwpid = ptid_get_lwp (ptid);
 911
 912   if (ptrace (PTRACE_ATTACH, lwpid, (PTRACE_TYPE_ARG3) 0, 
(PTRACE_TYPE_ARG4) 0)
 913   != 0)
 914 return errno;
 915
 916   new_lwp = add_lwp (ptid);
 917
 918   /* We need to wait for SIGSTOP before being able to make the next
 919  ptrace call on this LWP.  */
 920   new_lwp->must_set_ptrace_flags = 1;
 921
 922   if (linux_proc_pid_is_stopped (lwpid))
 923 {
 924   if (debug_threads)
 925 debug_printf ("Attached to a stopped process\n");
 926
 927   /* The process is definitely stopped.  It is in a job control
 928  stop, unless the kernel predates the TASK_STOPPED /
 929  TASK_TRACED distinction, in which case it might be in a
 930  ptrace stop.  Make sure it is in a ptrace stop; from there we
 931  can kill it, signal it, et cetera.
 932
 933  First make sure there is a pending SIGSTOP.  Since we are
 934  already attached, the process can not transition from stopped
 935  to running without a PTRACE_CONT; so we know this signal will
 936  go into the queue.  The SIGSTOP generated by PTRACE_ATTACH is
 937  probably already in the queue (unless this kernel is old
 938  enough to use TASK_STOPPED for ptrace stops); but since
 939  SIGSTOP is not an RT signal, it can only be queued once.  */
 940   kill_lwp (lwpid, SIGSTOP);
 941
 942   /* Finally, resume the stopped process.  This will deliver the
 943  SIGSTOP (or a higher priority signal, just like normal
 944  PTRACE_ATTACH), which we'll catch later on.  */
 945   ptrace (PTRACE_CONT, lwpid, (PTRACE_TYPE_ARG3) 0, (PTRACE_TYPE_ARG4) 
0);
 946 }
 947
 948   /* The next time we wait for this LWP we'll see a SIGSTOP as 
PTRACE_ATTACH
 949  brings it to a halt.
 950

linux_proc_pid_is_stopped checks whether the state in /proc/pid/status is "T 
(stopped)".

Here's the equivalent in gdb:

  
https://sourceware.org/git/?p=binutils-gdb.git;a=blob;f=gdb/linux-nat.c;h=841ec3949c37438dfba924d8db6b37ffc416dd29;hb=HEAD#l974

This queuing of a SIGSTOP + PTRACE_CONT was necessary because
otherwise when gdb attaches to a job stopped process, gdb would hang in the 
waitpid
after PTRACE_ATTACH, waiting for the initial SIGSTOP which would never arrive.

If the proposed change makes it so that a new intermediate state can be observed
right after PTRACE_ATTACH, and so linux_proc_pid_is_stopped can return false,
then there's potential for breakage.  But maybe not, if we're sure that
that when that happens, waitpid returns for the initial
PTRACE_ATTACH-induced SIGSTOP.

Thanks,
Pedro Alves

--
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/


<    1   2   3   4   5   6   7   8   9   10   >